d = 390,429,468,507,546 l, s = input().split() l = int(l) if s == 'Beat': l += 1 print(d[l-1])