G = input() fh,mh = map(int,input().split()) S = input() D = input() if G == "M":
h = (fh + mh) * 0.54
else:
h = (fh * 0.923 + mh) / 2
def function(h):
if (S == "Y" and D == "N"):
h *= 1.02
elif (S == "N" and D == "Y"):
h = h * 1.015
elif (S == "Y" and D == "Y"):
h = h * 1.035
return h
h = function(h) print(h)