The World Chess Championship 2022 is about to start. 14 Classical games will be played between Chef and Carlsen in the championship, where each game has one of three outcomes — it can be won by Carlsen, won by Chef, or it can be a draw. The winner of a game gets 2 points, and the loser gets 0 points. If it’s a draw, both players get 1 point each.

The total prize pool of the championship is 100 \cdot X. At end of the 14 Classical games, if one player has strictly more points than the other, he is declared the champion and gets 60 \cdot X as his prize money, and the loser gets 40 \cdot X.

If the total points are tied, then the defending champion Carlsen is declared the winner. However, if this happens, the winner gets only 55 \cdot X, and the loser gets 45 \cdot X.

Given the results of all the 14 games, output the prize money that Carlsen receives.

The results are given as a string of length 14 consisting of the characters C, N, and D.
C denotes a victory by Carlsen.
N denotes a victory by Chef.
D denotes a draw.

------ Input Format ------ 

- The first line of input contains an integer T, denoting the number of test cases. The description of T test cases follows.
- The first line of each test case contains one integer X, denoting that the total prize pool is 100\cdot X.
- The second line contains the results of the match, as a string of length 14 containing only the characters C, N, and D.

------ Output Format ------ 

For each test case, output in a single line the total prize money won by Carlsen.

------ Constraints ------ 

$1 ≤ T ≤ 1000$
$1 ≤ X ≤ 10^{6}$
$|S| = 14$ 
$S$ contains only characters D, C, N.

------ subtasks ------ 

Subtask #1 (100 points): Original constraints

----- Sample Input 1 ------ 
4
100
CCCCCCCCCCCCCC
400
CDCDCDCDCDCDCD
30
DDCCNNDDDCCNND
1
NNDNNDDDNNDNDN
----- Sample Output 1 ------ 
6000
24000
1650
40

----- explanation 1 ------ 
Test case $1$: Since Carlsen won all the games, he will be crowned the champion and will get $60 \cdot X$ as the prize money which is $60 \cdot 100 = 6000$

Test case $2$: Carlsen won $7$ games and drew $7$, so his score is $2 \cdot 7 + 1 \cdot 7 = 21$. Chef lost $7$ games and drew $7$, so his score is $0 \cdot 7 + 1 \cdot 7 = 7$. Since Carlsen has more points, he will be crowned the champion and will get $60 \cdot X$ as the prize money which is $60 \cdot 400 = 24000$

Test case $3$: Carlsen and Chef both end up with $14$ points. So, Carlsen is declared the winner, but because the points were tied, he receives $55\cdot X = 55\cdot 30 = 1650$ in prize money.

Difficulty: EASY
Tags: Mathematics

Implementation

Starter code:

Solutions:
for _ in range(int(input())):
	priya = int(input())
	sc = input()
	ds = sc.count('D')
	cs = sc.count('C')
	ns = sc.count('N')
	if sc.count('C') > sc.count('N'):
		print(60 * priya)
	elif cs == ns:
		print(55 * priya)
	else:
		print(40 * priya)


t = int(input())
for i in range(t):
	a = int(input())
	b = input('')
	x = b.count('C')
	y = b.count('N')
	z = b.count('D')
	c = x * 2 + z * 1 > z * 1 + y * 2
	if c is True:
		print(60 * a)
	elif z + x * 2 == z + y * 2:
		print(55 * a)
	else:
		print(40 * a)


n = int(input())
for i in range(n):
	x = int(input())
	z = input()
	if z.count('C') + z.count('D') > z.count('N') + z.count('D'):
		print(x * 60)
	elif z.count('C') + z.count('D') == z.count('N') + z.count('D'):
		print(x * 55)
	else:
		print(x * 40)


t = int(input())
for i in range(t):
	X = int(input())
	s = input()
	(c, n) = (0, 0)
	for i in s:
		if i == 'C':
			c += 2
		elif i == 'N':
			n += 2
		else:
			c += 1
			n += 1
	print(55 * X if c == n else 60 * X if c > n else 40 * X)


