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
Provide tags and a correct Python 3 solution for this coding contest problem. Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: * Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. * Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get? Input The first line contains a single integer n (1 ≤ n ≤ 3·105). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the initial group that is given to Toastman. Output Print a single integer — the largest possible score. Examples Input 3 3 1 5 Output 26 Input 1 10 Output 10 Note Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.
instruction
0
44,216
19
88,432
Tags: greedy, sortings Correct Solution: ``` n=int(input()) l=list(map(int,input().split())) l.sort() s1=sum(l) s2=0 ans=s1 for i in range(n-1): #print(ans) s2+=l[i] ans+=s1+l[i]-s2 print(ans) ```
output
1
44,216
19
88,433
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: * Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. * Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get? Input The first line contains a single integer n (1 ≤ n ≤ 3·105). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the initial group that is given to Toastman. Output Print a single integer — the largest possible score. Examples Input 3 3 1 5 Output 26 Input 1 10 Output 10 Note Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions. Submitted Solution: ``` n=int(input()) a=input().split() b=[] s=0 for i in range(len(a)): b.append(int(a[i])) b.sort() for i in range(len(b)): s=s+b[i] for i in range(0,len(b)): s=s+(i+1)*b[i] s=s-int(b[n-1]) print(s) ```
instruction
0
44,217
19
88,434
Yes
output
1
44,217
19
88,435
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: * Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. * Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get? Input The first line contains a single integer n (1 ≤ n ≤ 3·105). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the initial group that is given to Toastman. Output Print a single integer — the largest possible score. Examples Input 3 3 1 5 Output 26 Input 1 10 Output 10 Note Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions. Submitted Solution: ``` from sys import stdin, stdout from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log from collections import defaultdict as dd, deque from heapq import merge, heapify, heappop, heappush, nsmallest from bisect import bisect_left as bl, bisect_right as br, bisect mod = pow(10, 9) + 7 mod2 = 998244353 def inp(): return stdin.readline().strip() def iinp(): return int(inp()) def out(var, end="\n"): stdout.write(str(var)+"\n") def outa(*var, end="\n"): stdout.write(' '.join(map(str, var)) + end) def lmp(): return list(mp()) def mp(): return map(int, inp().split()) def smp(): return map(str, inp().split()) def l1d(n, val=0): return [val for i in range(n)] def l2d(n, m, val=0): return [l1d(m, val) for j in range(n)] def remadd(x, y): return 1 if x%y else 0 def ceil(a,b): return (a+b-1)//b def isprime(x): if x<=1: return False if x in (2, 3): return True if x%2 == 0: return False for i in range(3, int(sqrt(x))+1, 2): if x%i == 0: return False return True n = iinp() arr = lmp() arr.sort(reverse=True) pre = [arr[0]] for i in range(1, n): pre.append(pre[-1]+arr[i]) ans = pre[-1]+sum(pre[1:]) print(ans) ```
instruction
0
44,218
19
88,436
Yes
output
1
44,218
19
88,437
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: * Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. * Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get? Input The first line contains a single integer n (1 ≤ n ≤ 3·105). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the initial group that is given to Toastman. Output Print a single integer — the largest possible score. Examples Input 3 3 1 5 Output 26 Input 1 10 Output 10 Note Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions. Submitted Solution: ``` n=int(input()) l=input().split() for i in range(0,n): l[i]=int(l[i]) m=sorted(l) x=0 for i in range(0,n): x=x+m[i]*(i+2) x=x-m[n-1] print(x) ```
instruction
0
44,219
19
88,438
Yes
output
1
44,219
19
88,439
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: * Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. * Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get? Input The first line contains a single integer n (1 ≤ n ≤ 3·105). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the initial group that is given to Toastman. Output Print a single integer — the largest possible score. Examples Input 3 3 1 5 Output 26 Input 1 10 Output 10 Note Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions. Submitted Solution: ``` from sys import stdin, stdout input = stdin.readline n = int(input()) a = sorted(list(map(int, input().split())), reverse = True) s = sum(a) ans = 0 for i in range(n): dlt = a.pop() ans += dlt + s s -= dlt stdout.write(str(ans - dlt)) ```
instruction
0
44,220
19
88,440
Yes
output
1
44,220
19
88,441
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: * Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. * Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get? Input The first line contains a single integer n (1 ≤ n ≤ 3·105). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the initial group that is given to Toastman. Output Print a single integer — the largest possible score. Examples Input 3 3 1 5 Output 26 Input 1 10 Output 10 Note Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions. Submitted Solution: ``` #461A. Appleman and Toastman, n = int(input()) l = [int(k) for k in input().split()] a = sum(l) l.sort() print(l) if n != 1: while n > 1: a += sum(l) del(l[0]) n -= 1 print(a) ```
instruction
0
44,221
19
88,442
No
output
1
44,221
19
88,443
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: * Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. * Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get? Input The first line contains a single integer n (1 ≤ n ≤ 3·105). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the initial group that is given to Toastman. Output Print a single integer — the largest possible score. Examples Input 3 3 1 5 Output 26 Input 1 10 Output 10 Note Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions. Submitted Solution: ``` import math, os, sys import string, re import itertools, functools, operator from collections import Counter def inputint(): return int(input()) def inputarray(func=int): return map(func, input().split()) def ans(A, i, j): if j - i == 1: return A[i] elif j - i == 2: return 2*(A[i] + A[i + 1]) else: m = i + (j - i)//2 return sum(A[i:j]) + ans(A, i, m) \ + ans(A, m, j) n = inputint() A = sorted(inputarray()) print(ans(A, 0, len(A))) ```
instruction
0
44,222
19
88,444
No
output
1
44,222
19
88,445
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: * Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. * Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get? Input The first line contains a single integer n (1 ≤ n ≤ 3·105). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the initial group that is given to Toastman. Output Print a single integer — the largest possible score. Examples Input 3 3 1 5 Output 26 Input 1 10 Output 10 Note Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions. Submitted Solution: ``` inp = int(input()) score = 0 currScore = 0 group = [] seq = input().split(" ") seq.sort() for i in range(inp): group.append(int(seq[i])) currScore += group[i] score += currScore for i in range(len(group)-1): score += group[i] currScore -= group[i] score += currScore print(score) ```
instruction
0
44,223
19
88,446
No
output
1
44,223
19
88,447
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: * Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. * Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get? Input The first line contains a single integer n (1 ≤ n ≤ 3·105). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the initial group that is given to Toastman. Output Print a single integer — the largest possible score. Examples Input 3 3 1 5 Output 26 Input 1 10 Output 10 Note Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions. Submitted Solution: ``` n=int(input()) a=sorted([int(x) for x in input().split()],reverse=True) score=0 for i in range(n): score=score+a[i]*(i+2) print(score-a[-1]) ```
instruction
0
44,224
19
88,448
No
output
1
44,224
19
88,449
Provide tags and a correct Python 3 solution for this coding contest problem. At regular competition Vladik and Valera won a and b candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vladik for same reason gave 3 candies to Valera in next turn. More formally, the guys take turns giving each other one candy more than they received in the previous turn. This continued until the moment when one of them couldn’t give the right amount of candy. Candies, which guys got from each other, they don’t consider as their own. You need to know, who is the first who can’t give the right amount of candy. Input Single line of input data contains two space-separated integers a, b (1 ≤ a, b ≤ 109) — number of Vladik and Valera candies respectively. Output Pring a single line "Vladik’’ in case, if Vladik first who can’t give right amount of candy, or "Valera’’ otherwise. Examples Input 1 1 Output Valera Input 7 6 Output Vladik Note Illustration for first test case: <image> Illustration for second test case: <image>
instruction
0
44,333
19
88,666
Tags: brute force, implementation Correct Solution: ``` def switch(A): if(A): return False return True [lad,ale]=input().split() [lad,ale]=[int(lad),int(ale)] check=True turn=False#lad's turn, tru=ale i=1 while check: if turn: ale=ale-i if(ale<0): check=False else: lad=lad-i if(lad<0): check=False turn=switch(turn) i=i+1 if not turn: print("Valera") else: print("Vladik") ```
output
1
44,333
19
88,667
Provide a correct Python 3 solution for this coding contest problem. Two players, A and B, play the game using cards with numbers from 0 to 9. First, the two arrange the given n cards face down in a horizontal row. After that, the two players turn their cards face up one by one from the left, and the owner of the card with the larger number takes the two cards. At this time, the sum of the numbers written on the two cards shall be the score of the player who took the card. However, if the same number is written on the two open cards, it is a draw and each player takes one of his own cards. For example, consider the case where the hands of A and B are arranged as shown in the following input examples 1 to 3. However, the input file consists of n + 1 lines, the first line contains the number of cards n for each player, and the i + 1 line (i = 1, 2, ..., n) is A. The numbers on the i-th card from the left and the numbers on the i-th card from the left of B are written in this order, with a blank as the delimiter. That is, from the second row onward of the input file, the left column represents the sequence of A cards, and the right column represents the sequence of B cards. At this time, the scores of A and B after the end of the game are shown in the corresponding output examples, respectively. Create a program that outputs the score of A and the score of B when the game corresponding to the input file ends on one line with a space as a delimiter in this order. However, n ≤ 10000. Input example 1 | Input example 2 | Input example 3 --- | --- | --- 3 | 3 | 3 9 1 | 9 1 | 9 1 5 4 | 5 4 | 5 5 0 8 | 1 0 | 1 8 Output example 1 | Output example 2 | Output example 3 19 8 | 20 0 | 15 14 input The input consists of multiple datasets. Input ends when n is 0. The number of datasets does not exceed 5. output For each dataset, the score of A and the score of B are output on one line. Input example 3 9 1 5 4 0 8 3 9 1 5 4 Ten 3 9 1 5 5 1 8 0 Output example 19 8 20 0 15 14 Insert a line break after the output of each dataset (after the score of B). The above question sentences and the data used for the automatic referee are the question sentences created and published by the Japan Committee for Information Olympics and the test data for scoring. Example Input 3 9 1 5 4 0 8 3 9 1 5 4 1 0 3 9 1 5 5 1 8 0 Output 19 8 20 0 15 14
instruction
0
44,583
19
89,166
"Correct Solution: ``` while 1: A=[] B=[] n=int(input()) if n==0: break else: for i in range(n): d=map(int,input().split(' ')) D=list(d) if D[0]>D[1]: A.append(D[0]) A.append(D[1]) elif D[0]==D[1]: A.append(D[0]) B.append(D[1]) else: B.append(D[0]) B.append(D[1]) AP=sum(A) BP=sum(B) print(AP,BP) #print (A,B) ```
output
1
44,583
19
89,167
Provide a correct Python 3 solution for this coding contest problem. Two players, A and B, play the game using cards with numbers from 0 to 9. First, the two arrange the given n cards face down in a horizontal row. After that, the two players turn their cards face up one by one from the left, and the owner of the card with the larger number takes the two cards. At this time, the sum of the numbers written on the two cards shall be the score of the player who took the card. However, if the same number is written on the two open cards, it is a draw and each player takes one of his own cards. For example, consider the case where the hands of A and B are arranged as shown in the following input examples 1 to 3. However, the input file consists of n + 1 lines, the first line contains the number of cards n for each player, and the i + 1 line (i = 1, 2, ..., n) is A. The numbers on the i-th card from the left and the numbers on the i-th card from the left of B are written in this order, with a blank as the delimiter. That is, from the second row onward of the input file, the left column represents the sequence of A cards, and the right column represents the sequence of B cards. At this time, the scores of A and B after the end of the game are shown in the corresponding output examples, respectively. Create a program that outputs the score of A and the score of B when the game corresponding to the input file ends on one line with a space as a delimiter in this order. However, n ≤ 10000. Input example 1 | Input example 2 | Input example 3 --- | --- | --- 3 | 3 | 3 9 1 | 9 1 | 9 1 5 4 | 5 4 | 5 5 0 8 | 1 0 | 1 8 Output example 1 | Output example 2 | Output example 3 19 8 | 20 0 | 15 14 input The input consists of multiple datasets. Input ends when n is 0. The number of datasets does not exceed 5. output For each dataset, the score of A and the score of B are output on one line. Input example 3 9 1 5 4 0 8 3 9 1 5 4 Ten 3 9 1 5 5 1 8 0 Output example 19 8 20 0 15 14 Insert a line break after the output of each dataset (after the score of B). The above question sentences and the data used for the automatic referee are the question sentences created and published by the Japan Committee for Information Olympics and the test data for scoring. Example Input 3 9 1 5 4 0 8 3 9 1 5 4 1 0 3 9 1 5 5 1 8 0 Output 19 8 20 0 15 14
instruction
0
44,584
19
89,168
"Correct Solution: ``` import collections import sys l = collections.deque(sys.stdin.readlines()) l.pop() s = "" while l: a = 0 b = 0 for i in range(int(l.popleft())): x,y = map(int, l.popleft().split()) if x > y: a = a + x + y elif x < y: b = b + x + y else: a = a+x b = b+y s += str(a) + " " + str(b) + "\n" print(s,end="") ```
output
1
44,584
19
89,169
Provide a correct Python 3 solution for this coding contest problem. Two players, A and B, play the game using cards with numbers from 0 to 9. First, the two arrange the given n cards face down in a horizontal row. After that, the two players turn their cards face up one by one from the left, and the owner of the card with the larger number takes the two cards. At this time, the sum of the numbers written on the two cards shall be the score of the player who took the card. However, if the same number is written on the two open cards, it is a draw and each player takes one of his own cards. For example, consider the case where the hands of A and B are arranged as shown in the following input examples 1 to 3. However, the input file consists of n + 1 lines, the first line contains the number of cards n for each player, and the i + 1 line (i = 1, 2, ..., n) is A. The numbers on the i-th card from the left and the numbers on the i-th card from the left of B are written in this order, with a blank as the delimiter. That is, from the second row onward of the input file, the left column represents the sequence of A cards, and the right column represents the sequence of B cards. At this time, the scores of A and B after the end of the game are shown in the corresponding output examples, respectively. Create a program that outputs the score of A and the score of B when the game corresponding to the input file ends on one line with a space as a delimiter in this order. However, n ≤ 10000. Input example 1 | Input example 2 | Input example 3 --- | --- | --- 3 | 3 | 3 9 1 | 9 1 | 9 1 5 4 | 5 4 | 5 5 0 8 | 1 0 | 1 8 Output example 1 | Output example 2 | Output example 3 19 8 | 20 0 | 15 14 input The input consists of multiple datasets. Input ends when n is 0. The number of datasets does not exceed 5. output For each dataset, the score of A and the score of B are output on one line. Input example 3 9 1 5 4 0 8 3 9 1 5 4 Ten 3 9 1 5 5 1 8 0 Output example 19 8 20 0 15 14 Insert a line break after the output of each dataset (after the score of B). The above question sentences and the data used for the automatic referee are the question sentences created and published by the Japan Committee for Information Olympics and the test data for scoring. Example Input 3 9 1 5 4 0 8 3 9 1 5 4 1 0 3 9 1 5 5 1 8 0 Output 19 8 20 0 15 14
instruction
0
44,585
19
89,170
"Correct Solution: ``` while True: n = int(input()) if n == 0: break a = 0 b = 0 for i in range(n): a1,b1 = map(int,input().split()) if a1 > b1: a += a1+b1 elif a1 < b1: b += a1+b1 else: a += a1 b += b1 print(a,b) ```
output
1
44,585
19
89,171
Provide a correct Python 3 solution for this coding contest problem. Two players, A and B, play the game using cards with numbers from 0 to 9. First, the two arrange the given n cards face down in a horizontal row. After that, the two players turn their cards face up one by one from the left, and the owner of the card with the larger number takes the two cards. At this time, the sum of the numbers written on the two cards shall be the score of the player who took the card. However, if the same number is written on the two open cards, it is a draw and each player takes one of his own cards. For example, consider the case where the hands of A and B are arranged as shown in the following input examples 1 to 3. However, the input file consists of n + 1 lines, the first line contains the number of cards n for each player, and the i + 1 line (i = 1, 2, ..., n) is A. The numbers on the i-th card from the left and the numbers on the i-th card from the left of B are written in this order, with a blank as the delimiter. That is, from the second row onward of the input file, the left column represents the sequence of A cards, and the right column represents the sequence of B cards. At this time, the scores of A and B after the end of the game are shown in the corresponding output examples, respectively. Create a program that outputs the score of A and the score of B when the game corresponding to the input file ends on one line with a space as a delimiter in this order. However, n ≤ 10000. Input example 1 | Input example 2 | Input example 3 --- | --- | --- 3 | 3 | 3 9 1 | 9 1 | 9 1 5 4 | 5 4 | 5 5 0 8 | 1 0 | 1 8 Output example 1 | Output example 2 | Output example 3 19 8 | 20 0 | 15 14 input The input consists of multiple datasets. Input ends when n is 0. The number of datasets does not exceed 5. output For each dataset, the score of A and the score of B are output on one line. Input example 3 9 1 5 4 0 8 3 9 1 5 4 Ten 3 9 1 5 5 1 8 0 Output example 19 8 20 0 15 14 Insert a line break after the output of each dataset (after the score of B). The above question sentences and the data used for the automatic referee are the question sentences created and published by the Japan Committee for Information Olympics and the test data for scoring. Example Input 3 9 1 5 4 0 8 3 9 1 5 4 1 0 3 9 1 5 5 1 8 0 Output 19 8 20 0 15 14
instruction
0
44,586
19
89,172
"Correct Solution: ``` while True: n = int(input()) if n == 0: break ascore = 0 bscore = 0 for i in range(n): a,b = list(map(int,input().split())) if a < b: bscore += a + b elif a > b: ascore += a + b elif a == b: ascore += a bscore += b print(f"{ascore} {bscore}") ```
output
1
44,586
19
89,173
Provide a correct Python 3 solution for this coding contest problem. Two players, A and B, play the game using cards with numbers from 0 to 9. First, the two arrange the given n cards face down in a horizontal row. After that, the two players turn their cards face up one by one from the left, and the owner of the card with the larger number takes the two cards. At this time, the sum of the numbers written on the two cards shall be the score of the player who took the card. However, if the same number is written on the two open cards, it is a draw and each player takes one of his own cards. For example, consider the case where the hands of A and B are arranged as shown in the following input examples 1 to 3. However, the input file consists of n + 1 lines, the first line contains the number of cards n for each player, and the i + 1 line (i = 1, 2, ..., n) is A. The numbers on the i-th card from the left and the numbers on the i-th card from the left of B are written in this order, with a blank as the delimiter. That is, from the second row onward of the input file, the left column represents the sequence of A cards, and the right column represents the sequence of B cards. At this time, the scores of A and B after the end of the game are shown in the corresponding output examples, respectively. Create a program that outputs the score of A and the score of B when the game corresponding to the input file ends on one line with a space as a delimiter in this order. However, n ≤ 10000. Input example 1 | Input example 2 | Input example 3 --- | --- | --- 3 | 3 | 3 9 1 | 9 1 | 9 1 5 4 | 5 4 | 5 5 0 8 | 1 0 | 1 8 Output example 1 | Output example 2 | Output example 3 19 8 | 20 0 | 15 14 input The input consists of multiple datasets. Input ends when n is 0. The number of datasets does not exceed 5. output For each dataset, the score of A and the score of B are output on one line. Input example 3 9 1 5 4 0 8 3 9 1 5 4 Ten 3 9 1 5 5 1 8 0 Output example 19 8 20 0 15 14 Insert a line break after the output of each dataset (after the score of B). The above question sentences and the data used for the automatic referee are the question sentences created and published by the Japan Committee for Information Olympics and the test data for scoring. Example Input 3 9 1 5 4 0 8 3 9 1 5 4 1 0 3 9 1 5 5 1 8 0 Output 19 8 20 0 15 14
instruction
0
44,587
19
89,174
"Correct Solution: ``` #!/usr/bin/env python # -*- coding: utf-8 -*- while True: n = int(input()) if n == 0: break A, B = 0, 0 for i in range(n): a, b = map(int, input().split()) if a > b: A += a + b elif a < b: B += a + b else: A += a B += b print(A, B) ```
output
1
44,587
19
89,175
Provide a correct Python 3 solution for this coding contest problem. Two players, A and B, play the game using cards with numbers from 0 to 9. First, the two arrange the given n cards face down in a horizontal row. After that, the two players turn their cards face up one by one from the left, and the owner of the card with the larger number takes the two cards. At this time, the sum of the numbers written on the two cards shall be the score of the player who took the card. However, if the same number is written on the two open cards, it is a draw and each player takes one of his own cards. For example, consider the case where the hands of A and B are arranged as shown in the following input examples 1 to 3. However, the input file consists of n + 1 lines, the first line contains the number of cards n for each player, and the i + 1 line (i = 1, 2, ..., n) is A. The numbers on the i-th card from the left and the numbers on the i-th card from the left of B are written in this order, with a blank as the delimiter. That is, from the second row onward of the input file, the left column represents the sequence of A cards, and the right column represents the sequence of B cards. At this time, the scores of A and B after the end of the game are shown in the corresponding output examples, respectively. Create a program that outputs the score of A and the score of B when the game corresponding to the input file ends on one line with a space as a delimiter in this order. However, n ≤ 10000. Input example 1 | Input example 2 | Input example 3 --- | --- | --- 3 | 3 | 3 9 1 | 9 1 | 9 1 5 4 | 5 4 | 5 5 0 8 | 1 0 | 1 8 Output example 1 | Output example 2 | Output example 3 19 8 | 20 0 | 15 14 input The input consists of multiple datasets. Input ends when n is 0. The number of datasets does not exceed 5. output For each dataset, the score of A and the score of B are output on one line. Input example 3 9 1 5 4 0 8 3 9 1 5 4 Ten 3 9 1 5 5 1 8 0 Output example 19 8 20 0 15 14 Insert a line break after the output of each dataset (after the score of B). The above question sentences and the data used for the automatic referee are the question sentences created and published by the Japan Committee for Information Olympics and the test data for scoring. Example Input 3 9 1 5 4 0 8 3 9 1 5 4 1 0 3 9 1 5 5 1 8 0 Output 19 8 20 0 15 14
instruction
0
44,588
19
89,176
"Correct Solution: ``` while True: n_line = input() if n_line == "0": break score_a, score_b = (0, 0) for i in range(int(n_line)): a, b = [int(x) for x in input().split(" ")] if a > b: score_a += a + b elif a < b: score_b += a + b else: score_a += a score_b += b print("{} {}".format(score_a, score_b)) ```
output
1
44,588
19
89,177
Provide a correct Python 3 solution for this coding contest problem. Two players, A and B, play the game using cards with numbers from 0 to 9. First, the two arrange the given n cards face down in a horizontal row. After that, the two players turn their cards face up one by one from the left, and the owner of the card with the larger number takes the two cards. At this time, the sum of the numbers written on the two cards shall be the score of the player who took the card. However, if the same number is written on the two open cards, it is a draw and each player takes one of his own cards. For example, consider the case where the hands of A and B are arranged as shown in the following input examples 1 to 3. However, the input file consists of n + 1 lines, the first line contains the number of cards n for each player, and the i + 1 line (i = 1, 2, ..., n) is A. The numbers on the i-th card from the left and the numbers on the i-th card from the left of B are written in this order, with a blank as the delimiter. That is, from the second row onward of the input file, the left column represents the sequence of A cards, and the right column represents the sequence of B cards. At this time, the scores of A and B after the end of the game are shown in the corresponding output examples, respectively. Create a program that outputs the score of A and the score of B when the game corresponding to the input file ends on one line with a space as a delimiter in this order. However, n ≤ 10000. Input example 1 | Input example 2 | Input example 3 --- | --- | --- 3 | 3 | 3 9 1 | 9 1 | 9 1 5 4 | 5 4 | 5 5 0 8 | 1 0 | 1 8 Output example 1 | Output example 2 | Output example 3 19 8 | 20 0 | 15 14 input The input consists of multiple datasets. Input ends when n is 0. The number of datasets does not exceed 5. output For each dataset, the score of A and the score of B are output on one line. Input example 3 9 1 5 4 0 8 3 9 1 5 4 Ten 3 9 1 5 5 1 8 0 Output example 19 8 20 0 15 14 Insert a line break after the output of each dataset (after the score of B). The above question sentences and the data used for the automatic referee are the question sentences created and published by the Japan Committee for Information Olympics and the test data for scoring. Example Input 3 9 1 5 4 0 8 3 9 1 5 4 1 0 3 9 1 5 5 1 8 0 Output 19 8 20 0 15 14
instruction
0
44,589
19
89,178
"Correct Solution: ``` while True: n = int(input()) if n == 0: break A = B = 0 for i in range(n): a, b = map(int, input().split()) if a == b: A += a B += b elif a > b: A += a+b else: B += a+b print(A, B) ```
output
1
44,589
19
89,179
Provide a correct Python 3 solution for this coding contest problem. Two players, A and B, play the game using cards with numbers from 0 to 9. First, the two arrange the given n cards face down in a horizontal row. After that, the two players turn their cards face up one by one from the left, and the owner of the card with the larger number takes the two cards. At this time, the sum of the numbers written on the two cards shall be the score of the player who took the card. However, if the same number is written on the two open cards, it is a draw and each player takes one of his own cards. For example, consider the case where the hands of A and B are arranged as shown in the following input examples 1 to 3. However, the input file consists of n + 1 lines, the first line contains the number of cards n for each player, and the i + 1 line (i = 1, 2, ..., n) is A. The numbers on the i-th card from the left and the numbers on the i-th card from the left of B are written in this order, with a blank as the delimiter. That is, from the second row onward of the input file, the left column represents the sequence of A cards, and the right column represents the sequence of B cards. At this time, the scores of A and B after the end of the game are shown in the corresponding output examples, respectively. Create a program that outputs the score of A and the score of B when the game corresponding to the input file ends on one line with a space as a delimiter in this order. However, n ≤ 10000. Input example 1 | Input example 2 | Input example 3 --- | --- | --- 3 | 3 | 3 9 1 | 9 1 | 9 1 5 4 | 5 4 | 5 5 0 8 | 1 0 | 1 8 Output example 1 | Output example 2 | Output example 3 19 8 | 20 0 | 15 14 input The input consists of multiple datasets. Input ends when n is 0. The number of datasets does not exceed 5. output For each dataset, the score of A and the score of B are output on one line. Input example 3 9 1 5 4 0 8 3 9 1 5 4 Ten 3 9 1 5 5 1 8 0 Output example 19 8 20 0 15 14 Insert a line break after the output of each dataset (after the score of B). The above question sentences and the data used for the automatic referee are the question sentences created and published by the Japan Committee for Information Olympics and the test data for scoring. Example Input 3 9 1 5 4 0 8 3 9 1 5 4 1 0 3 9 1 5 5 1 8 0 Output 19 8 20 0 15 14
instruction
0
44,590
19
89,180
"Correct Solution: ``` while True: n = int(input()) if n == 0:break A = B = 0 for i in range(n): a,b = map(int,input().split()) if a > b:A += a + b elif a < b:B += a + b else: A+=a B+=b print(A,B) ```
output
1
44,590
19
89,181
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two players, A and B, play the game using cards with numbers from 0 to 9. First, the two arrange the given n cards face down in a horizontal row. After that, the two players turn their cards face up one by one from the left, and the owner of the card with the larger number takes the two cards. At this time, the sum of the numbers written on the two cards shall be the score of the player who took the card. However, if the same number is written on the two open cards, it is a draw and each player takes one of his own cards. For example, consider the case where the hands of A and B are arranged as shown in the following input examples 1 to 3. However, the input file consists of n + 1 lines, the first line contains the number of cards n for each player, and the i + 1 line (i = 1, 2, ..., n) is A. The numbers on the i-th card from the left and the numbers on the i-th card from the left of B are written in this order, with a blank as the delimiter. That is, from the second row onward of the input file, the left column represents the sequence of A cards, and the right column represents the sequence of B cards. At this time, the scores of A and B after the end of the game are shown in the corresponding output examples, respectively. Create a program that outputs the score of A and the score of B when the game corresponding to the input file ends on one line with a space as a delimiter in this order. However, n ≤ 10000. Input example 1 | Input example 2 | Input example 3 --- | --- | --- 3 | 3 | 3 9 1 | 9 1 | 9 1 5 4 | 5 4 | 5 5 0 8 | 1 0 | 1 8 Output example 1 | Output example 2 | Output example 3 19 8 | 20 0 | 15 14 input The input consists of multiple datasets. Input ends when n is 0. The number of datasets does not exceed 5. output For each dataset, the score of A and the score of B are output on one line. Input example 3 9 1 5 4 0 8 3 9 1 5 4 Ten 3 9 1 5 5 1 8 0 Output example 19 8 20 0 15 14 Insert a line break after the output of each dataset (after the score of B). The above question sentences and the data used for the automatic referee are the question sentences created and published by the Japan Committee for Information Olympics and the test data for scoring. Example Input 3 9 1 5 4 0 8 3 9 1 5 4 1 0 3 9 1 5 5 1 8 0 Output 19 8 20 0 15 14 Submitted Solution: ``` def evaluate_score(data): a_score = 0 b_score = 0 for a, b in data: if a > b: a_score += (a + b) elif b > a: b_score += (a + b) else: a_score += a b_score += b return a_score, b_score if __name__ == '__main__': # ??????????????\??? while True: data_num = int(input()) if data_num == 0: break data = [] for i in range(data_num): data.append([int(x) for x in input().split(' ')]) # ??????????????? a_scores, b_scores = evaluate_score(data) # ???????????¨??? print('{0} {1}'.format(a_scores, b_scores)) ```
instruction
0
44,591
19
89,182
Yes
output
1
44,591
19
89,183
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two players, A and B, play the game using cards with numbers from 0 to 9. First, the two arrange the given n cards face down in a horizontal row. After that, the two players turn their cards face up one by one from the left, and the owner of the card with the larger number takes the two cards. At this time, the sum of the numbers written on the two cards shall be the score of the player who took the card. However, if the same number is written on the two open cards, it is a draw and each player takes one of his own cards. For example, consider the case where the hands of A and B are arranged as shown in the following input examples 1 to 3. However, the input file consists of n + 1 lines, the first line contains the number of cards n for each player, and the i + 1 line (i = 1, 2, ..., n) is A. The numbers on the i-th card from the left and the numbers on the i-th card from the left of B are written in this order, with a blank as the delimiter. That is, from the second row onward of the input file, the left column represents the sequence of A cards, and the right column represents the sequence of B cards. At this time, the scores of A and B after the end of the game are shown in the corresponding output examples, respectively. Create a program that outputs the score of A and the score of B when the game corresponding to the input file ends on one line with a space as a delimiter in this order. However, n ≤ 10000. Input example 1 | Input example 2 | Input example 3 --- | --- | --- 3 | 3 | 3 9 1 | 9 1 | 9 1 5 4 | 5 4 | 5 5 0 8 | 1 0 | 1 8 Output example 1 | Output example 2 | Output example 3 19 8 | 20 0 | 15 14 input The input consists of multiple datasets. Input ends when n is 0. The number of datasets does not exceed 5. output For each dataset, the score of A and the score of B are output on one line. Input example 3 9 1 5 4 0 8 3 9 1 5 4 Ten 3 9 1 5 5 1 8 0 Output example 19 8 20 0 15 14 Insert a line break after the output of each dataset (after the score of B). The above question sentences and the data used for the automatic referee are the question sentences created and published by the Japan Committee for Information Olympics and the test data for scoring. Example Input 3 9 1 5 4 0 8 3 9 1 5 4 1 0 3 9 1 5 5 1 8 0 Output 19 8 20 0 15 14 Submitted Solution: ``` def main(): while True: n = int(input()) player1 = 0 player2 = 0 if n == 0: break for i in range(n): str = input().split() right = int(str[0]) left = int(str[1]) if right > left: player1 += right + left elif right < left: player2 += right + left else: player1 += right player2 += left print("{0} {1}".format(player1, player2) ) if __name__=="__main__": main() ```
instruction
0
44,592
19
89,184
Yes
output
1
44,592
19
89,185
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two players, A and B, play the game using cards with numbers from 0 to 9. First, the two arrange the given n cards face down in a horizontal row. After that, the two players turn their cards face up one by one from the left, and the owner of the card with the larger number takes the two cards. At this time, the sum of the numbers written on the two cards shall be the score of the player who took the card. However, if the same number is written on the two open cards, it is a draw and each player takes one of his own cards. For example, consider the case where the hands of A and B are arranged as shown in the following input examples 1 to 3. However, the input file consists of n + 1 lines, the first line contains the number of cards n for each player, and the i + 1 line (i = 1, 2, ..., n) is A. The numbers on the i-th card from the left and the numbers on the i-th card from the left of B are written in this order, with a blank as the delimiter. That is, from the second row onward of the input file, the left column represents the sequence of A cards, and the right column represents the sequence of B cards. At this time, the scores of A and B after the end of the game are shown in the corresponding output examples, respectively. Create a program that outputs the score of A and the score of B when the game corresponding to the input file ends on one line with a space as a delimiter in this order. However, n ≤ 10000. Input example 1 | Input example 2 | Input example 3 --- | --- | --- 3 | 3 | 3 9 1 | 9 1 | 9 1 5 4 | 5 4 | 5 5 0 8 | 1 0 | 1 8 Output example 1 | Output example 2 | Output example 3 19 8 | 20 0 | 15 14 input The input consists of multiple datasets. Input ends when n is 0. The number of datasets does not exceed 5. output For each dataset, the score of A and the score of B are output on one line. Input example 3 9 1 5 4 0 8 3 9 1 5 4 Ten 3 9 1 5 5 1 8 0 Output example 19 8 20 0 15 14 Insert a line break after the output of each dataset (after the score of B). The above question sentences and the data used for the automatic referee are the question sentences created and published by the Japan Committee for Information Olympics and the test data for scoring. Example Input 3 9 1 5 4 0 8 3 9 1 5 4 1 0 3 9 1 5 5 1 8 0 Output 19 8 20 0 15 14 Submitted Solution: ``` while 1: n = int(input()) if n == 0: break sum_a = 0 sum_b = 0 for i in range(n): a,b = map(int, input().split()) if a > b: sum_a = sum_a + a + b elif a < b: sum_b = sum_b + a + b elif a == b: sum_a = sum_a + a sum_b = sum_b + b print("%s %s" %(sum_a,sum_b)) ```
instruction
0
44,593
19
89,186
Yes
output
1
44,593
19
89,187
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two players, A and B, play the game using cards with numbers from 0 to 9. First, the two arrange the given n cards face down in a horizontal row. After that, the two players turn their cards face up one by one from the left, and the owner of the card with the larger number takes the two cards. At this time, the sum of the numbers written on the two cards shall be the score of the player who took the card. However, if the same number is written on the two open cards, it is a draw and each player takes one of his own cards. For example, consider the case where the hands of A and B are arranged as shown in the following input examples 1 to 3. However, the input file consists of n + 1 lines, the first line contains the number of cards n for each player, and the i + 1 line (i = 1, 2, ..., n) is A. The numbers on the i-th card from the left and the numbers on the i-th card from the left of B are written in this order, with a blank as the delimiter. That is, from the second row onward of the input file, the left column represents the sequence of A cards, and the right column represents the sequence of B cards. At this time, the scores of A and B after the end of the game are shown in the corresponding output examples, respectively. Create a program that outputs the score of A and the score of B when the game corresponding to the input file ends on one line with a space as a delimiter in this order. However, n ≤ 10000. Input example 1 | Input example 2 | Input example 3 --- | --- | --- 3 | 3 | 3 9 1 | 9 1 | 9 1 5 4 | 5 4 | 5 5 0 8 | 1 0 | 1 8 Output example 1 | Output example 2 | Output example 3 19 8 | 20 0 | 15 14 input The input consists of multiple datasets. Input ends when n is 0. The number of datasets does not exceed 5. output For each dataset, the score of A and the score of B are output on one line. Input example 3 9 1 5 4 0 8 3 9 1 5 4 Ten 3 9 1 5 5 1 8 0 Output example 19 8 20 0 15 14 Insert a line break after the output of each dataset (after the score of B). The above question sentences and the data used for the automatic referee are the question sentences created and published by the Japan Committee for Information Olympics and the test data for scoring. Example Input 3 9 1 5 4 0 8 3 9 1 5 4 1 0 3 9 1 5 5 1 8 0 Output 19 8 20 0 15 14 Submitted Solution: ``` while 1: n = int(input()) scoreA = 0 scoreB = 0 if n == 0: break for i in range(n): A,B = map(int, input().split()) if A > B: scoreA += A + B elif A < B : scoreB += A + B elif A == B: scoreA += A scoreB += B print(scoreA,scoreB) ```
instruction
0
44,594
19
89,188
Yes
output
1
44,594
19
89,189
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two players, A and B, play the game using cards with numbers from 0 to 9. First, the two arrange the given n cards face down in a horizontal row. After that, the two players turn their cards face up one by one from the left, and the owner of the card with the larger number takes the two cards. At this time, the sum of the numbers written on the two cards shall be the score of the player who took the card. However, if the same number is written on the two open cards, it is a draw and each player takes one of his own cards. For example, consider the case where the hands of A and B are arranged as shown in the following input examples 1 to 3. However, the input file consists of n + 1 lines, the first line contains the number of cards n for each player, and the i + 1 line (i = 1, 2, ..., n) is A. The numbers on the i-th card from the left and the numbers on the i-th card from the left of B are written in this order, with a blank as the delimiter. That is, from the second row onward of the input file, the left column represents the sequence of A cards, and the right column represents the sequence of B cards. At this time, the scores of A and B after the end of the game are shown in the corresponding output examples, respectively. Create a program that outputs the score of A and the score of B when the game corresponding to the input file ends on one line with a space as a delimiter in this order. However, n ≤ 10000. Input example 1 | Input example 2 | Input example 3 --- | --- | --- 3 | 3 | 3 9 1 | 9 1 | 9 1 5 4 | 5 4 | 5 5 0 8 | 1 0 | 1 8 Output example 1 | Output example 2 | Output example 3 19 8 | 20 0 | 15 14 input The input consists of multiple datasets. Input ends when n is 0. The number of datasets does not exceed 5. output For each dataset, the score of A and the score of B are output on one line. Input example 3 9 1 5 4 0 8 3 9 1 5 4 Ten 3 9 1 5 5 1 8 0 Output example 19 8 20 0 15 14 Insert a line break after the output of each dataset (after the score of B). The above question sentences and the data used for the automatic referee are the question sentences created and published by the Japan Committee for Information Olympics and the test data for scoring. Example Input 3 9 1 5 4 0 8 3 9 1 5 4 1 0 3 9 1 5 5 1 8 0 Output 19 8 20 0 15 14 Submitted Solution: ``` A_cards, B_cards = [], [] A_result, B_result = 0, 0 while True: n = int(input()) if n == 0: break for i in range(n): A, B = map(int, input().split()) A_cards.append(A) B_cards.append(B) if A_cards[i] > B_cards[i]: A_result += A_cards[i] + B_cards[i] elif A_cards[i] < B_cards[i]: B_result += A_cards[i] + B_cards[i] else: A_result += A_cards[i] B_result += B_cards[i] print('{} {}'.format(A_result, B_result)) ```
instruction
0
44,595
19
89,190
No
output
1
44,595
19
89,191
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two players, A and B, play the game using cards with numbers from 0 to 9. First, the two arrange the given n cards face down in a horizontal row. After that, the two players turn their cards face up one by one from the left, and the owner of the card with the larger number takes the two cards. At this time, the sum of the numbers written on the two cards shall be the score of the player who took the card. However, if the same number is written on the two open cards, it is a draw and each player takes one of his own cards. For example, consider the case where the hands of A and B are arranged as shown in the following input examples 1 to 3. However, the input file consists of n + 1 lines, the first line contains the number of cards n for each player, and the i + 1 line (i = 1, 2, ..., n) is A. The numbers on the i-th card from the left and the numbers on the i-th card from the left of B are written in this order, with a blank as the delimiter. That is, from the second row onward of the input file, the left column represents the sequence of A cards, and the right column represents the sequence of B cards. At this time, the scores of A and B after the end of the game are shown in the corresponding output examples, respectively. Create a program that outputs the score of A and the score of B when the game corresponding to the input file ends on one line with a space as a delimiter in this order. However, n ≤ 10000. Input example 1 | Input example 2 | Input example 3 --- | --- | --- 3 | 3 | 3 9 1 | 9 1 | 9 1 5 4 | 5 4 | 5 5 0 8 | 1 0 | 1 8 Output example 1 | Output example 2 | Output example 3 19 8 | 20 0 | 15 14 input The input consists of multiple datasets. Input ends when n is 0. The number of datasets does not exceed 5. output For each dataset, the score of A and the score of B are output on one line. Input example 3 9 1 5 4 0 8 3 9 1 5 4 Ten 3 9 1 5 5 1 8 0 Output example 19 8 20 0 15 14 Insert a line break after the output of each dataset (after the score of B). The above question sentences and the data used for the automatic referee are the question sentences created and published by the Japan Committee for Information Olympics and the test data for scoring. Example Input 3 9 1 5 4 0 8 3 9 1 5 4 1 0 3 9 1 5 5 1 8 0 Output 19 8 20 0 15 14 Submitted Solution: ``` while True: n_line = input() if n_line == "0": break score_a, score_b = (0, 0) for i in range(int(n_line)): a, b = [int(x) for x in input().split(" ")] if a >= b: score_a += a if a <= b: score_b += b print("{} {}".format(score_a, score_b)) ```
instruction
0
44,596
19
89,192
No
output
1
44,596
19
89,193
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two players, A and B, play the game using cards with numbers from 0 to 9. First, the two arrange the given n cards face down in a horizontal row. After that, the two players turn their cards face up one by one from the left, and the owner of the card with the larger number takes the two cards. At this time, the sum of the numbers written on the two cards shall be the score of the player who took the card. However, if the same number is written on the two open cards, it is a draw and each player takes one of his own cards. For example, consider the case where the hands of A and B are arranged as shown in the following input examples 1 to 3. However, the input file consists of n + 1 lines, the first line contains the number of cards n for each player, and the i + 1 line (i = 1, 2, ..., n) is A. The numbers on the i-th card from the left and the numbers on the i-th card from the left of B are written in this order, with a blank as the delimiter. That is, from the second row onward of the input file, the left column represents the sequence of A cards, and the right column represents the sequence of B cards. At this time, the scores of A and B after the end of the game are shown in the corresponding output examples, respectively. Create a program that outputs the score of A and the score of B when the game corresponding to the input file ends on one line with a space as a delimiter in this order. However, n ≤ 10000. Input example 1 | Input example 2 | Input example 3 --- | --- | --- 3 | 3 | 3 9 1 | 9 1 | 9 1 5 4 | 5 4 | 5 5 0 8 | 1 0 | 1 8 Output example 1 | Output example 2 | Output example 3 19 8 | 20 0 | 15 14 input The input consists of multiple datasets. Input ends when n is 0. The number of datasets does not exceed 5. output For each dataset, the score of A and the score of B are output on one line. Input example 3 9 1 5 4 0 8 3 9 1 5 4 Ten 3 9 1 5 5 1 8 0 Output example 19 8 20 0 15 14 Insert a line break after the output of each dataset (after the score of B). The above question sentences and the data used for the automatic referee are the question sentences created and published by the Japan Committee for Information Olympics and the test data for scoring. Example Input 3 9 1 5 4 0 8 3 9 1 5 4 1 0 3 9 1 5 5 1 8 0 Output 19 8 20 0 15 14 Submitted Solution: ``` while True: try: n = int(input()) scores = [0, 0] for i in range(n): cards = list(map(int, input().split())) if cards[0] > cards[1]: scores[0] += cards[0] + cards[1] elif cards[0] < cards[1]: scores[1] += cards[0] + cards[1] else: scores[0] += cards[0] scores[1] += cards[1] print(' '.join([str(score) for score in scores])) except EOFError: exit() ```
instruction
0
44,597
19
89,194
No
output
1
44,597
19
89,195
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two players, A and B, play the game using cards with numbers from 0 to 9. First, the two arrange the given n cards face down in a horizontal row. After that, the two players turn their cards face up one by one from the left, and the owner of the card with the larger number takes the two cards. At this time, the sum of the numbers written on the two cards shall be the score of the player who took the card. However, if the same number is written on the two open cards, it is a draw and each player takes one of his own cards. For example, consider the case where the hands of A and B are arranged as shown in the following input examples 1 to 3. However, the input file consists of n + 1 lines, the first line contains the number of cards n for each player, and the i + 1 line (i = 1, 2, ..., n) is A. The numbers on the i-th card from the left and the numbers on the i-th card from the left of B are written in this order, with a blank as the delimiter. That is, from the second row onward of the input file, the left column represents the sequence of A cards, and the right column represents the sequence of B cards. At this time, the scores of A and B after the end of the game are shown in the corresponding output examples, respectively. Create a program that outputs the score of A and the score of B when the game corresponding to the input file ends on one line with a space as a delimiter in this order. However, n ≤ 10000. Input example 1 | Input example 2 | Input example 3 --- | --- | --- 3 | 3 | 3 9 1 | 9 1 | 9 1 5 4 | 5 4 | 5 5 0 8 | 1 0 | 1 8 Output example 1 | Output example 2 | Output example 3 19 8 | 20 0 | 15 14 input The input consists of multiple datasets. Input ends when n is 0. The number of datasets does not exceed 5. output For each dataset, the score of A and the score of B are output on one line. Input example 3 9 1 5 4 0 8 3 9 1 5 4 Ten 3 9 1 5 5 1 8 0 Output example 19 8 20 0 15 14 Insert a line break after the output of each dataset (after the score of B). The above question sentences and the data used for the automatic referee are the question sentences created and published by the Japan Committee for Information Olympics and the test data for scoring. Example Input 3 9 1 5 4 0 8 3 9 1 5 4 1 0 3 9 1 5 5 1 8 0 Output 19 8 20 0 15 14 Submitted Solution: ``` import sys e=iter(sys.stdin) while 1: a=b=0;n=int(e) if n==0:break for i in[0]*n: s,t=map(int,e.split()) if s>t:a+=s+t elif s<t:b+=s+t else:a+=s;b+=t print(a,b) ```
instruction
0
44,598
19
89,196
No
output
1
44,598
19
89,197
Provide a correct Python 3 solution for this coding contest problem. Professor Random, known for his research on randomized algorithms, is now conducting an experiment on biased dice. His experiment consists of dropping a number of dice onto a plane, one after another from a fixed position above the plane. The dice fall onto the plane or dice already there, without rotating, and may roll and fall according to their property. Then he observes and records the status of the stack formed on the plane, specifically, how many times each number appears on the faces visible from above. All the dice have the same size and their face numbering is identical, which we show in Figure C-1. <image> Figure C-1: Numbering of a die The dice have very special properties, as in the following. (1) Ordinary dice can roll in four directions, but the dice used in this experiment never roll in the directions of faces 1, 2 and 3; they can only roll in the directions of faces 4, 5 and 6. In the situation shown in Figure C-2, our die can only roll to one of two directions. <image> Figure C-2: An ordinary die and a biased die (2) The die can only roll when it will fall down after rolling, as shown in Figure C-3. When multiple possibilities exist, the die rolls towards the face with the largest number among those directions it can roll to. <image> Figure C-3: A die can roll only when it can fall (3) When a die rolls, it rolls exactly 90 degrees, and then falls straight down until its bottom face touches another die or the plane, as in the case [B] or [C] of Figure C-4. (4) After rolling and falling, the die repeatedly does so according to the rules (1) to (3) above. <image> Figure C-4: Example stacking of biased dice For example, when we drop four dice all in the same orientation, 6 at the top and 4 at the front, then a stack will be formed as shown in Figure C-4. <image> Figure C-5: Example records After forming the stack, we count the numbers of faces with 1 through 6 visible from above and record them. For example, in the left case of Figure C-5, the record will be "0 2 1 0 0 0", and in the right case, "0 1 1 0 0 1". Input The input consists of several datasets each in the following format. > n > t1 f1 > t2 f2 > ... > tn fn > Here, n (1 ≤ n ≤ 100) is an integer and is the number of the dice to be dropped. ti and fi (1 ≤ ti, fi ≤ 6) are two integers separated by a space and represent the numbers on the top and the front faces of the i-th die, when it is released, respectively. The end of the input is indicated by a line containing a single zero. Output For each dataset, output six integers separated by a space. The integers represent the numbers of faces with 1 through 6 correspondingly, visible from above. There may not be any other characters in the output. Sample Input 4 6 4 6 4 6 4 6 4 2 5 3 5 3 8 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 6 4 6 1 5 2 3 5 3 2 4 4 2 0 Output for the Sample Input 0 1 1 0 0 1 1 0 0 0 1 0 1 2 2 1 0 0 2 3 0 0 0 0 Example Input 4 6 4 6 4 6 4 6 4 2 5 3 5 3 8 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 6 4 6 1 5 2 3 5 3 2 4 4 2 0 Output 0 1 1 0 0 1 1 0 0 0 1 0 1 2 2 1 0 0 2 3 0 0 0 0
instruction
0
44,600
19
89,200
"Correct Solution: ``` right_dic = {(1, 3):5, (1, 5):4, (1, 4):2, (1, 2):3, (2, 1):4, (2, 4):6, (2, 6):3, (2, 3):1, (3, 1):2, (3, 2):6, (3, 6):5, (3, 5):1, (4, 1):5, (4, 5):6, (4, 6):2, (4, 2):1, (5, 1):3, (5, 3):6, (5, 6):4, (5, 4):1, (6, 2):4, (6, 4):5, (6, 5):3, (6, 3):2} class Dice: def __init__(self, top, front): self.top = top self.front = front self.right = right_dic[(top, front)] self.under = 7 - self.top self.back= 7 - self.front self.left = 7 - self.right def spin_right(self): self.top, self.right, self.under, self.left = self.left, self.top, self.right, self.under def spin_left(self): self.top, self.right, self.under, self.left = self.right, self.under, self.left, self.top def spin_front(self): self.top, self.front, self.under, self.back = self.back, self.top, self.front, self.under def spin_back(self): self.top, self.front, self.under, self.back = self.front, self.under, self.back, self.top while True: n = int(input()) if n == 0: break mp = [[0] * (n * 2 + 2) for _ in range(n * 2 + 2)] show = [[0] * (n * 2 + 2) for _ in range(n * 2 + 2)] counter = [0] * 7 STOP, FRONT, RIGHT, BACK, LEFT = 0, 1, 2, 3, 4 for _ in range(n): x, y = n + 1, n + 1 top, front = map(int, input().split()) dice = Dice(top, front) while True: rec = 3 direct = STOP if mp[y + 1][x] < mp[y][x] and dice.front > rec: rec = dice.front direct = FRONT if mp[y][x + 1] < mp[y][x] and dice.right > rec: rec = dice.right direct = RIGHT if mp[y - 1][x] < mp[y][x] and dice.back > rec: rec = dice.back direct = BACK if mp[y][x - 1] < mp[y][x] and dice.left > rec: rec = dice.left direct = LEFT if direct == STOP: mp[y][x] += 1 counter[show[y][x]] -= 1 counter[dice.top] += 1 show[y][x] = dice.top break elif direct == FRONT: dice.spin_front() y += 1 elif direct == RIGHT: dice.spin_right() x += 1 elif direct == BACK: dice.spin_back() y -= 1 elif direct == LEFT: dice.spin_left() x -= 1 print(*counter[1:]) ```
output
1
44,600
19
89,201
Provide a correct Python 3 solution for this coding contest problem. Professor Random, known for his research on randomized algorithms, is now conducting an experiment on biased dice. His experiment consists of dropping a number of dice onto a plane, one after another from a fixed position above the plane. The dice fall onto the plane or dice already there, without rotating, and may roll and fall according to their property. Then he observes and records the status of the stack formed on the plane, specifically, how many times each number appears on the faces visible from above. All the dice have the same size and their face numbering is identical, which we show in Figure C-1. <image> Figure C-1: Numbering of a die The dice have very special properties, as in the following. (1) Ordinary dice can roll in four directions, but the dice used in this experiment never roll in the directions of faces 1, 2 and 3; they can only roll in the directions of faces 4, 5 and 6. In the situation shown in Figure C-2, our die can only roll to one of two directions. <image> Figure C-2: An ordinary die and a biased die (2) The die can only roll when it will fall down after rolling, as shown in Figure C-3. When multiple possibilities exist, the die rolls towards the face with the largest number among those directions it can roll to. <image> Figure C-3: A die can roll only when it can fall (3) When a die rolls, it rolls exactly 90 degrees, and then falls straight down until its bottom face touches another die or the plane, as in the case [B] or [C] of Figure C-4. (4) After rolling and falling, the die repeatedly does so according to the rules (1) to (3) above. <image> Figure C-4: Example stacking of biased dice For example, when we drop four dice all in the same orientation, 6 at the top and 4 at the front, then a stack will be formed as shown in Figure C-4. <image> Figure C-5: Example records After forming the stack, we count the numbers of faces with 1 through 6 visible from above and record them. For example, in the left case of Figure C-5, the record will be "0 2 1 0 0 0", and in the right case, "0 1 1 0 0 1". Input The input consists of several datasets each in the following format. > n > t1 f1 > t2 f2 > ... > tn fn > Here, n (1 ≤ n ≤ 100) is an integer and is the number of the dice to be dropped. ti and fi (1 ≤ ti, fi ≤ 6) are two integers separated by a space and represent the numbers on the top and the front faces of the i-th die, when it is released, respectively. The end of the input is indicated by a line containing a single zero. Output For each dataset, output six integers separated by a space. The integers represent the numbers of faces with 1 through 6 correspondingly, visible from above. There may not be any other characters in the output. Sample Input 4 6 4 6 4 6 4 6 4 2 5 3 5 3 8 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 6 4 6 1 5 2 3 5 3 2 4 4 2 0 Output for the Sample Input 0 1 1 0 0 1 1 0 0 0 1 0 1 2 2 1 0 0 2 3 0 0 0 0 Example Input 4 6 4 6 4 6 4 6 4 2 5 3 5 3 8 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 6 4 6 1 5 2 3 5 3 2 4 4 2 0 Output 0 1 1 0 0 1 1 0 0 0 1 0 1 2 2 1 0 0 2 3 0 0 0 0
instruction
0
44,601
19
89,202
"Correct Solution: ``` class Dice: def __init__(self, top=1, front=2, left=4, right=3, back=5, bottom=6): self.d = {"TOP": top, "FRONT": front, "LEFT": left, "RIGHT": right, "BACK": back, "BOTTOM": bottom} def roll_x(self): self._roll("TOP", "FRONT", "BOTTOM", "BACK") def roll_y(self): self._roll("FRONT", "LEFT", "BACK", "RIGHT") def roll_z(self): self._roll("TOP", "LEFT", "BOTTOM", "RIGHT") def _roll(self, a, b, c, d): self.d[a], self.d[b], self.d[c], self.d[d] = self.d[b], self.d[c], self.d[d], self.d[a] def all_rolls(self): import copy ret = [] for i in range(6): if i % 2: self.roll_x() else: self.roll_y() for _ in range(4): self.roll_z() ret.append(copy.deepcopy(self)) return ret import copy from collections import defaultdict while True: n = int(input()) if n==0: break board = [[0 for i in range(100)] for j in range(100)] height = [[0 for i in range(100)] for j in range(100)] for i in range(n): t, f = list(map(int, input().split())) dice = Dice() for di in dice.all_rolls(): if di.d["TOP"]==t and di.d["FRONT"]==f: break x, y = 50, 50 while True: dxy = [] for s in ["FRONT", "LEFT", "BACK", "RIGHT"]: tt = di.d[s] if tt>=4: dxy.append((tt, s)) dxy.sort(reverse=True) move = False for _, s in dxy: newdice = copy.deepcopy(di) if s=="FRONT": dx = 0 dy = 1 newdice.roll_x() newdice.roll_x() newdice.roll_x() elif s=="LEFT": dx = -1 dy = 0 newdice.roll_z() newdice.roll_z() newdice.roll_z() elif s=="BACK": dx = 0 dy = -1 newdice.roll_x() elif s=="RIGHT": dx = 1 dy = 0 newdice.roll_z() if height[x][y]>height[x+dx][y+dy]: x = x+dx y = y+dy di = newdice move = True break if not move: board[x][y] = di.d["TOP"] height[x][y] += 1 break ans = defaultdict(int) for e in board: for ee in e: ans[ee] += 1 print(*[ans[i] for i in range(1, 7)]) ```
output
1
44,601
19
89,203
Provide a correct Python 3 solution for this coding contest problem. Professor Random, known for his research on randomized algorithms, is now conducting an experiment on biased dice. His experiment consists of dropping a number of dice onto a plane, one after another from a fixed position above the plane. The dice fall onto the plane or dice already there, without rotating, and may roll and fall according to their property. Then he observes and records the status of the stack formed on the plane, specifically, how many times each number appears on the faces visible from above. All the dice have the same size and their face numbering is identical, which we show in Figure C-1. <image> Figure C-1: Numbering of a die The dice have very special properties, as in the following. (1) Ordinary dice can roll in four directions, but the dice used in this experiment never roll in the directions of faces 1, 2 and 3; they can only roll in the directions of faces 4, 5 and 6. In the situation shown in Figure C-2, our die can only roll to one of two directions. <image> Figure C-2: An ordinary die and a biased die (2) The die can only roll when it will fall down after rolling, as shown in Figure C-3. When multiple possibilities exist, the die rolls towards the face with the largest number among those directions it can roll to. <image> Figure C-3: A die can roll only when it can fall (3) When a die rolls, it rolls exactly 90 degrees, and then falls straight down until its bottom face touches another die or the plane, as in the case [B] or [C] of Figure C-4. (4) After rolling and falling, the die repeatedly does so according to the rules (1) to (3) above. <image> Figure C-4: Example stacking of biased dice For example, when we drop four dice all in the same orientation, 6 at the top and 4 at the front, then a stack will be formed as shown in Figure C-4. <image> Figure C-5: Example records After forming the stack, we count the numbers of faces with 1 through 6 visible from above and record them. For example, in the left case of Figure C-5, the record will be "0 2 1 0 0 0", and in the right case, "0 1 1 0 0 1". Input The input consists of several datasets each in the following format. > n > t1 f1 > t2 f2 > ... > tn fn > Here, n (1 ≤ n ≤ 100) is an integer and is the number of the dice to be dropped. ti and fi (1 ≤ ti, fi ≤ 6) are two integers separated by a space and represent the numbers on the top and the front faces of the i-th die, when it is released, respectively. The end of the input is indicated by a line containing a single zero. Output For each dataset, output six integers separated by a space. The integers represent the numbers of faces with 1 through 6 correspondingly, visible from above. There may not be any other characters in the output. Sample Input 4 6 4 6 4 6 4 6 4 2 5 3 5 3 8 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 6 4 6 1 5 2 3 5 3 2 4 4 2 0 Output for the Sample Input 0 1 1 0 0 1 1 0 0 0 1 0 1 2 2 1 0 0 2 3 0 0 0 0 Example Input 4 6 4 6 4 6 4 6 4 2 5 3 5 3 8 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 6 4 6 1 5 2 3 5 3 2 4 4 2 0 Output 0 1 1 0 0 1 1 0 0 0 1 0 1 2 2 1 0 0 2 3 0 0 0 0
instruction
0
44,602
19
89,204
"Correct Solution: ``` #!usr/bin/env python3 from collections import defaultdict,deque from heapq import heappush, heappop import sys import math import bisect import random def LI(): return [int(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS():return [list(x) for x in sys.stdin.readline().split()] def S(): return list(sys.stdin.readline())[:-1] def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] sys.setrecursionlimit(1000000) mod = 1000000007 #2005_c """ n = int(input()) k = list("mcxi") for i in range(n): d = {"m":0,"c":0,"x":0,"i":0} a,b = input().split() a = list(a) b = list(b) a.insert(0,1) b.insert(0,1) for j in range(1,len(a)): if a[j] in k: if a[j-1] in k: d[a[j]] += 1 else: d[a[j]] += int(a[j-1]) for j in range(1,len(b))[::-1]: if b[j] in k: if b[j-1] in k: d[b[j]] += 1 else: d[b[j]] += int(b[j-1]) if d[b[j]] >= 10: l = b[j] while d[l] >= 10: d[l] -= 10 l = k[k.index(l)-1] d[l] += 1 for j in k: if d[j]: if d[j] == 1: print(j,end = "") else: print(str(d[j])+j,end = "") print() """ #2017_c """ while 1: h, w = map(int, input().split()) if h == w == 0: break s = [list(map(int, input().split())) for i in range(h)] ans = 0 for u in range(h): for d in range(u+2,h): for l in range(w): for r in range(l+2,w): m = float("inf") for i in range(u,d+1): m = min(m,s[i][l],s[i][r]) for i in range(l,r+1): m = min(m,s[u][i],s[d][i]) f = 1 su = 0 for i in range(u+1,d): for j in range(l+1,r): su += (m-s[i][j]) if s[i][j] >= m: f = 0 break if not f: break if f: ans = max(ans,su) print(ans) """ #2016_c """ while 1: m,n = map(int, input().split()) if m == n == 0: break ma = 7368791 d = [0]*(ma+1) z = m for i in range(n): while d[z]: z += 1 j = z while j <= ma: d[j] = 1 j += z for j in range(z,ma+1): if not d[j]: print(j) break """ #2018_c """ def factorize(n): if n < 4: return [1,n] i = 2 l = [1] while i**2 <= n: if n%i == 0: l.append(i) if n//i != i: l.append(n//i) i += 1 l.append(n) l.sort() return l while 1: b = int(input()) if b == 0: break f = factorize(2*b) for n in f[::-1]: a = 1-n+(2*b)//n if a >= 1 and a%2 == 0: print(a//2,n) break """ #2010_c """ import sys dp = [100]*1000000 dp_2 = [100]*1000000 dp[0] = 0 dp_2[0] = 0 for i in range(1,181): s = i*(i+1)*(i+2)//6 for j in range(s,1000000): if dp[j-s]+1 < dp[j]: dp[j] = dp[j-s]+1 if s%2: for j in range(s,1000000): if dp_2[j-s]+1 < dp_2[j]: dp_2[j] = dp_2[j-s]+1 while 1: m = int(sys.stdin.readline()) if m == 0: break print(dp[m],dp_2[m]) """ #2015_c """ from collections import deque while 1: n = int(input()) if n == 0: break s = [input() for i in range(n)] d = [s[i].count(".") for i in range(n)] m = max(d) c = [s[i][-1] for i in range(n)] q = deque() for i in range(1,m+1)[::-1]: j = 0 while j < n: for k in range(j,n): if d[k] == i:break else: break j = k op = c[j-1] while j < n and d[j] == i: q.append(j) j += 1 j = k if op == "+": k = 0 while q: x = q.pop() k += int(c[x]) c.pop(x) d.pop(x) n -= 1 else: k = 1 while q: x = q.pop() k *= int(c[x]) c.pop(x) d.pop(x) n -= 1 c[j-1] = k print(c[0]) """ #2013_c """ from collections import defaultdict def parse_expr(s,i): i += 1 if s[i] == "[": q = [] while s[i] != "]": e,i = parse_expr(s,i) q.append(e) return (calc(q),i+1) else: n,i = parse_num(s,i) return (calc([n]),i+1) def parse_num(s,i): m = int(s[i]) i += 1 while f_num[s[i]]: m *= 10 m += int(s[i]) i += 1 return (m,i) def calc(q): if len(q) == 1: return (q[0]+1)//2 q.sort() return sum(q[:len(q)//2+1]) f_num = defaultdict(lambda : 0) for i in range(10): f_num[str(i)] = 1 n = int(input()) for i in range(n): s = input() print(parse_expr(s,0)[0]) """ #2003_C """ while 1: w,h = LI() if w == h == 0: break s = SR(h) dp = [[0]*w for i in range(h)] for y in range(h): for x in range(w): if s[y][x].isdecimal(): dp[y][x] = max(dp[y-1][x],dp[y][x-1])*10+int(s[y][x]) ans = 0 for i in dp: ans = max(ans,max(i)) print(ans) """ #2008_C """def parse_formula(s,i): if s[i] == "-": i += 1 e,i = parse_formula(s,i) return 2-e,i elif s[i] == "(": i += 1 e1,i = parse_formula(s,i) op = s[i] i += 1 e2,i = parse_formula(s,i) i += 1 return calc(op,e1,e2),i else: return int(s[i]),i+1 def calc(op,a,b): if op == "*": return min(a,b) else: return max(a,b) while 1: s = S() if s[0] == ".": break t = [] f = defaultdict(int) for p in range(3): f["P"] = p for q in range(3): f["Q"] = q for r in range(3): f["R"] = r t.append([f[s[i]] if s[i] in "PQR" else s[i] for i in range(len(s))]) ans = 0 for s in t: if parse_formula(s,0)[0] == 2: ans += 1 print(ans) """ #2011_C """ d = [(1,0),(-1,0),(0,1),(0,-1)] def dfs(dep,s): global ans if dep == 5: b = bfs(s) m = 0 for i in b: m += sum(i) ans = max(ans, m) else: if dep < 4: for i in range(6): b = bfs(s) dfs(dep+1,[[i+1 if b[y][x] else s[y][x] for x in range(w)] for y in range(h)]) else: b = bfs(s) dfs(dep+1,[[c if b[y][x] else s[y][x] for x in range(w)] for y in range(h)]) def bfs(s): b = [[0]*w for i in range(h)] b[0][0] = 1 q = deque([(0,0)]) while q: y,x = q.popleft() for dy,dx in d: y_ = y+dy x_ = x+dx if 0 <= y_ < h and 0 <= x_ < w: if not b[y_][x_] and s[y_][x_] == s[0][0]: b[y_][x_] = 1 q.append((y_,x_)) return b while 1: h,w,c = LI() if h == 0: break s = LIR(h) ans = 0 dfs(0,s) print(ans) """ #2012_C def make_dice(t,f): if t == 1: if f == 2: return [t,f,3,7-f,4,7-t] if f == 3: return [t,f,5,7-f,2,7-t] if f == 5: return [t,f,4,7-f,3,7-t] if f == 4: return [t,f,2,7-f,5,7-t] if t == 2: if f == 1: return [t,f,4,7-f,3,7-t] if f == 4: return [t,f,6,7-f,1,7-t] if f == 6: return [t,f,3,7-f,4,7-t] if f == 3: return [t,f,1,7-f,6,7-t] if t == 3: if f == 1: return [t,f,2,7-f,5,7-t] if f == 2: return [t,f,6,7-f,1,7-t] if f == 6: return [t,f,5,7-f,2,7-t] if f == 5: return [t,f,1,7-f,6,7-t] if t == 4: if f == 1: return [t,f,5,7-f,2,7-t] if f == 5: return [t,f,6,7-f,1,7-t] if f == 6: return [t,f,2,7-f,5,7-t] if f == 2: return [t,f,1,7-f,6,7-t] if t == 5: if f == 1: return [t,f,3,7-f,4,7-t] if f == 3: return [t,f,6,7-f,1,7-t] if f == 6: return [t,f,4,7-f,3,7-t] if f == 4: return [t,f,1,7-f,6,7-t] if t == 6: if f == 2: return [t,f,4,7-f,3,7-t] if f == 4: return [t,f,5,7-f,2,7-t] if f == 5: return [t,f,3,7-f,4,7-t] if f == 3: return [t,f,2,7-f,5,7-t] dy = [0,-1,0,1,0,0] dx = [0,0,1,0,-1,0] def Set(s,dice): z,y,x = fall(s,dice,99,99) dir = check(s,z,y,x,dice) while dir: s[z][y][x] = 0 dice = rotate(dice,dir) z,y,x = fall(s,dice,y+dy[dir],x+dx[dir]) dir = check(s,z,y,x,dice) def fall(s,dice,y,x): for z in range(100): if s[z][y][x] == 0: s[z][y][x] = dice[0] return z,y,x def check(s,z,y,x,dice): if z == 0: return 0 for c in (6,5,4): dir = dice.index(c) if s[z][y+dy[dir]][x+dx[dir]] == 0 and s[z-1][y+dy[dir]][x+dx[dir]] == 0 : return dir return 0 def rotate(dice,dir): if dir == 1: return [dice[3],dice[0],dice[2],dice[5],dice[4],dice[1]] if dir == 2: return [dice[4],dice[1],dice[0],dice[3],dice[5],dice[2]] if dir == 3: return [dice[1],dice[5],dice[2],dice[0],dice[4],dice[3]] else: return [dice[2],dice[1],dice[5],dice[3],dice[0],dice[4]] while 1: n = I() if n == 0: break s = [[[0]*200 for i in range(200)] for j in range(100)] for i in range(n): t,f = LI() dice = make_dice(t,f) Set(s,dice) d = {0:0,1:0,2:0,3:0,4:0,5:0,6:0} for y in range(200): for x in range(200): for z in range(100): if s[z][y][x] == 0: break d[s[z-1][y][x]] += 1 for i in range(1,6): print(d[i],end = " ") print(d[6]) ```
output
1
44,602
19
89,205
Provide a correct Python 3 solution for this coding contest problem. Professor Random, known for his research on randomized algorithms, is now conducting an experiment on biased dice. His experiment consists of dropping a number of dice onto a plane, one after another from a fixed position above the plane. The dice fall onto the plane or dice already there, without rotating, and may roll and fall according to their property. Then he observes and records the status of the stack formed on the plane, specifically, how many times each number appears on the faces visible from above. All the dice have the same size and their face numbering is identical, which we show in Figure C-1. <image> Figure C-1: Numbering of a die The dice have very special properties, as in the following. (1) Ordinary dice can roll in four directions, but the dice used in this experiment never roll in the directions of faces 1, 2 and 3; they can only roll in the directions of faces 4, 5 and 6. In the situation shown in Figure C-2, our die can only roll to one of two directions. <image> Figure C-2: An ordinary die and a biased die (2) The die can only roll when it will fall down after rolling, as shown in Figure C-3. When multiple possibilities exist, the die rolls towards the face with the largest number among those directions it can roll to. <image> Figure C-3: A die can roll only when it can fall (3) When a die rolls, it rolls exactly 90 degrees, and then falls straight down until its bottom face touches another die or the plane, as in the case [B] or [C] of Figure C-4. (4) After rolling and falling, the die repeatedly does so according to the rules (1) to (3) above. <image> Figure C-4: Example stacking of biased dice For example, when we drop four dice all in the same orientation, 6 at the top and 4 at the front, then a stack will be formed as shown in Figure C-4. <image> Figure C-5: Example records After forming the stack, we count the numbers of faces with 1 through 6 visible from above and record them. For example, in the left case of Figure C-5, the record will be "0 2 1 0 0 0", and in the right case, "0 1 1 0 0 1". Input The input consists of several datasets each in the following format. > n > t1 f1 > t2 f2 > ... > tn fn > Here, n (1 ≤ n ≤ 100) is an integer and is the number of the dice to be dropped. ti and fi (1 ≤ ti, fi ≤ 6) are two integers separated by a space and represent the numbers on the top and the front faces of the i-th die, when it is released, respectively. The end of the input is indicated by a line containing a single zero. Output For each dataset, output six integers separated by a space. The integers represent the numbers of faces with 1 through 6 correspondingly, visible from above. There may not be any other characters in the output. Sample Input 4 6 4 6 4 6 4 6 4 2 5 3 5 3 8 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 6 4 6 1 5 2 3 5 3 2 4 4 2 0 Output for the Sample Input 0 1 1 0 0 1 1 0 0 0 1 0 1 2 2 1 0 0 2 3 0 0 0 0 Example Input 4 6 4 6 4 6 4 6 4 2 5 3 5 3 8 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 6 4 6 1 5 2 3 5 3 2 4 4 2 0 Output 0 1 1 0 0 1 1 0 0 0 1 0 1 2 2 1 0 0 2 3 0 0 0 0
instruction
0
44,603
19
89,206
"Correct Solution: ``` def get_num(top): # 転がす番号の候補を決める if top == 1: return [5, 4] elif top == 2: return [6, 4] elif top == 3: return [6, 5] elif top == 4: return [6, 5] elif top == 5: return [6, 4] elif top == 6: return [5, 4] def get_dir(num, front, top): # 転がる向きを決める if num == front: return ["F", num] elif num == 7 - front: return ["B", num] # print(num, front) if num == 4: if (front == 1 and top == 5) or (front == 5 and top == 6) or (front == 6 and top == 2) or (front == 2 and top == 1): return ["L", num] elif (front == 5 and top == 1) or (front == 6 and top == 5) or (front == 2 and top == 6) or (front == 1 and top == 2): return ["R", num] if num == 5: if (front == 1 and top == 3) or (front == 3 and top == 6) or (front == 6 and top == 4) or (front == 4 and top == 1): return ["L", num] elif (front == 3 and top == 1) or (front == 6 and top == 3) or (front == 4 and top == 6) or (front == 1 and top == 4): return ["R", num] if num == 6: if (front == 2 and top == 4) or (front == 4 and top == 5) or (front == 5 and top == 3) or (front == 3 and top == 2): return ["L", num] elif (front == 4 and top == 2) or (front == 5 and top == 4) or (front == 3 and top == 5) or (front == 2 and top == 3): return ["R", num] def can_roll(dir, nowi, nowj, maps): I = 0 J = 0 if dir == "F": I += 1 if dir == "B": I -= 1 if dir == "R": J += 1 if dir == "L": J -= 1 if maps[nowi][nowj][0] >= maps[nowi + I][nowj + J][0] + 1: return True return False def roll(maps, nowi, nowj, top, front): roll_num = get_num(top) # print(roll_num, front, top) dir1_list = get_dir(roll_num[0], front, top) dir2_list = get_dir(roll_num[1], front, top) # print(dir1_list, dir2_list) dir1 = dir1_list[0] dir2 = dir2_list[0] # print(dir1, dir2) if can_roll(dir1, nowi, nowj, maps): # print(nowi, nowj, dir1, 7 - dir1_list[1]) I = 0 J = 0 if dir1 == "F": I += 1 front = top if dir1 == "B": I -= 1 front = 7 - top if dir1 == "R": J += 1 if dir1 == "L": J -= 1 maps = roll(maps, nowi + I, nowj + J, 7 - dir1_list[1], front) elif can_roll(dir2, nowi, nowj, maps): # print(nowi, nowj, dir2, 7 - dir2_list[1]) I = 0 J = 0 if dir2 == "F": I += 1 front = top if dir2 == "B": I -= 1 front = 7 - top if dir2 == "R": J += 1 if dir2 == "L": J -= 1 maps = roll(maps, nowi + I, nowj + J, 7 - dir2_list[1], front) else: maps[nowi][nowj][0] += 1 maps[nowi][nowj][1] = top return maps while True: n = int(input()) if not n: break maps = [[[0, 0] for _ in range(201)] for _ in range(201)] nowi = 100 nowj = 100 for i in range(n): t, f = map(int, input().split()) maps = roll(maps, nowi, nowj, t, f) cnt = [0 for _ in range(6)] for i in range(len(maps)): for j in range(len(maps[i])): if maps[i][j][1]: cnt[maps[i][j][1] - 1] += 1 for i in range(len(cnt)): cnt[i] = str(cnt[i]) # print(maps[100]) print(" ".join(cnt)) ```
output
1
44,603
19
89,207
Provide a correct Python 3 solution for this coding contest problem. Professor Random, known for his research on randomized algorithms, is now conducting an experiment on biased dice. His experiment consists of dropping a number of dice onto a plane, one after another from a fixed position above the plane. The dice fall onto the plane or dice already there, without rotating, and may roll and fall according to their property. Then he observes and records the status of the stack formed on the plane, specifically, how many times each number appears on the faces visible from above. All the dice have the same size and their face numbering is identical, which we show in Figure C-1. <image> Figure C-1: Numbering of a die The dice have very special properties, as in the following. (1) Ordinary dice can roll in four directions, but the dice used in this experiment never roll in the directions of faces 1, 2 and 3; they can only roll in the directions of faces 4, 5 and 6. In the situation shown in Figure C-2, our die can only roll to one of two directions. <image> Figure C-2: An ordinary die and a biased die (2) The die can only roll when it will fall down after rolling, as shown in Figure C-3. When multiple possibilities exist, the die rolls towards the face with the largest number among those directions it can roll to. <image> Figure C-3: A die can roll only when it can fall (3) When a die rolls, it rolls exactly 90 degrees, and then falls straight down until its bottom face touches another die or the plane, as in the case [B] or [C] of Figure C-4. (4) After rolling and falling, the die repeatedly does so according to the rules (1) to (3) above. <image> Figure C-4: Example stacking of biased dice For example, when we drop four dice all in the same orientation, 6 at the top and 4 at the front, then a stack will be formed as shown in Figure C-4. <image> Figure C-5: Example records After forming the stack, we count the numbers of faces with 1 through 6 visible from above and record them. For example, in the left case of Figure C-5, the record will be "0 2 1 0 0 0", and in the right case, "0 1 1 0 0 1". Input The input consists of several datasets each in the following format. > n > t1 f1 > t2 f2 > ... > tn fn > Here, n (1 ≤ n ≤ 100) is an integer and is the number of the dice to be dropped. ti and fi (1 ≤ ti, fi ≤ 6) are two integers separated by a space and represent the numbers on the top and the front faces of the i-th die, when it is released, respectively. The end of the input is indicated by a line containing a single zero. Output For each dataset, output six integers separated by a space. The integers represent the numbers of faces with 1 through 6 correspondingly, visible from above. There may not be any other characters in the output. Sample Input 4 6 4 6 4 6 4 6 4 2 5 3 5 3 8 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 6 4 6 1 5 2 3 5 3 2 4 4 2 0 Output for the Sample Input 0 1 1 0 0 1 1 0 0 0 1 0 1 2 2 1 0 0 2 3 0 0 0 0 Example Input 4 6 4 6 4 6 4 6 4 2 5 3 5 3 8 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 6 4 6 1 5 2 3 5 3 2 4 4 2 0 Output 0 1 1 0 0 1 1 0 0 0 1 0 1 2 2 1 0 0 2 3 0 0 0 0
instruction
0
44,604
19
89,208
"Correct Solution: ``` class RollDir: def __init__(self, d, w): self.d = d self.w = w def __str__(self): return "Roll dir: {}, weight: {}".format(self.d, self.w) @classmethod def create(cls, d, w): if w == 6 or w == 5 or w == 4: return cls(d, w) else: return None class Dice: def __init__(self, t, f): self.top = t self.bot = 7 - t if t == 1: arr = [2, 3, 5, 4] elif t == 6: arr = [5, 3, 2, 4] elif t == 2: arr = [3, 1, 4, 6] elif t == 5: arr = [3, 6, 4, 1] elif t == 3: arr = [6, 5, 1, 2] elif t == 4: arr = [1, 5, 6, 2] idx = arr.index(f) self.front = arr[idx] self.right = arr[(idx + 1) % 4] self.back = arr[(idx + 2) % 4] self.left = arr[(idx + 3) % 4] def roll(self, direction): if direction == 'N': temp = self.top self.top = self.front self.front = self.bot self.bot = self.back self.back = temp elif direction == 'E': temp = self.top self.top = self.left self.left = self.bot self.bot = self.right self.right = temp elif direction == 'W': temp = self.top self.top = self.right self.right = self.bot self.bot = self.left self.left = temp elif direction == 'S': temp = self.top self.top = self.back self.back = self.bot self.bot = self.front self.front = temp def getRollDir(self): arr = [] roll = RollDir.create('S', self.front) if roll != None: arr.append(roll) roll = RollDir.create('E', self.right) if roll != None: arr.append(roll) roll = RollDir.create('N', self.back) if roll != None: arr.append(roll) roll = RollDir.create('W', self.left) if roll != None: arr.append(roll) return sorted(arr, key=lambda x: x.w ,reverse=True) def __str__(self): return "Top: {} Front: {} Left: {} Right: {}" \ .format(self.top, self.front, self.left, self.right) class Cell: def __init__(self): self.height = 0 self.val = None class Grid: def __init__(self): self.cells = {} def drop(self, dice, x, y): if (x, y) not in self.cells: self.cells[ (x, y) ] = Cell() cell = self.cells[ (x, y) ] diceRollDirs = dice.getRollDir() gridRollDirs = self.getRollableDir(x, y) didRoll = False for roll in diceRollDirs: if roll.d in gridRollDirs: direction = roll.d dice.roll(direction) rollCoord = self.getRollCoord(x, y, direction) self.drop(dice, rollCoord[0], rollCoord[1]) didRoll = True break if not didRoll: cell.height += 1 cell.val = dice.top def getRollableDir(self, x, y): if (x, y) not in self.cells: self.cells[(x, y)] = Cell() cell = self.cells[(x, y)] arr = [] if cell.height == 0: return [] if (x-1, y) not in self.cells or self.cells[(x-1, y)].height < cell.height: arr.append('N') if (x, y+1) not in self.cells or self.cells[(x, y+1)].height < cell.height: arr.append('E') if (x, y-1) not in self.cells or self.cells[(x, y-1)].height < cell.height: arr.append('W') if (x+1, y) not in self.cells or self.cells[(x+1, y)].height < cell.height: arr.append('S') return arr def getRollCoord(self, x, y, d): if d == 'N': return (x-1, y) elif d == 'E': return (x, y+1) elif d == 'W': return (x, y-1) elif d == 'S': return (x+1, y) def countVals(self): count = [0, 0, 0, 0, 0, 0] for coord in self.cells: cell = self.cells[coord] count[ cell.val - 1 ] += 1 return count if __name__ == '__main__': while True: N = int(input()) if N == 0: break grid = Grid() for _ in range(N): t, f = [ int(x) for x in list(filter(lambda x: x != '', \ input().strip().split(' '))) ] dice = Dice(t, f) grid.drop(dice, 0, 0) print(" ".join(list(map(str, grid.countVals())))) ```
output
1
44,604
19
89,209
Provide a correct Python 3 solution for this coding contest problem. Professor Random, known for his research on randomized algorithms, is now conducting an experiment on biased dice. His experiment consists of dropping a number of dice onto a plane, one after another from a fixed position above the plane. The dice fall onto the plane or dice already there, without rotating, and may roll and fall according to their property. Then he observes and records the status of the stack formed on the plane, specifically, how many times each number appears on the faces visible from above. All the dice have the same size and their face numbering is identical, which we show in Figure C-1. <image> Figure C-1: Numbering of a die The dice have very special properties, as in the following. (1) Ordinary dice can roll in four directions, but the dice used in this experiment never roll in the directions of faces 1, 2 and 3; they can only roll in the directions of faces 4, 5 and 6. In the situation shown in Figure C-2, our die can only roll to one of two directions. <image> Figure C-2: An ordinary die and a biased die (2) The die can only roll when it will fall down after rolling, as shown in Figure C-3. When multiple possibilities exist, the die rolls towards the face with the largest number among those directions it can roll to. <image> Figure C-3: A die can roll only when it can fall (3) When a die rolls, it rolls exactly 90 degrees, and then falls straight down until its bottom face touches another die or the plane, as in the case [B] or [C] of Figure C-4. (4) After rolling and falling, the die repeatedly does so according to the rules (1) to (3) above. <image> Figure C-4: Example stacking of biased dice For example, when we drop four dice all in the same orientation, 6 at the top and 4 at the front, then a stack will be formed as shown in Figure C-4. <image> Figure C-5: Example records After forming the stack, we count the numbers of faces with 1 through 6 visible from above and record them. For example, in the left case of Figure C-5, the record will be "0 2 1 0 0 0", and in the right case, "0 1 1 0 0 1". Input The input consists of several datasets each in the following format. > n > t1 f1 > t2 f2 > ... > tn fn > Here, n (1 ≤ n ≤ 100) is an integer and is the number of the dice to be dropped. ti and fi (1 ≤ ti, fi ≤ 6) are two integers separated by a space and represent the numbers on the top and the front faces of the i-th die, when it is released, respectively. The end of the input is indicated by a line containing a single zero. Output For each dataset, output six integers separated by a space. The integers represent the numbers of faces with 1 through 6 correspondingly, visible from above. There may not be any other characters in the output. Sample Input 4 6 4 6 4 6 4 6 4 2 5 3 5 3 8 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 6 4 6 1 5 2 3 5 3 2 4 4 2 0 Output for the Sample Input 0 1 1 0 0 1 1 0 0 0 1 0 1 2 2 1 0 0 2 3 0 0 0 0 Example Input 4 6 4 6 4 6 4 6 4 2 5 3 5 3 8 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 6 4 6 1 5 2 3 5 3 2 4 4 2 0 Output 0 1 1 0 0 1 1 0 0 0 1 0 1 2 2 1 0 0 2 3 0 0 0 0
instruction
0
44,605
19
89,210
"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) class Dice(): def __init__(self, top, front): # [top, front, bottom, rear, right, left] self.A = [top, front, 7 - top, 7 - front] for i in range(4): t = (self.A[i-1], self.A[i]) if t == (6, 4): self.A += [5, 2] elif t == (4, 6): self.A += [2, 5] elif t == (6, 5): self.A += [3, 4] elif t == (6, 2): self.A += [4, 3] elif t == (5, 4): self.A += [1, 6] elif t == (5, 3): self.A += [6, 1] else: continue break def top(self): return self.A[0] def front(self): return self.A[1] def bottom(self): return self.A[2] def rear(self): return self.A[3] def right(self): return self.A[4] def left(self): return self.A[5] # di: 0 == front, 1 == rear, 2 == right, 3 == left def rotate(self, di): a = self.A if di == 0: self.A = [a[3], a[0], a[1], a[2], a[4], a[5]] elif di == 1: self.A = [a[1], a[2], a[3], a[0], a[4], a[5]] elif di == 2: self.A = [a[5], a[1], a[4], a[3], a[0], a[2]] elif di == 3: self.A = [a[4], a[1], a[5], a[3], a[2], a[0]] def main(): rr = [] while True: n = I() if n == 0: break a = [LI() for _ in range(n)] rb = collections.defaultdict(int) b = collections.defaultdict(int) for t,f in a: ki = 0 kj = 0 d = Dice(t,f) f = True while f: f = False bt = b[(ki,kj)] for i in range(6,3,-1): if d.front() == i and bt > b[(ki-1,kj)]: f = True d.rotate(0) ki -= 1 break if d.rear() == i and bt > b[(ki+1,kj)]: f = True d.rotate(1) ki += 1 break if d.right() == i and bt > b[(ki,kj+1)]: f = True d.rotate(2) kj += 1 break if d.left() == i and bt > b[(ki,kj-1)]: f = True d.rotate(3) kj -= 1 break b[(ki,kj)] += 1 rb[(ki,kj)] = d.top() r = [0] * 6 for v in rb.values(): if v == 0: continue r[v-1] += 1 rr.append(' '.join(map(str,r))) return '\n'.join(map(str, rr)) print(main()) ```
output
1
44,605
19
89,211
Provide a correct Python 3 solution for this coding contest problem. Professor Random, known for his research on randomized algorithms, is now conducting an experiment on biased dice. His experiment consists of dropping a number of dice onto a plane, one after another from a fixed position above the plane. The dice fall onto the plane or dice already there, without rotating, and may roll and fall according to their property. Then he observes and records the status of the stack formed on the plane, specifically, how many times each number appears on the faces visible from above. All the dice have the same size and their face numbering is identical, which we show in Figure C-1. <image> Figure C-1: Numbering of a die The dice have very special properties, as in the following. (1) Ordinary dice can roll in four directions, but the dice used in this experiment never roll in the directions of faces 1, 2 and 3; they can only roll in the directions of faces 4, 5 and 6. In the situation shown in Figure C-2, our die can only roll to one of two directions. <image> Figure C-2: An ordinary die and a biased die (2) The die can only roll when it will fall down after rolling, as shown in Figure C-3. When multiple possibilities exist, the die rolls towards the face with the largest number among those directions it can roll to. <image> Figure C-3: A die can roll only when it can fall (3) When a die rolls, it rolls exactly 90 degrees, and then falls straight down until its bottom face touches another die or the plane, as in the case [B] or [C] of Figure C-4. (4) After rolling and falling, the die repeatedly does so according to the rules (1) to (3) above. <image> Figure C-4: Example stacking of biased dice For example, when we drop four dice all in the same orientation, 6 at the top and 4 at the front, then a stack will be formed as shown in Figure C-4. <image> Figure C-5: Example records After forming the stack, we count the numbers of faces with 1 through 6 visible from above and record them. For example, in the left case of Figure C-5, the record will be "0 2 1 0 0 0", and in the right case, "0 1 1 0 0 1". Input The input consists of several datasets each in the following format. > n > t1 f1 > t2 f2 > ... > tn fn > Here, n (1 ≤ n ≤ 100) is an integer and is the number of the dice to be dropped. ti and fi (1 ≤ ti, fi ≤ 6) are two integers separated by a space and represent the numbers on the top and the front faces of the i-th die, when it is released, respectively. The end of the input is indicated by a line containing a single zero. Output For each dataset, output six integers separated by a space. The integers represent the numbers of faces with 1 through 6 correspondingly, visible from above. There may not be any other characters in the output. Sample Input 4 6 4 6 4 6 4 6 4 2 5 3 5 3 8 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 6 4 6 1 5 2 3 5 3 2 4 4 2 0 Output for the Sample Input 0 1 1 0 0 1 1 0 0 0 1 0 1 2 2 1 0 0 2 3 0 0 0 0 Example Input 4 6 4 6 4 6 4 6 4 2 5 3 5 3 8 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 6 4 6 1 5 2 3 5 3 2 4 4 2 0 Output 0 1 1 0 0 1 1 0 0 0 1 0 1 2 2 1 0 0 2 3 0 0 0 0
instruction
0
44,606
19
89,212
"Correct Solution: ``` #! cat input | python3 main.py def debug(): for X in field[size//2:] + field[:size//2]: print(X[size//2:], X[:size//2]) dice_data = [[], [4, 2, 3, 5], [4, 6, 3, 1], [6, 5, 1, 2], [1, 5, 6, 2], [4, 1, 3, 6], [4, 5, 3, 2], ] def dice(t, f): i = dice_data[t].index(f) return [dice_data[t][x%4] for x in range(i, i + 4)] size = 6 move = [[-1, 0], [0, 1], [1, 0], [0, -1]] def drop(t, f, nowl, nowr): target = list(map(lambda x: x > 3, dice(t, f))) now = [nowl, nowr] now_field = field[now[0]][now[1]] for i, tg in enumerate(target): if tg: nb_field = field[now[0] + move[i][0]][now[1] + move[i][1]] if nb_field[1] >= now_field[1]: target[i] = False for i, v in sorted(enumerate(dice(t, f)), key=lambda x: x[1], reverse=True): if target[i]: if i == 0: f = t elif i == 2: f = 7 - t t = 7 - v drop(t, f, now[0] + move[i][0], now[1] + move[i][1]) break else: change = field[now[0]][now[1]] change[0] = t change[1] += 1 while True: n = int(input()) if not n: break field = [[[0, 0] for i in range(size)] for j in range(size)] tfs = [list(map(int, input().split())) for x in range(n)] for t, f in tfs: drop(t, f, 0, 0) cnt = [0 for x in range(7)] for row in field: for cell in row: cnt[cell[0]] += 1 print(*cnt[1:]) ```
output
1
44,606
19
89,213
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Professor Random, known for his research on randomized algorithms, is now conducting an experiment on biased dice. His experiment consists of dropping a number of dice onto a plane, one after another from a fixed position above the plane. The dice fall onto the plane or dice already there, without rotating, and may roll and fall according to their property. Then he observes and records the status of the stack formed on the plane, specifically, how many times each number appears on the faces visible from above. All the dice have the same size and their face numbering is identical, which we show in Figure C-1. <image> Figure C-1: Numbering of a die The dice have very special properties, as in the following. (1) Ordinary dice can roll in four directions, but the dice used in this experiment never roll in the directions of faces 1, 2 and 3; they can only roll in the directions of faces 4, 5 and 6. In the situation shown in Figure C-2, our die can only roll to one of two directions. <image> Figure C-2: An ordinary die and a biased die (2) The die can only roll when it will fall down after rolling, as shown in Figure C-3. When multiple possibilities exist, the die rolls towards the face with the largest number among those directions it can roll to. <image> Figure C-3: A die can roll only when it can fall (3) When a die rolls, it rolls exactly 90 degrees, and then falls straight down until its bottom face touches another die or the plane, as in the case [B] or [C] of Figure C-4. (4) After rolling and falling, the die repeatedly does so according to the rules (1) to (3) above. <image> Figure C-4: Example stacking of biased dice For example, when we drop four dice all in the same orientation, 6 at the top and 4 at the front, then a stack will be formed as shown in Figure C-4. <image> Figure C-5: Example records After forming the stack, we count the numbers of faces with 1 through 6 visible from above and record them. For example, in the left case of Figure C-5, the record will be "0 2 1 0 0 0", and in the right case, "0 1 1 0 0 1". Input The input consists of several datasets each in the following format. > n > t1 f1 > t2 f2 > ... > tn fn > Here, n (1 ≤ n ≤ 100) is an integer and is the number of the dice to be dropped. ti and fi (1 ≤ ti, fi ≤ 6) are two integers separated by a space and represent the numbers on the top and the front faces of the i-th die, when it is released, respectively. The end of the input is indicated by a line containing a single zero. Output For each dataset, output six integers separated by a space. The integers represent the numbers of faces with 1 through 6 correspondingly, visible from above. There may not be any other characters in the output. Sample Input 4 6 4 6 4 6 4 6 4 2 5 3 5 3 8 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 6 4 6 1 5 2 3 5 3 2 4 4 2 0 Output for the Sample Input 0 1 1 0 0 1 1 0 0 0 1 0 1 2 2 1 0 0 2 3 0 0 0 0 Example Input 4 6 4 6 4 6 4 6 4 2 5 3 5 3 8 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 6 4 6 1 5 2 3 5 3 2 4 4 2 0 Output 0 1 1 0 0 1 1 0 0 0 1 0 1 2 2 1 0 0 2 3 0 0 0 0 Submitted Solution: ``` false=False true=True dices={} me=[0,0,0,0,0,0] def getDice(x,y,z): return dices["{},{},{}".format(x,y,z)] def setDice(x,y,z,top,ground=False): dices["{},{},{}".format(x,y,z)]=top me[top]+=1 if not ground: me[getDice(x,y,z-1)]-=1 while True: n=int(input()) if n==0: break ######### Z=0 for i in range(n): top,fwd=map(int,input().split()) x=0,y=0,z=Z+1 while True: if z==0 : setDice(x,y,z,top,True) break never=True def canContinue(smx,smy,lgx,lgy): small=getDice(x+smx,y+smy,z-1) large=getDice(x+lgx,y+lgy,z-1) if large is not None: x+=lgx y-=lgy z-=1 never=False return True elif small is not None: x+=smx y+=smy z-=1 return True never=False else: return False if top==1: if fwd==2: if canContinue(-1,0,0,-1): continue elif fwd==3: if canContinue(0,-1,1,0): continue elif fwd==4: if canContinue(0,1,-1,0): continue elif fwd==5: if canContinue(1,0,0,1): continue elif top==2: if fwd==1: if canContinue(1,0,0,-1): continue elif fwd==3: if canContinue(0,-1,-1,0): continue elif fwd==4: if canContinue(0,1,1,0): continue elif fwd==6: if canContinue(-1,0,0,1): continue elif top==3: if fwd==1: if canContinue(-1,0,0,-1): continue elif fwd==2: if canContinue(0,-1,1,0): continue elif fwd==5: if canContinue(0,1,-1,0): continue elif fwd==6: if canContinue(1,0,0,1): continue elif top==4: if fwd==1: if canContinue(1,0,0,-1): continue elif fwd==2: if canContinue(0,-1,-1,0): continue elif fwd==5: if canContinue(0,1,1,0): continue elif fwd==6: if canContinue(-1,0,0,1): continue elif top==5: if fwd==1: if canContinue(-1,0,0,-1): continue elif fwd==3: if canContinue(0,-1,1,0): continue elif fwd==4: if canContinue(0,1,-1,0): continue elif fwd==6: if canContinue(1,0,0,1): continue elif top==6: if fwd==2: if canContinue(1,0,0,-1): continue elif fwd==3: if canContinue(0,-1,-1,0): continue elif fwd==4: if canContinue(0,1,1,0): continue elif fwd==5: if canContinue(-1,0,0,1): continue setDice(x,y,z,top) if never: Z+=1 break print(" ".join(me)) ```
instruction
0
44,607
19
89,214
No
output
1
44,607
19
89,215
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Furlo and Rublo play a game. The table has n piles of coins lying on it, the i-th pile has ai coins. Furlo and Rublo move in turns, Furlo moves first. In one move you are allowed to: * choose some pile, let's denote the current number of coins in it as x; * choose some integer y (0 ≤ y < x; x1 / 4 ≤ y ≤ x1 / 2) and decrease the number of coins in this pile to y. In other words, after the described move the pile will have y coins left. The player who can't make a move, loses. Your task is to find out, who wins in the given game if both Furlo and Rublo play optimally well. Input The first line contains integer n (1 ≤ n ≤ 77777) — the number of piles. The next line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 777777777777) — the sizes of piles. The numbers are separated by single spaces. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. Output If both players play optimally well and Furlo wins, print "Furlo", otherwise print "Rublo". Print the answers without the quotes. Examples Input 1 1 Output Rublo Input 2 1 2 Output Rublo Input 10 1 2 3 4 5 6 7 8 9 10 Output Furlo Submitted Solution: ``` from random import random print("Rublo") if random() > .5 else print("Furlo") ```
instruction
0
44,860
19
89,720
No
output
1
44,860
19
89,721
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Furlo and Rublo play a game. The table has n piles of coins lying on it, the i-th pile has ai coins. Furlo and Rublo move in turns, Furlo moves first. In one move you are allowed to: * choose some pile, let's denote the current number of coins in it as x; * choose some integer y (0 ≤ y < x; x1 / 4 ≤ y ≤ x1 / 2) and decrease the number of coins in this pile to y. In other words, after the described move the pile will have y coins left. The player who can't make a move, loses. Your task is to find out, who wins in the given game if both Furlo and Rublo play optimally well. Input The first line contains integer n (1 ≤ n ≤ 77777) — the number of piles. The next line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 777777777777) — the sizes of piles. The numbers are separated by single spaces. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. Output If both players play optimally well and Furlo wins, print "Furlo", otherwise print "Rublo". Print the answers without the quotes. Examples Input 1 1 Output Rublo Input 2 1 2 Output Rublo Input 10 1 2 3 4 5 6 7 8 9 10 Output Furlo Submitted Solution: ``` import math input() i = [math.floor(math.log(int(x), 4)) for x in input().split()] s = 0 for item in i: s ^= item print("Rublo") if s == 0 else print("Furlo") ```
instruction
0
44,861
19
89,722
No
output
1
44,861
19
89,723
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Furlo and Rublo play a game. The table has n piles of coins lying on it, the i-th pile has ai coins. Furlo and Rublo move in turns, Furlo moves first. In one move you are allowed to: * choose some pile, let's denote the current number of coins in it as x; * choose some integer y (0 ≤ y < x; x1 / 4 ≤ y ≤ x1 / 2) and decrease the number of coins in this pile to y. In other words, after the described move the pile will have y coins left. The player who can't make a move, loses. Your task is to find out, who wins in the given game if both Furlo and Rublo play optimally well. Input The first line contains integer n (1 ≤ n ≤ 77777) — the number of piles. The next line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 777777777777) — the sizes of piles. The numbers are separated by single spaces. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. Output If both players play optimally well and Furlo wins, print "Furlo", otherwise print "Rublo". Print the answers without the quotes. Examples Input 1 1 Output Rublo Input 2 1 2 Output Rublo Input 10 1 2 3 4 5 6 7 8 9 10 Output Furlo Submitted Solution: ``` from __future__ import division, print_function import os import sys from io import BytesIO, IOBase def main(): class Node: def __init__(self, id): self.id = id self.front = None self.back = None class LinkedList: def __init__(self): self.leftLimit = Node(-1) self.rightLimit = Node(0) self.leftLimit.back = self.rightLimit self.rightLimit.front = self.leftLimit self.outerLeft = self.leftLimit self.outerRight = self.rightLimit s = input() sequence = LinkedList() for i in range(len(s)): newNode = Node(i+1) newNode.back = sequence.rightLimit newNode.front = sequence.leftLimit sequence.rightLimit.front = newNode sequence.leftLimit.back = newNode if s[i] == 'l': sequence.rightLimit = newNode else: sequence.leftLimit = newNode current = sequence.outerLeft.back for node in range(len(s)): print(current.id) current = current.back BUFFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") input = lambda: sys.stdin.readline().rstrip("\r\n") def print(*args, **kwargs): sep = kwargs.pop("sep", " ") file = kwargs.pop("file", sys.stdout) atStart = True for x in args: if not atStart: file.write(sep) file.write(str(x)) atStart = False file.write(kwargs.pop("end", "\n")) if kwargs.pop("flush", False): file.flush() sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) main() ```
instruction
0
44,862
19
89,724
No
output
1
44,862
19
89,725
Provide tags and a correct Python 3 solution for this coding contest problem. Ilya is working for the company that constructs robots. Ilya writes programs for entertainment robots, and his current project is "Bob", a new-generation game robot. Ilya's boss wants to know his progress so far. Especially he is interested if Bob is better at playing different games than the previous model, "Alice". So now Ilya wants to compare his robots' performance in a simple game called "1-2-3". This game is similar to the "Rock-Paper-Scissors" game: both robots secretly choose a number from the set {1, 2, 3} and say it at the same moment. If both robots choose the same number, then it's a draw and noone gets any points. But if chosen numbers are different, then one of the robots gets a point: 3 beats 2, 2 beats 1 and 1 beats 3. Both robots' programs make them choose their numbers in such a way that their choice in (i + 1)-th game depends only on the numbers chosen by them in i-th game. Ilya knows that the robots will play k games, Alice will choose number a in the first game, and Bob will choose b in the first game. He also knows both robots' programs and can tell what each robot will choose depending on their choices in previous game. Ilya doesn't want to wait until robots play all k games, so he asks you to predict the number of points they will have after the final game. Input The first line contains three numbers k, a, b (1 ≤ k ≤ 1018, 1 ≤ a, b ≤ 3). Then 3 lines follow, i-th of them containing 3 numbers Ai, 1, Ai, 2, Ai, 3, where Ai, j represents Alice's choice in the game if Alice chose i in previous game and Bob chose j (1 ≤ Ai, j ≤ 3). Then 3 lines follow, i-th of them containing 3 numbers Bi, 1, Bi, 2, Bi, 3, where Bi, j represents Bob's choice in the game if Alice chose i in previous game and Bob chose j (1 ≤ Bi, j ≤ 3). Output Print two numbers. First of them has to be equal to the number of points Alice will have, and second of them must be Bob's score after k games. Examples Input 10 2 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 Output 1 9 Input 8 1 1 2 2 1 3 3 1 3 1 3 1 1 1 2 1 1 1 2 3 Output 5 2 Input 5 1 1 1 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 Output 0 0 Note In the second example game goes like this: <image> The fourth and the seventh game are won by Bob, the first game is draw and the rest are won by Alice.
instruction
0
45,099
19
90,198
Tags: graphs, implementation Correct Solution: ``` class Player: __slots__ = ['choices'] def __init__(self, choices): self.choices = choices def choose_next(self, row, col): return self.choices[row - 1][col - 1] def round_score(own, other): if own == other + 1 or (own == 1 and other == 3): return 1 return 0 class State: __slots__ = ['score_a', 'score_b', 'time'] def __init__(self, a, b, time): self.score_a = a self.score_b = b self.time = time def read_player(): choices = [list(map(int, input().split())) for i in range(3)] return Player(choices) def play(rounds, pa, a, pb, b): memo = {} score = [0, 0] cacat = False for i in range(rounds): pair = (a, b) if pair in memo: cycle_len = (i - memo[pair].time) cycles = (rounds - i) // cycle_len score_a = score[0] - memo[pair].score_a score_b = score[1] - memo[pair].score_b score[0] += score_a * cycles score[1] += score_b * cycles rounds -= i + cycles * cycle_len cacat = True break else: memo[pair] = State(score[0], score[1], i) score[0] += Player.round_score(a, b) score[1] += Player.round_score(b, a) a, b = pa.choose_next(a, b), pb.choose_next(a, b) if cacat: for i in range(rounds): score[0] += Player.round_score(a, b) score[1] += Player.round_score(b, a) a, b = pa.choose_next(a, b), pb.choose_next(a, b) return score def main(): rounds, a, b = map(int, input().split()) pa = read_player() pb = read_player() score = play(rounds, pa, a, pb, b) print(score[0], score[1]) main() ```
output
1
45,099
19
90,199
Provide tags and a correct Python 3 solution for this coding contest problem. Ilya is working for the company that constructs robots. Ilya writes programs for entertainment robots, and his current project is "Bob", a new-generation game robot. Ilya's boss wants to know his progress so far. Especially he is interested if Bob is better at playing different games than the previous model, "Alice". So now Ilya wants to compare his robots' performance in a simple game called "1-2-3". This game is similar to the "Rock-Paper-Scissors" game: both robots secretly choose a number from the set {1, 2, 3} and say it at the same moment. If both robots choose the same number, then it's a draw and noone gets any points. But if chosen numbers are different, then one of the robots gets a point: 3 beats 2, 2 beats 1 and 1 beats 3. Both robots' programs make them choose their numbers in such a way that their choice in (i + 1)-th game depends only on the numbers chosen by them in i-th game. Ilya knows that the robots will play k games, Alice will choose number a in the first game, and Bob will choose b in the first game. He also knows both robots' programs and can tell what each robot will choose depending on their choices in previous game. Ilya doesn't want to wait until robots play all k games, so he asks you to predict the number of points they will have after the final game. Input The first line contains three numbers k, a, b (1 ≤ k ≤ 1018, 1 ≤ a, b ≤ 3). Then 3 lines follow, i-th of them containing 3 numbers Ai, 1, Ai, 2, Ai, 3, where Ai, j represents Alice's choice in the game if Alice chose i in previous game and Bob chose j (1 ≤ Ai, j ≤ 3). Then 3 lines follow, i-th of them containing 3 numbers Bi, 1, Bi, 2, Bi, 3, where Bi, j represents Bob's choice in the game if Alice chose i in previous game and Bob chose j (1 ≤ Bi, j ≤ 3). Output Print two numbers. First of them has to be equal to the number of points Alice will have, and second of them must be Bob's score after k games. Examples Input 10 2 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 Output 1 9 Input 8 1 1 2 2 1 3 3 1 3 1 3 1 1 1 2 1 1 1 2 3 Output 5 2 Input 5 1 1 1 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 Output 0 0 Note In the second example game goes like this: <image> The fourth and the seventh game are won by Bob, the first game is draw and the rest are won by Alice.
instruction
0
45,100
19
90,200
Tags: graphs, implementation Correct Solution: ``` x = [[0 for i in range(4)] for j in range(4)] y = [[0 for i in range(4)] for j in range(4)] vis = [[0 for i in range(4)] for j in range(4)] dic = {} k, a, b = list(map(lambda _: int(_), input().split())) for i in range(3): x[i+1][1], x[i+1][2], x[i+1][3] = list(map(lambda _: int(_), input().split())) for i in range(3): y[i+1][1], y[i+1][2], y[i+1][3] = list(map(lambda _: int(_), input().split())) s1 = s2 = 0 dic[1] = [s1, s2] xx = a - b yy = b - a if xx == -2 or xx == 1: xx = 1 else: xx = 0 if yy == -2 or yy == 1: yy = 1 else: yy = 0 s1 += xx s2 += yy vis[a][b] = 1 k -= 1 cnt = 1 a1 = a b1 = b while True and k > 0: aa = a1 bb = b1 a1 = x[aa][bb] b1 = y[aa][bb] cnt += 1 if vis[a1][b1] != 0: tmp = vis[a1][b1] break vis[a1][b1] = cnt dic[cnt] = [s1, s2] xx = a1 - b1 yy = b1 - a1 if xx == -2 or xx == 1: xx = 1 else: xx = 0 if yy == -2 or yy == 1: yy = 1 else: yy = 0 s1 += xx s2 += yy k -= 1 if k == 0: print(s1, s2) else: ans1 = s1 ans2 = s2 s1 -= dic[tmp][0] s2 -= dic[tmp][1] cnt -= tmp ans1 += (k // cnt) * s1 ans2 += (k // cnt) * s2 k %= cnt while k > 0: xx = a1 - b1 yy = b1 - a1 if xx == -2 or xx == 1: xx = 1 else: xx = 0 if yy == -2 or yy == 1: yy = 1 else: yy = 0 ans1 += xx ans2 += yy aa = a1 bb = b1 a1 = x[aa][bb] b1 = y[aa][bb] k -= 1 print(ans1, ans2) ```
output
1
45,100
19
90,201
Provide tags and a correct Python 3 solution for this coding contest problem. Ilya is working for the company that constructs robots. Ilya writes programs for entertainment robots, and his current project is "Bob", a new-generation game robot. Ilya's boss wants to know his progress so far. Especially he is interested if Bob is better at playing different games than the previous model, "Alice". So now Ilya wants to compare his robots' performance in a simple game called "1-2-3". This game is similar to the "Rock-Paper-Scissors" game: both robots secretly choose a number from the set {1, 2, 3} and say it at the same moment. If both robots choose the same number, then it's a draw and noone gets any points. But if chosen numbers are different, then one of the robots gets a point: 3 beats 2, 2 beats 1 and 1 beats 3. Both robots' programs make them choose their numbers in such a way that their choice in (i + 1)-th game depends only on the numbers chosen by them in i-th game. Ilya knows that the robots will play k games, Alice will choose number a in the first game, and Bob will choose b in the first game. He also knows both robots' programs and can tell what each robot will choose depending on their choices in previous game. Ilya doesn't want to wait until robots play all k games, so he asks you to predict the number of points they will have after the final game. Input The first line contains three numbers k, a, b (1 ≤ k ≤ 1018, 1 ≤ a, b ≤ 3). Then 3 lines follow, i-th of them containing 3 numbers Ai, 1, Ai, 2, Ai, 3, where Ai, j represents Alice's choice in the game if Alice chose i in previous game and Bob chose j (1 ≤ Ai, j ≤ 3). Then 3 lines follow, i-th of them containing 3 numbers Bi, 1, Bi, 2, Bi, 3, where Bi, j represents Bob's choice in the game if Alice chose i in previous game and Bob chose j (1 ≤ Bi, j ≤ 3). Output Print two numbers. First of them has to be equal to the number of points Alice will have, and second of them must be Bob's score after k games. Examples Input 10 2 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 Output 1 9 Input 8 1 1 2 2 1 3 3 1 3 1 3 1 1 1 2 1 1 1 2 3 Output 5 2 Input 5 1 1 1 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 Output 0 0 Note In the second example game goes like this: <image> The fourth and the seventh game are won by Bob, the first game is draw and the rest are won by Alice.
instruction
0
45,101
19
90,202
Tags: graphs, implementation Correct Solution: ``` from math import floor def kek(a, b): if a == b: return ([0, 0]) elif a == 3 and b == 1: return ([0, 1]) elif a == 1 and b == 3: return ([1, 0]) elif a == 1 and b == 2: return ([0, 1]) elif a == 2 and b == 1: return ([1, 0]) elif a == 2 and b == 3: return ([0, 1]) elif a == 3 and b == 2: return ([1, 0]) k, a1, b1 = map(int, input().split()) a, b = [], [] for i in range(3): a.append([int(i) for i in input().split()]) for i in range(3): b.append([int(i) for i in input().split()]) n, m = [], [] n.append([a1, b1]) m.append(kek(a1, b1)) i = 0 ansb, ansa = 0, 0 while i != k: i += 1 if i == k: break a1, b1 = a[a1 - 1][b1 - 1], b[a1 - 1][b1 - 1] t = [a1, b1] if t not in n: n.append([a1, b1]) m.append(kek(a1, b1)) m[-1][0] += m[-2][0] m[-1][1] += m[-2][1] else: break if i == k: print(*m[-1]) else: ansa, ansb = m[-1][0], m[-1][1] for j in range(len(n)): if n[j] == [a1, b1]: t = j break ror = int((k - i) // (len(n) - t)) i = i + (len(n) - t) * ror if ror != 0: if t != 0: ansa += (m[-1][0] - m[t - 1][0]) * ror ansb += (m[-1][1] - m[t - 1][1]) * ror else: ansa += (m[-1][0]) * ror ansb += (m[-1][1]) * ror # while i + len(n) - t <= k: # if t != 0: # ansa += m[-1][0] - m[t - 1][0] # ansb += m[-1][1] - m[t - 1][1] # else: # ansa += m[-1][0] # ansb += m[-1][1] # i += len(n) - t if i != k: tmp = kek(a1, b1) ansa += tmp[0] ansb += tmp[1] i += 1 for j in range(k - i): a1, b1 = a[a1 - 1][b1 - 1], b[a1 - 1][b1 - 1] tmp = kek(a1, b1) ansa += tmp[0] ansb += tmp[1] print(ansa, ansb) ```
output
1
45,101
19
90,203
Provide tags and a correct Python 3 solution for this coding contest problem. Ilya is working for the company that constructs robots. Ilya writes programs for entertainment robots, and his current project is "Bob", a new-generation game robot. Ilya's boss wants to know his progress so far. Especially he is interested if Bob is better at playing different games than the previous model, "Alice". So now Ilya wants to compare his robots' performance in a simple game called "1-2-3". This game is similar to the "Rock-Paper-Scissors" game: both robots secretly choose a number from the set {1, 2, 3} and say it at the same moment. If both robots choose the same number, then it's a draw and noone gets any points. But if chosen numbers are different, then one of the robots gets a point: 3 beats 2, 2 beats 1 and 1 beats 3. Both robots' programs make them choose their numbers in such a way that their choice in (i + 1)-th game depends only on the numbers chosen by them in i-th game. Ilya knows that the robots will play k games, Alice will choose number a in the first game, and Bob will choose b in the first game. He also knows both robots' programs and can tell what each robot will choose depending on their choices in previous game. Ilya doesn't want to wait until robots play all k games, so he asks you to predict the number of points they will have after the final game. Input The first line contains three numbers k, a, b (1 ≤ k ≤ 1018, 1 ≤ a, b ≤ 3). Then 3 lines follow, i-th of them containing 3 numbers Ai, 1, Ai, 2, Ai, 3, where Ai, j represents Alice's choice in the game if Alice chose i in previous game and Bob chose j (1 ≤ Ai, j ≤ 3). Then 3 lines follow, i-th of them containing 3 numbers Bi, 1, Bi, 2, Bi, 3, where Bi, j represents Bob's choice in the game if Alice chose i in previous game and Bob chose j (1 ≤ Bi, j ≤ 3). Output Print two numbers. First of them has to be equal to the number of points Alice will have, and second of them must be Bob's score after k games. Examples Input 10 2 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 Output 1 9 Input 8 1 1 2 2 1 3 3 1 3 1 3 1 1 1 2 1 1 1 2 3 Output 5 2 Input 5 1 1 1 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 Output 0 0 Note In the second example game goes like this: <image> The fourth and the seventh game are won by Bob, the first game is draw and the rest are won by Alice.
instruction
0
45,102
19
90,204
Tags: graphs, implementation Correct Solution: ``` from functools import reduce def get_scores(a, b): if a == b: return (0, 0) elif (a, b) in ((2, 1), (1, 0), (0, 2)): return (1, 0) else: return (0, 1) def add(t1, t2): return tuple(map(sum, zip(t1, t2))) def mul(t, x): return t[0] * x, t[1] * x k, a, b = map(int, input().split(' ')) alice_ts = {} bob_ts = {} for ts in (alice_ts, bob_ts): for i in range(3): xs = list(map(int, input().split(' ')))[::-1] for j in range(3): ts[(i, j)] = xs.pop() - 1 state = (a - 1, b - 1) result = (0, 0) log = {} step_results = [] start, end = None, None for i in range(k): if state in log: start = log[state] end = i break current_res = get_scores(*state) result = add(result, current_res) log[state] = i step_results.append(current_res) if end is not None: break state = alice_ts[state], bob_ts[state] if end is not None: cycle_sum = reduce(add, step_results[start:end]) total_cycle_sum = mul(cycle_sum, (k - end) // (end - start)) result = add(result, total_cycle_sum) for i in range(0, (k - end) % (end - start)): result = add(result, step_results[start + i]) print(result[0], result[1]) ```
output
1
45,102
19
90,205
Provide tags and a correct Python 3 solution for this coding contest problem. Ilya is working for the company that constructs robots. Ilya writes programs for entertainment robots, and his current project is "Bob", a new-generation game robot. Ilya's boss wants to know his progress so far. Especially he is interested if Bob is better at playing different games than the previous model, "Alice". So now Ilya wants to compare his robots' performance in a simple game called "1-2-3". This game is similar to the "Rock-Paper-Scissors" game: both robots secretly choose a number from the set {1, 2, 3} and say it at the same moment. If both robots choose the same number, then it's a draw and noone gets any points. But if chosen numbers are different, then one of the robots gets a point: 3 beats 2, 2 beats 1 and 1 beats 3. Both robots' programs make them choose their numbers in such a way that their choice in (i + 1)-th game depends only on the numbers chosen by them in i-th game. Ilya knows that the robots will play k games, Alice will choose number a in the first game, and Bob will choose b in the first game. He also knows both robots' programs and can tell what each robot will choose depending on their choices in previous game. Ilya doesn't want to wait until robots play all k games, so he asks you to predict the number of points they will have after the final game. Input The first line contains three numbers k, a, b (1 ≤ k ≤ 1018, 1 ≤ a, b ≤ 3). Then 3 lines follow, i-th of them containing 3 numbers Ai, 1, Ai, 2, Ai, 3, where Ai, j represents Alice's choice in the game if Alice chose i in previous game and Bob chose j (1 ≤ Ai, j ≤ 3). Then 3 lines follow, i-th of them containing 3 numbers Bi, 1, Bi, 2, Bi, 3, where Bi, j represents Bob's choice in the game if Alice chose i in previous game and Bob chose j (1 ≤ Bi, j ≤ 3). Output Print two numbers. First of them has to be equal to the number of points Alice will have, and second of them must be Bob's score after k games. Examples Input 10 2 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 Output 1 9 Input 8 1 1 2 2 1 3 3 1 3 1 3 1 1 1 2 1 1 1 2 3 Output 5 2 Input 5 1 1 1 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 Output 0 0 Note In the second example game goes like this: <image> The fourth and the seventh game are won by Bob, the first game is draw and the rest are won by Alice.
instruction
0
45,103
19
90,206
Tags: graphs, implementation Correct Solution: ``` #!/usr/bin/env python3 # encoding: utf-8 #---------- # Constants #---------- #---------- # Functions #---------- # Reads a string from stdin, splits it by space chars, converts each # substring to int, adds it to a list and returns the list as a result. def get_ints(): return [ int(n) for n in input().split() ] def move(matrix, a, b): return matrix[a][b] def game(a, b): res = (a - b) % 3 if res == 1: return (1, 0) elif res == 2: return (0, 1) else: return (0, 0) #---------- # Execution start point #---------- if __name__ == "__main__": z = get_ints() assert len(z) == 3 k, a, b = z[0], z[1]-1, z[2]-1 alice = list() for i in range(3): z = get_ints() assert len(z) == 3 for j in range(len(z)): z[j] -= 1 alice.append(z.copy()) bob = list() for i in range(3): z = get_ints() assert len(z) == 3 for j in range(len(z)): z[j] -= 1 bob.append(z.copy()) moves = list() results = list() index = -1 for m in range(k): if (a, b) in moves: index = moves.index((a, b)) break moves.append((a, b)) results.append(game(a, b)) a, b = move(alice, a, b), move(bob, a, b) # periods apoint, bpoint = 0, 0 c = len(moves) - index rep = (k - index) // c for res in results[index:]: da, db = res apoint += da bpoint += db apoint *= rep bpoint *= rep # after rem = (k - index) % c for i in range(rem): da, db = results[i + index] apoint += da bpoint += db # before for res in results[:index]: da, db = res apoint += da bpoint += db print(apoint, bpoint) ```
output
1
45,103
19
90,207
Provide tags and a correct Python 3 solution for this coding contest problem. Ilya is working for the company that constructs robots. Ilya writes programs for entertainment robots, and his current project is "Bob", a new-generation game robot. Ilya's boss wants to know his progress so far. Especially he is interested if Bob is better at playing different games than the previous model, "Alice". So now Ilya wants to compare his robots' performance in a simple game called "1-2-3". This game is similar to the "Rock-Paper-Scissors" game: both robots secretly choose a number from the set {1, 2, 3} and say it at the same moment. If both robots choose the same number, then it's a draw and noone gets any points. But if chosen numbers are different, then one of the robots gets a point: 3 beats 2, 2 beats 1 and 1 beats 3. Both robots' programs make them choose their numbers in such a way that their choice in (i + 1)-th game depends only on the numbers chosen by them in i-th game. Ilya knows that the robots will play k games, Alice will choose number a in the first game, and Bob will choose b in the first game. He also knows both robots' programs and can tell what each robot will choose depending on their choices in previous game. Ilya doesn't want to wait until robots play all k games, so he asks you to predict the number of points they will have after the final game. Input The first line contains three numbers k, a, b (1 ≤ k ≤ 1018, 1 ≤ a, b ≤ 3). Then 3 lines follow, i-th of them containing 3 numbers Ai, 1, Ai, 2, Ai, 3, where Ai, j represents Alice's choice in the game if Alice chose i in previous game and Bob chose j (1 ≤ Ai, j ≤ 3). Then 3 lines follow, i-th of them containing 3 numbers Bi, 1, Bi, 2, Bi, 3, where Bi, j represents Bob's choice in the game if Alice chose i in previous game and Bob chose j (1 ≤ Bi, j ≤ 3). Output Print two numbers. First of them has to be equal to the number of points Alice will have, and second of them must be Bob's score after k games. Examples Input 10 2 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 Output 1 9 Input 8 1 1 2 2 1 3 3 1 3 1 3 1 1 1 2 1 1 1 2 3 Output 5 2 Input 5 1 1 1 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 Output 0 0 Note In the second example game goes like this: <image> The fourth and the seventh game are won by Bob, the first game is draw and the rest are won by Alice.
instruction
0
45,104
19
90,208
Tags: graphs, implementation Correct Solution: ``` def winner(A,B): if A==B: return -1 if A==1 and B!=2: return 0 if A==2 and B!=3: return 0 if A==3 and B!=1: return 0 if A!=2 and B==1: return 1 if A!=3 and B==2: return 1 if A!=1 and B==3: return 1 return -1 k,A,B=map(int,input().split()) arr=[0]*3 brr=[0]*3 for i in range(3): arr[i]=list(map(int,input().split())) for i in range(3): brr[i]=list(map(int,input().split())) q=[0]*81 p=[0]*81 w=[-1]*81 q[0]=A p[0]=B w[0]=winner(A,B) j=1 flag=1 while(flag): for i in range(81): # print(arr[q[j-1]][p[j-1]],q[i]) if arr[q[j-1]-1][p[j-1]-1]==q[i] and brr[q[j-1]-1][p[j-1]-1]==p[i]: flag=0 ans =i if flag: q[j]=arr[q[j-1]-1][p[j-1]-1] p[j]=brr[q[j-1]-1][p[j-1]-1] w[j]=winner(q[j],p[j]) j+=1 ze=0 on=0 for i in range(ans,81): if w[i]==0: ze+=1 if w[i]==1: on+=1 r=(k-ans)%(j-ans) d=(k-ans)//(j-ans) if d<0: d=0 r=0 ze=ze*d on=on*d #print(r,d) for i in range(min(ans,k)): if w[i]==0: ze+=1 if w[i]==1: on+=1 i=ans #print(p) #print(q) while(r): if w[i]==0: ze+=1 if w[i]==1: on+=1 i+=1 r-=1 print(ze,on) ```
output
1
45,104
19
90,209
Provide tags and a correct Python 3 solution for this coding contest problem. Ilya is working for the company that constructs robots. Ilya writes programs for entertainment robots, and his current project is "Bob", a new-generation game robot. Ilya's boss wants to know his progress so far. Especially he is interested if Bob is better at playing different games than the previous model, "Alice". So now Ilya wants to compare his robots' performance in a simple game called "1-2-3". This game is similar to the "Rock-Paper-Scissors" game: both robots secretly choose a number from the set {1, 2, 3} and say it at the same moment. If both robots choose the same number, then it's a draw and noone gets any points. But if chosen numbers are different, then one of the robots gets a point: 3 beats 2, 2 beats 1 and 1 beats 3. Both robots' programs make them choose their numbers in such a way that their choice in (i + 1)-th game depends only on the numbers chosen by them in i-th game. Ilya knows that the robots will play k games, Alice will choose number a in the first game, and Bob will choose b in the first game. He also knows both robots' programs and can tell what each robot will choose depending on their choices in previous game. Ilya doesn't want to wait until robots play all k games, so he asks you to predict the number of points they will have after the final game. Input The first line contains three numbers k, a, b (1 ≤ k ≤ 1018, 1 ≤ a, b ≤ 3). Then 3 lines follow, i-th of them containing 3 numbers Ai, 1, Ai, 2, Ai, 3, where Ai, j represents Alice's choice in the game if Alice chose i in previous game and Bob chose j (1 ≤ Ai, j ≤ 3). Then 3 lines follow, i-th of them containing 3 numbers Bi, 1, Bi, 2, Bi, 3, where Bi, j represents Bob's choice in the game if Alice chose i in previous game and Bob chose j (1 ≤ Bi, j ≤ 3). Output Print two numbers. First of them has to be equal to the number of points Alice will have, and second of them must be Bob's score after k games. Examples Input 10 2 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 Output 1 9 Input 8 1 1 2 2 1 3 3 1 3 1 3 1 1 1 2 1 1 1 2 3 Output 5 2 Input 5 1 1 1 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 Output 0 0 Note In the second example game goes like this: <image> The fourth and the seventh game are won by Bob, the first game is draw and the rest are won by Alice.
instruction
0
45,105
19
90,210
Tags: graphs, implementation Correct Solution: ``` def readln(): return map(int, input().rstrip().split()) def score_of(x, y): if x == y: return 0, 0 elif x == 3 and y == 2: return 1, 0 elif x == 2 and y == 3: return 0, 1 elif x == 2 and y == 1: return 1, 0 elif x == 1 and y == 2: return 0, 1 elif x == 1 and y == 3: return 1, 0 elif x == 3 and y == 1: return 0, 1 k, a, b = readln() A, B = [[0 for i in range(4)] for j in range(4)], [[0 for i in range(4)] for j in range(4)] for i in range(1, 4): a1, a2, a3 = readln() A[i][1], A[i][2], A[i][3] = a1, a2, a3 for i in range(1, 4): a1, a2, a3 = readln() B[i][1], B[i][2], B[i][3] = a1, a2, a3 circle = set() circle_score = [(0, 0)] circle_data = [] x, y = a, b while (x, y) not in circle and k > 0: circle.add((x, y)) circle_data.append((x, y)) x_, y_ = score_of(x, y) circle_score.append((circle_score[-1][0] + x_, circle_score[-1][1] + y_)) x, y = A[x][y], B[x][y] k -= 1 if k == 0: print("{} {}".format(circle_score[-1][0], circle_score[-1][1])) exit() pre_idx = circle_data.index((x, y)) freq = len(circle_data) - pre_idx fscorea, fscoreb = circle_score[-1][0] - circle_score[pre_idx][0], circle_score[-1][1] - circle_score[pre_idx][1] p = k // freq rsa = circle_score[-1][0] + fscorea * p rsb = circle_score[-1][1] + fscoreb * p r = k % freq while r > 0: x_, y_ = score_of(x, y) rsa += x_ rsb += y_ x, y = A[x][y], B[x][y] r -= 1 print("{} {}".format(rsa, rsb)) ```
output
1
45,105
19
90,211
Provide tags and a correct Python 3 solution for this coding contest problem. Ilya is working for the company that constructs robots. Ilya writes programs for entertainment robots, and his current project is "Bob", a new-generation game robot. Ilya's boss wants to know his progress so far. Especially he is interested if Bob is better at playing different games than the previous model, "Alice". So now Ilya wants to compare his robots' performance in a simple game called "1-2-3". This game is similar to the "Rock-Paper-Scissors" game: both robots secretly choose a number from the set {1, 2, 3} and say it at the same moment. If both robots choose the same number, then it's a draw and noone gets any points. But if chosen numbers are different, then one of the robots gets a point: 3 beats 2, 2 beats 1 and 1 beats 3. Both robots' programs make them choose their numbers in such a way that their choice in (i + 1)-th game depends only on the numbers chosen by them in i-th game. Ilya knows that the robots will play k games, Alice will choose number a in the first game, and Bob will choose b in the first game. He also knows both robots' programs and can tell what each robot will choose depending on their choices in previous game. Ilya doesn't want to wait until robots play all k games, so he asks you to predict the number of points they will have after the final game. Input The first line contains three numbers k, a, b (1 ≤ k ≤ 1018, 1 ≤ a, b ≤ 3). Then 3 lines follow, i-th of them containing 3 numbers Ai, 1, Ai, 2, Ai, 3, where Ai, j represents Alice's choice in the game if Alice chose i in previous game and Bob chose j (1 ≤ Ai, j ≤ 3). Then 3 lines follow, i-th of them containing 3 numbers Bi, 1, Bi, 2, Bi, 3, where Bi, j represents Bob's choice in the game if Alice chose i in previous game and Bob chose j (1 ≤ Bi, j ≤ 3). Output Print two numbers. First of them has to be equal to the number of points Alice will have, and second of them must be Bob's score after k games. Examples Input 10 2 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 Output 1 9 Input 8 1 1 2 2 1 3 3 1 3 1 3 1 1 1 2 1 1 1 2 3 Output 5 2 Input 5 1 1 1 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 Output 0 0 Note In the second example game goes like this: <image> The fourth and the seventh game are won by Bob, the first game is draw and the rest are won by Alice.
instruction
0
45,106
19
90,212
Tags: graphs, implementation Correct Solution: ``` from sys import stdin, stdout k, a, b = map(int, stdin.readline().split()) sze = 3 A = [[]] B = [[]] for i in range(sze): values = [0] + list(map(int, stdin.readline().split())) A.append(values) for i in range(sze): values = [0] + list(map(int, stdin.readline().split())) B.append(values) start = (a, b) power = 70 steps = [{} for i in range(power)] cnt = [{} for i in range(power)] for i in range(1, sze + 1): for j in range(1, sze + 1): steps[0][(i, j)] = (A[i][j], B[i][j]) cnt[0][(i, j)] = 0, 0 if i == 1 and j == 3: cnt[0][(i, j)] = (1, 0) if i == 2 and j == 1: cnt[0][(i, j)] = (1, 0) if i == 3 and j == 2: cnt[0][(i, j)] = (1, 0) if i == 3 and j == 1: cnt[0][(i, j)] = (0, 1) if i == 1 and j == 2: cnt[0][(i, j)] = (0, 1) if i == 2 and j == 3: cnt[0][(i, j)] = (0, 1) for z in range(1, power): for i in range(1, sze + 1): for j in range(1, sze + 1): steps[z][(i, j)] = steps[z - 1][steps[z - 1][(i, j)]] first, second = cnt[z - 1][(i, j)][0] + cnt[z - 1][steps[z - 1][(i, j)]][0], cnt[z - 1][(i, j)][1] + cnt[z - 1][steps[z - 1][(i, j)]][1] cnt[z][(i, j)] = (first, second) value = [0, 0] while k: power = 1 pw = 0 while power * 2 <= k: power *= 2 pw += 1 k -= power value[0] += cnt[pw][(a, b)][0] value[1] += cnt[pw][(a, b)][1] a, b = steps[pw][(a, b)] stdout.write(' '.join(list(map(str, value)))) ```
output
1
45,106
19
90,213
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ilya is working for the company that constructs robots. Ilya writes programs for entertainment robots, and his current project is "Bob", a new-generation game robot. Ilya's boss wants to know his progress so far. Especially he is interested if Bob is better at playing different games than the previous model, "Alice". So now Ilya wants to compare his robots' performance in a simple game called "1-2-3". This game is similar to the "Rock-Paper-Scissors" game: both robots secretly choose a number from the set {1, 2, 3} and say it at the same moment. If both robots choose the same number, then it's a draw and noone gets any points. But if chosen numbers are different, then one of the robots gets a point: 3 beats 2, 2 beats 1 and 1 beats 3. Both robots' programs make them choose their numbers in such a way that their choice in (i + 1)-th game depends only on the numbers chosen by them in i-th game. Ilya knows that the robots will play k games, Alice will choose number a in the first game, and Bob will choose b in the first game. He also knows both robots' programs and can tell what each robot will choose depending on their choices in previous game. Ilya doesn't want to wait until robots play all k games, so he asks you to predict the number of points they will have after the final game. Input The first line contains three numbers k, a, b (1 ≤ k ≤ 1018, 1 ≤ a, b ≤ 3). Then 3 lines follow, i-th of them containing 3 numbers Ai, 1, Ai, 2, Ai, 3, where Ai, j represents Alice's choice in the game if Alice chose i in previous game and Bob chose j (1 ≤ Ai, j ≤ 3). Then 3 lines follow, i-th of them containing 3 numbers Bi, 1, Bi, 2, Bi, 3, where Bi, j represents Bob's choice in the game if Alice chose i in previous game and Bob chose j (1 ≤ Bi, j ≤ 3). Output Print two numbers. First of them has to be equal to the number of points Alice will have, and second of them must be Bob's score after k games. Examples Input 10 2 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 Output 1 9 Input 8 1 1 2 2 1 3 3 1 3 1 3 1 1 1 2 1 1 1 2 3 Output 5 2 Input 5 1 1 1 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 Output 0 0 Note In the second example game goes like this: <image> The fourth and the seventh game are won by Bob, the first game is draw and the rest are won by Alice. Submitted Solution: ``` import sys def log(s): # print(s) pass k, a, b = map(int, sys.stdin.readline().strip().split(' ')) alice = {} for i in range(3): one, two, three = map(int, sys.stdin.readline().strip().split(' ')) alice[(i + 1, 1)] = one alice[(i + 1, 2)] = two alice[(i + 1, 3)] = three bob = {} for i in range(3): one, two, three = map(int, sys.stdin.readline().strip().split(' ')) bob[(i + 1, 1)] = one bob[(i + 1, 2)] = two bob[(i + 1, 3)] = three score = {(1, 1): (0, 0), (2, 2): (0, 0), (3, 3): (0, 0), (1, 2): (0, +1), (2, 3): (0, +1), (3, 1): (0, 1), (2, 1): (1, 0), (3, 2): (1, 0), (1, 3): (1, 0)} seen = [] current = (a, b) while current not in seen: seen.append(current) current = (alice[current], bob[current]) loop = seen.index(current) vals = [score[state] for state in seen] a_point, b_point = (0, 0) a_vals, b_vals = zip(*vals) a_point += sum(a_vals[:min(k, loop)]) b_point += sum(b_vals[:min(k, loop)]) k = k - loop loop_len = len(seen) - loop a_loop_val = sum(a_vals[loop:]) b_loop_val = sum(b_vals[loop:]) if k >= 0: tail = k % loop_len num_iters = k // loop_len a_point += sum(a_vals[loop:loop+tail]) b_point += sum(b_vals[loop:loop+tail]) a_point += num_iters * a_loop_val b_point += num_iters * b_loop_val log(a_point) log(b_point) print(round(a_point), round(b_point)) ```
instruction
0
45,107
19
90,214
Yes
output
1
45,107
19
90,215
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ilya is working for the company that constructs robots. Ilya writes programs for entertainment robots, and his current project is "Bob", a new-generation game robot. Ilya's boss wants to know his progress so far. Especially he is interested if Bob is better at playing different games than the previous model, "Alice". So now Ilya wants to compare his robots' performance in a simple game called "1-2-3". This game is similar to the "Rock-Paper-Scissors" game: both robots secretly choose a number from the set {1, 2, 3} and say it at the same moment. If both robots choose the same number, then it's a draw and noone gets any points. But if chosen numbers are different, then one of the robots gets a point: 3 beats 2, 2 beats 1 and 1 beats 3. Both robots' programs make them choose their numbers in such a way that their choice in (i + 1)-th game depends only on the numbers chosen by them in i-th game. Ilya knows that the robots will play k games, Alice will choose number a in the first game, and Bob will choose b in the first game. He also knows both robots' programs and can tell what each robot will choose depending on their choices in previous game. Ilya doesn't want to wait until robots play all k games, so he asks you to predict the number of points they will have after the final game. Input The first line contains three numbers k, a, b (1 ≤ k ≤ 1018, 1 ≤ a, b ≤ 3). Then 3 lines follow, i-th of them containing 3 numbers Ai, 1, Ai, 2, Ai, 3, where Ai, j represents Alice's choice in the game if Alice chose i in previous game and Bob chose j (1 ≤ Ai, j ≤ 3). Then 3 lines follow, i-th of them containing 3 numbers Bi, 1, Bi, 2, Bi, 3, where Bi, j represents Bob's choice in the game if Alice chose i in previous game and Bob chose j (1 ≤ Bi, j ≤ 3). Output Print two numbers. First of them has to be equal to the number of points Alice will have, and second of them must be Bob's score after k games. Examples Input 10 2 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 Output 1 9 Input 8 1 1 2 2 1 3 3 1 3 1 3 1 1 1 2 1 1 1 2 3 Output 5 2 Input 5 1 1 1 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 Output 0 0 Note In the second example game goes like this: <image> The fourth and the seventh game are won by Bob, the first game is draw and the rest are won by Alice. Submitted Solution: ``` f = lambda: list(map(int, input().split())) g = lambda: [[0] * 4] + [[0] + f() for i in range(3)] h = lambda x, y: x - 1 == y % 3 t = lambda a, b, u, v: (A[a][b], B[a][b], u + h(a, b), v + h(b, a)) k, a, b = f() p = 2520 s, d = divmod(k, p) A, B = g(), g() u = v = x = y = 0 for j in range(d): a, b, u, v = t(a, b, u, v) for i in range(p): a, b, x, y = t(a, b, x, y) print(u + x * s, v + y * s) # Made By Mostafa_Khaled ```
instruction
0
45,108
19
90,216
Yes
output
1
45,108
19
90,217
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ilya is working for the company that constructs robots. Ilya writes programs for entertainment robots, and his current project is "Bob", a new-generation game robot. Ilya's boss wants to know his progress so far. Especially he is interested if Bob is better at playing different games than the previous model, "Alice". So now Ilya wants to compare his robots' performance in a simple game called "1-2-3". This game is similar to the "Rock-Paper-Scissors" game: both robots secretly choose a number from the set {1, 2, 3} and say it at the same moment. If both robots choose the same number, then it's a draw and noone gets any points. But if chosen numbers are different, then one of the robots gets a point: 3 beats 2, 2 beats 1 and 1 beats 3. Both robots' programs make them choose their numbers in such a way that their choice in (i + 1)-th game depends only on the numbers chosen by them in i-th game. Ilya knows that the robots will play k games, Alice will choose number a in the first game, and Bob will choose b in the first game. He also knows both robots' programs and can tell what each robot will choose depending on their choices in previous game. Ilya doesn't want to wait until robots play all k games, so he asks you to predict the number of points they will have after the final game. Input The first line contains three numbers k, a, b (1 ≤ k ≤ 1018, 1 ≤ a, b ≤ 3). Then 3 lines follow, i-th of them containing 3 numbers Ai, 1, Ai, 2, Ai, 3, where Ai, j represents Alice's choice in the game if Alice chose i in previous game and Bob chose j (1 ≤ Ai, j ≤ 3). Then 3 lines follow, i-th of them containing 3 numbers Bi, 1, Bi, 2, Bi, 3, where Bi, j represents Bob's choice in the game if Alice chose i in previous game and Bob chose j (1 ≤ Bi, j ≤ 3). Output Print two numbers. First of them has to be equal to the number of points Alice will have, and second of them must be Bob's score after k games. Examples Input 10 2 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 Output 1 9 Input 8 1 1 2 2 1 3 3 1 3 1 3 1 1 1 2 1 1 1 2 3 Output 5 2 Input 5 1 1 1 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 Output 0 0 Note In the second example game goes like this: <image> The fourth and the seventh game are won by Bob, the first game is draw and the rest are won by Alice. Submitted Solution: ``` def winner(x, y): if x == 1 and y == 3: return (1, 0) if x == 2 and y == 1: return (1, 0) if x == 3 and y == 2: return (1, 0) if x == y: return (0, 0) if x == 3 and y == 1: return (0, 1) if x == 1 and y == 2: return (0, 1) if x == 2 and y == 3: return (0, 1) k, a, b = map(int, input().split()) choice_a = [] choice_b = [] for i in range(3): choice_a.append(list(map(int, input().split()))) for i in range(3): choice_b.append(list(map(int, input().split()))) line = [] win_line = [] line.append((a - 1, b - 1)) win_line.append(winner(a, b)) while True: x, y = line[-1] xc = choice_a[x][y] - 1 yc = choice_b[x][y] - 1 if (xc, yc) in line: s = line.index((xc, yc)) mod = len(line) - s s_cnt = win_line[s] s_mod = (win_line[-1][0] - win_line[s][0], win_line[-1][1] - win_line[s][1]) break line.append((xc , yc)) ans = winner(xc + 1, yc + 1) win_line.append((win_line[-1][0] + ans[0], win_line[-1][1] + ans[1])) if k < s: print(*win_line[k - 1]) else: kk = (k - s - 1) % mod km = (k - s - 1) // mod ans1 = win_line[kk + s] ans2 = win_line[-1] win_line.append((0, 0)) ans3 = win_line[s - 1] ans_mod = (ans2[0] - ans3[0], ans2[1] - ans3[1]) print(ans1[0] + ans_mod[0] * (km), ans1[1] + ans_mod[1] * (km)) ```
instruction
0
45,109
19
90,218
Yes
output
1
45,109
19
90,219
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ilya is working for the company that constructs robots. Ilya writes programs for entertainment robots, and his current project is "Bob", a new-generation game robot. Ilya's boss wants to know his progress so far. Especially he is interested if Bob is better at playing different games than the previous model, "Alice". So now Ilya wants to compare his robots' performance in a simple game called "1-2-3". This game is similar to the "Rock-Paper-Scissors" game: both robots secretly choose a number from the set {1, 2, 3} and say it at the same moment. If both robots choose the same number, then it's a draw and noone gets any points. But if chosen numbers are different, then one of the robots gets a point: 3 beats 2, 2 beats 1 and 1 beats 3. Both robots' programs make them choose their numbers in such a way that their choice in (i + 1)-th game depends only on the numbers chosen by them in i-th game. Ilya knows that the robots will play k games, Alice will choose number a in the first game, and Bob will choose b in the first game. He also knows both robots' programs and can tell what each robot will choose depending on their choices in previous game. Ilya doesn't want to wait until robots play all k games, so he asks you to predict the number of points they will have after the final game. Input The first line contains three numbers k, a, b (1 ≤ k ≤ 1018, 1 ≤ a, b ≤ 3). Then 3 lines follow, i-th of them containing 3 numbers Ai, 1, Ai, 2, Ai, 3, where Ai, j represents Alice's choice in the game if Alice chose i in previous game and Bob chose j (1 ≤ Ai, j ≤ 3). Then 3 lines follow, i-th of them containing 3 numbers Bi, 1, Bi, 2, Bi, 3, where Bi, j represents Bob's choice in the game if Alice chose i in previous game and Bob chose j (1 ≤ Bi, j ≤ 3). Output Print two numbers. First of them has to be equal to the number of points Alice will have, and second of them must be Bob's score after k games. Examples Input 10 2 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 Output 1 9 Input 8 1 1 2 2 1 3 3 1 3 1 3 1 1 1 2 1 1 1 2 3 Output 5 2 Input 5 1 1 1 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 Output 0 0 Note In the second example game goes like this: <image> The fourth and the seventh game are won by Bob, the first game is draw and the rest are won by Alice. Submitted Solution: ``` #educational round 29 #two robots play N rounds of game 1 2 3. each choose a number from 1 2 or 3 #game rule 3 win 2, 2 win 1, 1 win against 3 #player choose next number from previous move of both players. #input format #line 1: N a b - N round of games, a b is the number of first round from alice and bob #line 2 - 4: 3 x 3 grid Aij is next number of Alice if previous A=i, B=j #line 5 - 7: 3 x 3 grid Bij is next number of Bob if previous A=i, B=j #output format #total points of Alice and Bob class Game123: def __init__(self): self.alice = [0]*9 self.bob=[0]*9 self.moves=[-1]*10 self.count=0 self.pointsA=0 self.pointsB=0 #convert 3x3 grid into 1D array def gameChoice(self, m, r, bBob): choice=self.alice if bBob: choice=self.bob for i in range(len(m)): choice[3*r+i]=m[i] #look if move already exists def findMove(self, a, b): m=(a-1)*3+b-1 for i in range(self.count): if self.moves[i]==m: return i #print("a={0} b={1} m={2} count={3}".format(a,b,m, self.count)) self.moves[self.count]=m self.count += 1 return -1 def computePoints(self, m): #convert m back to a and b, m is from 0 to 8 b=m%3+1 a=m//3+1 #return positive if alice win if a==b: return if a==3 and b==2 or a==2 and b==1 or a==1 and b==3: self.pointsA += 1 else: self.pointsB += 1 def output(self): print("{0} {1}".format(self.pointsA,self.pointsB)) def startGame(self, a, b, totalmoves): #print(self.moves) #print(self.alice) #print(self.bob) found=-1 while found<0: found=self.findMove(a,b) m=(a-1)*3+b-1 a=self.alice[m] #next move b=self.bob[m] #print("repeat {0} to {1}".format(found, self.count)) pointaA=0 pointsB=0 # compute moves of no repeats if totalmoves <= self.count: for i in range(totalmoves): self.computePoints(self.moves[i]) else: totalmoves -= found repeats = totalmoves//(self.count-found) totalmoves %= (self.count-found) for i in range(found, self.count): #repeated moves self.computePoints(self.moves[i]) #self.output() self.pointsA *= repeats self.pointsB *= repeats #self.output() for i in range(found): #moves before repeat self.computePoints(self.moves[i]) #self.output() for i in range(found, totalmoves+found): #odd moves after repeat self.computePoints(self.moves[i]) self.output() def test(): g=Game123() g.gameChoice([2,2,1],0,False) g.gameChoice([3,3,1],1,False) g.gameChoice([3,1,3],2,False) g.gameChoice([1,1,1],0,True) g.gameChoice([2,1,1],1,True) g.gameChoice([1,2,3],2,True) g.startGame(1,1,8) def nia(): s=input() while len(s)==0: s=input() s=s.split() iVal=[]; for i in range (len(s)): iVal.append(int(s[i])) return iVal def solve(): g=Game123() nab=nia() for i in range(3): g.gameChoice(nia(), i, False) for i in range(3): g.gameChoice(nia(), i, True) g.startGame(nab[1],nab[2],nab[0]) solve() ```
instruction
0
45,110
19
90,220
Yes
output
1
45,110
19
90,221
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ilya is working for the company that constructs robots. Ilya writes programs for entertainment robots, and his current project is "Bob", a new-generation game robot. Ilya's boss wants to know his progress so far. Especially he is interested if Bob is better at playing different games than the previous model, "Alice". So now Ilya wants to compare his robots' performance in a simple game called "1-2-3". This game is similar to the "Rock-Paper-Scissors" game: both robots secretly choose a number from the set {1, 2, 3} and say it at the same moment. If both robots choose the same number, then it's a draw and noone gets any points. But if chosen numbers are different, then one of the robots gets a point: 3 beats 2, 2 beats 1 and 1 beats 3. Both robots' programs make them choose their numbers in such a way that their choice in (i + 1)-th game depends only on the numbers chosen by them in i-th game. Ilya knows that the robots will play k games, Alice will choose number a in the first game, and Bob will choose b in the first game. He also knows both robots' programs and can tell what each robot will choose depending on their choices in previous game. Ilya doesn't want to wait until robots play all k games, so he asks you to predict the number of points they will have after the final game. Input The first line contains three numbers k, a, b (1 ≤ k ≤ 1018, 1 ≤ a, b ≤ 3). Then 3 lines follow, i-th of them containing 3 numbers Ai, 1, Ai, 2, Ai, 3, where Ai, j represents Alice's choice in the game if Alice chose i in previous game and Bob chose j (1 ≤ Ai, j ≤ 3). Then 3 lines follow, i-th of them containing 3 numbers Bi, 1, Bi, 2, Bi, 3, where Bi, j represents Bob's choice in the game if Alice chose i in previous game and Bob chose j (1 ≤ Bi, j ≤ 3). Output Print two numbers. First of them has to be equal to the number of points Alice will have, and second of them must be Bob's score after k games. Examples Input 10 2 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 Output 1 9 Input 8 1 1 2 2 1 3 3 1 3 1 3 1 1 1 2 1 1 1 2 3 Output 5 2 Input 5 1 1 1 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 Output 0 0 Note In the second example game goes like this: <image> The fourth and the seventh game are won by Bob, the first game is draw and the rest are won by Alice. Submitted Solution: ``` k,a,b = map(int,input().split(' ')) mas = [] hm = [] hmhm = [] for j in range(2): mas.append([]) for i in range(3): mas[j].append(list(map(int,input().split(' ')))) aa = 0 bb = 0 hmhm.append((aa,bb)) if a != b: if ((a == 2 and b == 1) or (a == 3 and b == 2) or (a == 1 and b == 3)): aa += 1 else: bb += 1 hm.append((a,b)) hmhm.append((aa,bb)) i = 0 while (i < k-1 and (mas[0][a-1][b-1],mas[1][a-1][b-1]) not in hm): t = mas[0][a-1][b-1] y = mas[1][a-1][b-1] a = t b = y if a != b: if ((a == 2 and b == 1) or (a == 3 and b == 2) or (a == 1 and b == 3)): aa += 1 else: bb += 1 hm.append((a,b)) hmhm.append((aa,bb)) i += 1 if i < k-1: i = hm.index((mas[0][a-1][b-1],mas[1][a-1][b-1])) print(i) print(' '.join((str(aa),str(bb)))) aa += ((k-i) // (len(hm)-i) -1)*(hmhm[-1][0]-hmhm[0 if i==0 else i][0]) bb += ((k-i) // (len(hm)-i) -1)*(hmhm[-1][1]-hmhm[0 if i==0 else i][1]) print(' '.join((str(aa),str(bb)))) aa += (hmhm[((k-i) % (len(hm)-i))+(0 if i==0 else 1) + (0 if ((k-i) % (len(hm)-i))==0 else i)][0] - hmhm[0 if i==0 else i][0]) bb += (hmhm[((k-i) % (len(hm)-i))+(0 if i==0 else 1) + (0 if ((k-i) % (len(hm)-i))==0 else i)][1] - hmhm[0 if i==0 else i][1]) print(' '.join(map(str,hm))) print(' '.join(map(str,hmhm))) print(' '.join((str(aa),str(bb)))) ```
instruction
0
45,111
19
90,222
No
output
1
45,111
19
90,223