x,c = input().split()
int(x)
y = True
n = False
overfee = 4
ans = 8
if c == n:
if x <= 1000:
print(ans)
elif x > 1000:
over = x - 1000
while over >= 0:
ans = ans + 4
over = over - 500
print(ans)
elif c == y:
ans = ans + 5
if x <= 1000:
print(ans)
elif x > 1000:
over = x - 1000
while over >= 0:
ans = ans + 4
over = over - 500
print(ans)