for i in range(int(input())):
	x = int(input())
	s = input()
	(c, f) = (0, 0)
	for i in s:
		if i == 'C':
			c += 2
		elif i == 'N':
			f += 2
		elif i == 'D':
			c += 1
			f += 1
	if c == f:
		print(55 * x)
	elif c > f:
		print(60 * x)
	else:
		print(40 * x)


n = int(input())
for i in range(n):
	p = int(input())
	s = str(input())
	l = list(s)
	c = []
	n = []
	d = []
	for j in range(0, len(l)):
		if l[j] == 'C':
			c.append(1)
		elif l[j] == 'N':
			n.append(1)
		else:
			d.append(1)
	ca = len(c) * 2 + len(d) * 1
	cf = len(n) * 2 + len(d) * 1
	if ca > cf:
		print(60 * p)
	elif ca < cf:
		print(40 * p)
	else:
		print(55 * p)


for i in range(int(input())):
	chef = 0
	draw = 0
	carlsen = 0
	n = int(input())
	p = input()
	for j in range(14):
		if p[j] == 'C':
			carlsen += 2
		elif p[j] == 'N':
			chef += 2
		else:
			carlsen += 1
			chef += 1
	if carlsen > chef:
		print(60 * n)
	elif carlsen < chef:
		print(40 * n)
	else:
		print(55 * n)


T = int(input())
for i in range(T):
	n = int(input())
	C = 0
	Z = 0
	N = str(input())
	for i in range(len(N)):
		if N[i] == 'C':
			C += 2
		elif N[i] == 'N':
			Z += 2
		else:
			C += 1
			Z += 1
	if C == Z:
		print(55 * n)
	elif C > Z:
		print(60 * n)
	else:
		print(40 * n)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	a = s.count('C')
	b = s.count('N')
	if a > b:
		x = 60 * n
	elif b > a:
		x = 40 * n
	else:
		x = 55 * n
	print(x)


for i in range(0, int(input())):
	X = int(input())
	a = input()
	a = str(a)
	x = a.count('C')
	y = a.count('N')
	z = a.count('D')
	s = x * 2 + z * 1
	t = y * 2 + z * 1
	if s > t:
		print(60 * X)
	elif s == t:
		print(55 * X)
	elif s < t:
		print(40 * X)


T = int(input())
for i in range(T):
	X = int(input())
	results = input()
	pointsOfCarlsen = 0
	pointsOfChef = 0
	for i in results:
		if i == 'C':
			pointsOfCarlsen += 1
		if i == 'N':
			pointsOfChef += 1
	if pointsOfCarlsen > pointsOfChef:
		print(60 * X)
	elif pointsOfCarlsen < pointsOfChef:
		print(40 * X)
	else:
		print(55 * X)


t = int(input())
for i in range(t):
	x = int(input())
	S = str(input())
	winc = 0
	draw = 0
	winn = 0
	for i in range(14):
		if S[i] == 'C':
			winc = winc + 1
		elif S[i] == 'D':
			draw = draw + 1
		elif S[i] == 'N':
			winn = winn + 1
	carlsen_score = winc + 0.5 * draw
	chef_score = winn + 0.5 * draw
	if carlsen_score > chef_score:
		print(60 * x)
	elif carlsen_score == chef_score:
		print(55 * x)
	elif carlsen_score < chef_score:
		print(40 * x)


t = int(input())
for i in range(t):
	X = int(input())
	S = input()
	countC = S.count('C')
	countN = S.count('N')
	countD = S.count('D')
	chef = countN * 2 + countD
	carlsen = countC * 2 + countD
	if chef > carlsen:
		print(X * 40)
	elif carlsen > chef:
		print(X * 60)
	else:
		print(X * 55)


