message stringlengths 2 67k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 463 109k | cluster float64 19 19 | __index_level_0__ int64 926 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Create a program that reads poker hand data and outputs the role for each. However, this issue follows the rules below.
* Poker is a competition with 5 playing cards.
* No more than 5 cards with the same number.
* There is no joker.
* Suppose you only consider the following poker roles: (The higher the number, the higher the role.)
1. No role (does not apply to any of the following)
2. One pair (two cards with the same number)
3. Two pairs (two pairs of cards with the same number)
4. Three cards (one set of three cards with the same number)
5. Straight (the numbers on 5 cards are consecutive)
However, in the case of a straight containing A, the sequence ending with A is also straight. In other words, there are two types of straights containing A: A 2 3 4 5 and 10 J Q K A. Lines that straddle A, such as J Q K A 2, are not straight. (In this case, it will be "no role").
6. Full House (one set of three cards with the same number and the other two cards with the same number)
7. Four Cards (one set of four cards with the same number)
Input
The input consists of multiple datasets. Each dataset is given in the following format:
Hand 1, Hand 2, Hand 3, Hand 4, Hand 5
In your hand, Trump's J (jack) is 11, Q (queen) is 12, K (king) is 13, A (ace) is 1, and the others are represented by their respective numbers.
The number of datasets does not exceed 50.
Output
For each dataset, output one of the highest roles you can play in your hand. Follow the output example for the notation of the role.
Example
Input
1,2,3,4,1
2,3,2,3,12
12,13,11,12,12
7,6,7,6,7
3,3,2,3,3
6,7,8,9,10
11,12,10,1,13
11,12,13,1,2
Output
one pair
two pair
three card
full house
four card
straight
straight
null
Submitted Solution:
```
from itertools import permutations
import sys
import os
def inini(_card):
for i in range(len(_card)):
_card[i] = 0
def main():
for s in sys.stdin:
card = 14*[0]
inini(card)
number = list(map(int,s.split(',')))
for v in number:
card[v] += 1
one_pair = 0
tree_card = 0
four_card = 0
flag = 0
for value in sorted(set(number),key=number.index):
if card[value] == 2:
one_pair += 1
elif card[value] == 3:
tree_card += 1
elif card[value] == 4:
four_card += 1
if one_pair == 1 and tree_card ==1:
print('full house')
flag = 777
elif one_pair == 1:
print('one pair')
flag = 777
elif one_pair == 2:
print('two pair')
flag = 777
elif tree_card == 1:
print('tree card')
flag = 777
elif four_card == 1:
print('four card')
flag = 777
straight = [[1,2,3,4,5],[2,3,4,5,6],[3,4,5,6,7],[4,5,6,7,8],[5,6,7,8,9],[6,7,8,9,10],[7,8,9,10,11],[8,9,10,11,12],[9,10,11,12,13],[10,11,12,13,1]]
for s_list in straight:
number.sort()
if number[0] == 1 and number[4] == 13:
number.append(1)
number.pop(0)
if number == s_list:
print('straight')
flag = 777
break
if flag == 0:
print('null')
if __name__ == '__main__':
main()
``` | instruction | 0 | 38,492 | 19 | 76,984 |
No | output | 1 | 38,492 | 19 | 76,985 |
Provide a correct Python 3 solution for this coding contest problem.
Your friend recently came up with a card game called UT-Rummy.
The cards used in this game are numbered red, green, or blue and any number from 1 to 9. Each player in this game has 9 cards in his or her hand, chooses one from his or her hand, discards it, and draws one from the deck instead. In this way, the turn is advanced in order, and the player who first makes three "sets" of three cards on hand wins. A set is a set of three cards of the same color, all having the same number or serial numbers. Patrol of numbers is not allowed for serial numbers. For example, 7, 8 and 9 are serial numbers, but 9, 1 and 2 are not.
Your friend has planned to sell this game as a computer game, and as part of that, he has asked you to make a judgment part of the victory conditions. Your job is to write a program that determines if your hand meets the winning conditions.
Input
The first line of input is given the number T (0 <T โค 50), which represents the number of datasets. This line is followed by T datasets.
Each dataset consists of two lines, the first line is given the number ni of the i-th (i = 1, 2, ..., 9) card, each separated by a space, and the second line is i. The letters ci representing the color of the second card are given, separated by spaces. The number ni on the card is an integer that satisfies 1 โค ni โค 9, and the color ci on the card is one of the letters "` R` "," `G`", and "` B` ", respectively.
No more than 5 cards with the same color and number will appear in one dataset.
Output
For each dataset, output "` 1` "if the winning conditions are met, otherwise output" `0`".
Example
Input
5
1 2 3 3 4 5 7 7 7
R R R R R R G G G
1 2 2 3 4 4 4 4 5
R R R R R R R R R
1 2 3 4 4 4 5 5 5
R R B R R R R R R
1 1 1 3 4 5 6 6 6
R R B G G G R R R
2 2 2 3 3 3 1 1 1
R G B R G B R G B
Output
1
0
0
0
1 | instruction | 0 | 38,524 | 19 | 77,048 |
"Correct Solution:
```
T = int(input())
for i in range(T):
num = list(map(int, input().split()))
coler = input().split()
groups = [[], [], []]
for i, c in enumerate(coler):
if c == "R":
groups[0].append(num[i])
elif c == "G":
groups[1].append(num[i])
else:
groups[2].append(num[i])
for group in groups:
while len(group) != 0 and len(group) % 3 == 0:
tmp = group[:]
group.sort()
i = group[0]
if group.count(i) >= 3:
for _ in range(3):
group.remove(i)
if i + 1 in group and i + 2 in group:
for j in range(3):
group.remove(i + j)
if tmp == group:
break
if len(groups[0]) == len(groups[1]) == len(groups[2]) == 0:
print(1)
else:
print(0)
``` | output | 1 | 38,524 | 19 | 77,049 |
Provide a correct Python 3 solution for this coding contest problem.
Your friend recently came up with a card game called UT-Rummy.
The cards used in this game are numbered red, green, or blue and any number from 1 to 9. Each player in this game has 9 cards in his or her hand, chooses one from his or her hand, discards it, and draws one from the deck instead. In this way, the turn is advanced in order, and the player who first makes three "sets" of three cards on hand wins. A set is a set of three cards of the same color, all having the same number or serial numbers. Patrol of numbers is not allowed for serial numbers. For example, 7, 8 and 9 are serial numbers, but 9, 1 and 2 are not.
Your friend has planned to sell this game as a computer game, and as part of that, he has asked you to make a judgment part of the victory conditions. Your job is to write a program that determines if your hand meets the winning conditions.
Input
The first line of input is given the number T (0 <T โค 50), which represents the number of datasets. This line is followed by T datasets.
Each dataset consists of two lines, the first line is given the number ni of the i-th (i = 1, 2, ..., 9) card, each separated by a space, and the second line is i. The letters ci representing the color of the second card are given, separated by spaces. The number ni on the card is an integer that satisfies 1 โค ni โค 9, and the color ci on the card is one of the letters "` R` "," `G`", and "` B` ", respectively.
No more than 5 cards with the same color and number will appear in one dataset.
Output
For each dataset, output "` 1` "if the winning conditions are met, otherwise output" `0`".
Example
Input
5
1 2 3 3 4 5 7 7 7
R R R R R R G G G
1 2 2 3 4 4 4 4 5
R R R R R R R R R
1 2 3 4 4 4 5 5 5
R R B R R R R R R
1 1 1 3 4 5 6 6 6
R R B G G G R R R
2 2 2 3 3 3 1 1 1
R G B R G B R G B
Output
1
0
0
0
1 | instruction | 0 | 38,525 | 19 | 77,050 |
"Correct Solution:
```
# your code goes here
#rummy
T=int(input())
for i in range(T):
n=[int(i) for i in input().split()]
c=[i for i in input().split()]
R=[[],[],[]]
for i in range(9):
if c[i]=="R":
R[0].append(n[i])
elif c[i]=="G":
R[1].append(n[i])
else:
R[2].append(n[i])
y=1
i=0
# print(R)
while y>0 and i<3:
l=len(R[i])
if l%3!=0:
y=0
else:
R[i].sort()
s=l//3
j=0
while y>0 and s>0 and j<len(R[i])-2:
if R[i][j]==R[i][j+1]:
if R[i][j+1]==R[i][j+2]:
for k in range(3):
R[i].pop(j)
s-=1
elif R[i][j+1]+1==R[i][j+2]:
k=j+3
while k<len(R[i]) and R[i][k]==R[i][j+2]:
k+=1
if k>=len(R[i]) or R[i][k]!=R[i][j+2]+1:
y=0
else:
R[i].pop(k)
R[i].pop(j+2)
R[i].pop(j)
s-=1
else:
y=0
elif R[i][j]+1==R[i][j+1]:
k=j+2
while k<len(R[i]) and R[i][k]==R[i][j+1]:
k+=1
if k>=len(R[i]) or R[i][k]!=R[i][j+1]+1:
y=0
else:
R[i].pop(k)
R[i].pop(j+1)
R[i].pop(j)
s-=1
else:
y=0
i+=1
print(y)
``` | output | 1 | 38,525 | 19 | 77,051 |
Provide a correct Python 3 solution for this coding contest problem.
Your friend recently came up with a card game called UT-Rummy.
The cards used in this game are numbered red, green, or blue and any number from 1 to 9. Each player in this game has 9 cards in his or her hand, chooses one from his or her hand, discards it, and draws one from the deck instead. In this way, the turn is advanced in order, and the player who first makes three "sets" of three cards on hand wins. A set is a set of three cards of the same color, all having the same number or serial numbers. Patrol of numbers is not allowed for serial numbers. For example, 7, 8 and 9 are serial numbers, but 9, 1 and 2 are not.
Your friend has planned to sell this game as a computer game, and as part of that, he has asked you to make a judgment part of the victory conditions. Your job is to write a program that determines if your hand meets the winning conditions.
Input
The first line of input is given the number T (0 <T โค 50), which represents the number of datasets. This line is followed by T datasets.
Each dataset consists of two lines, the first line is given the number ni of the i-th (i = 1, 2, ..., 9) card, each separated by a space, and the second line is i. The letters ci representing the color of the second card are given, separated by spaces. The number ni on the card is an integer that satisfies 1 โค ni โค 9, and the color ci on the card is one of the letters "` R` "," `G`", and "` B` ", respectively.
No more than 5 cards with the same color and number will appear in one dataset.
Output
For each dataset, output "` 1` "if the winning conditions are met, otherwise output" `0`".
Example
Input
5
1 2 3 3 4 5 7 7 7
R R R R R R G G G
1 2 2 3 4 4 4 4 5
R R R R R R R R R
1 2 3 4 4 4 5 5 5
R R B R R R R R R
1 1 1 3 4 5 6 6 6
R R B G G G R R R
2 2 2 3 3 3 1 1 1
R G B R G B R G B
Output
1
0
0
0
1 | instruction | 0 | 38,526 | 19 | 77,052 |
"Correct Solution:
```
#!usr/bin/env python3
import sys
def main():
WINNING_HANDS = [
'111', '222', '333', '444', '555', '666', '777', '888', '999',
'123', '234', '345', '456', '567', '678', '789'
]
num_of_datasets = int(sys.stdin.readline().strip('\n'))
datasets = [{'R': [], 'G': [], 'B': []} for _ in range(num_of_datasets)]
results = list()
for dataset in range(num_of_datasets):
n_set = [num for num in sys.stdin.readline().strip('\n').split()]
c_set = [colour for colour in sys.stdin.readline().strip('\n').split()]
for idx, colour in enumerate(c_set):
if colour == 'R':
datasets[dataset]['R'].append(n_set[idx])
elif colour == 'G':
datasets[dataset]['G'].append(n_set[idx])
elif colour == 'B':
datasets[dataset]['B'].append(n_set[idx])
match_count = int()
for rgb_key in datasets[dataset]:
if len(datasets[dataset][rgb_key]) > 1:
nums = sorted(datasets[dataset][rgb_key])
else:
continue
for hand in WINNING_HANDS:
while hand[0] in nums and hand[1] in nums and hand[2] in nums:
tmp = nums.copy()
if hand[0] in tmp:
tmp.pop(tmp.index(hand[0]))
if hand[1] in tmp:
tmp.pop(tmp.index(hand[1]))
if hand[2] in tmp:
tmp.pop(tmp.index(hand[2]))
match_count += 1
nums = tmp
else:
break
else:
break
else:
break
if match_count == 3:
results.append(1)
break
if dataset < num_of_datasets and match_count != 3:
results.append(0)
for result in results:
print(result)
if __name__ == '__main__':
main()
``` | output | 1 | 38,526 | 19 | 77,053 |
Provide a correct Python 3 solution for this coding contest problem.
Your friend recently came up with a card game called UT-Rummy.
The cards used in this game are numbered red, green, or blue and any number from 1 to 9. Each player in this game has 9 cards in his or her hand, chooses one from his or her hand, discards it, and draws one from the deck instead. In this way, the turn is advanced in order, and the player who first makes three "sets" of three cards on hand wins. A set is a set of three cards of the same color, all having the same number or serial numbers. Patrol of numbers is not allowed for serial numbers. For example, 7, 8 and 9 are serial numbers, but 9, 1 and 2 are not.
Your friend has planned to sell this game as a computer game, and as part of that, he has asked you to make a judgment part of the victory conditions. Your job is to write a program that determines if your hand meets the winning conditions.
Input
The first line of input is given the number T (0 <T โค 50), which represents the number of datasets. This line is followed by T datasets.
Each dataset consists of two lines, the first line is given the number ni of the i-th (i = 1, 2, ..., 9) card, each separated by a space, and the second line is i. The letters ci representing the color of the second card are given, separated by spaces. The number ni on the card is an integer that satisfies 1 โค ni โค 9, and the color ci on the card is one of the letters "` R` "," `G`", and "` B` ", respectively.
No more than 5 cards with the same color and number will appear in one dataset.
Output
For each dataset, output "` 1` "if the winning conditions are met, otherwise output" `0`".
Example
Input
5
1 2 3 3 4 5 7 7 7
R R R R R R G G G
1 2 2 3 4 4 4 4 5
R R R R R R R R R
1 2 3 4 4 4 5 5 5
R R B R R R R R R
1 1 1 3 4 5 6 6 6
R R B G G G R R R
2 2 2 3 3 3 1 1 1
R G B R G B R G B
Output
1
0
0
0
1 | instruction | 0 | 38,527 | 19 | 77,054 |
"Correct Solution:
```
#!usr/bin/env python3
import sys
def main():
WINNING_HANDS = [
'111', '222', '333', '444', '555', '666', '777', '888', '999',
'123', '234', '345', '456', '567', '678', '789'
]
num_of_datasets = int(sys.stdin.readline().strip('\n'))
datasets = [{'R': [], 'G': [], 'B': []} for _ in range(num_of_datasets)]
results = list()
for dataset in range(num_of_datasets):
n_set = [num for num in sys.stdin.readline().strip('\n').split()]
c_set = [colour for colour in sys.stdin.readline().strip('\n').split()]
for idx, colour in enumerate(c_set):
if colour == 'R':
datasets[dataset]['R'].append(n_set[idx])
elif colour == 'G':
datasets[dataset]['G'].append(n_set[idx])
elif colour == 'B':
datasets[dataset]['B'].append(n_set[idx])
match_count = int()
for rgb_key in datasets[dataset]:
nums = sorted(datasets[dataset][rgb_key])
for hand in WINNING_HANDS:
while hand[0] in nums and hand[1] in nums and hand[2] in nums:
tmp = nums.copy()
if hand[0] in tmp:
tmp.pop(tmp.index(hand[0]))
if hand[1] in tmp:
tmp.pop(tmp.index(hand[1]))
if hand[2] in tmp:
tmp.pop(tmp.index(hand[2]))
match_count += 1
nums = tmp
else:
break
else:
break
else:
break
if match_count == 3:
results.append(1)
break
if dataset < num_of_datasets and match_count != 3:
results.append(0)
for result in results:
print(result)
if __name__ == '__main__':
main()
``` | output | 1 | 38,527 | 19 | 77,055 |
Provide a correct Python 3 solution for this coding contest problem.
Your friend recently came up with a card game called UT-Rummy.
The cards used in this game are numbered red, green, or blue and any number from 1 to 9. Each player in this game has 9 cards in his or her hand, chooses one from his or her hand, discards it, and draws one from the deck instead. In this way, the turn is advanced in order, and the player who first makes three "sets" of three cards on hand wins. A set is a set of three cards of the same color, all having the same number or serial numbers. Patrol of numbers is not allowed for serial numbers. For example, 7, 8 and 9 are serial numbers, but 9, 1 and 2 are not.
Your friend has planned to sell this game as a computer game, and as part of that, he has asked you to make a judgment part of the victory conditions. Your job is to write a program that determines if your hand meets the winning conditions.
Input
The first line of input is given the number T (0 <T โค 50), which represents the number of datasets. This line is followed by T datasets.
Each dataset consists of two lines, the first line is given the number ni of the i-th (i = 1, 2, ..., 9) card, each separated by a space, and the second line is i. The letters ci representing the color of the second card are given, separated by spaces. The number ni on the card is an integer that satisfies 1 โค ni โค 9, and the color ci on the card is one of the letters "` R` "," `G`", and "` B` ", respectively.
No more than 5 cards with the same color and number will appear in one dataset.
Output
For each dataset, output "` 1` "if the winning conditions are met, otherwise output" `0`".
Example
Input
5
1 2 3 3 4 5 7 7 7
R R R R R R G G G
1 2 2 3 4 4 4 4 5
R R R R R R R R R
1 2 3 4 4 4 5 5 5
R R B R R R R R R
1 1 1 3 4 5 6 6 6
R R B G G G R R R
2 2 2 3 3 3 1 1 1
R G B R G B R G B
Output
1
0
0
0
1 | instruction | 0 | 38,528 | 19 | 77,056 |
"Correct Solution:
```
n = int(input())
def check(nl):
fl = list(nl)
for w in range(len(nl)):
if (fl[w] in nl):
i = fl[w]
if ((i+1 in nl) and (i+2 in nl)):
for k in range(i,i+3):
nl.remove(k)
elif(nl.count(i)%3 == 0):
for k in range(nl.count(i)):
nl.remove(i)
for i in range(n):
num_list = list(map(int, input().split()))
c_list = list(map(str, input().split()))
r = c_list.count('R')
g = c_list.count('G')
b = c_list.count('B')
if (r%3 == 0 and g % 3 == 0 and b % 3 == 0):
rlist = []
glist = []
blist = []
for k in range(9):
if(c_list[k] == 'R'):
rlist.append(num_list[k])
elif(c_list[k] == 'G'):
glist.append(num_list[k])
elif(c_list[k] == 'B'):
blist.append(num_list[k])
rlist.sort()
glist.sort()
blist.sort()
check(rlist)
check(glist)
check(blist)
if(len(rlist) == 0 and len(glist) == 0 and len(blist) == 0):
print(1)
else:
print(0)
else:
print(0)
``` | output | 1 | 38,528 | 19 | 77,057 |
Provide a correct Python 3 solution for this coding contest problem.
Your friend recently came up with a card game called UT-Rummy.
The cards used in this game are numbered red, green, or blue and any number from 1 to 9. Each player in this game has 9 cards in his or her hand, chooses one from his or her hand, discards it, and draws one from the deck instead. In this way, the turn is advanced in order, and the player who first makes three "sets" of three cards on hand wins. A set is a set of three cards of the same color, all having the same number or serial numbers. Patrol of numbers is not allowed for serial numbers. For example, 7, 8 and 9 are serial numbers, but 9, 1 and 2 are not.
Your friend has planned to sell this game as a computer game, and as part of that, he has asked you to make a judgment part of the victory conditions. Your job is to write a program that determines if your hand meets the winning conditions.
Input
The first line of input is given the number T (0 <T โค 50), which represents the number of datasets. This line is followed by T datasets.
Each dataset consists of two lines, the first line is given the number ni of the i-th (i = 1, 2, ..., 9) card, each separated by a space, and the second line is i. The letters ci representing the color of the second card are given, separated by spaces. The number ni on the card is an integer that satisfies 1 โค ni โค 9, and the color ci on the card is one of the letters "` R` "," `G`", and "` B` ", respectively.
No more than 5 cards with the same color and number will appear in one dataset.
Output
For each dataset, output "` 1` "if the winning conditions are met, otherwise output" `0`".
Example
Input
5
1 2 3 3 4 5 7 7 7
R R R R R R G G G
1 2 2 3 4 4 4 4 5
R R R R R R R R R
1 2 3 4 4 4 5 5 5
R R B R R R R R R
1 1 1 3 4 5 6 6 6
R R B G G G R R R
2 2 2 3 3 3 1 1 1
R G B R G B R G B
Output
1
0
0
0
1 | instruction | 0 | 38,529 | 19 | 77,058 |
"Correct Solution:
```
R1 = [("R1","R2","R3"),("R2","R3","R4"),("R3","R4","R5"),("R4","R5","R6"),("R5","R6","R7"),("R6","R7","R8"),("R7","R8","R9")]
R2 = ["R1","R2","R3","R4","R5","R6","R7","R8","R9"]
G1 = [("G1","G2","G3"),("G2","G3","G4"),("G3","G4","G5"),("G4","G5","G6"),("G5","G6","G7"),("G6","G7","G8"),("G7","G8","G9")]
G2 = ["G1","G2","G3","G4","G5","G6","G7","G8","G9"]
B1 = [("B1","B2","B3"),("B2","B3","B4"),("B3","B4","B5"),("B4","B5","B6"),("B5","B6","B7"),("B6","B7","B8"),("B7","B8","B9")]
B2 = ["B1","B2","B3","B4","B5","B6","B7","B8","B9"]
def Rummy(C:list,N:list):
#RGBใฎๆฐใ3ใฎๅๆฐใง็กใๅ ดๅใ่ฒ ใ
if C.count("R") % 3 != 0 or C.count("G") % 3 != 0 or C.count("B") % 3 != 0:
print("0")
return
ans = []
for x,y in zip(C,N):
tmp = x + str(y)
ans.append(tmp)
REN = R1+G1+B1
DOU = R2+G2+B2
#ๅ็ชๆค็ดข
for z in DOU:
if ans.count(z) >= 3:
ans.remove(z)
ans.remove(z)
ans.remove(z)
#้ฃ็ชๆค็ดข
for j in REN:
while True:
if all(x in ans for x in j):
for k in j:
ans.remove(k)
else:
break
if len(ans) == 0:
print("1")
else:
print("0")
if __name__ == '__main__':
n = int(input())
for _ in range(n):
N = list(map(int,input().split()))
C = input().split()
Rummy(C,N)
``` | output | 1 | 38,529 | 19 | 77,059 |
Provide a correct Python 3 solution for this coding contest problem.
Your friend recently came up with a card game called UT-Rummy.
The cards used in this game are numbered red, green, or blue and any number from 1 to 9. Each player in this game has 9 cards in his or her hand, chooses one from his or her hand, discards it, and draws one from the deck instead. In this way, the turn is advanced in order, and the player who first makes three "sets" of three cards on hand wins. A set is a set of three cards of the same color, all having the same number or serial numbers. Patrol of numbers is not allowed for serial numbers. For example, 7, 8 and 9 are serial numbers, but 9, 1 and 2 are not.
Your friend has planned to sell this game as a computer game, and as part of that, he has asked you to make a judgment part of the victory conditions. Your job is to write a program that determines if your hand meets the winning conditions.
Input
The first line of input is given the number T (0 <T โค 50), which represents the number of datasets. This line is followed by T datasets.
Each dataset consists of two lines, the first line is given the number ni of the i-th (i = 1, 2, ..., 9) card, each separated by a space, and the second line is i. The letters ci representing the color of the second card are given, separated by spaces. The number ni on the card is an integer that satisfies 1 โค ni โค 9, and the color ci on the card is one of the letters "` R` "," `G`", and "` B` ", respectively.
No more than 5 cards with the same color and number will appear in one dataset.
Output
For each dataset, output "` 1` "if the winning conditions are met, otherwise output" `0`".
Example
Input
5
1 2 3 3 4 5 7 7 7
R R R R R R G G G
1 2 2 3 4 4 4 4 5
R R R R R R R R R
1 2 3 4 4 4 5 5 5
R R B R R R R R R
1 1 1 3 4 5 6 6 6
R R B G G G R R R
2 2 2 3 3 3 1 1 1
R G B R G B R G B
Output
1
0
0
0
1 | instruction | 0 | 38,530 | 19 | 77,060 |
"Correct Solution:
```
def Check(A) :
Set = 0
if len(A) < 3 :
return False
else :
a = 0
while True :
if a >= len(A)-2 :
break
if A[a] == A[a+1] and A[a] == A[a+2] :
Set += 1
youso = A[a]
A.remove(youso)
A.remove(youso)
A.remove(youso)
a = 0
elif A[a]+1 in A and A[a]+2 in A :
Set += 1
youso = A[a]
A.remove(youso)
A.remove(youso+1)
A.remove(youso+2)
a = 0
else :
a += 1
return Set
n = int(input())
for i in range(n) :
card = list([0, "X"] for i in range(9))
R = []
G = []
B = []
tmp = list(map(int,input().split()))
for j in range(9) :
card[j][0] = tmp[j]
tmp = list(input().split())
for j in range(9) :
card[j][1] = tmp[j]
if tmp[j] == "R" :
R.append(card[j][0])
elif tmp[j] == "G" :
G.append(card[j][0])
else :
B.append(card[j][0])
R.sort()
G.sort()
B.sort()
if Check(R) + Check(G) + Check(B) == 3 :
print(1)
else :
print(0)
``` | output | 1 | 38,530 | 19 | 77,061 |
Provide a correct Python 3 solution for this coding contest problem.
Your friend recently came up with a card game called UT-Rummy.
The cards used in this game are numbered red, green, or blue and any number from 1 to 9. Each player in this game has 9 cards in his or her hand, chooses one from his or her hand, discards it, and draws one from the deck instead. In this way, the turn is advanced in order, and the player who first makes three "sets" of three cards on hand wins. A set is a set of three cards of the same color, all having the same number or serial numbers. Patrol of numbers is not allowed for serial numbers. For example, 7, 8 and 9 are serial numbers, but 9, 1 and 2 are not.
Your friend has planned to sell this game as a computer game, and as part of that, he has asked you to make a judgment part of the victory conditions. Your job is to write a program that determines if your hand meets the winning conditions.
Input
The first line of input is given the number T (0 <T โค 50), which represents the number of datasets. This line is followed by T datasets.
Each dataset consists of two lines, the first line is given the number ni of the i-th (i = 1, 2, ..., 9) card, each separated by a space, and the second line is i. The letters ci representing the color of the second card are given, separated by spaces. The number ni on the card is an integer that satisfies 1 โค ni โค 9, and the color ci on the card is one of the letters "` R` "," `G`", and "` B` ", respectively.
No more than 5 cards with the same color and number will appear in one dataset.
Output
For each dataset, output "` 1` "if the winning conditions are met, otherwise output" `0`".
Example
Input
5
1 2 3 3 4 5 7 7 7
R R R R R R G G G
1 2 2 3 4 4 4 4 5
R R R R R R R R R
1 2 3 4 4 4 5 5 5
R R B R R R R R R
1 1 1 3 4 5 6 6 6
R R B G G G R R R
2 2 2 3 3 3 1 1 1
R G B R G B R G B
Output
1
0
0
0
1 | instruction | 0 | 38,531 | 19 | 77,062 |
"Correct Solution:
```
for _ in range(int(input())):
n, c = map(int, input().split()), input().split()
c = list(zip(c, n))
c.sort(key = lambda x:x[1])
c.sort(key = lambda x:x[0])
while c != []:
if c[-1] == c[-2] == c[-3]:
c = c[:-3]
elif (c[-1][0], c[-1][1] -1) in c and (c[-1][0], c[-1][1] -2) in c :
c.remove((c[-1][0], c[-1][1] -1))
c.remove((c[-1][0], c[-1][1] -2))
c.pop()
else:print(0);break
else:print(1)
``` | output | 1 | 38,531 | 19 | 77,063 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Your friend recently came up with a card game called UT-Rummy.
The cards used in this game are numbered red, green, or blue and any number from 1 to 9. Each player in this game has 9 cards in his or her hand, chooses one from his or her hand, discards it, and draws one from the deck instead. In this way, the turn is advanced in order, and the player who first makes three "sets" of three cards on hand wins. A set is a set of three cards of the same color, all having the same number or serial numbers. Patrol of numbers is not allowed for serial numbers. For example, 7, 8 and 9 are serial numbers, but 9, 1 and 2 are not.
Your friend has planned to sell this game as a computer game, and as part of that, he has asked you to make a judgment part of the victory conditions. Your job is to write a program that determines if your hand meets the winning conditions.
Input
The first line of input is given the number T (0 <T โค 50), which represents the number of datasets. This line is followed by T datasets.
Each dataset consists of two lines, the first line is given the number ni of the i-th (i = 1, 2, ..., 9) card, each separated by a space, and the second line is i. The letters ci representing the color of the second card are given, separated by spaces. The number ni on the card is an integer that satisfies 1 โค ni โค 9, and the color ci on the card is one of the letters "` R` "," `G`", and "` B` ", respectively.
No more than 5 cards with the same color and number will appear in one dataset.
Output
For each dataset, output "` 1` "if the winning conditions are met, otherwise output" `0`".
Example
Input
5
1 2 3 3 4 5 7 7 7
R R R R R R G G G
1 2 2 3 4 4 4 4 5
R R R R R R R R R
1 2 3 4 4 4 5 5 5
R R B R R R R R R
1 1 1 3 4 5 6 6 6
R R B G G G R R R
2 2 2 3 3 3 1 1 1
R G B R G B R G B
Output
1
0
0
0
1
Submitted Solution:
```
#!usr/bin/env python3
import sys
def main():
WINNING_HANDS = [
'111', '222', '333', '444', '555', '666', '777', '888', '999',
'123', '234', '345', '456', '567', '678', '789'
]
num_of_datasets = int(sys.stdin.readline().strip('\n'))
datasets = [{'R': [], 'G': [], 'B': []} for _ in range(num_of_datasets)]
results = list()
for dataset in range(num_of_datasets):
n_set = [num for num in sys.stdin.readline().strip('\n').split()]
c_set = [colour for colour in sys.stdin.readline().strip('\n').split()]
for idx, colour in enumerate(c_set):
if colour == 'R':
datasets[dataset]['R'].append(n_set[idx])
elif colour == 'G':
datasets[dataset]['G'].append(n_set[idx])
elif colour == 'B':
datasets[dataset]['B'].append(n_set[idx])
match_count = int()
for rgb_key in datasets[dataset]:
nums = sorted(datasets[dataset][rgb_key])
for hand in WINNING_HANDS:
while hand[0] in nums and hand[1] in nums and hand[2] in nums:
tmp = nums.copy()
if hand[0] in tmp:
tmp.pop(tmp.index(hand[0]))
if hand[1] in tmp:
tmp.pop(tmp.index(hand[1]))
if hand[2] in tmp:
tmp.pop(tmp.index(hand[2]))
match_count += 1
nums = tmp
else:
break
else:
break
else:
break
if match_count == 3:
results.append(1)
continue
if dataset < num_of_datasets and match_count != 3:
results.append(0)
for result in results:
print(result)
if __name__ == '__main__':
main()
``` | instruction | 0 | 38,532 | 19 | 77,064 |
Yes | output | 1 | 38,532 | 19 | 77,065 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Your friend recently came up with a card game called UT-Rummy.
The cards used in this game are numbered red, green, or blue and any number from 1 to 9. Each player in this game has 9 cards in his or her hand, chooses one from his or her hand, discards it, and draws one from the deck instead. In this way, the turn is advanced in order, and the player who first makes three "sets" of three cards on hand wins. A set is a set of three cards of the same color, all having the same number or serial numbers. Patrol of numbers is not allowed for serial numbers. For example, 7, 8 and 9 are serial numbers, but 9, 1 and 2 are not.
Your friend has planned to sell this game as a computer game, and as part of that, he has asked you to make a judgment part of the victory conditions. Your job is to write a program that determines if your hand meets the winning conditions.
Input
The first line of input is given the number T (0 <T โค 50), which represents the number of datasets. This line is followed by T datasets.
Each dataset consists of two lines, the first line is given the number ni of the i-th (i = 1, 2, ..., 9) card, each separated by a space, and the second line is i. The letters ci representing the color of the second card are given, separated by spaces. The number ni on the card is an integer that satisfies 1 โค ni โค 9, and the color ci on the card is one of the letters "` R` "," `G`", and "` B` ", respectively.
No more than 5 cards with the same color and number will appear in one dataset.
Output
For each dataset, output "` 1` "if the winning conditions are met, otherwise output" `0`".
Example
Input
5
1 2 3 3 4 5 7 7 7
R R R R R R G G G
1 2 2 3 4 4 4 4 5
R R R R R R R R R
1 2 3 4 4 4 5 5 5
R R B R R R R R R
1 1 1 3 4 5 6 6 6
R R B G G G R R R
2 2 2 3 3 3 1 1 1
R G B R G B R G B
Output
1
0
0
0
1
Submitted Solution:
```
def judge(nums):
if nums == []:
return True
ret = False
m = nums[0]
if nums.count(m) == 3:
ret = ret or judge(nums[3:])
if m in nums and m + 1 in nums and m + 2 in nums:
new_nums = nums[:]
new_nums.remove(m)
new_nums.remove(m + 1)
new_nums.remove(m + 2)
ret = ret or judge(new_nums)
return ret
n = int(input())
for _ in range(n):
nums = list(map(int, input().split()))
colors = input().split()
dic = {"R":[], "G":[], "B":[]}
for num, color in zip(nums, colors):
dic[color].append(num)
ans = judge(sorted(dic["R"])) and judge(sorted(dic["G"])) and judge(sorted(dic["B"]))
print(int(ans))
``` | instruction | 0 | 38,533 | 19 | 77,066 |
Yes | output | 1 | 38,533 | 19 | 77,067 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Your friend recently came up with a card game called UT-Rummy.
The cards used in this game are numbered red, green, or blue and any number from 1 to 9. Each player in this game has 9 cards in his or her hand, chooses one from his or her hand, discards it, and draws one from the deck instead. In this way, the turn is advanced in order, and the player who first makes three "sets" of three cards on hand wins. A set is a set of three cards of the same color, all having the same number or serial numbers. Patrol of numbers is not allowed for serial numbers. For example, 7, 8 and 9 are serial numbers, but 9, 1 and 2 are not.
Your friend has planned to sell this game as a computer game, and as part of that, he has asked you to make a judgment part of the victory conditions. Your job is to write a program that determines if your hand meets the winning conditions.
Input
The first line of input is given the number T (0 <T โค 50), which represents the number of datasets. This line is followed by T datasets.
Each dataset consists of two lines, the first line is given the number ni of the i-th (i = 1, 2, ..., 9) card, each separated by a space, and the second line is i. The letters ci representing the color of the second card are given, separated by spaces. The number ni on the card is an integer that satisfies 1 โค ni โค 9, and the color ci on the card is one of the letters "` R` "," `G`", and "` B` ", respectively.
No more than 5 cards with the same color and number will appear in one dataset.
Output
For each dataset, output "` 1` "if the winning conditions are met, otherwise output" `0`".
Example
Input
5
1 2 3 3 4 5 7 7 7
R R R R R R G G G
1 2 2 3 4 4 4 4 5
R R R R R R R R R
1 2 3 4 4 4 5 5 5
R R B R R R R R R
1 1 1 3 4 5 6 6 6
R R B G G G R R R
2 2 2 3 3 3 1 1 1
R G B R G B R G B
Output
1
0
0
0
1
Submitted Solution:
```
T=int(input())
for i in range(T):
n=[int(i) for i in input().split()]
c=[i for i in input().split()]
R=[[],[],[]]
for i in range(9):
if c[i]=="R":
R[0].append(n[i])
elif c[i]=="G":
R[1].append(n[i])
else:
R[2].append(n[i])
y=1
i=0
# print(R)
while y>0 and i<3:
l=len(R[i])
if l%3!=0:
y=0
else:
R[i].sort()
s=l//3
j=0
while y>0 and s>0 and j<len(R[i])-2:
if R[i][j]==R[i][j+1]:
if R[i][j+1]==R[i][j+2]:
for k in range(3):
R[i].pop(j)
s-=1
elif R[i][j+1]+1==R[i][j+2]:
k=j+3
while k<len(R[i]) and R[i][k]==R[i][j+2]:
k+=1
if k>=len(R[i]) or R[i][k]!=R[i][j+2]+1:
y=0
else:
R[i].pop(k)
R[i].pop(j+2)
R[i].pop(j)
s-=1
else:
y=0
elif R[i][j]+1==R[i][j+1]:
k=j+2
while k<len(R[i]) and R[i][k]==R[i][j+1]:
k+=1
if k>=len(R[i]) or R[i][k]!=R[i][j+1]+1:
y=0
else:
R[i].pop(k)
R[i].pop(j+1)
R[i].pop(j)
s-=1
else:
y=0
i+=1
print(y)
``` | instruction | 0 | 38,534 | 19 | 77,068 |
Yes | output | 1 | 38,534 | 19 | 77,069 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Your friend recently came up with a card game called UT-Rummy.
The cards used in this game are numbered red, green, or blue and any number from 1 to 9. Each player in this game has 9 cards in his or her hand, chooses one from his or her hand, discards it, and draws one from the deck instead. In this way, the turn is advanced in order, and the player who first makes three "sets" of three cards on hand wins. A set is a set of three cards of the same color, all having the same number or serial numbers. Patrol of numbers is not allowed for serial numbers. For example, 7, 8 and 9 are serial numbers, but 9, 1 and 2 are not.
Your friend has planned to sell this game as a computer game, and as part of that, he has asked you to make a judgment part of the victory conditions. Your job is to write a program that determines if your hand meets the winning conditions.
Input
The first line of input is given the number T (0 <T โค 50), which represents the number of datasets. This line is followed by T datasets.
Each dataset consists of two lines, the first line is given the number ni of the i-th (i = 1, 2, ..., 9) card, each separated by a space, and the second line is i. The letters ci representing the color of the second card are given, separated by spaces. The number ni on the card is an integer that satisfies 1 โค ni โค 9, and the color ci on the card is one of the letters "` R` "," `G`", and "` B` ", respectively.
No more than 5 cards with the same color and number will appear in one dataset.
Output
For each dataset, output "` 1` "if the winning conditions are met, otherwise output" `0`".
Example
Input
5
1 2 3 3 4 5 7 7 7
R R R R R R G G G
1 2 2 3 4 4 4 4 5
R R R R R R R R R
1 2 3 4 4 4 5 5 5
R R B R R R R R R
1 1 1 3 4 5 6 6 6
R R B G G G R R R
2 2 2 3 3 3 1 1 1
R G B R G B R G B
Output
1
0
0
0
1
Submitted Solution:
```
T = int(input())
for i in range(T):
n = [int(i) for i in input().split()]
c = [i for i in input().split()]
value = [[],[],[]]
for j in range(9):
if c[j] == "R":
value[0].append(n[j])
elif c[j] == "G":
value[1].append(n[j])
else:
value[2].append(n[j])
ans = 1
for i in range(3):
l = len(value[i])
if l%3 != 0:#RGBใฎ้ทใใ3ใฎๅๆฐใงใชใใจใๆญฃ่งฃใซใชใๅฏ่ฝๆงใฏใชใ
ans = 0
else:
value[i].sort()
s = l//3
j=0
while ans>0 and s>0 and j<len(value[i])-2:
if value[i][j] == value[i][j+1]:#้ฃใๅใๆฐๅญใไธ่ดใใฆใใๅ ดๅ
if value[i][j+1] == value[i][j+2]:#3้ฃ็ถใงๅใๆฐๅญใไธฆใใงใใๅ ดๅ
for k in range(3):
value[i].pop(j)#ๅคใฎๅ้ค
s-=1
elif value[i][j+1]+1==value[i][j+2]:#2ใคใใฎๆฐๅญใจ3ใค็ฎใฎๆฐๅญใ้ฃ็ชใex)112,223,334,
k=j+3
while k<len(value[i]) and value[i][k]==value[i][j+2]:#3ใคใใจ4ใคใใฎๅคใๅใ
k+=1
if k>=len(value[i]) or value[i][k]!=value[i][j+2]+1:#4ใค็ฎใจ5ใค็ฎใฎๆฐๅญใ้ฃ็ชใงใชใๅ ดๅ ex)11225,22335ใไธๆญฃ่งฃ
ans=0
else:
#ๅคๅ้ค
value[i].pop(k)
value[i].pop(j+2)
value[i].pop(j)
s-=1
else:#3ใค็ฎใฎๆฐๅญใๅ
จ็ถ้ใใใค
ans=0
elif value[i][j]+1==value[i][j+1]:#้ฃใๅใๆฐๅญใ้ฃ็ชใฎๅ ดๅ
k=j+2
while k<len(value[i]) and value[i][k]==value[i][j+1]:
k+=1
if k>=len(value[i]) or value[i][k]!=value[i][j+1]+1:#3ใคใใฎๆฐๅญใ้ฃ็ชใงใชใๅ ดๅใไธๆญฃ่งฃ
ans=0
else:
#ๅคๅ้ค
value[i].pop(k)
value[i].pop(j+1)
value[i].pop(j)
s-=1
else:#้ฃใๅใๆฐๅญใ้ฃ็ชใงใใชใใๅๅคใงใใชใๅ ดๅใไธๆญฃ่งฃ
ans=0
i+=1
print(ans)
``` | instruction | 0 | 38,535 | 19 | 77,070 |
Yes | output | 1 | 38,535 | 19 | 77,071 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Your friend recently came up with a card game called UT-Rummy.
The cards used in this game are numbered red, green, or blue and any number from 1 to 9. Each player in this game has 9 cards in his or her hand, chooses one from his or her hand, discards it, and draws one from the deck instead. In this way, the turn is advanced in order, and the player who first makes three "sets" of three cards on hand wins. A set is a set of three cards of the same color, all having the same number or serial numbers. Patrol of numbers is not allowed for serial numbers. For example, 7, 8 and 9 are serial numbers, but 9, 1 and 2 are not.
Your friend has planned to sell this game as a computer game, and as part of that, he has asked you to make a judgment part of the victory conditions. Your job is to write a program that determines if your hand meets the winning conditions.
Input
The first line of input is given the number T (0 <T โค 50), which represents the number of datasets. This line is followed by T datasets.
Each dataset consists of two lines, the first line is given the number ni of the i-th (i = 1, 2, ..., 9) card, each separated by a space, and the second line is i. The letters ci representing the color of the second card are given, separated by spaces. The number ni on the card is an integer that satisfies 1 โค ni โค 9, and the color ci on the card is one of the letters "` R` "," `G`", and "` B` ", respectively.
No more than 5 cards with the same color and number will appear in one dataset.
Output
For each dataset, output "` 1` "if the winning conditions are met, otherwise output" `0`".
Example
Input
5
1 2 3 3 4 5 7 7 7
R R R R R R G G G
1 2 2 3 4 4 4 4 5
R R R R R R R R R
1 2 3 4 4 4 5 5 5
R R B R R R R R R
1 1 1 3 4 5 6 6 6
R R B G G G R R R
2 2 2 3 3 3 1 1 1
R G B R G B R G B
Output
1
0
0
0
1
Submitted Solution:
```
#!usr/bin/env python3
import sys
def main():
WINNING_HANDS = [
'111', '222', '333', '444', '555', '666', '777', '888', '999',
'123', '234', '345', '456', '567', '678', '789'
]
num_of_datasets = int(sys.stdin.readline().strip('\n'))
datasets = [{'R': [], 'G': [], 'B': []} for _ in range(num_of_datasets)]
results = list()
for dataset in range(num_of_datasets):
n_set = [int(num) for num in sys.stdin.readline().strip('\n').split()]
c_set = [colour for colour in sys.stdin.readline().strip('\n').split()]
for idx, colour in enumerate(c_set):
if colour == 'R':
datasets[dataset]['R'].append(n_set[idx])
elif colour == 'G':
datasets[dataset]['G'].append(n_set[idx])
elif colour == 'B':
datasets[dataset]['B'].append(n_set[idx])
match_count = int()
for rgb_key in datasets[dataset]:
nums = ''.join(str(num) for num in sorted(datasets[dataset][rgb_key]))
for hand in WINNING_HANDS:
if hand in nums:
match_count += 1
nums.replace(hand, '')
if match_count == 3:
results.append(1)
continue
if dataset < num_of_datasets-1 and match_count != 3:
results.append(0)
for result in results:
print(result)
if __name__ == '__main__':
main()
``` | instruction | 0 | 38,536 | 19 | 77,072 |
No | output | 1 | 38,536 | 19 | 77,073 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Your friend recently came up with a card game called UT-Rummy.
The cards used in this game are numbered red, green, or blue and any number from 1 to 9. Each player in this game has 9 cards in his or her hand, chooses one from his or her hand, discards it, and draws one from the deck instead. In this way, the turn is advanced in order, and the player who first makes three "sets" of three cards on hand wins. A set is a set of three cards of the same color, all having the same number or serial numbers. Patrol of numbers is not allowed for serial numbers. For example, 7, 8 and 9 are serial numbers, but 9, 1 and 2 are not.
Your friend has planned to sell this game as a computer game, and as part of that, he has asked you to make a judgment part of the victory conditions. Your job is to write a program that determines if your hand meets the winning conditions.
Input
The first line of input is given the number T (0 <T โค 50), which represents the number of datasets. This line is followed by T datasets.
Each dataset consists of two lines, the first line is given the number ni of the i-th (i = 1, 2, ..., 9) card, each separated by a space, and the second line is i. The letters ci representing the color of the second card are given, separated by spaces. The number ni on the card is an integer that satisfies 1 โค ni โค 9, and the color ci on the card is one of the letters "` R` "," `G`", and "` B` ", respectively.
No more than 5 cards with the same color and number will appear in one dataset.
Output
For each dataset, output "` 1` "if the winning conditions are met, otherwise output" `0`".
Example
Input
5
1 2 3 3 4 5 7 7 7
R R R R R R G G G
1 2 2 3 4 4 4 4 5
R R R R R R R R R
1 2 3 4 4 4 5 5 5
R R B R R R R R R
1 1 1 3 4 5 6 6 6
R R B G G G R R R
2 2 2 3 3 3 1 1 1
R G B R G B R G B
Output
1
0
0
0
1
Submitted Solution:
```
#!usr/bin/env python3
import sys
def main():
WINNING_HANDS = [
'111', '222', '333', '444', '555', '666', '777', '888', '999',
'123', '234', '345', '456', '567', '678', '789'
]
num_of_datasets = int(sys.stdin.readline().strip('\n'))
datasets = [{'R': [], 'G': [], 'B': []} for _ in range(num_of_datasets)]
results = list()
for dataset in range(num_of_datasets):
n_set = [num for num in sys.stdin.readline().strip('\n').split()]
c_set = [colour for colour in sys.stdin.readline().strip('\n').split()]
for idx, colour in enumerate(c_set):
if colour == 'R':
datasets[dataset]['R'].append(n_set[idx])
elif colour == 'G':
datasets[dataset]['G'].append(n_set[idx])
elif colour == 'B':
datasets[dataset]['B'].append(n_set[idx])
match_count = int()
for rgb_key in datasets[dataset]:
nums = sorted(datasets[dataset][rgb_key])
for hand in WINNING_HANDS:
if hand in ''.join(nums):
match_count += 1
for digit in hand:
nums.pop(nums.index(digit))
if match_count == 3:
results.append(1)
continue
if dataset < num_of_datasets-1 and match_count != 3:
results.append(0)
for result in results:
print(result)
if __name__ == '__main__':
main()
``` | instruction | 0 | 38,537 | 19 | 77,074 |
No | output | 1 | 38,537 | 19 | 77,075 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Your friend recently came up with a card game called UT-Rummy.
The cards used in this game are numbered red, green, or blue and any number from 1 to 9. Each player in this game has 9 cards in his or her hand, chooses one from his or her hand, discards it, and draws one from the deck instead. In this way, the turn is advanced in order, and the player who first makes three "sets" of three cards on hand wins. A set is a set of three cards of the same color, all having the same number or serial numbers. Patrol of numbers is not allowed for serial numbers. For example, 7, 8 and 9 are serial numbers, but 9, 1 and 2 are not.
Your friend has planned to sell this game as a computer game, and as part of that, he has asked you to make a judgment part of the victory conditions. Your job is to write a program that determines if your hand meets the winning conditions.
Input
The first line of input is given the number T (0 <T โค 50), which represents the number of datasets. This line is followed by T datasets.
Each dataset consists of two lines, the first line is given the number ni of the i-th (i = 1, 2, ..., 9) card, each separated by a space, and the second line is i. The letters ci representing the color of the second card are given, separated by spaces. The number ni on the card is an integer that satisfies 1 โค ni โค 9, and the color ci on the card is one of the letters "` R` "," `G`", and "` B` ", respectively.
No more than 5 cards with the same color and number will appear in one dataset.
Output
For each dataset, output "` 1` "if the winning conditions are met, otherwise output" `0`".
Example
Input
5
1 2 3 3 4 5 7 7 7
R R R R R R G G G
1 2 2 3 4 4 4 4 5
R R R R R R R R R
1 2 3 4 4 4 5 5 5
R R B R R R R R R
1 1 1 3 4 5 6 6 6
R R B G G G R R R
2 2 2 3 3 3 1 1 1
R G B R G B R G B
Output
1
0
0
0
1
Submitted Solution:
```
def sort(a):
temp = 0
for i in range(a-1):
if a[i] > a[i+1]:
temp = a[i]
a[i] = a[i+1]
a[i+1] = temp
return a
T = int(input())
count = 0
a = []
b = [[] for j in range(T)]
answer = [[False for i in range(3)] for j in range(T)]
for i in range(2*T):
a.append(list(input().split()))
for i in range(T):
for j in range(9):
a[i*2][j] = int(a[i*2][j])
for i in range(T):
for j in range(9):
if a[2*i+1][j] == "R":
a[2*i][j] = a[2*i][j] + 10
if a[2*i+1][j] == "G":
a[2*i][j] = a[2*i][j] + 20
if a[2*i+1][j] == "B":
a[2*i][j] = a[2*i][j] + 30
b[i].append(a[2*i][j])
for j in range(T):
for k in range(9):
for i in range(8):
temp = 0
if b[j][i] > b[j][i+1]:
temp = b[j][i]
b[j][i] = b[j][i+1]
b[j][i+1] = temp
for i in range(T):
for j in range(3):
if ((b[i][3*j] == b[i][3*j+1]) and (b[i][3*j] == b[i][3*j+2])) or ((b[i][3*j]+1 == b[i][3*j+1]) and (b[i][3*j]+2 == b[i][3*j+2])):
answer[i][j] = True
if answer[i][0] and answer[i][1] and answer[i][2]:
print(1)
else:
print(0)
``` | instruction | 0 | 38,538 | 19 | 77,076 |
No | output | 1 | 38,538 | 19 | 77,077 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Your friend recently came up with a card game called UT-Rummy.
The cards used in this game are numbered red, green, or blue and any number from 1 to 9. Each player in this game has 9 cards in his or her hand, chooses one from his or her hand, discards it, and draws one from the deck instead. In this way, the turn is advanced in order, and the player who first makes three "sets" of three cards on hand wins. A set is a set of three cards of the same color, all having the same number or serial numbers. Patrol of numbers is not allowed for serial numbers. For example, 7, 8 and 9 are serial numbers, but 9, 1 and 2 are not.
Your friend has planned to sell this game as a computer game, and as part of that, he has asked you to make a judgment part of the victory conditions. Your job is to write a program that determines if your hand meets the winning conditions.
Input
The first line of input is given the number T (0 <T โค 50), which represents the number of datasets. This line is followed by T datasets.
Each dataset consists of two lines, the first line is given the number ni of the i-th (i = 1, 2, ..., 9) card, each separated by a space, and the second line is i. The letters ci representing the color of the second card are given, separated by spaces. The number ni on the card is an integer that satisfies 1 โค ni โค 9, and the color ci on the card is one of the letters "` R` "," `G`", and "` B` ", respectively.
No more than 5 cards with the same color and number will appear in one dataset.
Output
For each dataset, output "` 1` "if the winning conditions are met, otherwise output" `0`".
Example
Input
5
1 2 3 3 4 5 7 7 7
R R R R R R G G G
1 2 2 3 4 4 4 4 5
R R R R R R R R R
1 2 3 4 4 4 5 5 5
R R B R R R R R R
1 1 1 3 4 5 6 6 6
R R B G G G R R R
2 2 2 3 3 3 1 1 1
R G B R G B R G B
Output
1
0
0
0
1
Submitted Solution:
```
T = int(input())
for i in range(T):
n = [int(i) for i in input().split()]
c = [i for i in input().split()]
value = [[],[],[]]
for j in range(9):
if c[j] == "R":
value[0].append(n[j])
elif c[j] == "G":
value[1].append(n[j])
else:
value[2].append(n[j])
print(value)
ans = 1
for i in range(3):
l = len(value[i])
if l%3 != 0:#RGBใฎ้ทใใ3ใฎๅๆฐใงใชใใจใๆญฃ่งฃใซใชใๅฏ่ฝๆงใฏใชใ
ans = 0
else:
value[i].sort()
s = l//3
print(i,s,value[i])
j=0
while ans>0 and s>0 and j<len(value[i])-2:
if value[i][j] == value[i][j+1]:#้ฃใๅใๆฐๅญใไธ่ดใใฆใใๅ ดๅ
print("ไบใคไธฆใใงใ")
if value[i][j+1] == value[i][j+2]:#3้ฃ็ถใงๅใๆฐๅญใไธฆใใงใใๅ ดๅ
for k in range(3):
value[i].pop(j)#ๅคใฎๅ้ค
s-=1
elif value[i][j+1]+1==value[i][j+2]:#2ใคใใฎๆฐๅญใจ3ใค็ฎใฎๆฐๅญใ้ฃ็ชใex)112,223,334,
print(value[i][j+1]+1)
k=j+3
while k<len(value[i]) and value[i][k]==value[i][j+2]:#3ใคใใจ4ใคใใฎๅคใๅใ
k+=1
if k>=len(value[i]) or value[i][k]!=value[i][j+2]+1:#4ใค็ฎใจ5ใค็ฎใฎๆฐๅญใ้ฃ็ชใงใชใๅ ดๅ ex)11225,22335ใไธๆญฃ่งฃ
ans=0
else:
#ๅคๅ้ค
value[i].pop(k)
value[i].pop(j+2)
value[i].pop(j)
s-=1
else:#3ใค็ฎใฎๆฐๅญใๅ
จ็ถ้ใใใค
ans=0
elif value[i][j]+1==value[i][j+1]:#้ฃใๅใๆฐๅญใ้ฃ็ชใฎๅ ดๅ
k=j+2
while k<len(value[i]) and value[i][k]==value[i][j+1]:
k+=1
if k>=len(value[i]) or value[i][k]!=value[i][j+1]+1:#3ใคใใฎๆฐๅญใ้ฃ็ชใงใชใๅ ดๅใไธๆญฃ่งฃ
ans=0
else:
#ๅคๅ้ค
value[i].pop(k)
value[i].pop(j+1)
value[i].pop(j)
s-=1
else:#้ฃใๅใๆฐๅญใ้ฃ็ชใงใใชใใๅๅคใงใใชใๅ ดๅใไธๆญฃ่งฃ
ans=0
i+=1
print(ans)
``` | instruction | 0 | 38,539 | 19 | 77,078 |
No | output | 1 | 38,539 | 19 | 77,079 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Gennady owns a small hotel in the countryside where he lives a peaceful life. He loves to take long walks, watch sunsets and play cards with tourists staying in his hotel. His favorite game is called "Mau-Mau".
To play Mau-Mau, you need a pack of 52 cards. Each card has a suit (Diamonds โ D, Clubs โ C, Spades โ S, or Hearts โ H), and a rank (2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K, or A).
At the start of the game, there is one card on the table and you have five cards in your hand. You can play a card from your hand if and only if it has the same rank or the same suit as the card on the table.
In order to check if you'd be a good playing partner, Gennady has prepared a task for you. Given the card on the table and five cards in your hand, check if you can play at least one card.
Input
The first line of the input contains one string which describes the card on the table. The second line contains five strings which describe the cards in your hand.
Each string is two characters long. The first character denotes the rank and belongs to the set \{{\tt 2}, {\tt 3}, {\tt 4}, {\tt 5}, {\tt 6}, {\tt 7}, {\tt 8}, {\tt 9}, {\tt T}, {\tt J}, {\tt Q}, {\tt K}, {\tt A}\}. The second character denotes the suit and belongs to the set \{{\tt D}, {\tt C}, {\tt S}, {\tt H}\}.
All the cards in the input are different.
Output
If it is possible to play a card from your hand, print one word "YES". Otherwise, print "NO".
You can print each letter in any case (upper or lower).
Examples
Input
AS
2H 4C TH JH AD
Output
YES
Input
2H
3D 4C AC KD AS
Output
NO
Input
4D
AS AC AD AH 5H
Output
YES
Note
In the first example, there is an Ace of Spades (AS) on the table. You can play an Ace of Diamonds (AD) because both of them are Aces.
In the second example, you cannot play any card.
In the third example, you can play an Ace of Diamonds (AD) because it has the same suit as a Four of Diamonds (4D), which lies on the table. | instruction | 0 | 38,666 | 19 | 77,332 |
Tags: brute force, implementation
Correct Solution:
```
inp = input().strip().split()
arr = input().strip().split()
flag=0
for i in range(len(arr)):
if(inp[0][0]==arr[i][0] or inp[0][1]==arr[i][1]):
print("YES")
flag=1
break
if(flag==0):
print("NO")
``` | output | 1 | 38,666 | 19 | 77,333 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Gennady owns a small hotel in the countryside where he lives a peaceful life. He loves to take long walks, watch sunsets and play cards with tourists staying in his hotel. His favorite game is called "Mau-Mau".
To play Mau-Mau, you need a pack of 52 cards. Each card has a suit (Diamonds โ D, Clubs โ C, Spades โ S, or Hearts โ H), and a rank (2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K, or A).
At the start of the game, there is one card on the table and you have five cards in your hand. You can play a card from your hand if and only if it has the same rank or the same suit as the card on the table.
In order to check if you'd be a good playing partner, Gennady has prepared a task for you. Given the card on the table and five cards in your hand, check if you can play at least one card.
Input
The first line of the input contains one string which describes the card on the table. The second line contains five strings which describe the cards in your hand.
Each string is two characters long. The first character denotes the rank and belongs to the set \{{\tt 2}, {\tt 3}, {\tt 4}, {\tt 5}, {\tt 6}, {\tt 7}, {\tt 8}, {\tt 9}, {\tt T}, {\tt J}, {\tt Q}, {\tt K}, {\tt A}\}. The second character denotes the suit and belongs to the set \{{\tt D}, {\tt C}, {\tt S}, {\tt H}\}.
All the cards in the input are different.
Output
If it is possible to play a card from your hand, print one word "YES". Otherwise, print "NO".
You can print each letter in any case (upper or lower).
Examples
Input
AS
2H 4C TH JH AD
Output
YES
Input
2H
3D 4C AC KD AS
Output
NO
Input
4D
AS AC AD AH 5H
Output
YES
Note
In the first example, there is an Ace of Spades (AS) on the table. You can play an Ace of Diamonds (AD) because both of them are Aces.
In the second example, you cannot play any card.
In the third example, you can play an Ace of Diamonds (AD) because it has the same suit as a Four of Diamonds (4D), which lies on the table. | instruction | 0 | 38,667 | 19 | 77,334 |
Tags: brute force, implementation
Correct Solution:
```
import sys
input = sys.stdin.readline
def inp():
return(int(input()))
def inlt():
return(list(map(int, input().split())))
def insr():
s = input()
return(list(s[:len(s) - 1]))
def invr():
return(map(int, input().split()))
def foo():
# AS
# 2H 4C TH JH AD
t = insr() # '4D'
h = list(input().split()) # ['AS', 'AC', 'AD', 'AH', '5H']
for i in range(2):
for j in range(5):
if h[j][i] == t[i]:
# print(h[j][i], t[i])
print("YES")
return 0
print("NO")
if __name__ == '__main__':
foo()
``` | output | 1 | 38,667 | 19 | 77,335 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Gennady owns a small hotel in the countryside where he lives a peaceful life. He loves to take long walks, watch sunsets and play cards with tourists staying in his hotel. His favorite game is called "Mau-Mau".
To play Mau-Mau, you need a pack of 52 cards. Each card has a suit (Diamonds โ D, Clubs โ C, Spades โ S, or Hearts โ H), and a rank (2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K, or A).
At the start of the game, there is one card on the table and you have five cards in your hand. You can play a card from your hand if and only if it has the same rank or the same suit as the card on the table.
In order to check if you'd be a good playing partner, Gennady has prepared a task for you. Given the card on the table and five cards in your hand, check if you can play at least one card.
Input
The first line of the input contains one string which describes the card on the table. The second line contains five strings which describe the cards in your hand.
Each string is two characters long. The first character denotes the rank and belongs to the set \{{\tt 2}, {\tt 3}, {\tt 4}, {\tt 5}, {\tt 6}, {\tt 7}, {\tt 8}, {\tt 9}, {\tt T}, {\tt J}, {\tt Q}, {\tt K}, {\tt A}\}. The second character denotes the suit and belongs to the set \{{\tt D}, {\tt C}, {\tt S}, {\tt H}\}.
All the cards in the input are different.
Output
If it is possible to play a card from your hand, print one word "YES". Otherwise, print "NO".
You can print each letter in any case (upper or lower).
Examples
Input
AS
2H 4C TH JH AD
Output
YES
Input
2H
3D 4C AC KD AS
Output
NO
Input
4D
AS AC AD AH 5H
Output
YES
Note
In the first example, there is an Ace of Spades (AS) on the table. You can play an Ace of Diamonds (AD) because both of them are Aces.
In the second example, you cannot play any card.
In the third example, you can play an Ace of Diamonds (AD) because it has the same suit as a Four of Diamonds (4D), which lies on the table. | instruction | 0 | 38,668 | 19 | 77,336 |
Tags: brute force, implementation
Correct Solution:
```
CardOnTaple = str(input())
CardOnHand = list(str(input()).split())
x=0
for e in CardOnHand:
if CardOnTaple[0] == e[0] :
x = x +1
elif CardOnTaple[1] == e[1] :
x = x + 1
if x >= 1 :
print("Yes")
else :
print("No")
``` | output | 1 | 38,668 | 19 | 77,337 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Gennady owns a small hotel in the countryside where he lives a peaceful life. He loves to take long walks, watch sunsets and play cards with tourists staying in his hotel. His favorite game is called "Mau-Mau".
To play Mau-Mau, you need a pack of 52 cards. Each card has a suit (Diamonds โ D, Clubs โ C, Spades โ S, or Hearts โ H), and a rank (2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K, or A).
At the start of the game, there is one card on the table and you have five cards in your hand. You can play a card from your hand if and only if it has the same rank or the same suit as the card on the table.
In order to check if you'd be a good playing partner, Gennady has prepared a task for you. Given the card on the table and five cards in your hand, check if you can play at least one card.
Input
The first line of the input contains one string which describes the card on the table. The second line contains five strings which describe the cards in your hand.
Each string is two characters long. The first character denotes the rank and belongs to the set \{{\tt 2}, {\tt 3}, {\tt 4}, {\tt 5}, {\tt 6}, {\tt 7}, {\tt 8}, {\tt 9}, {\tt T}, {\tt J}, {\tt Q}, {\tt K}, {\tt A}\}. The second character denotes the suit and belongs to the set \{{\tt D}, {\tt C}, {\tt S}, {\tt H}\}.
All the cards in the input are different.
Output
If it is possible to play a card from your hand, print one word "YES". Otherwise, print "NO".
You can print each letter in any case (upper or lower).
Examples
Input
AS
2H 4C TH JH AD
Output
YES
Input
2H
3D 4C AC KD AS
Output
NO
Input
4D
AS AC AD AH 5H
Output
YES
Note
In the first example, there is an Ace of Spades (AS) on the table. You can play an Ace of Diamonds (AD) because both of them are Aces.
In the second example, you cannot play any card.
In the third example, you can play an Ace of Diamonds (AD) because it has the same suit as a Four of Diamonds (4D), which lies on the table. | instruction | 0 | 38,669 | 19 | 77,338 |
Tags: brute force, implementation
Correct Solution:
```
x = input()
y = input().split()
a = 0
for i in y:
if x[0] in i or x[1] in i:
a = 1
if a == 1:
print("YES")
else:
print("NO")
``` | output | 1 | 38,669 | 19 | 77,339 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Gennady owns a small hotel in the countryside where he lives a peaceful life. He loves to take long walks, watch sunsets and play cards with tourists staying in his hotel. His favorite game is called "Mau-Mau".
To play Mau-Mau, you need a pack of 52 cards. Each card has a suit (Diamonds โ D, Clubs โ C, Spades โ S, or Hearts โ H), and a rank (2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K, or A).
At the start of the game, there is one card on the table and you have five cards in your hand. You can play a card from your hand if and only if it has the same rank or the same suit as the card on the table.
In order to check if you'd be a good playing partner, Gennady has prepared a task for you. Given the card on the table and five cards in your hand, check if you can play at least one card.
Input
The first line of the input contains one string which describes the card on the table. The second line contains five strings which describe the cards in your hand.
Each string is two characters long. The first character denotes the rank and belongs to the set \{{\tt 2}, {\tt 3}, {\tt 4}, {\tt 5}, {\tt 6}, {\tt 7}, {\tt 8}, {\tt 9}, {\tt T}, {\tt J}, {\tt Q}, {\tt K}, {\tt A}\}. The second character denotes the suit and belongs to the set \{{\tt D}, {\tt C}, {\tt S}, {\tt H}\}.
All the cards in the input are different.
Output
If it is possible to play a card from your hand, print one word "YES". Otherwise, print "NO".
You can print each letter in any case (upper or lower).
Examples
Input
AS
2H 4C TH JH AD
Output
YES
Input
2H
3D 4C AC KD AS
Output
NO
Input
4D
AS AC AD AH 5H
Output
YES
Note
In the first example, there is an Ace of Spades (AS) on the table. You can play an Ace of Diamonds (AD) because both of them are Aces.
In the second example, you cannot play any card.
In the third example, you can play an Ace of Diamonds (AD) because it has the same suit as a Four of Diamonds (4D), which lies on the table. | instruction | 0 | 38,670 | 19 | 77,340 |
Tags: brute force, implementation
Correct Solution:
```
s=input()
f=0
l = input().split(' ')
for i in l:
if s[0] in i[0]:
f=1
break
elif s[1] in i[1]:
f=1
break
if f == 1:
print('YES')
else:
print('NO')
``` | output | 1 | 38,670 | 19 | 77,341 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Gennady owns a small hotel in the countryside where he lives a peaceful life. He loves to take long walks, watch sunsets and play cards with tourists staying in his hotel. His favorite game is called "Mau-Mau".
To play Mau-Mau, you need a pack of 52 cards. Each card has a suit (Diamonds โ D, Clubs โ C, Spades โ S, or Hearts โ H), and a rank (2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K, or A).
At the start of the game, there is one card on the table and you have five cards in your hand. You can play a card from your hand if and only if it has the same rank or the same suit as the card on the table.
In order to check if you'd be a good playing partner, Gennady has prepared a task for you. Given the card on the table and five cards in your hand, check if you can play at least one card.
Input
The first line of the input contains one string which describes the card on the table. The second line contains five strings which describe the cards in your hand.
Each string is two characters long. The first character denotes the rank and belongs to the set \{{\tt 2}, {\tt 3}, {\tt 4}, {\tt 5}, {\tt 6}, {\tt 7}, {\tt 8}, {\tt 9}, {\tt T}, {\tt J}, {\tt Q}, {\tt K}, {\tt A}\}. The second character denotes the suit and belongs to the set \{{\tt D}, {\tt C}, {\tt S}, {\tt H}\}.
All the cards in the input are different.
Output
If it is possible to play a card from your hand, print one word "YES". Otherwise, print "NO".
You can print each letter in any case (upper or lower).
Examples
Input
AS
2H 4C TH JH AD
Output
YES
Input
2H
3D 4C AC KD AS
Output
NO
Input
4D
AS AC AD AH 5H
Output
YES
Note
In the first example, there is an Ace of Spades (AS) on the table. You can play an Ace of Diamonds (AD) because both of them are Aces.
In the second example, you cannot play any card.
In the third example, you can play an Ace of Diamonds (AD) because it has the same suit as a Four of Diamonds (4D), which lies on the table. | instruction | 0 | 38,671 | 19 | 77,342 |
Tags: brute force, implementation
Correct Solution:
```
played = list(input())
hand = [list(i) for i in input().split()]
possible = False
for card in hand:
if card[0] == played[0] or card[1] == played[1]:
possible = True
break
if possible:
print('YES')
else:
print('NO')
``` | output | 1 | 38,671 | 19 | 77,343 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Gennady owns a small hotel in the countryside where he lives a peaceful life. He loves to take long walks, watch sunsets and play cards with tourists staying in his hotel. His favorite game is called "Mau-Mau".
To play Mau-Mau, you need a pack of 52 cards. Each card has a suit (Diamonds โ D, Clubs โ C, Spades โ S, or Hearts โ H), and a rank (2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K, or A).
At the start of the game, there is one card on the table and you have five cards in your hand. You can play a card from your hand if and only if it has the same rank or the same suit as the card on the table.
In order to check if you'd be a good playing partner, Gennady has prepared a task for you. Given the card on the table and five cards in your hand, check if you can play at least one card.
Input
The first line of the input contains one string which describes the card on the table. The second line contains five strings which describe the cards in your hand.
Each string is two characters long. The first character denotes the rank and belongs to the set \{{\tt 2}, {\tt 3}, {\tt 4}, {\tt 5}, {\tt 6}, {\tt 7}, {\tt 8}, {\tt 9}, {\tt T}, {\tt J}, {\tt Q}, {\tt K}, {\tt A}\}. The second character denotes the suit and belongs to the set \{{\tt D}, {\tt C}, {\tt S}, {\tt H}\}.
All the cards in the input are different.
Output
If it is possible to play a card from your hand, print one word "YES". Otherwise, print "NO".
You can print each letter in any case (upper or lower).
Examples
Input
AS
2H 4C TH JH AD
Output
YES
Input
2H
3D 4C AC KD AS
Output
NO
Input
4D
AS AC AD AH 5H
Output
YES
Note
In the first example, there is an Ace of Spades (AS) on the table. You can play an Ace of Diamonds (AD) because both of them are Aces.
In the second example, you cannot play any card.
In the third example, you can play an Ace of Diamonds (AD) because it has the same suit as a Four of Diamonds (4D), which lies on the table. | instruction | 0 | 38,672 | 19 | 77,344 |
Tags: brute force, implementation
Correct Solution:
```
def cardGame():
tableCard = input()
cards = input().split()
for i in cards:
if tableCard[0] == i[0]:
return "YES"
elif tableCard[1] == i[1]:
return "YES"
return "NO"
print(cardGame())
``` | output | 1 | 38,672 | 19 | 77,345 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Gennady owns a small hotel in the countryside where he lives a peaceful life. He loves to take long walks, watch sunsets and play cards with tourists staying in his hotel. His favorite game is called "Mau-Mau".
To play Mau-Mau, you need a pack of 52 cards. Each card has a suit (Diamonds โ D, Clubs โ C, Spades โ S, or Hearts โ H), and a rank (2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K, or A).
At the start of the game, there is one card on the table and you have five cards in your hand. You can play a card from your hand if and only if it has the same rank or the same suit as the card on the table.
In order to check if you'd be a good playing partner, Gennady has prepared a task for you. Given the card on the table and five cards in your hand, check if you can play at least one card.
Input
The first line of the input contains one string which describes the card on the table. The second line contains five strings which describe the cards in your hand.
Each string is two characters long. The first character denotes the rank and belongs to the set \{{\tt 2}, {\tt 3}, {\tt 4}, {\tt 5}, {\tt 6}, {\tt 7}, {\tt 8}, {\tt 9}, {\tt T}, {\tt J}, {\tt Q}, {\tt K}, {\tt A}\}. The second character denotes the suit and belongs to the set \{{\tt D}, {\tt C}, {\tt S}, {\tt H}\}.
All the cards in the input are different.
Output
If it is possible to play a card from your hand, print one word "YES". Otherwise, print "NO".
You can print each letter in any case (upper or lower).
Examples
Input
AS
2H 4C TH JH AD
Output
YES
Input
2H
3D 4C AC KD AS
Output
NO
Input
4D
AS AC AD AH 5H
Output
YES
Note
In the first example, there is an Ace of Spades (AS) on the table. You can play an Ace of Diamonds (AD) because both of them are Aces.
In the second example, you cannot play any card.
In the third example, you can play an Ace of Diamonds (AD) because it has the same suit as a Four of Diamonds (4D), which lies on the table. | instruction | 0 | 38,673 | 19 | 77,346 |
Tags: brute force, implementation
Correct Solution:
```
board = input()
hand = input().split()
def solve():
global board, hand
for el in hand:
if el[0]== board[0]:
return 'yes'
if el[1]==board[1]:
return 'yes'
return 'no'
print(solve())
``` | output | 1 | 38,673 | 19 | 77,347 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Gennady owns a small hotel in the countryside where he lives a peaceful life. He loves to take long walks, watch sunsets and play cards with tourists staying in his hotel. His favorite game is called "Mau-Mau".
To play Mau-Mau, you need a pack of 52 cards. Each card has a suit (Diamonds โ D, Clubs โ C, Spades โ S, or Hearts โ H), and a rank (2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K, or A).
At the start of the game, there is one card on the table and you have five cards in your hand. You can play a card from your hand if and only if it has the same rank or the same suit as the card on the table.
In order to check if you'd be a good playing partner, Gennady has prepared a task for you. Given the card on the table and five cards in your hand, check if you can play at least one card.
Input
The first line of the input contains one string which describes the card on the table. The second line contains five strings which describe the cards in your hand.
Each string is two characters long. The first character denotes the rank and belongs to the set \{{\tt 2}, {\tt 3}, {\tt 4}, {\tt 5}, {\tt 6}, {\tt 7}, {\tt 8}, {\tt 9}, {\tt T}, {\tt J}, {\tt Q}, {\tt K}, {\tt A}\}. The second character denotes the suit and belongs to the set \{{\tt D}, {\tt C}, {\tt S}, {\tt H}\}.
All the cards in the input are different.
Output
If it is possible to play a card from your hand, print one word "YES". Otherwise, print "NO".
You can print each letter in any case (upper or lower).
Examples
Input
AS
2H 4C TH JH AD
Output
YES
Input
2H
3D 4C AC KD AS
Output
NO
Input
4D
AS AC AD AH 5H
Output
YES
Note
In the first example, there is an Ace of Spades (AS) on the table. You can play an Ace of Diamonds (AD) because both of them are Aces.
In the second example, you cannot play any card.
In the third example, you can play an Ace of Diamonds (AD) because it has the same suit as a Four of Diamonds (4D), which lies on the table.
Submitted Solution:
```
n= input()
lists = list(map(str,input().split()))
for i in lists:
if(n[0]==i[0] or n[1]==i[1]):
print('YES')
break
else:
print('NO')
``` | instruction | 0 | 38,674 | 19 | 77,348 |
Yes | output | 1 | 38,674 | 19 | 77,349 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Gennady owns a small hotel in the countryside where he lives a peaceful life. He loves to take long walks, watch sunsets and play cards with tourists staying in his hotel. His favorite game is called "Mau-Mau".
To play Mau-Mau, you need a pack of 52 cards. Each card has a suit (Diamonds โ D, Clubs โ C, Spades โ S, or Hearts โ H), and a rank (2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K, or A).
At the start of the game, there is one card on the table and you have five cards in your hand. You can play a card from your hand if and only if it has the same rank or the same suit as the card on the table.
In order to check if you'd be a good playing partner, Gennady has prepared a task for you. Given the card on the table and five cards in your hand, check if you can play at least one card.
Input
The first line of the input contains one string which describes the card on the table. The second line contains five strings which describe the cards in your hand.
Each string is two characters long. The first character denotes the rank and belongs to the set \{{\tt 2}, {\tt 3}, {\tt 4}, {\tt 5}, {\tt 6}, {\tt 7}, {\tt 8}, {\tt 9}, {\tt T}, {\tt J}, {\tt Q}, {\tt K}, {\tt A}\}. The second character denotes the suit and belongs to the set \{{\tt D}, {\tt C}, {\tt S}, {\tt H}\}.
All the cards in the input are different.
Output
If it is possible to play a card from your hand, print one word "YES". Otherwise, print "NO".
You can print each letter in any case (upper or lower).
Examples
Input
AS
2H 4C TH JH AD
Output
YES
Input
2H
3D 4C AC KD AS
Output
NO
Input
4D
AS AC AD AH 5H
Output
YES
Note
In the first example, there is an Ace of Spades (AS) on the table. You can play an Ace of Diamonds (AD) because both of them are Aces.
In the second example, you cannot play any card.
In the third example, you can play an Ace of Diamonds (AD) because it has the same suit as a Four of Diamonds (4D), which lies on the table.
Submitted Solution:
```
a=input()
b=input().split()
flag=0
for (i,j) in b:
if i==a[0] or j==a[1]:
print("YES")
flag = 1
break
if flag == 0:
print("NO")
``` | instruction | 0 | 38,675 | 19 | 77,350 |
Yes | output | 1 | 38,675 | 19 | 77,351 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Gennady owns a small hotel in the countryside where he lives a peaceful life. He loves to take long walks, watch sunsets and play cards with tourists staying in his hotel. His favorite game is called "Mau-Mau".
To play Mau-Mau, you need a pack of 52 cards. Each card has a suit (Diamonds โ D, Clubs โ C, Spades โ S, or Hearts โ H), and a rank (2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K, or A).
At the start of the game, there is one card on the table and you have five cards in your hand. You can play a card from your hand if and only if it has the same rank or the same suit as the card on the table.
In order to check if you'd be a good playing partner, Gennady has prepared a task for you. Given the card on the table and five cards in your hand, check if you can play at least one card.
Input
The first line of the input contains one string which describes the card on the table. The second line contains five strings which describe the cards in your hand.
Each string is two characters long. The first character denotes the rank and belongs to the set \{{\tt 2}, {\tt 3}, {\tt 4}, {\tt 5}, {\tt 6}, {\tt 7}, {\tt 8}, {\tt 9}, {\tt T}, {\tt J}, {\tt Q}, {\tt K}, {\tt A}\}. The second character denotes the suit and belongs to the set \{{\tt D}, {\tt C}, {\tt S}, {\tt H}\}.
All the cards in the input are different.
Output
If it is possible to play a card from your hand, print one word "YES". Otherwise, print "NO".
You can print each letter in any case (upper or lower).
Examples
Input
AS
2H 4C TH JH AD
Output
YES
Input
2H
3D 4C AC KD AS
Output
NO
Input
4D
AS AC AD AH 5H
Output
YES
Note
In the first example, there is an Ace of Spades (AS) on the table. You can play an Ace of Diamonds (AD) because both of them are Aces.
In the second example, you cannot play any card.
In the third example, you can play an Ace of Diamonds (AD) because it has the same suit as a Four of Diamonds (4D), which lies on the table.
Submitted Solution:
```
"""Submitting by the name of Maa Sarashwati and Maa Bishwakarma. """
s=input()
g=""
a=input()
for i in a:
if i!=" ":
g+=i
l=s[0]
m=s[1]
if l in g:print("YES")
elif m in g:print("YES")
else:print("NO")
``` | instruction | 0 | 38,676 | 19 | 77,352 |
Yes | output | 1 | 38,676 | 19 | 77,353 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Gennady owns a small hotel in the countryside where he lives a peaceful life. He loves to take long walks, watch sunsets and play cards with tourists staying in his hotel. His favorite game is called "Mau-Mau".
To play Mau-Mau, you need a pack of 52 cards. Each card has a suit (Diamonds โ D, Clubs โ C, Spades โ S, or Hearts โ H), and a rank (2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K, or A).
At the start of the game, there is one card on the table and you have five cards in your hand. You can play a card from your hand if and only if it has the same rank or the same suit as the card on the table.
In order to check if you'd be a good playing partner, Gennady has prepared a task for you. Given the card on the table and five cards in your hand, check if you can play at least one card.
Input
The first line of the input contains one string which describes the card on the table. The second line contains five strings which describe the cards in your hand.
Each string is two characters long. The first character denotes the rank and belongs to the set \{{\tt 2}, {\tt 3}, {\tt 4}, {\tt 5}, {\tt 6}, {\tt 7}, {\tt 8}, {\tt 9}, {\tt T}, {\tt J}, {\tt Q}, {\tt K}, {\tt A}\}. The second character denotes the suit and belongs to the set \{{\tt D}, {\tt C}, {\tt S}, {\tt H}\}.
All the cards in the input are different.
Output
If it is possible to play a card from your hand, print one word "YES". Otherwise, print "NO".
You can print each letter in any case (upper or lower).
Examples
Input
AS
2H 4C TH JH AD
Output
YES
Input
2H
3D 4C AC KD AS
Output
NO
Input
4D
AS AC AD AH 5H
Output
YES
Note
In the first example, there is an Ace of Spades (AS) on the table. You can play an Ace of Diamonds (AD) because both of them are Aces.
In the second example, you cannot play any card.
In the third example, you can play an Ace of Diamonds (AD) because it has the same suit as a Four of Diamonds (4D), which lies on the table.
Submitted Solution:
```
"""
http://codeforces.com/contest/1097/problem/A
"""
tableCard = input()
handCards = input().split(' ')
flag = False
for handCard in handCards:
if handCard[0] == tableCard[0] or handCard[1] == tableCard[1]:
flag = True
break
if flag:
print("YES")
else:
print("NO")
``` | instruction | 0 | 38,677 | 19 | 77,354 |
Yes | output | 1 | 38,677 | 19 | 77,355 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Gennady owns a small hotel in the countryside where he lives a peaceful life. He loves to take long walks, watch sunsets and play cards with tourists staying in his hotel. His favorite game is called "Mau-Mau".
To play Mau-Mau, you need a pack of 52 cards. Each card has a suit (Diamonds โ D, Clubs โ C, Spades โ S, or Hearts โ H), and a rank (2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K, or A).
At the start of the game, there is one card on the table and you have five cards in your hand. You can play a card from your hand if and only if it has the same rank or the same suit as the card on the table.
In order to check if you'd be a good playing partner, Gennady has prepared a task for you. Given the card on the table and five cards in your hand, check if you can play at least one card.
Input
The first line of the input contains one string which describes the card on the table. The second line contains five strings which describe the cards in your hand.
Each string is two characters long. The first character denotes the rank and belongs to the set \{{\tt 2}, {\tt 3}, {\tt 4}, {\tt 5}, {\tt 6}, {\tt 7}, {\tt 8}, {\tt 9}, {\tt T}, {\tt J}, {\tt Q}, {\tt K}, {\tt A}\}. The second character denotes the suit and belongs to the set \{{\tt D}, {\tt C}, {\tt S}, {\tt H}\}.
All the cards in the input are different.
Output
If it is possible to play a card from your hand, print one word "YES". Otherwise, print "NO".
You can print each letter in any case (upper or lower).
Examples
Input
AS
2H 4C TH JH AD
Output
YES
Input
2H
3D 4C AC KD AS
Output
NO
Input
4D
AS AC AD AH 5H
Output
YES
Note
In the first example, there is an Ace of Spades (AS) on the table. You can play an Ace of Diamonds (AD) because both of them are Aces.
In the second example, you cannot play any card.
In the third example, you can play an Ace of Diamonds (AD) because it has the same suit as a Four of Diamonds (4D), which lies on the table.
Submitted Solution:
```
s=input()
x=0
a=list(map(str,input().split()))
if s[0]=='A' or s[0]=='K' or s[0]=='Q':
for i in a:
p=i
if s[0]==p[0] or s[1]==p[1]:
x=1
break
else:
for i in a:
p=i
if p==s or (p[0]=='A' and p[1]==s[1]):
x=1
break
else:
try:
if p[1]==s[1] and int(p[0])>=int(s[0]):
x=1
break
else:
if int(p[0])==int(s[0]):
x=1
break
except:
pass
if x==1:
print("YES")
else:
print("NO")
``` | instruction | 0 | 38,678 | 19 | 77,356 |
No | output | 1 | 38,678 | 19 | 77,357 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Gennady owns a small hotel in the countryside where he lives a peaceful life. He loves to take long walks, watch sunsets and play cards with tourists staying in his hotel. His favorite game is called "Mau-Mau".
To play Mau-Mau, you need a pack of 52 cards. Each card has a suit (Diamonds โ D, Clubs โ C, Spades โ S, or Hearts โ H), and a rank (2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K, or A).
At the start of the game, there is one card on the table and you have five cards in your hand. You can play a card from your hand if and only if it has the same rank or the same suit as the card on the table.
In order to check if you'd be a good playing partner, Gennady has prepared a task for you. Given the card on the table and five cards in your hand, check if you can play at least one card.
Input
The first line of the input contains one string which describes the card on the table. The second line contains five strings which describe the cards in your hand.
Each string is two characters long. The first character denotes the rank and belongs to the set \{{\tt 2}, {\tt 3}, {\tt 4}, {\tt 5}, {\tt 6}, {\tt 7}, {\tt 8}, {\tt 9}, {\tt T}, {\tt J}, {\tt Q}, {\tt K}, {\tt A}\}. The second character denotes the suit and belongs to the set \{{\tt D}, {\tt C}, {\tt S}, {\tt H}\}.
All the cards in the input are different.
Output
If it is possible to play a card from your hand, print one word "YES". Otherwise, print "NO".
You can print each letter in any case (upper or lower).
Examples
Input
AS
2H 4C TH JH AD
Output
YES
Input
2H
3D 4C AC KD AS
Output
NO
Input
4D
AS AC AD AH 5H
Output
YES
Note
In the first example, there is an Ace of Spades (AS) on the table. You can play an Ace of Diamonds (AD) because both of them are Aces.
In the second example, you cannot play any card.
In the third example, you can play an Ace of Diamonds (AD) because it has the same suit as a Four of Diamonds (4D), which lies on the table.
Submitted Solution:
```
hand=input()
table=input().split(' ')
print(table)
res="NO"
for i in table:
if i[0]==hand[0] or i[1]==hand[1]:
res='YES'
break
print(res)
``` | instruction | 0 | 38,679 | 19 | 77,358 |
No | output | 1 | 38,679 | 19 | 77,359 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Gennady owns a small hotel in the countryside where he lives a peaceful life. He loves to take long walks, watch sunsets and play cards with tourists staying in his hotel. His favorite game is called "Mau-Mau".
To play Mau-Mau, you need a pack of 52 cards. Each card has a suit (Diamonds โ D, Clubs โ C, Spades โ S, or Hearts โ H), and a rank (2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K, or A).
At the start of the game, there is one card on the table and you have five cards in your hand. You can play a card from your hand if and only if it has the same rank or the same suit as the card on the table.
In order to check if you'd be a good playing partner, Gennady has prepared a task for you. Given the card on the table and five cards in your hand, check if you can play at least one card.
Input
The first line of the input contains one string which describes the card on the table. The second line contains five strings which describe the cards in your hand.
Each string is two characters long. The first character denotes the rank and belongs to the set \{{\tt 2}, {\tt 3}, {\tt 4}, {\tt 5}, {\tt 6}, {\tt 7}, {\tt 8}, {\tt 9}, {\tt T}, {\tt J}, {\tt Q}, {\tt K}, {\tt A}\}. The second character denotes the suit and belongs to the set \{{\tt D}, {\tt C}, {\tt S}, {\tt H}\}.
All the cards in the input are different.
Output
If it is possible to play a card from your hand, print one word "YES". Otherwise, print "NO".
You can print each letter in any case (upper or lower).
Examples
Input
AS
2H 4C TH JH AD
Output
YES
Input
2H
3D 4C AC KD AS
Output
NO
Input
4D
AS AC AD AH 5H
Output
YES
Note
In the first example, there is an Ace of Spades (AS) on the table. You can play an Ace of Diamonds (AD) because both of them are Aces.
In the second example, you cannot play any card.
In the third example, you can play an Ace of Diamonds (AD) because it has the same suit as a Four of Diamonds (4D), which lies on the table.
Submitted Solution:
```
def split(word):
return [char for char in word]
rank, suit = split(input())
lst = list(input().split())
for i in range (len(lst)):
if rank in lst[i] or suit in lst[i]:
res = 1
else:
res = 0
continue
if res == 1:
print('YES')
else: print('NO')
``` | instruction | 0 | 38,680 | 19 | 77,360 |
No | output | 1 | 38,680 | 19 | 77,361 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Gennady owns a small hotel in the countryside where he lives a peaceful life. He loves to take long walks, watch sunsets and play cards with tourists staying in his hotel. His favorite game is called "Mau-Mau".
To play Mau-Mau, you need a pack of 52 cards. Each card has a suit (Diamonds โ D, Clubs โ C, Spades โ S, or Hearts โ H), and a rank (2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K, or A).
At the start of the game, there is one card on the table and you have five cards in your hand. You can play a card from your hand if and only if it has the same rank or the same suit as the card on the table.
In order to check if you'd be a good playing partner, Gennady has prepared a task for you. Given the card on the table and five cards in your hand, check if you can play at least one card.
Input
The first line of the input contains one string which describes the card on the table. The second line contains five strings which describe the cards in your hand.
Each string is two characters long. The first character denotes the rank and belongs to the set \{{\tt 2}, {\tt 3}, {\tt 4}, {\tt 5}, {\tt 6}, {\tt 7}, {\tt 8}, {\tt 9}, {\tt T}, {\tt J}, {\tt Q}, {\tt K}, {\tt A}\}. The second character denotes the suit and belongs to the set \{{\tt D}, {\tt C}, {\tt S}, {\tt H}\}.
All the cards in the input are different.
Output
If it is possible to play a card from your hand, print one word "YES". Otherwise, print "NO".
You can print each letter in any case (upper or lower).
Examples
Input
AS
2H 4C TH JH AD
Output
YES
Input
2H
3D 4C AC KD AS
Output
NO
Input
4D
AS AC AD AH 5H
Output
YES
Note
In the first example, there is an Ace of Spades (AS) on the table. You can play an Ace of Diamonds (AD) because both of them are Aces.
In the second example, you cannot play any card.
In the third example, you can play an Ace of Diamonds (AD) because it has the same suit as a Four of Diamonds (4D), which lies on the table.
Submitted Solution:
```
s=input()
h=list(map(str,input().split()))
c=0
for i in range(len(h)):
if s[0] in h[i]:
c=c+1
if s[1] in h[i]:
c=c+1
if c>0:
print('YES')
else:
print('N0')
``` | instruction | 0 | 38,681 | 19 | 77,362 |
No | output | 1 | 38,681 | 19 | 77,363 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
Play by arranging white and black stones on the table. First, place the stones on the left edge of the table. Then place the stones in the second place from the left. Repeat this n times to arrange n stones in a horizontal row. However, when placing a new i-th go stone, replace the go stone on the table according to the following rules.
* If i is odd: Do not replace the stones that were on the table, but place the new stones i-th from the left.
* If i is even: If the color of the new go stone placed i-th from the left and the color of the rightmost go stone on the table are the same, the go stone on the table is not replaced and the new go stone is placed i-th from the left. If this is not the case, that is, if the color of the new i-th go stone from the left is different from the color of the right-most go stone on the table, first remove all the consecutive right-end go stones of the same color on the table, and then use the i-th go stone. Replace with a go stone of the same color, and place the i-th go stone on the right edge of the table.
For example, when the first 7 go stones are placed,
โโ โโ โโโ
(โ represents white go stones, โ represents black go stones.)
* If the 8th go stone is white (โ), it is the same color as the rightmost go stone, so leave it as it is. Therefore, the go stone on the table is
โโ โโ โโโโ
Will be.
* If the 8th go stone is black (โ), the color is different from the rightmost go stone (โ), so first remove the 3 consecutive white go stones (โ) on the right end of the table, and then remove the black go stone (โ). And put the eighth go stone on the far right. Therefore, the go stone on the table
โโ โโโโโโ
Will be.
Given the order of the stones to be placed as input, create a program to find the number of white stones placed on the table after arranging n stones.
input
The input consists of multiple datasets. Each dataset is given in the following format.
A positive integer n (1 โค n โค 100000) is written on the first line. In the second and subsequent lines i + 1 (1 โค i โค n), the color of the go stone placed in the i-th position is written. The integer ci is written, and if ci is 0, it means that the color of the i-th go stone is white, and if it is 1, it means that the color of the i-th go stone is black.
Of the scoring data, 50% of the points are given by satisfying n โค 10000.
When n is 0, it indicates the end of input. The number of datasets does not exceed 10.
output
For each dataset, output the number of white stones placed on the table after arranging n stones in one line.
Examples
Input
8
1
0
1
1
0
0
0
0
8
1
0
1
1
0
0
0
1
0
Output
6
2
Input
None
Output
None
Submitted Solution:
```
from collections import deque
while True:
n = int(input())
if n == 0: break
line = deque()
for i in range(n):
s = input()
if i % 2 == 0:
line.append(s)
else:
if line[-1] == s:
line.append(s)
else:
j = 0
for i in range(len(line))[::-1]:
j += 1
if line[i] == s:
break
for _ in range(j): line.pop()
for _ in range(j+1): line.append(s)
print(sum([1 for l in line if l == '0']))
``` | instruction | 0 | 39,551 | 19 | 79,102 |
No | output | 1 | 39,551 | 19 | 79,103 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
Play by arranging white and black stones on the table. First, place the stones on the left edge of the table. Then place the stones in the second place from the left. Repeat this n times to arrange n stones in a horizontal row. However, when placing a new i-th go stone, replace the go stone on the table according to the following rules.
* If i is odd: Do not replace the stones that were on the table, but place the new stones i-th from the left.
* If i is even: If the color of the new go stone placed i-th from the left and the color of the rightmost go stone on the table are the same, the go stone on the table is not replaced and the new go stone is placed i-th from the left. If this is not the case, that is, if the color of the new i-th go stone from the left is different from the color of the right-most go stone on the table, first remove all the consecutive right-end go stones of the same color on the table, and then use the i-th go stone. Replace with a go stone of the same color, and place the i-th go stone on the right edge of the table.
For example, when the first 7 go stones are placed,
โโ โโ โโโ
(โ represents white go stones, โ represents black go stones.)
* If the 8th go stone is white (โ), it is the same color as the rightmost go stone, so leave it as it is. Therefore, the go stone on the table is
โโ โโ โโโโ
Will be.
* If the 8th go stone is black (โ), the color is different from the rightmost go stone (โ), so first remove the 3 consecutive white go stones (โ) on the right end of the table, and then remove the black go stone (โ). And put the eighth go stone on the far right. Therefore, the go stone on the table
โโ โโโโโโ
Will be.
Given the order of the stones to be placed as input, create a program to find the number of white stones placed on the table after arranging n stones.
input
The input consists of multiple datasets. Each dataset is given in the following format.
A positive integer n (1 โค n โค 100000) is written on the first line. In the second and subsequent lines i + 1 (1 โค i โค n), the color of the go stone placed in the i-th position is written. The integer ci is written, and if ci is 0, it means that the color of the i-th go stone is white, and if it is 1, it means that the color of the i-th go stone is black.
Of the scoring data, 50% of the points are given by satisfying n โค 10000.
When n is 0, it indicates the end of input. The number of datasets does not exceed 10.
output
For each dataset, output the number of white stones placed on the table after arranging n stones in one line.
Examples
Input
8
1
0
1
1
0
0
0
0
8
1
0
1
1
0
0
0
1
0
Output
6
2
Input
None
Output
None
Submitted Solution:
```
while True:
n=int(input())
if n==0:break
com=[int(input())for i in range(n)]
seq=[1]
isW=com[0]==0
stW=isW
for i in range(1,n):
if i%2!=0:
if len(seq)!=1:
seq[len(seq)-2]+=seq.pop()+1
else:
seq[0]+=1
stW=not stW
isW=com[i]==0
else:
if isW:
if com[i]==0:seq[len(seq)-1]+=1
else:
seq.append(1)
isW=False
else:
if com[i]==0:
seq.append(1)
isW=True
else:seq[len(seq)-1]+=1
total=0
if stW:total+=sum(seq[0::2])
else:total+=sum(seq[1::2])
print(total)
``` | instruction | 0 | 39,552 | 19 | 79,104 |
No | output | 1 | 39,552 | 19 | 79,105 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
Play by arranging white and black stones on the table. First, place the stones on the left edge of the table. Then place the stones in the second place from the left. Repeat this n times to arrange n stones in a horizontal row. However, when placing a new i-th go stone, replace the go stone on the table according to the following rules.
* If i is odd: Do not replace the stones that were on the table, but place the new stones i-th from the left.
* If i is even: If the color of the new go stone placed i-th from the left and the color of the rightmost go stone on the table are the same, the go stone on the table is not replaced and the new go stone is placed i-th from the left. If this is not the case, that is, if the color of the new i-th go stone from the left is different from the color of the right-most go stone on the table, first remove all the consecutive right-end go stones of the same color on the table, and then use the i-th go stone. Replace with a go stone of the same color, and place the i-th go stone on the right edge of the table.
For example, when the first 7 go stones are placed,
โโ โโ โโโ
(โ represents white go stones, โ represents black go stones.)
* If the 8th go stone is white (โ), it is the same color as the rightmost go stone, so leave it as it is. Therefore, the go stone on the table is
โโ โโ โโโโ
Will be.
* If the 8th go stone is black (โ), the color is different from the rightmost go stone (โ), so first remove the 3 consecutive white go stones (โ) on the right end of the table, and then remove the black go stone (โ). And put the eighth go stone on the far right. Therefore, the go stone on the table
โโ โโโโโโ
Will be.
Given the order of the stones to be placed as input, create a program to find the number of white stones placed on the table after arranging n stones.
input
The input consists of multiple datasets. Each dataset is given in the following format.
A positive integer n (1 โค n โค 100000) is written on the first line. In the second and subsequent lines i + 1 (1 โค i โค n), the color of the go stone placed in the i-th position is written. The integer ci is written, and if ci is 0, it means that the color of the i-th go stone is white, and if it is 1, it means that the color of the i-th go stone is black.
Of the scoring data, 50% of the points are given by satisfying n โค 10000.
When n is 0, it indicates the end of input. The number of datasets does not exceed 10.
output
For each dataset, output the number of white stones placed on the table after arranging n stones in one line.
Examples
Input
8
1
0
1
1
0
0
0
0
8
1
0
1
1
0
0
0
1
0
Output
6
2
Input
None
Output
None
Submitted Solution:
```
f = open('input.txt')
fo = open('output.txt',"w")
while True:
n = int(f.readline())
if n == 0:
f.close
fo.close
break
arr = [0 for i in range(n)]
for i in range(n):
stone = int(f.readline())
if i%2 == 0:
arr[i] = stone
else:
for j in reversed(range(i)):
if arr[j] != stone:
arr[j] = stone
else:
break
arr[i] = stone
fo.write(arr.count(0))
``` | instruction | 0 | 39,553 | 19 | 79,106 |
No | output | 1 | 39,553 | 19 | 79,107 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
Play by arranging white and black stones on the table. First, place the stones on the left edge of the table. Then place the stones in the second place from the left. Repeat this n times to arrange n stones in a horizontal row. However, when placing a new i-th go stone, replace the go stone on the table according to the following rules.
* If i is odd: Do not replace the stones that were on the table, but place the new stones i-th from the left.
* If i is even: If the color of the new go stone placed i-th from the left and the color of the rightmost go stone on the table are the same, the go stone on the table is not replaced and the new go stone is placed i-th from the left. If this is not the case, that is, if the color of the new i-th go stone from the left is different from the color of the right-most go stone on the table, first remove all the consecutive right-end go stones of the same color on the table, and then use the i-th go stone. Replace with a go stone of the same color, and place the i-th go stone on the right edge of the table.
For example, when the first 7 go stones are placed,
โโ โโ โโโ
(โ represents white go stones, โ represents black go stones.)
* If the 8th go stone is white (โ), it is the same color as the rightmost go stone, so leave it as it is. Therefore, the go stone on the table is
โโ โโ โโโโ
Will be.
* If the 8th go stone is black (โ), the color is different from the rightmost go stone (โ), so first remove the 3 consecutive white go stones (โ) on the right end of the table, and then remove the black go stone (โ). And put the eighth go stone on the far right. Therefore, the go stone on the table
โโ โโโโโโ
Will be.
Given the order of the stones to be placed as input, create a program to find the number of white stones placed on the table after arranging n stones.
input
The input consists of multiple datasets. Each dataset is given in the following format.
A positive integer n (1 โค n โค 100000) is written on the first line. In the second and subsequent lines i + 1 (1 โค i โค n), the color of the go stone placed in the i-th position is written. The integer ci is written, and if ci is 0, it means that the color of the i-th go stone is white, and if it is 1, it means that the color of the i-th go stone is black.
Of the scoring data, 50% of the points are given by satisfying n โค 10000.
When n is 0, it indicates the end of input. The number of datasets does not exceed 10.
output
For each dataset, output the number of white stones placed on the table after arranging n stones in one line.
Examples
Input
8
1
0
1
1
0
0
0
0
8
1
0
1
1
0
0
0
1
0
Output
6
2
Input
None
Output
None
Submitted Solution:
```
while True:
n=int(input())
if n==0:break
com=[int(input())for i in range(n)]
seq=1
total=0
isW=com[0]==0
for i in range(1,n):
if i%2!=0:
seq+=1
isW=com[i]==0
else:
if isW:
if com[i]==0:seq+=1
else:
total+=seq
seq=1
isW=False
else:
if com[i]==0:
seq=1
isW=True
else:seq+=1
if isW:total+=seq
print(total)
``` | instruction | 0 | 39,554 | 19 | 79,108 |
No | output | 1 | 39,554 | 19 | 79,109 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This is an interactive problem.
Chouti was tired of studying, so he opened the computer and started playing a puzzle game.
Long long ago, the boy found a sequence s_1, s_2, โฆ, s_n of length n, kept by a tricky interactor. It consisted of 0s and 1s only and the number of 1s is t. The boy knows nothing about this sequence except n and t, but he can try to find it out with some queries with the interactor.
We define an operation called flipping. Flipping [l,r] (1 โค l โค r โค n) means for each x โ [l,r], changing s_x to 1-s_x.
In each query, the boy can give the interactor two integers l,r satisfying 1 โค l โค r โค n and the interactor will either flip [1,r] or [l,n] (both outcomes have the same probability and all decisions made by interactor are independent from each other, see Notes section for more details). The interactor will tell the current number of 1s after each operation. Note, that the sequence won't be restored after each operation.
Help the boy to find the original sequence in no more than 10000 interactions.
"Weird legend, dumb game." he thought. However, after several tries, he is still stuck with it. Can you help him beat this game?
Interaction
The interaction starts with a line containing two integers n and t (1 โค n โค 300, 0 โค t โค n) โ the length of the sequence and the number of 1s in it.
After that, you can make queries.
To make a query, print a line "? l r" (1 โค l โค r โค n), then flush the output.
After each query, read a single integer t (-1 โค t โค n).
* If t=-1, it means that you're out of queries, you should terminate your program immediately, then you will get Wrong Answer, otherwise the judging result would be undefined because you will interact with a closed stream.
* If t โฅ 0, it represents the current number of 1s in the sequence.
When you found the original sequence, print a line "! s", flush the output and terminate. Print s_1, s_2, โฆ, s_n as a binary string and do not print spaces in between.
Your solution will get Idleness Limit Exceeded if you don't print anything or forget to flush the output.
To flush you need to do the following right after printing a query and a line end:
* fflush(stdout) or cout.flush() in C++;
* System.out.flush() in Java;
* flush(output) in Pascal;
* stdout.flush() in Python;
* see documentation for other languages.
Hacks
For hacks, use the following format:
In the first and only line, print a non-empty binary string. Its length will be n and it will be treated as s_1, s_2, โฆ, s_n.
For example, the the test corresponding to the example contains a line "0011".
Example
Input
4 2
2
2
0
Output
? 1 1
? 1 1
? 3 4
! 0011
Note
For first query 1,1, the interactor should flip [1,1] or [1,4]. It chose to flip [1,4], so the sequence became 1100.
For second query 1,1, the interactor should flip [1,1] or [1,4]. It again chose to flip [1,4], so the sequence became 0011.
For third query 3,4, the interactor should flip [1,4] or [3,4]. It chose to flip [3,4], so the sequence became 0000.
Q: How does interactor choose between [1,r] and [l,n]? Is it really random?
A: The interactor will use a secret [pseudorandom number generator](https://en.wikipedia.org/wiki/Pseudorandom_number_generator). Only s and your queries will be hashed and used as the seed. So if you give the same sequence of queries twice for the same secret string, you will get the same results. Except this, you can consider the choices fully random, like flipping a fair coin. You needn't (and shouldn't) exploit the exact generator to pass this problem.
Submitted Solution:
```
import sys
R=range
I=sys.stdout.flush
J=input
def f(l,r):
print('?',l,r);I();J()
print('?',l,r);I();return int(J())
n,t=map(int,J().split())
a=[0]*(n+1)
w=[0]*(n+1)
def F(l,r):
for i in R(1,r+1):
a[i]^=1;w[i]^=1
for i in R(l,n+1):
a[i]^=1;w[i]^=1
def D(x,l,r):
global t
T=t
while 1>0:
t=f(l,r)
if t!=T:
F(l,r);break
K=[0,0]
for i in R(1,n+1):
if(i<l or i>r)and i!=x:
K[a[i]]+=1
L,K=K
a[x]=(1-K+L+t-T)//2
def P():
S=""
for i in R(1,n+1):
S+=str(a[i]^w[i])
print('!',S);I();exit(0)
if n<2:
a[1]=t;P()
D(1,2,n)
D(n,1,n-1)
if n==3:
a[2]=t-a[1]-a[3];P()
for i in R(2,n-1):
D(i,i+1,n-1+i%2)
if n>2:
a[n-1]=t-sum(a)-a[n-1];P()
``` | instruction | 0 | 40,445 | 19 | 80,890 |
No | output | 1 | 40,445 | 19 | 80,891 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This is an interactive problem.
Chouti was tired of studying, so he opened the computer and started playing a puzzle game.
Long long ago, the boy found a sequence s_1, s_2, โฆ, s_n of length n, kept by a tricky interactor. It consisted of 0s and 1s only and the number of 1s is t. The boy knows nothing about this sequence except n and t, but he can try to find it out with some queries with the interactor.
We define an operation called flipping. Flipping [l,r] (1 โค l โค r โค n) means for each x โ [l,r], changing s_x to 1-s_x.
In each query, the boy can give the interactor two integers l,r satisfying 1 โค l โค r โค n and the interactor will either flip [1,r] or [l,n] (both outcomes have the same probability and all decisions made by interactor are independent from each other, see Notes section for more details). The interactor will tell the current number of 1s after each operation. Note, that the sequence won't be restored after each operation.
Help the boy to find the original sequence in no more than 10000 interactions.
"Weird legend, dumb game." he thought. However, after several tries, he is still stuck with it. Can you help him beat this game?
Interaction
The interaction starts with a line containing two integers n and t (1 โค n โค 300, 0 โค t โค n) โ the length of the sequence and the number of 1s in it.
After that, you can make queries.
To make a query, print a line "? l r" (1 โค l โค r โค n), then flush the output.
After each query, read a single integer t (-1 โค t โค n).
* If t=-1, it means that you're out of queries, you should terminate your program immediately, then you will get Wrong Answer, otherwise the judging result would be undefined because you will interact with a closed stream.
* If t โฅ 0, it represents the current number of 1s in the sequence.
When you found the original sequence, print a line "! s", flush the output and terminate. Print s_1, s_2, โฆ, s_n as a binary string and do not print spaces in between.
Your solution will get Idleness Limit Exceeded if you don't print anything or forget to flush the output.
To flush you need to do the following right after printing a query and a line end:
* fflush(stdout) or cout.flush() in C++;
* System.out.flush() in Java;
* flush(output) in Pascal;
* stdout.flush() in Python;
* see documentation for other languages.
Hacks
For hacks, use the following format:
In the first and only line, print a non-empty binary string. Its length will be n and it will be treated as s_1, s_2, โฆ, s_n.
For example, the the test corresponding to the example contains a line "0011".
Example
Input
4 2
2
2
0
Output
? 1 1
? 1 1
? 3 4
! 0011
Note
For first query 1,1, the interactor should flip [1,1] or [1,4]. It chose to flip [1,4], so the sequence became 1100.
For second query 1,1, the interactor should flip [1,1] or [1,4]. It again chose to flip [1,4], so the sequence became 0011.
For third query 3,4, the interactor should flip [1,4] or [3,4]. It chose to flip [3,4], so the sequence became 0000.
Q: How does interactor choose between [1,r] and [l,n]? Is it really random?
A: The interactor will use a secret [pseudorandom number generator](https://en.wikipedia.org/wiki/Pseudorandom_number_generator). Only s and your queries will be hashed and used as the seed. So if you give the same sequence of queries twice for the same secret string, you will get the same results. Except this, you can consider the choices fully random, like flipping a fair coin. You needn't (and shouldn't) exploit the exact generator to pass this problem.
Submitted Solution:
```
from sys import stdout
def ask(l) :
global n
print('?', l + 1, n)
stdout.flush()
return int(input())
n, t = map(int, input().split())
a = [0] * n
def reset(i) :
while True :
ask(i + 1)
if ask(i + 1) == t:
return
for i in range(n - 1) :
s = set()
s1 = set([t, t - sum(a[:i]) - 1 + i - sum(a[:i])])
for _ in range(30) :
ask(i + 1)
s.add(ask(i + 1))
reset(i)
if s == s1 :
a[i] = 1
a[-1] = t - sum(a)
print('!', ''.join(map(str, a)))
``` | instruction | 0 | 40,446 | 19 | 80,892 |
No | output | 1 | 40,446 | 19 | 80,893 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This is an interactive problem.
Chouti was tired of studying, so he opened the computer and started playing a puzzle game.
Long long ago, the boy found a sequence s_1, s_2, โฆ, s_n of length n, kept by a tricky interactor. It consisted of 0s and 1s only and the number of 1s is t. The boy knows nothing about this sequence except n and t, but he can try to find it out with some queries with the interactor.
We define an operation called flipping. Flipping [l,r] (1 โค l โค r โค n) means for each x โ [l,r], changing s_x to 1-s_x.
In each query, the boy can give the interactor two integers l,r satisfying 1 โค l โค r โค n and the interactor will either flip [1,r] or [l,n] (both outcomes have the same probability and all decisions made by interactor are independent from each other, see Notes section for more details). The interactor will tell the current number of 1s after each operation. Note, that the sequence won't be restored after each operation.
Help the boy to find the original sequence in no more than 10000 interactions.
"Weird legend, dumb game." he thought. However, after several tries, he is still stuck with it. Can you help him beat this game?
Interaction
The interaction starts with a line containing two integers n and t (1 โค n โค 300, 0 โค t โค n) โ the length of the sequence and the number of 1s in it.
After that, you can make queries.
To make a query, print a line "? l r" (1 โค l โค r โค n), then flush the output.
After each query, read a single integer t (-1 โค t โค n).
* If t=-1, it means that you're out of queries, you should terminate your program immediately, then you will get Wrong Answer, otherwise the judging result would be undefined because you will interact with a closed stream.
* If t โฅ 0, it represents the current number of 1s in the sequence.
When you found the original sequence, print a line "! s", flush the output and terminate. Print s_1, s_2, โฆ, s_n as a binary string and do not print spaces in between.
Your solution will get Idleness Limit Exceeded if you don't print anything or forget to flush the output.
To flush you need to do the following right after printing a query and a line end:
* fflush(stdout) or cout.flush() in C++;
* System.out.flush() in Java;
* flush(output) in Pascal;
* stdout.flush() in Python;
* see documentation for other languages.
Hacks
For hacks, use the following format:
In the first and only line, print a non-empty binary string. Its length will be n and it will be treated as s_1, s_2, โฆ, s_n.
For example, the the test corresponding to the example contains a line "0011".
Example
Input
4 2
2
2
0
Output
? 1 1
? 1 1
? 3 4
! 0011
Note
For first query 1,1, the interactor should flip [1,1] or [1,4]. It chose to flip [1,4], so the sequence became 1100.
For second query 1,1, the interactor should flip [1,1] or [1,4]. It again chose to flip [1,4], so the sequence became 0011.
For third query 3,4, the interactor should flip [1,4] or [3,4]. It chose to flip [3,4], so the sequence became 0000.
Q: How does interactor choose between [1,r] and [l,n]? Is it really random?
A: The interactor will use a secret [pseudorandom number generator](https://en.wikipedia.org/wiki/Pseudorandom_number_generator). Only s and your queries will be hashed and used as the seed. So if you give the same sequence of queries twice for the same secret string, you will get the same results. Except this, you can consider the choices fully random, like flipping a fair coin. You needn't (and shouldn't) exploit the exact generator to pass this problem.
Submitted Solution:
```
import sys
R=range
I=sys.stdout.flush
J=input
def f(l,r):
print('?',l,r);I();J()
print('?',l,r);I();return int(J())
n,t=map(int,J().split())
a=[0]*(n+1)
w=[0]*(n+1)
def F(l,r):
for i in R(1,r+1):
a[i]^=1;w[i]^=1
for i in R(l,n+1):
a[i]^=1;w[i]^=1
def D(x,l,r):
global t
T=t
while 1>0:
t=f(l,r)
if t!=T:
F(l,r);break
K=L=0
for i in R(1,n+1):
if(i<l or i>r)and i!=x:
if a[i]<1:
L+=1
else:
K+=1
a[x]=(1-K+L+t-T)//2
def P():
for i in R(n):
a[i]^=w[i]
print('!',*a[1:]);I();exit(0)
if n<2:
a[1]=t;P()
D(1,2,n)
D(n,1,n-1)
for i in R(2,n-1):
D(i,i+1,n-1+i%2)
a[n-2]=t-sum(a)
P()
``` | instruction | 0 | 40,447 | 19 | 80,894 |
No | output | 1 | 40,447 | 19 | 80,895 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This is an interactive problem.
Chouti was tired of studying, so he opened the computer and started playing a puzzle game.
Long long ago, the boy found a sequence s_1, s_2, โฆ, s_n of length n, kept by a tricky interactor. It consisted of 0s and 1s only and the number of 1s is t. The boy knows nothing about this sequence except n and t, but he can try to find it out with some queries with the interactor.
We define an operation called flipping. Flipping [l,r] (1 โค l โค r โค n) means for each x โ [l,r], changing s_x to 1-s_x.
In each query, the boy can give the interactor two integers l,r satisfying 1 โค l โค r โค n and the interactor will either flip [1,r] or [l,n] (both outcomes have the same probability and all decisions made by interactor are independent from each other, see Notes section for more details). The interactor will tell the current number of 1s after each operation. Note, that the sequence won't be restored after each operation.
Help the boy to find the original sequence in no more than 10000 interactions.
"Weird legend, dumb game." he thought. However, after several tries, he is still stuck with it. Can you help him beat this game?
Interaction
The interaction starts with a line containing two integers n and t (1 โค n โค 300, 0 โค t โค n) โ the length of the sequence and the number of 1s in it.
After that, you can make queries.
To make a query, print a line "? l r" (1 โค l โค r โค n), then flush the output.
After each query, read a single integer t (-1 โค t โค n).
* If t=-1, it means that you're out of queries, you should terminate your program immediately, then you will get Wrong Answer, otherwise the judging result would be undefined because you will interact with a closed stream.
* If t โฅ 0, it represents the current number of 1s in the sequence.
When you found the original sequence, print a line "! s", flush the output and terminate. Print s_1, s_2, โฆ, s_n as a binary string and do not print spaces in between.
Your solution will get Idleness Limit Exceeded if you don't print anything or forget to flush the output.
To flush you need to do the following right after printing a query and a line end:
* fflush(stdout) or cout.flush() in C++;
* System.out.flush() in Java;
* flush(output) in Pascal;
* stdout.flush() in Python;
* see documentation for other languages.
Hacks
For hacks, use the following format:
In the first and only line, print a non-empty binary string. Its length will be n and it will be treated as s_1, s_2, โฆ, s_n.
For example, the the test corresponding to the example contains a line "0011".
Example
Input
4 2
2
2
0
Output
? 1 1
? 1 1
? 3 4
! 0011
Note
For first query 1,1, the interactor should flip [1,1] or [1,4]. It chose to flip [1,4], so the sequence became 1100.
For second query 1,1, the interactor should flip [1,1] or [1,4]. It again chose to flip [1,4], so the sequence became 0011.
For third query 3,4, the interactor should flip [1,4] or [3,4]. It chose to flip [3,4], so the sequence became 0000.
Q: How does interactor choose between [1,r] and [l,n]? Is it really random?
A: The interactor will use a secret [pseudorandom number generator](https://en.wikipedia.org/wiki/Pseudorandom_number_generator). Only s and your queries will be hashed and used as the seed. So if you give the same sequence of queries twice for the same secret string, you will get the same results. Except this, you can consider the choices fully random, like flipping a fair coin. You needn't (and shouldn't) exploit the exact generator to pass this problem.
Submitted Solution:
```
import sys
R=range
I=sys.stdout.flush
J=input
def f(l,r):
print('?',l,r);I();J()
print('?',l,r);I();return int(J())
n,t=map(int,J().split())
a=[0]*(n+1)
w=[0]*(n+1)
def F(l,r):
for i in R(1,r+1):
a[i]^=1;w[i]^=1
for i in R(l,n+1):
a[i]^=1;w[i]^=1
def D(x,l,r):
global t
T=t
while 1>0:
t=f(l,r)
if t!=T:
F(l,r);break
K=[0,0]
for i in R(1,n+1):
if(i<l or i>r)and i!=x:
K[a[i]]+=1
K,L=K
a[x]=(1-K+L+t-T)//2
def P():
for i in R(n):
a[i]^=w[i]
print('!',*a[1:]);I();exit(0)
if n<2:
a[1]=t;P()
D(1,2,n)
D(n,1,n-1)
if n==3:
a[2]=t-a[1]-a[3];P()
for i in R(2,n-1):
D(i,i+1,n-1+i%2)
if n>2:
a[n-1]=t-sum(a)-a[n-1]
P()
``` | instruction | 0 | 40,448 | 19 | 80,896 |
No | output | 1 | 40,448 | 19 | 80,897 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A and B are preparing themselves for programming contests.
To train their logical thinking and solve problems better, A and B decided to play chess. During the game A wondered whose position is now stronger.
For each chess piece we know its weight:
* the queen's weight is 9,
* the rook's weight is 5,
* the bishop's weight is 3,
* the knight's weight is 3,
* the pawn's weight is 1,
* the king's weight isn't considered in evaluating position.
The player's weight equals to the sum of weights of all his pieces on the board.
As A doesn't like counting, he asked you to help him determine which player has the larger position weight.
Input
The input contains eight lines, eight characters each โ the board's description.
The white pieces on the board are marked with uppercase letters, the black pieces are marked with lowercase letters.
The white pieces are denoted as follows: the queen is represented is 'Q', the rook โ as 'R', the bishop โ as'B', the knight โ as 'N', the pawn โ as 'P', the king โ as 'K'.
The black pieces are denoted as 'q', 'r', 'b', 'n', 'p', 'k', respectively.
An empty square of the board is marked as '.' (a dot).
It is not guaranteed that the given chess position can be achieved in a real game. Specifically, there can be an arbitrary (possibly zero) number pieces of each type, the king may be under attack and so on.
Output
Print "White" (without quotes) if the weight of the position of the white pieces is more than the weight of the position of the black pieces, print "Black" if the weight of the black pieces is more than the weight of the white pieces and print "Draw" if the weights of the white and black pieces are equal.
Examples
Input
...QK...
........
........
........
........
........
........
...rk...
Output
White
Input
rnbqkbnr
pppppppp
........
........
........
........
PPPPPPPP
RNBQKBNR
Output
Draw
Input
rppppppr
...k....
........
........
........
........
K...Q...
........
Output
Black
Note
In the first test sample the weight of the position of the white pieces equals to 9, the weight of the position of the black pieces equals 5.
In the second test sample the weights of the positions of the black and the white pieces are equal to 39.
In the third test sample the weight of the position of the white pieces equals to 9, the weight of the position of the black pieces equals to 16. | instruction | 0 | 40,763 | 19 | 81,526 |
Tags: implementation
Correct Solution:
```
wight = {"q" : 9 , "r":5 ,"b":3,"n":3 , "p":1}
p1 , p2 = [0,0]
for i in range(8):
for j in input():
if j.isupper():
p2 += wight.get(j.lower() , 0)
else :
p1 += wight.get(j , 0)
if p2 > p1:
print("White")
elif p1 > p2:
print("Black")
else :
print("Draw")
``` | output | 1 | 40,763 | 19 | 81,527 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A and B are preparing themselves for programming contests.
To train their logical thinking and solve problems better, A and B decided to play chess. During the game A wondered whose position is now stronger.
For each chess piece we know its weight:
* the queen's weight is 9,
* the rook's weight is 5,
* the bishop's weight is 3,
* the knight's weight is 3,
* the pawn's weight is 1,
* the king's weight isn't considered in evaluating position.
The player's weight equals to the sum of weights of all his pieces on the board.
As A doesn't like counting, he asked you to help him determine which player has the larger position weight.
Input
The input contains eight lines, eight characters each โ the board's description.
The white pieces on the board are marked with uppercase letters, the black pieces are marked with lowercase letters.
The white pieces are denoted as follows: the queen is represented is 'Q', the rook โ as 'R', the bishop โ as'B', the knight โ as 'N', the pawn โ as 'P', the king โ as 'K'.
The black pieces are denoted as 'q', 'r', 'b', 'n', 'p', 'k', respectively.
An empty square of the board is marked as '.' (a dot).
It is not guaranteed that the given chess position can be achieved in a real game. Specifically, there can be an arbitrary (possibly zero) number pieces of each type, the king may be under attack and so on.
Output
Print "White" (without quotes) if the weight of the position of the white pieces is more than the weight of the position of the black pieces, print "Black" if the weight of the black pieces is more than the weight of the white pieces and print "Draw" if the weights of the white and black pieces are equal.
Examples
Input
...QK...
........
........
........
........
........
........
...rk...
Output
White
Input
rnbqkbnr
pppppppp
........
........
........
........
PPPPPPPP
RNBQKBNR
Output
Draw
Input
rppppppr
...k....
........
........
........
........
K...Q...
........
Output
Black
Note
In the first test sample the weight of the position of the white pieces equals to 9, the weight of the position of the black pieces equals 5.
In the second test sample the weights of the positions of the black and the white pieces are equal to 39.
In the third test sample the weight of the position of the white pieces equals to 9, the weight of the position of the black pieces equals to 16. | instruction | 0 | 40,764 | 19 | 81,528 |
Tags: implementation
Correct Solution:
```
T_ON = 0
DEBUG_ON = 1
MOD = 998244353
def solve():
G = {'q': 9, 'r': 5, 'b': 3, 'n': 3, 'p': 1}
white = 0
black = 0
for i in range(8):
for c in input():
w = G.get(c.lower(), 0)
if c.isupper():
white += w
else:
black += w
if white > black:
print("White")
elif white < black:
print("Black")
else:
print("Draw")
def main():
T = read_int() if T_ON else 1
for i in range(T):
solve()
def debug(*xargs):
if DEBUG_ON:
print(*xargs)
from collections import *
import math
#---------------------------------FAST_IO---------------------------------------
import os
import sys
from io import BytesIO, IOBase
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
#----------------------------------IO_WRAP--------------------------------------
def read_int():
return int(input())
def read_ints():
return list(map(int, input().split()))
def print_nums(nums):
print(" ".join(map(str, nums)))
def YES():
print("YES")
def Yes():
print("Yes")
def NO():
print("NO")
def No():
print("No")
def First():
print("First")
def Second():
print("Second")
#----------------------------------FIB--------------------------------------
def fib(n):
"""
the nth fib, start from zero
"""
a, b = 0, 1
for _ in range(n):
a, b = b, a + b
return a
def fib_ns(n):
"""
the first n fibs, start from zero
"""
assert n >= 1
f = [0 for _ in range(n + 1)]
f[0] = 0
f[1] = 1
for i in range(2, n + 1):
f[i] = f[i - 1] + f[i - 2]
return f
def fib_to_n(n):
"""
return fibs <= n, start from zero
n=8
f=[0,1,1,2,3,5,8]
"""
f = []
a, b = 0, 1
while a <= n:
f.append(a)
a, b = b, a + b
return f
#----------------------------------MOD--------------------------------------
def gcd(a, b):
if a == 0:
return b
return gcd(b % a, a)
def xgcd(a, b):
"""return (g, x, y) such that a*x + b*y = g = gcd(a, b)"""
x0, x1, y0, y1 = 0, 1, 1, 0
while a != 0:
(q, a), b = divmod(b, a), a
y0, y1 = y1, y0 - q * y1
x0, x1 = x1, x0 - q * x1
return b, x0, y0
def lcm(a, b):
d = gcd(a, b)
return a * b // d
def is_even(x):
return x % 2 == 0
def is_odd(x):
return x % 2 == 1
def modinv(a, m):
"""return x such that (a * x) % m == 1"""
g, x, _ = xgcd(a, m)
if g != 1:
raise Exception('gcd(a, m) != 1')
return x % m
def mod_add(x, y):
x += y
while x >= MOD:
x -= MOD
while x < 0:
x += MOD
return x
def mod_mul(x, y):
return (x * y) % MOD
def mod_pow(x, y):
if y == 0:
return 1
if y % 2:
return mod_mul(x, mod_pow(x, y - 1))
p = mod_pow(x, y // 2)
return mod_mul(p, p)
def mod_inv(y):
return mod_pow(y, MOD - 2)
def mod_div(x, y):
# y^(-1): Fermat little theorem, MOD is a prime
return mod_mul(x, mod_inv(y))
#---------------------------------PRIME---------------------------------------
def is_prime(n):
if n == 1:
return False
for i in range(2, int(n ** 0.5) + 1):
if n % i:
return False
return True
def gen_primes(n):
"""
generate primes of [1..n] using sieve's method
"""
P = [True for _ in range(n + 1)]
P[0] = P[1] = False
for i in range(int(n ** 0.5) + 1):
if P[i]:
for j in range(2 * i, n + 1, i):
P[j] = False
return P
#---------------------------------MISC---------------------------------------
def is_lucky(n):
return set(list(str(n))).issubset({'4', '7'})
#---------------------------------MAIN---------------------------------------
main()
``` | output | 1 | 40,764 | 19 | 81,529 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A and B are preparing themselves for programming contests.
To train their logical thinking and solve problems better, A and B decided to play chess. During the game A wondered whose position is now stronger.
For each chess piece we know its weight:
* the queen's weight is 9,
* the rook's weight is 5,
* the bishop's weight is 3,
* the knight's weight is 3,
* the pawn's weight is 1,
* the king's weight isn't considered in evaluating position.
The player's weight equals to the sum of weights of all his pieces on the board.
As A doesn't like counting, he asked you to help him determine which player has the larger position weight.
Input
The input contains eight lines, eight characters each โ the board's description.
The white pieces on the board are marked with uppercase letters, the black pieces are marked with lowercase letters.
The white pieces are denoted as follows: the queen is represented is 'Q', the rook โ as 'R', the bishop โ as'B', the knight โ as 'N', the pawn โ as 'P', the king โ as 'K'.
The black pieces are denoted as 'q', 'r', 'b', 'n', 'p', 'k', respectively.
An empty square of the board is marked as '.' (a dot).
It is not guaranteed that the given chess position can be achieved in a real game. Specifically, there can be an arbitrary (possibly zero) number pieces of each type, the king may be under attack and so on.
Output
Print "White" (without quotes) if the weight of the position of the white pieces is more than the weight of the position of the black pieces, print "Black" if the weight of the black pieces is more than the weight of the white pieces and print "Draw" if the weights of the white and black pieces are equal.
Examples
Input
...QK...
........
........
........
........
........
........
...rk...
Output
White
Input
rnbqkbnr
pppppppp
........
........
........
........
PPPPPPPP
RNBQKBNR
Output
Draw
Input
rppppppr
...k....
........
........
........
........
K...Q...
........
Output
Black
Note
In the first test sample the weight of the position of the white pieces equals to 9, the weight of the position of the black pieces equals 5.
In the second test sample the weights of the positions of the black and the white pieces are equal to 39.
In the third test sample the weight of the position of the white pieces equals to 9, the weight of the position of the black pieces equals to 16. | instruction | 0 | 40,765 | 19 | 81,530 |
Tags: implementation
Correct Solution:
```
whiteWeight=blackWeight=0
whitePieces = {'Q':9, 'R':5, 'B':3, 'N':3, 'P':1}
blackPieces = {'q':9, 'r':5, 'b':3, 'n':3, 'p':1}
for i in range(8):
x = list(input())
for y in x:
if y in whitePieces:
whiteWeight += whitePieces[y]
elif y in blackPieces:
blackWeight += blackPieces[y]
if whiteWeight > blackWeight:
print('White')
elif whiteWeight < blackWeight:
print('Black')
else:
print('Draw')
``` | output | 1 | 40,765 | 19 | 81,531 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A and B are preparing themselves for programming contests.
To train their logical thinking and solve problems better, A and B decided to play chess. During the game A wondered whose position is now stronger.
For each chess piece we know its weight:
* the queen's weight is 9,
* the rook's weight is 5,
* the bishop's weight is 3,
* the knight's weight is 3,
* the pawn's weight is 1,
* the king's weight isn't considered in evaluating position.
The player's weight equals to the sum of weights of all his pieces on the board.
As A doesn't like counting, he asked you to help him determine which player has the larger position weight.
Input
The input contains eight lines, eight characters each โ the board's description.
The white pieces on the board are marked with uppercase letters, the black pieces are marked with lowercase letters.
The white pieces are denoted as follows: the queen is represented is 'Q', the rook โ as 'R', the bishop โ as'B', the knight โ as 'N', the pawn โ as 'P', the king โ as 'K'.
The black pieces are denoted as 'q', 'r', 'b', 'n', 'p', 'k', respectively.
An empty square of the board is marked as '.' (a dot).
It is not guaranteed that the given chess position can be achieved in a real game. Specifically, there can be an arbitrary (possibly zero) number pieces of each type, the king may be under attack and so on.
Output
Print "White" (without quotes) if the weight of the position of the white pieces is more than the weight of the position of the black pieces, print "Black" if the weight of the black pieces is more than the weight of the white pieces and print "Draw" if the weights of the white and black pieces are equal.
Examples
Input
...QK...
........
........
........
........
........
........
...rk...
Output
White
Input
rnbqkbnr
pppppppp
........
........
........
........
PPPPPPPP
RNBQKBNR
Output
Draw
Input
rppppppr
...k....
........
........
........
........
K...Q...
........
Output
Black
Note
In the first test sample the weight of the position of the white pieces equals to 9, the weight of the position of the black pieces equals 5.
In the second test sample the weights of the positions of the black and the white pieces are equal to 39.
In the third test sample the weight of the position of the white pieces equals to 9, the weight of the position of the black pieces equals to 16. | instruction | 0 | 40,766 | 19 | 81,532 |
Tags: implementation
Correct Solution:
```
b = 0
w = 0
for k in range(8):
inp = input()
for i in range(len(inp)):
if(inp[i]=='Q'):
w += 9
elif(inp[i]=='q'):
b += 9
elif(inp[i]=='R'):
w += 5
elif(inp[i]=='P'):
w += 1
elif(inp[i]=='B' or inp[i]=='N'):
w += 3
elif(inp[i]=='r'):
b += 5
elif(inp[i]=='p'):
b += 1
elif(inp[i]=='b' or inp[i]=='n'):
b += 3
else:
b = b
if(w>b):
print("White")
elif(w==b):
print("Draw")
else:
print("Black")
``` | output | 1 | 40,766 | 19 | 81,533 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A and B are preparing themselves for programming contests.
To train their logical thinking and solve problems better, A and B decided to play chess. During the game A wondered whose position is now stronger.
For each chess piece we know its weight:
* the queen's weight is 9,
* the rook's weight is 5,
* the bishop's weight is 3,
* the knight's weight is 3,
* the pawn's weight is 1,
* the king's weight isn't considered in evaluating position.
The player's weight equals to the sum of weights of all his pieces on the board.
As A doesn't like counting, he asked you to help him determine which player has the larger position weight.
Input
The input contains eight lines, eight characters each โ the board's description.
The white pieces on the board are marked with uppercase letters, the black pieces are marked with lowercase letters.
The white pieces are denoted as follows: the queen is represented is 'Q', the rook โ as 'R', the bishop โ as'B', the knight โ as 'N', the pawn โ as 'P', the king โ as 'K'.
The black pieces are denoted as 'q', 'r', 'b', 'n', 'p', 'k', respectively.
An empty square of the board is marked as '.' (a dot).
It is not guaranteed that the given chess position can be achieved in a real game. Specifically, there can be an arbitrary (possibly zero) number pieces of each type, the king may be under attack and so on.
Output
Print "White" (without quotes) if the weight of the position of the white pieces is more than the weight of the position of the black pieces, print "Black" if the weight of the black pieces is more than the weight of the white pieces and print "Draw" if the weights of the white and black pieces are equal.
Examples
Input
...QK...
........
........
........
........
........
........
...rk...
Output
White
Input
rnbqkbnr
pppppppp
........
........
........
........
PPPPPPPP
RNBQKBNR
Output
Draw
Input
rppppppr
...k....
........
........
........
........
K...Q...
........
Output
Black
Note
In the first test sample the weight of the position of the white pieces equals to 9, the weight of the position of the black pieces equals 5.
In the second test sample the weights of the positions of the black and the white pieces are equal to 39.
In the third test sample the weight of the position of the white pieces equals to 9, the weight of the position of the black pieces equals to 16. | instruction | 0 | 40,767 | 19 | 81,534 |
Tags: implementation
Correct Solution:
```
weights = {'Q': 9, 'R': 5, 'B': 3, 'N': 3, 'P': 1}
chess = ""
white = 0
black = 0
for i in range(8):
chess += input()
for key in weights.keys():
white += weights.get(key) * chess.count(key)
black += weights.get(key) * chess.count(key.lower())
if white > black:
print("White")
elif white < black:
print("Black")
else:
print("Draw")
``` | output | 1 | 40,767 | 19 | 81,535 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A and B are preparing themselves for programming contests.
To train their logical thinking and solve problems better, A and B decided to play chess. During the game A wondered whose position is now stronger.
For each chess piece we know its weight:
* the queen's weight is 9,
* the rook's weight is 5,
* the bishop's weight is 3,
* the knight's weight is 3,
* the pawn's weight is 1,
* the king's weight isn't considered in evaluating position.
The player's weight equals to the sum of weights of all his pieces on the board.
As A doesn't like counting, he asked you to help him determine which player has the larger position weight.
Input
The input contains eight lines, eight characters each โ the board's description.
The white pieces on the board are marked with uppercase letters, the black pieces are marked with lowercase letters.
The white pieces are denoted as follows: the queen is represented is 'Q', the rook โ as 'R', the bishop โ as'B', the knight โ as 'N', the pawn โ as 'P', the king โ as 'K'.
The black pieces are denoted as 'q', 'r', 'b', 'n', 'p', 'k', respectively.
An empty square of the board is marked as '.' (a dot).
It is not guaranteed that the given chess position can be achieved in a real game. Specifically, there can be an arbitrary (possibly zero) number pieces of each type, the king may be under attack and so on.
Output
Print "White" (without quotes) if the weight of the position of the white pieces is more than the weight of the position of the black pieces, print "Black" if the weight of the black pieces is more than the weight of the white pieces and print "Draw" if the weights of the white and black pieces are equal.
Examples
Input
...QK...
........
........
........
........
........
........
...rk...
Output
White
Input
rnbqkbnr
pppppppp
........
........
........
........
PPPPPPPP
RNBQKBNR
Output
Draw
Input
rppppppr
...k....
........
........
........
........
K...Q...
........
Output
Black
Note
In the first test sample the weight of the position of the white pieces equals to 9, the weight of the position of the black pieces equals 5.
In the second test sample the weights of the positions of the black and the white pieces are equal to 39.
In the third test sample the weight of the position of the white pieces equals to 9, the weight of the position of the black pieces equals to 16. | instruction | 0 | 40,768 | 19 | 81,536 |
Tags: implementation
Correct Solution:
```
sumwhite = 0
sumblack = 0
for n in range(8):
line = input()
for ch in line:
if ch == '.':
continue
elif ch == 'Q':
sumwhite += 9
elif ch == 'R':
sumwhite += 5
elif ch == 'B':
sumwhite += 3
elif ch == 'N':
sumwhite += 3
elif ch == 'P':
sumwhite += 1
elif ch == 'q':
sumblack += 9
elif ch == 'r':
sumblack += 5
elif ch == 'b':
sumblack += 3
elif ch == 'n':
sumblack += 3
elif ch == 'p':
sumblack += 1
if sumblack > sumwhite:
print ('Black')
elif sumblack == sumwhite:
print ('Draw')
else:
print ('White')
``` | output | 1 | 40,768 | 19 | 81,537 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A and B are preparing themselves for programming contests.
To train their logical thinking and solve problems better, A and B decided to play chess. During the game A wondered whose position is now stronger.
For each chess piece we know its weight:
* the queen's weight is 9,
* the rook's weight is 5,
* the bishop's weight is 3,
* the knight's weight is 3,
* the pawn's weight is 1,
* the king's weight isn't considered in evaluating position.
The player's weight equals to the sum of weights of all his pieces on the board.
As A doesn't like counting, he asked you to help him determine which player has the larger position weight.
Input
The input contains eight lines, eight characters each โ the board's description.
The white pieces on the board are marked with uppercase letters, the black pieces are marked with lowercase letters.
The white pieces are denoted as follows: the queen is represented is 'Q', the rook โ as 'R', the bishop โ as'B', the knight โ as 'N', the pawn โ as 'P', the king โ as 'K'.
The black pieces are denoted as 'q', 'r', 'b', 'n', 'p', 'k', respectively.
An empty square of the board is marked as '.' (a dot).
It is not guaranteed that the given chess position can be achieved in a real game. Specifically, there can be an arbitrary (possibly zero) number pieces of each type, the king may be under attack and so on.
Output
Print "White" (without quotes) if the weight of the position of the white pieces is more than the weight of the position of the black pieces, print "Black" if the weight of the black pieces is more than the weight of the white pieces and print "Draw" if the weights of the white and black pieces are equal.
Examples
Input
...QK...
........
........
........
........
........
........
...rk...
Output
White
Input
rnbqkbnr
pppppppp
........
........
........
........
PPPPPPPP
RNBQKBNR
Output
Draw
Input
rppppppr
...k....
........
........
........
........
K...Q...
........
Output
Black
Note
In the first test sample the weight of the position of the white pieces equals to 9, the weight of the position of the black pieces equals 5.
In the second test sample the weights of the positions of the black and the white pieces are equal to 39.
In the third test sample the weight of the position of the white pieces equals to 9, the weight of the position of the black pieces equals to 16. | instruction | 0 | 40,769 | 19 | 81,538 |
Tags: implementation
Correct Solution:
```
desk = []
for test in range(8):
test = list(input())
desk += test
white = 0
black = 0
for j in desk:
if 'Q' in j:
white += 9
if 'R' in j:
white += 5
if 'B' in j:
white += 3
if 'N' in j:
white += 3
if 'P' in j:
white += 1
if 'q' in j:
black += 9
if 'r' in j:
black += 5
if 'b' in j:
black += 3
if 'n' in j:
black += 3
if 'p' in j:
black += 1
if white > black:
print('White')
elif black > white:
print('Black')
else:
print('Draw')
``` | output | 1 | 40,769 | 19 | 81,539 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A and B are preparing themselves for programming contests.
To train their logical thinking and solve problems better, A and B decided to play chess. During the game A wondered whose position is now stronger.
For each chess piece we know its weight:
* the queen's weight is 9,
* the rook's weight is 5,
* the bishop's weight is 3,
* the knight's weight is 3,
* the pawn's weight is 1,
* the king's weight isn't considered in evaluating position.
The player's weight equals to the sum of weights of all his pieces on the board.
As A doesn't like counting, he asked you to help him determine which player has the larger position weight.
Input
The input contains eight lines, eight characters each โ the board's description.
The white pieces on the board are marked with uppercase letters, the black pieces are marked with lowercase letters.
The white pieces are denoted as follows: the queen is represented is 'Q', the rook โ as 'R', the bishop โ as'B', the knight โ as 'N', the pawn โ as 'P', the king โ as 'K'.
The black pieces are denoted as 'q', 'r', 'b', 'n', 'p', 'k', respectively.
An empty square of the board is marked as '.' (a dot).
It is not guaranteed that the given chess position can be achieved in a real game. Specifically, there can be an arbitrary (possibly zero) number pieces of each type, the king may be under attack and so on.
Output
Print "White" (without quotes) if the weight of the position of the white pieces is more than the weight of the position of the black pieces, print "Black" if the weight of the black pieces is more than the weight of the white pieces and print "Draw" if the weights of the white and black pieces are equal.
Examples
Input
...QK...
........
........
........
........
........
........
...rk...
Output
White
Input
rnbqkbnr
pppppppp
........
........
........
........
PPPPPPPP
RNBQKBNR
Output
Draw
Input
rppppppr
...k....
........
........
........
........
K...Q...
........
Output
Black
Note
In the first test sample the weight of the position of the white pieces equals to 9, the weight of the position of the black pieces equals 5.
In the second test sample the weights of the positions of the black and the white pieces are equal to 39.
In the third test sample the weight of the position of the white pieces equals to 9, the weight of the position of the black pieces equals to 16. | instruction | 0 | 40,770 | 19 | 81,540 |
Tags: implementation
Correct Solution:
```
white = 0
black = 0
d = {'Q' : 9 , 'R' : 5, 'B' : 3, 'N' : 3, 'P' : 1, 'K' : 0}
for _ in range (8):
s = input()
for i in s:
if(i != '.'):
if(i==i.upper()): white += d[i]
else: black += d[i.upper()]
if(white > black): print('White')
elif(white == black): print('Draw')
else: print('Black')
``` | output | 1 | 40,770 | 19 | 81,541 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A and B are preparing themselves for programming contests.
To train their logical thinking and solve problems better, A and B decided to play chess. During the game A wondered whose position is now stronger.
For each chess piece we know its weight:
* the queen's weight is 9,
* the rook's weight is 5,
* the bishop's weight is 3,
* the knight's weight is 3,
* the pawn's weight is 1,
* the king's weight isn't considered in evaluating position.
The player's weight equals to the sum of weights of all his pieces on the board.
As A doesn't like counting, he asked you to help him determine which player has the larger position weight.
Input
The input contains eight lines, eight characters each โ the board's description.
The white pieces on the board are marked with uppercase letters, the black pieces are marked with lowercase letters.
The white pieces are denoted as follows: the queen is represented is 'Q', the rook โ as 'R', the bishop โ as'B', the knight โ as 'N', the pawn โ as 'P', the king โ as 'K'.
The black pieces are denoted as 'q', 'r', 'b', 'n', 'p', 'k', respectively.
An empty square of the board is marked as '.' (a dot).
It is not guaranteed that the given chess position can be achieved in a real game. Specifically, there can be an arbitrary (possibly zero) number pieces of each type, the king may be under attack and so on.
Output
Print "White" (without quotes) if the weight of the position of the white pieces is more than the weight of the position of the black pieces, print "Black" if the weight of the black pieces is more than the weight of the white pieces and print "Draw" if the weights of the white and black pieces are equal.
Examples
Input
...QK...
........
........
........
........
........
........
...rk...
Output
White
Input
rnbqkbnr
pppppppp
........
........
........
........
PPPPPPPP
RNBQKBNR
Output
Draw
Input
rppppppr
...k....
........
........
........
........
K...Q...
........
Output
Black
Note
In the first test sample the weight of the position of the white pieces equals to 9, the weight of the position of the black pieces equals 5.
In the second test sample the weights of the positions of the black and the white pieces are equal to 39.
In the third test sample the weight of the position of the white pieces equals to 9, the weight of the position of the black pieces equals to 16.
Submitted Solution:
```
w = dict()
b = dict()
w['Q'] = 9
w['R'] = 5
w['B'] = 3
w['N'] = 3
w['P'] = 1
b['q'] = 9
b['r'] = 5
b['b'] = 3
b['n'] = 3
b['p'] = 1
n = 8
m = 8
white = 0
black = 0
for i in range(n):
s = input()
for i in s:
if i in w:
white += w[i]
if i in b:
black += b[i]
if white > black:
print('White')
if black > white:
print('Black')
if white == black:
print('Draw')
``` | instruction | 0 | 40,771 | 19 | 81,542 |
Yes | output | 1 | 40,771 | 19 | 81,543 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.