message
stringlengths
2
67k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
463
109k
cluster
float64
19
19
__index_level_0__
int64
926
217k
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two soldiers are playing a game. At the beginning first of them chooses a positive integer n and gives it to the second soldier. Then the second one tries to make maximum possible number of rounds. Each round consists of choosing a positive integer x > 1, such that n is divisible by x and replacing n with n / x. When n becomes equal to 1 and there is no more possible valid moves the game is over and the score of the second soldier is equal to the number of rounds he performed. To make the game more interesting, first soldier chooses n of form a! / b! for some positive integer a and b (a β‰₯ b). Here by k! we denote the factorial of k that is defined as a product of all positive integers not large than k. What is the maximum possible score of the second soldier? Input First line of input consists of single integer t (1 ≀ t ≀ 1 000 000) denoting number of games soldiers play. Then follow t lines, each contains pair of integers a and b (1 ≀ b ≀ a ≀ 5 000 000) defining the value of n for a game. Output For each game output a maximum score that the second soldier can get. Examples Input 2 3 1 6 3 Output 2 5 Submitted Solution: ``` # Author : nitish420 -------------------------------------------------------------------- import os import sys from io import BytesIO, IOBase mod=10**9+7 # sys.setrecursionlimit(10**6) # from functools import lru_cache def sieve(n): global dp i=2 while i*i<=n: if dp[i]==0: z=i*i for j in range(i,n+1,i): if j==z: for k in range(z,n+1,z): dp[k]+=1 z*=i # continue dp[j]+=1 i+=1 return dp=[0]*(5000009) sieve(5000005) for _ in range(int(input())): a,b=map(int,input().split()) if a==1: print(0) continue ans=0 for i in range(b+1,a+1): ans+=dp[i] # print(dp[:20]) print(ans) #---------------------------------------------------------------------------------------- def nouse0(): # This is to save my code from plag due to use of FAST IO template in it. a=420 b=420 print(f'i am nitish{(a+b)//2}') def nouse1(): # This is to save my code from plag due to use of FAST IO template in it. a=420 b=420 print(f'i am nitish{(a+b)//2}') def nouse2(): # This is to save my code from plag due to use of FAST IO template in it. a=420 b=420 print(f'i am nitish{(a+b)//2}') # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = 'x' in file.mode or 'r' not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b'\n') + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode('ascii')) self.read = lambda: self.buffer.read().decode('ascii') self.readline = lambda: self.buffer.readline().decode('ascii') sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip('\r\n') def nouse3(): # This is to save my code from plag due to use of FAST IO template in it. a=420 b=420 print(f'i am nitish{(a+b)//2}') def nouse4(): # This is to save my code from plag due to use of FAST IO template in it. a=420 b=420 print(f'i am nitish{(a+b)//2}') def nouse5(): # This is to save my code from plag due to use of FAST IO template in it. a=420 b=420 print(f'i am nitish{(a+b)//2}') ```
instruction
0
54,369
19
108,738
No
output
1
54,369
19
108,739
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two soldiers are playing a game. At the beginning first of them chooses a positive integer n and gives it to the second soldier. Then the second one tries to make maximum possible number of rounds. Each round consists of choosing a positive integer x > 1, such that n is divisible by x and replacing n with n / x. When n becomes equal to 1 and there is no more possible valid moves the game is over and the score of the second soldier is equal to the number of rounds he performed. To make the game more interesting, first soldier chooses n of form a! / b! for some positive integer a and b (a β‰₯ b). Here by k! we denote the factorial of k that is defined as a product of all positive integers not large than k. What is the maximum possible score of the second soldier? Input First line of input consists of single integer t (1 ≀ t ≀ 1 000 000) denoting number of games soldiers play. Then follow t lines, each contains pair of integers a and b (1 ≀ b ≀ a ≀ 5 000 000) defining the value of n for a game. Output For each game output a maximum score that the second soldier can get. Examples Input 2 3 1 6 3 Output 2 5 Submitted Solution: ``` import math MAXN=5*(10**6)+1 spf=[i for i in range(MAXN)] def create(MAXN,spf): for i in range(4, MAXN, 2): spf[i] = 2 for i in range(3, math.ceil(math.sqrt(MAXN))): if (spf[i] == i): for j in range(i * i, MAXN, i): if (spf[j] == j): spf[j] = i def factors(x): count=0 while (x != 1): count+=1 x = x // spf[x] return count for _ in range(int(input())): a,b=map(int,input().split()) create(b+1,spf) ans=0 for i in range(b+1,a+1): ans+=factors(i) print(ans) ```
instruction
0
54,370
19
108,740
No
output
1
54,370
19
108,741
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two soldiers are playing a game. At the beginning first of them chooses a positive integer n and gives it to the second soldier. Then the second one tries to make maximum possible number of rounds. Each round consists of choosing a positive integer x > 1, such that n is divisible by x and replacing n with n / x. When n becomes equal to 1 and there is no more possible valid moves the game is over and the score of the second soldier is equal to the number of rounds he performed. To make the game more interesting, first soldier chooses n of form a! / b! for some positive integer a and b (a β‰₯ b). Here by k! we denote the factorial of k that is defined as a product of all positive integers not large than k. What is the maximum possible score of the second soldier? Input First line of input consists of single integer t (1 ≀ t ≀ 1 000 000) denoting number of games soldiers play. Then follow t lines, each contains pair of integers a and b (1 ≀ b ≀ a ≀ 5 000 000) defining the value of n for a game. Output For each game output a maximum score that the second soldier can get. Examples Input 2 3 1 6 3 Output 2 5 Submitted Solution: ``` def fat2(m, n): total = 1 while(m > n): #print("m: " + str(m)) #print("total:" + str(total)) total *= m m = m - 1 return total rodadas = int(input()) for i in range(rodadas): a, b = [*map(int, input().split())] n = fat2(a, b) print(n) score = 0 #divisores = getDivisores(n) #print(divisores) while(n > 1): menorDiv = 2 while(n % menorDiv != 0): menorDiv = menorDiv + 1 n = n // menorDiv score += 1 print(score) ```
instruction
0
54,371
19
108,742
No
output
1
54,371
19
108,743
Provide tags and a correct Python 3 solution for this coding contest problem. Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are n players (including Limak himself) and right now all of them have bids on the table. i-th of them has bid with size ai dollars. Each player can double his bid any number of times and triple his bid any number of times. The casino has a great jackpot for making all bids equal. Is it possible that Limak and his friends will win a jackpot? Input First line of input contains an integer n (2 ≀ n ≀ 105), the number of players. The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the bids of players. Output Print "Yes" (without the quotes) if players can make their bids become equal, or "No" otherwise. Examples Input 4 75 150 75 50 Output Yes Input 3 100 150 250 Output No Note In the first sample test first and third players should double their bids twice, second player should double his bid once and fourth player should both double and triple his bid. It can be shown that in the second sample test there is no way to make all bids equal.
instruction
0
54,372
19
108,744
Tags: implementation, math, number theory Correct Solution: ``` def div23(a): while (a % 2 == 0): a //= 2 while (a % 3 == 0): a //= 3 return a n = int(input()) s = [int(i) for i in input().split(' ')] a = div23(s[0]) i = 1 while i < len(s): if (a != div23(s[i])): break i += 1 if i == len(s): print("Yes") else: print("No") ```
output
1
54,372
19
108,745
Provide tags and a correct Python 3 solution for this coding contest problem. Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are n players (including Limak himself) and right now all of them have bids on the table. i-th of them has bid with size ai dollars. Each player can double his bid any number of times and triple his bid any number of times. The casino has a great jackpot for making all bids equal. Is it possible that Limak and his friends will win a jackpot? Input First line of input contains an integer n (2 ≀ n ≀ 105), the number of players. The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the bids of players. Output Print "Yes" (without the quotes) if players can make their bids become equal, or "No" otherwise. Examples Input 4 75 150 75 50 Output Yes Input 3 100 150 250 Output No Note In the first sample test first and third players should double their bids twice, second player should double his bid once and fourth player should both double and triple his bid. It can be shown that in the second sample test there is no way to make all bids equal.
instruction
0
54,373
19
108,746
Tags: implementation, math, number theory Correct Solution: ``` def hello(a): res = sol(arr[0]) for i in arr[1:]: re = sol(i) if re != res: return False return True def sol(a): while a % 2 == 0: a //= 2 while a % 3 == 0: a //= 3 return a n = int(input()) arr = list(map(int, input().split(' '))) if hello(arr): print('YES') else: print('NO') ```
output
1
54,373
19
108,747
Provide tags and a correct Python 3 solution for this coding contest problem. Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are n players (including Limak himself) and right now all of them have bids on the table. i-th of them has bid with size ai dollars. Each player can double his bid any number of times and triple his bid any number of times. The casino has a great jackpot for making all bids equal. Is it possible that Limak and his friends will win a jackpot? Input First line of input contains an integer n (2 ≀ n ≀ 105), the number of players. The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the bids of players. Output Print "Yes" (without the quotes) if players can make their bids become equal, or "No" otherwise. Examples Input 4 75 150 75 50 Output Yes Input 3 100 150 250 Output No Note In the first sample test first and third players should double their bids twice, second player should double his bid once and fourth player should both double and triple his bid. It can be shown that in the second sample test there is no way to make all bids equal.
instruction
0
54,374
19
108,748
Tags: implementation, math, number theory Correct Solution: ``` n = int(input()) a = list(map(int, input().split())) for i in range(n): while a[i] % 2 == 0: a[i] //= 2 while a[i] % 3 == 0: a[i] //= 3 if min(a) == max(a): print('Yes') else: print('No') ```
output
1
54,374
19
108,749
Provide tags and a correct Python 3 solution for this coding contest problem. Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are n players (including Limak himself) and right now all of them have bids on the table. i-th of them has bid with size ai dollars. Each player can double his bid any number of times and triple his bid any number of times. The casino has a great jackpot for making all bids equal. Is it possible that Limak and his friends will win a jackpot? Input First line of input contains an integer n (2 ≀ n ≀ 105), the number of players. The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the bids of players. Output Print "Yes" (without the quotes) if players can make their bids become equal, or "No" otherwise. Examples Input 4 75 150 75 50 Output Yes Input 3 100 150 250 Output No Note In the first sample test first and third players should double their bids twice, second player should double his bid once and fourth player should both double and triple his bid. It can be shown that in the second sample test there is no way to make all bids equal.
instruction
0
54,375
19
108,750
Tags: implementation, math, number theory Correct Solution: ``` import sys n = int(input()) an = list(map(int, sys.stdin.readline().split())) ans = True for i in range(n): while an[i] % 2 == 0: an[i] = int(an[i] / 2) while an[i] % 3 == 0: an[i] = int(an[i] / 3) if i != 0 and an[i] != an[0]: ans = False break if ans: print("Yes") else: print("No") ```
output
1
54,375
19
108,751
Provide tags and a correct Python 3 solution for this coding contest problem. Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are n players (including Limak himself) and right now all of them have bids on the table. i-th of them has bid with size ai dollars. Each player can double his bid any number of times and triple his bid any number of times. The casino has a great jackpot for making all bids equal. Is it possible that Limak and his friends will win a jackpot? Input First line of input contains an integer n (2 ≀ n ≀ 105), the number of players. The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the bids of players. Output Print "Yes" (without the quotes) if players can make their bids become equal, or "No" otherwise. Examples Input 4 75 150 75 50 Output Yes Input 3 100 150 250 Output No Note In the first sample test first and third players should double their bids twice, second player should double his bid once and fourth player should both double and triple his bid. It can be shown that in the second sample test there is no way to make all bids equal.
instruction
0
54,376
19
108,752
Tags: implementation, math, number theory Correct Solution: ``` n = input() n = int(n) j = 0 f = input().split() f = [int(i) for i in f] for i in range(len(f)): while f[i] % 2 == 0: f[i] /= 2 while f[i] % 3 == 0: f[i] /= 3 for i in f: if i != f[0]: j = 1 print("No") break if j == 0: print("Yes") ```
output
1
54,376
19
108,753
Provide tags and a correct Python 3 solution for this coding contest problem. Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are n players (including Limak himself) and right now all of them have bids on the table. i-th of them has bid with size ai dollars. Each player can double his bid any number of times and triple his bid any number of times. The casino has a great jackpot for making all bids equal. Is it possible that Limak and his friends will win a jackpot? Input First line of input contains an integer n (2 ≀ n ≀ 105), the number of players. The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the bids of players. Output Print "Yes" (without the quotes) if players can make their bids become equal, or "No" otherwise. Examples Input 4 75 150 75 50 Output Yes Input 3 100 150 250 Output No Note In the first sample test first and third players should double their bids twice, second player should double his bid once and fourth player should both double and triple his bid. It can be shown that in the second sample test there is no way to make all bids equal.
instruction
0
54,377
19
108,754
Tags: implementation, math, number theory Correct Solution: ``` import sys from functools import lru_cache, cmp_to_key from heapq import merge, heapify, heappop, heappush from math import * from collections import defaultdict as dd, deque, Counter as C from itertools import combinations as comb, permutations as perm from bisect import bisect_left as bl, bisect_right as br, bisect, insort from time import perf_counter from fractions import Fraction import copy from copy import deepcopy import time starttime = time.time() mod = int(pow(10, 9) + 7) mod2 = 998244353 def data(): return sys.stdin.readline().strip() def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end) def L(): return list(sp()) def sl(): return list(ssp()) def sp(): return map(int, data().split()) def ssp(): return map(str, data().split()) def l1d(n, val=0): return [val for i in range(n)] def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)] try: # sys.setrecursionlimit(int(pow(10,6))) sys.stdin = open("input.txt", "r") # sys.stdout = open("../output.txt", "w") except: pass def pmat(A): for ele in A: print(*ele,end="\n") x=0 n=L()[0] A=L() for ele in A: x=gcd(x,ele) for i in range(n): A[i]//=x x=set(A) for ele in x: while(ele%3==0): ele//=3 while(ele%2==0): ele//=2 if ele !=1: print("No") exit() print("Yes") endtime = time.time() # print(f"Runtime of the program is {endtime - starttime}") ```
output
1
54,377
19
108,755
Provide tags and a correct Python 3 solution for this coding contest problem. Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are n players (including Limak himself) and right now all of them have bids on the table. i-th of them has bid with size ai dollars. Each player can double his bid any number of times and triple his bid any number of times. The casino has a great jackpot for making all bids equal. Is it possible that Limak and his friends will win a jackpot? Input First line of input contains an integer n (2 ≀ n ≀ 105), the number of players. The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the bids of players. Output Print "Yes" (without the quotes) if players can make their bids become equal, or "No" otherwise. Examples Input 4 75 150 75 50 Output Yes Input 3 100 150 250 Output No Note In the first sample test first and third players should double their bids twice, second player should double his bid once and fourth player should both double and triple his bid. It can be shown that in the second sample test there is no way to make all bids equal.
instruction
0
54,378
19
108,756
Tags: implementation, math, number theory Correct Solution: ``` def change(n): while n and not n % 2: n /= 2 while n and not n % 3: n /= 3 return n n = int(input()) a = [int(i) for i in input().split()] a = [change(i) for i in a] print("Yes" if len(set(a)) == 1 else "No") ```
output
1
54,378
19
108,757
Provide tags and a correct Python 3 solution for this coding contest problem. Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are n players (including Limak himself) and right now all of them have bids on the table. i-th of them has bid with size ai dollars. Each player can double his bid any number of times and triple his bid any number of times. The casino has a great jackpot for making all bids equal. Is it possible that Limak and his friends will win a jackpot? Input First line of input contains an integer n (2 ≀ n ≀ 105), the number of players. The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the bids of players. Output Print "Yes" (without the quotes) if players can make their bids become equal, or "No" otherwise. Examples Input 4 75 150 75 50 Output Yes Input 3 100 150 250 Output No Note In the first sample test first and third players should double their bids twice, second player should double his bid once and fourth player should both double and triple his bid. It can be shown that in the second sample test there is no way to make all bids equal.
instruction
0
54,379
19
108,758
Tags: implementation, math, number theory Correct Solution: ``` N = int(input()) s = input().split(' ') a = [int(x) for x in s] for i in range(N): while a[i]%2 == 0: a[i] //= 2 while a[i]%3 == 0: a[i] //= 3 ans = True for i in range(1,N): if a[i] != a[i-1]: ans = False break if ans: print("Yes") else: print("No") ```
output
1
54,379
19
108,759
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are n players (including Limak himself) and right now all of them have bids on the table. i-th of them has bid with size ai dollars. Each player can double his bid any number of times and triple his bid any number of times. The casino has a great jackpot for making all bids equal. Is it possible that Limak and his friends will win a jackpot? Input First line of input contains an integer n (2 ≀ n ≀ 105), the number of players. The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the bids of players. Output Print "Yes" (without the quotes) if players can make their bids become equal, or "No" otherwise. Examples Input 4 75 150 75 50 Output Yes Input 3 100 150 250 Output No Note In the first sample test first and third players should double their bids twice, second player should double his bid once and fourth player should both double and triple his bid. It can be shown that in the second sample test there is no way to make all bids equal. Submitted Solution: ``` input() a=0 for t in map(int,input().split()): while t%2==0:t//=2 while t%3==0:t//=3 if not a:a=t elif a!=t:print('No');exit() print('Yes') ```
instruction
0
54,380
19
108,760
Yes
output
1
54,380
19
108,761
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are n players (including Limak himself) and right now all of them have bids on the table. i-th of them has bid with size ai dollars. Each player can double his bid any number of times and triple his bid any number of times. The casino has a great jackpot for making all bids equal. Is it possible that Limak and his friends will win a jackpot? Input First line of input contains an integer n (2 ≀ n ≀ 105), the number of players. The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the bids of players. Output Print "Yes" (without the quotes) if players can make their bids become equal, or "No" otherwise. Examples Input 4 75 150 75 50 Output Yes Input 3 100 150 250 Output No Note In the first sample test first and third players should double their bids twice, second player should double his bid once and fourth player should both double and triple his bid. It can be shown that in the second sample test there is no way to make all bids equal. Submitted Solution: ``` from sys import stdin,stdout from collections import Counter from math import ceil from bisect import bisect_left from bisect import bisect_right import math ai = lambda: list(map(int, stdin.readline().split())) ei = lambda: map(int, stdin.readline().split()) ip = lambda: int(stdin.readline().strip()) n = ip() li = ai() for i in range(n): while li[i] % 2==0: li[i] //= 2 while li[i] %3 == 0:li[i] //= 3 for i in range(1,n): if li[i] != li[0]: exit(print('No')) print('Yes') ```
instruction
0
54,381
19
108,762
Yes
output
1
54,381
19
108,763
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are n players (including Limak himself) and right now all of them have bids on the table. i-th of them has bid with size ai dollars. Each player can double his bid any number of times and triple his bid any number of times. The casino has a great jackpot for making all bids equal. Is it possible that Limak and his friends will win a jackpot? Input First line of input contains an integer n (2 ≀ n ≀ 105), the number of players. The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the bids of players. Output Print "Yes" (without the quotes) if players can make their bids become equal, or "No" otherwise. Examples Input 4 75 150 75 50 Output Yes Input 3 100 150 250 Output No Note In the first sample test first and third players should double their bids twice, second player should double his bid once and fourth player should both double and triple his bid. It can be shown that in the second sample test there is no way to make all bids equal. Submitted Solution: ``` n = int(input()) a = list(map(int, input().split())) val = -1 for i in range(n): while a[i] % 2 == 0: a[i] //= 2 while a[i] % 3 == 0: a[i] //= 3 if val == -1: val = a[i] elif val != a[i]: print('No') exit(0) print('Yes') ```
instruction
0
54,382
19
108,764
Yes
output
1
54,382
19
108,765
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are n players (including Limak himself) and right now all of them have bids on the table. i-th of them has bid with size ai dollars. Each player can double his bid any number of times and triple his bid any number of times. The casino has a great jackpot for making all bids equal. Is it possible that Limak and his friends will win a jackpot? Input First line of input contains an integer n (2 ≀ n ≀ 105), the number of players. The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the bids of players. Output Print "Yes" (without the quotes) if players can make their bids become equal, or "No" otherwise. Examples Input 4 75 150 75 50 Output Yes Input 3 100 150 250 Output No Note In the first sample test first and third players should double their bids twice, second player should double his bid once and fourth player should both double and triple his bid. It can be shown that in the second sample test there is no way to make all bids equal. Submitted Solution: ``` #in the name of god #Mr_Rubick input() a=0 for t in map(int,input().split()): while t%2==0:t//=2 while t%3==0:t//=3 if not a:a=t elif a!=t:print('No');exit() print('Yes') ```
instruction
0
54,383
19
108,766
Yes
output
1
54,383
19
108,767
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are n players (including Limak himself) and right now all of them have bids on the table. i-th of them has bid with size ai dollars. Each player can double his bid any number of times and triple his bid any number of times. The casino has a great jackpot for making all bids equal. Is it possible that Limak and his friends will win a jackpot? Input First line of input contains an integer n (2 ≀ n ≀ 105), the number of players. The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the bids of players. Output Print "Yes" (without the quotes) if players can make their bids become equal, or "No" otherwise. Examples Input 4 75 150 75 50 Output Yes Input 3 100 150 250 Output No Note In the first sample test first and third players should double their bids twice, second player should double his bid once and fourth player should both double and triple his bid. It can be shown that in the second sample test there is no way to make all bids equal. Submitted Solution: ``` n=int(input()) li=list(map(int,input().split())) li.sort(reverse=True) a=li[0] d=0 for i in range(1,n): if(a%li[i]!=0): d=1 break else: if(a//li[i]>3): d=1 break if(d==0): print("Yes") else: print("No") ```
instruction
0
54,384
19
108,768
No
output
1
54,384
19
108,769
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are n players (including Limak himself) and right now all of them have bids on the table. i-th of them has bid with size ai dollars. Each player can double his bid any number of times and triple his bid any number of times. The casino has a great jackpot for making all bids equal. Is it possible that Limak and his friends will win a jackpot? Input First line of input contains an integer n (2 ≀ n ≀ 105), the number of players. The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the bids of players. Output Print "Yes" (without the quotes) if players can make their bids become equal, or "No" otherwise. Examples Input 4 75 150 75 50 Output Yes Input 3 100 150 250 Output No Note In the first sample test first and third players should double their bids twice, second player should double his bid once and fourth player should both double and triple his bid. It can be shown that in the second sample test there is no way to make all bids equal. Submitted Solution: ``` def remove_int(n, divisors): res = n for d in divisors: if res % d == 0: res /= d return res n = int(input()) bids = list(map(int, input().split())) remaining_bids = [remove_int(bid, [2, 3]) for bid in bids] print('Yes' if len(set(remaining_bids)) == 1 else 'No') ```
instruction
0
54,385
19
108,770
No
output
1
54,385
19
108,771
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are n players (including Limak himself) and right now all of them have bids on the table. i-th of them has bid with size ai dollars. Each player can double his bid any number of times and triple his bid any number of times. The casino has a great jackpot for making all bids equal. Is it possible that Limak and his friends will win a jackpot? Input First line of input contains an integer n (2 ≀ n ≀ 105), the number of players. The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the bids of players. Output Print "Yes" (without the quotes) if players can make their bids become equal, or "No" otherwise. Examples Input 4 75 150 75 50 Output Yes Input 3 100 150 250 Output No Note In the first sample test first and third players should double their bids twice, second player should double his bid once and fourth player should both double and triple his bid. It can be shown that in the second sample test there is no way to make all bids equal. Submitted Solution: ``` def find_lcm(num1, num2): if(num1>num2): num = num1 den = num2 else: num = num2 den = num1 rem = num % den while(rem != 0): num = den den = rem rem = num % den gcd = den lcm = int(int(num1 * num2)/int(gcd)) return lcm n = int(input()) lst = list(map(int,input().split())) num1 = lst[0] num2 = lst[1] lcm = find_lcm(num1,num2) yo = "Yes" min1 = min(lst) for i in range(2, len(lst)): lcm = find_lcm(lcm, lst[i]) #print(lcm) while int(lcm) != 1: if lcm in lst: yo = "Yes" break elif lcm % 2 == 0: lcm /= 2 elif lcm % 3 == 0: lcm /= 3 else: yo = "No" break print(yo) ```
instruction
0
54,386
19
108,772
No
output
1
54,386
19
108,773
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are n players (including Limak himself) and right now all of them have bids on the table. i-th of them has bid with size ai dollars. Each player can double his bid any number of times and triple his bid any number of times. The casino has a great jackpot for making all bids equal. Is it possible that Limak and his friends will win a jackpot? Input First line of input contains an integer n (2 ≀ n ≀ 105), the number of players. The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the bids of players. Output Print "Yes" (without the quotes) if players can make their bids become equal, or "No" otherwise. Examples Input 4 75 150 75 50 Output Yes Input 3 100 150 250 Output No Note In the first sample test first and third players should double their bids twice, second player should double his bid once and fourth player should both double and triple his bid. It can be shown that in the second sample test there is no way to make all bids equal. Submitted Solution: ``` n = int(input()) import math t = list(map(int,input().split())) f = t[0] for k in range(n): f = math.gcd(f,t[k]) for j in range(n): t[j]//=f h=0 for j in t: if j%5==0 or j%7==0: print('No') h+=1 break if h==0: print('Yes') ```
instruction
0
54,387
19
108,774
No
output
1
54,387
19
108,775
Provide a correct Python 3 solution for this coding contest problem. A game is played on a strip consisting of N cells consecutively numbered from 1 to N. Alice has her token on cell A. Borys has his token on a different cell B. Players take turns, Alice moves first. The moving player must shift his or her token from its current cell X to the neighboring cell on the left, cell X-1, or on the right, cell X+1. Note that it's disallowed to move the token outside the strip or to the cell with the other player's token. In one turn, the token of the moving player must be shifted exactly once. The player who can't make a move loses, and the other player wins. Both players want to win. Who wins if they play optimally? Constraints * 2 \leq N \leq 100 * 1 \leq A < B \leq N * All input values are integers. Input Input is given from Standard Input in the following format: N A B Output Print `Alice` if Alice wins, `Borys` if Borys wins, and `Draw` if nobody wins. Examples Input 5 2 4 Output Alice Input 2 1 2 Output Borys Input 58 23 42 Output Borys
instruction
0
54,634
19
109,268
"Correct Solution: ``` n,a,b=map(int,input().split()) print("Alice" if (b-a+1)%2 else "Borys") ```
output
1
54,634
19
109,269
Provide a correct Python 3 solution for this coding contest problem. A game is played on a strip consisting of N cells consecutively numbered from 1 to N. Alice has her token on cell A. Borys has his token on a different cell B. Players take turns, Alice moves first. The moving player must shift his or her token from its current cell X to the neighboring cell on the left, cell X-1, or on the right, cell X+1. Note that it's disallowed to move the token outside the strip or to the cell with the other player's token. In one turn, the token of the moving player must be shifted exactly once. The player who can't make a move loses, and the other player wins. Both players want to win. Who wins if they play optimally? Constraints * 2 \leq N \leq 100 * 1 \leq A < B \leq N * All input values are integers. Input Input is given from Standard Input in the following format: N A B Output Print `Alice` if Alice wins, `Borys` if Borys wins, and `Draw` if nobody wins. Examples Input 5 2 4 Output Alice Input 2 1 2 Output Borys Input 58 23 42 Output Borys
instruction
0
54,635
19
109,270
"Correct Solution: ``` n,a,b = map(int, input().split()) print('Alice' if abs(a-b) % 2 == 0 else 'Borys') ```
output
1
54,635
19
109,271
Provide a correct Python 3 solution for this coding contest problem. A game is played on a strip consisting of N cells consecutively numbered from 1 to N. Alice has her token on cell A. Borys has his token on a different cell B. Players take turns, Alice moves first. The moving player must shift his or her token from its current cell X to the neighboring cell on the left, cell X-1, or on the right, cell X+1. Note that it's disallowed to move the token outside the strip or to the cell with the other player's token. In one turn, the token of the moving player must be shifted exactly once. The player who can't make a move loses, and the other player wins. Both players want to win. Who wins if they play optimally? Constraints * 2 \leq N \leq 100 * 1 \leq A < B \leq N * All input values are integers. Input Input is given from Standard Input in the following format: N A B Output Print `Alice` if Alice wins, `Borys` if Borys wins, and `Draw` if nobody wins. Examples Input 5 2 4 Output Alice Input 2 1 2 Output Borys Input 58 23 42 Output Borys
instruction
0
54,636
19
109,272
"Correct Solution: ``` n,a,b = map(int,input().split()) print("Alice" if (b-a)%2==0 else "Borys") ```
output
1
54,636
19
109,273
Provide a correct Python 3 solution for this coding contest problem. A game is played on a strip consisting of N cells consecutively numbered from 1 to N. Alice has her token on cell A. Borys has his token on a different cell B. Players take turns, Alice moves first. The moving player must shift his or her token from its current cell X to the neighboring cell on the left, cell X-1, or on the right, cell X+1. Note that it's disallowed to move the token outside the strip or to the cell with the other player's token. In one turn, the token of the moving player must be shifted exactly once. The player who can't make a move loses, and the other player wins. Both players want to win. Who wins if they play optimally? Constraints * 2 \leq N \leq 100 * 1 \leq A < B \leq N * All input values are integers. Input Input is given from Standard Input in the following format: N A B Output Print `Alice` if Alice wins, `Borys` if Borys wins, and `Draw` if nobody wins. Examples Input 5 2 4 Output Alice Input 2 1 2 Output Borys Input 58 23 42 Output Borys
instruction
0
54,637
19
109,274
"Correct Solution: ``` n, a, b = map(int, input().split()) d = b - a print('Alice' if d % 2 == 0 else 'Borys') ```
output
1
54,637
19
109,275
Provide a correct Python 3 solution for this coding contest problem. A game is played on a strip consisting of N cells consecutively numbered from 1 to N. Alice has her token on cell A. Borys has his token on a different cell B. Players take turns, Alice moves first. The moving player must shift his or her token from its current cell X to the neighboring cell on the left, cell X-1, or on the right, cell X+1. Note that it's disallowed to move the token outside the strip or to the cell with the other player's token. In one turn, the token of the moving player must be shifted exactly once. The player who can't make a move loses, and the other player wins. Both players want to win. Who wins if they play optimally? Constraints * 2 \leq N \leq 100 * 1 \leq A < B \leq N * All input values are integers. Input Input is given from Standard Input in the following format: N A B Output Print `Alice` if Alice wins, `Borys` if Borys wins, and `Draw` if nobody wins. Examples Input 5 2 4 Output Alice Input 2 1 2 Output Borys Input 58 23 42 Output Borys
instruction
0
54,638
19
109,276
"Correct Solution: ``` N, A, B = map(int, input().split()) print("Borys" if (A-B)%2==1 else "Alice") ```
output
1
54,638
19
109,277
Provide a correct Python 3 solution for this coding contest problem. A game is played on a strip consisting of N cells consecutively numbered from 1 to N. Alice has her token on cell A. Borys has his token on a different cell B. Players take turns, Alice moves first. The moving player must shift his or her token from its current cell X to the neighboring cell on the left, cell X-1, or on the right, cell X+1. Note that it's disallowed to move the token outside the strip or to the cell with the other player's token. In one turn, the token of the moving player must be shifted exactly once. The player who can't make a move loses, and the other player wins. Both players want to win. Who wins if they play optimally? Constraints * 2 \leq N \leq 100 * 1 \leq A < B \leq N * All input values are integers. Input Input is given from Standard Input in the following format: N A B Output Print `Alice` if Alice wins, `Borys` if Borys wins, and `Draw` if nobody wins. Examples Input 5 2 4 Output Alice Input 2 1 2 Output Borys Input 58 23 42 Output Borys
instruction
0
54,639
19
109,278
"Correct Solution: ``` n,a,b = map(int,input().split()) if abs(a-b)%2 : print('Borys') else: print('Alice') ```
output
1
54,639
19
109,279
Provide a correct Python 3 solution for this coding contest problem. A game is played on a strip consisting of N cells consecutively numbered from 1 to N. Alice has her token on cell A. Borys has his token on a different cell B. Players take turns, Alice moves first. The moving player must shift his or her token from its current cell X to the neighboring cell on the left, cell X-1, or on the right, cell X+1. Note that it's disallowed to move the token outside the strip or to the cell with the other player's token. In one turn, the token of the moving player must be shifted exactly once. The player who can't make a move loses, and the other player wins. Both players want to win. Who wins if they play optimally? Constraints * 2 \leq N \leq 100 * 1 \leq A < B \leq N * All input values are integers. Input Input is given from Standard Input in the following format: N A B Output Print `Alice` if Alice wins, `Borys` if Borys wins, and `Draw` if nobody wins. Examples Input 5 2 4 Output Alice Input 2 1 2 Output Borys Input 58 23 42 Output Borys
instruction
0
54,640
19
109,280
"Correct Solution: ``` n,a,b=map(int,input().split()) if (b-a+1)%2==0: print('Borys') else: print('Alice') ```
output
1
54,640
19
109,281
Provide a correct Python 3 solution for this coding contest problem. A game is played on a strip consisting of N cells consecutively numbered from 1 to N. Alice has her token on cell A. Borys has his token on a different cell B. Players take turns, Alice moves first. The moving player must shift his or her token from its current cell X to the neighboring cell on the left, cell X-1, or on the right, cell X+1. Note that it's disallowed to move the token outside the strip or to the cell with the other player's token. In one turn, the token of the moving player must be shifted exactly once. The player who can't make a move loses, and the other player wins. Both players want to win. Who wins if they play optimally? Constraints * 2 \leq N \leq 100 * 1 \leq A < B \leq N * All input values are integers. Input Input is given from Standard Input in the following format: N A B Output Print `Alice` if Alice wins, `Borys` if Borys wins, and `Draw` if nobody wins. Examples Input 5 2 4 Output Alice Input 2 1 2 Output Borys Input 58 23 42 Output Borys
instruction
0
54,641
19
109,282
"Correct Solution: ``` n,a,b=map(int,input().split()) if abs(a-b)%2!=0: print("Borys") else: print("Alice") ```
output
1
54,641
19
109,283
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A game is played on a strip consisting of N cells consecutively numbered from 1 to N. Alice has her token on cell A. Borys has his token on a different cell B. Players take turns, Alice moves first. The moving player must shift his or her token from its current cell X to the neighboring cell on the left, cell X-1, or on the right, cell X+1. Note that it's disallowed to move the token outside the strip or to the cell with the other player's token. In one turn, the token of the moving player must be shifted exactly once. The player who can't make a move loses, and the other player wins. Both players want to win. Who wins if they play optimally? Constraints * 2 \leq N \leq 100 * 1 \leq A < B \leq N * All input values are integers. Input Input is given from Standard Input in the following format: N A B Output Print `Alice` if Alice wins, `Borys` if Borys wins, and `Draw` if nobody wins. Examples Input 5 2 4 Output Alice Input 2 1 2 Output Borys Input 58 23 42 Output Borys Submitted Solution: ``` n, a, b = list(map(int, input().split())) print(['Alice','Borys'][(b-a)%2]) ```
instruction
0
54,642
19
109,284
Yes
output
1
54,642
19
109,285
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A game is played on a strip consisting of N cells consecutively numbered from 1 to N. Alice has her token on cell A. Borys has his token on a different cell B. Players take turns, Alice moves first. The moving player must shift his or her token from its current cell X to the neighboring cell on the left, cell X-1, or on the right, cell X+1. Note that it's disallowed to move the token outside the strip or to the cell with the other player's token. In one turn, the token of the moving player must be shifted exactly once. The player who can't make a move loses, and the other player wins. Both players want to win. Who wins if they play optimally? Constraints * 2 \leq N \leq 100 * 1 \leq A < B \leq N * All input values are integers. Input Input is given from Standard Input in the following format: N A B Output Print `Alice` if Alice wins, `Borys` if Borys wins, and `Draw` if nobody wins. Examples Input 5 2 4 Output Alice Input 2 1 2 Output Borys Input 58 23 42 Output Borys Submitted Solution: ``` N,A,B=map(int,input().split()) print(["Borys","Alice"][(B-A)%2==0]) ```
instruction
0
54,643
19
109,286
Yes
output
1
54,643
19
109,287
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A game is played on a strip consisting of N cells consecutively numbered from 1 to N. Alice has her token on cell A. Borys has his token on a different cell B. Players take turns, Alice moves first. The moving player must shift his or her token from its current cell X to the neighboring cell on the left, cell X-1, or on the right, cell X+1. Note that it's disallowed to move the token outside the strip or to the cell with the other player's token. In one turn, the token of the moving player must be shifted exactly once. The player who can't make a move loses, and the other player wins. Both players want to win. Who wins if they play optimally? Constraints * 2 \leq N \leq 100 * 1 \leq A < B \leq N * All input values are integers. Input Input is given from Standard Input in the following format: N A B Output Print `Alice` if Alice wins, `Borys` if Borys wins, and `Draw` if nobody wins. Examples Input 5 2 4 Output Alice Input 2 1 2 Output Borys Input 58 23 42 Output Borys Submitted Solution: ``` N,A,B = list(map(int,input().split())) if (B-A)%2==1: print("Borys") else: print("Alice") ```
instruction
0
54,644
19
109,288
Yes
output
1
54,644
19
109,289
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A game is played on a strip consisting of N cells consecutively numbered from 1 to N. Alice has her token on cell A. Borys has his token on a different cell B. Players take turns, Alice moves first. The moving player must shift his or her token from its current cell X to the neighboring cell on the left, cell X-1, or on the right, cell X+1. Note that it's disallowed to move the token outside the strip or to the cell with the other player's token. In one turn, the token of the moving player must be shifted exactly once. The player who can't make a move loses, and the other player wins. Both players want to win. Who wins if they play optimally? Constraints * 2 \leq N \leq 100 * 1 \leq A < B \leq N * All input values are integers. Input Input is given from Standard Input in the following format: N A B Output Print `Alice` if Alice wins, `Borys` if Borys wins, and `Draw` if nobody wins. Examples Input 5 2 4 Output Alice Input 2 1 2 Output Borys Input 58 23 42 Output Borys Submitted Solution: ``` n, a, b = map(int, input().split()) d = b - a - 1 print("Alice") if d % 2 else print("Borys") ```
instruction
0
54,645
19
109,290
Yes
output
1
54,645
19
109,291
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A game is played on a strip consisting of N cells consecutively numbered from 1 to N. Alice has her token on cell A. Borys has his token on a different cell B. Players take turns, Alice moves first. The moving player must shift his or her token from its current cell X to the neighboring cell on the left, cell X-1, or on the right, cell X+1. Note that it's disallowed to move the token outside the strip or to the cell with the other player's token. In one turn, the token of the moving player must be shifted exactly once. The player who can't make a move loses, and the other player wins. Both players want to win. Who wins if they play optimally? Constraints * 2 \leq N \leq 100 * 1 \leq A < B \leq N * All input values are integers. Input Input is given from Standard Input in the following format: N A B Output Print `Alice` if Alice wins, `Borys` if Borys wins, and `Draw` if nobody wins. Examples Input 5 2 4 Output Alice Input 2 1 2 Output Borys Input 58 23 42 Output Borys Submitted Solution: ``` nums = [int(i) for i in input().split()] point = nums[0] alice = nums[1] borys = nums[2] if borys - alice == 1: print("Borys") elif borys - alice == 2: print("Alice") elif borys - alice > 2 and (borys - alice) % 2 == 1: print("Alice") elif borys - alice > 2 and(borys - alice) % 2 == 0: print("Borys") ```
instruction
0
54,646
19
109,292
No
output
1
54,646
19
109,293
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A game is played on a strip consisting of N cells consecutively numbered from 1 to N. Alice has her token on cell A. Borys has his token on a different cell B. Players take turns, Alice moves first. The moving player must shift his or her token from its current cell X to the neighboring cell on the left, cell X-1, or on the right, cell X+1. Note that it's disallowed to move the token outside the strip or to the cell with the other player's token. In one turn, the token of the moving player must be shifted exactly once. The player who can't make a move loses, and the other player wins. Both players want to win. Who wins if they play optimally? Constraints * 2 \leq N \leq 100 * 1 \leq A < B \leq N * All input values are integers. Input Input is given from Standard Input in the following format: N A B Output Print `Alice` if Alice wins, `Borys` if Borys wins, and `Draw` if nobody wins. Examples Input 5 2 4 Output Alice Input 2 1 2 Output Borys Input 58 23 42 Output Borys Submitted Solution: ``` n, a, b = [int(i) for i in input().splti(' ')] print('Alice' if abs(a-b) % 2 == 0 else 'Borys') ```
instruction
0
54,647
19
109,294
No
output
1
54,647
19
109,295
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A game is played on a strip consisting of N cells consecutively numbered from 1 to N. Alice has her token on cell A. Borys has his token on a different cell B. Players take turns, Alice moves first. The moving player must shift his or her token from its current cell X to the neighboring cell on the left, cell X-1, or on the right, cell X+1. Note that it's disallowed to move the token outside the strip or to the cell with the other player's token. In one turn, the token of the moving player must be shifted exactly once. The player who can't make a move loses, and the other player wins. Both players want to win. Who wins if they play optimally? Constraints * 2 \leq N \leq 100 * 1 \leq A < B \leq N * All input values are integers. Input Input is given from Standard Input in the following format: N A B Output Print `Alice` if Alice wins, `Borys` if Borys wins, and `Draw` if nobody wins. Examples Input 5 2 4 Output Alice Input 2 1 2 Output Borys Input 58 23 42 Output Borys Submitted Solution: ``` N,A,B = map(int,input().split()) if A == 1 and B == 2: print("Borys") exit() if (A == N-2 or A == N-1) and B == N: print("Alice") exit() if (B-A)%2 == 0 and A%2 == 1: print("Alice") else: print("Borys") ```
instruction
0
54,648
19
109,296
No
output
1
54,648
19
109,297
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A game is played on a strip consisting of N cells consecutively numbered from 1 to N. Alice has her token on cell A. Borys has his token on a different cell B. Players take turns, Alice moves first. The moving player must shift his or her token from its current cell X to the neighboring cell on the left, cell X-1, or on the right, cell X+1. Note that it's disallowed to move the token outside the strip or to the cell with the other player's token. In one turn, the token of the moving player must be shifted exactly once. The player who can't make a move loses, and the other player wins. Both players want to win. Who wins if they play optimally? Constraints * 2 \leq N \leq 100 * 1 \leq A < B \leq N * All input values are integers. Input Input is given from Standard Input in the following format: N A B Output Print `Alice` if Alice wins, `Borys` if Borys wins, and `Draw` if nobody wins. Examples Input 5 2 4 Output Alice Input 2 1 2 Output Borys Input 58 23 42 Output Borys Submitted Solution: ``` N, A, B = map(int, input().split()) if (B - A) % 2 == 0: print('Borys') else: print('Alice') ```
instruction
0
54,649
19
109,298
No
output
1
54,649
19
109,299
Provide a correct Python 3 solution for this coding contest problem. Your company’s next product will be a new game, which is a three-dimensional variant of the classic game β€œTic-Tac-Toe”. Two players place balls in a three-dimensional space (board), and try to make a sequence of a certain length. People believe that it is fun to play the game, but they still cannot fix the values of some parameters of the game. For example, what size of the board makes the game most exciting? Parameters currently under discussion are the board size (we call it n in the following) and the length of the sequence (m). In order to determine these parameter values, you are requested to write a computer simulator of the game. You can see several snapshots of the game in Figures 1-3. These figures correspond to the three datasets given in the Sample Input. <image> Figure 1: A game with n = m = 3 Here are the precise rules of the game. 1. Two players, Black and White, play alternately. Black plays first. 2. There are n Γ— n vertical pegs. Each peg can accommodate up to n balls. A peg can be specified by its x- and y-coordinates (1 ≀ x, y ≀ n). A ball on a peg can be specified by its z-coordinate (1 ≀ z ≀ n). At the beginning of a game, there are no balls on any of the pegs. <image> Figure 2: A game with n = m = 3 (White made a 3-sequence before Black) 3. On his turn, a player chooses one of n Γ— n pegs, and puts a ball of his color onto the peg. The ball follows the law of gravity. That is, the ball stays just above the top-most ball on the same peg or on the floor (if there are no balls on the peg). Speaking differently, a player can choose x- and y-coordinates of the ball, but he cannot choose its z-coordinate. 4. The objective of the game is to make an m-sequence. If a player makes an m-sequence or longer of his color, he wins. An m-sequence is a row of m consecutive balls of the same color. For example, black balls in positions (5, 1, 2), (5, 2, 2) and (5, 3, 2) form a 3-sequence. A sequence can be horizontal, vertical, or diagonal. Precisely speaking, there are 13 possible directions to make a sequence, categorized as follows. <image> Figure 3: A game with n = 4, m = 3 (Black made two 4-sequences) (a) One-dimensional axes. For example, (3, 1, 2), (4, 1, 2) and (5, 1, 2) is a 3-sequence. There are three directions in this category. (b) Two-dimensional diagonals. For example, (2, 3, 1), (3, 3, 2) and (4, 3, 3) is a 3-sequence. There are six directions in this category. (c) Three-dimensional diagonals. For example, (5, 1, 3), (4, 2, 4) and (3, 3, 5) is a 3- sequence. There are four directions in this category. Note that we do not distinguish between opposite directions. As the evaluation process of the game, people have been playing the game several times changing the parameter values. You are given the records of these games. It is your job to write a computer program which determines the winner of each recorded game. Since it is difficult for a human to find three-dimensional sequences, players often do not notice the end of the game, and continue to play uselessly. In these cases, moves after the end of the game, i.e. after the winner is determined, should be ignored. For example, after a player won making an m-sequence, players may make additional m-sequences. In this case, all m-sequences but the first should be ignored, and the winner of the game is unchanged. A game does not necessarily end with the victory of one of the players. If there are no pegs left to put a ball on, the game ends with a draw. Moreover, people may quit a game before making any m-sequence. In such cases also, the game ends with a draw. Input The input consists of multiple datasets each corresponding to the record of a game. A dataset starts with a line containing three positive integers n, m, and p separated by a space. The relations 3 ≀ m ≀ n ≀ 7 and 1 ≀ p ≀ n3 hold between them. n and m are the parameter values of the game as described above. p is the number of moves in the game. The rest of the dataset is p lines each containing two positive integers x and y. Each of these lines describes a move, i.e. the player on turn puts his ball on the peg specified. You can assume that 1 ≀ x ≀ n and 1 ≀ y ≀ n. You can also assume that at most n balls are put on a peg throughout a game. The end of the input is indicated by a line with three zeros separated by a space. Output For each dataset, a line describing the winner and the number of moves until the game ends should be output. The winner is either β€œBlack” or β€œWhite”. A single space should be inserted between the winner and the number of moves. No other extra characters are allowed in the output. In case of a draw, the output line should be β€œDraw”. Example Input 3 3 3 1 1 1 1 1 1 3 3 7 2 2 1 3 1 1 2 3 2 1 3 3 3 1 4 3 15 1 1 2 2 1 1 3 3 3 3 1 1 3 3 3 3 4 4 1 1 4 4 4 4 4 4 4 1 2 2 0 0 0 Output Draw White 6 Black 15
instruction
0
54,731
19
109,462
"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 = 998244353 def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s, flush=True) def main(): rr = [] dd = [(1,0,0),(0,1,0),(0,0,1),(1,1,0),(1,0,1),(0,1,1),(1,1,1),(1,-1,0),(1,0,-1),(0,1,-1),(1,1,-1),(1,-1,1),(-1,1,1)] while True: n,m,p = LI() if n == 0 and m == 0 and p == 0: break a = [LI() for _ in range(p)] r = 'Draw' d = collections.defaultdict(int) for i in range(p): ci,cj = a[i] t = i % 2 + 1 ck = 0 for k in range(p): if d[(ci,cj,k)] == 0: d[(ci,cj,k)] = t ck = k break ff = False for di,dj,dk in dd: if ff: break for k in range(1-m,1): f = True for kk in range(k,k+m): ni = ci + di*kk nj = cj + dj*kk nk = ck + dk*kk if d[(ni,nj,nk)] != t: f = False break if f: ff = True break if ff: if t == 1: r = 'Black {}'.format(i+1) else: r = 'White {}'.format(i+1) break rr.append(r) return '\n'.join(map(str, rr)) print(main()) ```
output
1
54,731
19
109,463
Provide a correct Python 3 solution for this coding contest problem. Your company’s next product will be a new game, which is a three-dimensional variant of the classic game β€œTic-Tac-Toe”. Two players place balls in a three-dimensional space (board), and try to make a sequence of a certain length. People believe that it is fun to play the game, but they still cannot fix the values of some parameters of the game. For example, what size of the board makes the game most exciting? Parameters currently under discussion are the board size (we call it n in the following) and the length of the sequence (m). In order to determine these parameter values, you are requested to write a computer simulator of the game. You can see several snapshots of the game in Figures 1-3. These figures correspond to the three datasets given in the Sample Input. <image> Figure 1: A game with n = m = 3 Here are the precise rules of the game. 1. Two players, Black and White, play alternately. Black plays first. 2. There are n Γ— n vertical pegs. Each peg can accommodate up to n balls. A peg can be specified by its x- and y-coordinates (1 ≀ x, y ≀ n). A ball on a peg can be specified by its z-coordinate (1 ≀ z ≀ n). At the beginning of a game, there are no balls on any of the pegs. <image> Figure 2: A game with n = m = 3 (White made a 3-sequence before Black) 3. On his turn, a player chooses one of n Γ— n pegs, and puts a ball of his color onto the peg. The ball follows the law of gravity. That is, the ball stays just above the top-most ball on the same peg or on the floor (if there are no balls on the peg). Speaking differently, a player can choose x- and y-coordinates of the ball, but he cannot choose its z-coordinate. 4. The objective of the game is to make an m-sequence. If a player makes an m-sequence or longer of his color, he wins. An m-sequence is a row of m consecutive balls of the same color. For example, black balls in positions (5, 1, 2), (5, 2, 2) and (5, 3, 2) form a 3-sequence. A sequence can be horizontal, vertical, or diagonal. Precisely speaking, there are 13 possible directions to make a sequence, categorized as follows. <image> Figure 3: A game with n = 4, m = 3 (Black made two 4-sequences) (a) One-dimensional axes. For example, (3, 1, 2), (4, 1, 2) and (5, 1, 2) is a 3-sequence. There are three directions in this category. (b) Two-dimensional diagonals. For example, (2, 3, 1), (3, 3, 2) and (4, 3, 3) is a 3-sequence. There are six directions in this category. (c) Three-dimensional diagonals. For example, (5, 1, 3), (4, 2, 4) and (3, 3, 5) is a 3- sequence. There are four directions in this category. Note that we do not distinguish between opposite directions. As the evaluation process of the game, people have been playing the game several times changing the parameter values. You are given the records of these games. It is your job to write a computer program which determines the winner of each recorded game. Since it is difficult for a human to find three-dimensional sequences, players often do not notice the end of the game, and continue to play uselessly. In these cases, moves after the end of the game, i.e. after the winner is determined, should be ignored. For example, after a player won making an m-sequence, players may make additional m-sequences. In this case, all m-sequences but the first should be ignored, and the winner of the game is unchanged. A game does not necessarily end with the victory of one of the players. If there are no pegs left to put a ball on, the game ends with a draw. Moreover, people may quit a game before making any m-sequence. In such cases also, the game ends with a draw. Input The input consists of multiple datasets each corresponding to the record of a game. A dataset starts with a line containing three positive integers n, m, and p separated by a space. The relations 3 ≀ m ≀ n ≀ 7 and 1 ≀ p ≀ n3 hold between them. n and m are the parameter values of the game as described above. p is the number of moves in the game. The rest of the dataset is p lines each containing two positive integers x and y. Each of these lines describes a move, i.e. the player on turn puts his ball on the peg specified. You can assume that 1 ≀ x ≀ n and 1 ≀ y ≀ n. You can also assume that at most n balls are put on a peg throughout a game. The end of the input is indicated by a line with three zeros separated by a space. Output For each dataset, a line describing the winner and the number of moves until the game ends should be output. The winner is either β€œBlack” or β€œWhite”. A single space should be inserted between the winner and the number of moves. No other extra characters are allowed in the output. In case of a draw, the output line should be β€œDraw”. Example Input 3 3 3 1 1 1 1 1 1 3 3 7 2 2 1 3 1 1 2 3 2 1 3 3 3 1 4 3 15 1 1 2 2 1 1 3 3 3 3 1 1 3 3 3 3 4 4 1 1 4 4 4 4 4 4 4 1 2 2 0 0 0 Output Draw White 6 Black 15
instruction
0
54,732
19
109,464
"Correct Solution: ``` dirs = [ (1,0,0),(0,1,0),(0,0,1), (1,1,0),(1,-1,0), (0,1,1),(0,1,-1), (1,0,1),(-1,0,1), (1,1,1),(1,1,-1), (1,-1,1),(1,-1,-1) ] def judge(x,y,z): c = pegs[x][y][z] for dx,dy,dz in dirs: sq = 1 for _m in (1,-1): m = _m while True: mx,my,mz = x + m*dx, y + m*dy, z + m*dz if any(map(lambda l:not(0<=l<N), (mx,my,mz))): break if pegs[mx][my][mz] == c: sq += 1 if sq >= M: return c else: break m += _m return 0 while True: N,M,P = map(int,input().split()) if N == 0: break moves = [tuple(map(lambda x:int(x)-1, input().split())) for i in range(P)] pegs = [[[0 for z in range(N)] for y in range(N)] for x in range(N)] turn = 1 for i,(x,y) in enumerate(moves): z = pegs[x][y].index(0) pegs[x][y][z] = turn turn *= -1 c = judge(x,y,z) if c != 0: winner = 'Black' if c > 0 else 'White' print(winner + ' ' + str(i+1)) break else: print('Draw') ```
output
1
54,732
19
109,465
Provide a correct Python 3 solution for this coding contest problem. Your company’s next product will be a new game, which is a three-dimensional variant of the classic game β€œTic-Tac-Toe”. Two players place balls in a three-dimensional space (board), and try to make a sequence of a certain length. People believe that it is fun to play the game, but they still cannot fix the values of some parameters of the game. For example, what size of the board makes the game most exciting? Parameters currently under discussion are the board size (we call it n in the following) and the length of the sequence (m). In order to determine these parameter values, you are requested to write a computer simulator of the game. You can see several snapshots of the game in Figures 1-3. These figures correspond to the three datasets given in the Sample Input. <image> Figure 1: A game with n = m = 3 Here are the precise rules of the game. 1. Two players, Black and White, play alternately. Black plays first. 2. There are n Γ— n vertical pegs. Each peg can accommodate up to n balls. A peg can be specified by its x- and y-coordinates (1 ≀ x, y ≀ n). A ball on a peg can be specified by its z-coordinate (1 ≀ z ≀ n). At the beginning of a game, there are no balls on any of the pegs. <image> Figure 2: A game with n = m = 3 (White made a 3-sequence before Black) 3. On his turn, a player chooses one of n Γ— n pegs, and puts a ball of his color onto the peg. The ball follows the law of gravity. That is, the ball stays just above the top-most ball on the same peg or on the floor (if there are no balls on the peg). Speaking differently, a player can choose x- and y-coordinates of the ball, but he cannot choose its z-coordinate. 4. The objective of the game is to make an m-sequence. If a player makes an m-sequence or longer of his color, he wins. An m-sequence is a row of m consecutive balls of the same color. For example, black balls in positions (5, 1, 2), (5, 2, 2) and (5, 3, 2) form a 3-sequence. A sequence can be horizontal, vertical, or diagonal. Precisely speaking, there are 13 possible directions to make a sequence, categorized as follows. <image> Figure 3: A game with n = 4, m = 3 (Black made two 4-sequences) (a) One-dimensional axes. For example, (3, 1, 2), (4, 1, 2) and (5, 1, 2) is a 3-sequence. There are three directions in this category. (b) Two-dimensional diagonals. For example, (2, 3, 1), (3, 3, 2) and (4, 3, 3) is a 3-sequence. There are six directions in this category. (c) Three-dimensional diagonals. For example, (5, 1, 3), (4, 2, 4) and (3, 3, 5) is a 3- sequence. There are four directions in this category. Note that we do not distinguish between opposite directions. As the evaluation process of the game, people have been playing the game several times changing the parameter values. You are given the records of these games. It is your job to write a computer program which determines the winner of each recorded game. Since it is difficult for a human to find three-dimensional sequences, players often do not notice the end of the game, and continue to play uselessly. In these cases, moves after the end of the game, i.e. after the winner is determined, should be ignored. For example, after a player won making an m-sequence, players may make additional m-sequences. In this case, all m-sequences but the first should be ignored, and the winner of the game is unchanged. A game does not necessarily end with the victory of one of the players. If there are no pegs left to put a ball on, the game ends with a draw. Moreover, people may quit a game before making any m-sequence. In such cases also, the game ends with a draw. Input The input consists of multiple datasets each corresponding to the record of a game. A dataset starts with a line containing three positive integers n, m, and p separated by a space. The relations 3 ≀ m ≀ n ≀ 7 and 1 ≀ p ≀ n3 hold between them. n and m are the parameter values of the game as described above. p is the number of moves in the game. The rest of the dataset is p lines each containing two positive integers x and y. Each of these lines describes a move, i.e. the player on turn puts his ball on the peg specified. You can assume that 1 ≀ x ≀ n and 1 ≀ y ≀ n. You can also assume that at most n balls are put on a peg throughout a game. The end of the input is indicated by a line with three zeros separated by a space. Output For each dataset, a line describing the winner and the number of moves until the game ends should be output. The winner is either β€œBlack” or β€œWhite”. A single space should be inserted between the winner and the number of moves. No other extra characters are allowed in the output. In case of a draw, the output line should be β€œDraw”. Example Input 3 3 3 1 1 1 1 1 1 3 3 7 2 2 1 3 1 1 2 3 2 1 3 3 3 1 4 3 15 1 1 2 2 1 1 3 3 3 3 1 1 3 3 3 3 4 4 1 1 4 4 4 4 4 4 4 1 2 2 0 0 0 Output Draw White 6 Black 15
instruction
0
54,733
19
109,466
"Correct Solution: ``` import sys sys.setrecursionlimit(1000000000) input=lambda : sys.stdin.readline().rstrip() dx=[1,1,0,-1,1,1,0,-1,-1,-1,0,1,0] dy=[0,1,1,1,0,1,1,1,0,-1,-1,-1,0] dz=[0,0,0,0,1,1,1,1,1,1,1,1,1] while True: n,m,q=map(int,input().split()) if n==m==q==0: break field=[[[-1 for i in range(n)]for i in range(n)]for i in range(n)] d=True turn=1 for t in range(q): x,y=map(int,input().split()) if d==False: continue x,y=x-1,y-1 z=n while z>0: if field[x][y][z-1]==-1: z-=1 else: break field[x][y][z]=turn for i in range(13): tx,ty,tz=x,y,z count=0 while 0<=tx<n and 0<=ty<n and 0<=tz<n: if field[tx][ty][tz]==turn: count+=1 else: break tx,ty,tz=tx+dx[i],ty+dy[i],tz+dz[i] tx,ty,tz=x,y,z while 0<=tx<n and 0<=ty<n and 0<=tz<n: if field[tx][ty][tz]==turn: count+=1 else: break tx,ty,tz=tx-dx[i],ty-dy[i],tz-dz[i] count-=1 if count>=m: print('Black' if turn else 'White',t+1) d=False break turn=(turn+1)%2 if d: print('Draw') ```
output
1
54,733
19
109,467
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Your company’s next product will be a new game, which is a three-dimensional variant of the classic game β€œTic-Tac-Toe”. Two players place balls in a three-dimensional space (board), and try to make a sequence of a certain length. People believe that it is fun to play the game, but they still cannot fix the values of some parameters of the game. For example, what size of the board makes the game most exciting? Parameters currently under discussion are the board size (we call it n in the following) and the length of the sequence (m). In order to determine these parameter values, you are requested to write a computer simulator of the game. You can see several snapshots of the game in Figures 1-3. These figures correspond to the three datasets given in the Sample Input. <image> Figure 1: A game with n = m = 3 Here are the precise rules of the game. 1. Two players, Black and White, play alternately. Black plays first. 2. There are n Γ— n vertical pegs. Each peg can accommodate up to n balls. A peg can be specified by its x- and y-coordinates (1 ≀ x, y ≀ n). A ball on a peg can be specified by its z-coordinate (1 ≀ z ≀ n). At the beginning of a game, there are no balls on any of the pegs. <image> Figure 2: A game with n = m = 3 (White made a 3-sequence before Black) 3. On his turn, a player chooses one of n Γ— n pegs, and puts a ball of his color onto the peg. The ball follows the law of gravity. That is, the ball stays just above the top-most ball on the same peg or on the floor (if there are no balls on the peg). Speaking differently, a player can choose x- and y-coordinates of the ball, but he cannot choose its z-coordinate. 4. The objective of the game is to make an m-sequence. If a player makes an m-sequence or longer of his color, he wins. An m-sequence is a row of m consecutive balls of the same color. For example, black balls in positions (5, 1, 2), (5, 2, 2) and (5, 3, 2) form a 3-sequence. A sequence can be horizontal, vertical, or diagonal. Precisely speaking, there are 13 possible directions to make a sequence, categorized as follows. <image> Figure 3: A game with n = 4, m = 3 (Black made two 4-sequences) (a) One-dimensional axes. For example, (3, 1, 2), (4, 1, 2) and (5, 1, 2) is a 3-sequence. There are three directions in this category. (b) Two-dimensional diagonals. For example, (2, 3, 1), (3, 3, 2) and (4, 3, 3) is a 3-sequence. There are six directions in this category. (c) Three-dimensional diagonals. For example, (5, 1, 3), (4, 2, 4) and (3, 3, 5) is a 3- sequence. There are four directions in this category. Note that we do not distinguish between opposite directions. As the evaluation process of the game, people have been playing the game several times changing the parameter values. You are given the records of these games. It is your job to write a computer program which determines the winner of each recorded game. Since it is difficult for a human to find three-dimensional sequences, players often do not notice the end of the game, and continue to play uselessly. In these cases, moves after the end of the game, i.e. after the winner is determined, should be ignored. For example, after a player won making an m-sequence, players may make additional m-sequences. In this case, all m-sequences but the first should be ignored, and the winner of the game is unchanged. A game does not necessarily end with the victory of one of the players. If there are no pegs left to put a ball on, the game ends with a draw. Moreover, people may quit a game before making any m-sequence. In such cases also, the game ends with a draw. Input The input consists of multiple datasets each corresponding to the record of a game. A dataset starts with a line containing three positive integers n, m, and p separated by a space. The relations 3 ≀ m ≀ n ≀ 7 and 1 ≀ p ≀ n3 hold between them. n and m are the parameter values of the game as described above. p is the number of moves in the game. The rest of the dataset is p lines each containing two positive integers x and y. Each of these lines describes a move, i.e. the player on turn puts his ball on the peg specified. You can assume that 1 ≀ x ≀ n and 1 ≀ y ≀ n. You can also assume that at most n balls are put on a peg throughout a game. The end of the input is indicated by a line with three zeros separated by a space. Output For each dataset, a line describing the winner and the number of moves until the game ends should be output. The winner is either β€œBlack” or β€œWhite”. A single space should be inserted between the winner and the number of moves. No other extra characters are allowed in the output. In case of a draw, the output line should be β€œDraw”. Example Input 3 3 3 1 1 1 1 1 1 3 3 7 2 2 1 3 1 1 2 3 2 1 3 3 3 1 4 3 15 1 1 2 2 1 1 3 3 3 3 1 1 3 3 3 3 4 4 1 1 4 4 4 4 4 4 4 1 2 2 0 0 0 Output Draw White 6 Black 15 Submitted Solution: ``` dirs = [ (1,0,0),(0,1,0),(0,0,1), (1,1,0),(1,-1,0), (0,1,1),(0,1,-1), (1,0,1),(-1,0,1), (1,1,1),(1,1,-1), (1,-1,1),(1,-1,-1) ] def judge(x,y,z): c = pegs[x][y][z] for dx,dy,dz in dirs: sq = 1 for _m in (1,-1): m = _m while True: mx,my,mz = x + m*dx, y + m*dy, z + m*dz if mx >= N or my >= N or mz >= N: break if pegs[mx][my][mz] == c: sq += 1 if sq >= M: return c else: break m += _m return 0 while True: N,M,P = map(int,input().split()) if N == 0: break moves = [tuple(map(lambda x:int(x)-1, input().split())) for i in range(P)] pegs = [[[0 for z in range(N)] for y in range(N)] for x in range(N)] turn = 1 for i,(x,y) in enumerate(moves): z = pegs[x][y].index(0) pegs[x][y][z] = turn turn *= -1 c = judge(x,y,z) if c != 0: winner = 'Black' if c > 0 else 'White' print(winner + ' ' + str(i+1)) break else: print('Draw') ```
instruction
0
54,734
19
109,468
No
output
1
54,734
19
109,469
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Your company’s next product will be a new game, which is a three-dimensional variant of the classic game β€œTic-Tac-Toe”. Two players place balls in a three-dimensional space (board), and try to make a sequence of a certain length. People believe that it is fun to play the game, but they still cannot fix the values of some parameters of the game. For example, what size of the board makes the game most exciting? Parameters currently under discussion are the board size (we call it n in the following) and the length of the sequence (m). In order to determine these parameter values, you are requested to write a computer simulator of the game. You can see several snapshots of the game in Figures 1-3. These figures correspond to the three datasets given in the Sample Input. <image> Figure 1: A game with n = m = 3 Here are the precise rules of the game. 1. Two players, Black and White, play alternately. Black plays first. 2. There are n Γ— n vertical pegs. Each peg can accommodate up to n balls. A peg can be specified by its x- and y-coordinates (1 ≀ x, y ≀ n). A ball on a peg can be specified by its z-coordinate (1 ≀ z ≀ n). At the beginning of a game, there are no balls on any of the pegs. <image> Figure 2: A game with n = m = 3 (White made a 3-sequence before Black) 3. On his turn, a player chooses one of n Γ— n pegs, and puts a ball of his color onto the peg. The ball follows the law of gravity. That is, the ball stays just above the top-most ball on the same peg or on the floor (if there are no balls on the peg). Speaking differently, a player can choose x- and y-coordinates of the ball, but he cannot choose its z-coordinate. 4. The objective of the game is to make an m-sequence. If a player makes an m-sequence or longer of his color, he wins. An m-sequence is a row of m consecutive balls of the same color. For example, black balls in positions (5, 1, 2), (5, 2, 2) and (5, 3, 2) form a 3-sequence. A sequence can be horizontal, vertical, or diagonal. Precisely speaking, there are 13 possible directions to make a sequence, categorized as follows. <image> Figure 3: A game with n = 4, m = 3 (Black made two 4-sequences) (a) One-dimensional axes. For example, (3, 1, 2), (4, 1, 2) and (5, 1, 2) is a 3-sequence. There are three directions in this category. (b) Two-dimensional diagonals. For example, (2, 3, 1), (3, 3, 2) and (4, 3, 3) is a 3-sequence. There are six directions in this category. (c) Three-dimensional diagonals. For example, (5, 1, 3), (4, 2, 4) and (3, 3, 5) is a 3- sequence. There are four directions in this category. Note that we do not distinguish between opposite directions. As the evaluation process of the game, people have been playing the game several times changing the parameter values. You are given the records of these games. It is your job to write a computer program which determines the winner of each recorded game. Since it is difficult for a human to find three-dimensional sequences, players often do not notice the end of the game, and continue to play uselessly. In these cases, moves after the end of the game, i.e. after the winner is determined, should be ignored. For example, after a player won making an m-sequence, players may make additional m-sequences. In this case, all m-sequences but the first should be ignored, and the winner of the game is unchanged. A game does not necessarily end with the victory of one of the players. If there are no pegs left to put a ball on, the game ends with a draw. Moreover, people may quit a game before making any m-sequence. In such cases also, the game ends with a draw. Input The input consists of multiple datasets each corresponding to the record of a game. A dataset starts with a line containing three positive integers n, m, and p separated by a space. The relations 3 ≀ m ≀ n ≀ 7 and 1 ≀ p ≀ n3 hold between them. n and m are the parameter values of the game as described above. p is the number of moves in the game. The rest of the dataset is p lines each containing two positive integers x and y. Each of these lines describes a move, i.e. the player on turn puts his ball on the peg specified. You can assume that 1 ≀ x ≀ n and 1 ≀ y ≀ n. You can also assume that at most n balls are put on a peg throughout a game. The end of the input is indicated by a line with three zeros separated by a space. Output For each dataset, a line describing the winner and the number of moves until the game ends should be output. The winner is either β€œBlack” or β€œWhite”. A single space should be inserted between the winner and the number of moves. No other extra characters are allowed in the output. In case of a draw, the output line should be β€œDraw”. Example Input 3 3 3 1 1 1 1 1 1 3 3 7 2 2 1 3 1 1 2 3 2 1 3 3 3 1 4 3 15 1 1 2 2 1 1 3 3 3 3 1 1 3 3 3 3 4 4 1 1 4 4 4 4 4 4 4 1 2 2 0 0 0 Output Draw White 6 Black 15 Submitted Solution: ``` dx = [1, 1, 0, -1, 0, 0, 0, 0, 1, 1, 0, -1, 1, 1, 0, -1, 1, 1, 0, -1] dy = [0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1] dz = [0, 0, 0, 0, 1, 1, 0, -1, 0, 1, 1, 1, 1, 1, 0, -1, 1, 1, 0, -1] def check(i, col, x, y, z): if not(0 <= x < n and 0 <= y < n and 0 <= z < n): return 0 if col != d[z][y][x]: return 0 return check(i, col, x + dx[i], y + dy[i], z + dz[i]) + 1 from itertools import product while True: n, m, p = map(int, input().split()) if not n: break d = [[[0 for z in range(n)] for y in range(n)] for x in range(n)] done = False for i in range(p): x, y = map(int, input().split()) if done: continue x, y, z = x - 1, y - 1, n - 1 while z > 0 and not d[z - 1][y][x]: z -= 1 d[z][y][x] = i % 2 + 1 for x, y, z in product(range(n), repeat=3): for j in range(len(dx)): if check(j, 1, x, y, z) >= m: print('Black', i + 1) done = True break if check(j, 2, x, y, z) >= m: print('White', i + 1) done = True break if done: break if not done: print('Draw') ```
instruction
0
54,735
19
109,470
No
output
1
54,735
19
109,471
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Your company’s next product will be a new game, which is a three-dimensional variant of the classic game β€œTic-Tac-Toe”. Two players place balls in a three-dimensional space (board), and try to make a sequence of a certain length. People believe that it is fun to play the game, but they still cannot fix the values of some parameters of the game. For example, what size of the board makes the game most exciting? Parameters currently under discussion are the board size (we call it n in the following) and the length of the sequence (m). In order to determine these parameter values, you are requested to write a computer simulator of the game. You can see several snapshots of the game in Figures 1-3. These figures correspond to the three datasets given in the Sample Input. <image> Figure 1: A game with n = m = 3 Here are the precise rules of the game. 1. Two players, Black and White, play alternately. Black plays first. 2. There are n Γ— n vertical pegs. Each peg can accommodate up to n balls. A peg can be specified by its x- and y-coordinates (1 ≀ x, y ≀ n). A ball on a peg can be specified by its z-coordinate (1 ≀ z ≀ n). At the beginning of a game, there are no balls on any of the pegs. <image> Figure 2: A game with n = m = 3 (White made a 3-sequence before Black) 3. On his turn, a player chooses one of n Γ— n pegs, and puts a ball of his color onto the peg. The ball follows the law of gravity. That is, the ball stays just above the top-most ball on the same peg or on the floor (if there are no balls on the peg). Speaking differently, a player can choose x- and y-coordinates of the ball, but he cannot choose its z-coordinate. 4. The objective of the game is to make an m-sequence. If a player makes an m-sequence or longer of his color, he wins. An m-sequence is a row of m consecutive balls of the same color. For example, black balls in positions (5, 1, 2), (5, 2, 2) and (5, 3, 2) form a 3-sequence. A sequence can be horizontal, vertical, or diagonal. Precisely speaking, there are 13 possible directions to make a sequence, categorized as follows. <image> Figure 3: A game with n = 4, m = 3 (Black made two 4-sequences) (a) One-dimensional axes. For example, (3, 1, 2), (4, 1, 2) and (5, 1, 2) is a 3-sequence. There are three directions in this category. (b) Two-dimensional diagonals. For example, (2, 3, 1), (3, 3, 2) and (4, 3, 3) is a 3-sequence. There are six directions in this category. (c) Three-dimensional diagonals. For example, (5, 1, 3), (4, 2, 4) and (3, 3, 5) is a 3- sequence. There are four directions in this category. Note that we do not distinguish between opposite directions. As the evaluation process of the game, people have been playing the game several times changing the parameter values. You are given the records of these games. It is your job to write a computer program which determines the winner of each recorded game. Since it is difficult for a human to find three-dimensional sequences, players often do not notice the end of the game, and continue to play uselessly. In these cases, moves after the end of the game, i.e. after the winner is determined, should be ignored. For example, after a player won making an m-sequence, players may make additional m-sequences. In this case, all m-sequences but the first should be ignored, and the winner of the game is unchanged. A game does not necessarily end with the victory of one of the players. If there are no pegs left to put a ball on, the game ends with a draw. Moreover, people may quit a game before making any m-sequence. In such cases also, the game ends with a draw. Input The input consists of multiple datasets each corresponding to the record of a game. A dataset starts with a line containing three positive integers n, m, and p separated by a space. The relations 3 ≀ m ≀ n ≀ 7 and 1 ≀ p ≀ n3 hold between them. n and m are the parameter values of the game as described above. p is the number of moves in the game. The rest of the dataset is p lines each containing two positive integers x and y. Each of these lines describes a move, i.e. the player on turn puts his ball on the peg specified. You can assume that 1 ≀ x ≀ n and 1 ≀ y ≀ n. You can also assume that at most n balls are put on a peg throughout a game. The end of the input is indicated by a line with three zeros separated by a space. Output For each dataset, a line describing the winner and the number of moves until the game ends should be output. The winner is either β€œBlack” or β€œWhite”. A single space should be inserted between the winner and the number of moves. No other extra characters are allowed in the output. In case of a draw, the output line should be β€œDraw”. Example Input 3 3 3 1 1 1 1 1 1 3 3 7 2 2 1 3 1 1 2 3 2 1 3 3 3 1 4 3 15 1 1 2 2 1 1 3 3 3 3 1 1 3 3 3 3 4 4 1 1 4 4 4 4 4 4 4 1 2 2 0 0 0 Output Draw White 6 Black 15 Submitted Solution: ``` import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**10 mod = 998244353 def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s, flush=True) def main(): rr = [] dd = [(1,0,0),(0,1,0),(0,0,1),(1,1,0),(1,0,1),(0,1,1),(1,1,1)] while True: n,m,p = LI() if n == 0 and m == 0 and p == 0: break a = [LI() for _ in range(p)] r = 'Draw' d = collections.defaultdict(int) for i in range(p): ci,cj = a[i] t = i % 2 + 1 ck = 0 for k in range(p): if d[(ci,cj,k)] == 0: d[(ci,cj,k)] = t ck = k break ff = False for di,dj,dk in dd: if ff: break for k in range(-2,1): f = True for kk in range(k,k+3): ni = ci + di*kk nj = cj + dj*kk nk = ck + dk*kk if d[(ni,nj,nk)] != t: f = False break if f: ff = True break if ff: if t == 1: r = 'Black {}'.format(i+1) else: r = 'White {}'.format(i+1) break rr.append(r) return '\n'.join(map(str, rr)) print(main()) ```
instruction
0
54,736
19
109,472
No
output
1
54,736
19
109,473
Provide a correct Python 3 solution for this coding contest problem. You are playing a popular video game which is famous for its depthful story and interesting puzzles. In the game you were locked in a mysterious house alone and there is no way to call for help, so you have to escape on yours own. However, almost every room in the house has some kind of puzzles and you cannot move to neighboring room without solving them. One of the puzzles you encountered in the house is following. In a room, there was a device which looked just like a dice and laid on a table in the center of the room. Direction was written on the wall. It read: "This cube is a remote controller and you can manipulate a remote room, Dice Room, by it. The room has also a cubic shape whose surfaces are made up of 3x3 unit squares and some squares have a hole on them large enough for you to go though it. You can rotate this cube so that in the middle of rotation at least one edge always touch the table, that is, to 4 directions. Rotating this cube affects the remote room in the same way and positions of holes on the room change. To get through the room, you should have holes on at least one of lower three squares on the front and back side of the room." You can see current positions of holes by a monitor. Before going to Dice Room, you should rotate the cube so that you can go though the room. But you know rotating a room takes some time and you don’t have much time, so you should minimize the number of rotation. How many rotations do you need to make it possible to get though Dice Room? Input The input consists of several datasets. Each dataset contains 6 tables of 3x3 characters which describe the initial position of holes on each side. Each character is either '*' or '.'. A hole is indicated by '*'. The order which six sides appears in is: front, right, back, left, top, bottom. The order and orientation of them are described by this development view: <image> Figure 4: Dice Room <image> Figure 5: available dice rotations <image> There is a blank line after each dataset. The end of the input is indicated by a single '#'. Output Print the minimum number of rotations needed in a line for each dataset. You may assume all datasets have a solution. Examples Input ... ... .*. ... ... .*. ... ... ... ... ... .*. ... ... .*. ... ... ... ... .*. ... *.. ... ..* *.* *.* *.* *.* .*. *.* *.. .*. ..* *.* ... *.* ... .*. .*. ... .** *.. ... ... .*. .*. ... *.. ..* ... .** ... *.. ... # Output 3 1 0 Input ... ... .*. ... ... .*. ... ... ... ... ... .*. ... ... .*. ... ... ... ... .*. ... *.. ... ..* *.* *.* *.* *.* .*. *.* *.. .*. ..* *.* ... *.* ... .*. .*. ... .** *.. ... ... .*. .*. ... *.. ..* ... .** ... *.. ... Output 3 1 0
instruction
0
54,744
19
109,488
"Correct Solution: ``` from collections import deque def main(): I = { 1: ((6, 0), (2, 1), (5, 2), (4, 3)), 2: ((6, 3), (3, 1), (5, 3), (1, 3)), 3: ((6, 2), (4, 1), (5, 0), (2, 3)), 4: ((6, 1), (1, 1), (5, 1), (3, 3)), 5: ((1, 0), (2, 0), (3, 0), (4, 0)), 6: ((1, 2), (2, 2), (3, 2), (4, 2)), } J = [[6, 7, 8], [2, 5, 8], [0, 1, 2], [0, 3, 6]] D = [ (1, 5, 2, 3, 0, 4), # 'U' (3, 1, 0, 5, 4, 2), # 'R' (4, 0, 2, 3, 5, 1), # 'D' (2, 1, 5, 0, 4, 3), # 'L' ] def rotate_dice(L, k): return tuple(L[e] for e in D[k]) R = (5, 1, 2, 4, 3, 6) que = deque() dist = {R: 0} que.append(R) while que: s = que.popleft() d = dist[s] for i in range(4): t = rotate_dice(s, i) if t in dist: continue dist[t] = d+1 que.append(t) C = [None]*6 while 1: S = input() if S == '#': break C[0] = "".join([S, input(), input()]) for i in range(5): C[i+1] = "".join([input() for i in range(3)]) ans = 10 for s, v in dist.items(): a = s[0]; b = s[1] for k, (i, e) in enumerate(I[a]): if i == b: j, f = I[a][k-2] if any(C[i-1][k1] == '*' for k1 in J[e]) and any(C[j-1][k2] == '*' for k2 in J[f]): ans = min(ans, v) break print(ans) input() main() ```
output
1
54,744
19
109,489
Provide tags and a correct Python 3 solution for this coding contest problem. Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, the number on each card doesn't exceed x in the absolute value. Natasha doesn't like when Vanya spends a long time playing, so she hid all of his cards. Vanya became sad and started looking for the cards but he only found n of them. Vanya loves the balance, so he wants the sum of all numbers on found cards equal to zero. On the other hand, he got very tired of looking for cards. Help the boy and say what is the minimum number of cards does he need to find to make the sum equal to zero? You can assume that initially Vanya had infinitely many cards with each integer number from - x to x. Input The first line contains two integers: n (1 ≀ n ≀ 1000) β€” the number of found cards and x (1 ≀ x ≀ 1000) β€” the maximum absolute value of the number on a card. The second line contains n space-separated integers β€” the numbers on found cards. It is guaranteed that the numbers do not exceed x in their absolute value. Output Print a single number β€” the answer to the problem. Examples Input 3 2 -1 1 2 Output 1 Input 2 3 -2 -2 Output 2 Note In the first sample, Vanya needs to find a single card with number -2. In the second sample, Vanya needs to find two cards with number 2. He can't find a single card with the required number as the numbers on the lost cards do not exceed 3 in their absolute value.
instruction
0
55,129
19
110,258
Tags: implementation, math Correct Solution: ``` n,x = map(int,input().split()) arr = list(map(int,input().split())) su = abs(sum(arr)) if su==0: print(0) else: if su%(x)==0: print(su//x) else: print(su//x + 1) ```
output
1
55,129
19
110,259
Provide tags and a correct Python 3 solution for this coding contest problem. Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, the number on each card doesn't exceed x in the absolute value. Natasha doesn't like when Vanya spends a long time playing, so she hid all of his cards. Vanya became sad and started looking for the cards but he only found n of them. Vanya loves the balance, so he wants the sum of all numbers on found cards equal to zero. On the other hand, he got very tired of looking for cards. Help the boy and say what is the minimum number of cards does he need to find to make the sum equal to zero? You can assume that initially Vanya had infinitely many cards with each integer number from - x to x. Input The first line contains two integers: n (1 ≀ n ≀ 1000) β€” the number of found cards and x (1 ≀ x ≀ 1000) β€” the maximum absolute value of the number on a card. The second line contains n space-separated integers β€” the numbers on found cards. It is guaranteed that the numbers do not exceed x in their absolute value. Output Print a single number β€” the answer to the problem. Examples Input 3 2 -1 1 2 Output 1 Input 2 3 -2 -2 Output 2 Note In the first sample, Vanya needs to find a single card with number -2. In the second sample, Vanya needs to find two cards with number 2. He can't find a single card with the required number as the numbers on the lost cards do not exceed 3 in their absolute value.
instruction
0
55,131
19
110,262
Tags: implementation, math Correct Solution: ``` import math n , x = map(int,input().split()) a = list(map(int,input().split())) z = sum(a) print(math.ceil(abs(0-z)/x)) ```
output
1
55,131
19
110,263
Provide tags and a correct Python 3 solution for this coding contest problem. Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, the number on each card doesn't exceed x in the absolute value. Natasha doesn't like when Vanya spends a long time playing, so she hid all of his cards. Vanya became sad and started looking for the cards but he only found n of them. Vanya loves the balance, so he wants the sum of all numbers on found cards equal to zero. On the other hand, he got very tired of looking for cards. Help the boy and say what is the minimum number of cards does he need to find to make the sum equal to zero? You can assume that initially Vanya had infinitely many cards with each integer number from - x to x. Input The first line contains two integers: n (1 ≀ n ≀ 1000) β€” the number of found cards and x (1 ≀ x ≀ 1000) β€” the maximum absolute value of the number on a card. The second line contains n space-separated integers β€” the numbers on found cards. It is guaranteed that the numbers do not exceed x in their absolute value. Output Print a single number β€” the answer to the problem. Examples Input 3 2 -1 1 2 Output 1 Input 2 3 -2 -2 Output 2 Note In the first sample, Vanya needs to find a single card with number -2. In the second sample, Vanya needs to find two cards with number 2. He can't find a single card with the required number as the numbers on the lost cards do not exceed 3 in their absolute value.
instruction
0
55,133
19
110,266
Tags: implementation, math Correct Solution: ``` import math (n, x) = map(int, input().split()) sum_found = sum([int(i) for i in input().split()]) sum_need = abs(sum_found) print(math.ceil(sum_need / x)) ```
output
1
55,133
19
110,267
Provide tags and a correct Python 3 solution for this coding contest problem. Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, the number on each card doesn't exceed x in the absolute value. Natasha doesn't like when Vanya spends a long time playing, so she hid all of his cards. Vanya became sad and started looking for the cards but he only found n of them. Vanya loves the balance, so he wants the sum of all numbers on found cards equal to zero. On the other hand, he got very tired of looking for cards. Help the boy and say what is the minimum number of cards does he need to find to make the sum equal to zero? You can assume that initially Vanya had infinitely many cards with each integer number from - x to x. Input The first line contains two integers: n (1 ≀ n ≀ 1000) β€” the number of found cards and x (1 ≀ x ≀ 1000) β€” the maximum absolute value of the number on a card. The second line contains n space-separated integers β€” the numbers on found cards. It is guaranteed that the numbers do not exceed x in their absolute value. Output Print a single number β€” the answer to the problem. Examples Input 3 2 -1 1 2 Output 1 Input 2 3 -2 -2 Output 2 Note In the first sample, Vanya needs to find a single card with number -2. In the second sample, Vanya needs to find two cards with number 2. He can't find a single card with the required number as the numbers on the lost cards do not exceed 3 in their absolute value.
instruction
0
55,134
19
110,268
Tags: implementation, math Correct Solution: ``` import math n,x=map(int,input().split()) a=list(map(int,input().split())) r=0 for i in a: r+=i print(math.ceil(abs(r)/x)) ```
output
1
55,134
19
110,269
Provide tags and a correct Python 3 solution for this coding contest problem. Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, the number on each card doesn't exceed x in the absolute value. Natasha doesn't like when Vanya spends a long time playing, so she hid all of his cards. Vanya became sad and started looking for the cards but he only found n of them. Vanya loves the balance, so he wants the sum of all numbers on found cards equal to zero. On the other hand, he got very tired of looking for cards. Help the boy and say what is the minimum number of cards does he need to find to make the sum equal to zero? You can assume that initially Vanya had infinitely many cards with each integer number from - x to x. Input The first line contains two integers: n (1 ≀ n ≀ 1000) β€” the number of found cards and x (1 ≀ x ≀ 1000) β€” the maximum absolute value of the number on a card. The second line contains n space-separated integers β€” the numbers on found cards. It is guaranteed that the numbers do not exceed x in their absolute value. Output Print a single number β€” the answer to the problem. Examples Input 3 2 -1 1 2 Output 1 Input 2 3 -2 -2 Output 2 Note In the first sample, Vanya needs to find a single card with number -2. In the second sample, Vanya needs to find two cards with number 2. He can't find a single card with the required number as the numbers on the lost cards do not exceed 3 in their absolute value.
instruction
0
55,136
19
110,272
Tags: implementation, math Correct Solution: ``` from math import ceil as c n,x = map(int,input().split()) l = list(map(int,input().split())) k = abs(sum(l)) print(c(k/x)) ```
output
1
55,136
19
110,273
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, the number on each card doesn't exceed x in the absolute value. Natasha doesn't like when Vanya spends a long time playing, so she hid all of his cards. Vanya became sad and started looking for the cards but he only found n of them. Vanya loves the balance, so he wants the sum of all numbers on found cards equal to zero. On the other hand, he got very tired of looking for cards. Help the boy and say what is the minimum number of cards does he need to find to make the sum equal to zero? You can assume that initially Vanya had infinitely many cards with each integer number from - x to x. Input The first line contains two integers: n (1 ≀ n ≀ 1000) β€” the number of found cards and x (1 ≀ x ≀ 1000) β€” the maximum absolute value of the number on a card. The second line contains n space-separated integers β€” the numbers on found cards. It is guaranteed that the numbers do not exceed x in their absolute value. Output Print a single number β€” the answer to the problem. Examples Input 3 2 -1 1 2 Output 1 Input 2 3 -2 -2 Output 2 Note In the first sample, Vanya needs to find a single card with number -2. In the second sample, Vanya needs to find two cards with number 2. He can't find a single card with the required number as the numbers on the lost cards do not exceed 3 in their absolute value. Submitted Solution: ``` a,b=map(int,input().split()) l=list(map(int,input().split())) s=sum(l) k=0 while(s!=0): if(s>0 and s>=b): s-=b k+=1 elif(s<0 and s+b<=0): s+=b k+=1 else: break if(s==0): print(k) else: print(k+1) ```
instruction
0
55,137
19
110,274
Yes
output
1
55,137
19
110,275
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, the number on each card doesn't exceed x in the absolute value. Natasha doesn't like when Vanya spends a long time playing, so she hid all of his cards. Vanya became sad and started looking for the cards but he only found n of them. Vanya loves the balance, so he wants the sum of all numbers on found cards equal to zero. On the other hand, he got very tired of looking for cards. Help the boy and say what is the minimum number of cards does he need to find to make the sum equal to zero? You can assume that initially Vanya had infinitely many cards with each integer number from - x to x. Input The first line contains two integers: n (1 ≀ n ≀ 1000) β€” the number of found cards and x (1 ≀ x ≀ 1000) β€” the maximum absolute value of the number on a card. The second line contains n space-separated integers β€” the numbers on found cards. It is guaranteed that the numbers do not exceed x in their absolute value. Output Print a single number β€” the answer to the problem. Examples Input 3 2 -1 1 2 Output 1 Input 2 3 -2 -2 Output 2 Note In the first sample, Vanya needs to find a single card with number -2. In the second sample, Vanya needs to find two cards with number 2. He can't find a single card with the required number as the numbers on the lost cards do not exceed 3 in their absolute value. Submitted Solution: ``` import math from operator import itemgetter def get_primes(prime_supr): is_prime = [0]*2 + [1]*prime_supr for i in range(2,int(math.sqrt(prime_supr)) + 1): if is_prime[i]: for j in range(i * i, prime_supr + 1, i): is_prime[j] = 0 return is_prime get_int = lambda: map(int, input().split()) n, m = get_int() a = int(math.fabs(sum(list(get_int())))) print([a//m, a//m + 1][a%m != 0]) ```
instruction
0
55,138
19
110,276
Yes
output
1
55,138
19
110,277
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, the number on each card doesn't exceed x in the absolute value. Natasha doesn't like when Vanya spends a long time playing, so she hid all of his cards. Vanya became sad and started looking for the cards but he only found n of them. Vanya loves the balance, so he wants the sum of all numbers on found cards equal to zero. On the other hand, he got very tired of looking for cards. Help the boy and say what is the minimum number of cards does he need to find to make the sum equal to zero? You can assume that initially Vanya had infinitely many cards with each integer number from - x to x. Input The first line contains two integers: n (1 ≀ n ≀ 1000) β€” the number of found cards and x (1 ≀ x ≀ 1000) β€” the maximum absolute value of the number on a card. The second line contains n space-separated integers β€” the numbers on found cards. It is guaranteed that the numbers do not exceed x in their absolute value. Output Print a single number β€” the answer to the problem. Examples Input 3 2 -1 1 2 Output 1 Input 2 3 -2 -2 Output 2 Note In the first sample, Vanya needs to find a single card with number -2. In the second sample, Vanya needs to find two cards with number 2. He can't find a single card with the required number as the numbers on the lost cards do not exceed 3 in their absolute value. Submitted Solution: ``` #!/usr/bin/python3 from math import ceil def main(): n, x = [int(x) for x in input().split()] _sum = abs(sum([int(x) for x in input().split()])) print(ceil(float(_sum)/x)) if __name__ == "__main__": main() ```
instruction
0
55,139
19
110,278
Yes
output
1
55,139
19
110,279