t = int(input())
for i in range(t):
	x = int(input())
	a = input()
	c = n = d = 0
	for j in a:
		if j == 'C':
			c += 1
		elif j == 'N':
			n += 1
		else:
			d += 1
	if c > n:
		print(60 * x)
	elif c < n:
		print(40 * x)
	else:
		print(55 * x)


n = int(input())
for i in range(n):
	a = int(input())
	m = input()
	carlsen = list(filter(lambda x: x == 'C', m))
	chef = list(filter(lambda x: x == 'N', m))
	draw = list(filter(lambda x: x == 'D', m))
	car_wins = len(carlsen) * 2 + len(draw)
	chef_wins = len(chef) * 2 + len(draw)
	if car_wins > chef_wins:
		car_money = 60 * a
		chef_money = 40 * a
		print(car_money)
	elif chef_wins > car_wins:
		chef_money = 60 * a
		car_money = 40 * a
		print(car_money)
	if car_wins == chef_wins:
		print(55 * a)


t = int(input())
for i in range(t):
	x = int(input())
	l = list(input())
	c = l.count('C')
	n = l.count('N')
	d = l.count('D')
	c = c + d
	n = n + d
	if c > n:
		print(60 * x)
	elif n > c:
		print(40 * x)
	else:
		print(55 * x)


for _ in range(int(input())):
	x = int(input())
	s = input()
	c = s.count('C')
	n = s.count('N')
	d = s.count('D')
	if c > n:
		print(60 * x)
	elif c < n:
		print(40 * x)
	else:
		print(55 * x)


from collections import Counter
T = int(input())
for _ in range(T):
	X = int(input())
	CND = input()
	CND_Counter = Counter(CND)
	(C, N, D) = (CND_Counter.get('C', 0), CND_Counter.get('N', 0), CND_Counter.get('D', 0))
	if C * 2 + D > D + N * 2:
		print(60 * X)
	elif D + C * 2 == D + N * 2:
		print(55 * X)
	else:
		print(40 * X)


t = int(input())
for i in range(t):
	x = int(input())
	S = input()
	c = 0
	n = 0
	for j in S:
		if j == 'D':
			c += 1
			n += 1
		elif j == 'C':
			c += 2
		else:
			n += 2
	if c == n:
		print(55 * x)
	elif c > n:
		print(60 * x)
	else:
		print(40 * x)


for i in range(int(input())):
	a = int(input())
	b = input()
	c = b.count('C')
	d = b.count('D')
	f = b.count('N')
	if c > f:
		print(60 * a)
	elif c < f:
		print(40 * a)
	else:
		print(55 * a)


for _ in range(int(input())):
	a = int(input())
	b = input()
	c = b.count('C')
	d = b.count('D')
	n = b.count('N')
	if c > n:
		print(60 * a)
	elif n > c:
		print(40 * a)
	else:
		print(55 * a)


for i in range(int(input())):
	i = int(input())
	s = input()
	c = 2 * s.count('C') + s.count('D')
	n = 2 * s.count('N') + s.count('D')
	if c > n:
		print(60 * i)
	elif c < n:
		print(40 * i)
	else:
		print(55 * i)


t = int(input())
for i in range(t):
	a = int(input())
	b = str(input())
	f = b.count('D')
	d = b.count('C') * 2 + f
	e = b.count('N') * 2 + f
	if d == e:
		print(55 * a)
	elif d > e:
		print(60 * a)
	else:
		print(40 * a)


for _ in range(int(input())):
	x = int(input())
	s = input()
	win_list = [s[i] for i in range(len(s))]
	c = 0
	n = 0
	for i in win_list:
		if i == 'C':
			c = c + 2
		elif i == 'N':
			n = n + 2
		else:
			c = c + 1
			n = n + 1
	if c == n:
		print(55 * x)
	elif c > n:
		print(60 * x)
	else:
		print(40 * x)


