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 players play a game. Initially there are n integers a_1, a_2, …, a_n written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the board, i. e. n - 1 turns are made. The first player makes the first move, then players alternate turns. The first player wants to minimize the last number that would be left on the board, while the second player wants to maximize it. You want to know what number will be left on the board after n - 1 turns if both players make optimal moves. Input The first line contains one integer n (1 ≤ n ≤ 1000) — the number of numbers on the board. The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^6). Output Print one number that will be left on the board. Examples Input 3 2 1 3 Output 2 Input 3 2 2 2 Output 2 Note In the first sample, the first player erases 3 and the second erases 1. 2 is left on the board. In the second sample, 2 is left on the board regardless of the actions of the players. Submitted Solution: ``` n=int(input());L=[int(z)for z in input().split()] for i in range(n-1): z=[max(L),min(L)][i%2] L.remove(z) print(L[0]) ```
instruction
0
34,889
19
69,778
Yes
output
1
34,889
19
69,779
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two players play a game. Initially there are n integers a_1, a_2, …, a_n written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the board, i. e. n - 1 turns are made. The first player makes the first move, then players alternate turns. The first player wants to minimize the last number that would be left on the board, while the second player wants to maximize it. You want to know what number will be left on the board after n - 1 turns if both players make optimal moves. Input The first line contains one integer n (1 ≤ n ≤ 1000) — the number of numbers on the board. The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^6). Output Print one number that will be left on the board. Examples Input 3 2 1 3 Output 2 Input 3 2 2 2 Output 2 Note In the first sample, the first player erases 3 and the second erases 1. 2 is left on the board. In the second sample, 2 is left on the board regardless of the actions of the players. Submitted Solution: ``` n = int(input()) p = sorted(list(map(int, input().split()))) if n % 2 == 1: print(p[n // 2]) else: print(p[int(n / 2 - 1)]) ```
instruction
0
34,890
19
69,780
Yes
output
1
34,890
19
69,781
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two players play a game. Initially there are n integers a_1, a_2, …, a_n written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the board, i. e. n - 1 turns are made. The first player makes the first move, then players alternate turns. The first player wants to minimize the last number that would be left on the board, while the second player wants to maximize it. You want to know what number will be left on the board after n - 1 turns if both players make optimal moves. Input The first line contains one integer n (1 ≤ n ≤ 1000) — the number of numbers on the board. The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^6). Output Print one number that will be left on the board. Examples Input 3 2 1 3 Output 2 Input 3 2 2 2 Output 2 Note In the first sample, the first player erases 3 and the second erases 1. 2 is left on the board. In the second sample, 2 is left on the board regardless of the actions of the players. Submitted Solution: ``` n = int(input().strip()) a = list(map(int, input().rstrip().split())) for i in range(0,n-1): if(i%2==0): a.remove(max(a)) else: a.remove(min(a)) print(a[0]) ```
instruction
0
34,891
19
69,782
Yes
output
1
34,891
19
69,783
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two players play a game. Initially there are n integers a_1, a_2, …, a_n written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the board, i. e. n - 1 turns are made. The first player makes the first move, then players alternate turns. The first player wants to minimize the last number that would be left on the board, while the second player wants to maximize it. You want to know what number will be left on the board after n - 1 turns if both players make optimal moves. Input The first line contains one integer n (1 ≤ n ≤ 1000) — the number of numbers on the board. The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^6). Output Print one number that will be left on the board. Examples Input 3 2 1 3 Output 2 Input 3 2 2 2 Output 2 Note In the first sample, the first player erases 3 and the second erases 1. 2 is left on the board. In the second sample, 2 is left on the board regardless of the actions of the players. Submitted Solution: ``` import sys n = int(sys.stdin.readline().strip()) line = sys.stdin.readline().strip() a = list(map(int, line.split())) a.sort() print(a[(n - 1) // 2]) # For integers, // in python3 is equivalent to / in python2, acting as the "floor division". While / in python3 is performing the "real division", which means 5 / 2 == 2.5 in python 3. ```
instruction
0
34,892
19
69,784
Yes
output
1
34,892
19
69,785
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two players play a game. Initially there are n integers a_1, a_2, …, a_n written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the board, i. e. n - 1 turns are made. The first player makes the first move, then players alternate turns. The first player wants to minimize the last number that would be left on the board, while the second player wants to maximize it. You want to know what number will be left on the board after n - 1 turns if both players make optimal moves. Input The first line contains one integer n (1 ≤ n ≤ 1000) — the number of numbers on the board. The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^6). Output Print one number that will be left on the board. Examples Input 3 2 1 3 Output 2 Input 3 2 2 2 Output 2 Note In the first sample, the first player erases 3 and the second erases 1. 2 is left on the board. In the second sample, 2 is left on the board regardless of the actions of the players. Submitted Solution: ``` numNumbers = int(input()) numbers = list(map(int,input().split(" "))) numbers.sort() print(numbers[numNumbers//2]) ```
instruction
0
34,893
19
69,786
No
output
1
34,893
19
69,787
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two players play a game. Initially there are n integers a_1, a_2, …, a_n written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the board, i. e. n - 1 turns are made. The first player makes the first move, then players alternate turns. The first player wants to minimize the last number that would be left on the board, while the second player wants to maximize it. You want to know what number will be left on the board after n - 1 turns if both players make optimal moves. Input The first line contains one integer n (1 ≤ n ≤ 1000) — the number of numbers on the board. The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^6). Output Print one number that will be left on the board. Examples Input 3 2 1 3 Output 2 Input 3 2 2 2 Output 2 Note In the first sample, the first player erases 3 and the second erases 1. 2 is left on the board. In the second sample, 2 is left on the board regardless of the actions of the players. Submitted Solution: ``` import math input() a = list(map(int, input().split())) for i in range(math.ceil(len(a) / 2) - 1): a.remove(max(a)) a.remove(min(a)) print(*a) ```
instruction
0
34,894
19
69,788
No
output
1
34,894
19
69,789
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two players play a game. Initially there are n integers a_1, a_2, …, a_n written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the board, i. e. n - 1 turns are made. The first player makes the first move, then players alternate turns. The first player wants to minimize the last number that would be left on the board, while the second player wants to maximize it. You want to know what number will be left on the board after n - 1 turns if both players make optimal moves. Input The first line contains one integer n (1 ≤ n ≤ 1000) — the number of numbers on the board. The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^6). Output Print one number that will be left on the board. Examples Input 3 2 1 3 Output 2 Input 3 2 2 2 Output 2 Note In the first sample, the first player erases 3 and the second erases 1. 2 is left on the board. In the second sample, 2 is left on the board regardless of the actions of the players. Submitted Solution: ``` N = int(input()) NUMBERS = list(map(int, input().split(" "))); NUMBERS.sort() print(NUMBERS[N//2 - 1] if N % 2 == 0 else NUMBERS[N//2 + 1]) ```
instruction
0
34,895
19
69,790
No
output
1
34,895
19
69,791
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two players play a game. Initially there are n integers a_1, a_2, …, a_n written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the board, i. e. n - 1 turns are made. The first player makes the first move, then players alternate turns. The first player wants to minimize the last number that would be left on the board, while the second player wants to maximize it. You want to know what number will be left on the board after n - 1 turns if both players make optimal moves. Input The first line contains one integer n (1 ≤ n ≤ 1000) — the number of numbers on the board. The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^6). Output Print one number that will be left on the board. Examples Input 3 2 1 3 Output 2 Input 3 2 2 2 Output 2 Note In the first sample, the first player erases 3 and the second erases 1. 2 is left on the board. In the second sample, 2 is left on the board regardless of the actions of the players. Submitted Solution: ``` n=int(input()) print(list(map(int,input().split()))[(n-1)//2]) ```
instruction
0
34,896
19
69,792
No
output
1
34,896
19
69,793
Provide a correct Python 3 solution for this coding contest problem. A cheetah and a cheater are going to play the game of Nim. In this game they use N piles of stones. Initially the i-th pile contains a_i stones. The players take turns alternately, and the cheetah plays first. In each turn, the player chooses one of the piles, and takes one or more stones from the pile. The player who can't make a move loses. However, before the game starts, the cheater wants to cheat a bit to make sure that he can win regardless of the moves by the cheetah. From each pile, the cheater takes zero or one stone and eats it before the game. In case there are multiple ways to guarantee his winning, he wants to minimize the number of stones he eats. Compute the number of stones the cheater will eat. In case there is no way for the cheater to win the game even with the cheating, print `-1` instead. Constraints * 1 ≤ N ≤ 10^5 * 2 ≤ a_i ≤ 10^9 Input The input is given from Standard Input in the following format: N a_1 : a_N Output Print the answer. Examples Input 3 2 3 4 Output 3 Input 3 100 100 100 Output -1
instruction
0
35,027
19
70,054
"Correct Solution: ``` # -*- coding: utf-8 -*- import sys from functools import reduce from operator import xor def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') sys.setrecursionlimit(10 ** 9) INF = float('inf') MOD = 10 ** 9 + 7 N=INT() A=[INT() for i in range(N)] mnbit=set() for i, a in enumerate(A): bina=format(a, 'b') # 2進で最初に1になる桁を、各値について見る mnbit.add(len(bina)-bina.rfind('1')) # 現状のA全部XOR res=reduce(xor, A, 0) ln=len(format(res, 'b')) cnt=0 for i in range(ln): idx=ln-i # 大きい桁から見て、1になっているところについて処理する if res>>(idx-1)&1: # その桁用の値があるか if idx in mnbit: # あればそれを1減らせば、その桁より下が全部反転する(1111..とXORする) res^=(1<<idx)-1 cnt+=1 else: # 必要な桁用の値がなければNG print(-1) exit() print(cnt) ```
output
1
35,027
19
70,055
Provide a correct Python 3 solution for this coding contest problem. A cheetah and a cheater are going to play the game of Nim. In this game they use N piles of stones. Initially the i-th pile contains a_i stones. The players take turns alternately, and the cheetah plays first. In each turn, the player chooses one of the piles, and takes one or more stones from the pile. The player who can't make a move loses. However, before the game starts, the cheater wants to cheat a bit to make sure that he can win regardless of the moves by the cheetah. From each pile, the cheater takes zero or one stone and eats it before the game. In case there are multiple ways to guarantee his winning, he wants to minimize the number of stones he eats. Compute the number of stones the cheater will eat. In case there is no way for the cheater to win the game even with the cheating, print `-1` instead. Constraints * 1 ≤ N ≤ 10^5 * 2 ≤ a_i ≤ 10^9 Input The input is given from Standard Input in the following format: N a_1 : a_N Output Print the answer. Examples Input 3 2 3 4 Output 3 Input 3 100 100 100 Output -1
instruction
0
35,028
19
70,056
"Correct Solution: ``` import sys input=sys.stdin.readline N=int(input()) ALL=0 bit=[0 for i in range(31)] for i in range(N): a=int(input()) ALL^=a B=100 for j in range(31): if a//(2**(30-j))==1: B=j a%=(2**(30-j)) bit[B]=1 #print(bit) all=[0 for i in range(31)] for j in range(31): if ALL//(2**(30-j))==1: all[j]+=1 ALL%=(2**(30-j)) #print(all) cnt=0 ans=0 for i in range(31): if (all[i]+cnt)%2==1: if bit[i]>=1: ans+=1 cnt+=1 else: print(-1) exit() print(ans) ```
output
1
35,028
19
70,057
Provide a correct Python 3 solution for this coding contest problem. A cheetah and a cheater are going to play the game of Nim. In this game they use N piles of stones. Initially the i-th pile contains a_i stones. The players take turns alternately, and the cheetah plays first. In each turn, the player chooses one of the piles, and takes one or more stones from the pile. The player who can't make a move loses. However, before the game starts, the cheater wants to cheat a bit to make sure that he can win regardless of the moves by the cheetah. From each pile, the cheater takes zero or one stone and eats it before the game. In case there are multiple ways to guarantee his winning, he wants to minimize the number of stones he eats. Compute the number of stones the cheater will eat. In case there is no way for the cheater to win the game even with the cheating, print `-1` instead. Constraints * 1 ≤ N ≤ 10^5 * 2 ≤ a_i ≤ 10^9 Input The input is given from Standard Input in the following format: N a_1 : a_N Output Print the answer. Examples Input 3 2 3 4 Output 3 Input 3 100 100 100 Output -1
instruction
0
35,029
19
70,058
"Correct Solution: ``` # -*- coding: utf-8 -*- import sys from collections import Counter from functools import reduce from operator import xor def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') sys.setrecursionlimit(10 ** 9) INF = float('inf') MOD = 10 ** 9 + 7 N=INT() A=[INT() for i in range(N)] mnbit=[0]*N for i, a in enumerate(A): bina=format(a, 'b') mnbit[i]=len(bina)-bina.rfind('1') C=Counter(mnbit) res=reduce(xor, A, 0) ln=len(format(res, 'b')) cnt=0 for i in range(ln): idx=ln-i if res>>(idx-1)&1: if C[idx]: res^=(1<<idx)-1 cnt+=1 else: print(-1) exit() print(cnt) ```
output
1
35,029
19
70,059
Provide a correct Python 3 solution for this coding contest problem. A cheetah and a cheater are going to play the game of Nim. In this game they use N piles of stones. Initially the i-th pile contains a_i stones. The players take turns alternately, and the cheetah plays first. In each turn, the player chooses one of the piles, and takes one or more stones from the pile. The player who can't make a move loses. However, before the game starts, the cheater wants to cheat a bit to make sure that he can win regardless of the moves by the cheetah. From each pile, the cheater takes zero or one stone and eats it before the game. In case there are multiple ways to guarantee his winning, he wants to minimize the number of stones he eats. Compute the number of stones the cheater will eat. In case there is no way for the cheater to win the game even with the cheating, print `-1` instead. Constraints * 1 ≤ N ≤ 10^5 * 2 ≤ a_i ≤ 10^9 Input The input is given from Standard Input in the following format: N a_1 : a_N Output Print the answer. Examples Input 3 2 3 4 Output 3 Input 3 100 100 100 Output -1
instruction
0
35,030
19
70,060
"Correct Solution: ``` n = int(input()) a = [int(input()) for _ in range(n)] gr = 0 for x in a: gr ^= x exist = set() for i in range(n): cnt = 0 while (a[i]>>cnt)&1 == 0: cnt += 1 exist.add(cnt) ok = True ans = 0 for i in range(35, -1, -1): if (gr>>i)&1: if i not in exist: ok = False else: gr %= (1<<(i+1)) gr = (1<<(i+1)) - gr - 1 ans += 1 else: gr %= (1<<(i+1)) if ok: print(ans) else: print(-1) ```
output
1
35,030
19
70,061
Provide a correct Python 3 solution for this coding contest problem. A cheetah and a cheater are going to play the game of Nim. In this game they use N piles of stones. Initially the i-th pile contains a_i stones. The players take turns alternately, and the cheetah plays first. In each turn, the player chooses one of the piles, and takes one or more stones from the pile. The player who can't make a move loses. However, before the game starts, the cheater wants to cheat a bit to make sure that he can win regardless of the moves by the cheetah. From each pile, the cheater takes zero or one stone and eats it before the game. In case there are multiple ways to guarantee his winning, he wants to minimize the number of stones he eats. Compute the number of stones the cheater will eat. In case there is no way for the cheater to win the game even with the cheating, print `-1` instead. Constraints * 1 ≤ N ≤ 10^5 * 2 ≤ a_i ≤ 10^9 Input The input is given from Standard Input in the following format: N a_1 : a_N Output Print the answer. Examples Input 3 2 3 4 Output 3 Input 3 100 100 100 Output -1
instruction
0
35,031
19
70,062
"Correct Solution: ``` n = int(input()) a = [int(input()) for i in range(n)] xora = 0 xorls = [] for i in a: xora ^= i xorls.append(i^(i-1)) xorls.sort(reverse=True) ans = 0 for i in xorls: if xora == 0: break if xora.bit_length() == i.bit_length(): xora ^= i ans += 1 if xora: print(-1) else: print(ans) ```
output
1
35,031
19
70,063
Provide a correct Python 3 solution for this coding contest problem. A cheetah and a cheater are going to play the game of Nim. In this game they use N piles of stones. Initially the i-th pile contains a_i stones. The players take turns alternately, and the cheetah plays first. In each turn, the player chooses one of the piles, and takes one or more stones from the pile. The player who can't make a move loses. However, before the game starts, the cheater wants to cheat a bit to make sure that he can win regardless of the moves by the cheetah. From each pile, the cheater takes zero or one stone and eats it before the game. In case there are multiple ways to guarantee his winning, he wants to minimize the number of stones he eats. Compute the number of stones the cheater will eat. In case there is no way for the cheater to win the game even with the cheating, print `-1` instead. Constraints * 1 ≤ N ≤ 10^5 * 2 ≤ a_i ≤ 10^9 Input The input is given from Standard Input in the following format: N a_1 : a_N Output Print the answer. Examples Input 3 2 3 4 Output 3 Input 3 100 100 100 Output -1
instruction
0
35,032
19
70,064
"Correct Solution: ``` import sys, collections def solve(): file = sys.stdin.readline N = int(file()) mindig = collections.defaultdict(int) nim = 0 for i in range(N): a = int(file()) nim ^= a mindig[a^(a-1)] += 1 if nim == 0: print(0) else: nim = format(nim, "b").zfill(30) flip = 0 for i in range(30): if int(nim[i]) != flip % 2: if mindig[pow(2, 30-i) - 1] == 0: print(-1) break else: flip += 1 else: print(flip) return if __name__ == "__main__": solve() ```
output
1
35,032
19
70,065
Provide a correct Python 3 solution for this coding contest problem. A cheetah and a cheater are going to play the game of Nim. In this game they use N piles of stones. Initially the i-th pile contains a_i stones. The players take turns alternately, and the cheetah plays first. In each turn, the player chooses one of the piles, and takes one or more stones from the pile. The player who can't make a move loses. However, before the game starts, the cheater wants to cheat a bit to make sure that he can win regardless of the moves by the cheetah. From each pile, the cheater takes zero or one stone and eats it before the game. In case there are multiple ways to guarantee his winning, he wants to minimize the number of stones he eats. Compute the number of stones the cheater will eat. In case there is no way for the cheater to win the game even with the cheating, print `-1` instead. Constraints * 1 ≤ N ≤ 10^5 * 2 ≤ a_i ≤ 10^9 Input The input is given from Standard Input in the following format: N a_1 : a_N Output Print the answer. Examples Input 3 2 3 4 Output 3 Input 3 100 100 100 Output -1
instruction
0
35,033
19
70,066
"Correct Solution: ``` # cf16-exhibition-final-openC - Cheating Nim import sys input = sys.stdin.readline def main(): # player is second move -> make xor 0 N = int(input()) A = sorted(map(int, [input() for _ in range(N)]), reverse=1) ans, x, flg = 0, 0, [0] * 30 for i in A: x ^= i p = bin(i ^ i - 1)[::-1].rfind("1") flg[p] = 1 for i in range(29, -1, -1): p = 2 ** i if x & p: # i-th bit is on if flg[i]: # possible to erase i-th bit of x x ^= p - 1 ans += 1 else: print(-1) return print(ans) if __name__ == "__main__": main() ```
output
1
35,033
19
70,067
Provide a correct Python 3 solution for this coding contest problem. A cheetah and a cheater are going to play the game of Nim. In this game they use N piles of stones. Initially the i-th pile contains a_i stones. The players take turns alternately, and the cheetah plays first. In each turn, the player chooses one of the piles, and takes one or more stones from the pile. The player who can't make a move loses. However, before the game starts, the cheater wants to cheat a bit to make sure that he can win regardless of the moves by the cheetah. From each pile, the cheater takes zero or one stone and eats it before the game. In case there are multiple ways to guarantee his winning, he wants to minimize the number of stones he eats. Compute the number of stones the cheater will eat. In case there is no way for the cheater to win the game even with the cheating, print `-1` instead. Constraints * 1 ≤ N ≤ 10^5 * 2 ≤ a_i ≤ 10^9 Input The input is given from Standard Input in the following format: N a_1 : a_N Output Print the answer. Examples Input 3 2 3 4 Output 3 Input 3 100 100 100 Output -1
instruction
0
35,034
19
70,068
"Correct Solution: ``` N=int(input()) x=0 A=[0]*N from collections import defaultdict cnt=defaultdict(int) for i in range(N): a=int(input()) x^=a cnt[a^(a-1)]+=1 two=[1]*31 for i in range(1,31): two[i]=two[i-1]*2 ans=0 for i in range(30,0,-1): if ans<0: break if x%two[i]//two[i-1]==1: if cnt[two[i]-1]>0: ans+=1 x^=two[i]-1 else: ans=-1 break print(ans) ```
output
1
35,034
19
70,069
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A cheetah and a cheater are going to play the game of Nim. In this game they use N piles of stones. Initially the i-th pile contains a_i stones. The players take turns alternately, and the cheetah plays first. In each turn, the player chooses one of the piles, and takes one or more stones from the pile. The player who can't make a move loses. However, before the game starts, the cheater wants to cheat a bit to make sure that he can win regardless of the moves by the cheetah. From each pile, the cheater takes zero or one stone and eats it before the game. In case there are multiple ways to guarantee his winning, he wants to minimize the number of stones he eats. Compute the number of stones the cheater will eat. In case there is no way for the cheater to win the game even with the cheating, print `-1` instead. Constraints * 1 ≤ N ≤ 10^5 * 2 ≤ a_i ≤ 10^9 Input The input is given from Standard Input in the following format: N a_1 : a_N Output Print the answer. Examples Input 3 2 3 4 Output 3 Input 3 100 100 100 Output -1 Submitted Solution: ``` # -*- coding: utf-8 -*- import sys from collections import Counter from functools import reduce from operator import xor def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') sys.setrecursionlimit(10 ** 9) INF = float('inf') MOD = 10 ** 9 + 7 N=INT() A=[INT() for i in range(N)] mnbit=[0]*N for i, a in enumerate(A): bina=format(a, 'b') mnbit[i]=len(bina)-bina.rfind('1') C=Counter(mnbit) res=format(reduce(xor, A, 0), 'b') cnt=0 ln=len(res) for i in range(ln): idx=len(res)-i if res[i]=='1': if C[idx]: res=format(int(res, 2)^int('1'*idx, 2), '0'+str(ln)+'b') cnt+=1 else: print(-1) exit() print(cnt) ```
instruction
0
35,035
19
70,070
Yes
output
1
35,035
19
70,071
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A cheetah and a cheater are going to play the game of Nim. In this game they use N piles of stones. Initially the i-th pile contains a_i stones. The players take turns alternately, and the cheetah plays first. In each turn, the player chooses one of the piles, and takes one or more stones from the pile. The player who can't make a move loses. However, before the game starts, the cheater wants to cheat a bit to make sure that he can win regardless of the moves by the cheetah. From each pile, the cheater takes zero or one stone and eats it before the game. In case there are multiple ways to guarantee his winning, he wants to minimize the number of stones he eats. Compute the number of stones the cheater will eat. In case there is no way for the cheater to win the game even with the cheating, print `-1` instead. Constraints * 1 ≤ N ≤ 10^5 * 2 ≤ a_i ≤ 10^9 Input The input is given from Standard Input in the following format: N a_1 : a_N Output Print the answer. Examples Input 3 2 3 4 Output 3 Input 3 100 100 100 Output -1 Submitted Solution: ``` N=int(input()) S=0 canuse=[False]*40 for i in range(N): A=int(input()) S^=A for k in range(40): if A&(1<<k): canuse[k]=True break ans=0 for k in range(40)[::-1]: if S&(1<<k): if canuse[k]: S^=(1<<(k+1))-1 ans+=1 else: print(-1) exit() print(ans) ```
instruction
0
35,036
19
70,072
Yes
output
1
35,036
19
70,073
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A cheetah and a cheater are going to play the game of Nim. In this game they use N piles of stones. Initially the i-th pile contains a_i stones. The players take turns alternately, and the cheetah plays first. In each turn, the player chooses one of the piles, and takes one or more stones from the pile. The player who can't make a move loses. However, before the game starts, the cheater wants to cheat a bit to make sure that he can win regardless of the moves by the cheetah. From each pile, the cheater takes zero or one stone and eats it before the game. In case there are multiple ways to guarantee his winning, he wants to minimize the number of stones he eats. Compute the number of stones the cheater will eat. In case there is no way for the cheater to win the game even with the cheating, print `-1` instead. Constraints * 1 ≤ N ≤ 10^5 * 2 ≤ a_i ≤ 10^9 Input The input is given from Standard Input in the following format: N a_1 : a_N Output Print the answer. Examples Input 3 2 3 4 Output 3 Input 3 100 100 100 Output -1 Submitted Solution: ``` # -*- coding: utf-8 -*- import sys from functools import reduce from operator import xor def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') sys.setrecursionlimit(10 ** 9) INF = float('inf') MOD = 10 ** 9 + 7 N=INT() A=[INT() for i in range(N)] mnbit=set() for i, a in enumerate(A): bina=format(a, 'b') # 2進で最初に1になる桁を、各値について見る mnbit.add(len(bina)-bina.rfind('1')) # 現状のA全部XOR res=format(reduce(xor, A, 0), 'b') cnt=0 ln=len(res) for i in range(ln): idx=ln-i # 大きい桁から見て、1になっているところについて処理する if res[i]=='1': # その桁用の値があるか if idx in mnbit: # あればそれを1減らせば、その桁より下が全部反転する res=format(int(res, 2)^int('1'*idx, 2), '0'+str(ln)+'b') cnt+=1 else: # 必要な桁用の値がなければNG print(-1) exit() print(cnt) ```
instruction
0
35,037
19
70,074
Yes
output
1
35,037
19
70,075
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A cheetah and a cheater are going to play the game of Nim. In this game they use N piles of stones. Initially the i-th pile contains a_i stones. The players take turns alternately, and the cheetah plays first. In each turn, the player chooses one of the piles, and takes one or more stones from the pile. The player who can't make a move loses. However, before the game starts, the cheater wants to cheat a bit to make sure that he can win regardless of the moves by the cheetah. From each pile, the cheater takes zero or one stone and eats it before the game. In case there are multiple ways to guarantee his winning, he wants to minimize the number of stones he eats. Compute the number of stones the cheater will eat. In case there is no way for the cheater to win the game even with the cheating, print `-1` instead. Constraints * 1 ≤ N ≤ 10^5 * 2 ≤ a_i ≤ 10^9 Input The input is given from Standard Input in the following format: N a_1 : a_N Output Print the answer. Examples Input 3 2 3 4 Output 3 Input 3 100 100 100 Output -1 Submitted Solution: ``` N=int(input()) A=[int(input()) for _ in range(N)] grundy=0 edible=set() def solve(grundy, edible): ans=0 while grundy: b=(1<<grundy.bit_length())-1 if b not in edible: return -1 ans+=1 grundy^=b return ans for a in A: grundy^=a edible.add(a^(a-1)) print(solve(grundy,edible)) ```
instruction
0
35,038
19
70,076
Yes
output
1
35,038
19
70,077
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A cheetah and a cheater are going to play the game of Nim. In this game they use N piles of stones. Initially the i-th pile contains a_i stones. The players take turns alternately, and the cheetah plays first. In each turn, the player chooses one of the piles, and takes one or more stones from the pile. The player who can't make a move loses. However, before the game starts, the cheater wants to cheat a bit to make sure that he can win regardless of the moves by the cheetah. From each pile, the cheater takes zero or one stone and eats it before the game. In case there are multiple ways to guarantee his winning, he wants to minimize the number of stones he eats. Compute the number of stones the cheater will eat. In case there is no way for the cheater to win the game even with the cheating, print `-1` instead. Constraints * 1 ≤ N ≤ 10^5 * 2 ≤ a_i ≤ 10^9 Input The input is given from Standard Input in the following format: N a_1 : a_N Output Print the answer. Examples Input 3 2 3 4 Output 3 Input 3 100 100 100 Output -1 Submitted Solution: ``` N = int(input()) A = [int(input()) for _ in range(N)] A.sort(reverse=True) xor = 0 for a in A: xor ^= a left = 0 ans = 0 for digit in range(1, xor.bit_length() + 1)[:: -1]: if xor & (1 << digit) > 0: while left < N and (A[left] & (1 << digit)) != A[left]: left += 1 if left >= N: print(-1) exit() if (A[left] & (1 << digit)) == A[left]: ans += 1 xor ^= ((1 << (digit + 1)) - 1) else: print(-1) exit() if xor: for a in A: if a % 2 == 1: ans += 1 break else: print(-1) exit() print(ans) ```
instruction
0
35,039
19
70,078
No
output
1
35,039
19
70,079
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A cheetah and a cheater are going to play the game of Nim. In this game they use N piles of stones. Initially the i-th pile contains a_i stones. The players take turns alternately, and the cheetah plays first. In each turn, the player chooses one of the piles, and takes one or more stones from the pile. The player who can't make a move loses. However, before the game starts, the cheater wants to cheat a bit to make sure that he can win regardless of the moves by the cheetah. From each pile, the cheater takes zero or one stone and eats it before the game. In case there are multiple ways to guarantee his winning, he wants to minimize the number of stones he eats. Compute the number of stones the cheater will eat. In case there is no way for the cheater to win the game even with the cheating, print `-1` instead. Constraints * 1 ≤ N ≤ 10^5 * 2 ≤ a_i ≤ 10^9 Input The input is given from Standard Input in the following format: N a_1 : a_N Output Print the answer. Examples Input 3 2 3 4 Output 3 Input 3 100 100 100 Output -1 Submitted Solution: ``` def main(): n = int(input()) a = [int(input()) for _ in [0]*n] m = max(a) xor = 0 for i in a: xor ^= i i = 1 cnt = 0 while True: if xor >= i: i *= 2 cnt += 1 else: break ans = 0 for i in range(cnt-1, -1, -1): j = (xor & 2**i) // (2**i) if j == 1: for k in a: if k % (2**i) == 0: xor ^= k xor ^= k-1 ans += 1 a.remove(k) break else: print(-1/0) return 0 print(ans) main() ```
instruction
0
35,040
19
70,080
No
output
1
35,040
19
70,081
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A cheetah and a cheater are going to play the game of Nim. In this game they use N piles of stones. Initially the i-th pile contains a_i stones. The players take turns alternately, and the cheetah plays first. In each turn, the player chooses one of the piles, and takes one or more stones from the pile. The player who can't make a move loses. However, before the game starts, the cheater wants to cheat a bit to make sure that he can win regardless of the moves by the cheetah. From each pile, the cheater takes zero or one stone and eats it before the game. In case there are multiple ways to guarantee his winning, he wants to minimize the number of stones he eats. Compute the number of stones the cheater will eat. In case there is no way for the cheater to win the game even with the cheating, print `-1` instead. Constraints * 1 ≤ N ≤ 10^5 * 2 ≤ a_i ≤ 10^9 Input The input is given from Standard Input in the following format: N a_1 : a_N Output Print the answer. Examples Input 3 2 3 4 Output 3 Input 3 100 100 100 Output -1 Submitted Solution: ``` N = int(input()) A = [int(input()) for _ in range(N)] A.sort(reverse=True, key=lambda a: (a & -a)) xor = 0 for a in A: xor ^= a left = 0 ans = 0 for digit in range(1, xor.bit_length() + 1)[:: -1]: if (xor & (1 << digit)) > 0: while left < N and (A[left] & -A[left]).bit_length() > digit: left += 1 if left >= N: print(-1) exit() ans += 1 xor ^= ((1 << (digit + 1)) - 1) if xor: for a in A: if a % 2 == 1: ans += 1 break else: print(-1) exit() print(ans) ```
instruction
0
35,041
19
70,082
No
output
1
35,041
19
70,083
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A cheetah and a cheater are going to play the game of Nim. In this game they use N piles of stones. Initially the i-th pile contains a_i stones. The players take turns alternately, and the cheetah plays first. In each turn, the player chooses one of the piles, and takes one or more stones from the pile. The player who can't make a move loses. However, before the game starts, the cheater wants to cheat a bit to make sure that he can win regardless of the moves by the cheetah. From each pile, the cheater takes zero or one stone and eats it before the game. In case there are multiple ways to guarantee his winning, he wants to minimize the number of stones he eats. Compute the number of stones the cheater will eat. In case there is no way for the cheater to win the game even with the cheating, print `-1` instead. Constraints * 1 ≤ N ≤ 10^5 * 2 ≤ a_i ≤ 10^9 Input The input is given from Standard Input in the following format: N a_1 : a_N Output Print the answer. Examples Input 3 2 3 4 Output 3 Input 3 100 100 100 Output -1 Submitted Solution: ``` n = int(input()) A = [int(input()) for _ in range(n)] m = 30 C = [False]*m x = 0 for a in A: x ^= a for i in range(m): if a>>i & 1: C[i] = True total = 0 ans = 0 for i in range(m): if (x>>i & 1) ^ total: if C[i]: ans += 1 total ^= 1 else: print(-1) break else: print(ans) ```
instruction
0
35,042
19
70,084
No
output
1
35,042
19
70,085
Provide tags and a correct Python 3 solution for this coding contest problem. A famous gang of pirates, Sea Dogs, has come back to their hideout from one of their extravagant plunders. They want to split their treasure fairly amongst themselves, that is why You, their trusted financial advisor, devised a game to help them: All of them take a sit at their round table, some of them with the golden coins they have just stolen. At each iteration of the game if one of them has equal or more than 2 coins, he is eligible to the splitting and he gives one coin to each pirate sitting next to him. If there are more candidates (pirates with equal or more than 2 coins) then You are the one that chooses which one of them will do the splitting in that iteration. The game ends when there are no more candidates eligible to do the splitting. Pirates can call it a day, only when the game ends. Since they are beings with a finite amount of time at their disposal, they would prefer if the game that they are playing can end after finite iterations, and if so, they call it a good game. On the other hand, if no matter how You do the splitting, the game cannot end in finite iterations, they call it a bad game. Can You help them figure out before they start playing if the game will be good or bad? Input The first line of input contains two integer numbers n and k (1 ≤ n ≤ 10^{9}, 0 ≤ k ≤ 2⋅10^5), where n denotes total number of pirates and k is the number of pirates that have any coins. The next k lines of input contain integers a_i and b_i (1 ≤ a_i ≤ n, 1 ≤ b_i ≤ 10^{9}), where a_i denotes the index of the pirate sitting at the round table (n and 1 are neighbours) and b_i the total number of coins that pirate a_i has at the start of the game. Output Print 1 if the game is a good game: There is a way to do the splitting so the game ends after finite number of iterations. Print -1 if the game is a bad game: No matter how You do the splitting the game does not end in finite number of iterations. Examples Input 4 2 1 2 2 2 Output 1 Input 6 2 2 3 4 1 Output 1 Input 3 2 1 1 2 2 Output -1 Note In the third example the game has no end, because You always only have only one candidate, after whose splitting you end up in the same position as the starting one.
instruction
0
35,382
19
70,764
Tags: math Correct Solution: ``` import os import sys from io import BytesIO, IOBase # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") def main(): n, k = [int(x) for x in input().split()] p, s = 0, 0 for _ in range(k): a, b = [int(x) for x in input().split()] s += b p += a * b p %= n print(['-1', '1'][s < n or (s == n and p == (n * (n + 1) // 2) % n)]) main() ```
output
1
35,382
19
70,765
Provide tags and a correct Python 3 solution for this coding contest problem. A famous gang of pirates, Sea Dogs, has come back to their hideout from one of their extravagant plunders. They want to split their treasure fairly amongst themselves, that is why You, their trusted financial advisor, devised a game to help them: All of them take a sit at their round table, some of them with the golden coins they have just stolen. At each iteration of the game if one of them has equal or more than 2 coins, he is eligible to the splitting and he gives one coin to each pirate sitting next to him. If there are more candidates (pirates with equal or more than 2 coins) then You are the one that chooses which one of them will do the splitting in that iteration. The game ends when there are no more candidates eligible to do the splitting. Pirates can call it a day, only when the game ends. Since they are beings with a finite amount of time at their disposal, they would prefer if the game that they are playing can end after finite iterations, and if so, they call it a good game. On the other hand, if no matter how You do the splitting, the game cannot end in finite iterations, they call it a bad game. Can You help them figure out before they start playing if the game will be good or bad? Input The first line of input contains two integer numbers n and k (1 ≤ n ≤ 10^{9}, 0 ≤ k ≤ 2⋅10^5), where n denotes total number of pirates and k is the number of pirates that have any coins. The next k lines of input contain integers a_i and b_i (1 ≤ a_i ≤ n, 1 ≤ b_i ≤ 10^{9}), where a_i denotes the index of the pirate sitting at the round table (n and 1 are neighbours) and b_i the total number of coins that pirate a_i has at the start of the game. Output Print 1 if the game is a good game: There is a way to do the splitting so the game ends after finite number of iterations. Print -1 if the game is a bad game: No matter how You do the splitting the game does not end in finite number of iterations. Examples Input 4 2 1 2 2 2 Output 1 Input 6 2 2 3 4 1 Output 1 Input 3 2 1 1 2 2 Output -1 Note In the third example the game has no end, because You always only have only one candidate, after whose splitting you end up in the same position as the starting one.
instruction
0
35,383
19
70,766
Tags: math Correct Solution: ``` import os import sys from io import BytesIO, IOBase def main(): pass # 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") n, k = map(int, input().split()) coins = 0 pos = 0 for _ in range(k): a, b = map(int, input().split()) coins += b pos += a * b pos %= n if coins < n or coins == n and (pos - (n*n-n)//2) % n == 0: print(1) else: print(-1) ```
output
1
35,383
19
70,767
Provide tags and a correct Python 3 solution for this coding contest problem. SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is <image> for SmallR while <image> for Zanoes. The one who shoots in the target first should be the winner. Output the probability that SmallR will win the match. Input A single line contains four integers <image>. Output Print a single real number, the probability that SmallR will win the match. The answer will be considered correct if the absolute or relative error doesn't exceed 10 - 6. Examples Input 1 2 1 2 Output 0.666666666667
instruction
0
35,481
19
70,962
Tags: math, probabilities Correct Solution: ``` a,b,c,d=list(map(int,input().split())) awin=a/b aloss=1-(a/b) bloss=1-(c/d) ans=awin*(1/(1-(aloss*bloss))) print("%.12f" % ans) ```
output
1
35,481
19
70,963
Provide tags and a correct Python 3 solution for this coding contest problem. SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is <image> for SmallR while <image> for Zanoes. The one who shoots in the target first should be the winner. Output the probability that SmallR will win the match. Input A single line contains four integers <image>. Output Print a single real number, the probability that SmallR will win the match. The answer will be considered correct if the absolute or relative error doesn't exceed 10 - 6. Examples Input 1 2 1 2 Output 0.666666666667
instruction
0
35,482
19
70,964
Tags: math, probabilities Correct Solution: ``` def main(): l=[int(x) for x in input().split(' ')] r=(l[0]*l[3])/(l[1]*l[2]+l[0]*l[3]-l[0]*l[2]) print(r) if __name__=='__main__': main() ```
output
1
35,482
19
70,965
Provide tags and a correct Python 3 solution for this coding contest problem. SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is <image> for SmallR while <image> for Zanoes. The one who shoots in the target first should be the winner. Output the probability that SmallR will win the match. Input A single line contains four integers <image>. Output Print a single real number, the probability that SmallR will win the match. The answer will be considered correct if the absolute or relative error doesn't exceed 10 - 6. Examples Input 1 2 1 2 Output 0.666666666667
instruction
0
35,483
19
70,966
Tags: math, probabilities Correct Solution: ``` #!/usr/bin/env python import os import sys from io import BytesIO, IOBase from typing import Union def main(): a, b, c, d = map(int, input().split()) p = a / b x = (1 - p) * (1 - c / d) print(p / (1 - x)) # 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") # endregion if __name__ == "__main__": main() ```
output
1
35,483
19
70,967
Provide tags and a correct Python 3 solution for this coding contest problem. SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is <image> for SmallR while <image> for Zanoes. The one who shoots in the target first should be the winner. Output the probability that SmallR will win the match. Input A single line contains four integers <image>. Output Print a single real number, the probability that SmallR will win the match. The answer will be considered correct if the absolute or relative error doesn't exceed 10 - 6. Examples Input 1 2 1 2 Output 0.666666666667
instruction
0
35,484
19
70,968
Tags: math, probabilities Correct Solution: ``` a,b,c,d = list(map(int, input().split())) b1 = a/b q = (1-b1)*(1-(c/d)) n = 10000 res = b1*(q**n - 1) / (q - 1) print(res) ```
output
1
35,484
19
70,969
Provide tags and a correct Python 3 solution for this coding contest problem. SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is <image> for SmallR while <image> for Zanoes. The one who shoots in the target first should be the winner. Output the probability that SmallR will win the match. Input A single line contains four integers <image>. Output Print a single real number, the probability that SmallR will win the match. The answer will be considered correct if the absolute or relative error doesn't exceed 10 - 6. Examples Input 1 2 1 2 Output 0.666666666667
instruction
0
35,485
19
70,970
Tags: math, probabilities Correct Solution: ``` def main(): args=input().split() a=int(args[0]) b=int(args[1]) c=int(args[2]) d=int(args[3]) p=a/b q=(1-c/d)*(1-a/b) print(p/(1-q)) main() ```
output
1
35,485
19
70,971
Provide tags and a correct Python 3 solution for this coding contest problem. SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is <image> for SmallR while <image> for Zanoes. The one who shoots in the target first should be the winner. Output the probability that SmallR will win the match. Input A single line contains four integers <image>. Output Print a single real number, the probability that SmallR will win the match. The answer will be considered correct if the absolute or relative error doesn't exceed 10 - 6. Examples Input 1 2 1 2 Output 0.666666666667
instruction
0
35,486
19
70,972
Tags: math, probabilities Correct Solution: ``` a, b, c, d = map(int, input().split()) p1 = a / b p2 = c / d print(p1 / (1 - (1 - p1) * (1 - p2))) ```
output
1
35,486
19
70,973
Provide tags and a correct Python 3 solution for this coding contest problem. SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is <image> for SmallR while <image> for Zanoes. The one who shoots in the target first should be the winner. Output the probability that SmallR will win the match. Input A single line contains four integers <image>. Output Print a single real number, the probability that SmallR will win the match. The answer will be considered correct if the absolute or relative error doesn't exceed 10 - 6. Examples Input 1 2 1 2 Output 0.666666666667
instruction
0
35,487
19
70,974
Tags: math, probabilities Correct Solution: ``` a,b,c,d=map(int,input().split());print((a/b)/(1-(1-c/d)*(1-a/b))) ```
output
1
35,487
19
70,975
Provide tags and a correct Python 3 solution for this coding contest problem. SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is <image> for SmallR while <image> for Zanoes. The one who shoots in the target first should be the winner. Output the probability that SmallR will win the match. Input A single line contains four integers <image>. Output Print a single real number, the probability that SmallR will win the match. The answer will be considered correct if the absolute or relative error doesn't exceed 10 - 6. Examples Input 1 2 1 2 Output 0.666666666667
instruction
0
35,488
19
70,976
Tags: math, probabilities Correct Solution: ``` a,b,c,d = [int(i) for i in input().split()] prob1 = a/b prob2 = c/d probDoisErrarem = (1-prob1)*(1-prob2) prob1Ganhar = prob1/(1-probDoisErrarem) print(prob1Ganhar) ```
output
1
35,488
19
70,977
Provide tags and a correct Python 3 solution for this coding contest problem. Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork. For each team Olympiad, Vanya takes his play cards with numbers. He takes only the cards containing numbers 1 and 0. The boys are very superstitious. They think that they can do well at the Olympiad if they begin with laying all the cards in a row so that: * there wouldn't be a pair of any side-adjacent cards with zeroes in a row; * there wouldn't be a group of three consecutive cards containing numbers one. Today Vanya brought n cards with zeroes and m cards with numbers one. The number of cards was so much that the friends do not know how to put all those cards in the described way. Help them find the required arrangement of the cards or else tell the guys that it is impossible to arrange cards in such a way. Input The first line contains two integers: n (1 ≤ n ≤ 106) — the number of cards containing number 0; m (1 ≤ m ≤ 106) — the number of cards containing number 1. Output In a single line print the required sequence of zeroes and ones without any spaces. If such sequence is impossible to obtain, print -1. Examples Input 1 2 Output 101 Input 4 8 Output 110110110101 Input 4 10 Output 11011011011011 Input 1 5 Output -1
instruction
0
35,498
19
70,996
Tags: constructive algorithms, greedy, implementation Correct Solution: ``` def zip_sorted(a,b): # sorted by a a,b = zip(*sorted(zip(a,b))) # sorted by b sorted(zip(a, b), key=lambda x: x[1]) return a,b import sys input = sys.stdin.readline I = lambda : list(map(int,input().split())) S = lambda : list(map(str,input().split())) n,m = I() a = ['0']*(2*n-1) for i in range(len(a)): if i%2!=0: a[i] = '1' if (m<n-1 or m>2*(n+1)): print(-1) elif m==n-1: print(''.join(a)) elif m==n: print('1'+''.join(a)) elif m==n+1: a = ['1']+a+['1'] print(''.join(a)) else: a = ['1']+a+['1'] whole = m-(n+1) for j in range(0,len(a),2): if whole>0: pass else: break if a[j]=='1': a[j] = '11' whole = whole-1 print(''.join(a)) ```
output
1
35,498
19
70,997
Provide tags and a correct Python 3 solution for this coding contest problem. Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork. For each team Olympiad, Vanya takes his play cards with numbers. He takes only the cards containing numbers 1 and 0. The boys are very superstitious. They think that they can do well at the Olympiad if they begin with laying all the cards in a row so that: * there wouldn't be a pair of any side-adjacent cards with zeroes in a row; * there wouldn't be a group of three consecutive cards containing numbers one. Today Vanya brought n cards with zeroes and m cards with numbers one. The number of cards was so much that the friends do not know how to put all those cards in the described way. Help them find the required arrangement of the cards or else tell the guys that it is impossible to arrange cards in such a way. Input The first line contains two integers: n (1 ≤ n ≤ 106) — the number of cards containing number 0; m (1 ≤ m ≤ 106) — the number of cards containing number 1. Output In a single line print the required sequence of zeroes and ones without any spaces. If such sequence is impossible to obtain, print -1. Examples Input 1 2 Output 101 Input 4 8 Output 110110110101 Input 4 10 Output 11011011011011 Input 1 5 Output -1
instruction
0
35,499
19
70,998
Tags: constructive algorithms, greedy, implementation Correct Solution: ``` n,m=map(int,input().split()) if n==m: print('01'*m) elif m==n-1: print('01'*m+'0') elif m>n and m<=2*(n+1): while n!=m and n>0 and m>0: print('110',end='') n-=1 m-=2 print('10'*n,end='') m-=n print('1'*m,end='') else: print(-1) ```
output
1
35,499
19
70,999
Provide tags and a correct Python 3 solution for this coding contest problem. Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork. For each team Olympiad, Vanya takes his play cards with numbers. He takes only the cards containing numbers 1 and 0. The boys are very superstitious. They think that they can do well at the Olympiad if they begin with laying all the cards in a row so that: * there wouldn't be a pair of any side-adjacent cards with zeroes in a row; * there wouldn't be a group of three consecutive cards containing numbers one. Today Vanya brought n cards with zeroes and m cards with numbers one. The number of cards was so much that the friends do not know how to put all those cards in the described way. Help them find the required arrangement of the cards or else tell the guys that it is impossible to arrange cards in such a way. Input The first line contains two integers: n (1 ≤ n ≤ 106) — the number of cards containing number 0; m (1 ≤ m ≤ 106) — the number of cards containing number 1. Output In a single line print the required sequence of zeroes and ones without any spaces. If such sequence is impossible to obtain, print -1. Examples Input 1 2 Output 101 Input 4 8 Output 110110110101 Input 4 10 Output 11011011011011 Input 1 5 Output -1
instruction
0
35,500
19
71,000
Tags: constructive algorithms, greedy, implementation Correct Solution: ``` n,m = list(map(int,input().split())) if m>(n+1)*2 or m<n-1: print(-1) else: a = '10'*n p = m-n s = '' i = 0 if p<0: print(a[1:]) elif p==0: print(a) else: v = min(n,p) s = '110'*v vl = p-v vn = n-v if vl>0: s+='1'*vl if vn>0: s+='10'*vn print(s) ```
output
1
35,500
19
71,001
Provide tags and a correct Python 3 solution for this coding contest problem. Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork. For each team Olympiad, Vanya takes his play cards with numbers. He takes only the cards containing numbers 1 and 0. The boys are very superstitious. They think that they can do well at the Olympiad if they begin with laying all the cards in a row so that: * there wouldn't be a pair of any side-adjacent cards with zeroes in a row; * there wouldn't be a group of three consecutive cards containing numbers one. Today Vanya brought n cards with zeroes and m cards with numbers one. The number of cards was so much that the friends do not know how to put all those cards in the described way. Help them find the required arrangement of the cards or else tell the guys that it is impossible to arrange cards in such a way. Input The first line contains two integers: n (1 ≤ n ≤ 106) — the number of cards containing number 0; m (1 ≤ m ≤ 106) — the number of cards containing number 1. Output In a single line print the required sequence of zeroes and ones without any spaces. If such sequence is impossible to obtain, print -1. Examples Input 1 2 Output 101 Input 4 8 Output 110110110101 Input 4 10 Output 11011011011011 Input 1 5 Output -1
instruction
0
35,501
19
71,002
Tags: constructive algorithms, greedy, implementation Correct Solution: ``` from collections import Counter,defaultdict from math import factorial as fact #t = int(input()) n,m = [int(x) for x in input().split()] if n>m+1 or (m-2)/n>2: print(-1) else: if n==m+1: print('01'*m+'0') elif n==m: print('01'*m) else: while m>n and n!=0: print('110',end='') m-=2 n-=1 ok = False while m!=n: ok = True print('1',end='') m-=1 if ok: print('01'*m) else: print('10'*m) ```
output
1
35,501
19
71,003
Provide tags and a correct Python 3 solution for this coding contest problem. Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork. For each team Olympiad, Vanya takes his play cards with numbers. He takes only the cards containing numbers 1 and 0. The boys are very superstitious. They think that they can do well at the Olympiad if they begin with laying all the cards in a row so that: * there wouldn't be a pair of any side-adjacent cards with zeroes in a row; * there wouldn't be a group of three consecutive cards containing numbers one. Today Vanya brought n cards with zeroes and m cards with numbers one. The number of cards was so much that the friends do not know how to put all those cards in the described way. Help them find the required arrangement of the cards or else tell the guys that it is impossible to arrange cards in such a way. Input The first line contains two integers: n (1 ≤ n ≤ 106) — the number of cards containing number 0; m (1 ≤ m ≤ 106) — the number of cards containing number 1. Output In a single line print the required sequence of zeroes and ones without any spaces. If such sequence is impossible to obtain, print -1. Examples Input 1 2 Output 101 Input 4 8 Output 110110110101 Input 4 10 Output 11011011011011 Input 1 5 Output -1
instruction
0
35,502
19
71,004
Tags: constructive algorithms, greedy, implementation Correct Solution: ``` m, n = map(int, input().split()) if(n >= m-1 and n<=2*(m+1)): if(n == m-1): print("01"*n,"0",sep="") else: while(n > m and m > 0): print("110",end="") n -= 2 m -= 1 if(m==n and m>0): print("10"*m,end="") elif(n>0 and m == 0): print("1"*n,end="") print() else: print(-1) ```
output
1
35,502
19
71,005
Provide tags and a correct Python 3 solution for this coding contest problem. Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork. For each team Olympiad, Vanya takes his play cards with numbers. He takes only the cards containing numbers 1 and 0. The boys are very superstitious. They think that they can do well at the Olympiad if they begin with laying all the cards in a row so that: * there wouldn't be a pair of any side-adjacent cards with zeroes in a row; * there wouldn't be a group of three consecutive cards containing numbers one. Today Vanya brought n cards with zeroes and m cards with numbers one. The number of cards was so much that the friends do not know how to put all those cards in the described way. Help them find the required arrangement of the cards or else tell the guys that it is impossible to arrange cards in such a way. Input The first line contains two integers: n (1 ≤ n ≤ 106) — the number of cards containing number 0; m (1 ≤ m ≤ 106) — the number of cards containing number 1. Output In a single line print the required sequence of zeroes and ones without any spaces. If such sequence is impossible to obtain, print -1. Examples Input 1 2 Output 101 Input 4 8 Output 110110110101 Input 4 10 Output 11011011011011 Input 1 5 Output -1
instruction
0
35,503
19
71,006
Tags: constructive algorithms, greedy, implementation Correct Solution: ``` n,m=map(int,input().split()) if(m<=2*(n+1) and m>=n-1): if(n==m): s='01'*(n) print(s) elif(n<m): s='' while(True): if(n==m or n<=0 or m<=0): break s+='110' m-=2 n-=1 if(n==m and n!=0 and m!=0): x='10'*n print(s+x) elif(n==0 and m!=0): x='1'*m print(s+x) elif(n!=0 and m==0): x='0'*n print(s+x) else: print(s) elif(n>m): s='01'*m s+='0' print(s) else: print(-1) ```
output
1
35,503
19
71,007
Provide tags and a correct Python 3 solution for this coding contest problem. Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork. For each team Olympiad, Vanya takes his play cards with numbers. He takes only the cards containing numbers 1 and 0. The boys are very superstitious. They think that they can do well at the Olympiad if they begin with laying all the cards in a row so that: * there wouldn't be a pair of any side-adjacent cards with zeroes in a row; * there wouldn't be a group of three consecutive cards containing numbers one. Today Vanya brought n cards with zeroes and m cards with numbers one. The number of cards was so much that the friends do not know how to put all those cards in the described way. Help them find the required arrangement of the cards or else tell the guys that it is impossible to arrange cards in such a way. Input The first line contains two integers: n (1 ≤ n ≤ 106) — the number of cards containing number 0; m (1 ≤ m ≤ 106) — the number of cards containing number 1. Output In a single line print the required sequence of zeroes and ones without any spaces. If such sequence is impossible to obtain, print -1. Examples Input 1 2 Output 101 Input 4 8 Output 110110110101 Input 4 10 Output 11011011011011 Input 1 5 Output -1
instruction
0
35,504
19
71,008
Tags: constructive algorithms, greedy, implementation Correct Solution: ``` from sys import stdin,stdout from math import gcd, ceil, sqrt ii1 = lambda: int(stdin.readline().strip()) is1 = lambda: stdin.readline().strip() iia = lambda: list(map(int, stdin.readline().strip().split())) isa = lambda: stdin.readline().strip().split() mod = 1000000007 n, m = iia() res = "" if m < n - 1 or 2 * n < m - 2: print("-1") elif n > m: print('01' * m + '0') elif n == m: print('01' * m) else: print(('10' * n + '1').replace('1', '11', m - n - 1)) ```
output
1
35,504
19
71,009
Provide tags and a correct Python 3 solution for this coding contest problem. Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork. For each team Olympiad, Vanya takes his play cards with numbers. He takes only the cards containing numbers 1 and 0. The boys are very superstitious. They think that they can do well at the Olympiad if they begin with laying all the cards in a row so that: * there wouldn't be a pair of any side-adjacent cards with zeroes in a row; * there wouldn't be a group of three consecutive cards containing numbers one. Today Vanya brought n cards with zeroes and m cards with numbers one. The number of cards was so much that the friends do not know how to put all those cards in the described way. Help them find the required arrangement of the cards or else tell the guys that it is impossible to arrange cards in such a way. Input The first line contains two integers: n (1 ≤ n ≤ 106) — the number of cards containing number 0; m (1 ≤ m ≤ 106) — the number of cards containing number 1. Output In a single line print the required sequence of zeroes and ones without any spaces. If such sequence is impossible to obtain, print -1. Examples Input 1 2 Output 101 Input 4 8 Output 110110110101 Input 4 10 Output 11011011011011 Input 1 5 Output -1
instruction
0
35,505
19
71,010
Tags: constructive algorithms, greedy, implementation Correct Solution: ``` n,m=map(int,input().split()) if(n==m or n==m-1): s='' s2="10" while(len(s)<m+n): s=s+s2 s=s[:m+n] print(s) elif(n==m+1): s='' s2="01" while(len(s)<m+n): s=s+s2 s=s[:m+n] print(s) else: if((m > n and m <= 2 * (n + 1))): s="110" c1=n c2=m s1='' while(c1!=c2 and (c1>0 or c2>0)): s1=s1+s c1-=1 c2-=2 if(c1==c2): s2='10' s1=s1+(c2*s2) s1=s1[:m+n] print(s1) else: print(-1) ```
output
1
35,505
19
71,011
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork. For each team Olympiad, Vanya takes his play cards with numbers. He takes only the cards containing numbers 1 and 0. The boys are very superstitious. They think that they can do well at the Olympiad if they begin with laying all the cards in a row so that: * there wouldn't be a pair of any side-adjacent cards with zeroes in a row; * there wouldn't be a group of three consecutive cards containing numbers one. Today Vanya brought n cards with zeroes and m cards with numbers one. The number of cards was so much that the friends do not know how to put all those cards in the described way. Help them find the required arrangement of the cards or else tell the guys that it is impossible to arrange cards in such a way. Input The first line contains two integers: n (1 ≤ n ≤ 106) — the number of cards containing number 0; m (1 ≤ m ≤ 106) — the number of cards containing number 1. Output In a single line print the required sequence of zeroes and ones without any spaces. If such sequence is impossible to obtain, print -1. Examples Input 1 2 Output 101 Input 4 8 Output 110110110101 Input 4 10 Output 11011011011011 Input 1 5 Output -1 Submitted Solution: ``` ''' Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork. For each team Olympiad, Vanya takes his play cards with numbers. He takes only the cards containing numbers 1 and 0. The boys are very superstitious. They think that they can do well at the Olympiad if they begin with laying all the cards in a row so that: there wouldn't be a pair of any side-adjacent cards with zeroes in a row; there wouldn't be a group of three consecutive cards containing numbers one. Today Vanya brought n cards with zeroes and m cards with numbers one. The number of cards was so much that the friends do not know how to put all those cards in the described way. Help them find the required arrangement of the cards or else tell the guys that it is impossible to arrange cards in such a wa 4 10 2 6 4 12 11011011011011 11011011 10/4 = 2 11011011011011 2 6 11011011 11011011011 1 3 1101 2 11101110111 110110101011 4 7 11010101011 101010101 11010101011 1101 ''' # # # n, m = list(map(int,input().split())) # # print(n,m) # # if(m < n-1 ) or (m > 2*n +2): # print(-1) # elif(n==m): # print('10'*n) # elif(m<n): # print('0'+'10'*m) # else: # n2 = n/2 # n1 = n-(n/2) # if n2<=m: # print('110'*n2 + '10'*n1 + '11'*()) # else: # print("110"*) # print(m/n) # if(int(m/n)==1): # # print('11') # x = '110'*(m%n) # x += '10'*(n-(m%n)) # t = m%n # print(x) # if(int(m/n)==2): # x = '110'*(n) # t = m % n # if (t == 1): # x += '1' # elif (t == 2): # x += '1' # x += '1' # elif (t == 3): # x += '1' # x += '1' # x = '1'+x # print(x) # elif(n/m == 3): # pass # # else: # if(n == 1 and m ==3): # print('1101') # else: # print('11011') z, o = list(map(int, input().split())) # print(z, o) a = 0; b= 0; c= 0 yy = 0 if(o>z): # yy = min(z-1, o/2) # if z>=yy: for i in range(z, 0, -1): if(i*2<=o and (o - i*2) >= (z-i)): a = int(i) break # print('a',a) aa = 0 # if(a>=1): a = int(a) aa = yy z = z - a # print('--==--', o) o = o - 2*a b = z # print('a z o ',a,z,o,b) aaa = 0 if(z): mi = min(z,o) # print('herer',z,o) b = mi z -= b o -= b xx = '' x = '' # print('-->>', o) # print('-=-=', o,z) if(z): if z==1: xx = '0' else: x = '-1' elif(o>=3): x = '-1' elif(o>0): x = '1'*int(o) # print(a,b,x,z,o) if(x == '-1'): print(x) else: print(xx + '110'*int(a)+'10'*int(b)+x) ```
instruction
0
35,506
19
71,012
Yes
output
1
35,506
19
71,013
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork. For each team Olympiad, Vanya takes his play cards with numbers. He takes only the cards containing numbers 1 and 0. The boys are very superstitious. They think that they can do well at the Olympiad if they begin with laying all the cards in a row so that: * there wouldn't be a pair of any side-adjacent cards with zeroes in a row; * there wouldn't be a group of three consecutive cards containing numbers one. Today Vanya brought n cards with zeroes and m cards with numbers one. The number of cards was so much that the friends do not know how to put all those cards in the described way. Help them find the required arrangement of the cards or else tell the guys that it is impossible to arrange cards in such a way. Input The first line contains two integers: n (1 ≤ n ≤ 106) — the number of cards containing number 0; m (1 ≤ m ≤ 106) — the number of cards containing number 1. Output In a single line print the required sequence of zeroes and ones without any spaces. If such sequence is impossible to obtain, print -1. Examples Input 1 2 Output 101 Input 4 8 Output 110110110101 Input 4 10 Output 11011011011011 Input 1 5 Output -1 Submitted Solution: ``` def f(n,m): if m>n+1 or n>2*(m+1): return -1 elif m==n+1: return "01"*n+str(0) elif n==2*m+2: return "110"*m+str(11) elif n==2*m+1: return "110"*m+str(1) else: d1=n-m d2=2*m-n return "110"*d1+"10"*d2 nm=list(map(int, input().rstrip().split())) n=nm[1] m=nm[0] print(f(n,m)) ```
instruction
0
35,507
19
71,014
Yes
output
1
35,507
19
71,015
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork. For each team Olympiad, Vanya takes his play cards with numbers. He takes only the cards containing numbers 1 and 0. The boys are very superstitious. They think that they can do well at the Olympiad if they begin with laying all the cards in a row so that: * there wouldn't be a pair of any side-adjacent cards with zeroes in a row; * there wouldn't be a group of three consecutive cards containing numbers one. Today Vanya brought n cards with zeroes and m cards with numbers one. The number of cards was so much that the friends do not know how to put all those cards in the described way. Help them find the required arrangement of the cards or else tell the guys that it is impossible to arrange cards in such a way. Input The first line contains two integers: n (1 ≤ n ≤ 106) — the number of cards containing number 0; m (1 ≤ m ≤ 106) — the number of cards containing number 1. Output In a single line print the required sequence of zeroes and ones without any spaces. If such sequence is impossible to obtain, print -1. Examples Input 1 2 Output 101 Input 4 8 Output 110110110101 Input 4 10 Output 11011011011011 Input 1 5 Output -1 Submitted Solution: ``` import random import math from collections import defaultdict import itertools from sys import stdin, stdout import sys import operator from decimal import Decimal # sys.setrecursionlimit(10**6) p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.buffer.readline()) def MI(): return map(int, sys.stdin.buffer.readline().split()) def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def BI(): return sys.stdin.buffer.readline().rstrip() def SI(): return sys.stdin.buffer.readline().rstrip().decode() def main(): # z = '' # p = lambda *a: print(*a, flush = True) # d = defaultdict() #mod = 10 ** 9 + 7 #for _ in range(int(input())): #n = int(input()) n, m = [int(i) for i in input().split()] #a = input().split() #b = list(map(int, input().split())) # s = SI() # c = LI() if m> 2*(n+1): print(-1) elif n>m+1: print(-1) else: s = '' if m == 2*(n+1): s+= '11' m-=2 elif m == 2*n+1: s+= '1' m-=1 while n>0: s+= '0' if m>1 and m>n: s+= '11' m-=2 else: if m>0: s+= '1' m-=1 n-=1 print(s) # print(b) # s = input() # s = input() # z += str(ans) + '\n' # print(len(ans), ' '.join(map(str, ans)), sep='\n') # stdout.write(z) # for interactive problems # print("? {} {}".format(l,m), flush=True) # or print this after each print statement # sys.stdout.flush() if __name__ == "__main__": main() ```
instruction
0
35,508
19
71,016
Yes
output
1
35,508
19
71,017
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork. For each team Olympiad, Vanya takes his play cards with numbers. He takes only the cards containing numbers 1 and 0. The boys are very superstitious. They think that they can do well at the Olympiad if they begin with laying all the cards in a row so that: * there wouldn't be a pair of any side-adjacent cards with zeroes in a row; * there wouldn't be a group of three consecutive cards containing numbers one. Today Vanya brought n cards with zeroes and m cards with numbers one. The number of cards was so much that the friends do not know how to put all those cards in the described way. Help them find the required arrangement of the cards or else tell the guys that it is impossible to arrange cards in such a way. Input The first line contains two integers: n (1 ≤ n ≤ 106) — the number of cards containing number 0; m (1 ≤ m ≤ 106) — the number of cards containing number 1. Output In a single line print the required sequence of zeroes and ones without any spaces. If such sequence is impossible to obtain, print -1. Examples Input 1 2 Output 101 Input 4 8 Output 110110110101 Input 4 10 Output 11011011011011 Input 1 5 Output -1 Submitted Solution: ``` n, m = map(int, input().split()) if 2 * (n+ 1) < m or n - m > 1: print(-1) else: while m - n > 1 and m >0 and n > 0: print("110", end = "") m -= 2 n -= 1 while (m - n == 1 or n == m) and m > 0 and n > 0: print("10", end = "") m -= 1 n -= 1 while n - m == 1 and m > 0 and n > 0: print("01", end= "") m -= 1 n -= 1 while m > 0 : print("1", end = "") m -= 1 while n > 0 : print("0", end = "") n -= 1 ```
instruction
0
35,509
19
71,018
Yes
output
1
35,509
19
71,019
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork. For each team Olympiad, Vanya takes his play cards with numbers. He takes only the cards containing numbers 1 and 0. The boys are very superstitious. They think that they can do well at the Olympiad if they begin with laying all the cards in a row so that: * there wouldn't be a pair of any side-adjacent cards with zeroes in a row; * there wouldn't be a group of three consecutive cards containing numbers one. Today Vanya brought n cards with zeroes and m cards with numbers one. The number of cards was so much that the friends do not know how to put all those cards in the described way. Help them find the required arrangement of the cards or else tell the guys that it is impossible to arrange cards in such a way. Input The first line contains two integers: n (1 ≤ n ≤ 106) — the number of cards containing number 0; m (1 ≤ m ≤ 106) — the number of cards containing number 1. Output In a single line print the required sequence of zeroes and ones without any spaces. If such sequence is impossible to obtain, print -1. Examples Input 1 2 Output 101 Input 4 8 Output 110110110101 Input 4 10 Output 11011011011011 Input 1 5 Output -1 Submitted Solution: ``` zeros, ones = [int(i) for i in input().split()] if ones > (zeros*2)+2: print(-1) elif zeros > (ones+1): print(-1) elif ones >= zeros: x = ones//zeros arr = [] rem = ones - (x * zeros) temp1 = 0 if rem > 0: temp1 = rem-2 for i in range(temp1): arr += (([1] * (x+1)) + [0]) rem -= temp1 for i in range(temp1,zeros): arr += (([1]*x)+[0]) arr += ([1]*rem) n = [str(i) for i in arr] n = "".join(n) print(int(n)) elif zeros > ones: x = zeros//ones arr = [0] for i in range(zeros-1): arr += ([1,0]) n = [str(i) for i in arr] n = "".join(n) print(int(n)) ```
instruction
0
35,510
19
71,020
No
output
1
35,510
19
71,021
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork. For each team Olympiad, Vanya takes his play cards with numbers. He takes only the cards containing numbers 1 and 0. The boys are very superstitious. They think that they can do well at the Olympiad if they begin with laying all the cards in a row so that: * there wouldn't be a pair of any side-adjacent cards with zeroes in a row; * there wouldn't be a group of three consecutive cards containing numbers one. Today Vanya brought n cards with zeroes and m cards with numbers one. The number of cards was so much that the friends do not know how to put all those cards in the described way. Help them find the required arrangement of the cards or else tell the guys that it is impossible to arrange cards in such a way. Input The first line contains two integers: n (1 ≤ n ≤ 106) — the number of cards containing number 0; m (1 ≤ m ≤ 106) — the number of cards containing number 1. Output In a single line print the required sequence of zeroes and ones without any spaces. If such sequence is impossible to obtain, print -1. Examples Input 1 2 Output 101 Input 4 8 Output 110110110101 Input 4 10 Output 11011011011011 Input 1 5 Output -1 Submitted Solution: ``` num=list();m,n=map(int,input().split()) if(((m-1)<=n and n<=2*(m+1))): if(m==n or n==m-1): num=['10']*m if(n==m-1):num.append('1') else: while(m!=0 or n!=0): if(n>m and m>0): n-=2;m-=1 num.append('110') elif(m==0): num.append('1') n-=1 else: num.append('10') m-=1;n-=1 print(*num,sep='') else:print(-1) ```
instruction
0
35,511
19
71,022
No
output
1
35,511
19
71,023
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork. For each team Olympiad, Vanya takes his play cards with numbers. He takes only the cards containing numbers 1 and 0. The boys are very superstitious. They think that they can do well at the Olympiad if they begin with laying all the cards in a row so that: * there wouldn't be a pair of any side-adjacent cards with zeroes in a row; * there wouldn't be a group of three consecutive cards containing numbers one. Today Vanya brought n cards with zeroes and m cards with numbers one. The number of cards was so much that the friends do not know how to put all those cards in the described way. Help them find the required arrangement of the cards or else tell the guys that it is impossible to arrange cards in such a way. Input The first line contains two integers: n (1 ≤ n ≤ 106) — the number of cards containing number 0; m (1 ≤ m ≤ 106) — the number of cards containing number 1. Output In a single line print the required sequence of zeroes and ones without any spaces. If such sequence is impossible to obtain, print -1. Examples Input 1 2 Output 101 Input 4 8 Output 110110110101 Input 4 10 Output 11011011011011 Input 1 5 Output -1 Submitted Solution: ``` n,m = map(int,input().split()) s = "" if (m+1< n or m > 2*(n+1)): print(-1) else: if n==m: s = "01"*n n=0 m= 0 print(s) elif n==m-1: s = "101"+ "01"*(n-1) n=0 m=0 print(s) else: k = n+m i = 0 while(n > 0 and m > 0 ): if m>=1: s+="1" m-=1 if n>=1: s+="0" n-=1 i+=2 x = len(s) s= list(s) for i in range(0,x): if s[i]== "1": s[i] = "11" print("".join(s)) ```
instruction
0
35,512
19
71,024
No
output
1
35,512
19
71,025
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork. For each team Olympiad, Vanya takes his play cards with numbers. He takes only the cards containing numbers 1 and 0. The boys are very superstitious. They think that they can do well at the Olympiad if they begin with laying all the cards in a row so that: * there wouldn't be a pair of any side-adjacent cards with zeroes in a row; * there wouldn't be a group of three consecutive cards containing numbers one. Today Vanya brought n cards with zeroes and m cards with numbers one. The number of cards was so much that the friends do not know how to put all those cards in the described way. Help them find the required arrangement of the cards or else tell the guys that it is impossible to arrange cards in such a way. Input The first line contains two integers: n (1 ≤ n ≤ 106) — the number of cards containing number 0; m (1 ≤ m ≤ 106) — the number of cards containing number 1. Output In a single line print the required sequence of zeroes and ones without any spaces. If such sequence is impossible to obtain, print -1. Examples Input 1 2 Output 101 Input 4 8 Output 110110110101 Input 4 10 Output 11011011011011 Input 1 5 Output -1 Submitted Solution: ``` n, m = map(int, input().split()) s = [] if not (n-1 <= m and m <= 2 * (n+1)): print(-1) exit() if m == n-1: print("1" + "01"*(n-1)) elif m-1 <= n: print("110" * (m-1) + "10"*(n-m+1)) else: print("110"*n + "1"*(m-n-1)) ```
instruction
0
35,513
19
71,026
No
output
1
35,513
19
71,027