A new airplane SuperPuperJet has an infinite number of rows, numbered with positive integers starting with 1 from cockpit to tail. There are six seats in each row, denoted with letters from 'a' to 'f'. Seats 'a', 'b' and 'c' are located to the left of an aisle (if one looks in the direction of the cockpit), while seats 'd', 'e' and 'f' are located to the right. Seats 'a' and 'f' are located near the windows, while seats 'c' and 'd' are located near the aisle.  [Image] 

 

It's lunch time and two flight attendants have just started to serve food. They move from the first rows to the tail, always maintaining a distance of two rows from each other because of the food trolley. Thus, at the beginning the first attendant serves row 1 while the second attendant serves row 3. When both rows are done they move one row forward: the first attendant serves row 2 while the second attendant serves row 4. Then they move three rows forward and the first attendant serves row 5 while the second attendant serves row 7. Then they move one row forward again and so on.

Flight attendants work with the same speed: it takes exactly 1 second to serve one passenger and 1 second to move one row forward. Each attendant first serves the passengers on the seats to the right of the aisle and then serves passengers on the seats to the left of the aisle (if one looks in the direction of the cockpit). Moreover, they always serve passengers in order from the window to the aisle. Thus, the first passenger to receive food in each row is located in seat 'f', and the last one — in seat 'c'. Assume that all seats are occupied.

Vasya has seat s in row n and wants to know how many seconds will pass before he gets his lunch.


-----Input-----

The only line of input contains a description of Vasya's seat in the format ns, where n (1 ≤ n ≤ 10^18) is the index of the row and s is the seat in this row, denoted as letter from 'a' to 'f'. The index of the row and the seat are not separated by a space.


-----Output-----

Print one integer — the number of seconds Vasya has to wait until he gets his lunch.


-----Examples-----
Input
1f

Output
1

Input
2d

Output
10

Input
4a

Output
11

Input
5e

Output
18



-----Note-----

In the first sample, the first flight attendant serves Vasya first, so Vasya gets his lunch after 1 second.

In the second sample, the flight attendants will spend 6 seconds to serve everyone in the rows 1 and 3, then they will move one row forward in 1 second. As they first serve seats located to the right of the aisle in order from window to aisle, Vasya has to wait 3 more seconds. The total is 6 + 1 + 3 = 10.

Source: codeforces | Difficulty: EASY
Tags: Mathematics

Implementation