for _ in range(int(input())):
	x = int(input())
	result = input()
	car = 0
	chef = 0
	draw = 0
	for i in result:
		if i == 'C':
			car += 2
		elif i == 'N':
			chef += 2
		else:
			car += 1
			chef += 1
	if car == chef:
		print(55 * x)
	elif car > chef:
		print(60 * x)
	else:
		print(40 * x)


for i in range(int(input())):
	n = int(input())
	s = input()
	x = s.count('C')
	y = s.count('N')
	z = s.count('D')
	a = x * 2 + z
	b = y * 2 + z
	if a > b:
		print(60 * n)
	elif a < b:
		print(40 * n)
	else:
		print(55 * n)


test = int(input())
for i in range(test):
	number = int(input())
	List = list(input())
	C_count = List.count('C')
	N_count = List.count('N')
	D_count = List.count('D')
	c_score = C_count * 2 + D_count
	n_score = N_count * 2 + D_count
	if c_score > n_score:
		price = 60 * number
	elif c_score == n_score:
		price = 55 * number
	else:
		price = 40 * number
	print(price)


import math
t = int(input())
for i in range(t):
	x = int(input())
	cnd = input()
	for i in cnd:
		c1 = cnd.count('C')
		c2 = cnd.count('N')
		c3 = cnd.count('D')
	if c1 * 2 > c2 * 2:
		print(x * 60)
	elif c1 * 2 == c2 * 2:
		print(x * 55)
	else:
		print(x * 40)


T = int(input())
for i in range(T):
	X = int(input())
	S = input()
	Carlsen = 0
	Chef = 0
	for j in S:
		if j == 'C':
			Carlsen += 2
		elif j == 'N':
			Chef += 2
		else:
			Carlsen += 1
			Chef += 1
	if Carlsen > Chef:
		print(60 * X)
	elif Carlsen == Chef:
		print(55 * X)
	else:
		print(40 * X)


for i in range(int(input())):
	x = int(input())
	l = input()
	if l.count('C') > l.count('N'):
		print(60 * x)
	elif l.count('C') < l.count('N'):
		print(40 * x)
	else:
		print(55 * x)


t = int(input())
for i in range(t):
	x = int(input())
	y = list(map(str, input()))
	c = 0
	n = 0
	for i in y:
		if i == 'C':
			c += 2
		elif i == 'N':
			n += 2
		else:
			c += 1
			n += 1
	if c == n:
		print(55 * x)
	elif c < n:
		print(40 * x)
	else:
		print(60 * x)


t = int(input())
for i in range(t):
	x = int(input())
	p = input()
	lis = [x for x in p]
	c = 0
	n = 0
	for z in lis:
		if z == 'C':
			c += 2
		elif z == 'N':
			n += 2
		elif z == 'D':
			n += 1
			c += 1
	if c > n:
		print(60 * x)
	elif c < n:
		print(40 * x)
	else:
		print(55 * x)


try:
	t = int(input())
	for r in range(t):
		x = int(input())
		b = str(input())
		c = 0
		d = 0
		for a in b:
			if a == 'C':
				c += 1
			if a == 'N':
				d += 1
		if c == d:
			print(x * 55)
		elif c > d:
			print(x * 60)
		elif c < d:
			print(x * 40)
except:
	pass


a = int(input())
for i in range(a):
	lst = int(input())
	for j in range(a):
		lst2 = input()
		d = lst2.count('C')
		e = lst2.count('N')
		if e > d:
			print(lst * 40)
		elif d > e:
			print(lst * 60)
		else:
			print(lst * 55)
		break


for i in range(int(input())):
	prize = int(input())
	lis = input()
	(c_won, n_won) = (0, 0)
	for i in lis:
		if i == 'C':
			c_won += 1
		elif i == 'N':
			n_won += 1
	if c_won > n_won:
		print(60 * prize)
	elif c_won == n_won:
		print(55 * prize)
	else:
		print(40 * prize)


n = int(input())
for i in range(n):
	m = int(input())
	x = input()
	c = x.count('C') * 2 + x.count('D')
	chef = 28 - c
	if c > chef:
		print(m * 60)
	elif c < chef:
		print(m * 40)
	else:
		print(m * 55)


