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. Quickly after finishing the tutorial of the online game ATChat, you have decided to visit a particular place with N-1 players who happen to be there. These N players, including you, are numbered 1 through N, and the friendliness of Player i is A_i. The N players will arrive at the place one by one in some order. To make sure nobody gets lost, you have set the following rule: players who have already arrived there should form a circle, and a player who has just arrived there should cut into the circle somewhere. When each player, except the first one to arrive, arrives at the place, the player gets comfort equal to the smaller of the friendliness of the clockwise adjacent player and that of the counter-clockwise adjacent player. The first player to arrive there gets the comfort of 0. What is the maximum total comfort the N players can get by optimally choosing the order of arrivals and the positions in the circle to cut into? Constraints * All values in input are integers. * 2 \leq N \leq 2 \times 10^5 * 1 \leq A_i \leq 10^9 Input Input is given from Standard Input in the following format: N A_1 A_2 \dots A_N Output Print the maximum total comfort the N players can get. Examples Input 4 2 2 1 3 Output 7 Input 7 1 1 1 1 1 1 1 Output 6 Submitted Solution: ``` n = int(input()) a = sorted(map(int, input().split())) comfort = a[-1] for i in range(n-2): comfort += a[-2-i//2] print(comfort) ```
instruction
0
29,752
19
59,504
Yes
output
1
29,752
19
59,505
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Quickly after finishing the tutorial of the online game ATChat, you have decided to visit a particular place with N-1 players who happen to be there. These N players, including you, are numbered 1 through N, and the friendliness of Player i is A_i. The N players will arrive at the place one by one in some order. To make sure nobody gets lost, you have set the following rule: players who have already arrived there should form a circle, and a player who has just arrived there should cut into the circle somewhere. When each player, except the first one to arrive, arrives at the place, the player gets comfort equal to the smaller of the friendliness of the clockwise adjacent player and that of the counter-clockwise adjacent player. The first player to arrive there gets the comfort of 0. What is the maximum total comfort the N players can get by optimally choosing the order of arrivals and the positions in the circle to cut into? Constraints * All values in input are integers. * 2 \leq N \leq 2 \times 10^5 * 1 \leq A_i \leq 10^9 Input Input is given from Standard Input in the following format: N A_1 A_2 \dots A_N Output Print the maximum total comfort the N players can get. Examples Input 4 2 2 1 3 Output 7 Input 7 1 1 1 1 1 1 1 Output 6 Submitted Solution: ``` n,*a=map(int,open(0).read().split());print(sum(sorted(a*2)[-n:-1])) ```
instruction
0
29,753
19
59,506
Yes
output
1
29,753
19
59,507
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Quickly after finishing the tutorial of the online game ATChat, you have decided to visit a particular place with N-1 players who happen to be there. These N players, including you, are numbered 1 through N, and the friendliness of Player i is A_i. The N players will arrive at the place one by one in some order. To make sure nobody gets lost, you have set the following rule: players who have already arrived there should form a circle, and a player who has just arrived there should cut into the circle somewhere. When each player, except the first one to arrive, arrives at the place, the player gets comfort equal to the smaller of the friendliness of the clockwise adjacent player and that of the counter-clockwise adjacent player. The first player to arrive there gets the comfort of 0. What is the maximum total comfort the N players can get by optimally choosing the order of arrivals and the positions in the circle to cut into? Constraints * All values in input are integers. * 2 \leq N \leq 2 \times 10^5 * 1 \leq A_i \leq 10^9 Input Input is given from Standard Input in the following format: N A_1 A_2 \dots A_N Output Print the maximum total comfort the N players can get. Examples Input 4 2 2 1 3 Output 7 Input 7 1 1 1 1 1 1 1 Output 6 Submitted Solution: ``` n = int(input()) a = list(map(int,input().split())) a.sort(reverse = True) ans = a[0] for i in range(n-2): ans += a[i//2+1] print(ans) ```
instruction
0
29,754
19
59,508
Yes
output
1
29,754
19
59,509
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Quickly after finishing the tutorial of the online game ATChat, you have decided to visit a particular place with N-1 players who happen to be there. These N players, including you, are numbered 1 through N, and the friendliness of Player i is A_i. The N players will arrive at the place one by one in some order. To make sure nobody gets lost, you have set the following rule: players who have already arrived there should form a circle, and a player who has just arrived there should cut into the circle somewhere. When each player, except the first one to arrive, arrives at the place, the player gets comfort equal to the smaller of the friendliness of the clockwise adjacent player and that of the counter-clockwise adjacent player. The first player to arrive there gets the comfort of 0. What is the maximum total comfort the N players can get by optimally choosing the order of arrivals and the positions in the circle to cut into? Constraints * All values in input are integers. * 2 \leq N \leq 2 \times 10^5 * 1 \leq A_i \leq 10^9 Input Input is given from Standard Input in the following format: N A_1 A_2 \dots A_N Output Print the maximum total comfort the N players can get. Examples Input 4 2 2 1 3 Output 7 Input 7 1 1 1 1 1 1 1 Output 6 Submitted Solution: ``` import sys from io import StringIO import unittest import os import heapq # 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む) sys.setrecursionlimit(999999999) # 実装を行う関数 def resolve(test_def_name=""): n = int(input()) a_s = list(map(int, input().split())) a_s.sort(reverse=True) que = [] heapq.heapify(que) ans = 0 for cnt, a in enumerate(a_s): if cnt == 0: heapq.heappush(que, a) else: # キューから値の取り出し target = heapq.heappop(que) ans += target heapq.heappush(que, a) heapq.heappush(que, a) print(ans) # テストクラス class TestClass(unittest.TestCase): def assertIO(self, assert_input, output): stdout, sat_in = sys.stdout, sys.stdin sys.stdout, sys.stdin = StringIO(), StringIO(assert_input) resolve(sys._getframe().f_back.f_code.co_name) sys.stdout.seek(0) out = sys.stdout.read()[:-1] sys.stdout, sys.stdin = stdout, sat_in self.assertEqual(out, output) def test_input_1(self): test_input = """4 2 2 1 3""" output = """7""" self.assertIO(test_input, output) def test_input_2(self): test_input = """7 1 1 1 1 1 1 1""" output = """6""" self.assertIO(test_input, output) # 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること def tes_t_1original_1(self): test_input = """データ""" output = """データ""" self.assertIO(test_input, output) # 実装orテストの呼び出し if __name__ == "__main__": if os.environ.get("USERNAME") is None: # AtCoder提出時の場合 resolve() else: # 自PCの場合 unittest.main() ```
instruction
0
29,755
19
59,510
No
output
1
29,755
19
59,511
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Quickly after finishing the tutorial of the online game ATChat, you have decided to visit a particular place with N-1 players who happen to be there. These N players, including you, are numbered 1 through N, and the friendliness of Player i is A_i. The N players will arrive at the place one by one in some order. To make sure nobody gets lost, you have set the following rule: players who have already arrived there should form a circle, and a player who has just arrived there should cut into the circle somewhere. When each player, except the first one to arrive, arrives at the place, the player gets comfort equal to the smaller of the friendliness of the clockwise adjacent player and that of the counter-clockwise adjacent player. The first player to arrive there gets the comfort of 0. What is the maximum total comfort the N players can get by optimally choosing the order of arrivals and the positions in the circle to cut into? Constraints * All values in input are integers. * 2 \leq N \leq 2 \times 10^5 * 1 \leq A_i \leq 10^9 Input Input is given from Standard Input in the following format: N A_1 A_2 \dots A_N Output Print the maximum total comfort the N players can get. Examples Input 4 2 2 1 3 Output 7 Input 7 1 1 1 1 1 1 1 Output 6 Submitted Solution: ``` N = int(input()) A = list(map(int, input().split())) A.sort(reverse = True) Sum = 0 for i in range(len(A)): if i == 0: pass elif i == 1: Sum += A.pop(0) else: if i % 2 == 0: Sum += A[0] else: Sum += A.pop(0) print(Sum) ```
instruction
0
29,756
19
59,512
No
output
1
29,756
19
59,513
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Quickly after finishing the tutorial of the online game ATChat, you have decided to visit a particular place with N-1 players who happen to be there. These N players, including you, are numbered 1 through N, and the friendliness of Player i is A_i. The N players will arrive at the place one by one in some order. To make sure nobody gets lost, you have set the following rule: players who have already arrived there should form a circle, and a player who has just arrived there should cut into the circle somewhere. When each player, except the first one to arrive, arrives at the place, the player gets comfort equal to the smaller of the friendliness of the clockwise adjacent player and that of the counter-clockwise adjacent player. The first player to arrive there gets the comfort of 0. What is the maximum total comfort the N players can get by optimally choosing the order of arrivals and the positions in the circle to cut into? Constraints * All values in input are integers. * 2 \leq N \leq 2 \times 10^5 * 1 \leq A_i \leq 10^9 Input Input is given from Standard Input in the following format: N A_1 A_2 \dots A_N Output Print the maximum total comfort the N players can get. Examples Input 4 2 2 1 3 Output 7 Input 7 1 1 1 1 1 1 1 Output 6 Submitted Solution: ``` import sys def max_comfort(array): comfort = 0 index = 0 n = len(array) if n == 0: return 0, 0 if n == 1: return array[0], 0 for i in range(n): if i < n - 1: if comfort < min(array[i], array[i + 1]): comfort = min(array[i], array[i + 1]) index = i + 1 else: if comfort < min(array[i], array[0]): comfort = min(array[i], array[0]) index = 0 return comfort, index def main(): input = sys.stdin.buffer.readline n = int(input()) a = list(map(int, input().split())) a.sort(reverse=True) round = [] ans = 0 for f in a: comfort, index = max_comfort(round) ans += comfort round.insert(index, f) print(ans) if __name__ == '__main__': main() ```
instruction
0
29,757
19
59,514
No
output
1
29,757
19
59,515
Provide a correct Python 3 solution for this coding contest problem. Two foxes Jiro and Saburo are playing a game called 1D Reversi. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original game of Reversi, when a white stone is placed, all black stones between the new white stone and another white stone, turn into white stones, and vice versa. In the middle of a game, something came up and Saburo has to leave the game. The state of the board at this point is described by a string S. There are |S| (the length of S) stones on the board, and each character in S represents the color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in S is `B`, it means that the color of the corresponding stone on the board is black. Similarly, if the i-th character in S is `W`, it means that the color of the corresponding stone is white. Jiro wants all stones on the board to be of the same color. For this purpose, he will place new stones on the board according to the rules. Find the minimum number of new stones that he needs to place. Constraints * 1 ≦ |S| ≦ 10^5 * Each character in S is `B` or `W`. Input The input is given from Standard Input in the following format: S Output Print the minimum number of new stones that Jiro needs to place for his purpose. Examples Input BBBWW Output 1 Input WWWWWW Output 0 Input WBWBWBWBWB Output 9
instruction
0
29,883
19
59,766
"Correct Solution: ``` s = input() ex = s[0] count = 0 for c in s: if c!= ex: count +=1 ex = c print(count) ```
output
1
29,883
19
59,767
Provide a correct Python 3 solution for this coding contest problem. Two foxes Jiro and Saburo are playing a game called 1D Reversi. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original game of Reversi, when a white stone is placed, all black stones between the new white stone and another white stone, turn into white stones, and vice versa. In the middle of a game, something came up and Saburo has to leave the game. The state of the board at this point is described by a string S. There are |S| (the length of S) stones on the board, and each character in S represents the color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in S is `B`, it means that the color of the corresponding stone on the board is black. Similarly, if the i-th character in S is `W`, it means that the color of the corresponding stone is white. Jiro wants all stones on the board to be of the same color. For this purpose, he will place new stones on the board according to the rules. Find the minimum number of new stones that he needs to place. Constraints * 1 ≦ |S| ≦ 10^5 * Each character in S is `B` or `W`. Input The input is given from Standard Input in the following format: S Output Print the minimum number of new stones that Jiro needs to place for his purpose. Examples Input BBBWW Output 1 Input WWWWWW Output 0 Input WBWBWBWBWB Output 9
instruction
0
29,884
19
59,768
"Correct Solution: ``` from itertools import groupby print(len([k for k,v in groupby(input())])-1) ```
output
1
29,884
19
59,769
Provide a correct Python 3 solution for this coding contest problem. Two foxes Jiro and Saburo are playing a game called 1D Reversi. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original game of Reversi, when a white stone is placed, all black stones between the new white stone and another white stone, turn into white stones, and vice versa. In the middle of a game, something came up and Saburo has to leave the game. The state of the board at this point is described by a string S. There are |S| (the length of S) stones on the board, and each character in S represents the color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in S is `B`, it means that the color of the corresponding stone on the board is black. Similarly, if the i-th character in S is `W`, it means that the color of the corresponding stone is white. Jiro wants all stones on the board to be of the same color. For this purpose, he will place new stones on the board according to the rules. Find the minimum number of new stones that he needs to place. Constraints * 1 ≦ |S| ≦ 10^5 * Each character in S is `B` or `W`. Input The input is given from Standard Input in the following format: S Output Print the minimum number of new stones that Jiro needs to place for his purpose. Examples Input BBBWW Output 1 Input WWWWWW Output 0 Input WBWBWBWBWB Output 9
instruction
0
29,885
19
59,770
"Correct Solution: ``` s = input() print(sum(s[i] != s[i + 1] for i in range(len(s)-1))) ```
output
1
29,885
19
59,771
Provide a correct Python 3 solution for this coding contest problem. Two foxes Jiro and Saburo are playing a game called 1D Reversi. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original game of Reversi, when a white stone is placed, all black stones between the new white stone and another white stone, turn into white stones, and vice versa. In the middle of a game, something came up and Saburo has to leave the game. The state of the board at this point is described by a string S. There are |S| (the length of S) stones on the board, and each character in S represents the color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in S is `B`, it means that the color of the corresponding stone on the board is black. Similarly, if the i-th character in S is `W`, it means that the color of the corresponding stone is white. Jiro wants all stones on the board to be of the same color. For this purpose, he will place new stones on the board according to the rules. Find the minimum number of new stones that he needs to place. Constraints * 1 ≦ |S| ≦ 10^5 * Each character in S is `B` or `W`. Input The input is given from Standard Input in the following format: S Output Print the minimum number of new stones that Jiro needs to place for his purpose. Examples Input BBBWW Output 1 Input WWWWWW Output 0 Input WBWBWBWBWB Output 9
instruction
0
29,886
19
59,772
"Correct Solution: ``` s = input() c = sum(1 for i in range(len(s) - 1) if s[i] != s[i + 1]) print(c) ```
output
1
29,886
19
59,773
Provide a correct Python 3 solution for this coding contest problem. Two foxes Jiro and Saburo are playing a game called 1D Reversi. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original game of Reversi, when a white stone is placed, all black stones between the new white stone and another white stone, turn into white stones, and vice versa. In the middle of a game, something came up and Saburo has to leave the game. The state of the board at this point is described by a string S. There are |S| (the length of S) stones on the board, and each character in S represents the color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in S is `B`, it means that the color of the corresponding stone on the board is black. Similarly, if the i-th character in S is `W`, it means that the color of the corresponding stone is white. Jiro wants all stones on the board to be of the same color. For this purpose, he will place new stones on the board according to the rules. Find the minimum number of new stones that he needs to place. Constraints * 1 ≦ |S| ≦ 10^5 * Each character in S is `B` or `W`. Input The input is given from Standard Input in the following format: S Output Print the minimum number of new stones that Jiro needs to place for his purpose. Examples Input BBBWW Output 1 Input WWWWWW Output 0 Input WBWBWBWBWB Output 9
instruction
0
29,887
19
59,774
"Correct Solution: ``` s=input() n=len(s) c=0 for i in range(1,n): if s[i]!=s[i-1]: c+=1 print(c) ```
output
1
29,887
19
59,775
Provide a correct Python 3 solution for this coding contest problem. Two foxes Jiro and Saburo are playing a game called 1D Reversi. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original game of Reversi, when a white stone is placed, all black stones between the new white stone and another white stone, turn into white stones, and vice versa. In the middle of a game, something came up and Saburo has to leave the game. The state of the board at this point is described by a string S. There are |S| (the length of S) stones on the board, and each character in S represents the color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in S is `B`, it means that the color of the corresponding stone on the board is black. Similarly, if the i-th character in S is `W`, it means that the color of the corresponding stone is white. Jiro wants all stones on the board to be of the same color. For this purpose, he will place new stones on the board according to the rules. Find the minimum number of new stones that he needs to place. Constraints * 1 ≦ |S| ≦ 10^5 * Each character in S is `B` or `W`. Input The input is given from Standard Input in the following format: S Output Print the minimum number of new stones that Jiro needs to place for his purpose. Examples Input BBBWW Output 1 Input WWWWWW Output 0 Input WBWBWBWBWB Output 9
instruction
0
29,888
19
59,776
"Correct Solution: ``` ans = 0 S = input() for i in range(1,len(S)): if S[i-1] != S[i]: ans += 1 print(ans) ```
output
1
29,888
19
59,777
Provide a correct Python 3 solution for this coding contest problem. Two foxes Jiro and Saburo are playing a game called 1D Reversi. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original game of Reversi, when a white stone is placed, all black stones between the new white stone and another white stone, turn into white stones, and vice versa. In the middle of a game, something came up and Saburo has to leave the game. The state of the board at this point is described by a string S. There are |S| (the length of S) stones on the board, and each character in S represents the color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in S is `B`, it means that the color of the corresponding stone on the board is black. Similarly, if the i-th character in S is `W`, it means that the color of the corresponding stone is white. Jiro wants all stones on the board to be of the same color. For this purpose, he will place new stones on the board according to the rules. Find the minimum number of new stones that he needs to place. Constraints * 1 ≦ |S| ≦ 10^5 * Each character in S is `B` or `W`. Input The input is given from Standard Input in the following format: S Output Print the minimum number of new stones that Jiro needs to place for his purpose. Examples Input BBBWW Output 1 Input WWWWWW Output 0 Input WBWBWBWBWB Output 9
instruction
0
29,889
19
59,778
"Correct Solution: ``` s = input() print(s.count("BW")+s.count("WB")) ```
output
1
29,889
19
59,779
Provide a correct Python 3 solution for this coding contest problem. Two foxes Jiro and Saburo are playing a game called 1D Reversi. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original game of Reversi, when a white stone is placed, all black stones between the new white stone and another white stone, turn into white stones, and vice versa. In the middle of a game, something came up and Saburo has to leave the game. The state of the board at this point is described by a string S. There are |S| (the length of S) stones on the board, and each character in S represents the color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in S is `B`, it means that the color of the corresponding stone on the board is black. Similarly, if the i-th character in S is `W`, it means that the color of the corresponding stone is white. Jiro wants all stones on the board to be of the same color. For this purpose, he will place new stones on the board according to the rules. Find the minimum number of new stones that he needs to place. Constraints * 1 ≦ |S| ≦ 10^5 * Each character in S is `B` or `W`. Input The input is given from Standard Input in the following format: S Output Print the minimum number of new stones that Jiro needs to place for his purpose. Examples Input BBBWW Output 1 Input WWWWWW Output 0 Input WBWBWBWBWB Output 9
instruction
0
29,890
19
59,780
"Correct Solution: ``` a=input() n=len(a) ans=0 for i in range(n-1): if a[i]!=a[i+1]: ans+=1 print(ans) ```
output
1
29,890
19
59,781
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two foxes Jiro and Saburo are playing a game called 1D Reversi. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original game of Reversi, when a white stone is placed, all black stones between the new white stone and another white stone, turn into white stones, and vice versa. In the middle of a game, something came up and Saburo has to leave the game. The state of the board at this point is described by a string S. There are |S| (the length of S) stones on the board, and each character in S represents the color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in S is `B`, it means that the color of the corresponding stone on the board is black. Similarly, if the i-th character in S is `W`, it means that the color of the corresponding stone is white. Jiro wants all stones on the board to be of the same color. For this purpose, he will place new stones on the board according to the rules. Find the minimum number of new stones that he needs to place. Constraints * 1 ≦ |S| ≦ 10^5 * Each character in S is `B` or `W`. Input The input is given from Standard Input in the following format: S Output Print the minimum number of new stones that Jiro needs to place for his purpose. Examples Input BBBWW Output 1 Input WWWWWW Output 0 Input WBWBWBWBWB Output 9 Submitted Solution: ``` A=input() cnt=0 tmp=A[0] for i in A: if tmp!=i: cnt+=1 tmp=i print(cnt) ```
instruction
0
29,891
19
59,782
Yes
output
1
29,891
19
59,783
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two foxes Jiro and Saburo are playing a game called 1D Reversi. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original game of Reversi, when a white stone is placed, all black stones between the new white stone and another white stone, turn into white stones, and vice versa. In the middle of a game, something came up and Saburo has to leave the game. The state of the board at this point is described by a string S. There are |S| (the length of S) stones on the board, and each character in S represents the color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in S is `B`, it means that the color of the corresponding stone on the board is black. Similarly, if the i-th character in S is `W`, it means that the color of the corresponding stone is white. Jiro wants all stones on the board to be of the same color. For this purpose, he will place new stones on the board according to the rules. Find the minimum number of new stones that he needs to place. Constraints * 1 ≦ |S| ≦ 10^5 * Each character in S is `B` or `W`. Input The input is given from Standard Input in the following format: S Output Print the minimum number of new stones that Jiro needs to place for his purpose. Examples Input BBBWW Output 1 Input WWWWWW Output 0 Input WBWBWBWBWB Output 9 Submitted Solution: ``` r = "" c = 0 for s in input(): if s != r: c += 1 r = s print(c - 1) ```
instruction
0
29,892
19
59,784
Yes
output
1
29,892
19
59,785
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two foxes Jiro and Saburo are playing a game called 1D Reversi. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original game of Reversi, when a white stone is placed, all black stones between the new white stone and another white stone, turn into white stones, and vice versa. In the middle of a game, something came up and Saburo has to leave the game. The state of the board at this point is described by a string S. There are |S| (the length of S) stones on the board, and each character in S represents the color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in S is `B`, it means that the color of the corresponding stone on the board is black. Similarly, if the i-th character in S is `W`, it means that the color of the corresponding stone is white. Jiro wants all stones on the board to be of the same color. For this purpose, he will place new stones on the board according to the rules. Find the minimum number of new stones that he needs to place. Constraints * 1 ≦ |S| ≦ 10^5 * Each character in S is `B` or `W`. Input The input is given from Standard Input in the following format: S Output Print the minimum number of new stones that Jiro needs to place for his purpose. Examples Input BBBWW Output 1 Input WWWWWW Output 0 Input WBWBWBWBWB Output 9 Submitted Solution: ``` s=input() n=len(s) ans=0 for i in range(n-1): if s[i+1]!=s[i]: ans+=1 print(ans) ```
instruction
0
29,893
19
59,786
Yes
output
1
29,893
19
59,787
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two foxes Jiro and Saburo are playing a game called 1D Reversi. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original game of Reversi, when a white stone is placed, all black stones between the new white stone and another white stone, turn into white stones, and vice versa. In the middle of a game, something came up and Saburo has to leave the game. The state of the board at this point is described by a string S. There are |S| (the length of S) stones on the board, and each character in S represents the color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in S is `B`, it means that the color of the corresponding stone on the board is black. Similarly, if the i-th character in S is `W`, it means that the color of the corresponding stone is white. Jiro wants all stones on the board to be of the same color. For this purpose, he will place new stones on the board according to the rules. Find the minimum number of new stones that he needs to place. Constraints * 1 ≦ |S| ≦ 10^5 * Each character in S is `B` or `W`. Input The input is given from Standard Input in the following format: S Output Print the minimum number of new stones that Jiro needs to place for his purpose. Examples Input BBBWW Output 1 Input WWWWWW Output 0 Input WBWBWBWBWB Output 9 Submitted Solution: ``` s=input() cnt=0 tmp=s[0] for x in s: if tmp!=x: cnt+=1 tmp=x print(cnt) ```
instruction
0
29,894
19
59,788
Yes
output
1
29,894
19
59,789
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two foxes Jiro and Saburo are playing a game called 1D Reversi. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original game of Reversi, when a white stone is placed, all black stones between the new white stone and another white stone, turn into white stones, and vice versa. In the middle of a game, something came up and Saburo has to leave the game. The state of the board at this point is described by a string S. There are |S| (the length of S) stones on the board, and each character in S represents the color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in S is `B`, it means that the color of the corresponding stone on the board is black. Similarly, if the i-th character in S is `W`, it means that the color of the corresponding stone is white. Jiro wants all stones on the board to be of the same color. For this purpose, he will place new stones on the board according to the rules. Find the minimum number of new stones that he needs to place. Constraints * 1 ≦ |S| ≦ 10^5 * Each character in S is `B` or `W`. Input The input is given from Standard Input in the following format: S Output Print the minimum number of new stones that Jiro needs to place for his purpose. Examples Input BBBWW Output 1 Input WWWWWW Output 0 Input WBWBWBWBWB Output 9 Submitted Solution: ``` S = input() w = S.split('B') w.remove('') b = S.split('W') b.remove('') print(len(w)+len(b)-1) ```
instruction
0
29,895
19
59,790
No
output
1
29,895
19
59,791
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two foxes Jiro and Saburo are playing a game called 1D Reversi. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original game of Reversi, when a white stone is placed, all black stones between the new white stone and another white stone, turn into white stones, and vice versa. In the middle of a game, something came up and Saburo has to leave the game. The state of the board at this point is described by a string S. There are |S| (the length of S) stones on the board, and each character in S represents the color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in S is `B`, it means that the color of the corresponding stone on the board is black. Similarly, if the i-th character in S is `W`, it means that the color of the corresponding stone is white. Jiro wants all stones on the board to be of the same color. For this purpose, he will place new stones on the board according to the rules. Find the minimum number of new stones that he needs to place. Constraints * 1 ≦ |S| ≦ 10^5 * Each character in S is `B` or `W`. Input The input is given from Standard Input in the following format: S Output Print the minimum number of new stones that Jiro needs to place for his purpose. Examples Input BBBWW Output 1 Input WWWWWW Output 0 Input WBWBWBWBWB Output 9 Submitted Solution: ``` # -*- coding: utf-8 import sys def leftside_reverse(s, turn): for num in range(len(s)): if s[num] == turn: break else: s[num] = turn return s def rightside_reverse(s, turn): for num in range(len(s) - 1, -1): if s[num] == turn: break else: s[num] = turn return s def function(s, first): count = 0 turn = first while True: if s.count(first) == len(s): break if s[0] == turn: s = rightside_reverse(s, turn) count += 1 else: s = leftside_reverse(s, turn) count += 1 if turn == 'B': turn = 'W' else: turn = 'B' return count if __name__ == '__main__': s = list(input()) b = 'B' w = 'W' if s.count(b) == len(s) or s.count(w) == len(s): print('0') else: b_count = function(s, b) w_count = function(s, w) print(min(b_count, w_count)) ```
instruction
0
29,896
19
59,792
No
output
1
29,896
19
59,793
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two foxes Jiro and Saburo are playing a game called 1D Reversi. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original game of Reversi, when a white stone is placed, all black stones between the new white stone and another white stone, turn into white stones, and vice versa. In the middle of a game, something came up and Saburo has to leave the game. The state of the board at this point is described by a string S. There are |S| (the length of S) stones on the board, and each character in S represents the color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in S is `B`, it means that the color of the corresponding stone on the board is black. Similarly, if the i-th character in S is `W`, it means that the color of the corresponding stone is white. Jiro wants all stones on the board to be of the same color. For this purpose, he will place new stones on the board according to the rules. Find the minimum number of new stones that he needs to place. Constraints * 1 ≦ |S| ≦ 10^5 * Each character in S is `B` or `W`. Input The input is given from Standard Input in the following format: S Output Print the minimum number of new stones that Jiro needs to place for his purpose. Examples Input BBBWW Output 1 Input WWWWWW Output 0 Input WBWBWBWBWB Output 9 Submitted Solution: ``` s=input() ans,i=-1,0 while i<len(s)-1: while i<len(s)-1 and s[i]==s[i+1]: i+=1 ans+=1 print(ans) ```
instruction
0
29,897
19
59,794
No
output
1
29,897
19
59,795
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two foxes Jiro and Saburo are playing a game called 1D Reversi. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original game of Reversi, when a white stone is placed, all black stones between the new white stone and another white stone, turn into white stones, and vice versa. In the middle of a game, something came up and Saburo has to leave the game. The state of the board at this point is described by a string S. There are |S| (the length of S) stones on the board, and each character in S represents the color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in S is `B`, it means that the color of the corresponding stone on the board is black. Similarly, if the i-th character in S is `W`, it means that the color of the corresponding stone is white. Jiro wants all stones on the board to be of the same color. For this purpose, he will place new stones on the board according to the rules. Find the minimum number of new stones that he needs to place. Constraints * 1 ≦ |S| ≦ 10^5 * Each character in S is `B` or `W`. Input The input is given from Standard Input in the following format: S Output Print the minimum number of new stones that Jiro needs to place for his purpose. Examples Input BBBWW Output 1 Input WWWWWW Output 0 Input WBWBWBWBWB Output 9 Submitted Solution: ``` S = input() ans = 0 if S.count('W') == 0 or S.count('B') == 0: print(0) exit() a = S[0] while True: for i, s in enumerate(S): if s != a: break S = S[i:] a = S[0] ans += 1 if S.count('W') == 0 or S.count('B') == 0:break print(ans) ```
instruction
0
29,898
19
59,796
No
output
1
29,898
19
59,797
Provide a correct Python 3 solution for this coding contest problem. Blackjack is a type of card game played in casinos, where the game is played using cards with numbers from 1 to 13. The score of each card is decided as follows. * 1 is 1 point or 11 points * From 2 to 9, the score is as written. * 10 points from 10 to 13 There are several participants in this game, including parents, each with several sets of cards. This set of cards is called a hand. The hand score is the total of the card scores. The calculation shall be performed as follows. * If the total score of the cards is greater than 21, the score of the hand is set to 0. * As the score of the card, 1 may be calculated as 1 point or 11 points, but the one with the maximum hand score shall be selected. Create a program that uses the information of the cards dealt as input and outputs the score of the hand. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format: c1 c2 ... cn The integer ci (1 ≤ ci ≤ 13) written on the i-th card is given to each line, separated by blanks. The number of cards n does not exceed 100. The number of datasets does not exceed 200. Output The score of the hand is output to one line for each data set. Example Input 1 7 7 7 7 7 8 12 1 10 1 1 0 Output 11 21 0 21 12
instruction
0
29,915
19
59,830
"Correct Solution: ``` while 1: a=list(map(int,input().split())) if a[0]==0:break b,c=0,0 for i in a: if i>=10: b+=10 else:b+=i if i==1:c+=1 while c: if b+10<=21:b+=10 c-=1 print(0 if b>21 else b) ```
output
1
29,915
19
59,831
Provide a correct Python 3 solution for this coding contest problem. Blackjack is a type of card game played in casinos, where the game is played using cards with numbers from 1 to 13. The score of each card is decided as follows. * 1 is 1 point or 11 points * From 2 to 9, the score is as written. * 10 points from 10 to 13 There are several participants in this game, including parents, each with several sets of cards. This set of cards is called a hand. The hand score is the total of the card scores. The calculation shall be performed as follows. * If the total score of the cards is greater than 21, the score of the hand is set to 0. * As the score of the card, 1 may be calculated as 1 point or 11 points, but the one with the maximum hand score shall be selected. Create a program that uses the information of the cards dealt as input and outputs the score of the hand. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format: c1 c2 ... cn The integer ci (1 ≤ ci ≤ 13) written on the i-th card is given to each line, separated by blanks. The number of cards n does not exceed 100. The number of datasets does not exceed 200. Output The score of the hand is output to one line for each data set. Example Input 1 7 7 7 7 7 8 12 1 10 1 1 0 Output 11 21 0 21 12
instruction
0
29,916
19
59,832
"Correct Solution: ``` while True: N = list(map(int, input().split())) if N[0] == 0: break total, ace = 0, 0 for n in N: if n == 1: n = 0 ace += 1 elif n >= 10: n = 10 total += n if total + ace > 21: break if total + ace > 21: print(0) elif 0 < ace and total + ace <= 11: print(total + ace + 10) else: print(total + ace) ```
output
1
29,916
19
59,833
Provide a correct Python 3 solution for this coding contest problem. Blackjack is a type of card game played in casinos, where the game is played using cards with numbers from 1 to 13. The score of each card is decided as follows. * 1 is 1 point or 11 points * From 2 to 9, the score is as written. * 10 points from 10 to 13 There are several participants in this game, including parents, each with several sets of cards. This set of cards is called a hand. The hand score is the total of the card scores. The calculation shall be performed as follows. * If the total score of the cards is greater than 21, the score of the hand is set to 0. * As the score of the card, 1 may be calculated as 1 point or 11 points, but the one with the maximum hand score shall be selected. Create a program that uses the information of the cards dealt as input and outputs the score of the hand. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format: c1 c2 ... cn The integer ci (1 ≤ ci ≤ 13) written on the i-th card is given to each line, separated by blanks. The number of cards n does not exceed 100. The number of datasets does not exceed 200. Output The score of the hand is output to one line for each data set. Example Input 1 7 7 7 7 7 8 12 1 10 1 1 0 Output 11 21 0 21 12
instruction
0
29,917
19
59,834
"Correct Solution: ``` while True: inp = input() if inp == '0': break inp = inp.replace('11', '10') inp = inp.replace('12', '10') inp = inp.replace('13', '10') cards = tuple(map(int, inp.split())) ans = sum(cards) for i in range(cards.count(1)): if sum(cards) + 10 * (i+1) > 21: break elif ans < sum(cards) + 10 * (i+1): ans = sum(cards) + 10 * (i+1) if ans > 21: ans = 0 print(ans) ```
output
1
29,917
19
59,835
Provide a correct Python 3 solution for this coding contest problem. Blackjack is a type of card game played in casinos, where the game is played using cards with numbers from 1 to 13. The score of each card is decided as follows. * 1 is 1 point or 11 points * From 2 to 9, the score is as written. * 10 points from 10 to 13 There are several participants in this game, including parents, each with several sets of cards. This set of cards is called a hand. The hand score is the total of the card scores. The calculation shall be performed as follows. * If the total score of the cards is greater than 21, the score of the hand is set to 0. * As the score of the card, 1 may be calculated as 1 point or 11 points, but the one with the maximum hand score shall be selected. Create a program that uses the information of the cards dealt as input and outputs the score of the hand. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format: c1 c2 ... cn The integer ci (1 ≤ ci ≤ 13) written on the i-th card is given to each line, separated by blanks. The number of cards n does not exceed 100. The number of datasets does not exceed 200. Output The score of the hand is output to one line for each data set. Example Input 1 7 7 7 7 7 8 12 1 10 1 1 0 Output 11 21 0 21 12
instruction
0
29,918
19
59,836
"Correct Solution: ``` # -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0169 """ import sys from sys import stdin input = stdin.readline def main(args): while True: data = [int(x) for x in input().split()] if len(data) == 1 and data[0] == 0: break total = 0 for d in data: if d > 10: total += 10 else: total += d ace = data.count(1) for _ in range(ace): if total + 10 <= 21: total += 10 if total > 21: total = 0 print(total) if __name__ == '__main__': main(sys.argv[1:]) ```
output
1
29,918
19
59,837
Provide a correct Python 3 solution for this coding contest problem. Blackjack is a type of card game played in casinos, where the game is played using cards with numbers from 1 to 13. The score of each card is decided as follows. * 1 is 1 point or 11 points * From 2 to 9, the score is as written. * 10 points from 10 to 13 There are several participants in this game, including parents, each with several sets of cards. This set of cards is called a hand. The hand score is the total of the card scores. The calculation shall be performed as follows. * If the total score of the cards is greater than 21, the score of the hand is set to 0. * As the score of the card, 1 may be calculated as 1 point or 11 points, but the one with the maximum hand score shall be selected. Create a program that uses the information of the cards dealt as input and outputs the score of the hand. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format: c1 c2 ... cn The integer ci (1 ≤ ci ≤ 13) written on the i-th card is given to each line, separated by blanks. The number of cards n does not exceed 100. The number of datasets does not exceed 200. Output The score of the hand is output to one line for each data set. Example Input 1 7 7 7 7 7 8 12 1 10 1 1 0 Output 11 21 0 21 12
instruction
0
29,919
19
59,838
"Correct Solution: ``` while True: c = [int(x) for x in input().split()] if c[0] == 0: break L = [] for i in c: if i > 10: L.append(10) else: L.append(i) p = [] for i in range(L.count(1)+1): t = sum(L) + 10 *i if t > 21: t =0 p.append(t) print(max(p)) ```
output
1
29,919
19
59,839
Provide a correct Python 3 solution for this coding contest problem. Blackjack is a type of card game played in casinos, where the game is played using cards with numbers from 1 to 13. The score of each card is decided as follows. * 1 is 1 point or 11 points * From 2 to 9, the score is as written. * 10 points from 10 to 13 There are several participants in this game, including parents, each with several sets of cards. This set of cards is called a hand. The hand score is the total of the card scores. The calculation shall be performed as follows. * If the total score of the cards is greater than 21, the score of the hand is set to 0. * As the score of the card, 1 may be calculated as 1 point or 11 points, but the one with the maximum hand score shall be selected. Create a program that uses the information of the cards dealt as input and outputs the score of the hand. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format: c1 c2 ... cn The integer ci (1 ≤ ci ≤ 13) written on the i-th card is given to each line, separated by blanks. The number of cards n does not exceed 100. The number of datasets does not exceed 200. Output The score of the hand is output to one line for each data set. Example Input 1 7 7 7 7 7 8 12 1 10 1 1 0 Output 11 21 0 21 12
instruction
0
29,920
19
59,840
"Correct Solution: ``` while True : A = list(map(int,input().split())) if A[0] == 0 : break cnt = 0 S = 0 for i in A : S += min(i, 10) if i == 1 : cnt += 1 while cnt > 0 and S + 10 <= 21 : cnt -= 1 S += 10 if S > 21 : S = 0 print(S) ```
output
1
29,920
19
59,841
Provide a correct Python 3 solution for this coding contest problem. Blackjack is a type of card game played in casinos, where the game is played using cards with numbers from 1 to 13. The score of each card is decided as follows. * 1 is 1 point or 11 points * From 2 to 9, the score is as written. * 10 points from 10 to 13 There are several participants in this game, including parents, each with several sets of cards. This set of cards is called a hand. The hand score is the total of the card scores. The calculation shall be performed as follows. * If the total score of the cards is greater than 21, the score of the hand is set to 0. * As the score of the card, 1 may be calculated as 1 point or 11 points, but the one with the maximum hand score shall be selected. Create a program that uses the information of the cards dealt as input and outputs the score of the hand. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format: c1 c2 ... cn The integer ci (1 ≤ ci ≤ 13) written on the i-th card is given to each line, separated by blanks. The number of cards n does not exceed 100. The number of datasets does not exceed 200. Output The score of the hand is output to one line for each data set. Example Input 1 7 7 7 7 7 8 12 1 10 1 1 0 Output 11 21 0 21 12
instruction
0
29,921
19
59,842
"Correct Solution: ``` from collections import Counter def point(lst): counter = Counter(lst) acc = 0 for i in range(2, 10): acc += i * counter[i] for i in range(10, 14): acc += 10 * counter[i] one_num = counter[1] for i in range(one_num + 1): if i + (one_num - i) * 11 + acc <= 21: acc += i + (one_num - i) * 11 break else: acc += one_num if acc > 21: return 0 else: return acc while True: s = input() if s == "0": break lst = list(map(int, s.split())) print(point(lst)) ```
output
1
29,921
19
59,843
Provide a correct Python 3 solution for this coding contest problem. Blackjack is a type of card game played in casinos, where the game is played using cards with numbers from 1 to 13. The score of each card is decided as follows. * 1 is 1 point or 11 points * From 2 to 9, the score is as written. * 10 points from 10 to 13 There are several participants in this game, including parents, each with several sets of cards. This set of cards is called a hand. The hand score is the total of the card scores. The calculation shall be performed as follows. * If the total score of the cards is greater than 21, the score of the hand is set to 0. * As the score of the card, 1 may be calculated as 1 point or 11 points, but the one with the maximum hand score shall be selected. Create a program that uses the information of the cards dealt as input and outputs the score of the hand. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format: c1 c2 ... cn The integer ci (1 ≤ ci ≤ 13) written on the i-th card is given to each line, separated by blanks. The number of cards n does not exceed 100. The number of datasets does not exceed 200. Output The score of the hand is output to one line for each data set. Example Input 1 7 7 7 7 7 8 12 1 10 1 1 0 Output 11 21 0 21 12
instruction
0
29,922
19
59,844
"Correct Solution: ``` while 1: *C, = map(int, input().split()) if C == [0]: break s = 0 C.sort(reverse=1) one = 0 for c in C: if c == 1: s += 1 one += 1 elif c > 10: s += 10 else: s += c while one and s + 10 <= 21: s += 10 one -= 1 if s > 21: s = 0 print(s) ```
output
1
29,922
19
59,845
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Blackjack is a type of card game played in casinos, where the game is played using cards with numbers from 1 to 13. The score of each card is decided as follows. * 1 is 1 point or 11 points * From 2 to 9, the score is as written. * 10 points from 10 to 13 There are several participants in this game, including parents, each with several sets of cards. This set of cards is called a hand. The hand score is the total of the card scores. The calculation shall be performed as follows. * If the total score of the cards is greater than 21, the score of the hand is set to 0. * As the score of the card, 1 may be calculated as 1 point or 11 points, but the one with the maximum hand score shall be selected. Create a program that uses the information of the cards dealt as input and outputs the score of the hand. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format: c1 c2 ... cn The integer ci (1 ≤ ci ≤ 13) written on the i-th card is given to each line, separated by blanks. The number of cards n does not exceed 100. The number of datasets does not exceed 200. Output The score of the hand is output to one line for each data set. Example Input 1 7 7 7 7 7 8 12 1 10 1 1 0 Output 11 21 0 21 12 Submitted Solution: ``` while 1: C = list(map(int,input().split())) if(C == [0]): break ans = [False]*22 ans[0] = True for c in C: l = [min(c,10)] if(c == 1): l.append(11) ans_ = [False]*22 for i in range(21,-1,-1): if not ans[i]: continue for a in l: if i+a > 21: continue ans_[i+a] = True ans = ans_ A = 0 for i in range(22): if not ans[i]: continue A = max(A,i) print(A) ```
instruction
0
29,923
19
59,846
Yes
output
1
29,923
19
59,847
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Blackjack is a type of card game played in casinos, where the game is played using cards with numbers from 1 to 13. The score of each card is decided as follows. * 1 is 1 point or 11 points * From 2 to 9, the score is as written. * 10 points from 10 to 13 There are several participants in this game, including parents, each with several sets of cards. This set of cards is called a hand. The hand score is the total of the card scores. The calculation shall be performed as follows. * If the total score of the cards is greater than 21, the score of the hand is set to 0. * As the score of the card, 1 may be calculated as 1 point or 11 points, but the one with the maximum hand score shall be selected. Create a program that uses the information of the cards dealt as input and outputs the score of the hand. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format: c1 c2 ... cn The integer ci (1 ≤ ci ≤ 13) written on the i-th card is given to each line, separated by blanks. The number of cards n does not exceed 100. The number of datasets does not exceed 200. Output The score of the hand is output to one line for each data set. Example Input 1 7 7 7 7 7 8 12 1 10 1 1 0 Output 11 21 0 21 12 Submitted Solution: ``` # Aizu Problem 00169: Blackjack # import sys, math, os, bisect # read input: PYDEV = os.environ.get('PYDEV') if PYDEV=="True": sys.stdin = open("sample-input.txt", "rt") def blackjack(hand): hand = [min(h, 10) for h in hand] S = sum(hand) if S > 21: return 0 C = hand.count(1) if C == 0: return S for k in range(C): C -= 1 S += 10 if S > 21: return S - 10 return S while True: hand = [int(_) for _ in input().split()] if len(hand) == 1 and hand[0] == 0: break print(blackjack(hand)) ```
instruction
0
29,924
19
59,848
Yes
output
1
29,924
19
59,849
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Blackjack is a type of card game played in casinos, where the game is played using cards with numbers from 1 to 13. The score of each card is decided as follows. * 1 is 1 point or 11 points * From 2 to 9, the score is as written. * 10 points from 10 to 13 There are several participants in this game, including parents, each with several sets of cards. This set of cards is called a hand. The hand score is the total of the card scores. The calculation shall be performed as follows. * If the total score of the cards is greater than 21, the score of the hand is set to 0. * As the score of the card, 1 may be calculated as 1 point or 11 points, but the one with the maximum hand score shall be selected. Create a program that uses the information of the cards dealt as input and outputs the score of the hand. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format: c1 c2 ... cn The integer ci (1 ≤ ci ≤ 13) written on the i-th card is given to each line, separated by blanks. The number of cards n does not exceed 100. The number of datasets does not exceed 200. Output The score of the hand is output to one line for each data set. Example Input 1 7 7 7 7 7 8 12 1 10 1 1 0 Output 11 21 0 21 12 Submitted Solution: ``` while True: n=[int(i) for i in input().split(" ")] if n==[0]: break for i in range(len(n)): if n[i]>10: n[i]=10 one=n.count(1) score=sum(n) while score<=11 and one>0: if one>0: score+=10 one-=1 if score>21: score=0 print(score) ```
instruction
0
29,925
19
59,850
Yes
output
1
29,925
19
59,851
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Blackjack is a type of card game played in casinos, where the game is played using cards with numbers from 1 to 13. The score of each card is decided as follows. * 1 is 1 point or 11 points * From 2 to 9, the score is as written. * 10 points from 10 to 13 There are several participants in this game, including parents, each with several sets of cards. This set of cards is called a hand. The hand score is the total of the card scores. The calculation shall be performed as follows. * If the total score of the cards is greater than 21, the score of the hand is set to 0. * As the score of the card, 1 may be calculated as 1 point or 11 points, but the one with the maximum hand score shall be selected. Create a program that uses the information of the cards dealt as input and outputs the score of the hand. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format: c1 c2 ... cn The integer ci (1 ≤ ci ≤ 13) written on the i-th card is given to each line, separated by blanks. The number of cards n does not exceed 100. The number of datasets does not exceed 200. Output The score of the hand is output to one line for each data set. Example Input 1 7 7 7 7 7 8 12 1 10 1 1 0 Output 11 21 0 21 12 Submitted Solution: ``` while True: input_list = [int(item) for item in input().split(" ")] if input_list[0] == 0: break total = 0 count = 0 for num in input_list: if 10 < num: num = 10 elif num == 1: count += 1 total += num if 21 < total: break if total <= 21: while total + 10 <= 21 and 0 < count: total += 10 count -= 1 print(total) else: print(0) ```
instruction
0
29,926
19
59,852
Yes
output
1
29,926
19
59,853
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Blackjack is a type of card game played in casinos, where the game is played using cards with numbers from 1 to 13. The score of each card is decided as follows. * 1 is 1 point or 11 points * From 2 to 9, the score is as written. * 10 points from 10 to 13 There are several participants in this game, including parents, each with several sets of cards. This set of cards is called a hand. The hand score is the total of the card scores. The calculation shall be performed as follows. * If the total score of the cards is greater than 21, the score of the hand is set to 0. * As the score of the card, 1 may be calculated as 1 point or 11 points, but the one with the maximum hand score shall be selected. Create a program that uses the information of the cards dealt as input and outputs the score of the hand. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format: c1 c2 ... cn The integer ci (1 ≤ ci ≤ 13) written on the i-th card is given to each line, separated by blanks. The number of cards n does not exceed 100. The number of datasets does not exceed 200. Output The score of the hand is output to one line for each data set. Example Input 1 7 7 7 7 7 8 12 1 10 1 1 0 Output 11 21 0 21 12 Submitted Solution: ``` if input() == '1': pass while True: inp = input() if inp == '0': break inp = inp.replace('11', '10') inp = inp.replace('12', '10') inp = inp.replace('13', '10') cards = tuple(map(int, inp.split())) ans = sum(cards) for i in range(cards.count(1)): if sum(cards) + 9 * (i+1) > 21: print('test', ans) break elif ans < sum(cards) + 9 * (i+1): print('test2', ans) ans = sum(cards) + 9 * (i+1) if ans > 21: ans = 0 print(ans) ```
instruction
0
29,927
19
59,854
No
output
1
29,927
19
59,855
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Blackjack is a type of card game played in casinos, where the game is played using cards with numbers from 1 to 13. The score of each card is decided as follows. * 1 is 1 point or 11 points * From 2 to 9, the score is as written. * 10 points from 10 to 13 There are several participants in this game, including parents, each with several sets of cards. This set of cards is called a hand. The hand score is the total of the card scores. The calculation shall be performed as follows. * If the total score of the cards is greater than 21, the score of the hand is set to 0. * As the score of the card, 1 may be calculated as 1 point or 11 points, but the one with the maximum hand score shall be selected. Create a program that uses the information of the cards dealt as input and outputs the score of the hand. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format: c1 c2 ... cn The integer ci (1 ≤ ci ≤ 13) written on the i-th card is given to each line, separated by blanks. The number of cards n does not exceed 100. The number of datasets does not exceed 200. Output The score of the hand is output to one line for each data set. Example Input 1 7 7 7 7 7 8 12 1 10 1 1 0 Output 11 21 0 21 12 Submitted Solution: ``` if input() == '1': pass while True: inp = input() if inp == '0': break inp = inp.replace('11', '10') inp = inp.replace('12', '10') inp = inp.replace('13', '10') cards = tuple(map(int, inp.split())) ans = sum(cards) for i in range(cards.count(1)): if sum(cards) + 10 * (i+1) > 21: break elif ans < sum(cards) + 10 * (i+1): ans = sum(cards) + 10 * (i+1) if ans > 21: ans = 0 print(ans) ```
instruction
0
29,928
19
59,856
No
output
1
29,928
19
59,857
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Blackjack is a type of card game played in casinos, where the game is played using cards with numbers from 1 to 13. The score of each card is decided as follows. * 1 is 1 point or 11 points * From 2 to 9, the score is as written. * 10 points from 10 to 13 There are several participants in this game, including parents, each with several sets of cards. This set of cards is called a hand. The hand score is the total of the card scores. The calculation shall be performed as follows. * If the total score of the cards is greater than 21, the score of the hand is set to 0. * As the score of the card, 1 may be calculated as 1 point or 11 points, but the one with the maximum hand score shall be selected. Create a program that uses the information of the cards dealt as input and outputs the score of the hand. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format: c1 c2 ... cn The integer ci (1 ≤ ci ≤ 13) written on the i-th card is given to each line, separated by blanks. The number of cards n does not exceed 100. The number of datasets does not exceed 200. Output The score of the hand is output to one line for each data set. Example Input 1 7 7 7 7 7 8 12 1 10 1 1 0 Output 11 21 0 21 12 Submitted Solution: ``` from collections import Counter def point(lst): counter = Counter(lst) acc = 0 for i in range(2, 10): acc += i * counter[i] for i in range(11, 14): acc += 10 * counter[i] one_num = counter[1] for i in range(one_num + 1): if i + (one_num - i) * 11 + acc <= 21: acc += i + (one_num - i) * 11 break else: acc += one_num if acc > 21: return 0 else: return acc while True: s = input() if s == "0": break lst = list(map(int, s.split())) print(point(lst)) ```
instruction
0
29,929
19
59,858
No
output
1
29,929
19
59,859
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Blackjack is a type of card game played in casinos, where the game is played using cards with numbers from 1 to 13. The score of each card is decided as follows. * 1 is 1 point or 11 points * From 2 to 9, the score is as written. * 10 points from 10 to 13 There are several participants in this game, including parents, each with several sets of cards. This set of cards is called a hand. The hand score is the total of the card scores. The calculation shall be performed as follows. * If the total score of the cards is greater than 21, the score of the hand is set to 0. * As the score of the card, 1 may be calculated as 1 point or 11 points, but the one with the maximum hand score shall be selected. Create a program that uses the information of the cards dealt as input and outputs the score of the hand. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format: c1 c2 ... cn The integer ci (1 ≤ ci ≤ 13) written on the i-th card is given to each line, separated by blanks. The number of cards n does not exceed 100. The number of datasets does not exceed 200. Output The score of the hand is output to one line for each data set. Example Input 1 7 7 7 7 7 8 12 1 10 1 1 0 Output 11 21 0 21 12 Submitted Solution: ``` if input() == '1': pass while True: inp = input() if inp == '0': break inp = inp.replace('11', '10') inp = inp.replace('12', '10') inp = inp.replace('13', '10') cards = tuple(map(int, inp.split())) ans = sum(cards) for i in range(cards.count(1)): if sum(cards) + 10 * (i+1) > 21: print('test', ans) break elif ans < sum(cards) + 10 * (i+1): print('test2', ans) ans = sum(cards) + 10 * (i+1) if ans > 21: ans = 0 print(ans) ```
instruction
0
29,930
19
59,860
No
output
1
29,930
19
59,861
Provide a correct Python 3 solution for this coding contest problem. Rabbits and cats are competing. The rules are as follows. First, each of the two animals wrote n2 integers on a piece of paper in a square with n rows and n columns, and drew one card at a time. Shuffle two cards and draw them one by one alternately. Each time a card is drawn, the two will mark it if the same number as the card is written on their paper. The winning condition is that the number of "a set of n numbers with a mark and is in a straight line" is equal to or greater than the number of playing cards drawn at the beginning. Answer which of the rabbit and the cat wins up to the mth card given. However, the victory or defeat is when only one of the two cards meets the victory condition when a certain card is drawn and marked. In other cases, it is a draw. Cards may be drawn even after one of them meets the victory conditions, but this does not affect the victory or defeat. Input Line 1: “nuvm” (square size, number of rabbit playing cards, number of cat playing cards, number of cards drawn) 2- (N + 1) Line: n2 numbers that the rabbit writes on paper ( N + 2)-(2N + 1) Line: n2 numbers that the cat writes on paper (2N + 2)-(2N + M + 1) Line: m cards drawn 1 ≤ n ≤ 500 1 ≤ u, v ≤ 13 1 ≤ m ≤ 100 000 1 ≤ (number written) ≤ 1 000 000 The number of n2 rabbits write on paper, the number of n2 cats write on paper, and the number of m cards drawn are different. Output Output "USAGI" if the rabbit wins, "NEKO" if the cat wins, and "DRAW" if the tie, each in one line. Examples Input 3 2 2 10 1 2 3 4 5 6 7 8 9 1 2 3 6 5 4 7 8 9 11 4 7 5 10 9 2 1 3 8 Output USAGI Input 3 2 1 10 1 2 3 4 5 6 7 8 9 1 2 3 6 5 4 7 8 9 11 4 7 5 10 9 2 1 3 8 Output DRAW
instruction
0
29,975
19
59,950
"Correct Solution: ``` n, u, v, m = map(int, input().split()) usa_mat = [list(map(int, input().split())) for _ in range(n)] nek_mat = [list(map(int, input().split())) for _ in range(n)] usa_dic = {} nek_dic = {} for y in range(n): for x in range(n): usa_dic[usa_mat[y][x]] = (x, y) nek_dic[nek_mat[y][x]] = (x, y) usa_count = [0] * (2 * n + 2) nek_count = [0] * (2 * n + 2) flag = 0 usa_point = 0 nek_point = 0 for _ in range(m): a = int(input()) if flag: continue if a in usa_dic: ux, uy = usa_dic[a] usa_count[ux] += 1 if usa_count[ux] == n: usa_point += 1 usa_count[uy + n] += 1 if usa_count[uy + n] == n: usa_point += 1 if ux + uy == n - 1: usa_count[-1] += 1 if usa_count[-1] == n: usa_point += 1 if ux == uy: usa_count[-2] += 1 if usa_count[-2] == n: usa_point += 1 if a in nek_dic: nx, ny = nek_dic[a] nek_count[nx] += 1 if nek_count[nx] == n: nek_point += 1 nek_count[ny + n] += 1 if nek_count[ny + n] == n: nek_point += 1 if nx + ny == n - 1: nek_count[-1] += 1 if nek_count[-1] == n: nek_point += 1 if nx == ny: nek_count[-2] += 1 if nek_count[-2] == n: nek_point += 1 if n == 1: usa_point = min(usa_point, 1) nek_point = min(nek_point, 1) if usa_point >= u and nek_point >= v: flag = 1 elif usa_point >= u: flag = 2 elif nek_point >= v: flag = 3 if flag == 2: print("USAGI") elif flag == 3: print("NEKO") else: print("DRAW") ```
output
1
29,975
19
59,951
Provide a correct Python 3 solution for this coding contest problem. Rabbits and cats are competing. The rules are as follows. First, each of the two animals wrote n2 integers on a piece of paper in a square with n rows and n columns, and drew one card at a time. Shuffle two cards and draw them one by one alternately. Each time a card is drawn, the two will mark it if the same number as the card is written on their paper. The winning condition is that the number of "a set of n numbers with a mark and is in a straight line" is equal to or greater than the number of playing cards drawn at the beginning. Answer which of the rabbit and the cat wins up to the mth card given. However, the victory or defeat is when only one of the two cards meets the victory condition when a certain card is drawn and marked. In other cases, it is a draw. Cards may be drawn even after one of them meets the victory conditions, but this does not affect the victory or defeat. Input Line 1: “nuvm” (square size, number of rabbit playing cards, number of cat playing cards, number of cards drawn) 2- (N + 1) Line: n2 numbers that the rabbit writes on paper ( N + 2)-(2N + 1) Line: n2 numbers that the cat writes on paper (2N + 2)-(2N + M + 1) Line: m cards drawn 1 ≤ n ≤ 500 1 ≤ u, v ≤ 13 1 ≤ m ≤ 100 000 1 ≤ (number written) ≤ 1 000 000 The number of n2 rabbits write on paper, the number of n2 cats write on paper, and the number of m cards drawn are different. Output Output "USAGI" if the rabbit wins, "NEKO" if the cat wins, and "DRAW" if the tie, each in one line. Examples Input 3 2 2 10 1 2 3 4 5 6 7 8 9 1 2 3 6 5 4 7 8 9 11 4 7 5 10 9 2 1 3 8 Output USAGI Input 3 2 1 10 1 2 3 4 5 6 7 8 9 1 2 3 6 5 4 7 8 9 11 4 7 5 10 9 2 1 3 8 Output DRAW
instruction
0
29,976
19
59,952
"Correct Solution: ``` import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**10 mod = 10**9+7 dd = [(-1,0),(0,1),(1,0),(0,-1)] ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s, flush=True) def main(): n,u,v,m = LI() ud = {} for i in range(n): t = LI() for j in range(n): ud[t[j]] = (i,j) vd = {} for i in range(n): t = LI() for j in range(n): vd[t[j]] = (i,j) ma = [I() for _ in range(m)] ut = collections.defaultdict(bool) vt = collections.defaultdict(bool) un = 0 vn = 0 for t in ma: if t in ud: ut[ud[t]] = True ui,uj = ud[t] for di,dj in ddn[:4]: k = 1 for i in range(1, n): if not ut[(ui+di*i, uj+dj*i)]: break k += 1 for i in range(-1, -n, -1): if not ut[(ui+di*i, uj+dj*i)]: break k += 1 if k >= n: un += 1 if k == 1: un = 1 if t in vd: vt[vd[t]] = True vi,vj = vd[t] for di,dj in ddn[:4]: k = 1 for i in range(1, n): if not vt[(vi+di*i, vj+dj*i)]: break k += 1 for i in range(-1, -n, -1): if not vt[(vi+di*i, vj+dj*i)]: break k += 1 if k >= n: vn += 1 if k == 1: vn = 1 if un >= u and vn < v: return 'USAGI' if vn >= v and un < u: return 'NEKO' if un >= u and vn >= v: break return 'DRAW' print(main()) ```
output
1
29,976
19
59,953
Provide a correct Python 3 solution for this coding contest problem. Rabbits and cats are competing. The rules are as follows. First, each of the two animals wrote n2 integers on a piece of paper in a square with n rows and n columns, and drew one card at a time. Shuffle two cards and draw them one by one alternately. Each time a card is drawn, the two will mark it if the same number as the card is written on their paper. The winning condition is that the number of "a set of n numbers with a mark and is in a straight line" is equal to or greater than the number of playing cards drawn at the beginning. Answer which of the rabbit and the cat wins up to the mth card given. However, the victory or defeat is when only one of the two cards meets the victory condition when a certain card is drawn and marked. In other cases, it is a draw. Cards may be drawn even after one of them meets the victory conditions, but this does not affect the victory or defeat. Input Line 1: “nuvm” (square size, number of rabbit playing cards, number of cat playing cards, number of cards drawn) 2- (N + 1) Line: n2 numbers that the rabbit writes on paper ( N + 2)-(2N + 1) Line: n2 numbers that the cat writes on paper (2N + 2)-(2N + M + 1) Line: m cards drawn 1 ≤ n ≤ 500 1 ≤ u, v ≤ 13 1 ≤ m ≤ 100 000 1 ≤ (number written) ≤ 1 000 000 The number of n2 rabbits write on paper, the number of n2 cats write on paper, and the number of m cards drawn are different. Output Output "USAGI" if the rabbit wins, "NEKO" if the cat wins, and "DRAW" if the tie, each in one line. Examples Input 3 2 2 10 1 2 3 4 5 6 7 8 9 1 2 3 6 5 4 7 8 9 11 4 7 5 10 9 2 1 3 8 Output USAGI Input 3 2 1 10 1 2 3 4 5 6 7 8 9 1 2 3 6 5 4 7 8 9 11 4 7 5 10 9 2 1 3 8 Output DRAW
instruction
0
29,977
19
59,954
"Correct Solution: ``` # coding: utf-8 n,u,v,m=map(int,input().split()) usa=[list(map(int,input().split())) for i in range(n)] neko=[list(map(int,input().split())) for i in range(n)] usadic={} nekodic={} usatable=[0 for i in range(2*n+2)] nekotable=[0 for i in range(2*n+2)] for i in range(n): for j in range(n): usadic[usa[i][j]]=[] nekodic[neko[i][j]]=[] usadic[usa[i][j]].append(i) nekodic[neko[i][j]].append(i) usadic[usa[i][j]].append(n+j) nekodic[neko[i][j]].append(n+j) if i==j: usadic[usa[i][j]].append(2*n) nekodic[neko[i][j]].append(2*n) if i+j==n-1: usadic[usa[i][j]].append(2*n+1) nekodic[neko[i][j]].append(2*n+1) usacount=0 nekocount=0 for i in range(m): t=int(input()) if t in usadic: for x in usadic[t]: usatable[x]+=1 if usatable[x]==n: usacount+=1 if t in nekodic: for x in nekodic[t]: nekotable[x]+=1 if nekotable[x]==n: nekocount+=1 if n==1: usacount=min(usacount,1) nekocount=min(nekocount,1) if usacount>=u and nekocount>=v: print('DRAW') break elif usacount>=u: print('USAGI') break elif nekocount>=v: print('NEKO') break else: print('DRAW') ```
output
1
29,977
19
59,955
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Rabbits and cats are competing. The rules are as follows. First, each of the two animals wrote n2 integers on a piece of paper in a square with n rows and n columns, and drew one card at a time. Shuffle two cards and draw them one by one alternately. Each time a card is drawn, the two will mark it if the same number as the card is written on their paper. The winning condition is that the number of "a set of n numbers with a mark and is in a straight line" is equal to or greater than the number of playing cards drawn at the beginning. Answer which of the rabbit and the cat wins up to the mth card given. However, the victory or defeat is when only one of the two cards meets the victory condition when a certain card is drawn and marked. In other cases, it is a draw. Cards may be drawn even after one of them meets the victory conditions, but this does not affect the victory or defeat. Input Line 1: “nuvm” (square size, number of rabbit playing cards, number of cat playing cards, number of cards drawn) 2- (N + 1) Line: n2 numbers that the rabbit writes on paper ( N + 2)-(2N + 1) Line: n2 numbers that the cat writes on paper (2N + 2)-(2N + M + 1) Line: m cards drawn 1 ≤ n ≤ 500 1 ≤ u, v ≤ 13 1 ≤ m ≤ 100 000 1 ≤ (number written) ≤ 1 000 000 The number of n2 rabbits write on paper, the number of n2 cats write on paper, and the number of m cards drawn are different. Output Output "USAGI" if the rabbit wins, "NEKO" if the cat wins, and "DRAW" if the tie, each in one line. Examples Input 3 2 2 10 1 2 3 4 5 6 7 8 9 1 2 3 6 5 4 7 8 9 11 4 7 5 10 9 2 1 3 8 Output USAGI Input 3 2 1 10 1 2 3 4 5 6 7 8 9 1 2 3 6 5 4 7 8 9 11 4 7 5 10 9 2 1 3 8 Output DRAW Submitted Solution: ``` n, u, v, m = map(int, input().split()) usa_mat = [list(map(int, input().split())) for _ in range(n)] nek_mat = [list(map(int, input().split())) for _ in range(n)] usa_dic = {} nek_dic = {} for y in range(n): for x in range(n): usa_dic[usa_mat[y][x]] = (x, y) nek_dic[nek_mat[y][x]] = (x, y) usa_count = [0] * (2 * n + 2) nek_count = [0] * (2 * n + 2) flag = 0 usa_point = 0 nek_point = 0 for _ in range(m): a = int(input()) if flag: continue if a in usa_dic: ux, uy = usa_dic[a] usa_count[ux] += 1 if usa_count[ux] == n: usa_point += 1 usa_count[uy + n] += 1 if usa_count[uy + n] == n: usa_point += 1 if ux + uy == n: usa_count[-1] += 1 if usa_count[-1] == n: usa_point += 1 if ux == uy: usa_count[-2] += 1 if usa_count[-2] == n: usa_point += 1 if a in nek_dic: nx, ny = nek_dic[a] nek_count[nx] += 1 if nek_count[nx] == n: nek_point += 1 nek_count[ny + n] += 1 if nek_count[ny + n] == n: nek_point += 1 if nx + ny == n: nek_count[-1] += 1 if nek_count[-1] == n: nek_point += 1 if nx == ny: nek_count[-2] += 1 if nek_count[-2] == n: nek_point += 1 if usa_point >= u and nek_point >= v: flag = 1 elif usa_point >= u: flag = 2 elif nek_point >= v: flag = 3 if flag == 2: print("USAGI") elif flag == 3: print("NEKO") else: print("DRAW") ```
instruction
0
29,978
19
59,956
No
output
1
29,978
19
59,957
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Rabbits and cats are competing. The rules are as follows. First, each of the two animals wrote n2 integers on a piece of paper in a square with n rows and n columns, and drew one card at a time. Shuffle two cards and draw them one by one alternately. Each time a card is drawn, the two will mark it if the same number as the card is written on their paper. The winning condition is that the number of "a set of n numbers with a mark and is in a straight line" is equal to or greater than the number of playing cards drawn at the beginning. Answer which of the rabbit and the cat wins up to the mth card given. However, the victory or defeat is when only one of the two cards meets the victory condition when a certain card is drawn and marked. In other cases, it is a draw. Cards may be drawn even after one of them meets the victory conditions, but this does not affect the victory or defeat. Input Line 1: “nuvm” (square size, number of rabbit playing cards, number of cat playing cards, number of cards drawn) 2- (N + 1) Line: n2 numbers that the rabbit writes on paper ( N + 2)-(2N + 1) Line: n2 numbers that the cat writes on paper (2N + 2)-(2N + M + 1) Line: m cards drawn 1 ≤ n ≤ 500 1 ≤ u, v ≤ 13 1 ≤ m ≤ 100 000 1 ≤ (number written) ≤ 1 000 000 The number of n2 rabbits write on paper, the number of n2 cats write on paper, and the number of m cards drawn are different. Output Output "USAGI" if the rabbit wins, "NEKO" if the cat wins, and "DRAW" if the tie, each in one line. Examples Input 3 2 2 10 1 2 3 4 5 6 7 8 9 1 2 3 6 5 4 7 8 9 11 4 7 5 10 9 2 1 3 8 Output USAGI Input 3 2 1 10 1 2 3 4 5 6 7 8 9 1 2 3 6 5 4 7 8 9 11 4 7 5 10 9 2 1 3 8 Output DRAW Submitted Solution: ``` import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**10 mod = 10**9+7 dd = [(-1,0),(0,1),(1,0),(0,-1)] ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s, flush=True) def main(): n,u,v,m = LI() ud = {} for i in range(n): t = LI() for j in range(n): ud[t[j]] = (i,j) vd = {} for i in range(n): t = LI() for j in range(n): vd[t[j]] = (i,j) ma = [I() for _ in range(m)] ut = collections.defaultdict(bool) vt = collections.defaultdict(bool) un = 0 vn = 0 for t in ma: if t in ud: ut[ud[t]] = True ui,uj = ud[t] for di,dj in ddn[:4]: k = 1 for i in range(1, n): if not ut[(ui+di*i, uj+dj*i)]: break k += 1 for i in range(-1, -n, -1): if not ut[(ui+di*i, uj+dj*i)]: break k += 1 if k >= n: un += 1 if t in vd: vt[vd[t]] = True vi,vj = vd[t] for di,dj in ddn[:4]: k = 1 for i in range(1, n): if not vt[(vi+di*i, vj+dj*i)]: break k += 1 for i in range(-1, -n, -1): if not vt[(vi+di*i, vj+dj*i)]: break k += 1 if k >= n: vn += 1 if un >= u and vn < v: return 'USAGI' if vn >= v and un < u: return 'NEKO' if un >= u and vn >= v: break return 'DRAW' print(main()) ```
instruction
0
29,979
19
59,958
No
output
1
29,979
19
59,959
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Rabbits and cats are competing. The rules are as follows. First, each of the two animals wrote n2 integers on a piece of paper in a square with n rows and n columns, and drew one card at a time. Shuffle two cards and draw them one by one alternately. Each time a card is drawn, the two will mark it if the same number as the card is written on their paper. The winning condition is that the number of "a set of n numbers with a mark and is in a straight line" is equal to or greater than the number of playing cards drawn at the beginning. Answer which of the rabbit and the cat wins up to the mth card given. However, the victory or defeat is when only one of the two cards meets the victory condition when a certain card is drawn and marked. In other cases, it is a draw. Cards may be drawn even after one of them meets the victory conditions, but this does not affect the victory or defeat. Input Line 1: “nuvm” (square size, number of rabbit playing cards, number of cat playing cards, number of cards drawn) 2- (N + 1) Line: n2 numbers that the rabbit writes on paper ( N + 2)-(2N + 1) Line: n2 numbers that the cat writes on paper (2N + 2)-(2N + M + 1) Line: m cards drawn 1 ≤ n ≤ 500 1 ≤ u, v ≤ 13 1 ≤ m ≤ 100 000 1 ≤ (number written) ≤ 1 000 000 The number of n2 rabbits write on paper, the number of n2 cats write on paper, and the number of m cards drawn are different. Output Output "USAGI" if the rabbit wins, "NEKO" if the cat wins, and "DRAW" if the tie, each in one line. Examples Input 3 2 2 10 1 2 3 4 5 6 7 8 9 1 2 3 6 5 4 7 8 9 11 4 7 5 10 9 2 1 3 8 Output USAGI Input 3 2 1 10 1 2 3 4 5 6 7 8 9 1 2 3 6 5 4 7 8 9 11 4 7 5 10 9 2 1 3 8 Output DRAW Submitted Solution: ``` n, u, v, m = map(int, input().split()) usa_mat = [list(map(int, input().split())) for _ in range(n)] nek_mat = [list(map(int, input().split())) for _ in range(n)] usa_dic = {} nek_dic = {} for y in range(n): for x in range(n): usa_dic[usa_mat[y][x]] = (x, y) nek_dic[nek_mat[y][x]] = (x, y) usa_count = [0] * (2 * n + 2) nek_count = [0] * (2 * n + 2) flag = 0 usa_point = 0 nek_point = 0 for _ in range(m): a = int(input()) if flag: continue if a in usa_dic: ux, uy = usa_dic[a] usa_count[ux] += 1 if usa_count[ux] == n: usa_point += 1 usa_count[uy + n] += 1 if usa_count[uy + n] == n: usa_point += 1 if ux + uy == n: usa_count[-1] += 1 if usa_count[-1] == n: usa_point += 1 if ux == uy: usa_count[-2] += 1 if usa_count[-2] == n: usa_point += 1 if a in nek_dic: nx, ny = nek_dic[a] nek_count[nx] += 1 if nek_count[nx] == n: nek_point += 1 nek_count[ny + n] += 1 if nek_count[ny + n] == n: nek_point += 1 if nx + ny == n: nek_count[-1] += 1 if nek_count[-1] == n: nek_point += 1 if nx == ny: nek_count[-2] += 1 if nek_count[-2] == n: nek_point += 1 if n == 1: usa_point = min(usa_point, 1) nek_point = min(nek_point, 1) if usa_point >= u and nek_point >= v: flag = 1 elif usa_point >= u: flag = 2 elif nek_point >= v: flag = 3 if flag == 2: print("USAGI") elif flag == 3: print("NEKO") else: print("DRAW") ```
instruction
0
29,980
19
59,960
No
output
1
29,980
19
59,961
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have a bag which contains n cards. There is a number written on each card; the number on i-th card is a_i. You are playing the following game. During each turn, you choose and remove a random card from the bag (all cards that are still left inside the bag are chosen equiprobably). Nothing else happens during the first turn — but during the next turns, after removing a card (let the number on it be x), you compare it with the card that was removed during the previous turn (let the number on it be y). Possible outcomes are: * if x < y, the game ends and you lose; * if x = y, the game ends and you win; * if x > y, the game continues. If there are no cards left in the bag, you lose. Cards are not returned into the bag after you remove them. You have to calculate the probability of winning in this game. It can be shown that it is in the form of P/Q where P and Q are non-negative integers and Q ≠ 0, P ≤ Q. Output the value of P ⋅ Q^{−1} ~(mod ~~ 998244353). Input The first line contains one integer n (2 ≤ n ≤ 5000) — the number of cards in the bag. The second live contains n integers a_1, a_2, ... a_n (1 ≤ a_i ≤ n) — the i-th integer is the number written on the i-th card. Output Print one integer — the probability of winning in this game modulo 998244353. Examples Input 5 1 1 4 2 3 Output 299473306 Input 2 2 2 Output 1 Input 5 4 5 1 3 2 Output 0 Input 4 1 3 4 3 Output 748683265 Note In the first test case the probability of winning is 1/10. In the second test case the probability of winning is 1. In the third test case the probability of winning is 0. In the fourth test case the probability of winning is 1/4. Submitted Solution: ``` class Trie: head = {} def add(self, word): cur = self.head for ch in word: if ch not in cur: cur[ch] = {} cur = cur[ch] # * denotes the Trie has this word as item # if * doesn't exist, Trie doesn't have this word but as a path to longer word cur['*'] = True def search(self, word): cur = self.head for ch in word: if ch not in cur: return False cur = cur[ch] if '*' in cur: return True else: return False dictionary = Trie() dictionary.add("hi") dictionary.add("hello") dictionary.add("hellogbhailog") print(dictionary.search("hi")) print(dictionary.search("hello")) print(dictionary.search("hellogbhailog")) print(dictionary.search("hey")) ```
instruction
0
30,125
19
60,250
No
output
1
30,125
19
60,251
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have a bag which contains n cards. There is a number written on each card; the number on i-th card is a_i. You are playing the following game. During each turn, you choose and remove a random card from the bag (all cards that are still left inside the bag are chosen equiprobably). Nothing else happens during the first turn — but during the next turns, after removing a card (let the number on it be x), you compare it with the card that was removed during the previous turn (let the number on it be y). Possible outcomes are: * if x < y, the game ends and you lose; * if x = y, the game ends and you win; * if x > y, the game continues. If there are no cards left in the bag, you lose. Cards are not returned into the bag after you remove them. You have to calculate the probability of winning in this game. It can be shown that it is in the form of P/Q where P and Q are non-negative integers and Q ≠ 0, P ≤ Q. Output the value of P ⋅ Q^{−1} ~(mod ~~ 998244353). Input The first line contains one integer n (2 ≤ n ≤ 5000) — the number of cards in the bag. The second live contains n integers a_1, a_2, ... a_n (1 ≤ a_i ≤ n) — the i-th integer is the number written on the i-th card. Output Print one integer — the probability of winning in this game modulo 998244353. Examples Input 5 1 1 4 2 3 Output 299473306 Input 2 2 2 Output 1 Input 5 4 5 1 3 2 Output 0 Input 4 1 3 4 3 Output 748683265 Note In the first test case the probability of winning is 1/10. In the second test case the probability of winning is 1. In the third test case the probability of winning is 0. In the fourth test case the probability of winning is 1/4. Submitted Solution: ``` mod = 998244353 eps = 10**-9 def main(): import sys input = sys.stdin.readline N = int(input()) A = list(map(int, input().split())) cnt = [0] * (N+1) for a in A: cnt[a] += 1 A_unique = sorted(list(set(A))) dp = [[0] * (N+1) for _ in range(N+1)] dp[0][0] = 1 ans = 0 for i in range(N): inv = pow(N-1, mod-2, mod) cs = [0] * (N+1) cs[0] = dp[i][0] for j in range(1, N+1): cs[j] = (cs[j-1] + dp[i][j])%mod for a in A_unique: if cnt[a] > 1: ans = (ans + ((dp[i][a] * (cnt[a] - 1))%mod * inv)%mod)%mod dp[i+1][a] = (dp[i+1][a] + ((cs[a-1] * cnt[a])%mod * inv)%mod)%mod print(ans) if __name__ == '__main__': main() ```
instruction
0
30,126
19
60,252
No
output
1
30,126
19
60,253
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have a bag which contains n cards. There is a number written on each card; the number on i-th card is a_i. You are playing the following game. During each turn, you choose and remove a random card from the bag (all cards that are still left inside the bag are chosen equiprobably). Nothing else happens during the first turn — but during the next turns, after removing a card (let the number on it be x), you compare it with the card that was removed during the previous turn (let the number on it be y). Possible outcomes are: * if x < y, the game ends and you lose; * if x = y, the game ends and you win; * if x > y, the game continues. If there are no cards left in the bag, you lose. Cards are not returned into the bag after you remove them. You have to calculate the probability of winning in this game. It can be shown that it is in the form of P/Q where P and Q are non-negative integers and Q ≠ 0, P ≤ Q. Output the value of P ⋅ Q^{−1} ~(mod ~~ 998244353). Input The first line contains one integer n (2 ≤ n ≤ 5000) — the number of cards in the bag. The second live contains n integers a_1, a_2, ... a_n (1 ≤ a_i ≤ n) — the i-th integer is the number written on the i-th card. Output Print one integer — the probability of winning in this game modulo 998244353. Examples Input 5 1 1 4 2 3 Output 299473306 Input 2 2 2 Output 1 Input 5 4 5 1 3 2 Output 0 Input 4 1 3 4 3 Output 748683265 Note In the first test case the probability of winning is 1/10. In the second test case the probability of winning is 1. In the third test case the probability of winning is 0. In the fourth test case the probability of winning is 1/4. Submitted Solution: ``` def cmb(n, r, mod): if ( r<0 or r>n ): return 0 r = min(r, n-r) return g1[n] * g2[r] * g2[n-r] % mod mod = 998244353 N = 5001 g1 = [1]*(N+1) g2 = [1]*(N+1) inverse = [1]*(N+1) for i in range( 2, N + 1 ): g1[i]=( ( g1[i-1] * i ) % mod ) inverse[i]=( ( -inverse[mod % i] * (mod//i) ) % mod ) g2[i]=( (g2[i-1] * inverse[i]) % mod ) inverse[0]=0 def comp(L): S=list(set(L)) S.sort() return {i:e for e,i in enumerate(S)} mod=998244353 import random,time n=int(input()) a=list(map(int,input().split())) #a=[random.randint(0,10000) for i in range(n)] start=time.time() Comp=comp(a) N=max(Comp[i] for i in Comp)+1 cnt=[0]*N for i in range(n): id=Comp[a[i]] cnt[id]+=1 ans=0 for i in range(N): for j in range(i+1): ans+=cmb(i,j,mod)*(cnt[i]*(cnt[i]-1))*g1[n-2-j] ans%=mod ans*=g2[n] print(ans%mod) ```
instruction
0
30,127
19
60,254
No
output
1
30,127
19
60,255
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have a bag which contains n cards. There is a number written on each card; the number on i-th card is a_i. You are playing the following game. During each turn, you choose and remove a random card from the bag (all cards that are still left inside the bag are chosen equiprobably). Nothing else happens during the first turn — but during the next turns, after removing a card (let the number on it be x), you compare it with the card that was removed during the previous turn (let the number on it be y). Possible outcomes are: * if x < y, the game ends and you lose; * if x = y, the game ends and you win; * if x > y, the game continues. If there are no cards left in the bag, you lose. Cards are not returned into the bag after you remove them. You have to calculate the probability of winning in this game. It can be shown that it is in the form of P/Q where P and Q are non-negative integers and Q ≠ 0, P ≤ Q. Output the value of P ⋅ Q^{−1} ~(mod ~~ 998244353). Input The first line contains one integer n (2 ≤ n ≤ 5000) — the number of cards in the bag. The second live contains n integers a_1, a_2, ... a_n (1 ≤ a_i ≤ n) — the i-th integer is the number written on the i-th card. Output Print one integer — the probability of winning in this game modulo 998244353. Examples Input 5 1 1 4 2 3 Output 299473306 Input 2 2 2 Output 1 Input 5 4 5 1 3 2 Output 0 Input 4 1 3 4 3 Output 748683265 Note In the first test case the probability of winning is 1/10. In the second test case the probability of winning is 1. In the third test case the probability of winning is 0. In the fourth test case the probability of winning is 1/4. Submitted Solution: ``` def cmb(n, r, mod): if ( r<0 or r>n ): return 0 r = min(r, n-r) return g1[n] * g2[r] * g2[n-r] % mod mod = 998244353 N = 5001 g1 = [1]*(N+1) g2 = [1]*(N+1) inverse = [1]*(N+1) for i in range( 2, N + 1 ): g1[i]=( ( g1[i-1] * i ) % mod ) inverse[i]=( ( -inverse[mod % i] * (mod//i) ) % mod ) g2[i]=( (g2[i-1] * inverse[i]) % mod ) inverse[0]=0 def comp(L): S=list(set(L)) S.sort() return {i:e for e,i in enumerate(S)} mod=998244353 import random,time n=int(input()) #a=list(map(int,input().split())) a=[random.randint(0,10000) for i in range(n)] start=time.time() Comp=comp(a) N=max(Comp[i] for i in Comp)+1 cnt=[0]*N for i in range(n): id=Comp[a[i]] cnt[id]+=1 dp=[0 for i in range(n)] imos=[0 for i in range(n)] dp[0]=cnt[0] imos[0]=cnt[0] ans=dp[0]*((cnt[0]-1)*g1[n-2]%mod) for i in range(1,N): ndp=[0]*n nimos=[0]*n ndp[0]=cnt[i] ans+=ndp[0]*((cnt[i]-1)*g1[n-2]%mod) ans%=mod nimos[0]=(cnt[i]+imos[0])%mod for j in range(1,n): ndp[j]=(cnt[i]*imos[j-1])%mod ans+=ndp[j]*((cnt[i]-1)*g1[n-j-2]%mod) ans%=mod nimos[j]=(ndp[j]+imos[j])%mod dp=ndp imos=nimos ans*=g2[n] ans%=mod print(ans) #print(time.time()-start) ```
instruction
0
30,128
19
60,256
No
output
1
30,128
19
60,257
Provide tags and a correct Python 3 solution for this coding contest problem. A MIPT student named Misha has a birthday today, and he decided to celebrate it in his country house in suburban Moscow. n friends came by, and after a typical party they decided to play blind man's buff. The birthday boy gets blindfolded and the other players scatter around the house. The game is played in several rounds. In each round, Misha catches exactly one of his friends and has to guess who it is. The probability of catching the i-th friend does not change between rounds and is equal to pi percent (as we know, it is directly proportional to the amount of alcohol consumed by the i-th friend) and p1 + p2 + ... + pn = 100 holds. Misha has no information about who he caught. After Misha makes an attempt to guess the caught person, the round ends. Even then, Misha isn't told whether he guessed correctly, and a new round begins. The game ends when Misha guesses every friend at least once, that is, there exists such set of rounds k1, k2, ..., kn, that during round number ki Misha caught the i-th friend and guessed him. Misha wants to minimize the expectation of the number of rounds of the game. Despite the fact that at any point in the game Misha has no information about who he has already guessed, his friends are honest, and if they see that the condition for the end of the game is fulfilled, the game ends immediately. Find the expectation of the number of rounds in the game if Misha plays optimally. Input The first line of the input contains a single integer n (1 ≤ n ≤ 100) — the number of Misha's friends. The second line contains n integers pi (<image>), giving the probability to catch the i-th friend in one particular round in percent. Output Print a single real value — the expectation of the number of rounds provided that Misha plays optimally. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>. Examples Input 2 50 50 Output 5.0000000000 Input 4 50 20 20 10 Output 39.2846263444 Note The optimal strategy in the first sample is to guess friends alternately.
instruction
0
30,508
19
61,016
Tags: greedy, math, probabilities Correct Solution: ``` import random N = int(input()) prob = [float(x)/100 for x in input().strip().split()] prob_sum = [] cur = 0 for i in range(N): cur += prob[i] prob_sum.append(cur) def experiment(): cur_prob = [1.] * N cur_exp = 0 for i in range(200000): bp = [prob[i] * cur_prob[i] / (1-cur_prob[i]+1E-100) for i in range(N)] mn = max(bp) for j in range(N): if bp[j] == mn: choice = j cur_prob[choice] *= 1-prob[choice] tp = 1 for j in range(N): tp *= (1-cur_prob[j]) tp = 1 - tp cur_exp += tp return cur_exp + 1 ans = experiment() print(ans) ```
output
1
30,508
19
61,017
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A MIPT student named Misha has a birthday today, and he decided to celebrate it in his country house in suburban Moscow. n friends came by, and after a typical party they decided to play blind man's buff. The birthday boy gets blindfolded and the other players scatter around the house. The game is played in several rounds. In each round, Misha catches exactly one of his friends and has to guess who it is. The probability of catching the i-th friend does not change between rounds and is equal to pi percent (as we know, it is directly proportional to the amount of alcohol consumed by the i-th friend) and p1 + p2 + ... + pn = 100 holds. Misha has no information about who he caught. After Misha makes an attempt to guess the caught person, the round ends. Even then, Misha isn't told whether he guessed correctly, and a new round begins. The game ends when Misha guesses every friend at least once, that is, there exists such set of rounds k1, k2, ..., kn, that during round number ki Misha caught the i-th friend and guessed him. Misha wants to minimize the expectation of the number of rounds of the game. Despite the fact that at any point in the game Misha has no information about who he has already guessed, his friends are honest, and if they see that the condition for the end of the game is fulfilled, the game ends immediately. Find the expectation of the number of rounds in the game if Misha plays optimally. Input The first line of the input contains a single integer n (1 ≤ n ≤ 100) — the number of Misha's friends. The second line contains n integers pi (<image>), giving the probability to catch the i-th friend in one particular round in percent. Output Print a single real value — the expectation of the number of rounds provided that Misha plays optimally. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>. Examples Input 2 50 50 Output 5.0000000000 Input 4 50 20 20 10 Output 39.2846263444 Note The optimal strategy in the first sample is to guess friends alternately. Submitted Solution: ``` n = int(input()) tt = n p = list(map(lambda x: int(x)/100, input().split(' '))) k = [1 for i in range(n)] def prod(): t=1 for i in range(len(p)): t*=(1-(1-p[i])**k[i]) return t ex = n for i in p: ex*=i last = 1 while last*n > 1e-8: mi = -1 mv = 0 for j in range(tt): tmp = (1-p[j])**k[j]*p[j]/(1-(1-p[j])**k[j]) if tmp>mv: mv = tmp mi = j last = prod()*mv k[mi] += 1 n += 1 ex += n*last print(ex) ```
instruction
0
30,509
19
61,018
No
output
1
30,509
19
61,019