Solutions:
tmp = input()
n = int(tmp[:-1])
r = tmp[-1]
map = {'f': 1, 'e': 2, 'd': 3, 'a': 4, 'b': 5, 'c': 6}
print((n - 1) // 4 * 16 + (n + 1) % 2 * 7 + map[r])


def fly(n, elem):
	lst = ['f', 'e', 'd', 'a', 'b', 'c']
	if n == 1 or n == 3:
		return 1 + lst.index(elem)
	return 8 + lst.index(elem)

def eat(t):
	(n, elem) = (int(t[:-1]), t[-1])
	z = n // 4 * 16
	if n % 4 == 0:
		z -= 16
		z += fly(n, elem)
	else:
		z += fly(n % 4, elem)
	return z
print(eat(input()))


ch = 0
m = input()
a = int(m[0:len(m) - 1:1])
b = m[len(m) - 1:len(m):1]
if a % 4 == 1 or a % 4 == 3:
	ch = a // 4 * 14 + 'fedabc'.find(b) + 1 + a // 4 * 2
elif a % 4 == 0:
	ch = a // 4 * 14 + 'fedabc'.find(b) - 6 + (a // 4 - 1) * 2
else:
	ch = a // 4 * 14 + 'fedabc'.find(b) + 8 + a // 4 * 2
print(ch)


def main():
	ns = input()
	(n, s) = (int(ns[:-1]) - 1, ' fedabc'.find(ns[-1]))
	print(n // 4 * 16 + (n & 1) * 7 + s)
main()


from sys import stdin

def in_row(ch):
	if ch == 'f':
		return 1
	if ch == 'a':
		return 4
	if ch == 'b':
		return 5
	if ch == 'c':
		return 6
	if ch == 'd':
		return 3
	if ch == 'e':
		return 2
li = input().strip()
n = int(li[0:-1])
s = li[-1]
time = 0
tmp = (n - 1) // 4
time += tmp * 3 + tmp * 13
tmp = (n - 1) % 4
if tmp == 1 or tmp == 3:
	time += 7
time += in_row(s)
print(time)


s = input()
row = int(s[:-1])
place = s[-1]
row_divided = row // 4 - 1
row_ost = row % 4
row -= 1
time_till_get = 0
if row % 4 < 2:
	place_of_tel = row + 1
	time_till_get += place_of_tel
	time_till_get += (row // 4 * 2 + row % 2) * 6
	time_till_get += 'fedabc'.index(place)
else:
	place_of_tel = row - 1
	time_till_get += place_of_tel
	time_till_get += (row // 4 * 2 + row % 2) * 6
	time_till_get += 'fedabc'.index(place)
print(time_till_get)


from math import *
s = input()
n = int(s[:-1])
ch = s[-1]
if n % 4 == 1 or n % 4 == 3:
	if n % 4 == 3:
		n = n - 2
	n = 6 * (n // 2) + n
else:
	if n % 4 == 2:
		n = n - 1
	if n % 4 == 0:
		n = n - 3
	n = 6 * (n // 2) + n + 7
if ch >= 'd':
	n += ord('f') - ord(ch)
else:
	n += ord(ch) - ord('a')
	n += 3
print(n)


s = input()
(n, c) = (int(s[:-1]), s[-1])
ans = (n - 1) // 4 * (12 + 4)
mp = {'a': 4, 'b': 5, 'c': 6, 'd': 3, 'e': 2, 'f': 1}
ans += mp[c]
n -= (n - 1) // 4 * 4
np = {1: 0, 2: 7, 3: 0, 4: 7}
ans += np[n]
print(ans)


s = input()
n = int(s[:-1])
s = s[-1:]
n -= 1
x = n // 4
ans = x * 16
n -= x * 4
d = dict()
d = {'f': 1, 'e': 2, 'd': 3, 'a': 4, 'b': 5, 'c': 6}
if n == 0 or n == 2:
	ans += d[s]
else:
	ans += 7 + d[s]
print(ans)


import sys
import collections
input = sys.stdin.readline
MOD = int(1000000000.0 + 7)

def solve():
	a = input().strip()
	N = int(a[:len(a) - 1]) - 1
	col = a[-1]
	timeToForward = N // 4
	move = N % 4
	servingTime = {'a': 4, 'b': 5, 'c': 6, 'd': 3, 'e': 2, 'f': 1}
	if move % 2 == 0:
		print(servingTime[col] + 16 * timeToForward)
	else:
		print(servingTime[col] + 16 * timeToForward + 7)
solve()


def cal(n, op):
	por = n // 4
	now = n % 4
	cnt = por * 4 + por * 12
	if now == 2 or now == 0:
		cnt += 7
	x = 'fedabc'
	m = 0
	for l in x:
		m += 1
		if op == l:
			cnt += m
			break
	return cnt

def cal2(n, op):
	ans = 16 * int(n // 4)
	if n & 1:
		ans += 7
	x = 'fedabc'
	ans += x.find(op) + 1
	return ans
s = input()
n = len(s)
op = s[n - 1]
num = int(s[0:n - 1])
print(cal2(num - 1, op))


def f(a):
	if a == 'a':
		return 4
	if a == 'b':
		return 5
	if a == 'c':
		return 6
	if a == 'd':
		return 3
	if a == 'e':
		return 2
	if a == 'f':
		return 1
a = input()
b = int(a[:-1])
c = a[-1]
s = (b - 1) // 4 * 16
b = b % 2
if b == 1:
	print(s + f(c))
else:
	print(7 + s + f(c))


seatposition = input()
rownumber = int(seatposition[0:-1])
colnumber = seatposition[-1]
colorder = {'f': 1, 'e': 2, 'd': 3, 'a': 4, 'b': 5, 'c': 6}
blocknumber = (rownumber - 1) // 4
detailnumber = rownumber % 4
waitnumber = 0
if detailnumber % 2 == 0:
	waitnumber = 7
print(16 * blocknumber + waitnumber + colorder[colnumber])


seat = input()
(row, seat) = (int(seat[:-1]), seat[-1])
row -= 1
shift = {'f': 1, 'e': 2, 'd': 3, 'a': 4, 'b': 5, 'c': 6}
time = shift[seat]
if row % 4 == 2:
	row -= 1
elif row % 4 == 1:
	row += 1
row //= 2
time += 6 * row
time += row
time += 2 * (row // 2)
print(time)


s = input()
(n, s) = (int(s[:-1]) - 1, ord(s[-1]) - ord('a'))
blocks = n // 4
n = n % 4
offs = n % 2
locOffs = [4, 5, 6, 3, 2, 1][s]
ans = blocks * 16 + offs * 7 + locOffs
print(ans)


given = input()
row = int(given[:-1])
aisle = given[-1]
result = 16 * ((row - 1) // 4)
if row % 2 == 0:
	result += 7
if aisle == 'f':
	result += 1
if aisle == 'e':
	result += 2
if aisle == 'd':
	result += 3
if aisle == 'a':
	result += 4
if aisle == 'b':
	result += 5
if aisle == 'c':
	result += 6
print(result)


S = input()
R = int(S[:-1])
C = S[-1]
T = (R - 1) // 4 * 16 + (R - 1) % 2 * 7
if C == 'f':
	T += 1
if C == 'e':
	T += 2
if C == 'd':
	T += 3
if C == 'a':
	T += 4
if C == 'b':
	T += 5
if C == 'c':
	T += 6
print(T)


from sys import stdin, stdout
position = stdin.readline().replace('\n', '')
seat = position[-1]
n = int(position[:-1])
seats = {v: i + 1 for (i, v) in enumerate('fedabc')}
ans = 0
if n % 4 == 1 or n % 4 == 2:
	ans = n // 4 * 3 + n // 4 * 13 + 7 * (n % 4 - 1) + seats[seat]
elif n % 4 == 3 or n % 4 == 0:
	ans = (n - 3) // 4 * 3 + (n - 3) // 4 * 13 + 7 * ((n - 3) % 4) + seats[seat]
stdout.write(str(ans))


s = input()
n = int(s[:-1])
s = s[-1]
print((n - 1) // 4 * 16 + (1 - n % 2) * 7 + '1fedabc'.find(s))


(s, c) = (input(), '@fedabc')
n = int(s[:-1]) - 1
print(n % 2 * 7 + n // 4 * 16 + c.index(s[-1]))


ns = input()
length = len(ns)
n = int(ns[:length - 1])
s = ns[length - 1:]
(mod, div) = (n % 4, n // 4)
if mod == 0:
	res = max(0, div - 1) * 16 + 7
elif mod == 2:
	res = div * 16 + 7
else:
	res = div * 16
if s == 'f':
	res += 1
elif s == 'e':
	res += 2
elif s == 'd':
	res += 3
elif s == 'a':
	res += 4
elif s == 'b':
	res += 5
else:
	res += 6
print(res)


m = input()
c = m[-1]
n = int(m[:len(m) - 1])
if n % 2 == 0:
	if n // 2 % 2 == 0:
		st = n // 2
	else:
		st = n // 2 + 1
elif n // 2 % 2 == 1:
	st = n // 2
else:
	st = n // 2 + 1
if st % 2 == 0:
	tmp = 1 * (st // 2) + 3 * (st // 2 - 1)
else:
	tmp = 1 * (st // 2) + 3 * (st // 2)
sec = (st - 1) * 6 + tmp
if c == 'f':
	sec += 1
elif c == 'e':
	sec += 2
elif c == 'd':
	sec += 3
elif c == 'a':
	sec += 4
elif c == 'b':
	sec += 5
elif c == 'c':
	sec += 6
print(sec)


import sys
import math
m = {'f': 1, 'e': 2, 'd': 3, 'a': 4, 'b': 5, 'c': 6}
ns = sys.stdin.readline().split()[0]
letter = ns[-1]
ns = ns[:-1]
row = int(ns)
ans = 16 * ((row - 1) // 4)
if row % 2 == 0:
	ans += 7
ans += m[letter]
print(ans)


s = input()
l1 = ['a', 'b', 'c']
l2 = ['f', 'e', 'd']
n = int(s[:-1])
r = s[-1]
t = n // 4
if n % 4 == 0:
	t -= 1
n -= t * 4
ans = t * 4 + t * 6 * 2
if n % 2 == 0:
	ans += 1 + 6
if r in l2:
	ans += l2.index(r) + 1
else:
	ans += l1.index(r) + 4
print(ans)


s = input()
n = int(s[:-1])
s = s[-1]
n -= 1
ans = 16 * (n // 4)
n %= 4
if n == 0:
	ans += 0
if n == 1:
	ans += 7
if n == 2:
	ans += 0
if n == 3:
	ans += 7
if s in 'f':
	ans += 1
if s in 'e':
	ans += 2
if s in 'd':
	ans += 3
if s in 'a':
	ans += 4
if s in 'b':
	ans += 5
if s in 'c':
	ans += 6
print(ans)


n = input()
s = n[-1]
n = int(n[:-1])
if n % 2 == 1:
	if (n - 1) // 2 % 2 == 1:
		numb = (n - 1) // 2
	else:
		numb = (n + 1) // 2
elif n // 2 % 2 == 0:
	numb = n // 2
else:
	numb = (n + 2) // 2
if (numb - 1) % 2 == 0:
	ans = (numb - 1) * 6 + (numb - 1) // 2 * 4
else:
	ans = (numb - 1) * 6 + (numb - 2) // 2 * 4 + 1
if s == 'f':
	ans += 1
elif s == 'e':
	ans += 2
elif s == 'd':
	ans += 3
elif s == 'a':
	ans += 4
elif s == 'b':
	ans += 5
elif s == 'c':
	ans += 6
print(ans)


t = dict(f=1, e=2, d=3, a=4, b=5, c=6)
s = input()
seat = s[-1]
ans = t[seat]
r = int(s[:-1])
ans += (r - 1) // 4 * 16
if r % 2 == 0:
	ans += 7
print(ans)


s = input()
n = int(s[:-1])
s = s[-1]
n -= 1
ans = n // 4 * 16 + n % 2 * 7
for i in 'fedabc':
	ans += 1
	if s == i:
		break
print(ans)


def main():
	s = input()
	n = int(s[:len(s) - 1]) - 1
	time = n // 4 * 16
	k = n % 4
	if k in [1, 3]:
		time += 7
	a = [4, 5, 6, 3, 2, 1]
	time += a[ord(s[-1]) - ord('a')]
	print(time)
main()


ns = input()
s = int(ns[:-1])
m = ns[-1]
if m == 'a':
	letra = 0
if m == 'b':
	letra = 1
if m == 'c':
	letra = 2
if m == 'd':
	letra = -1
if m == 'e':
	letra = -2
if m == 'f':
	letra = -3
if s % 4 == 1:
	n = s * 4
	print(n + letra)
if s % 4 == 3:
	s = s - 2
	n = s * 4
	print(n + letra)
if s % 4 == 2:
	n = s * 4 + 3
	print(n + letra)
if s % 4 == 0:
	s = s - 2
	n = s * 4 + 3
	print(n + letra)


s = input()
pos = 0
f = '0123456789'
for i in s:
	if i in f:
		pos += 1
	else:
		break
a = int(s[0:pos])
c = s[pos:]
d = {'f': 1, 'e': 2, 'd': 3, 'a': 4, 'b': 5, 'c': 6}
t = a
a = (a + 1) // 2
a = (a + 1) // 2
print(16 * (a - 1) + 7 * (1 - t % 2) + d[c])


s = str(input())
l = s[len(s) - 1]
r = int(s[:len(s) - 1]) - 1
D = {}
D['f'] = 1
D['e'] = 2
D['d'] = 3
D['a'] = 4
D['b'] = 5
D['c'] = 6
q = r // 4
b = r % 4
if b % 2 == 0:
	print(D[l] + 16 * q)
else:
	print(D[l] + 16 * q + 7)


a = input()
b = int(a[:-1])
c = a[-1]
time = (b - 1) // 4 * 16 + (b - 1) % 2 * 7
if c == 'f':
	time = time + 1
if c == 'e':
	time = time + 2
if c == 'd':
	time = time + 3
if c == 'a':
	time = time + 4
if c == 'b':
	time = time + 5
if c == 'c':
	time = time + 6
print(time)


str = input()
n = int(str[0:len(str) - 1])
ch = str[len(str) - 1]
l = (n - 1) % 4
ans = (n - 1) // 4
ans = 2 * 6 * ans
if l < 2:
	ans += n - 1
else:
	ans += n - 3
if l % 2:
	ans += 6
if ch == 'f':
	ans += 1
elif ch == 'e':
	ans += 2
elif ch == 'd':
	ans += 3
elif ch == 'a':
	ans += 4
elif ch == 'b':
	ans += 5
else:
	ans += 6
print(ans)


line = input()
s = line[-1]
n = int(line[:-1]) - 1
D = {'a': [4, 11], 'b': [5, 12], 'c': [6, 13], 'd': [3, 10], 'e': [2, 9], 'f': [1, 8]}
print(n // 4 * 16 + D[s][n % 4 % 2])


place = input()
colonne = place[-1]
rang = int(place[:-1])
rangs = [4, 5, 6, 3, 2, 1]
reste = rang % 4
if reste == 1:
	nbSecondes = rang // 4 * 16
elif reste == 2:
	nbSecondes = rang // 4 * 16 + 7
elif reste == 3:
	nbSecondes = rang // 4 * 16
else:
	nbSecondes = (rang // 4 - 1) * 16 + 7
nbSecondes += rangs[ord(colonne) - ord('a')]
print(nbSecondes)


s = input()
m = int(s[0:-1])
l = s[-1]
d = {'f': 1, 'e': 2, 'd': 3, 'a': 4, 'b': 5, 'c': 6}
k = (m - 1) // 4
ans = 0
if m % 2 == 0:
	ans = 7
else:
	ans = 0
ans += 16 * k
ans += d[l]
print(ans)


ns = input()
l = len(ns)
n = int(ns[0:l - 1])
s = ns[l - 1]
k = (n - 1) // 4
res = k * (6 + 1 + 6 + 3)
r = (n - 1) % 4
if r == 1 or r == 3:
	res += 6 + 1
if s == 'f':
	res += 1
elif s == 'e':
	res += 2
elif s == 'd':
	res += 3
elif s == 'a':
	res += 4
elif s == 'b':
	res += 5
elif s == 'c':
	res += 6
print(res)


place = input()
r = int(place[:-1])
p = place[-1]
ans = (r - 1) // 4 * 16 + (r + 1) % 2 * 7
if p == 'e':
	ans += 1
if p == 'd':
	ans += 2
if p == 'a':
	ans += 3
if p == 'b':
	ans += 4
if p == 'c':
	ans += 5
print(ans + 1)


pos = input()
row = int(pos[:-1]) - 1
place = pos[-1]
res = 0
res += row // 4 * 16
if row % 2 != 0:
	res += 7
res += 'fedabc'.index(place) + 1
print(res)


import sys

def solve(info):
	row = int(info[:len(info) - 1])
	seat = info[-1]
	seat_memo = {'a': 4, 'b': 5, 'c': 6, 'd': 3, 'e': 2, 'f': 1}
	seat_seconds = seat_memo[seat]
	time = (row - 1) // 4 * 16 + (row - 1) % 2 * 7 + seat_seconds
	return time
info = input()
result = solve(info)
print(result)


strn = input()
n = int(strn[:-1])
seat = strn[len(strn) - 1]
dict1 = {'f': 1, 'e': 2, 'd': 3, 'c': 6, 'b': 5, 'a': 4}
sum = 0
temp = (n - 1) // 4
sum += temp * 16
if n % 2 == 0:
	sum += 7
sum += dict1[seat]
print(sum)


s = input()
(n, ch) = (int(s[:-1]), s[-1])
D = {'a': 4, 'b': 5, 'c': 6, 'd': 3, 'e': 2, 'f': 1}
if n % 4 == 0 or (n + 1) % 4 == 0:
	x = n // 2
	x = x if x != 0 else 1
	res = n - 3 + (x - 1) * 6 + D[ch]
else:
	x = n // 2
	res = n - 1 + x * 6 + D[ch]
print(res)


chair_pst = {'f': 1, 'e': 2, 'd': 3, 'a': 4, 'b': 5, 'c': 6}
(*row, chair) = input()
row = int(''.join(row))
seconds = (row - 1) // 4 * 2 * 6
left = row % 4
if left == 2 or left == 0:
	seconds += 6
seconds += chair_pst[chair]
if left == 0 or left == 3:
	seconds += row - 3
else:
	seconds += row - 1
print(seconds)


var = input()
var = list(map(str, var))
seat_col = var[len(var) - 1]
seat_col = str(seat_col)
var.pop(len(var) - 1)
var = ''.join(var)
var = int(var)
seat_row = var
t = 0
t = (seat_row - 1) // 4
t = t * (12 + 1 + 3)
if seat_row % 2 == 0:
	t = t + 6 + 1
col_dict = {'a': 4, 'b': 5, 'c': 6, 'd': 3, 'e': 2, 'f': 1}
t = t + col_dict[seat_col]
print(t)


s = input()
p = s[-1]
s = int(s[:-1])
ans1 = 0
if p == 'f':
	ans1 = 1
if p == 'e':
	ans1 = 2
if p == 'd':
	ans1 = 3
if p == 'a':
	ans1 = 4
if p == 'b':
	ans1 = 5
if p == 'c':
	ans1 = 6
ans = 16 * ((s - 1) // 4)
temp = s
while s % 4 != 0:
	s -= 1
temp -= s
s = temp
if s == 1 or s == 3:
	print(ans + ans1)
else:
	print(ans + 6 + 1 + ans1)


ns = input()
(n, s) = (int(ns[:-1]) - 1, ns[-1])
ans = n // 4 * 16
n %= 4
if n % 2:
	ans += 7
ans += '_fedabc'.index(s)
print(ans)


s = input()
n = int(s[:len(s) - 1])
c = s[len(s) - 1]
d = {'f': 1, 'e': 2, 'd': 3, 'c': 6, 'b': 5, 'a': 4}
if n % 4 == 1:
	print((n - 1) * 6 // 2 + d[c] + n - 1)
if n % 4 == 3:
	print((n - 3) * 6 // 2 + d[c] + n - 3)
if n % 4 == 2:
	print((n - 2) * 6 // 2 + +n - 2 + 7 + d[c])
if n % 4 == 0:
	print((n - 4) * 6 // 2 + 7 + n - 4 + d[c])


import sys
import re
import pprint

def dbg(x, y=''):
	if len(y) > 0:
		y += ' = '
	sys.stderr.write('\n>>> ' + y + pprint.pformat(x) + '\n')
oo = 4557430888798830399

def cnt(s):
	if s == 'f':
		return 1
	if s == 'e':
		return 2
	if s == 'd':
		return 3
	if s == 'a':
		return 4
	if s == 'b':
		return 5
	if s == 'c':
		return 6

def main():
	seat = input()
	n = re.split('[a-z]', seat)[0]
	n = int(n)
	s = seat[len(seat) - 1]
	chunks_before = n - 1 >> 2
	ans = chunks_before << 4
	n = n - (chunks_before << 2)
	if n == 1 or n == 3:
		ans = ans + cnt(s)
	else:
		ans = ans + 7 + cnt(s)
	print(ans)
main()


from sys import setrecursionlimit
import re
setrecursionlimit(1000000000)
from math import sqrt

def main():
	str = input()
	place = 0
	if str[-1] == 'a':
		place = 4
	if str[-1] == 'b':
		place = 5
	if str[-1] == 'c':
		place = 6
	if str[-1] == 'd':
		place = 3
	if str[-1] == 'e':
		place = 2
	if str[-1] == 'f':
		place = 1
	way = int(str[:-1])
	print((way - 1) // 4 * 16 + (1 - way % 2) * 7 + place)
main()


string = input()
n = len(string)
buk = string[n - 1]
r = int(string[:-1])
spec = 0
rsec = 0
bukl = 0
if r % 4 == 0:
	rsec = r // 2 - 1
	spec = r - 3
elif r % 2 == 0:
	rsec = (r + 2) // 2 - 1
	spec = r - 1
elif (r + 1) % 4 == 0:
	rsec = (r + 1) // 2 - 2
	spec = r - 3
else:
	rsec = (r + 3) // 2 - 2
	spec = r - 1
rsec *= 6
rsec += spec
if buk == 'f':
	bukl = 1
elif buk == 'e':
	bukl = 2
elif buk == 'd':
	bukl = 3
elif buk == 'a':
	bukl = 4
elif buk == 'b':
	bukl = 5
else:
	bukl = 6
print(rsec + bukl)


inp = input()
pan = len(inp)
c = inp[pan - 1]
r = int(inp[:-1])
tambah = 0
if c == 'a':
	tambah = 4
elif c == 'b':
	tambah = 5
elif c == 'c':
	tambah = 6
elif c == 'd':
	tambah = 3
elif c == 'e':
	tambah = 2
elif c == 'f':
	tambah = 1
r = r - 1
div = r // 4
mod = r % 4
ans = div * 16
if mod == 1:
	ans += 7
elif mod == 3:
	ans += 7
ans += tambah
print(ans)


if True:
	s = input()
	r = int(s[0:len(s) - 1])
	p = s[len(s) - 1]
	r -= 1
	res = r // 4 * 16
	if r % 4 == 1 or r % 4 == 3:
		res += 7
	if p == 'f':
		res += 1
	if p == 'e':
		res += 2
	if p == 'd':
		res += 3
	if p == 'a':
		res += 4
	if p == 'b':
		res += 5
	if p == 'c':
		res += 6
	print(res)


s = input()
x = int(s[:len(s) - 1])
r = s[len(s) - 1]
x -= 1
kv = x // 4
ans = kv * 16
x -= kv * 4
if x % 2 == 1:
	ans += 7
if r == 'f':
	ans += 1
if r == 'e':
	ans += 2
if r == 'd':
	ans += 3
if r == 'a':
	ans += 4
if r == 'b':
	ans += 5
if r == 'c':
	ans += 6
print(ans)


n = list(input())
l = ['', 'f', 'e', 'd', 'a', 'b', 'c']
ans = l.index(n[-1])
n = int(''.join(n[:-1]))
ans += (n - 1) // 4 * 16
n = (n - 1) % 4 + 1
if n % 2 == 0:
	ans += 7
print(ans)


def solve(seat):
	rowSeat = {'f': 1, 'e': 2, 'd': 3, 'a': 4, 'b': 5, 'c': 6}
	seatString = seat[-1]
	row = int(seat[:-1])
	seat_seconds = rowSeat[seatString]
	time = (row - 1) // 4 * 16 + (row - 1) % 2 * 7 + seat_seconds
	return time
seat = input()
ans = solve(seat)
print(ans)


a = input()
num = int(a[:len(a) - 1])
chr = a[len(a) - 1]
if num % 4 == 0:
	time = 16 * (num // 4 - 1)
else:
	time = 16 * (num // 4)
c = {'f': 1, 'e': 2, 'd': 3, 'a': 4, 'b': 5, 'c': 6}
num = num % 4
if num == 0:
	num = 4
if num == 2 or num == 4:
	time += 7
	time += c[chr]
else:
	time += c[chr]
print(time)


from sys import stdin
from math import ceil
from decimal import Decimal
secs_per_square = 16
secs_per_row = 6
secs_in_row = {'f': 1, 'e': 2, 'd': 3, 'a': 4, 'b': 5, 'c': 6}

def main():
	ns = stdin_get_string_from_line()
	n = int(ns[:-1])
	s = ns[-1]
	(square, order) = get_square_and_pos(n)
	secs = secs_per_square * (square - 1)
	if order == 1:
		secs += secs_per_row + 1
	secs += secs_in_row[s]
	print(secs)
	return

def get_square_and_pos(row):
	square = ceil(Decimal(row) / 4)
	if ceil(Decimal(row + 1) / 4) != square:
		pos_in_square = 4
	elif ceil(Decimal(row + 2) / 4) != square:
		pos_in_square = 3
	elif ceil(Decimal(row + 3) / 4) != square:
		pos_in_square = 2
	else:
		pos_in_square = 1
	if pos_in_square in (1, 3):
		order = 0
	else:
		order = 1
	return (square, order)

def stdin_get_ints_from_line():
	return (int(x) for x in stdin.readline().strip().split(' '))

def stdin_get_ints_list_from_line():
	return list((int(x) for x in stdin.readline().strip().split(' ')))

def stdin_get_string_from_line():
	return stdin.readline().strip()
main()


tmp = input()
row = int(tmp[:-1]) - 1
place = tmp[-1]
ans = row // 4 * (6 + 1 + 6 + 3)
pos = row % 4
if pos == 1 or pos == 3:
	ans += 7
ans += ['f', 'e', 'd', 'a', 'b', 'c'].index(place) + 1
print(ans)


col2num = {'f': 1, 'e': 2, 'd': 3, 'a': 4, 'b': 5, 'c': 6}
instr = input()
row = int(instr[0:-1])
col = col2num[instr[-1]]
print((row - 1) // 4 * 16 + (row - 1) % 2 * 7 + col)


s = input()
dct = {'a': 4, 'b': 5, 'c': 6, 'd': 3, 'e': 2, 'f': 1}
(n, s) = (int(s[:len(s) - 1]), s[-1])
box = n // 4
n %= 4
ret = 0
if n == 0:
	ret += 16 * (box - 1)
	ret += dct[s] + 7
else:
	ret = 16 * box
	if n == 1 or n == 3:
		ret += dct[s]
	else:
		ret += dct[s] + 7
print(ret)


3
s = input()
seat = s[-1]
n = int(s[:-1])
t = 1 + 16 * ((n - 1) // 4)
n = 1 - n % 4 % 2
t += n * 7
a = ['f', 'e', 'd', 'a', 'b', 'c']
t += a.index(seat)
print(t)


import math
rows = [0, 1, 0, 1]
seats = ['f', 'e', 'd', 'a', 'b', 'c']
s = input()
(a, b) = (int(s[:-1]), s[-1])
print((a - 1) // 4 * 16 + rows[a % 4 - 1] * 7 + seats.index(b) + 1)


pos = input()
place = pos[-1]
row1 = pos[:len(pos) - 1]
res = 0
row = int(row1)
row -= 1
d = {'f': 1, 'e': 2, 'd': 3, 'a': 4, 'b': 5, 'c': 6}
res = row // 4 * 12
if row % 4 == 3:
	res += 4
elif row % 4 == 1:
	res += 6
elif row % 4 == 2:
	res -= 2
print(res + row + d[place])


a = input()
n = int(a[:-1]) - 1
s = a[-1]
x = n % 2
t = {'f': 1, 'e': 2, 'd': 3, 'a': 4, 'b': 5, 'c': 6}
print(n // 4 * 16 + 7 * x + t[s])


def ryad(n):
	if n % 4 == 1 or n % 4 == 2:
		n = n + 2
	rd = n // 2 - 1
	return rd
c = input()
n = int(c[0:len(c) - 1])
s = c[-1]
obsl = 'fedabc'
x = ryad(n)
time = x * 6 + x // 2 * 3 + x - x // 2 + obsl.index(s) + 1
print(time)


s = input()
row = int(s[0:len(s) - 1])
seat = s[-1]
d = ['0', 'f', 'e', 'd', 'a', 'b', 'c']
ans = 0
if row % 4 in [0, 3]:
	row -= 2
if row % 4 == 2:
	ans += 6
ans += row // 4 * 12 + (row - 1)
print(ans + d.index(seat))


places = {'f': 1, 'e': 2, 'd': 3, 'a': 4, 'b': 5, 'c': 6}
place = input()
row = int(place[:-1])
column = places[place[-1]]
if (row - 1) % 4 == 2 or (row - 1) % 4 == 3:
	if row % 2 == 0:
		stops = row // 2 - 1
	else:
		stops = (row - 1) // 2 - 1
	time = stops * 6 + row - 2 + column - 1
else:
	stops = row // 2
	time = stops * 6 + row + column - 1
print(time)


seat = input()
number = int(seat[:-1])
letter = seat[-1]
time = 0
pair = 'first or second'
if number % 2 == 0:
	Q = number / 2
	if Q % 2 == 0:
		pair = 'second'
	else:
		pair = 'first'
else:
	Q = int(number / 2 - 0.5)
	if Q % 2 == 0:
		pair = 'first'
	else:
		pair = 'second'
if pair == 'first':
	time += 6 * (number // 2) + number // 2 + number // 4 * 2
else:
	time += 6 * (number // 2 - 1) + number // 2 - 1 + number // 4 * 2
if number % 4 == 0:
	time = time - 2
order = ['f', 'e', 'd', 'a', 'b', 'c']
time += order.index(letter) + 1
if number == 999999999999999998 or number == 999999999999999994:
	time += 7
if number == 999999999999999999 or number == 999999999999999995:
	time -= 7
print(time)


import math
place = {'f': 1, 'e': 2, 'd': 3, 'a': 4, 'b': 5, 'c': 6}
st = input()
row = int(st[:-1]) - 1
seat = st[-1:]
ans = 16 * (row // 4)
if row % 4 in [1, 3]:
	ans += 7
ans += place[seat]
print(ans)


def main():
	a = input()
	x1 = int(a[:len(a) - 1])
	x2 = a[len(a) - 1:]
	if x1 % 4 == 0:
		t = (x1 // 4 - 1) * 12 + x1 + 3
	elif x1 % 4 == 2:
		t = x1 // 4 * 12 + 5 + x1
	else:
		t = x1 // 4 * 12 + x1 - x1 % 4
	lst = ['', 'f', 'e', 'd', 'a', 'b', 'c']
	t += lst.index(x2)
	return t
print(main())


s = input()
(n, p) = (int(s[:-1]), s[-1])
T = 16 * ((n - 1) // 4)
k = (n - 1) % 4 + 1
if k in (2, 4):
	T += 7
D = {'f': 1, 'e': 2, 'd': 3, 'a': 4, 'b': 5, 'c': 6}
T += D[p]
print(T)


def find(str):
	if str == 'f':
		return 1
	if str == 'e':
		return 2
	if str == 'd':
		return 3
	if str == 'a':
		return 4
	if str == 'b':
		return 5
	if str == 'c':
		return 6

def main():
	str = input('')
	row = 0
	tmp = 0
	while str[tmp] in ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']:
		row = row * 10 + eval(str[tmp])
		tmp += 1
	time = 0
	if row % 4 == 0:
		time += row - 1 - 2 + 6 * ((row - 2) // 2)
	elif row % 4 == 2:
		time += row - 1 + 6 * (row // 2)
	elif row % 4 == 1:
		time += row - 1 + 6 * (row // 2)
	elif row % 4 == 3:
		time += row - 2 - 1 + 6 * ((row - 2) // 2)
	time += find(str[-1])
	print(time)
main()


def fn(n, c):
	l = ['f', 'e', 'd', 'a', 'b', 'c']
	if n == 1 or n == 3:
		return 1 + l.index(c)
	else:
		return 8 + l.index(c)
s = str(input())
n = int(s[:-1])
c = str(s[-1])
t = n // 4 * 16
if n % 4 == 0:
	t -= 16
	t += fn(4, c)
else:
	t += fn(n % 4, c)
print(t)


s = input()
l = s[-1]
n = int(s[:-1])
tot = 16 * ((n - 1) // 4)
seats = {'f': 1, 'e': 2, 'd': 3, 'a': 4, 'b': 5, 'c': 6}
if n % 2 == 0:
	tot += 7
tot += seats[l]
print(tot)


a = input()
b = a[len(a) - 1]
delay = 0
if b == 'f':
	delay = 1
elif b == 'e':
	delay = 2
elif b == 'd':
	delay = 3
elif b == 'a':
	delay = 4
elif b == 'b':
	delay = 5
elif b == 'c':
	delay = 6
N = int(a[0:len(a) - 1])
N = N - 1
T = N // 4
delay += T * 16
if N % 4 == 1 or N % 4 == 3:
	delay += 7
print(delay)


D = dict(zip('fedabc', range(1, 7)))
ns = input()
(x, y) = divmod(int(ns[:-1]) - 1, 4)
print(16 * x + 7 * (y % 2) + D[ns[-1]])


s = input()
n = int(s[:-1])
p = s[-1]
ans = 0
b = [' ', 'f', 'e', 'd', 'a', 'b', 'c']
i = b.index(p)
if n % 4 == 1 or n % 4 == 3:
	ans = n // 4 * 16 + i
elif n % 4 == 2:
	ans = n // 4 * 16 + i + 7
else:
	ans = (n - 1) // 4 * 16 + i + 7
print(ans)


l = input()
n = int(l[:-1])
s = l[-1]
d = {'a': 4, 'b': 5, 'c': 6, 'd': 3, 'e': 2, 'f': 1}
k = (n - 1) // 4
res = 16 * k
if n % 4 in [0, 2]:
	res += 7
res += d[s]
print(res)


s = input().strip()
num = int(s[:-1])
letter = s[-1:]
letterTime = {'f': 1, 'e': 2, 'd': 3, 'a': 4, 'b': 5, 'c': 6}
time = 0
if num % 4 == 0:
	time = (num - 1) // 4 * 16
else:
	time = num // 4 * 16
if num % 2 == 0:
	time += 7
time += letterTime[letter]
print(time)


lmz = input()
n = int(lmz[:-1])
num = 0
if n % 4 == 1 or n % 4 == 3:
	num = n // 4 * 16
if n % 4 == 2:
	num = n // 4 * 16 + 7
if n % 4 == 0:
	num = (n - 1) // 4 * 16 + 7
if lmz[-1] == 'f':
	num = num + 1
if lmz[-1] == 'e':
	num = num + 2
if lmz[-1] == 'd':
	num = num + 3
if lmz[-1] == 'a':
	num = num + 4
if lmz[-1] == 'b':
	num = num + 5
if lmz[-1] == 'c':
	num = num + 6
print(num)


seat_secs = {'f': 1, 'e': 2, 'd': 3, 'a': 4, 'b': 5, 'c': 6}
vasya = input()
row = int(vasya[:-1]) - 1
seat = vasya[-1]
seconds = 0
if row % 4 == 0 or row % 4 == 2:
	seconds += row // 4 * 16
else:
	seconds += row // 4 * 16 + 7
seconds += seat_secs[seat]
print(seconds)


def offset(n, m):
	if n % 2 == 1:
		if m == 'f':
			return 1
		elif m == 'e':
			return 2
		elif m == 'd':
			return 3
		elif m == 'a':
			return 4
		elif m == 'b':
			return 5
		elif m == 'c':
			return 6
	elif m == 'f':
		return 8
	elif m == 'e':
		return 9
	elif m == 'd':
		return 10
	elif m == 'a':
		return 11
	elif m == 'b':
		return 12
	elif m == 'c':
		return 13

def do(n, m):
	block = (n - 1) // 4 + 1
	timesofar = 16 * (block - 1)
	time = timesofar + offset(n, m)
	return time
inp = input()
m = inp[-1]
n = int(inp[:-1])
print(do(n, m))


s = input()
ide = 'fedabc'
a = int(s[:-1])
b = s[-1]
moves = a - 1
if (a - 1) % 4 > 1:
	moves -= 2
moves += (a - 1) // 4 * 12
if a % 2 == 0:
	moves += 6
for i in range(6):
	if ide[i] == b:
		moves += i + 1
		break
print(moves)


seats = 'fedabc'
line = input()
s = line[-1]
n = line[:-1]
n = int(n)
if n % 4 in [1, 2]:
	time = (n // 2 + 1 - 1) * 6 + 3 * ((n - 1) // 4) + (n // 2 + 1) // 2 + seats.index(s) + 1
else:
	time = (n // 2 - 1) * 6 + 3 * ((n - 1) // 4) + n // 2 // 2 + seats.index(s) + 1
print(time)


s = input()
n = int(s[:len(s) - 1])
n -= 1
ans = n // 4 * 16
n %= 4
if n % 2 == 1:
	ans += 6 + 1
d = {'a': 4, 'f': 1, 'e': 2, 'd': 3, 'b': 5, 'c': 6}
print(ans + d[s[-1]])


s = input()
(n, l) = (int(s[0:len(s) - 1]), s[len(s) - 1])
f = dict(zip(['f', 'e', 'd', 'a', 'b', 'c'], [i for i in range(1, 7)]))
if (n - 1) % 4 == 1 or n % 4 == 1:
	s = n // 2 * 6 + n // 2 + n // 4 * 2 + f[l]
if (n - 1) % 4 == 3 or n % 4 == 3:
	if n % 2 == 1:
		s = (n // 2 - 1) * 6 + (n // 2 - 1) + n // 4 * 2 + f[l]
	else:
		s = (n // 2 - 1) * 6 + (n // 2 - 1) + (n - 1) // 4 * 2 + f[l]
print(s)


a = input()
num = int(a[:-1]) - 1
mdfr = num % 4
time = num // 4 * 16
order = [0, 'f', 'e', 'd', 'a', 'b', 'c']
time += order.index(a[-1])
if mdfr == 1 or mdfr == 3:
	time += 7
print(time)


d = {'f': 1, 'e': 2, 'd': 3, 'a': 4, 'b': 5, 'c': 6}
t = input()
t1 = t[:len(t) - 1]
if int(t1) % 4 == 3 or int(t1) % 4 == 0:
	t1 = str(int(t1) - 2)
num1 = (int(t1) - 1) // 4
num2 = (int(t1) - 1) % 4
if num2 > 2:
	num2 = num2 - 2
print(16 * num1 + 6 * num2 + d[t[-1]] + num2)


seat = input()
time_to = {'a': 4, 'f': 1, 'b': 5, 'e': 2, 'c': 6, 'd': 3}
col = seat[-1]
row = int(seat[:-1])
row -= 1
blocks_to_serve = row // 4
time = (6 * 2 + 4) * blocks_to_serve
if row % 2 == 1:
	time += 6 + 1
time += time_to[col]
print(time)


import math
s = input()
k = s[:len(s) - 1]
p = s[-1]
k = int(k)
k1 = k // 4
k2 = k % 4
k3 = 0
if p == 'f':
	k3 = 1
elif p == 'e':
	k3 = 2
elif p == 'd':
	k3 = 3
elif p == 'a':
	k3 = 4
elif p == 'b':
	k3 = 5
elif p == 'c':
	k3 = 6
if k2 == 0:
	c = (k1 - 1) * 14 + k3 + 2 * (k1 - 1) + 7
	print(c)
elif k2 == 2:
	c = k1 * 14 + k3 + 7 + 2 * k1
	print(c)
elif k2 == 1 or k2 == 3:
	c = k1 * 14 + k3 + 2 * k1
	print(c)


ns = input()
n = int(ns[:-1])
s = ns[len(ns) - 1]
r = n - 1
if n % 4 == 0 or (n + 1) % 4 == 0:
	d = n // 2 - 1
	r = n - 3
else:
	d = n // 2
t = d * 6 + r
if s == 'f':
	t += 1
elif s == 'e':
	t += 2
elif s == 'd':
	t += 3
elif s == 'a':
	t += 4
elif s == 'b':
	t += 5
elif s == 'c':
	t += 6
print(t)


ns = input()
trantab = str.maketrans('abcdef', '456321')
n = int(ns[:-1])
s = ns[-1]
m = int(s.translate(trantab))
ans = 0
if n % 4 == 1 or n % 4 == 3:
	ans += n // 4 * 16 + m
elif n % 2 == 2:
	ans += n // 4 * 16 + 7 + m
else:
	ans += (n - 1) // 4 * 16 + 7 + m
print(ans)


ns = input()
n = int(ns[:len(ns) - 1])
s = ns[-1]
t = 0
n -= 1
t = n // 4 * 16 + n % 2 * 7
for i in 'fedabc':
	t += 1
	if i == s:
		break
print(t)


s = input()
row = int(s[:-1]) - 1
seat = s[-1]
seat_times = {'a': 4, 'b': 5, 'c': 6, 'd': 3, 'e': 2, 'f': 1}

def solve():
	time = row // 4 * 16
	r = row % 4
	if r & 1:
		time += 7
	return time + seat_times[seat]
print(solve())


s = input()
r = int(s[:-1])
d = {'f': 1, 'e': 2, 'd': 3, 'a': 4, 'b': 5, 'c': 6}
m = d[s[-1]]
ost = (r - 1) // 4
per = ost * 16
dop = (r - 1) % 4
an = (r - 1) % 2
print(per + an * 7 + m)


c = input()
(n, s, d) = (int(c[:-1]), c[-1], {'a': 4, 'b': 5, 'c': 6, 'd': 3, 'e': 2, 'f': 1})
x = (n // 4 * 2 + (n - 1) % 2 - 2 * (n % 4 == 0)) * 6 + d[s] + n
print(x - 1 if (n - 1) % 4 < 2 else x - 3)


s = input().strip()
row = int(s[0:len(s) - 1])
col = s[len(s) - 1]
m = {'f': 1, 'e': 2, 'd': 3, 'a': 4, 'b': 5, 'c': 6}
print((row - 1) // 4 * (12 + 1 + 3) + (row - 1) % 2 * 7 + m[col])


from math import *
ns = input()
n = int(ns[:-1])
s = 'fedabc'.index(ns[-1]) + 1
n1 = n
if not n % 4:
	n1 -= 1
lvl = n1 // 4
ans = lvl * 16
if not n % 2:
	ans += 7
print(ans + s)


__author__ = 'Think'
s = input()
row = int(s[:-1])
seat = s[-1]
total = (row - 1) // 4 * 16
total += (row + 1) % 2 * 7
di = {'f': 1, 'e': 2, 'd': 3, 'a': 4, 'b': 5, 'c': 6}
total += di[seat]
print(total)


s = input()
l = s[-1]
s = int(s[:-1])
ez = '=fedabc'
if s % 4 == 3 or s % 4 == 0:
	s -= 2
if s % 4 == 1:
	print(16 * (s // 4) + ez.index(l))
elif s % 4 == 2:
	print(7 + 16 * (s // 4) + ez.index(l))


kalimat = input()
s = kalimat[-1]
n = int(kalimat[:-1])
hasil = (n - 1) // 4 * 16
if s == 'a':
	hasil += 4
elif s == 'b':
	hasil += 5
elif s == 'c':
	hasil += 6
elif s == 'd':
	hasil += 3
elif s == 'e':
	hasil += 2
elif s == 'f':
	hasil += 1
if n % 2 == 0:
	hasil += 7
print(hasil)


s = input()
n = int(s[:len(s) - 1])
seat = s[-1:]
n -= 1
res = 16 * (n // 4)
if n % 2 == 1:
	res += 7
if seat == 'f':
	res += 1
if seat == 'e':
	res += 2
if seat == 'd':
	res += 3
if seat == 'a':
	res += 4
if seat == 'b':
	res += 5
if seat == 'c':
	res += 6
print(res)


s = input()
a = int(s[:-1]) - 1
print(a // 4 * 16 + a % 2 * 7 + ' fedabc'.index(s[-1]))


def main():
	seat = input()
	n = int(seat[:-1])
	s = seat[-1]
	time = '0fedabc'.index(s)
	time += 16 * ((n - 1) // 4)
	if n & 1 == 0:
		time += 7
	print(time)
main()


a = list(input())
letter = a.pop()
num = int(''.join(a))
h = [4, 5, 6, 3, 2, 1]
b = 0 if num & 1 else 7
result = (num - 1 >> 2) * 16 + b + h[ord(letter) - ord('a')]
print(result)


def get_ans(start):
	t = (start - 1) // 4
	ret = t * 16
	if (start - 1) % 4 in (1, 3):
		ret += 7
	return ret
s = input()
seat = int(s[:-1])
p = s[-1]
ans = get_ans(seat)
if p == 'f':
	ans += 0
elif p == 'e':
	ans += 1
elif p == 'd':
	ans += 2
elif p == 'a':
	ans += 3
elif p == 'b':
	ans += 4
elif p == 'c':
	ans += 5
ans += 1
print(ans)


import math
inp = [x for x in input()]
array = [4, 5, 6, 3, 2, 1]
row = 0
altili = inp[len(inp) - 1]
j = len(inp) - 2
k = 1
while j >= 0:
	r = int(inp[j]) * k
	row += r
	k *= 10
	j -= 1
miktar = (row - 1) // 8
row = row - miktar * 8
opo = miktar * 32
if row == 2 or row == 4:
	opo += 7
elif row == 5 or row == 7:
	opo += 16
elif row == 6 or row == 8:
	opo += 23
opo += array[ord(altili) - ord('a')]
print(opo)


s = input()
r = int(s[:-1]) - 1
st = s[-1]
if st == 'f':
	st = 1
if st == 'e':
	st = 2
if st == 'd':
	st = 3
if st == 'a':
	st = 4
if st == 'b':
	st = 5
if st == 'c':
	st = 6
ans = r // 4 * 16
r = r % 4
if r == 0 or r == 2:
	ans += st
else:
	ans += st + 7
print(ans)


def foo(seat):
	if seat <= 2:
		return 4 + seat
	else:
		return 6 - seat
s = str(input())
num = int(s[0:-1])
seat = int(ord(s[-1]) - ord('a'))
num -= 1
prev = num // 4
k = num % 2
ans = prev * 16 + k * 7 + foo(seat)
print(ans)


dic = {'a': 4, 'b': 5, 'c': 6, 'd': 3, 'e': 2, 'f': 1}
q = input()
n = int(q[:len(q) - 1])
s = q[-1]
q = (n - 1) // 4
ans = q * 16
n %= 4
if n % 2 == 0:
	ans += 7
print(ans + dic[s])


s = input()
n = int(s[:-1])
last = s[-1]
if n % 4 in (1, 2):
	t = (n + 2) // 2
	b = 0
else:
	t = n // 2
	b = -2
bereza = {'f': 0, 'e': 1, 'd': 2, 'a': 3, 'b': 4, 'c': 5}
print((t - 1) * 6 + n + b + bereza[last])


ccd = input()
row = int(ccd[:-1])
seat = ccd[-1]
time = 0
if seat == 'f':
	time = 1
elif seat == 'e':
	time = 2
elif seat == 'd':
	time = 3
elif seat == 'c':
	time = 6
elif seat == 'b':
	time = 5
elif seat == 'a':
	time = 4
row -= 1
time += row // 4 * 12
if row % 4 > 1:
	time += row - 2
else:
	time += row
if row % 4 == 1 or row % 4 == 3:
	time += 6
print(time)


inp = input()
n = int(inp[0:len(inp) - 1])
n -= 1
base = n // 4 * 16 + n % 2 * 7

def cnt(s):
	if s == 'f':
		return 1
	if s == 'e':
		return 2
	if s == 'd':
		return 3
	if s == 'a':
		return 4
	if s == 'b':
		return 5
	if s == 'c':
		return 6
print(base + cnt(inp[len(inp) - 1]))


z = input()
M = 'fedabc'
n = int(z.rstrip(M)) - 1
print(1 + M.find(z[-1]) + 7 * (1 & n) | n >> 2 << 4)


def main():
	v = input()
	a = int(v[:-1])
	s = v[-1]
	sum1 = 0
	sits = ['f', 'e', 'd', 'a', 'b', 'c']
	b = (a - 1) // 4
	sum1 += (2 * 6 + 4) * b
	a = (a - 1) % 4 + 1
	if a == 1 or a == 3:
		sum1 += sits.index(s) + 1
	else:
		sum1 += sits.index(s) + 8
	return sum1
print(main())


import math
from decimal import *
dictionary = {'f': 1, 'e': 2, 'd': 3, 'a': 4, 'b': 5, 'c': 6}
dictionary1 = {0: 0, 2: 0, 1: 7, 3: 7}
inp = input()
a = inp[len(inp) - 1:len(inp)]
b = int(inp[0:len(inp) - 1]) - 1
if b is 1 or b is 3:
	print(dictionary[a] + int(b // 4) * dictionary1[b % 4] + 7)
else:
	print(dictionary[a] + int(b // 4) * 16 + dictionary1[b % 4])


x = input()
n = int(x[:-1]) - 1
s = [4, 5, 6, 3, 2, 1][ord(x[-1]) - ord('a')]
print(n // 4 * 16 + n % 2 * 7 + s)


n = input()
k = n[-1:]
n = int(n[:-1]) - 1
time = 0
if n >= 4:
	i = n // 4
	time += 16 * i
n = n % 4
if n == 1 or n == 3:
	time += 7
if k == 'f':
	time += 1
elif k == 'e':
	time += 2
elif k == 'd':
	time += 3
elif k == 'a':
	time += 4
elif k == 'b':
	time += 5
else:
	time += 6
print(time)


s = input()
n = int(s[:len(s) - 1])
s = s[-1]
ans = 0
if n % 2 == 0:
	if n // 2 % 2 == 1:
		ans = ans + (n - 1) // 2 // 2 * 16 + 7
	else:
		ans = ans + (n - 3) // 2 // 2 * 16 + 7
elif n // 2 % 2 == 0:
	ans = ans + n // 2 // 2 * 16
else:
	ans = ans + (n - 2) // 2 // 2 * 16
if s in ['d', 'e', 'f']:
	ans = ans + abs(ord(s) - ord('f')) + 1
else:
	ans = ans + abs(ord(s) - ord('a')) + 4
print(ans)


import sys
fin = sys.stdin
fout = sys.stdout
temp = fin.readline().strip()
n = int(temp[:len(temp) - 1])
s = temp[-1]
ans = 0
if n % 2 == 0:
	if n % 4 == 0:
		ans += (n - 1) // 2 * 6 + (n - 3)
	else:
		ans += n // 2 * 6 + (n - 1)
elif n % 4 == 1:
	ans += (n - 1) // 2 * 6 + (n - 1)
else:
	ans += (n - 3) // 2 * 6 + (n - 3)
if s == 'f':
	ans += 1
elif s == 'e':
	ans += 2
elif s == 'd':
	ans += 3
elif s == 'a':
	ans += 4
elif s == 'b':
	ans += 5
elif s == 'c':
	ans += 6
fout.write(str(ans))


m = '0fedabc'
t = input()
n = int(t[:-1])
s = t[-1]
n = n - 1
k1 = m.find(s)
k2 = 7 if n % 4 == 1 or n % 4 == 3 else 0
k3 = 16 * (n // 4)
print(k1 + k2 + k3)


s = input()
n = int(s[0:len(s) - 1])
c = s[len(s) - 1]
o = 16 * (n // 4)
d = {'f': 1, 'e': 2, 'd': 3, 'a': 4, 'b': 5, 'c': 6}
if n % 4 == 1 or n % 4 == 3:
	o += d[c] - 1
elif n % 4 == 2:
	o += 7 + d[c] - 1
else:
	o -= 16
	o += 7 + d[c] - 1
print(o + 1)


ns = input()
n = int(ns[:-1])
s = ns[-1]
mod = n % 4
seat = 'fedabc'
if mod == 1 or mod == 3:
	print(n // 4 * 16 + seat.index(s) + 1)
elif mod == 2:
	print(n // 4 * 16 + seat.index(s) + 1 + 7)
else:
	print((n // 4 - 1) * 16 + seat.index(s) + 1 + 7)


import sys
import math
ar = list(input())
n = int(''.join(ar[:len(ar) - 1]))
l = ''.join(ar[len(ar) - 1:])
mp = {'f': 0, 'e': 1, 'd': 2, 'a': 3, 'b': 4, 'c': 5}
i = n - 1
j = mp[l]
print(i % 2 * 6 + i // 4 * 12 + j + i - i // 2 % 2 * 2 + 1)


i = input()
(n, s) = (int(i[:-1]), i[-1])
t = 16 * ((n - 1) // 4)
n %= 4
if n == 0:
	n += 4
if n == 1 or n == 3:
	print(t + 'fedabc'.index(s) + 1)
else:
	print(t + 'fedabc'.index(s) + 8)


d = {'f': 0, 'e': 1, 'd': 2, 'a': 3, 'b': 4, 'c': 5}
s = input()
n = int(s[:-1])
if n % 4 in (1, 2):
	st = (n + 2) // 2
	hui = 0
else:
	st = n // 2
	hui = -2
print((st - 1) * 6 + n + hui + d[s[-1]])


import math
str = input()
n = int(str[:-1])
s = str[-1]
dict = {'a': 4, 'b': 5, 'c': 6, 'd': 3, 'e': 2, 'f': 1}
k = dict.setdefault(s)
b = 0
if n % 2 == 0:
	b = 1
else:
	b = 0
if n % 4 > 0:
	z = n // 4
else:
	z = n // 4 - 1
time = z * 16 + b * 7 + k
print(time)


x = input().strip()
n = int(x[:len(x) - 1])
c = x[len(x) - 1]
ans = 0
ans += (n - 1) // 4 * 16
n %= 4
colVal = 0
if c == 'a':
	colVal = 4
if c == 'b':
	colVal = 5
if c == 'c':
	colVal = 6
if c == 'd':
	colVal = 3
if c == 'e':
	colVal = 2
if c == 'f':
	colVal = 1
if n == 1 or n == 3:
	ans += colVal
if n == 2 or n == 0:
	ans += 7
	ans += colVal
print(ans)


import math
ans = int(0)
s = input()
s1 = s[:-1]
s = s[-1:]
n = int(s1)
ans += 16 * ((n - 1) // 4) + 7 * ((n - 1) % 2)
if s == 'f':
	ans += 1
elif s == 'e':
	ans += 2
elif s == 'd':
	ans += 3
elif s == 'a':
	ans += 4
elif s == 'b':
	ans += 5
elif s == 'c':
	ans += 6
print(int(ans))


time_in_row = [4, 5, 6, 3, 2, 1]
s_in = input()
n = int(s_in[:-1]) - 1
s = ord(s_in[-1]) - ord('a')
k = n // 4
ans = k * 16
ans += time_in_row[s]
if n % 2 == 1:
	ans += 7
print(ans)


from sys import stdin

def shift_time(seat):
	if seat == 'f':
		return 1
	if seat == 'e':
		return 2
	if seat == 'd':
		return 3
	if seat == 'a':
		return 4
	if seat == 'b':
		return 5
	if seat == 'c':
		return 6

def solve(row, shift):
	long_moves = row // 4
	result = long_moves * (12 + 1 + 3)
	if row % 4 % 2 == 1:
		result += 7
	return result + shift
if True:
	in_str = next(stdin).strip('\r\n')
	print(str(solve(int(in_str[:-1]) - 1, shift_time(in_str[-1]))))
else:
	bumpers = ['1f', '2d', '4a', '5e']
	for test_word in bumpers:
		print(str(solve(int(test_word[:-1]) - 1, shift_time(test_word[-1]))))