for i in range(int(input())):
	x = int(input())
	s = input()
	(c, n, d) = (s.count('C'), s.count('N'), s.count('D'))
	ts = c * 2 + n * 0 + d * 1
	tc = n * 2 + d * 1
	if ts > tc:
		print(x * 60)
	elif ts < tc:
		print(x * 40)
	else:
		print(x * 55)


T = int(input())
for i in range(T):
	X = int(input())
	results = input()
	carlsen_points = 0
	chef_points = 0
	for i in range(len(results)):
		if results[i] == 'C':
			carlsen_points += 2
		elif results[i] == 'N':
			chef_points += 2
		else:
			carlsen_points += 1
			chef_points += 1
	if carlsen_points > chef_points:
		print(60 * X)
	elif carlsen_points == chef_points:
		print(55 * X)
	else:
		print(40 * X)


T = int(input())
for tc in range(T):
	x = int(input())
	s = input()
	count_c = 0
	count_n = 0
	count_d = 0
	for i in s:
		if i == 'C':
			count_c += 1
		elif i == 'N':
			count_n += 1
		else:
			count_d += 1
	if count_c > count_n:
		print(60 * x)
	elif count_c < count_n:
		print(40 * x)
	else:
		print(55 * x)


for i in range(int(input())):
	c = d = n = 0
	x = int(input())
	l = input()
	for j in range(len(l)):
		if l[j] == 'C':
			c += 1
		elif l[j] == 'D':
			d += 1
		else:
			n += 1
	if c == n:
		print(int(x * 100 * 0.55))
	elif c > n:
		print(int(x * 100 * 0.6))
	elif n > c:
		print(int(x * 100 * 0.4))


import collections
for _ in range(int(input())):
	x = int(input())
	l = [i for i in input()]
	(c, d, n) = (0, 0, 0)
	for i in l:
		if i == 'C':
			c += 1
		elif i == 'D':
			d += 1
		else:
			n += 1
	if c == n:
		print(int(x * 100 * 0.55))
	elif c > n:
		print(int(x * 100 * 0.6))
	elif n > c:
		print(int(x * 100 * 0.4))


for _ in range(int(input())):
	a = int(input())
	b = list(input())
	c = 0
	d = 0
	n = 0
	for x in b:
		if x == 'C':
			c += 1
		elif x == 'D':
			d += 1
		else:
			n += 1
	if c == n:
		print(55 * a)
	elif c > n:
		print(60 * a)
	else:
		print(40 * a)


for _ in range(int(input())):
	x = int(input())
	s = input()
	d = s.count('D')
	c = s.count('C') * 2 + d
	n = s.count('N') * 2 + d
	chef_money = carl_money = 0
	if c > n:
		carl_money = 60 * x
		chef_money = 40 * x
	elif n > c:
		chef_money = 60 * x
		carl_money = 40 * x
	else:
		chef_money = 45 * x
		carl_money = 55 * x
	print(carl_money)


for i in range(int(input())):
	num = int(input())
	str = input()
	c = 0
	d = 0
	n = 0
	for i in str:
		if i == 'C':
			c = c + 1
		elif i == 'D':
			d = d + 1
		elif i == 'N':
			n = n + 1
	c1 = c * 2 + d
	n1 = n * 2 + d
	if c1 > n1:
		print(num * 60)
	elif c1 == n1:
		print(55 * num)
	elif c1 < n1:
		print(40 * num)


for i in range(int(input())):
	X = int(input())
	G = input()
	c = 0
	d = 0
	n = 0
	for i in G:
		if i == 'C':
			c += 1
		elif i == 'D':
			d += 1
		elif i == 'N':
			n += 1
	car = c * 2 + d * 1
	ch = n * 2 + d * 1
	if car > ch:
		print(60 * X)
	elif car == ch:
		print(55 * X)
	else:
		print(40 * X)


tc = int(input())
for _ in range(tc):
	x = int(input())
	a = input()
	Carlsen = 0
	Carl = 0
	for i in a:
		if i == 'C':
			Carlsen += 2
		elif i == 'D':
			Carl += 1
			Carlsen += 1
		else:
			Carl += 2
	if Carlsen > Carl:
		print(60 * x)
	elif Carlsen < Carl:
		print(40 * x)
	else:
		print(55 * x)


t = int(input())
for t in range(t):
	x = int(input())
	pz = 100 * x
	s = input()
	ct1 = s.count('C')
	ct2 = s.count('N')
	if ct1 > ct2:
		print(60 * x)
	elif ct2 > ct1:
		print(40 * x)
	elif ct1 == ct2:
		print(55 * x)


for _ in range(int(input())):
	x = int(input())
	string = input()
	if string.count('C') > string.count('N'):
		print(60 * x)
	elif string.count('C') < string.count('N'):
		print(40 * x)
	else:
		print(55 * x)


t = int(input())
for i in range(t):
	x = int(input()) * 100
	list_a = input()
	car = list_a.count('C')
	chef = list_a.count('N')
	if car > chef:
		prize = int(x * (60 / 100))
	elif car < chef:
		prize = int(x * (40 / 100))
	else:
		prize = int(x * (55 / 100))
	print(prize)


for i in range(int(input())):
	x = int(input())
	st = input()
	carl = st.count('C')
	chef = st.count('N')
	draw = st.count('D')
	if carl > chef:
		print(60 * x)
	if carl == chef:
		print(55 * x)
	if chef > carl:
		print(40 * x)


t = int(input())
while t > 0:
	x = int(input())
	s = input()
	s = s.upper()
	if s.count('C') > s.count('N'):
		print(60 * x)
	elif s.count('C') < s.count('N'):
		print(40 * x)
	else:
		print(55 * x)
	t -= 1


t = int(input())
for i in range(t):
	X = int(input())
	result_str = input()
	c = result_str.count('C')
	n = result_str.count('N')
	d = result_str.count('D')
	if c > n:
		print(60 * X)
	elif c < n:
		print(40 * X)
	else:
		print(55 * X)


t = int(input())
for i in range(t):
	x = int(input())
	s = input()
	carlsen = 0
	chef = 0
	for i in s:
		if i == 'C':
			carlsen += 2
		elif i == 'N':
			chef += 2
		else:
			carlsen += 1
			chef += 1
	if chef > carlsen:
		print(40 * x)
	elif chef < carlsen:
		print(60 * x)
	else:
		print(55 * x)


T = int(input())
for i in range(T):
	PrizePool = int(input())
	GameResult = input()
	Carlsen = 0
	Chef = 0
	Draw = 0
	for Result in GameResult:
		if Result == 'C':
			Carlsen += 2
		elif Result == 'N':
			Chef += 2
		else:
			Carlsen += 1
			Chef += 1
	print(55 * PrizePool if Carlsen == Chef else 60 * PrizePool if Carlsen > Chef else 40 * PrizePool)


for i in range(int(input())):
	x = int(input())
	s = input()
	c = 0
	n = 0
	d = 0
	for i in s:
		if i == 'C':
			c = c + 1
		elif i == 'D':
			d = d + 1
		else:
			n = n + 1
	if c > n:
		print(60 * x)
	elif n > c:
		print(40 * x)
	else:
		print(55 * x)


for _ in range(int(input())):
	x = int(input())
	y = input()
	c = y.count('C')
	d = y.count('D')
	n = y.count('N')
	chef_point_win = n * 2
	carlsen_point_win = c * 2
	drwa_point = d
	condition = [carlsen_point_win + drwa_point > chef_point_win + drwa_point]
	if all(condition):
		print(60 * x)
	elif carlsen_point_win + drwa_point == chef_point_win + drwa_point:
		print(55 * x)
	else:
		print(40 * x)