message
stringlengths
2
65.1k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
0
108k
cluster
float64
14
14
__index_level_0__
int64
0
217k
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Cowboy Vlad has a birthday today! There are n children who came to the celebration. In order to greet Vlad, the children decided to form a circle around him. Among the children who came, there are both tall and low, so if they stand in a circle arbitrarily, it may turn out, that there is a tall and low child standing next to each other, and it will be difficult for them to hold hands. Therefore, children want to stand in a circle so that the maximum difference between the growth of two neighboring children would be minimal possible. Formally, let's number children from 1 to n in a circle order, that is, for every i child with number i will stand next to the child with number i+1, also the child with number 1 stands next to the child with number n. Then we will call the discomfort of the circle the maximum absolute difference of heights of the children, who stand next to each other. Please help children to find out how they should reorder themselves, so that the resulting discomfort is smallest possible. Input The first line contains a single integer n (2 ≤ n ≤ 100) — the number of the children who came to the cowboy Vlad's birthday. The second line contains integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^9) denoting heights of every child. Output Print exactly n integers — heights of the children in the order in which they should stand in a circle. You can start printing a circle with any child. If there are multiple possible answers, print any of them. Examples Input 5 2 1 1 3 2 Output 1 2 3 2 1 Input 3 30 10 20 Output 10 20 30 Note In the first example, the discomfort of the circle is equal to 1, since the corresponding absolute differences are 1, 1, 1 and 0. Note, that sequences [2, 3, 2, 1, 1] and [3, 2, 1, 1, 2] form the same circles and differ only by the selection of the starting point. In the second example, the discomfort of the circle is equal to 20, since the absolute difference of 10 and 30 is equal to 20. Submitted Solution: ``` n=int(input()) mas=list(map(int,input().split())) mas.sort() s='' for i in range (0,len(mas),2): print(mas[i], end=' ') if len(mas)%2==0: for i in range (len(mas)-1,-1,-2): print(mas[i],end=' ') else: for i in range (len(mas)-2,-1,-2): print(mas[i],end=' ') ```
instruction
0
35,195
14
70,390
Yes
output
1
35,195
14
70,391
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Cowboy Vlad has a birthday today! There are n children who came to the celebration. In order to greet Vlad, the children decided to form a circle around him. Among the children who came, there are both tall and low, so if they stand in a circle arbitrarily, it may turn out, that there is a tall and low child standing next to each other, and it will be difficult for them to hold hands. Therefore, children want to stand in a circle so that the maximum difference between the growth of two neighboring children would be minimal possible. Formally, let's number children from 1 to n in a circle order, that is, for every i child with number i will stand next to the child with number i+1, also the child with number 1 stands next to the child with number n. Then we will call the discomfort of the circle the maximum absolute difference of heights of the children, who stand next to each other. Please help children to find out how they should reorder themselves, so that the resulting discomfort is smallest possible. Input The first line contains a single integer n (2 ≤ n ≤ 100) — the number of the children who came to the cowboy Vlad's birthday. The second line contains integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^9) denoting heights of every child. Output Print exactly n integers — heights of the children in the order in which they should stand in a circle. You can start printing a circle with any child. If there are multiple possible answers, print any of them. Examples Input 5 2 1 1 3 2 Output 1 2 3 2 1 Input 3 30 10 20 Output 10 20 30 Note In the first example, the discomfort of the circle is equal to 1, since the corresponding absolute differences are 1, 1, 1 and 0. Note, that sequences [2, 3, 2, 1, 1] and [3, 2, 1, 1, 2] form the same circles and differ only by the selection of the starting point. In the second example, the discomfort of the circle is equal to 20, since the absolute difference of 10 and 30 is equal to 20. Submitted Solution: ``` m = [] n = int(input()) a = list(map(int, input().split())) if n > 2: m.append(a.pop(a.index(max(a)))) while len(a) > 1: m.append(a.pop(a.index(max(a)))) m.insert(0, a.pop(a.index(max(a)))) if len(a) == 1: m.append(a[0]) print(*m) else: print(*a) ```
instruction
0
35,196
14
70,392
Yes
output
1
35,196
14
70,393
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Cowboy Vlad has a birthday today! There are n children who came to the celebration. In order to greet Vlad, the children decided to form a circle around him. Among the children who came, there are both tall and low, so if they stand in a circle arbitrarily, it may turn out, that there is a tall and low child standing next to each other, and it will be difficult for them to hold hands. Therefore, children want to stand in a circle so that the maximum difference between the growth of two neighboring children would be minimal possible. Formally, let's number children from 1 to n in a circle order, that is, for every i child with number i will stand next to the child with number i+1, also the child with number 1 stands next to the child with number n. Then we will call the discomfort of the circle the maximum absolute difference of heights of the children, who stand next to each other. Please help children to find out how they should reorder themselves, so that the resulting discomfort is smallest possible. Input The first line contains a single integer n (2 ≤ n ≤ 100) — the number of the children who came to the cowboy Vlad's birthday. The second line contains integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^9) denoting heights of every child. Output Print exactly n integers — heights of the children in the order in which they should stand in a circle. You can start printing a circle with any child. If there are multiple possible answers, print any of them. Examples Input 5 2 1 1 3 2 Output 1 2 3 2 1 Input 3 30 10 20 Output 10 20 30 Note In the first example, the discomfort of the circle is equal to 1, since the corresponding absolute differences are 1, 1, 1 and 0. Note, that sequences [2, 3, 2, 1, 1] and [3, 2, 1, 1, 2] form the same circles and differ only by the selection of the starting point. In the second example, the discomfort of the circle is equal to 20, since the absolute difference of 10 and 30 is equal to 20. Submitted Solution: ``` n=input() nlist=list(input().split()) for aa in range(0,len(nlist)): nlist[aa]=int(nlist[aa]) nlist.sort(reverse=True) elist=[] side=True for aa in nlist: if side==True: elist.append(aa) else: elist.insert(0,aa) side=not side print(*elist) ```
instruction
0
35,197
14
70,394
Yes
output
1
35,197
14
70,395
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Cowboy Vlad has a birthday today! There are n children who came to the celebration. In order to greet Vlad, the children decided to form a circle around him. Among the children who came, there are both tall and low, so if they stand in a circle arbitrarily, it may turn out, that there is a tall and low child standing next to each other, and it will be difficult for them to hold hands. Therefore, children want to stand in a circle so that the maximum difference between the growth of two neighboring children would be minimal possible. Formally, let's number children from 1 to n in a circle order, that is, for every i child with number i will stand next to the child with number i+1, also the child with number 1 stands next to the child with number n. Then we will call the discomfort of the circle the maximum absolute difference of heights of the children, who stand next to each other. Please help children to find out how they should reorder themselves, so that the resulting discomfort is smallest possible. Input The first line contains a single integer n (2 ≤ n ≤ 100) — the number of the children who came to the cowboy Vlad's birthday. The second line contains integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^9) denoting heights of every child. Output Print exactly n integers — heights of the children in the order in which they should stand in a circle. You can start printing a circle with any child. If there are multiple possible answers, print any of them. Examples Input 5 2 1 1 3 2 Output 1 2 3 2 1 Input 3 30 10 20 Output 10 20 30 Note In the first example, the discomfort of the circle is equal to 1, since the corresponding absolute differences are 1, 1, 1 and 0. Note, that sequences [2, 3, 2, 1, 1] and [3, 2, 1, 1, 2] form the same circles and differ only by the selection of the starting point. In the second example, the discomfort of the circle is equal to 20, since the absolute difference of 10 and 30 is equal to 20. Submitted Solution: ``` n = int(input()) a = list(map(int,input().split())) a.sort() for i in range(0,n,2): print(a[i],end=" ") s=[] for i in range(1,n,2): s.append(str(a[i])) s.reverse() print(" ".join(s)) ```
instruction
0
35,198
14
70,396
Yes
output
1
35,198
14
70,397
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Cowboy Vlad has a birthday today! There are n children who came to the celebration. In order to greet Vlad, the children decided to form a circle around him. Among the children who came, there are both tall and low, so if they stand in a circle arbitrarily, it may turn out, that there is a tall and low child standing next to each other, and it will be difficult for them to hold hands. Therefore, children want to stand in a circle so that the maximum difference between the growth of two neighboring children would be minimal possible. Formally, let's number children from 1 to n in a circle order, that is, for every i child with number i will stand next to the child with number i+1, also the child with number 1 stands next to the child with number n. Then we will call the discomfort of the circle the maximum absolute difference of heights of the children, who stand next to each other. Please help children to find out how they should reorder themselves, so that the resulting discomfort is smallest possible. Input The first line contains a single integer n (2 ≤ n ≤ 100) — the number of the children who came to the cowboy Vlad's birthday. The second line contains integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^9) denoting heights of every child. Output Print exactly n integers — heights of the children in the order in which they should stand in a circle. You can start printing a circle with any child. If there are multiple possible answers, print any of them. Examples Input 5 2 1 1 3 2 Output 1 2 3 2 1 Input 3 30 10 20 Output 10 20 30 Note In the first example, the discomfort of the circle is equal to 1, since the corresponding absolute differences are 1, 1, 1 and 0. Note, that sequences [2, 3, 2, 1, 1] and [3, 2, 1, 1, 2] form the same circles and differ only by the selection of the starting point. In the second example, the discomfort of the circle is equal to 20, since the absolute difference of 10 and 30 is equal to 20. Submitted Solution: ``` n = int(input()) a = list(map(int,input().split())) a = sorted(a) a = a[0:int(len(a)/2)] + list(reversed(a[int(len(a)/2):len(a)])) for i in a: print(i,end = " ") ```
instruction
0
35,199
14
70,398
No
output
1
35,199
14
70,399
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Cowboy Vlad has a birthday today! There are n children who came to the celebration. In order to greet Vlad, the children decided to form a circle around him. Among the children who came, there are both tall and low, so if they stand in a circle arbitrarily, it may turn out, that there is a tall and low child standing next to each other, and it will be difficult for them to hold hands. Therefore, children want to stand in a circle so that the maximum difference between the growth of two neighboring children would be minimal possible. Formally, let's number children from 1 to n in a circle order, that is, for every i child with number i will stand next to the child with number i+1, also the child with number 1 stands next to the child with number n. Then we will call the discomfort of the circle the maximum absolute difference of heights of the children, who stand next to each other. Please help children to find out how they should reorder themselves, so that the resulting discomfort is smallest possible. Input The first line contains a single integer n (2 ≤ n ≤ 100) — the number of the children who came to the cowboy Vlad's birthday. The second line contains integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^9) denoting heights of every child. Output Print exactly n integers — heights of the children in the order in which they should stand in a circle. You can start printing a circle with any child. If there are multiple possible answers, print any of them. Examples Input 5 2 1 1 3 2 Output 1 2 3 2 1 Input 3 30 10 20 Output 10 20 30 Note In the first example, the discomfort of the circle is equal to 1, since the corresponding absolute differences are 1, 1, 1 and 0. Note, that sequences [2, 3, 2, 1, 1] and [3, 2, 1, 1, 2] form the same circles and differ only by the selection of the starting point. In the second example, the discomfort of the circle is equal to 20, since the absolute difference of 10 and 30 is equal to 20. Submitted Solution: ``` n = int(input()) a = [int(x) for x in input().split()] a = sorted(a) b = a[::1] + a[1::2][::-1] print(*b) ```
instruction
0
35,200
14
70,400
No
output
1
35,200
14
70,401
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Cowboy Vlad has a birthday today! There are n children who came to the celebration. In order to greet Vlad, the children decided to form a circle around him. Among the children who came, there are both tall and low, so if they stand in a circle arbitrarily, it may turn out, that there is a tall and low child standing next to each other, and it will be difficult for them to hold hands. Therefore, children want to stand in a circle so that the maximum difference between the growth of two neighboring children would be minimal possible. Formally, let's number children from 1 to n in a circle order, that is, for every i child with number i will stand next to the child with number i+1, also the child with number 1 stands next to the child with number n. Then we will call the discomfort of the circle the maximum absolute difference of heights of the children, who stand next to each other. Please help children to find out how they should reorder themselves, so that the resulting discomfort is smallest possible. Input The first line contains a single integer n (2 ≤ n ≤ 100) — the number of the children who came to the cowboy Vlad's birthday. The second line contains integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^9) denoting heights of every child. Output Print exactly n integers — heights of the children in the order in which they should stand in a circle. You can start printing a circle with any child. If there are multiple possible answers, print any of them. Examples Input 5 2 1 1 3 2 Output 1 2 3 2 1 Input 3 30 10 20 Output 10 20 30 Note In the first example, the discomfort of the circle is equal to 1, since the corresponding absolute differences are 1, 1, 1 and 0. Note, that sequences [2, 3, 2, 1, 1] and [3, 2, 1, 1, 2] form the same circles and differ only by the selection of the starting point. In the second example, the discomfort of the circle is equal to 20, since the absolute difference of 10 and 30 is equal to 20. Submitted Solution: ``` from sys import stdin, stdout from math import * from heapq import * from collections import * def main(): n=int(stdin.readline()) a=[int(x) for x in stdin.readline().split()] a.sort() stdout.write(" ".join([str(x) for x in a])) return 0 if __name__ == "__main__": main() ```
instruction
0
35,201
14
70,402
No
output
1
35,201
14
70,403
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Cowboy Vlad has a birthday today! There are n children who came to the celebration. In order to greet Vlad, the children decided to form a circle around him. Among the children who came, there are both tall and low, so if they stand in a circle arbitrarily, it may turn out, that there is a tall and low child standing next to each other, and it will be difficult for them to hold hands. Therefore, children want to stand in a circle so that the maximum difference between the growth of two neighboring children would be minimal possible. Formally, let's number children from 1 to n in a circle order, that is, for every i child with number i will stand next to the child with number i+1, also the child with number 1 stands next to the child with number n. Then we will call the discomfort of the circle the maximum absolute difference of heights of the children, who stand next to each other. Please help children to find out how they should reorder themselves, so that the resulting discomfort is smallest possible. Input The first line contains a single integer n (2 ≤ n ≤ 100) — the number of the children who came to the cowboy Vlad's birthday. The second line contains integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^9) denoting heights of every child. Output Print exactly n integers — heights of the children in the order in which they should stand in a circle. You can start printing a circle with any child. If there are multiple possible answers, print any of them. Examples Input 5 2 1 1 3 2 Output 1 2 3 2 1 Input 3 30 10 20 Output 10 20 30 Note In the first example, the discomfort of the circle is equal to 1, since the corresponding absolute differences are 1, 1, 1 and 0. Note, that sequences [2, 3, 2, 1, 1] and [3, 2, 1, 1, 2] form the same circles and differ only by the selection of the starting point. In the second example, the discomfort of the circle is equal to 20, since the absolute difference of 10 and 30 is equal to 20. Submitted Solution: ``` from collections import Counter n=int(input()) arr=list(map(int,input().split())) c=Counter(arr) t=sorted(arr) seq=len(set(arr)) if seq==n: print(*t) else: mn=min(t) for i,e in enumerate(t): if e!=mn and c[e]>1: y=t[:i]+t[i+1:]+[e] print(*y) break ```
instruction
0
35,202
14
70,404
No
output
1
35,202
14
70,405
Provide tags and a correct Python 3 solution for this coding contest problem. This is the easy version of the problem. The only difference between easy and hard versions is the constraint of m. You can make hacks only if both versions are solved. Chiori loves dolls and now she is going to decorate her bedroom! <image> As a doll collector, Chiori has got n dolls. The i-th doll has a non-negative integer value a_i (a_i < 2^m, m is given). Chiori wants to pick some (maybe zero) dolls for the decoration, so there are 2^n different picking ways. Let x be the bitwise-xor-sum of values of dolls Chiori picks (in case Chiori picks no dolls x = 0). The value of this picking way is equal to the number of 1-bits in the binary representation of x. More formally, it is also equal to the number of indices 0 ≤ i < m, such that \left⌊ (x)/(2^i) \right⌋ is odd. Tell her the number of picking ways with value i for each integer i from 0 to m. Due to the answers can be very huge, print them by modulo 998 244 353. Input The first line contains two integers n and m (1 ≤ n ≤ 2 ⋅ 10^5, 0 ≤ m ≤ 35) — the number of dolls and the maximum value of the picking way. The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i < 2^m) — the values of dolls. Output Print m+1 integers p_0, p_1, …, p_m — p_i is equal to the number of picking ways with value i by modulo 998 244 353. Examples Input 4 4 3 5 8 14 Output 2 2 6 6 0 Input 6 7 11 45 14 9 19 81 Output 1 2 11 20 15 10 5 0
instruction
0
35,334
14
70,668
Tags: bitmasks, brute force, combinatorics, math Correct Solution: ``` import sys MOD = 998244353 BOUND = 21 n, m = map(int, input().split()) l = list(map(int,input().split())) basis = [] for p in range(m-1,-1,-1): p2 = pow(2,p) nex = -1 for i in range(n): if l[i] >= p2: nex = l[i] break if nex != -1: basis.append(nex) for i in range(n): if l[i] >= p2: l[i] ^= nex extra = n - len(basis) def add(a, b): out = [0] * (max(len(a), len(b))) for i in range(len(a)): out[i] = a[i] for i in range(len(b)): out[i] += b[i] out[i] %= MOD return out def addSh(a, b): out = [0] * (max(len(a) + 1, len(b))) for i in range(len(a)): out[i + 1] = a[i] for i in range(len(b)): out[i] += b[i] out[i] %= MOD return out i = 0 curr = dict() curr[0] = [1] for p in range(m-1,-1,-1): if p == m - 1 and p < BOUND: curr = [curr[i] if i in curr else [] for i in range(2 ** 20)] if p >= BOUND: p2 = pow(2,p) if i < len(basis) and basis[i] >= p2: currN = dict(curr) for v in curr: if v ^ basis[i] not in currN: currN[v ^ basis[i]] = [0] currN[v ^ basis[i]] = add(curr[v], currN[v ^ basis[i]]) curr = currN i += 1 lis = list(curr.keys()) for v in lis: if v >= p2: if v ^ p2 not in currN: curr[v ^ p2] = [0] curr[v ^ p2] = addSh(curr[v], curr[v ^ p2]) del curr[v] else: p2 = pow(2,p) if i < len(basis) and basis[i] >= p2: for v in range(p2): curr[v ^ basis[i]] = add(curr[v], curr[v ^ basis[i]]) curr[v] = curr[v ^ basis[i]] i += 1 for v in range(p2): curr[v] = addSh(curr[v ^ p2], curr[v]) if p == BOUND: curr = [curr[i] if i in curr else [] for i in range(2 ** BOUND)] out = curr[0] while len(out) < m + 1: out.append(0) for i in range(m + 1): out[i] *= pow(2, extra, MOD) out[i] %= MOD for v in out: sys.stdout.write(str(v)+' ') ```
output
1
35,334
14
70,669
Provide tags and a correct Python 3 solution for this coding contest problem. This is the easy version of the problem. The only difference between easy and hard versions is the constraint of m. You can make hacks only if both versions are solved. Chiori loves dolls and now she is going to decorate her bedroom! <image> As a doll collector, Chiori has got n dolls. The i-th doll has a non-negative integer value a_i (a_i < 2^m, m is given). Chiori wants to pick some (maybe zero) dolls for the decoration, so there are 2^n different picking ways. Let x be the bitwise-xor-sum of values of dolls Chiori picks (in case Chiori picks no dolls x = 0). The value of this picking way is equal to the number of 1-bits in the binary representation of x. More formally, it is also equal to the number of indices 0 ≤ i < m, such that \left⌊ (x)/(2^i) \right⌋ is odd. Tell her the number of picking ways with value i for each integer i from 0 to m. Due to the answers can be very huge, print them by modulo 998 244 353. Input The first line contains two integers n and m (1 ≤ n ≤ 2 ⋅ 10^5, 0 ≤ m ≤ 35) — the number of dolls and the maximum value of the picking way. The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i < 2^m) — the values of dolls. Output Print m+1 integers p_0, p_1, …, p_m — p_i is equal to the number of picking ways with value i by modulo 998 244 353. Examples Input 4 4 3 5 8 14 Output 2 2 6 6 0 Input 6 7 11 45 14 9 19 81 Output 1 2 11 20 15 10 5 0
instruction
0
35,335
14
70,670
Tags: bitmasks, brute force, combinatorics, math Correct Solution: ``` MOD = 998244353 BOUND = 19 n, m = map(int, input().split()) l = list(map(int,input().split())) basis = [] for p in range(m-1,-1,-1): p2 = pow(2,p) nex = -1 for i in range(n): if l[i] >= p2: nex = l[i] break if nex != -1: basis.append(nex) for i in range(n): if l[i] >= p2: l[i] ^= nex extra = n - len(basis) def add(a, b): out = [0] * (max(len(a), len(b))) for i in range(len(a)): out[i] = a[i] for i in range(len(b)): out[i] += b[i] out[i] %= MOD return out def addSh(a, b): out = [0] * (max(len(a) + 1, len(b))) for i in range(len(a)): out[i + 1] = a[i] for i in range(len(b)): out[i] += b[i] out[i] %= MOD return out i = 0 curr = dict() curr[0] = [1] for p in range(m-1,-1,-1): p2 = pow(2,p) if i < len(basis) and basis[i] >= p2: currN = dict(curr) for v in curr: if v ^ basis[i] not in currN: currN[v ^ basis[i]] = [0] currN[v ^ basis[i]] = add(curr[v], currN[v ^ basis[i]]) curr = currN i += 1 currN = dict(curr) for v in curr: if v >= p2: if v ^ p2 not in currN: currN[v ^ p2] = [0] currN[v ^ p2] = addSh(curr[v], currN[v ^ p2]) del currN[v] curr = currN out = curr[0] while len(out) < m + 1: out.append(0) for i in range(m + 1): out[i] *= pow(2, extra, MOD) out[i] %= MOD print(' '.join(map(str,out))) ```
output
1
35,335
14
70,671
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The cinema theater hall in Sereja's city is n seats lined up in front of one large screen. There are slots for personal possessions to the left and to the right of each seat. Any two adjacent seats have exactly one shared slot. The figure below shows the arrangement of seats and slots for n = 4. <image> Today it's the premiere of a movie called "Dry Hard". The tickets for all the seats have been sold. There is a very strict controller at the entrance to the theater, so all n people will come into the hall one by one. As soon as a person enters a cinema hall, he immediately (momentarily) takes his seat and occupies all empty slots to the left and to the right from him. If there are no empty slots, the man gets really upset and leaves. People are not very constant, so it's hard to predict the order in which the viewers will enter the hall. For some seats, Sereja knows the number of the viewer (his number in the entering queue of the viewers) that will come and take this seat. For others, it can be any order. Being a programmer and a mathematician, Sereja wonders: how many ways are there for the people to enter the hall, such that nobody gets upset? As the number can be quite large, print it modulo 1000000007 (109 + 7). Input The first line contains integer n (1 ≤ n ≤ 105). The second line contains n integers, the i-th integer shows either the index of the person (index in the entering queue) with the ticket for the i-th seat or a 0, if his index is not known. It is guaranteed that all positive numbers in the second line are distinct. You can assume that the index of the person who enters the cinema hall is a unique integer from 1 to n. The person who has index 1 comes first to the hall, the person who has index 2 comes second and so on. Output In a single line print the remainder after dividing the answer by number 1000000007 (109 + 7). Examples Input 11 0 0 0 0 0 0 0 0 0 0 0 Output 1024 Input 6 0 3 1 0 0 0 Output 3 Submitted Solution: ``` __author__ = 'asmn' n = int(input()) maxn, base = n, 1000000007 fact, inv = [1] * maxn, [1] * maxn def extgcd(a, b): if b == 0: return 1, 0 x, y = extgcd(b, a % b) return y, x - a // b * y def inverse(a, n): return extgcd(a, n)[0] def C(n, m): return fact[n] * inv[m] * inv[n - m] % base for i in range(1, maxn): fact[i] = i * fact[i - 1] % base inv[i] = inverse(fact[i], base) a = list(map(int, input().split())) a.append(n + 1) ind = [] for i, v in enumerate(a): if v > 0: ind.append((v, i)) ind.sort() def f(st, end, ans): global n if st < 0 or end > n: ans=0 #print(st, end, ans) for num, pos in ind[1:]: if st < 0 or end > n or ans == 0 or st <= pos <= end: return 0 if end < pos: #print('C',num - (end - st + 1) - 1, pos - end - 1,C(num - (end - st + 1) - 1, pos - end - 1)) ans = ans * C(num - (end - st + 1) - 1, pos - end - 1) % base st,end=pos-num+1,pos else: #print('C',num - (end - st + 1) - 1, st - pos - 1,C(num - (end - st + 1) - 1, st - pos - 1)) ans = ans * C(num - (end - st + 1) - 1, st - pos - 1) % base st,end=pos,pos+num-1 return ans def mod(x,base): return (x%base+base)%base num, pos = ind[0] if num == 1: print(mod(f(pos, pos, 1),base)) else: print(mod(f(pos, pos + num - 1, 2 ** (num - 2)) + f(pos - num + 1, pos, 2 ** (num - 2)),base)) ```
instruction
0
35,497
14
70,994
No
output
1
35,497
14
70,995
Provide tags and a correct Python 3 solution for this coding contest problem. Two participants are each given a pair of distinct numbers from 1 to 9 such that there's exactly one number that is present in both pairs. They want to figure out the number that matches by using a communication channel you have access to without revealing it to you. Both participants communicated to each other a set of pairs of numbers, that includes the pair given to them. Each pair in the communicated sets comprises two different numbers. Determine if you can with certainty deduce the common number, or if you can determine with certainty that both participants know the number but you do not. Input The first line contains two integers n and m (1 ≤ n, m ≤ 12) — the number of pairs the first participant communicated to the second and vice versa. The second line contains n pairs of integers, each between 1 and 9, — pairs of numbers communicated from first participant to the second. The third line contains m pairs of integers, each between 1 and 9, — pairs of numbers communicated from the second participant to the first. All pairs within each set are distinct (in particular, if there is a pair (1,2), there will be no pair (2,1) within the same set), and no pair contains the same number twice. It is guaranteed that the two sets do not contradict the statements, in other words, there is pair from the first set and a pair from the second set that share exactly one number. Output If you can deduce the shared number with certainty, print that number. If you can with certainty deduce that both participants know the shared number, but you do not know it, print 0. Otherwise print -1. Examples Input 2 2 1 2 3 4 1 5 3 4 Output 1 Input 2 2 1 2 3 4 1 5 6 4 Output 0 Input 2 3 1 2 4 5 1 2 1 3 2 3 Output -1 Note In the first example the first participant communicated pairs (1,2) and (3,4), and the second communicated (1,5), (3,4). Since we know that the actual pairs they received share exactly one number, it can't be that they both have (3,4). Thus, the first participant has (1,2) and the second has (1,5), and at this point you already know the shared number is 1. In the second example either the first participant has (1,2) and the second has (1,5), or the first has (3,4) and the second has (6,4). In the first case both of them know the shared number is 1, in the second case both of them know the shared number is 4. You don't have enough information to tell 1 and 4 apart. In the third case if the first participant was given (1,2), they don't know what the shared number is, since from their perspective the second participant might have been given either (1,3), in which case the shared number is 1, or (2,3), in which case the shared number is 2. While the second participant does know the number with certainty, neither you nor the first participant do, so the output is -1.
instruction
0
35,729
14
71,458
Tags: bitmasks, brute force Correct Solution: ``` #Code by Sounak, IIESTS #------------------------------warmup---------------------------- import os import sys import math from io import BytesIO, IOBase import io from fractions import Fraction import collections from itertools import permutations from collections import defaultdict from collections import deque from collections import Counter import threading #sys.setrecursionlimit(300000) #threading.stack_size(10**8) 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") #-------------------game starts now----------------------------------------------------- #mod = 9223372036854775807 class SegmentTree: def __init__(self, data, default=0, func=lambda a, b: max(a,b)): """initialize the segment tree with data""" self._default = default self._func = func self._len = len(data) self._size = _size = 1 << (self._len - 1).bit_length() self.data = [default] * (2 * _size) self.data[_size:_size + self._len] = data for i in reversed(range(_size)): self.data[i] = func(self.data[i + i], self.data[i + i + 1]) def __delitem__(self, idx): self[idx] = self._default def __getitem__(self, idx): return self.data[idx + self._size] def __setitem__(self, idx, value): idx += self._size self.data[idx] = value idx >>= 1 while idx: self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1]) idx >>= 1 def __len__(self): return self._len def query(self, start, stop): if start == stop: return self.__getitem__(start) stop += 1 start += self._size stop += self._size res = self._default while start < stop: if start & 1: res = self._func(res, self.data[start]) start += 1 if stop & 1: stop -= 1 res = self._func(res, self.data[stop]) start >>= 1 stop >>= 1 return res def __repr__(self): return "SegmentTree({0})".format(self.data) class SegmentTree1: def __init__(self, data, default=0, func=lambda a, b: a+b): """initialize the segment tree with data""" self._default = default self._func = func self._len = len(data) self._size = _size = 1 << (self._len - 1).bit_length() self.data = [default] * (2 * _size) self.data[_size:_size + self._len] = data for i in reversed(range(_size)): self.data[i] = func(self.data[i + i], self.data[i + i + 1]) def __delitem__(self, idx): self[idx] = self._default def __getitem__(self, idx): return self.data[idx + self._size] def __setitem__(self, idx, value): idx += self._size self.data[idx] = value idx >>= 1 while idx: self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1]) idx >>= 1 def __len__(self): return self._len def query(self, start, stop): if start == stop: return self.__getitem__(start) stop += 1 start += self._size stop += self._size res = self._default while start < stop: if start & 1: res = self._func(res, self.data[start]) start += 1 if stop & 1: stop -= 1 res = self._func(res, self.data[stop]) start >>= 1 stop >>= 1 return res def __repr__(self): return "SegmentTree({0})".format(self.data) MOD=10**9+7 class Factorial: def __init__(self, MOD): self.MOD = MOD self.factorials = [1, 1] self.invModulos = [0, 1] self.invFactorial_ = [1, 1] def calc(self, n): if n <= -1: print("Invalid argument to calculate n!") print("n must be non-negative value. But the argument was " + str(n)) exit() if n < len(self.factorials): return self.factorials[n] nextArr = [0] * (n + 1 - len(self.factorials)) initialI = len(self.factorials) prev = self.factorials[-1] m = self.MOD for i in range(initialI, n + 1): prev = nextArr[i - initialI] = prev * i % m self.factorials += nextArr return self.factorials[n] def inv(self, n): if n <= -1: print("Invalid argument to calculate n^(-1)") print("n must be non-negative value. But the argument was " + str(n)) exit() p = self.MOD pi = n % p if pi < len(self.invModulos): return self.invModulos[pi] nextArr = [0] * (n + 1 - len(self.invModulos)) initialI = len(self.invModulos) for i in range(initialI, min(p, n + 1)): next = -self.invModulos[p % i] * (p // i) % p self.invModulos.append(next) return self.invModulos[pi] def invFactorial(self, n): if n <= -1: print("Invalid argument to calculate (n^(-1))!") print("n must be non-negative value. But the argument was " + str(n)) exit() if n < len(self.invFactorial_): return self.invFactorial_[n] self.inv(n) # To make sure already calculated n^-1 nextArr = [0] * (n + 1 - len(self.invFactorial_)) initialI = len(self.invFactorial_) prev = self.invFactorial_[-1] p = self.MOD for i in range(initialI, n + 1): prev = nextArr[i - initialI] = (prev * self.invModulos[i % p]) % p self.invFactorial_ += nextArr return self.invFactorial_[n] class Combination: def __init__(self, MOD): self.MOD = MOD self.factorial = Factorial(MOD) def ncr(self, n, k): if k < 0 or n < k: return 0 k = min(k, n - k) f = self.factorial return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD mod=10**9+7 omod=998244353 #------------------------------------------------------------------------- prime = [True for i in range(10001)] prime[0]=prime[1]=False #pp=[0]*10000 def SieveOfEratosthenes(n=10000): p = 2 c=0 while (p <= n): if (prime[p] == True): c+=1 for i in range(p, n+1, p): #pp[i]=1 prime[i] = False p += 1 #-----------------------------------DSU-------------------------------------------------- class DSU: def __init__(self, R, C): #R * C is the source, and isn't a grid square self.par = range(R*C + 1) self.rnk = [0] * (R*C + 1) self.sz = [1] * (R*C + 1) def find(self, x): if self.par[x] != x: self.par[x] = self.find(self.par[x]) return self.par[x] def union(self, x, y): xr, yr = self.find(x), self.find(y) if xr == yr: return if self.rnk[xr] < self.rnk[yr]: xr, yr = yr, xr if self.rnk[xr] == self.rnk[yr]: self.rnk[xr] += 1 self.par[yr] = xr self.sz[xr] += self.sz[yr] def size(self, x): return self.sz[self.find(x)] def top(self): # Size of component at ephemeral "source" node at index R*C, # minus 1 to not count the source itself in the size return self.size(len(self.sz) - 1) - 1 #---------------------------------Lazy Segment Tree-------------------------------------- # https://github.com/atcoder/ac-library/blob/master/atcoder/lazysegtree.hpp class LazySegTree: def __init__(self, _op, _e, _mapping, _composition, _id, v): def set(p, x): assert 0 <= p < _n p += _size for i in range(_log, 0, -1): _push(p >> i) _d[p] = x for i in range(1, _log + 1): _update(p >> i) def get(p): assert 0 <= p < _n p += _size for i in range(_log, 0, -1): _push(p >> i) return _d[p] def prod(l, r): assert 0 <= l <= r <= _n if l == r: return _e l += _size r += _size for i in range(_log, 0, -1): if ((l >> i) << i) != l: _push(l >> i) if ((r >> i) << i) != r: _push(r >> i) sml = _e smr = _e while l < r: if l & 1: sml = _op(sml, _d[l]) l += 1 if r & 1: r -= 1 smr = _op(_d[r], smr) l >>= 1 r >>= 1 return _op(sml, smr) def apply(l, r, f): assert 0 <= l <= r <= _n if l == r: return l += _size r += _size for i in range(_log, 0, -1): if ((l >> i) << i) != l: _push(l >> i) if ((r >> i) << i) != r: _push((r - 1) >> i) l2 = l r2 = r while l < r: if l & 1: _all_apply(l, f) l += 1 if r & 1: r -= 1 _all_apply(r, f) l >>= 1 r >>= 1 l = l2 r = r2 for i in range(1, _log + 1): if ((l >> i) << i) != l: _update(l >> i) if ((r >> i) << i) != r: _update((r - 1) >> i) def _update(k): _d[k] = _op(_d[2 * k], _d[2 * k + 1]) def _all_apply(k, f): _d[k] = _mapping(f, _d[k]) if k < _size: _lz[k] = _composition(f, _lz[k]) def _push(k): _all_apply(2 * k, _lz[k]) _all_apply(2 * k + 1, _lz[k]) _lz[k] = _id _n = len(v) _log = _n.bit_length() _size = 1 << _log _d = [_e] * (2 * _size) _lz = [_id] * _size for i in range(_n): _d[_size + i] = v[i] for i in range(_size - 1, 0, -1): _update(i) self.set = set self.get = get self.prod = prod self.apply = apply MIL = 1 << 20 def makeNode(total, count): # Pack a pair into a float return (total * MIL) + count def getTotal(node): return math.floor(node / MIL) def getCount(node): return node - getTotal(node) * MIL nodeIdentity = makeNode(0.0, 0.0) def nodeOp(node1, node2): return node1 + node2 # Equivalent to the following: return makeNode( getTotal(node1) + getTotal(node2), getCount(node1) + getCount(node2) ) identityMapping = -1 def mapping(tag, node): if tag == identityMapping: return node # If assigned, new total is the number assigned times count count = getCount(node) return makeNode(tag * count, count) def composition(mapping1, mapping2): # If assigned multiple times, take first non-identity assignment return mapping1 if mapping1 != identityMapping else mapping2 #---------------------------------Pollard rho-------------------------------------------- def memodict(f): """memoization decorator for a function taking a single argument""" class memodict(dict): def __missing__(self, key): ret = self[key] = f(key) return ret return memodict().__getitem__ def pollard_rho(n): """returns a random factor of n""" if n & 1 == 0: return 2 if n % 3 == 0: return 3 s = ((n - 1) & (1 - n)).bit_length() - 1 d = n >> s for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]: p = pow(a, d, n) if p == 1 or p == n - 1 or a % n == 0: continue for _ in range(s): prev = p p = (p * p) % n if p == 1: return math.gcd(prev - 1, n) if p == n - 1: break else: for i in range(2, n): x, y = i, (i * i + 1) % n f = math.gcd(abs(x - y), n) while f == 1: x, y = (x * x + 1) % n, (y * y + 1) % n y = (y * y + 1) % n f = math.gcd(abs(x - y), n) if f != n: return f return n @memodict def prime_factors(n): """returns a Counter of the prime factorization of n""" if n <= 1: return Counter() f = pollard_rho(n) return Counter([n]) if f == n else prime_factors(f) + prime_factors(n // f) def distinct_factors(n): """returns a list of all distinct factors of n""" factors = [1] for p, exp in prime_factors(n).items(): factors += [p**i * factor for factor in factors for i in range(1, exp + 1)] return factors def all_factors(n): """returns a sorted list of all distinct factors of n""" small, large = [], [] for i in range(1, int(n**0.5) + 1, 2 if n & 1 else 1): if not n % i: small.append(i) large.append(n // i) if small[-1] == large[-1]: large.pop() large.reverse() small.extend(large) return small #---------------------------------Binary Search------------------------------------------ def binarySearch(arr, n,i, key): left = 0 right = n-1 mid = 0 res=n while (left <= right): mid = (right + left)//2 if (arr[mid][i] > key): res=mid right = mid-1 else: left = mid + 1 return res def binarySearch1(arr, n,i, key): left = 0 right = n-1 mid = 0 res=-1 while (left <= right): mid = (right + left)//2 if (arr[mid][i] > key): right = mid-1 else: res=mid left = mid + 1 return res #---------------------------------running code------------------------------------------ t=1 #t=int(input()) for _ in range (t): #n=int(input()) n,m=map(int,input().split()) #a=list(map(int,input().split())) #tp=list(map(int,input().split())) #s=input() #n=len(s) a1=list(map(int,input().split())) b1=list(map(int,input().split())) a=[] for i in range (n): a.append([a1[2*i],a1[2*i+1]]) b=[] for i in range (m): b.append([b1[2*i],b1[2*i+1]]) candidates=set() neg=0 neg1=0 for i in range (n): x,y=a[i] possible=set() for j in range (m): p,q=b[j] if (x==p or x==q) and (y!=p and y!=q): possible.add(x) if (y==p or y==q) and (x!=p and x!=q): possible.add(y) if len(possible)>1: neg=1 candidates=candidates.union(possible) for i in range (m): x,y=b[i] possible=set() for j in range (n): p,q=a[j] if (x==p or x==q) and (y!=p and y!=q): possible.add(x) if (y==p or y==q) and (x!=p and x!=q): possible.add(y) if len(possible)>1: neg=1 if len(candidates)==1: print(candidates.pop()) elif neg: print(-1) else: print(0) ```
output
1
35,729
14
71,459
Provide tags and a correct Python 3 solution for this coding contest problem. Two participants are each given a pair of distinct numbers from 1 to 9 such that there's exactly one number that is present in both pairs. They want to figure out the number that matches by using a communication channel you have access to without revealing it to you. Both participants communicated to each other a set of pairs of numbers, that includes the pair given to them. Each pair in the communicated sets comprises two different numbers. Determine if you can with certainty deduce the common number, or if you can determine with certainty that both participants know the number but you do not. Input The first line contains two integers n and m (1 ≤ n, m ≤ 12) — the number of pairs the first participant communicated to the second and vice versa. The second line contains n pairs of integers, each between 1 and 9, — pairs of numbers communicated from first participant to the second. The third line contains m pairs of integers, each between 1 and 9, — pairs of numbers communicated from the second participant to the first. All pairs within each set are distinct (in particular, if there is a pair (1,2), there will be no pair (2,1) within the same set), and no pair contains the same number twice. It is guaranteed that the two sets do not contradict the statements, in other words, there is pair from the first set and a pair from the second set that share exactly one number. Output If you can deduce the shared number with certainty, print that number. If you can with certainty deduce that both participants know the shared number, but you do not know it, print 0. Otherwise print -1. Examples Input 2 2 1 2 3 4 1 5 3 4 Output 1 Input 2 2 1 2 3 4 1 5 6 4 Output 0 Input 2 3 1 2 4 5 1 2 1 3 2 3 Output -1 Note In the first example the first participant communicated pairs (1,2) and (3,4), and the second communicated (1,5), (3,4). Since we know that the actual pairs they received share exactly one number, it can't be that they both have (3,4). Thus, the first participant has (1,2) and the second has (1,5), and at this point you already know the shared number is 1. In the second example either the first participant has (1,2) and the second has (1,5), or the first has (3,4) and the second has (6,4). In the first case both of them know the shared number is 1, in the second case both of them know the shared number is 4. You don't have enough information to tell 1 and 4 apart. In the third case if the first participant was given (1,2), they don't know what the shared number is, since from their perspective the second participant might have been given either (1,3), in which case the shared number is 1, or (2,3), in which case the shared number is 2. While the second participant does know the number with certainty, neither you nor the first participant do, so the output is -1.
instruction
0
35,730
14
71,460
Tags: bitmasks, brute force Correct Solution: ``` import sys na, nb = map(int, sys.stdin.readline().split()) al, bl = list(map(int, sys.stdin.readline().split())), list(map(int, sys.stdin.readline().split())) a = [set((al[2*i], al[2*i+1])) for i in range(na)] b = [set((bl[2*i], bl[2*i+1])) for i in range(nb)] aposs, bposs = set(), set() possible_shared = set() i_know_a_knows, i_know_b_knows = True, True for ahas in a: bposshere = set() for bp in b: if len(ahas & bp) == 1: bposshere |= ahas & bp possible_shared |= bposshere if len(bposshere) == 2: i_know_a_knows = False for bhas in b: aposshere = set() for ap in a: if len(bhas & ap) == 1: aposshere |= bhas & ap possible_shared |= aposshere if len(aposshere) == 2: i_know_b_knows = False if len(possible_shared) == 1: print(list(possible_shared)[0]) elif i_know_a_knows and i_know_b_knows: print(0) else: print(-1) ```
output
1
35,730
14
71,461
Provide tags and a correct Python 3 solution for this coding contest problem. Two participants are each given a pair of distinct numbers from 1 to 9 such that there's exactly one number that is present in both pairs. They want to figure out the number that matches by using a communication channel you have access to without revealing it to you. Both participants communicated to each other a set of pairs of numbers, that includes the pair given to them. Each pair in the communicated sets comprises two different numbers. Determine if you can with certainty deduce the common number, or if you can determine with certainty that both participants know the number but you do not. Input The first line contains two integers n and m (1 ≤ n, m ≤ 12) — the number of pairs the first participant communicated to the second and vice versa. The second line contains n pairs of integers, each between 1 and 9, — pairs of numbers communicated from first participant to the second. The third line contains m pairs of integers, each between 1 and 9, — pairs of numbers communicated from the second participant to the first. All pairs within each set are distinct (in particular, if there is a pair (1,2), there will be no pair (2,1) within the same set), and no pair contains the same number twice. It is guaranteed that the two sets do not contradict the statements, in other words, there is pair from the first set and a pair from the second set that share exactly one number. Output If you can deduce the shared number with certainty, print that number. If you can with certainty deduce that both participants know the shared number, but you do not know it, print 0. Otherwise print -1. Examples Input 2 2 1 2 3 4 1 5 3 4 Output 1 Input 2 2 1 2 3 4 1 5 6 4 Output 0 Input 2 3 1 2 4 5 1 2 1 3 2 3 Output -1 Note In the first example the first participant communicated pairs (1,2) and (3,4), and the second communicated (1,5), (3,4). Since we know that the actual pairs they received share exactly one number, it can't be that they both have (3,4). Thus, the first participant has (1,2) and the second has (1,5), and at this point you already know the shared number is 1. In the second example either the first participant has (1,2) and the second has (1,5), or the first has (3,4) and the second has (6,4). In the first case both of them know the shared number is 1, in the second case both of them know the shared number is 4. You don't have enough information to tell 1 and 4 apart. In the third case if the first participant was given (1,2), they don't know what the shared number is, since from their perspective the second participant might have been given either (1,3), in which case the shared number is 1, or (2,3), in which case the shared number is 2. While the second participant does know the number with certainty, neither you nor the first participant do, so the output is -1.
instruction
0
35,731
14
71,462
Tags: bitmasks, brute force Correct Solution: ``` import sys #sys.stdin=open("data.txt") input=sys.stdin.readline n,m=map(int,input().split()) possible1=[set() for _ in range(200)] possible2=[set() for _ in range(200)] weird=[0]*15 p1=list(map(int,input().split())) p2=list(map(int,input().split())) for i in range(n): for j in range(m): a=sorted(p1[i*2:i*2+2]) b=sorted(p2[j*2:j*2+2]) if a==b: continue got=-1 if a[0] in b: got=a[0] if a[1] in b: got=a[1] if got==-1: continue weird[got]=1 possible1[a[0]*11+a[1]].add(got) possible2[b[0]*11+b[1]].add(got) if sum(weird)==1: print(weird.index(1)) elif max(len(i) for i in possible1)==1 and max(len(i) for i in possible2)==1: print(0) else: print(-1) ```
output
1
35,731
14
71,463
Provide tags and a correct Python 3 solution for this coding contest problem. Two participants are each given a pair of distinct numbers from 1 to 9 such that there's exactly one number that is present in both pairs. They want to figure out the number that matches by using a communication channel you have access to without revealing it to you. Both participants communicated to each other a set of pairs of numbers, that includes the pair given to them. Each pair in the communicated sets comprises two different numbers. Determine if you can with certainty deduce the common number, or if you can determine with certainty that both participants know the number but you do not. Input The first line contains two integers n and m (1 ≤ n, m ≤ 12) — the number of pairs the first participant communicated to the second and vice versa. The second line contains n pairs of integers, each between 1 and 9, — pairs of numbers communicated from first participant to the second. The third line contains m pairs of integers, each between 1 and 9, — pairs of numbers communicated from the second participant to the first. All pairs within each set are distinct (in particular, if there is a pair (1,2), there will be no pair (2,1) within the same set), and no pair contains the same number twice. It is guaranteed that the two sets do not contradict the statements, in other words, there is pair from the first set and a pair from the second set that share exactly one number. Output If you can deduce the shared number with certainty, print that number. If you can with certainty deduce that both participants know the shared number, but you do not know it, print 0. Otherwise print -1. Examples Input 2 2 1 2 3 4 1 5 3 4 Output 1 Input 2 2 1 2 3 4 1 5 6 4 Output 0 Input 2 3 1 2 4 5 1 2 1 3 2 3 Output -1 Note In the first example the first participant communicated pairs (1,2) and (3,4), and the second communicated (1,5), (3,4). Since we know that the actual pairs they received share exactly one number, it can't be that they both have (3,4). Thus, the first participant has (1,2) and the second has (1,5), and at this point you already know the shared number is 1. In the second example either the first participant has (1,2) and the second has (1,5), or the first has (3,4) and the second has (6,4). In the first case both of them know the shared number is 1, in the second case both of them know the shared number is 4. You don't have enough information to tell 1 and 4 apart. In the third case if the first participant was given (1,2), they don't know what the shared number is, since from their perspective the second participant might have been given either (1,3), in which case the shared number is 1, or (2,3), in which case the shared number is 2. While the second participant does know the number with certainty, neither you nor the first participant do, so the output is -1.
instruction
0
35,732
14
71,464
Tags: bitmasks, brute force Correct Solution: ``` def readpts(): ip = list(map(int, input().split())) return [(min(ip[i], ip[i+1]), max(ip[i], ip[i+1])) for i in range(0,len(ip),2)] N, M = map(int, input().split()) pts1 = readpts() pts2 = readpts() #print(pts1) #print(pts2) def psb(a, b): if a == b: return False return any(i in b for i in a) def sb(a, b): for i in a: if i in b: return i return -1 # should not happen def ipsv(pts1, pts2): ans = False for p1 in pts1: gsb = set() for p2 in pts2: if psb(p1, p2): gsb.add(sb(p1, p2)) if len(gsb) > 1: return False if len(gsb) == 1: ans = True return ans def sv(): gsb = set() for p1 in pts1: for p2 in pts2: if psb(p1, p2): gsb.add(sb(p1, p2)) if len(gsb) == 0: return -1 if len(gsb) == 1: return list(gsb)[0] if ipsv(pts1, pts2) and ipsv(pts2, pts1): return 0 return -1 print(sv()) ```
output
1
35,732
14
71,465
Provide tags and a correct Python 3 solution for this coding contest problem. Two participants are each given a pair of distinct numbers from 1 to 9 such that there's exactly one number that is present in both pairs. They want to figure out the number that matches by using a communication channel you have access to without revealing it to you. Both participants communicated to each other a set of pairs of numbers, that includes the pair given to them. Each pair in the communicated sets comprises two different numbers. Determine if you can with certainty deduce the common number, or if you can determine with certainty that both participants know the number but you do not. Input The first line contains two integers n and m (1 ≤ n, m ≤ 12) — the number of pairs the first participant communicated to the second and vice versa. The second line contains n pairs of integers, each between 1 and 9, — pairs of numbers communicated from first participant to the second. The third line contains m pairs of integers, each between 1 and 9, — pairs of numbers communicated from the second participant to the first. All pairs within each set are distinct (in particular, if there is a pair (1,2), there will be no pair (2,1) within the same set), and no pair contains the same number twice. It is guaranteed that the two sets do not contradict the statements, in other words, there is pair from the first set and a pair from the second set that share exactly one number. Output If you can deduce the shared number with certainty, print that number. If you can with certainty deduce that both participants know the shared number, but you do not know it, print 0. Otherwise print -1. Examples Input 2 2 1 2 3 4 1 5 3 4 Output 1 Input 2 2 1 2 3 4 1 5 6 4 Output 0 Input 2 3 1 2 4 5 1 2 1 3 2 3 Output -1 Note In the first example the first participant communicated pairs (1,2) and (3,4), and the second communicated (1,5), (3,4). Since we know that the actual pairs they received share exactly one number, it can't be that they both have (3,4). Thus, the first participant has (1,2) and the second has (1,5), and at this point you already know the shared number is 1. In the second example either the first participant has (1,2) and the second has (1,5), or the first has (3,4) and the second has (6,4). In the first case both of them know the shared number is 1, in the second case both of them know the shared number is 4. You don't have enough information to tell 1 and 4 apart. In the third case if the first participant was given (1,2), they don't know what the shared number is, since from their perspective the second participant might have been given either (1,3), in which case the shared number is 1, or (2,3), in which case the shared number is 2. While the second participant does know the number with certainty, neither you nor the first participant do, so the output is -1.
instruction
0
35,733
14
71,466
Tags: bitmasks, brute force Correct Solution: ``` q=input() q1=input().split() q2=input().split() parr1=[] for i in range(0,len(q1),2): pair=(q1[i],q1[i+1]) parr1.append(pair) parr2=[] for i in range(0,len(q2),2): pair=(q2[i],q2[i+1]) parr2.append(pair) matches1={} matches2={} for i in parr1: for j in parr2: if (i[0]==j[0] and i[1]==j[1]) or (i[0]==j[1] and i[1]==j[0]): continue elif i[0]==j[0] or i[0]==j[1]: if matches1.get(i)==None or matches1.get(i)==i[0]: matches1[i]=i[0] else: print('-1') quit() if matches2.get(j)==None or matches2.get(j)==i[0]: matches2[j]=i[0] else: print('-1') quit() elif i[1]==j[1] or i[1]==j[0]: if matches1.get(i)==None or matches1.get(i)==i[1]: matches1[i]=i[1] else: print('-1') quit() if matches2.get(j)==None or matches2.get(j)==i[1]: matches2[j]=i[1] else: print('-1') quit() else: pass matches=list(matches1.values()) for i in range(0,len(matches)): if matches[i]==matches[i-1]: pass else: print('0') quit() print(matches[0]) ```
output
1
35,733
14
71,467
Provide tags and a correct Python 3 solution for this coding contest problem. Two participants are each given a pair of distinct numbers from 1 to 9 such that there's exactly one number that is present in both pairs. They want to figure out the number that matches by using a communication channel you have access to without revealing it to you. Both participants communicated to each other a set of pairs of numbers, that includes the pair given to them. Each pair in the communicated sets comprises two different numbers. Determine if you can with certainty deduce the common number, or if you can determine with certainty that both participants know the number but you do not. Input The first line contains two integers n and m (1 ≤ n, m ≤ 12) — the number of pairs the first participant communicated to the second and vice versa. The second line contains n pairs of integers, each between 1 and 9, — pairs of numbers communicated from first participant to the second. The third line contains m pairs of integers, each between 1 and 9, — pairs of numbers communicated from the second participant to the first. All pairs within each set are distinct (in particular, if there is a pair (1,2), there will be no pair (2,1) within the same set), and no pair contains the same number twice. It is guaranteed that the two sets do not contradict the statements, in other words, there is pair from the first set and a pair from the second set that share exactly one number. Output If you can deduce the shared number with certainty, print that number. If you can with certainty deduce that both participants know the shared number, but you do not know it, print 0. Otherwise print -1. Examples Input 2 2 1 2 3 4 1 5 3 4 Output 1 Input 2 2 1 2 3 4 1 5 6 4 Output 0 Input 2 3 1 2 4 5 1 2 1 3 2 3 Output -1 Note In the first example the first participant communicated pairs (1,2) and (3,4), and the second communicated (1,5), (3,4). Since we know that the actual pairs they received share exactly one number, it can't be that they both have (3,4). Thus, the first participant has (1,2) and the second has (1,5), and at this point you already know the shared number is 1. In the second example either the first participant has (1,2) and the second has (1,5), or the first has (3,4) and the second has (6,4). In the first case both of them know the shared number is 1, in the second case both of them know the shared number is 4. You don't have enough information to tell 1 and 4 apart. In the third case if the first participant was given (1,2), they don't know what the shared number is, since from their perspective the second participant might have been given either (1,3), in which case the shared number is 1, or (2,3), in which case the shared number is 2. While the second participant does know the number with certainty, neither you nor the first participant do, so the output is -1.
instruction
0
35,734
14
71,468
Tags: bitmasks, brute force Correct Solution: ``` # Codeforces Round #488 by NEAR (Div. 2) import collections from functools import cmp_to_key #key=cmp_to_key(lambda x,y: 1 if x not in y else -1 ) import sys def getIntList(): return list(map(int, input().split())) import bisect def makePair(z): return [(z[i], z[i+1]) for i in range(0,len(z),2) ] N,M = getIntList() p1 = getIntList() p1 = makePair(p1) p1 = list(map( set, p1)) p2 = getIntList() p2 = makePair(p2) p2 = list(map( set, p2)) #print(p1) res = set() for x in p1: for y in p2: z = x&y if len(z) ==2 or len(z) ==0:continue res = res | z if len(res) == 1: print(res.pop()) sys.exit() for x in p1: nz = set() for y in p2: z = x&y if len(z) ==2 or len(z) ==0:continue nz = nz | z if len(nz) == 2: print(-1) sys.exit() for x in p2: nz = set() for y in p1: z = x&y if len(z) ==2 or len(z) ==0:continue nz = nz | z if len(nz) == 2: print(-1) sys.exit() print(0) ```
output
1
35,734
14
71,469
Provide tags and a correct Python 3 solution for this coding contest problem. Two participants are each given a pair of distinct numbers from 1 to 9 such that there's exactly one number that is present in both pairs. They want to figure out the number that matches by using a communication channel you have access to without revealing it to you. Both participants communicated to each other a set of pairs of numbers, that includes the pair given to them. Each pair in the communicated sets comprises two different numbers. Determine if you can with certainty deduce the common number, or if you can determine with certainty that both participants know the number but you do not. Input The first line contains two integers n and m (1 ≤ n, m ≤ 12) — the number of pairs the first participant communicated to the second and vice versa. The second line contains n pairs of integers, each between 1 and 9, — pairs of numbers communicated from first participant to the second. The third line contains m pairs of integers, each between 1 and 9, — pairs of numbers communicated from the second participant to the first. All pairs within each set are distinct (in particular, if there is a pair (1,2), there will be no pair (2,1) within the same set), and no pair contains the same number twice. It is guaranteed that the two sets do not contradict the statements, in other words, there is pair from the first set and a pair from the second set that share exactly one number. Output If you can deduce the shared number with certainty, print that number. If you can with certainty deduce that both participants know the shared number, but you do not know it, print 0. Otherwise print -1. Examples Input 2 2 1 2 3 4 1 5 3 4 Output 1 Input 2 2 1 2 3 4 1 5 6 4 Output 0 Input 2 3 1 2 4 5 1 2 1 3 2 3 Output -1 Note In the first example the first participant communicated pairs (1,2) and (3,4), and the second communicated (1,5), (3,4). Since we know that the actual pairs they received share exactly one number, it can't be that they both have (3,4). Thus, the first participant has (1,2) and the second has (1,5), and at this point you already know the shared number is 1. In the second example either the first participant has (1,2) and the second has (1,5), or the first has (3,4) and the second has (6,4). In the first case both of them know the shared number is 1, in the second case both of them know the shared number is 4. You don't have enough information to tell 1 and 4 apart. In the third case if the first participant was given (1,2), they don't know what the shared number is, since from their perspective the second participant might have been given either (1,3), in which case the shared number is 1, or (2,3), in which case the shared number is 2. While the second participant does know the number with certainty, neither you nor the first participant do, so the output is -1.
instruction
0
35,735
14
71,470
Tags: bitmasks, brute force Correct Solution: ``` n, m = map(int, input().split()) p1 = list(map(int, input().split())) p2 = list(map(int, input().split())) cand = set() cc = [set() for i in range(n)] dd = [set() for i in range(m)] for i in range(n): for j in range(m): a, b = p1[2 * i], p1[2 * i + 1] c, d = p2[2 * j], p2[2 * j + 1] if a not in (c, d) and b not in (c, d): continue if a in (c, d) and b in (c, d): continue if a in (c, d): kandidat = a else: kandidat = b cand.add(kandidat) cc[i].add(kandidat) dd[j].add(kandidat) if len(cand) == 1: print(cand.pop()) elif max(len(cc[i]) for i in range(n)) <= 1 and\ max(len(dd[i]) for i in range(m)) <= 1: print(0) else: print(-1) ```
output
1
35,735
14
71,471
Provide tags and a correct Python 3 solution for this coding contest problem. Two participants are each given a pair of distinct numbers from 1 to 9 such that there's exactly one number that is present in both pairs. They want to figure out the number that matches by using a communication channel you have access to without revealing it to you. Both participants communicated to each other a set of pairs of numbers, that includes the pair given to them. Each pair in the communicated sets comprises two different numbers. Determine if you can with certainty deduce the common number, or if you can determine with certainty that both participants know the number but you do not. Input The first line contains two integers n and m (1 ≤ n, m ≤ 12) — the number of pairs the first participant communicated to the second and vice versa. The second line contains n pairs of integers, each between 1 and 9, — pairs of numbers communicated from first participant to the second. The third line contains m pairs of integers, each between 1 and 9, — pairs of numbers communicated from the second participant to the first. All pairs within each set are distinct (in particular, if there is a pair (1,2), there will be no pair (2,1) within the same set), and no pair contains the same number twice. It is guaranteed that the two sets do not contradict the statements, in other words, there is pair from the first set and a pair from the second set that share exactly one number. Output If you can deduce the shared number with certainty, print that number. If you can with certainty deduce that both participants know the shared number, but you do not know it, print 0. Otherwise print -1. Examples Input 2 2 1 2 3 4 1 5 3 4 Output 1 Input 2 2 1 2 3 4 1 5 6 4 Output 0 Input 2 3 1 2 4 5 1 2 1 3 2 3 Output -1 Note In the first example the first participant communicated pairs (1,2) and (3,4), and the second communicated (1,5), (3,4). Since we know that the actual pairs they received share exactly one number, it can't be that they both have (3,4). Thus, the first participant has (1,2) and the second has (1,5), and at this point you already know the shared number is 1. In the second example either the first participant has (1,2) and the second has (1,5), or the first has (3,4) and the second has (6,4). In the first case both of them know the shared number is 1, in the second case both of them know the shared number is 4. You don't have enough information to tell 1 and 4 apart. In the third case if the first participant was given (1,2), they don't know what the shared number is, since from their perspective the second participant might have been given either (1,3), in which case the shared number is 1, or (2,3), in which case the shared number is 2. While the second participant does know the number with certainty, neither you nor the first participant do, so the output is -1.
instruction
0
35,736
14
71,472
Tags: bitmasks, brute force Correct Solution: ``` n, m = map(int, input().split()) aa = list(map(int, input().split())) bb = list(map(int, input().split())) a = [] b = [] for i in range(0, 2 * n, 2): a.append([aa[i], aa[i + 1]]) for i in range(0, 2 * m, 2): b.append([bb[i], bb[i + 1]]) accept = [] for num in range(1, 10): ina = [] inb = [] for x in a: if num in x: ina.append(x) for x in b: if num in x: inb.append(x) x = 0 for t in ina: t.sort() for p in inb: p.sort() if t != p: x += 1 if x > 0: accept.append(num) if len(accept) == 1: print(accept[0]) exit(0) #check fst for t in a: z = set() for p in b: if t != p: if t[0] in p: z.add(t[0]) if t[1] in p: z.add(t[1]) if len(z) > 1: print(-1) exit(0) #check scd for t in b: z = set() for p in a: if t != p: if t[0] in p: z.add(t[0]) if t[1] in p: z.add(t[1]) if len(z) > 1: print(-1) exit(0) print(0) ```
output
1
35,736
14
71,473
Provide tags and a correct Python 3 solution for this coding contest problem. Recently, Olya received a magical square with the size of 2^n× 2^n. It seems to her sister that one square is boring. Therefore, she asked Olya to perform exactly k splitting operations. A Splitting operation is an operation during which Olya takes a square with side a and cuts it into 4 equal squares with side a/2. If the side of the square is equal to 1, then it is impossible to apply a splitting operation to it (see examples for better understanding). Olya is happy to fulfill her sister's request, but she also wants the condition of Olya's happiness to be satisfied after all operations. The condition of Olya's happiness will be satisfied if the following statement is fulfilled: Let the length of the side of the lower left square be equal to a, then the length of the side of the right upper square should also be equal to a. There should also be a path between them that consists only of squares with the side of length a. All consecutive squares on a path should have a common side. Obviously, as long as we have one square, these conditions are met. So Olya is ready to fulfill her sister's request only under the condition that she is satisfied too. Tell her: is it possible to perform exactly k splitting operations in a certain order so that the condition of Olya's happiness is satisfied? If it is possible, tell also the size of the side of squares of which the path from the lower left square to the upper right one will consist. Input The first line contains one integer t (1 ≤ t ≤ 10^3) — the number of tests. Each of the following t lines contains two integers n_i and k_i (1 ≤ n_i ≤ 10^9, 1 ≤ k_i ≤ 10^{18}) — the description of the i-th test, which means that initially Olya's square has size of 2^{n_i}× 2^{n_i} and Olya's sister asks her to do exactly k_i splitting operations. Output Print t lines, where in the i-th line you should output "YES" if it is possible to perform k_i splitting operations in the i-th test in such a way that the condition of Olya's happiness is satisfied or print "NO" otherwise. If you printed "YES", then also print the log_2 of the length of the side of the squares through space, along which you can build a path from the lower left square to the upper right one. You can output each letter in any case (lower or upper). If there are multiple answers, print any. Example Input 3 1 1 2 2 2 12 Output YES 0 YES 1 NO Note In each of the illustrations, the pictures are shown in order in which Olya applied the operations. The recently-created squares are highlighted with red. In the first test, Olya can apply splitting operations in the following order: <image> Olya applies one operation on the only existing square. The condition of Olya's happiness will be met, since there is a path of squares of the same size from the lower left square to the upper right one: <image> The length of the sides of the squares on the path is 1. log_2(1) = 0. In the second test, Olya can apply splitting operations in the following order: <image> Olya applies the first operation on the only existing square. She applies the second one on the right bottom square. The condition of Olya's happiness will be met, since there is a path of squares of the same size from the lower left square to the upper right one: <image> The length of the sides of the squares on the path is 2. log_2(2) = 1. In the third test, it takes 5 operations for Olya to make the square look like this: <image> Since it requires her to perform 7 splitting operations, and it is impossible to perform them on squares with side equal to 1, then Olya cannot do anything more and the answer is "NO".
instruction
0
36,030
14
72,060
Tags: constructive algorithms, implementation, math Correct Solution: ``` pw = [1, 4] for i in range(2, 32): pw.append(pw[i - 1] * 4) t = int(input()) for cas in range(t): n, k = map(int, input().split()) last = 1 path = 1 ans = n i = 0 while True: if((pw[i + 1] - 1) // 3 > k): ans -= i last = k - (pw[i] - 1) // 3 break i = i + 1 path *= 2 sp = path * 2 - 1 if((ans < 0) or ((ans == 0) and (last > 0))): print("No") continue sq = path * path - sp if (ans == 1) and (last > sq) and (last < sp): print("No") continue elif (ans == 1) and (last >= sp): ans = ans - 1 print("Yes", ans) ```
output
1
36,030
14
72,061
Provide tags and a correct Python 3 solution for this coding contest problem. Recently, Olya received a magical square with the size of 2^n× 2^n. It seems to her sister that one square is boring. Therefore, she asked Olya to perform exactly k splitting operations. A Splitting operation is an operation during which Olya takes a square with side a and cuts it into 4 equal squares with side a/2. If the side of the square is equal to 1, then it is impossible to apply a splitting operation to it (see examples for better understanding). Olya is happy to fulfill her sister's request, but she also wants the condition of Olya's happiness to be satisfied after all operations. The condition of Olya's happiness will be satisfied if the following statement is fulfilled: Let the length of the side of the lower left square be equal to a, then the length of the side of the right upper square should also be equal to a. There should also be a path between them that consists only of squares with the side of length a. All consecutive squares on a path should have a common side. Obviously, as long as we have one square, these conditions are met. So Olya is ready to fulfill her sister's request only under the condition that she is satisfied too. Tell her: is it possible to perform exactly k splitting operations in a certain order so that the condition of Olya's happiness is satisfied? If it is possible, tell also the size of the side of squares of which the path from the lower left square to the upper right one will consist. Input The first line contains one integer t (1 ≤ t ≤ 10^3) — the number of tests. Each of the following t lines contains two integers n_i and k_i (1 ≤ n_i ≤ 10^9, 1 ≤ k_i ≤ 10^{18}) — the description of the i-th test, which means that initially Olya's square has size of 2^{n_i}× 2^{n_i} and Olya's sister asks her to do exactly k_i splitting operations. Output Print t lines, where in the i-th line you should output "YES" if it is possible to perform k_i splitting operations in the i-th test in such a way that the condition of Olya's happiness is satisfied or print "NO" otherwise. If you printed "YES", then also print the log_2 of the length of the side of the squares through space, along which you can build a path from the lower left square to the upper right one. You can output each letter in any case (lower or upper). If there are multiple answers, print any. Example Input 3 1 1 2 2 2 12 Output YES 0 YES 1 NO Note In each of the illustrations, the pictures are shown in order in which Olya applied the operations. The recently-created squares are highlighted with red. In the first test, Olya can apply splitting operations in the following order: <image> Olya applies one operation on the only existing square. The condition of Olya's happiness will be met, since there is a path of squares of the same size from the lower left square to the upper right one: <image> The length of the sides of the squares on the path is 1. log_2(1) = 0. In the second test, Olya can apply splitting operations in the following order: <image> Olya applies the first operation on the only existing square. She applies the second one on the right bottom square. The condition of Olya's happiness will be met, since there is a path of squares of the same size from the lower left square to the upper right one: <image> The length of the sides of the squares on the path is 2. log_2(2) = 1. In the third test, it takes 5 operations for Olya to make the square look like this: <image> Since it requires her to perform 7 splitting operations, and it is impossible to perform them on squares with side equal to 1, then Olya cannot do anything more and the answer is "NO".
instruction
0
36,031
14
72,062
Tags: constructive algorithms, implementation, math Correct Solution: ``` for _ in range(int(input())): n,k=map(int,input().split()) if n>31: print("YES",n-1) continue else: if k>(4**n-1)//3: print("NO") continue l=(4**n-1)//3 i=1 j=0 k1=k while i<=n: k-=(2**i-1) j=i if k<0: j=j-1 k+=(2**i-1) break i+=1 k2=k1-k k3=(2**(j+1)-1)*((4**(n-j)-1)//3) #print(j,k,k1,k2,k3,l) if l-k2-k3>=k: print("YES",n-i+1) else: print("NO") ```
output
1
36,031
14
72,063
Provide tags and a correct Python 3 solution for this coding contest problem. Recently, Olya received a magical square with the size of 2^n× 2^n. It seems to her sister that one square is boring. Therefore, she asked Olya to perform exactly k splitting operations. A Splitting operation is an operation during which Olya takes a square with side a and cuts it into 4 equal squares with side a/2. If the side of the square is equal to 1, then it is impossible to apply a splitting operation to it (see examples for better understanding). Olya is happy to fulfill her sister's request, but she also wants the condition of Olya's happiness to be satisfied after all operations. The condition of Olya's happiness will be satisfied if the following statement is fulfilled: Let the length of the side of the lower left square be equal to a, then the length of the side of the right upper square should also be equal to a. There should also be a path between them that consists only of squares with the side of length a. All consecutive squares on a path should have a common side. Obviously, as long as we have one square, these conditions are met. So Olya is ready to fulfill her sister's request only under the condition that she is satisfied too. Tell her: is it possible to perform exactly k splitting operations in a certain order so that the condition of Olya's happiness is satisfied? If it is possible, tell also the size of the side of squares of which the path from the lower left square to the upper right one will consist. Input The first line contains one integer t (1 ≤ t ≤ 10^3) — the number of tests. Each of the following t lines contains two integers n_i and k_i (1 ≤ n_i ≤ 10^9, 1 ≤ k_i ≤ 10^{18}) — the description of the i-th test, which means that initially Olya's square has size of 2^{n_i}× 2^{n_i} and Olya's sister asks her to do exactly k_i splitting operations. Output Print t lines, where in the i-th line you should output "YES" if it is possible to perform k_i splitting operations in the i-th test in such a way that the condition of Olya's happiness is satisfied or print "NO" otherwise. If you printed "YES", then also print the log_2 of the length of the side of the squares through space, along which you can build a path from the lower left square to the upper right one. You can output each letter in any case (lower or upper). If there are multiple answers, print any. Example Input 3 1 1 2 2 2 12 Output YES 0 YES 1 NO Note In each of the illustrations, the pictures are shown in order in which Olya applied the operations. The recently-created squares are highlighted with red. In the first test, Olya can apply splitting operations in the following order: <image> Olya applies one operation on the only existing square. The condition of Olya's happiness will be met, since there is a path of squares of the same size from the lower left square to the upper right one: <image> The length of the sides of the squares on the path is 1. log_2(1) = 0. In the second test, Olya can apply splitting operations in the following order: <image> Olya applies the first operation on the only existing square. She applies the second one on the right bottom square. The condition of Olya's happiness will be met, since there is a path of squares of the same size from the lower left square to the upper right one: <image> The length of the sides of the squares on the path is 2. log_2(2) = 1. In the third test, it takes 5 operations for Olya to make the square look like this: <image> Since it requires her to perform 7 splitting operations, and it is impossible to perform them on squares with side equal to 1, then Olya cannot do anything more and the answer is "NO".
instruction
0
36,032
14
72,064
Tags: constructive algorithms, implementation, math Correct Solution: ``` def f_pow(a, n): if n < 0: return 0 if n == 0: return 1 if n % 2 == 0: return f_pow(a * a, n // 2) else: return a * f_pow(a, n - 1) def get_c(n): if(n > 68): return int(1e40) return (f_pow(4, n) - 4) // 12 def get_cc(n): if(n > 51): return int(1e30) return (f_pow(4, n) - 4) // 12 def ans(n, k): side = n - 1 way = 4 cnt_all = get_c(n + 1) c = 2 op = 1 while (True): if k < op or side < 0: break way_blocks = way - 1 if(get_cc(side - 1) > k): return side per_block = get_cc(side + 1) kk = k - op if cnt_all - way_blocks * per_block - op >= kk: return side side -= 1 op += (1 << c) - 1 c += 1 way *= 2 return -1 def read(): return [int(i) for i in input().split()] t = int(input()) for i in range(t): n, k = read() a = ans(n, k) if(a == -1): print("NO") else: print("YES {}".format(a)) ```
output
1
36,032
14
72,065
Provide tags and a correct Python 3 solution for this coding contest problem. Recently, Olya received a magical square with the size of 2^n× 2^n. It seems to her sister that one square is boring. Therefore, she asked Olya to perform exactly k splitting operations. A Splitting operation is an operation during which Olya takes a square with side a and cuts it into 4 equal squares with side a/2. If the side of the square is equal to 1, then it is impossible to apply a splitting operation to it (see examples for better understanding). Olya is happy to fulfill her sister's request, but she also wants the condition of Olya's happiness to be satisfied after all operations. The condition of Olya's happiness will be satisfied if the following statement is fulfilled: Let the length of the side of the lower left square be equal to a, then the length of the side of the right upper square should also be equal to a. There should also be a path between them that consists only of squares with the side of length a. All consecutive squares on a path should have a common side. Obviously, as long as we have one square, these conditions are met. So Olya is ready to fulfill her sister's request only under the condition that she is satisfied too. Tell her: is it possible to perform exactly k splitting operations in a certain order so that the condition of Olya's happiness is satisfied? If it is possible, tell also the size of the side of squares of which the path from the lower left square to the upper right one will consist. Input The first line contains one integer t (1 ≤ t ≤ 10^3) — the number of tests. Each of the following t lines contains two integers n_i and k_i (1 ≤ n_i ≤ 10^9, 1 ≤ k_i ≤ 10^{18}) — the description of the i-th test, which means that initially Olya's square has size of 2^{n_i}× 2^{n_i} and Olya's sister asks her to do exactly k_i splitting operations. Output Print t lines, where in the i-th line you should output "YES" if it is possible to perform k_i splitting operations in the i-th test in such a way that the condition of Olya's happiness is satisfied or print "NO" otherwise. If you printed "YES", then also print the log_2 of the length of the side of the squares through space, along which you can build a path from the lower left square to the upper right one. You can output each letter in any case (lower or upper). If there are multiple answers, print any. Example Input 3 1 1 2 2 2 12 Output YES 0 YES 1 NO Note In each of the illustrations, the pictures are shown in order in which Olya applied the operations. The recently-created squares are highlighted with red. In the first test, Olya can apply splitting operations in the following order: <image> Olya applies one operation on the only existing square. The condition of Olya's happiness will be met, since there is a path of squares of the same size from the lower left square to the upper right one: <image> The length of the sides of the squares on the path is 1. log_2(1) = 0. In the second test, Olya can apply splitting operations in the following order: <image> Olya applies the first operation on the only existing square. She applies the second one on the right bottom square. The condition of Olya's happiness will be met, since there is a path of squares of the same size from the lower left square to the upper right one: <image> The length of the sides of the squares on the path is 2. log_2(2) = 1. In the third test, it takes 5 operations for Olya to make the square look like this: <image> Since it requires her to perform 7 splitting operations, and it is impossible to perform them on squares with side equal to 1, then Olya cannot do anything more and the answer is "NO".
instruction
0
36,033
14
72,066
Tags: constructive algorithms, implementation, math Correct Solution: ``` #!/usr/bin/python # encoding:UTF-8 # Filename:Base.py import sys import random from itertools import permutations, combinations from math import sqrt, fabs, ceil from collections import namedtuple # ------Util Const-------- in_file_path = "input.txt" output_file_path = "output.txt" SUBMIT = True def read_num(fin, num_type=int): tmp_list = [num_type(x) for x in fin.readline().strip().split()] if len(tmp_list) == 1: return tmp_list[0] else: return tuple(tmp_list) # A # def solve(fin, fout): # n, k = read_num(fin) # print(ceil((n * 8.0) / k) + ceil((n * 2.0) / k) + ceil((n * 5.0) / k)) # B # def solve(fin): # n = read_num(fin) # for _ in range(0, n): # l, r = read_num(fin) # if (r - l + 1) % 2 == 0: # if l % 2 == 0: # print(int(-(r - l + 1) / 2)) # else: # print(int((r - l + 1) / 2)) # else: # if l % 2 == 0: # print(int(-(r - l) / 2 + r)) # else: # print(int((r - l) / 2 - r)) # C # def solve(fin): # def count_color(x, y, xx, yy): # # return _w(x, y, xx, yy), _b(x, y, xx, yy) # if x > xx or y > yy: # return 0, 0 # t = (xx - x + 1) * (yy - y + 1) # if t % 2 == 0: # return t // 2, t // 2 # else: # if (x + y) % 2 == 0: # return t - t // 2, t // 2 # else: # return t // 2, t - t // 2 # # T = read_num(fin) # for _ in range(0, T): # # print('Test: ',T) # n, m = read_num(fin) # x1, y1, x2, y2 = read_num(fin) # x3, y3, x4, y4 = read_num(fin) # w, _ = count_color(1, 1, n, m) # if (max(x1, x3) > min(x2, x4)) or (max(y1, y3) > min(y2, y4)): # tmp_w, tmp_b = count_color(x1, y1, x2, y2) # w += tmp_b # tmp_w, tmp_b = count_color(x3, y3, x4, y4) # w -= tmp_w # else: # tmp_w, tmp_b = count_color(x1, y1, x2, y2) # w += tmp_b # tmp_w, tmp_b = count_color(x3, y3, x4, y4) # w -= tmp_w # tmp_x_list = sorted([x1, x2, x3, x4]) # tmp_y_list = sorted([y1, y2, y3, y4]) # x5, x6 = tmp_x_list[1], tmp_x_list[2] # y5, y6 = tmp_y_list[1], tmp_y_list[2] # tmp_w, tmp_b = count_color(x5, y5, x6, y6) # w -= tmp_b # print(w, n * m - w) def solve(fin): T = read_num(fin) for _ in range(0, T): n, k = read_num(fin) if n > 34 or k == 1: print('YES', n - 1) else: f = [0] for _ in range(0, n): f.append(f[-1] * 4 + 1) min_step = 1 max_step = 1 + f[n - 1] # print(f) # print(f[n - 1]) out_range = 3 flag = True for i in range(0, n): # print(min_step, max_step) if min_step <= k <= max_step: print('YES', n - i - 1) flag = False break max_step += out_range min_step += out_range out_range = out_range * 2 + 1 if n - 2 - i >= 0: # print(out_range - 2, f[n - 2 - i]) max_step += (out_range - 2) * f[n - 2 - i] if flag: print('NO') if __name__ == '__main__': if SUBMIT: solve(sys.stdin) else: solve(open(in_file_path, 'r')) ```
output
1
36,033
14
72,067
Provide tags and a correct Python 3 solution for this coding contest problem. Recently, Olya received a magical square with the size of 2^n× 2^n. It seems to her sister that one square is boring. Therefore, she asked Olya to perform exactly k splitting operations. A Splitting operation is an operation during which Olya takes a square with side a and cuts it into 4 equal squares with side a/2. If the side of the square is equal to 1, then it is impossible to apply a splitting operation to it (see examples for better understanding). Olya is happy to fulfill her sister's request, but she also wants the condition of Olya's happiness to be satisfied after all operations. The condition of Olya's happiness will be satisfied if the following statement is fulfilled: Let the length of the side of the lower left square be equal to a, then the length of the side of the right upper square should also be equal to a. There should also be a path between them that consists only of squares with the side of length a. All consecutive squares on a path should have a common side. Obviously, as long as we have one square, these conditions are met. So Olya is ready to fulfill her sister's request only under the condition that she is satisfied too. Tell her: is it possible to perform exactly k splitting operations in a certain order so that the condition of Olya's happiness is satisfied? If it is possible, tell also the size of the side of squares of which the path from the lower left square to the upper right one will consist. Input The first line contains one integer t (1 ≤ t ≤ 10^3) — the number of tests. Each of the following t lines contains two integers n_i and k_i (1 ≤ n_i ≤ 10^9, 1 ≤ k_i ≤ 10^{18}) — the description of the i-th test, which means that initially Olya's square has size of 2^{n_i}× 2^{n_i} and Olya's sister asks her to do exactly k_i splitting operations. Output Print t lines, where in the i-th line you should output "YES" if it is possible to perform k_i splitting operations in the i-th test in such a way that the condition of Olya's happiness is satisfied or print "NO" otherwise. If you printed "YES", then also print the log_2 of the length of the side of the squares through space, along which you can build a path from the lower left square to the upper right one. You can output each letter in any case (lower or upper). If there are multiple answers, print any. Example Input 3 1 1 2 2 2 12 Output YES 0 YES 1 NO Note In each of the illustrations, the pictures are shown in order in which Olya applied the operations. The recently-created squares are highlighted with red. In the first test, Olya can apply splitting operations in the following order: <image> Olya applies one operation on the only existing square. The condition of Olya's happiness will be met, since there is a path of squares of the same size from the lower left square to the upper right one: <image> The length of the sides of the squares on the path is 1. log_2(1) = 0. In the second test, Olya can apply splitting operations in the following order: <image> Olya applies the first operation on the only existing square. She applies the second one on the right bottom square. The condition of Olya's happiness will be met, since there is a path of squares of the same size from the lower left square to the upper right one: <image> The length of the sides of the squares on the path is 2. log_2(2) = 1. In the third test, it takes 5 operations for Olya to make the square look like this: <image> Since it requires her to perform 7 splitting operations, and it is impossible to perform them on squares with side equal to 1, then Olya cannot do anything more and the answer is "NO".
instruction
0
36,034
14
72,068
Tags: constructive algorithms, implementation, math Correct Solution: ``` test=int(input()) while test: test=test-1 n,k = input().split() n=int(n) k=int(k) if n==2 and k==3: print("NO") continue if n>=32: print("YES",n-1) continue val=[] val.append(0) for i in range(1,n+1): val.append(4*val[i-1]+1) if val[n]<k: print("NO") continue s=0 t=2 rem=0 flag=0 while s+t-1<=k and n>0: s=s+t-1 t*=2 n=n-1 print("YES",n) ```
output
1
36,034
14
72,069
Provide tags and a correct Python 3 solution for this coding contest problem. Recently, Olya received a magical square with the size of 2^n× 2^n. It seems to her sister that one square is boring. Therefore, she asked Olya to perform exactly k splitting operations. A Splitting operation is an operation during which Olya takes a square with side a and cuts it into 4 equal squares with side a/2. If the side of the square is equal to 1, then it is impossible to apply a splitting operation to it (see examples for better understanding). Olya is happy to fulfill her sister's request, but she also wants the condition of Olya's happiness to be satisfied after all operations. The condition of Olya's happiness will be satisfied if the following statement is fulfilled: Let the length of the side of the lower left square be equal to a, then the length of the side of the right upper square should also be equal to a. There should also be a path between them that consists only of squares with the side of length a. All consecutive squares on a path should have a common side. Obviously, as long as we have one square, these conditions are met. So Olya is ready to fulfill her sister's request only under the condition that she is satisfied too. Tell her: is it possible to perform exactly k splitting operations in a certain order so that the condition of Olya's happiness is satisfied? If it is possible, tell also the size of the side of squares of which the path from the lower left square to the upper right one will consist. Input The first line contains one integer t (1 ≤ t ≤ 10^3) — the number of tests. Each of the following t lines contains two integers n_i and k_i (1 ≤ n_i ≤ 10^9, 1 ≤ k_i ≤ 10^{18}) — the description of the i-th test, which means that initially Olya's square has size of 2^{n_i}× 2^{n_i} and Olya's sister asks her to do exactly k_i splitting operations. Output Print t lines, where in the i-th line you should output "YES" if it is possible to perform k_i splitting operations in the i-th test in such a way that the condition of Olya's happiness is satisfied or print "NO" otherwise. If you printed "YES", then also print the log_2 of the length of the side of the squares through space, along which you can build a path from the lower left square to the upper right one. You can output each letter in any case (lower or upper). If there are multiple answers, print any. Example Input 3 1 1 2 2 2 12 Output YES 0 YES 1 NO Note In each of the illustrations, the pictures are shown in order in which Olya applied the operations. The recently-created squares are highlighted with red. In the first test, Olya can apply splitting operations in the following order: <image> Olya applies one operation on the only existing square. The condition of Olya's happiness will be met, since there is a path of squares of the same size from the lower left square to the upper right one: <image> The length of the sides of the squares on the path is 1. log_2(1) = 0. In the second test, Olya can apply splitting operations in the following order: <image> Olya applies the first operation on the only existing square. She applies the second one on the right bottom square. The condition of Olya's happiness will be met, since there is a path of squares of the same size from the lower left square to the upper right one: <image> The length of the sides of the squares on the path is 2. log_2(2) = 1. In the third test, it takes 5 operations for Olya to make the square look like this: <image> Since it requires her to perform 7 splitting operations, and it is impossible to perform them on squares with side equal to 1, then Olya cannot do anything more and the answer is "NO".
instruction
0
36,035
14
72,070
Tags: constructive algorithms, implementation, math Correct Solution: ``` import sys t = int(input()) for _ in range(0, t): ri = input().split(" "); n = int(ri[0]) k = int(ri[1]) if k == 0: print("YES " + str(n)) continue; is_ok = False for i in range(1, min(64, n + 1)): # print (str(i)) l = 2 ** (i + 1) - i - 2 r = 0 if n > 100: r = k; else: r = (4 ** n - 1) // 3 - (2 ** (i + 1) - 1) * (4 ** (n - i) - 1) // 3 # print (str(l) + " " + str(r)) if l <= k and k <= r: print("YES " + str(n - i)) is_ok = True break if not is_ok: print("NO") ```
output
1
36,035
14
72,071
Provide tags and a correct Python 3 solution for this coding contest problem. Recently, Olya received a magical square with the size of 2^n× 2^n. It seems to her sister that one square is boring. Therefore, she asked Olya to perform exactly k splitting operations. A Splitting operation is an operation during which Olya takes a square with side a and cuts it into 4 equal squares with side a/2. If the side of the square is equal to 1, then it is impossible to apply a splitting operation to it (see examples for better understanding). Olya is happy to fulfill her sister's request, but she also wants the condition of Olya's happiness to be satisfied after all operations. The condition of Olya's happiness will be satisfied if the following statement is fulfilled: Let the length of the side of the lower left square be equal to a, then the length of the side of the right upper square should also be equal to a. There should also be a path between them that consists only of squares with the side of length a. All consecutive squares on a path should have a common side. Obviously, as long as we have one square, these conditions are met. So Olya is ready to fulfill her sister's request only under the condition that she is satisfied too. Tell her: is it possible to perform exactly k splitting operations in a certain order so that the condition of Olya's happiness is satisfied? If it is possible, tell also the size of the side of squares of which the path from the lower left square to the upper right one will consist. Input The first line contains one integer t (1 ≤ t ≤ 10^3) — the number of tests. Each of the following t lines contains two integers n_i and k_i (1 ≤ n_i ≤ 10^9, 1 ≤ k_i ≤ 10^{18}) — the description of the i-th test, which means that initially Olya's square has size of 2^{n_i}× 2^{n_i} and Olya's sister asks her to do exactly k_i splitting operations. Output Print t lines, where in the i-th line you should output "YES" if it is possible to perform k_i splitting operations in the i-th test in such a way that the condition of Olya's happiness is satisfied or print "NO" otherwise. If you printed "YES", then also print the log_2 of the length of the side of the squares through space, along which you can build a path from the lower left square to the upper right one. You can output each letter in any case (lower or upper). If there are multiple answers, print any. Example Input 3 1 1 2 2 2 12 Output YES 0 YES 1 NO Note In each of the illustrations, the pictures are shown in order in which Olya applied the operations. The recently-created squares are highlighted with red. In the first test, Olya can apply splitting operations in the following order: <image> Olya applies one operation on the only existing square. The condition of Olya's happiness will be met, since there is a path of squares of the same size from the lower left square to the upper right one: <image> The length of the sides of the squares on the path is 1. log_2(1) = 0. In the second test, Olya can apply splitting operations in the following order: <image> Olya applies the first operation on the only existing square. She applies the second one on the right bottom square. The condition of Olya's happiness will be met, since there is a path of squares of the same size from the lower left square to the upper right one: <image> The length of the sides of the squares on the path is 2. log_2(2) = 1. In the third test, it takes 5 operations for Olya to make the square look like this: <image> Since it requires her to perform 7 splitting operations, and it is impossible to perform them on squares with side equal to 1, then Olya cannot do anything more and the answer is "NO".
instruction
0
36,036
14
72,072
Tags: constructive algorithms, implementation, math Correct Solution: ``` t = int(input()) def sol(n, k): p = 1 q = 1 acc = 0 while n > 0 and k >= p: k -= p n -= 1 if n >= 40: return n acc += q*(4**n-1)//3 if k <= acc: return n p = 2*p+1 q = 2*q+3 return -1 for _ in range(t): n, k = (int(v) for v in input().split()) ans = sol(n, k) if ans == -1: print("NO") else: print("YES", ans) ```
output
1
36,036
14
72,073
Provide tags and a correct Python 3 solution for this coding contest problem. Recently, Olya received a magical square with the size of 2^n× 2^n. It seems to her sister that one square is boring. Therefore, she asked Olya to perform exactly k splitting operations. A Splitting operation is an operation during which Olya takes a square with side a and cuts it into 4 equal squares with side a/2. If the side of the square is equal to 1, then it is impossible to apply a splitting operation to it (see examples for better understanding). Olya is happy to fulfill her sister's request, but she also wants the condition of Olya's happiness to be satisfied after all operations. The condition of Olya's happiness will be satisfied if the following statement is fulfilled: Let the length of the side of the lower left square be equal to a, then the length of the side of the right upper square should also be equal to a. There should also be a path between them that consists only of squares with the side of length a. All consecutive squares on a path should have a common side. Obviously, as long as we have one square, these conditions are met. So Olya is ready to fulfill her sister's request only under the condition that she is satisfied too. Tell her: is it possible to perform exactly k splitting operations in a certain order so that the condition of Olya's happiness is satisfied? If it is possible, tell also the size of the side of squares of which the path from the lower left square to the upper right one will consist. Input The first line contains one integer t (1 ≤ t ≤ 10^3) — the number of tests. Each of the following t lines contains two integers n_i and k_i (1 ≤ n_i ≤ 10^9, 1 ≤ k_i ≤ 10^{18}) — the description of the i-th test, which means that initially Olya's square has size of 2^{n_i}× 2^{n_i} and Olya's sister asks her to do exactly k_i splitting operations. Output Print t lines, where in the i-th line you should output "YES" if it is possible to perform k_i splitting operations in the i-th test in such a way that the condition of Olya's happiness is satisfied or print "NO" otherwise. If you printed "YES", then also print the log_2 of the length of the side of the squares through space, along which you can build a path from the lower left square to the upper right one. You can output each letter in any case (lower or upper). If there are multiple answers, print any. Example Input 3 1 1 2 2 2 12 Output YES 0 YES 1 NO Note In each of the illustrations, the pictures are shown in order in which Olya applied the operations. The recently-created squares are highlighted with red. In the first test, Olya can apply splitting operations in the following order: <image> Olya applies one operation on the only existing square. The condition of Olya's happiness will be met, since there is a path of squares of the same size from the lower left square to the upper right one: <image> The length of the sides of the squares on the path is 1. log_2(1) = 0. In the second test, Olya can apply splitting operations in the following order: <image> Olya applies the first operation on the only existing square. She applies the second one on the right bottom square. The condition of Olya's happiness will be met, since there is a path of squares of the same size from the lower left square to the upper right one: <image> The length of the sides of the squares on the path is 2. log_2(2) = 1. In the third test, it takes 5 operations for Olya to make the square look like this: <image> Since it requires her to perform 7 splitting operations, and it is impossible to perform them on squares with side equal to 1, then Olya cannot do anything more and the answer is "NO".
instruction
0
36,037
14
72,074
Tags: constructive algorithms, implementation, math Correct Solution: ``` def solve(n, k): if n >= 60: return "YES " + str(n - 1) mxxx = (4 ** n - 1) // 3 if k > mxxx: return 'NO' mn, mx = 0, 0 for i in range(n): mn += 2 ** (i + 1) - 1 mx += 4 ** i if mn <= k and mx >= k: return "YES " + str(n - i - 1) # print(mn, mx) if k >= 22 and k <= 25: return 'YES ' + str(n - 3) # OK if k == 2: # OK if n >= 2: return 'YES ' + str(n - 1) return 'NO' if k == 3: # OK if n <= 2: return 'NO' return 'YES ' + str(n - 1) if k >= 6 and k <= 10: #OK return 'YES ' + str(n - 2) t = int(input()) for i in range(t): n, k = map(int, input().split()) print(solve(n, k)) ```
output
1
36,037
14
72,075
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Recently, Olya received a magical square with the size of 2^n× 2^n. It seems to her sister that one square is boring. Therefore, she asked Olya to perform exactly k splitting operations. A Splitting operation is an operation during which Olya takes a square with side a and cuts it into 4 equal squares with side a/2. If the side of the square is equal to 1, then it is impossible to apply a splitting operation to it (see examples for better understanding). Olya is happy to fulfill her sister's request, but she also wants the condition of Olya's happiness to be satisfied after all operations. The condition of Olya's happiness will be satisfied if the following statement is fulfilled: Let the length of the side of the lower left square be equal to a, then the length of the side of the right upper square should also be equal to a. There should also be a path between them that consists only of squares with the side of length a. All consecutive squares on a path should have a common side. Obviously, as long as we have one square, these conditions are met. So Olya is ready to fulfill her sister's request only under the condition that she is satisfied too. Tell her: is it possible to perform exactly k splitting operations in a certain order so that the condition of Olya's happiness is satisfied? If it is possible, tell also the size of the side of squares of which the path from the lower left square to the upper right one will consist. Input The first line contains one integer t (1 ≤ t ≤ 10^3) — the number of tests. Each of the following t lines contains two integers n_i and k_i (1 ≤ n_i ≤ 10^9, 1 ≤ k_i ≤ 10^{18}) — the description of the i-th test, which means that initially Olya's square has size of 2^{n_i}× 2^{n_i} and Olya's sister asks her to do exactly k_i splitting operations. Output Print t lines, where in the i-th line you should output "YES" if it is possible to perform k_i splitting operations in the i-th test in such a way that the condition of Olya's happiness is satisfied or print "NO" otherwise. If you printed "YES", then also print the log_2 of the length of the side of the squares through space, along which you can build a path from the lower left square to the upper right one. You can output each letter in any case (lower or upper). If there are multiple answers, print any. Example Input 3 1 1 2 2 2 12 Output YES 0 YES 1 NO Note In each of the illustrations, the pictures are shown in order in which Olya applied the operations. The recently-created squares are highlighted with red. In the first test, Olya can apply splitting operations in the following order: <image> Olya applies one operation on the only existing square. The condition of Olya's happiness will be met, since there is a path of squares of the same size from the lower left square to the upper right one: <image> The length of the sides of the squares on the path is 1. log_2(1) = 0. In the second test, Olya can apply splitting operations in the following order: <image> Olya applies the first operation on the only existing square. She applies the second one on the right bottom square. The condition of Olya's happiness will be met, since there is a path of squares of the same size from the lower left square to the upper right one: <image> The length of the sides of the squares on the path is 2. log_2(2) = 1. In the third test, it takes 5 operations for Olya to make the square look like this: <image> Since it requires her to perform 7 splitting operations, and it is impossible to perform them on squares with side equal to 1, then Olya cannot do anything more and the answer is "NO". Submitted Solution: ``` def A(n): return (4**n-1)//3 L = 31 T = int(input()) for _ in range(T): n,k = [int(_) for _ in input().split()] if n > L: print("YES",n-1) continue if k > A(n): print("NO") continue E = 1 M = 0 R = 0 while n >= 0: M += E I = 2*E-1 E = 2*E+1 n -= 1 R += I*A(n) if M <= k and k <= M+R: break if n >= 0: print("YES",n) else: print("NO") ```
instruction
0
36,038
14
72,076
Yes
output
1
36,038
14
72,077
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Recently, Olya received a magical square with the size of 2^n× 2^n. It seems to her sister that one square is boring. Therefore, she asked Olya to perform exactly k splitting operations. A Splitting operation is an operation during which Olya takes a square with side a and cuts it into 4 equal squares with side a/2. If the side of the square is equal to 1, then it is impossible to apply a splitting operation to it (see examples for better understanding). Olya is happy to fulfill her sister's request, but she also wants the condition of Olya's happiness to be satisfied after all operations. The condition of Olya's happiness will be satisfied if the following statement is fulfilled: Let the length of the side of the lower left square be equal to a, then the length of the side of the right upper square should also be equal to a. There should also be a path between them that consists only of squares with the side of length a. All consecutive squares on a path should have a common side. Obviously, as long as we have one square, these conditions are met. So Olya is ready to fulfill her sister's request only under the condition that she is satisfied too. Tell her: is it possible to perform exactly k splitting operations in a certain order so that the condition of Olya's happiness is satisfied? If it is possible, tell also the size of the side of squares of which the path from the lower left square to the upper right one will consist. Input The first line contains one integer t (1 ≤ t ≤ 10^3) — the number of tests. Each of the following t lines contains two integers n_i and k_i (1 ≤ n_i ≤ 10^9, 1 ≤ k_i ≤ 10^{18}) — the description of the i-th test, which means that initially Olya's square has size of 2^{n_i}× 2^{n_i} and Olya's sister asks her to do exactly k_i splitting operations. Output Print t lines, where in the i-th line you should output "YES" if it is possible to perform k_i splitting operations in the i-th test in such a way that the condition of Olya's happiness is satisfied or print "NO" otherwise. If you printed "YES", then also print the log_2 of the length of the side of the squares through space, along which you can build a path from the lower left square to the upper right one. You can output each letter in any case (lower or upper). If there are multiple answers, print any. Example Input 3 1 1 2 2 2 12 Output YES 0 YES 1 NO Note In each of the illustrations, the pictures are shown in order in which Olya applied the operations. The recently-created squares are highlighted with red. In the first test, Olya can apply splitting operations in the following order: <image> Olya applies one operation on the only existing square. The condition of Olya's happiness will be met, since there is a path of squares of the same size from the lower left square to the upper right one: <image> The length of the sides of the squares on the path is 1. log_2(1) = 0. In the second test, Olya can apply splitting operations in the following order: <image> Olya applies the first operation on the only existing square. She applies the second one on the right bottom square. The condition of Olya's happiness will be met, since there is a path of squares of the same size from the lower left square to the upper right one: <image> The length of the sides of the squares on the path is 2. log_2(2) = 1. In the third test, it takes 5 operations for Olya to make the square look like this: <image> Since it requires her to perform 7 splitting operations, and it is impossible to perform them on squares with side equal to 1, then Olya cannot do anything more and the answer is "NO". Submitted Solution: ``` T = int(input()) while (T != 0): T -= 1 N, K = map(int, input().split()) cur_usage = 0 reslog = 0 cnts = dict() while True: reslog += 1 cur_usage += (1 << reslog) - 1 if reslog != N: cnts[reslog] = (((1 << reslog)-2)<<1) + 1 if cur_usage + (1 << (reslog+1))-1 > K or reslog == N: break K -= cur_usage while K > 0: if len(cnts) == 0: break for key in cnts: K -= cnts[key] if key+1 >= N: del cnts[key] break if (key+1 not in cnts): cnts[key+1] = 0 cnts[key+1] += cnts[key] * 4 del cnts[key] break if K <= 0: print('YES %d' % (N-reslog)) else: print('NO') ```
instruction
0
36,039
14
72,078
Yes
output
1
36,039
14
72,079
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Recently, Olya received a magical square with the size of 2^n× 2^n. It seems to her sister that one square is boring. Therefore, she asked Olya to perform exactly k splitting operations. A Splitting operation is an operation during which Olya takes a square with side a and cuts it into 4 equal squares with side a/2. If the side of the square is equal to 1, then it is impossible to apply a splitting operation to it (see examples for better understanding). Olya is happy to fulfill her sister's request, but she also wants the condition of Olya's happiness to be satisfied after all operations. The condition of Olya's happiness will be satisfied if the following statement is fulfilled: Let the length of the side of the lower left square be equal to a, then the length of the side of the right upper square should also be equal to a. There should also be a path between them that consists only of squares with the side of length a. All consecutive squares on a path should have a common side. Obviously, as long as we have one square, these conditions are met. So Olya is ready to fulfill her sister's request only under the condition that she is satisfied too. Tell her: is it possible to perform exactly k splitting operations in a certain order so that the condition of Olya's happiness is satisfied? If it is possible, tell also the size of the side of squares of which the path from the lower left square to the upper right one will consist. Input The first line contains one integer t (1 ≤ t ≤ 10^3) — the number of tests. Each of the following t lines contains two integers n_i and k_i (1 ≤ n_i ≤ 10^9, 1 ≤ k_i ≤ 10^{18}) — the description of the i-th test, which means that initially Olya's square has size of 2^{n_i}× 2^{n_i} and Olya's sister asks her to do exactly k_i splitting operations. Output Print t lines, where in the i-th line you should output "YES" if it is possible to perform k_i splitting operations in the i-th test in such a way that the condition of Olya's happiness is satisfied or print "NO" otherwise. If you printed "YES", then also print the log_2 of the length of the side of the squares through space, along which you can build a path from the lower left square to the upper right one. You can output each letter in any case (lower or upper). If there are multiple answers, print any. Example Input 3 1 1 2 2 2 12 Output YES 0 YES 1 NO Note In each of the illustrations, the pictures are shown in order in which Olya applied the operations. The recently-created squares are highlighted with red. In the first test, Olya can apply splitting operations in the following order: <image> Olya applies one operation on the only existing square. The condition of Olya's happiness will be met, since there is a path of squares of the same size from the lower left square to the upper right one: <image> The length of the sides of the squares on the path is 1. log_2(1) = 0. In the second test, Olya can apply splitting operations in the following order: <image> Olya applies the first operation on the only existing square. She applies the second one on the right bottom square. The condition of Olya's happiness will be met, since there is a path of squares of the same size from the lower left square to the upper right one: <image> The length of the sides of the squares on the path is 2. log_2(2) = 1. In the third test, it takes 5 operations for Olya to make the square look like this: <image> Since it requires her to perform 7 splitting operations, and it is impossible to perform them on squares with side equal to 1, then Olya cannot do anything more and the answer is "NO". Submitted Solution: ``` t = int(input()) for iter in range(t): n, k = map(int, input().split()) if n >= 50: if k == 0: print("YES " + str(n)) else: print("YES " + str(n - 1)) else: a = [0] * (n + 1) b = [0] * (n + 1) c = [0] * (n + 1) a[0] = 0 b[n] = 1 c[n] = 0 for i in range(1, n + 1): a[i] = 4 * a[i - 1] + 1 for i in range(n - 1, -1, -1): b[i] = b[i + 1] * 2 + 1 for i in range(n - 1, -1, -1): c[i] = c[i + 1] + b[i + 1] res = -1 for d in range(n + 1): if c[d] <= k and k <= a[n] - a[d] * b[d]: res = d if res == -1: print("NO") else: print("YES " + str(res)) ```
instruction
0
36,040
14
72,080
Yes
output
1
36,040
14
72,081
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Recently, Olya received a magical square with the size of 2^n× 2^n. It seems to her sister that one square is boring. Therefore, she asked Olya to perform exactly k splitting operations. A Splitting operation is an operation during which Olya takes a square with side a and cuts it into 4 equal squares with side a/2. If the side of the square is equal to 1, then it is impossible to apply a splitting operation to it (see examples for better understanding). Olya is happy to fulfill her sister's request, but she also wants the condition of Olya's happiness to be satisfied after all operations. The condition of Olya's happiness will be satisfied if the following statement is fulfilled: Let the length of the side of the lower left square be equal to a, then the length of the side of the right upper square should also be equal to a. There should also be a path between them that consists only of squares with the side of length a. All consecutive squares on a path should have a common side. Obviously, as long as we have one square, these conditions are met. So Olya is ready to fulfill her sister's request only under the condition that she is satisfied too. Tell her: is it possible to perform exactly k splitting operations in a certain order so that the condition of Olya's happiness is satisfied? If it is possible, tell also the size of the side of squares of which the path from the lower left square to the upper right one will consist. Input The first line contains one integer t (1 ≤ t ≤ 10^3) — the number of tests. Each of the following t lines contains two integers n_i and k_i (1 ≤ n_i ≤ 10^9, 1 ≤ k_i ≤ 10^{18}) — the description of the i-th test, which means that initially Olya's square has size of 2^{n_i}× 2^{n_i} and Olya's sister asks her to do exactly k_i splitting operations. Output Print t lines, where in the i-th line you should output "YES" if it is possible to perform k_i splitting operations in the i-th test in such a way that the condition of Olya's happiness is satisfied or print "NO" otherwise. If you printed "YES", then also print the log_2 of the length of the side of the squares through space, along which you can build a path from the lower left square to the upper right one. You can output each letter in any case (lower or upper). If there are multiple answers, print any. Example Input 3 1 1 2 2 2 12 Output YES 0 YES 1 NO Note In each of the illustrations, the pictures are shown in order in which Olya applied the operations. The recently-created squares are highlighted with red. In the first test, Olya can apply splitting operations in the following order: <image> Olya applies one operation on the only existing square. The condition of Olya's happiness will be met, since there is a path of squares of the same size from the lower left square to the upper right one: <image> The length of the sides of the squares on the path is 1. log_2(1) = 0. In the second test, Olya can apply splitting operations in the following order: <image> Olya applies the first operation on the only existing square. She applies the second one on the right bottom square. The condition of Olya's happiness will be met, since there is a path of squares of the same size from the lower left square to the upper right one: <image> The length of the sides of the squares on the path is 2. log_2(2) = 1. In the third test, it takes 5 operations for Olya to make the square look like this: <image> Since it requires her to perform 7 splitting operations, and it is impossible to perform them on squares with side equal to 1, then Olya cannot do anything more and the answer is "NO". Submitted Solution: ``` a = [0 for i in range(100)] b = [0 for i in range(100)] for i in range(1, 100): a[i] = a[i - 1] * 2 + 1 b[i] = b[i - 1] + a[i] def calc(x): return (4 ** x - 1) // 3 for i in range(int(input())): n, k = map(int, input().split()) if n > 35: print("YES " + str(n - 1)) elif 1 + calc(n - 1) >= k: print("YES " + str(n - 1)) elif calc(n) < k: print("NO") else: for i in range(1, (n + 1)): if b[i] <= k and k <= calc(n) - (2 ** (i + 1) - 1) * calc(n - i): print("YES " + str(n - i)) break else: print("NO") ```
instruction
0
36,041
14
72,082
Yes
output
1
36,041
14
72,083
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Recently, Olya received a magical square with the size of 2^n× 2^n. It seems to her sister that one square is boring. Therefore, she asked Olya to perform exactly k splitting operations. A Splitting operation is an operation during which Olya takes a square with side a and cuts it into 4 equal squares with side a/2. If the side of the square is equal to 1, then it is impossible to apply a splitting operation to it (see examples for better understanding). Olya is happy to fulfill her sister's request, but she also wants the condition of Olya's happiness to be satisfied after all operations. The condition of Olya's happiness will be satisfied if the following statement is fulfilled: Let the length of the side of the lower left square be equal to a, then the length of the side of the right upper square should also be equal to a. There should also be a path between them that consists only of squares with the side of length a. All consecutive squares on a path should have a common side. Obviously, as long as we have one square, these conditions are met. So Olya is ready to fulfill her sister's request only under the condition that she is satisfied too. Tell her: is it possible to perform exactly k splitting operations in a certain order so that the condition of Olya's happiness is satisfied? If it is possible, tell also the size of the side of squares of which the path from the lower left square to the upper right one will consist. Input The first line contains one integer t (1 ≤ t ≤ 10^3) — the number of tests. Each of the following t lines contains two integers n_i and k_i (1 ≤ n_i ≤ 10^9, 1 ≤ k_i ≤ 10^{18}) — the description of the i-th test, which means that initially Olya's square has size of 2^{n_i}× 2^{n_i} and Olya's sister asks her to do exactly k_i splitting operations. Output Print t lines, where in the i-th line you should output "YES" if it is possible to perform k_i splitting operations in the i-th test in such a way that the condition of Olya's happiness is satisfied or print "NO" otherwise. If you printed "YES", then also print the log_2 of the length of the side of the squares through space, along which you can build a path from the lower left square to the upper right one. You can output each letter in any case (lower or upper). If there are multiple answers, print any. Example Input 3 1 1 2 2 2 12 Output YES 0 YES 1 NO Note In each of the illustrations, the pictures are shown in order in which Olya applied the operations. The recently-created squares are highlighted with red. In the first test, Olya can apply splitting operations in the following order: <image> Olya applies one operation on the only existing square. The condition of Olya's happiness will be met, since there is a path of squares of the same size from the lower left square to the upper right one: <image> The length of the sides of the squares on the path is 1. log_2(1) = 0. In the second test, Olya can apply splitting operations in the following order: <image> Olya applies the first operation on the only existing square. She applies the second one on the right bottom square. The condition of Olya's happiness will be met, since there is a path of squares of the same size from the lower left square to the upper right one: <image> The length of the sides of the squares on the path is 2. log_2(2) = 1. In the third test, it takes 5 operations for Olya to make the square look like this: <image> Since it requires her to perform 7 splitting operations, and it is impossible to perform them on squares with side equal to 1, then Olya cannot do anything more and the answer is "NO". Submitted Solution: ``` import math t = int(input()) def eval_(n, k): level = math.log(3*k+1,4) if level > n: return "NO" elif n == 2 and k == 3: return "NO" elif n == 1: return "YES 0" elif n == 2 and k==4: return "YES 0" else: level = math.floor(level) # print(level) if level > 5: return "YES " + str(n - level) else: delta = 2**(n-level)*(2**level-1)*(4**(n-level)-1)//3 start = (4**(level)-1)//3 if k <=(start+delta): return "YES " + str(n - level) else: return "YES " + str(n - level-1) for i in range(t): (n, k) = [int(i) for i in input().split()] print(eval_(n, k)) ```
instruction
0
36,042
14
72,084
No
output
1
36,042
14
72,085
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Recently, Olya received a magical square with the size of 2^n× 2^n. It seems to her sister that one square is boring. Therefore, she asked Olya to perform exactly k splitting operations. A Splitting operation is an operation during which Olya takes a square with side a and cuts it into 4 equal squares with side a/2. If the side of the square is equal to 1, then it is impossible to apply a splitting operation to it (see examples for better understanding). Olya is happy to fulfill her sister's request, but she also wants the condition of Olya's happiness to be satisfied after all operations. The condition of Olya's happiness will be satisfied if the following statement is fulfilled: Let the length of the side of the lower left square be equal to a, then the length of the side of the right upper square should also be equal to a. There should also be a path between them that consists only of squares with the side of length a. All consecutive squares on a path should have a common side. Obviously, as long as we have one square, these conditions are met. So Olya is ready to fulfill her sister's request only under the condition that she is satisfied too. Tell her: is it possible to perform exactly k splitting operations in a certain order so that the condition of Olya's happiness is satisfied? If it is possible, tell also the size of the side of squares of which the path from the lower left square to the upper right one will consist. Input The first line contains one integer t (1 ≤ t ≤ 10^3) — the number of tests. Each of the following t lines contains two integers n_i and k_i (1 ≤ n_i ≤ 10^9, 1 ≤ k_i ≤ 10^{18}) — the description of the i-th test, which means that initially Olya's square has size of 2^{n_i}× 2^{n_i} and Olya's sister asks her to do exactly k_i splitting operations. Output Print t lines, where in the i-th line you should output "YES" if it is possible to perform k_i splitting operations in the i-th test in such a way that the condition of Olya's happiness is satisfied or print "NO" otherwise. If you printed "YES", then also print the log_2 of the length of the side of the squares through space, along which you can build a path from the lower left square to the upper right one. You can output each letter in any case (lower or upper). If there are multiple answers, print any. Example Input 3 1 1 2 2 2 12 Output YES 0 YES 1 NO Note In each of the illustrations, the pictures are shown in order in which Olya applied the operations. The recently-created squares are highlighted with red. In the first test, Olya can apply splitting operations in the following order: <image> Olya applies one operation on the only existing square. The condition of Olya's happiness will be met, since there is a path of squares of the same size from the lower left square to the upper right one: <image> The length of the sides of the squares on the path is 1. log_2(1) = 0. In the second test, Olya can apply splitting operations in the following order: <image> Olya applies the first operation on the only existing square. She applies the second one on the right bottom square. The condition of Olya's happiness will be met, since there is a path of squares of the same size from the lower left square to the upper right one: <image> The length of the sides of the squares on the path is 2. log_2(2) = 1. In the third test, it takes 5 operations for Olya to make the square look like this: <image> Since it requires her to perform 7 splitting operations, and it is impossible to perform them on squares with side equal to 1, then Olya cannot do anything more and the answer is "NO". Submitted Solution: ``` t=int(input()) for _ in range(t): n,k=list(map(int,input().split())) if n>=32: print("YES "+str(n-1)) else: ans=-1 for i in range(1,n+1): p=(4**i)-(2**(i+1))+1 p*=(((4**(n-i))-1)//3) p+=(((4**i)-1)//3) if p>=k: ans=n-i break if ans!=-1: print("YES "+str(ans)) else: print("NO") ```
instruction
0
36,043
14
72,086
No
output
1
36,043
14
72,087
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Recently, Olya received a magical square with the size of 2^n× 2^n. It seems to her sister that one square is boring. Therefore, she asked Olya to perform exactly k splitting operations. A Splitting operation is an operation during which Olya takes a square with side a and cuts it into 4 equal squares with side a/2. If the side of the square is equal to 1, then it is impossible to apply a splitting operation to it (see examples for better understanding). Olya is happy to fulfill her sister's request, but she also wants the condition of Olya's happiness to be satisfied after all operations. The condition of Olya's happiness will be satisfied if the following statement is fulfilled: Let the length of the side of the lower left square be equal to a, then the length of the side of the right upper square should also be equal to a. There should also be a path between them that consists only of squares with the side of length a. All consecutive squares on a path should have a common side. Obviously, as long as we have one square, these conditions are met. So Olya is ready to fulfill her sister's request only under the condition that she is satisfied too. Tell her: is it possible to perform exactly k splitting operations in a certain order so that the condition of Olya's happiness is satisfied? If it is possible, tell also the size of the side of squares of which the path from the lower left square to the upper right one will consist. Input The first line contains one integer t (1 ≤ t ≤ 10^3) — the number of tests. Each of the following t lines contains two integers n_i and k_i (1 ≤ n_i ≤ 10^9, 1 ≤ k_i ≤ 10^{18}) — the description of the i-th test, which means that initially Olya's square has size of 2^{n_i}× 2^{n_i} and Olya's sister asks her to do exactly k_i splitting operations. Output Print t lines, where in the i-th line you should output "YES" if it is possible to perform k_i splitting operations in the i-th test in such a way that the condition of Olya's happiness is satisfied or print "NO" otherwise. If you printed "YES", then also print the log_2 of the length of the side of the squares through space, along which you can build a path from the lower left square to the upper right one. You can output each letter in any case (lower or upper). If there are multiple answers, print any. Example Input 3 1 1 2 2 2 12 Output YES 0 YES 1 NO Note In each of the illustrations, the pictures are shown in order in which Olya applied the operations. The recently-created squares are highlighted with red. In the first test, Olya can apply splitting operations in the following order: <image> Olya applies one operation on the only existing square. The condition of Olya's happiness will be met, since there is a path of squares of the same size from the lower left square to the upper right one: <image> The length of the sides of the squares on the path is 1. log_2(1) = 0. In the second test, Olya can apply splitting operations in the following order: <image> Olya applies the first operation on the only existing square. She applies the second one on the right bottom square. The condition of Olya's happiness will be met, since there is a path of squares of the same size from the lower left square to the upper right one: <image> The length of the sides of the squares on the path is 2. log_2(2) = 1. In the third test, it takes 5 operations for Olya to make the square look like this: <image> Since it requires her to perform 7 splitting operations, and it is impossible to perform them on squares with side equal to 1, then Olya cannot do anything more and the answer is "NO". Submitted Solution: ``` NANS = (False, None) def is_valid(n, k): if n > 17: return True return k <= (2**(2*n) - 1) / 3 def solve_mini(n, k): if not is_valid(n, k): return NANS if n == 1: if k == 1: return (True, 0) else: return (False, None) if n == 2: if k in [1, 2]: return (True, 1) if k in [4, 5]: return (True, 2) return (False, None) def solve(n, k): if n < 3: ans, log = solve_mini(n, k) return (ans, log) # validity of k if not is_valid(n, k): return NANS w = 1 while k >= w and n >= 1: k -= w n -= 1 w = w + w + 1 return(True, n) t = int(input()) for i in range(t): n, k = map(int, input().split()) ans, log = solve(n, k) if ans: print("YES", log) else: print("NO") ```
instruction
0
36,044
14
72,088
No
output
1
36,044
14
72,089
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Recently, Olya received a magical square with the size of 2^n× 2^n. It seems to her sister that one square is boring. Therefore, she asked Olya to perform exactly k splitting operations. A Splitting operation is an operation during which Olya takes a square with side a and cuts it into 4 equal squares with side a/2. If the side of the square is equal to 1, then it is impossible to apply a splitting operation to it (see examples for better understanding). Olya is happy to fulfill her sister's request, but she also wants the condition of Olya's happiness to be satisfied after all operations. The condition of Olya's happiness will be satisfied if the following statement is fulfilled: Let the length of the side of the lower left square be equal to a, then the length of the side of the right upper square should also be equal to a. There should also be a path between them that consists only of squares with the side of length a. All consecutive squares on a path should have a common side. Obviously, as long as we have one square, these conditions are met. So Olya is ready to fulfill her sister's request only under the condition that she is satisfied too. Tell her: is it possible to perform exactly k splitting operations in a certain order so that the condition of Olya's happiness is satisfied? If it is possible, tell also the size of the side of squares of which the path from the lower left square to the upper right one will consist. Input The first line contains one integer t (1 ≤ t ≤ 10^3) — the number of tests. Each of the following t lines contains two integers n_i and k_i (1 ≤ n_i ≤ 10^9, 1 ≤ k_i ≤ 10^{18}) — the description of the i-th test, which means that initially Olya's square has size of 2^{n_i}× 2^{n_i} and Olya's sister asks her to do exactly k_i splitting operations. Output Print t lines, where in the i-th line you should output "YES" if it is possible to perform k_i splitting operations in the i-th test in such a way that the condition of Olya's happiness is satisfied or print "NO" otherwise. If you printed "YES", then also print the log_2 of the length of the side of the squares through space, along which you can build a path from the lower left square to the upper right one. You can output each letter in any case (lower or upper). If there are multiple answers, print any. Example Input 3 1 1 2 2 2 12 Output YES 0 YES 1 NO Note In each of the illustrations, the pictures are shown in order in which Olya applied the operations. The recently-created squares are highlighted with red. In the first test, Olya can apply splitting operations in the following order: <image> Olya applies one operation on the only existing square. The condition of Olya's happiness will be met, since there is a path of squares of the same size from the lower left square to the upper right one: <image> The length of the sides of the squares on the path is 1. log_2(1) = 0. In the second test, Olya can apply splitting operations in the following order: <image> Olya applies the first operation on the only existing square. She applies the second one on the right bottom square. The condition of Olya's happiness will be met, since there is a path of squares of the same size from the lower left square to the upper right one: <image> The length of the sides of the squares on the path is 2. log_2(2) = 1. In the third test, it takes 5 operations for Olya to make the square look like this: <image> Since it requires her to perform 7 splitting operations, and it is impossible to perform them on squares with side equal to 1, then Olya cannot do anything more and the answer is "NO". Submitted Solution: ``` # -*- coding:utf-8 -*- """ created by shuangquan.huang at 11/26/18 """ import math def solve(N, K): k34 = math.log(3 * K + 1, 4) if N < k34: print('NO') else: a = N - int(math.floor(k34)) x = K - (4 ** (N - a) - 1) // 3 if a == 0: if x <= 0: print('YES 0') else: print("NO") return if x < 0: pass elif x == 0: print('YES {}'.format(a)) # if x == (2**(N-a+1)-1): elif N - a + 1 <= 64 and 2 ** (N - a + 1) == x + 1: print('YES {}'.format(a - 1)) else: splita = False if N - a + 1 <= math.floor(math.log(x + 1, 2)) and x >= (2**(N-a+1)-1): splita = True x -= (2 ** (N - a + 1) - 1) # if z = (2**(n-a))**2 - (2**(n-a+1)-1) # z*((4**a-1)/3) >= x # z*(4**a-1) >= 3*x # 4**a-1 >= 3*x/z # a >= log(x/3/z+1, 4) if (not splita and a >= 0) or (splita and a >= 1): # if z >= x: if N - a >= math.floor(math.log(math.sqrt(x) + 1, 2)) and (2**(N-a))**2 - (2**(N-a+1)-1) >= x: print('YES {}'.format(a-1 if splita else a)) else: y = 2 ** (N - a) z = (y - 1) ** 2 d = a - math.log(3 * x / z + 1, 4) if d >= 0: print('YES {}'.format(a if not splita else a-1)) elif abs(d) < 1 and z*(4**a-1) >= 3*x: print('YES {}'.format(a if not splita else a - 1)) else: print('NO') else: print("NO") T = int(input()) for ti in range(T): N, K = map(int, input().split()) solve(N, K) ```
instruction
0
36,045
14
72,090
No
output
1
36,045
14
72,091
Provide tags and a correct Python 3 solution for this coding contest problem. «Next please», — the princess called and cast an estimating glance at the next groom. The princess intends to choose the most worthy groom, this is, the richest one. Whenever she sees a groom who is more rich than each of the previous ones, she says a measured «Oh...». Whenever the groom is richer than all previous ones added together, she exclaims «Wow!» (no «Oh...» in this case). At the sight of the first groom the princess stays calm and says nothing. The fortune of each groom is described with an integer between 1 and 50000. You know that during the day the princess saw n grooms, said «Oh...» exactly a times and exclaimed «Wow!» exactly b times. Your task is to output a sequence of n integers t1, t2, ..., tn, where ti describes the fortune of i-th groom. If several sequences are possible, output any of them. If no sequence exists that would satisfy all the requirements, output a single number -1. Input The only line of input data contains three integer numbers n, a and b (1 ≤ n ≤ 100, 0 ≤ a, b ≤ 15, n > a + b), separated with single spaces. Output Output any sequence of integers t1, t2, ..., tn, where ti (1 ≤ ti ≤ 50000) is the fortune of i-th groom, that satisfies the given constraints. If no sequence exists that would satisfy all the requirements, output a single number -1. Examples Input 10 2 3 Output 5 1 3 6 16 35 46 4 200 99 Input 5 0 0 Output 10 10 6 6 5 Note Let's have a closer look at the answer for the first sample test. * The princess said «Oh...» (highlighted in bold): 5 1 3 6 16 35 46 4 200 99. * The princess exclaimed «Wow!» (highlighted in bold): 5 1 3 6 16 35 46 4 200 99.
instruction
0
36,313
14
72,626
Tags: constructive algorithms, greedy Correct Solution: ``` n, a, b = [int(i) for i in input().split()] mx, mxs = 1, 1 if b == 0: if a == 0: for i in range(n, 0, -1): print(i, end=" ") exit() elif a+2 > n: print(-1) exit() else: print(1, 1, end=" ") for i in range(n-2): if a>0: mx += 1 print(mx, end=" ") a-=1 else: print(1, end=" ") exit() else: print(1, end=" ") for i in range(n-1): if b>0: print(mxs+1, end=" ") mx = mxs+1 mxs*=2 mxs+=1 b-=1 elif a>0: print(mx+1, end=" ") mx += 1 a -= 1 else: print(mx, end=" ") ```
output
1
36,313
14
72,627
Provide tags and a correct Python 3 solution for this coding contest problem. «Next please», — the princess called and cast an estimating glance at the next groom. The princess intends to choose the most worthy groom, this is, the richest one. Whenever she sees a groom who is more rich than each of the previous ones, she says a measured «Oh...». Whenever the groom is richer than all previous ones added together, she exclaims «Wow!» (no «Oh...» in this case). At the sight of the first groom the princess stays calm and says nothing. The fortune of each groom is described with an integer between 1 and 50000. You know that during the day the princess saw n grooms, said «Oh...» exactly a times and exclaimed «Wow!» exactly b times. Your task is to output a sequence of n integers t1, t2, ..., tn, where ti describes the fortune of i-th groom. If several sequences are possible, output any of them. If no sequence exists that would satisfy all the requirements, output a single number -1. Input The only line of input data contains three integer numbers n, a and b (1 ≤ n ≤ 100, 0 ≤ a, b ≤ 15, n > a + b), separated with single spaces. Output Output any sequence of integers t1, t2, ..., tn, where ti (1 ≤ ti ≤ 50000) is the fortune of i-th groom, that satisfies the given constraints. If no sequence exists that would satisfy all the requirements, output a single number -1. Examples Input 10 2 3 Output 5 1 3 6 16 35 46 4 200 99 Input 5 0 0 Output 10 10 6 6 5 Note Let's have a closer look at the answer for the first sample test. * The princess said «Oh...» (highlighted in bold): 5 1 3 6 16 35 46 4 200 99. * The princess exclaimed «Wow!» (highlighted in bold): 5 1 3 6 16 35 46 4 200 99.
instruction
0
36,314
14
72,628
Tags: constructive algorithms, greedy Correct Solution: ``` n,a,b = map(int,input().split()) ans = [1 for i in range(n)] p = 2 for i in range(b): ans[i+1] = p p *= 2 p //= 2 if(b == 0 and a > n-2 >= 0): print(-1) exit(0) if(b == 0): b = 1 for i in range(a): ans[1+b+i] = p+1 p += 1 for i in ans: print(i,end = " ") ```
output
1
36,314
14
72,629
Provide tags and a correct Python 3 solution for this coding contest problem. «Next please», — the princess called and cast an estimating glance at the next groom. The princess intends to choose the most worthy groom, this is, the richest one. Whenever she sees a groom who is more rich than each of the previous ones, she says a measured «Oh...». Whenever the groom is richer than all previous ones added together, she exclaims «Wow!» (no «Oh...» in this case). At the sight of the first groom the princess stays calm and says nothing. The fortune of each groom is described with an integer between 1 and 50000. You know that during the day the princess saw n grooms, said «Oh...» exactly a times and exclaimed «Wow!» exactly b times. Your task is to output a sequence of n integers t1, t2, ..., tn, where ti describes the fortune of i-th groom. If several sequences are possible, output any of them. If no sequence exists that would satisfy all the requirements, output a single number -1. Input The only line of input data contains three integer numbers n, a and b (1 ≤ n ≤ 100, 0 ≤ a, b ≤ 15, n > a + b), separated with single spaces. Output Output any sequence of integers t1, t2, ..., tn, where ti (1 ≤ ti ≤ 50000) is the fortune of i-th groom, that satisfies the given constraints. If no sequence exists that would satisfy all the requirements, output a single number -1. Examples Input 10 2 3 Output 5 1 3 6 16 35 46 4 200 99 Input 5 0 0 Output 10 10 6 6 5 Note Let's have a closer look at the answer for the first sample test. * The princess said «Oh...» (highlighted in bold): 5 1 3 6 16 35 46 4 200 99. * The princess exclaimed «Wow!» (highlighted in bold): 5 1 3 6 16 35 46 4 200 99.
instruction
0
36,315
14
72,630
Tags: constructive algorithms, greedy Correct Solution: ``` '''input 10 2 3 ''' # A coding delight from sys import stdin # main starts n, a, b = list(map(int, stdin.readline().split())) k = n - (a + b) ans = [] if k <= 0: print(-1) exit() ans = [1] k -= 1 s = sum(ans) for i in range(b): ans.append(s + 1) s += ans[-1] if a > 0: if ans[-1] + 1 > s: if k == 0: print(-1) exit() else: ans.append(1) k -= 1 for i in range(a): ans.append(ans[-1] + 1) for i in range(k): ans.append(1) print(*ans) ```
output
1
36,315
14
72,631
Provide tags and a correct Python 3 solution for this coding contest problem. «Next please», — the princess called and cast an estimating glance at the next groom. The princess intends to choose the most worthy groom, this is, the richest one. Whenever she sees a groom who is more rich than each of the previous ones, she says a measured «Oh...». Whenever the groom is richer than all previous ones added together, she exclaims «Wow!» (no «Oh...» in this case). At the sight of the first groom the princess stays calm and says nothing. The fortune of each groom is described with an integer between 1 and 50000. You know that during the day the princess saw n grooms, said «Oh...» exactly a times and exclaimed «Wow!» exactly b times. Your task is to output a sequence of n integers t1, t2, ..., tn, where ti describes the fortune of i-th groom. If several sequences are possible, output any of them. If no sequence exists that would satisfy all the requirements, output a single number -1. Input The only line of input data contains three integer numbers n, a and b (1 ≤ n ≤ 100, 0 ≤ a, b ≤ 15, n > a + b), separated with single spaces. Output Output any sequence of integers t1, t2, ..., tn, where ti (1 ≤ ti ≤ 50000) is the fortune of i-th groom, that satisfies the given constraints. If no sequence exists that would satisfy all the requirements, output a single number -1. Examples Input 10 2 3 Output 5 1 3 6 16 35 46 4 200 99 Input 5 0 0 Output 10 10 6 6 5 Note Let's have a closer look at the answer for the first sample test. * The princess said «Oh...» (highlighted in bold): 5 1 3 6 16 35 46 4 200 99. * The princess exclaimed «Wow!» (highlighted in bold): 5 1 3 6 16 35 46 4 200 99.
instruction
0
36,316
14
72,632
Tags: constructive algorithms, greedy Correct Solution: ``` import sys #import math #from queue import * #import random #sys.setrecursionlimit(int(1e6)) input = sys.stdin.readline ############ ---- USER DEFINED INPUT FUNCTIONS ---- ############ def inp(): return(int(input())) def inara(): return(list(map(int,input().split()))) def insr(): s = input() return(list(s[:len(s) - 1])) def invr(): return(map(int,input().split())) ################################################################ ############ ---- THE ACTUAL CODE STARTS BELOW ---- ############ n,a,b=invr() if n==1: print(100) exit(0) if b==0: if a==n-1: print(-1) exit(0) ans=[0]*n ans[0]=2 ans[1]=1 for i in range(2,n): if i<2+a: ans[i]=i+1 else: ans[i]=1 print(*ans) exit(0) #assert(a!=0) ans=[1] curr=1 for i in range(1,b+1): ans.append(curr+1) if ans[i]>50000: print(-1) exit(0) curr+=ans[i] for i in range(a): ans.append(ans[-1]+1) while len(ans)<n: ans.append(1) if max(ans)>50000: print(-1) exit(0) print(*ans) ```
output
1
36,316
14
72,633
Provide tags and a correct Python 3 solution for this coding contest problem. «Next please», — the princess called and cast an estimating glance at the next groom. The princess intends to choose the most worthy groom, this is, the richest one. Whenever she sees a groom who is more rich than each of the previous ones, she says a measured «Oh...». Whenever the groom is richer than all previous ones added together, she exclaims «Wow!» (no «Oh...» in this case). At the sight of the first groom the princess stays calm and says nothing. The fortune of each groom is described with an integer between 1 and 50000. You know that during the day the princess saw n grooms, said «Oh...» exactly a times and exclaimed «Wow!» exactly b times. Your task is to output a sequence of n integers t1, t2, ..., tn, where ti describes the fortune of i-th groom. If several sequences are possible, output any of them. If no sequence exists that would satisfy all the requirements, output a single number -1. Input The only line of input data contains three integer numbers n, a and b (1 ≤ n ≤ 100, 0 ≤ a, b ≤ 15, n > a + b), separated with single spaces. Output Output any sequence of integers t1, t2, ..., tn, where ti (1 ≤ ti ≤ 50000) is the fortune of i-th groom, that satisfies the given constraints. If no sequence exists that would satisfy all the requirements, output a single number -1. Examples Input 10 2 3 Output 5 1 3 6 16 35 46 4 200 99 Input 5 0 0 Output 10 10 6 6 5 Note Let's have a closer look at the answer for the first sample test. * The princess said «Oh...» (highlighted in bold): 5 1 3 6 16 35 46 4 200 99. * The princess exclaimed «Wow!» (highlighted in bold): 5 1 3 6 16 35 46 4 200 99.
instruction
0
36,317
14
72,634
Tags: constructive algorithms, greedy Correct Solution: ``` n,a,b=map(int,input().split()) ma=1;su=1;k=0 if b==0 and a>0: if a==n-1: exit(print(-1)) print(1,end=' ') if b==0: for i in range(min(n-1,1)): print(1,end=' ');su+=1;n-=1 for i in range(b): k=su print(su+1,end=' ') su+=(su+1) ma=k+1 for i in range(a): ma+=1 print(ma,end=' ') for i in range(n-a-b-1): print(ma,end=' ') su+=ma ```
output
1
36,317
14
72,635
Provide tags and a correct Python 3 solution for this coding contest problem. «Next please», — the princess called and cast an estimating glance at the next groom. The princess intends to choose the most worthy groom, this is, the richest one. Whenever she sees a groom who is more rich than each of the previous ones, she says a measured «Oh...». Whenever the groom is richer than all previous ones added together, she exclaims «Wow!» (no «Oh...» in this case). At the sight of the first groom the princess stays calm and says nothing. The fortune of each groom is described with an integer between 1 and 50000. You know that during the day the princess saw n grooms, said «Oh...» exactly a times and exclaimed «Wow!» exactly b times. Your task is to output a sequence of n integers t1, t2, ..., tn, where ti describes the fortune of i-th groom. If several sequences are possible, output any of them. If no sequence exists that would satisfy all the requirements, output a single number -1. Input The only line of input data contains three integer numbers n, a and b (1 ≤ n ≤ 100, 0 ≤ a, b ≤ 15, n > a + b), separated with single spaces. Output Output any sequence of integers t1, t2, ..., tn, where ti (1 ≤ ti ≤ 50000) is the fortune of i-th groom, that satisfies the given constraints. If no sequence exists that would satisfy all the requirements, output a single number -1. Examples Input 10 2 3 Output 5 1 3 6 16 35 46 4 200 99 Input 5 0 0 Output 10 10 6 6 5 Note Let's have a closer look at the answer for the first sample test. * The princess said «Oh...» (highlighted in bold): 5 1 3 6 16 35 46 4 200 99. * The princess exclaimed «Wow!» (highlighted in bold): 5 1 3 6 16 35 46 4 200 99.
instruction
0
36,318
14
72,636
Tags: constructive algorithms, greedy Correct Solution: ``` n, a, b = map(int, input().split()) if b == 0 and n > 1: if a == n-1: print(-1) exit() print(1, end=' ') n -= 1 print(*[1<<i for i in range(b+1)], end=' ') print(*[(1<<b)+i+1 for i in range(a)], end=' ') print(*[1 for i in range(n - a - b - 1)], end=' ') ```
output
1
36,318
14
72,637
Provide tags and a correct Python 3 solution for this coding contest problem. «Next please», — the princess called and cast an estimating glance at the next groom. The princess intends to choose the most worthy groom, this is, the richest one. Whenever she sees a groom who is more rich than each of the previous ones, she says a measured «Oh...». Whenever the groom is richer than all previous ones added together, she exclaims «Wow!» (no «Oh...» in this case). At the sight of the first groom the princess stays calm and says nothing. The fortune of each groom is described with an integer between 1 and 50000. You know that during the day the princess saw n grooms, said «Oh...» exactly a times and exclaimed «Wow!» exactly b times. Your task is to output a sequence of n integers t1, t2, ..., tn, where ti describes the fortune of i-th groom. If several sequences are possible, output any of them. If no sequence exists that would satisfy all the requirements, output a single number -1. Input The only line of input data contains three integer numbers n, a and b (1 ≤ n ≤ 100, 0 ≤ a, b ≤ 15, n > a + b), separated with single spaces. Output Output any sequence of integers t1, t2, ..., tn, where ti (1 ≤ ti ≤ 50000) is the fortune of i-th groom, that satisfies the given constraints. If no sequence exists that would satisfy all the requirements, output a single number -1. Examples Input 10 2 3 Output 5 1 3 6 16 35 46 4 200 99 Input 5 0 0 Output 10 10 6 6 5 Note Let's have a closer look at the answer for the first sample test. * The princess said «Oh...» (highlighted in bold): 5 1 3 6 16 35 46 4 200 99. * The princess exclaimed «Wow!» (highlighted in bold): 5 1 3 6 16 35 46 4 200 99.
instruction
0
36,319
14
72,638
Tags: constructive algorithms, greedy Correct Solution: ``` l=input().split() n=int(l[0]) a=int(l[1]) b=int(l[2]) if(b==0): if(n>=a+2): print(1) print(1) for i in range(a): print(i+2) for i in range(n-a-2): print(a+1) elif(a==0): for i in range(n): print(1) else: print(-1) elif(b>15): print(-1) else: ans=1 print(ans,end=" ") for i in range(b): ans=2*ans print(ans,end=" ") for i in range(1,a+1): print(ans+i,end=" ") for i in range(n-a-b-1): print(1,end=" ") ```
output
1
36,319
14
72,639
Provide tags and a correct Python 3 solution for this coding contest problem. «Next please», — the princess called and cast an estimating glance at the next groom. The princess intends to choose the most worthy groom, this is, the richest one. Whenever she sees a groom who is more rich than each of the previous ones, she says a measured «Oh...». Whenever the groom is richer than all previous ones added together, she exclaims «Wow!» (no «Oh...» in this case). At the sight of the first groom the princess stays calm and says nothing. The fortune of each groom is described with an integer between 1 and 50000. You know that during the day the princess saw n grooms, said «Oh...» exactly a times and exclaimed «Wow!» exactly b times. Your task is to output a sequence of n integers t1, t2, ..., tn, where ti describes the fortune of i-th groom. If several sequences are possible, output any of them. If no sequence exists that would satisfy all the requirements, output a single number -1. Input The only line of input data contains three integer numbers n, a and b (1 ≤ n ≤ 100, 0 ≤ a, b ≤ 15, n > a + b), separated with single spaces. Output Output any sequence of integers t1, t2, ..., tn, where ti (1 ≤ ti ≤ 50000) is the fortune of i-th groom, that satisfies the given constraints. If no sequence exists that would satisfy all the requirements, output a single number -1. Examples Input 10 2 3 Output 5 1 3 6 16 35 46 4 200 99 Input 5 0 0 Output 10 10 6 6 5 Note Let's have a closer look at the answer for the first sample test. * The princess said «Oh...» (highlighted in bold): 5 1 3 6 16 35 46 4 200 99. * The princess exclaimed «Wow!» (highlighted in bold): 5 1 3 6 16 35 46 4 200 99.
instruction
0
36,320
14
72,640
Tags: constructive algorithms, greedy Correct Solution: ``` n,ohh,wow= list(map(int , input().split())) if(wow==0): if(n>=ohh+2): print(1,end=" ") print(1,end=" ") for i in range(ohh): print(i+2,end=" ") for i in range(n-ohh-2): print(ohh+1,end=" ") elif(ohh==0): for i in range(n): print(1,end=" ") else: print(-1) else: ans=1 print(ans,end=" ") for i in range(wow): ans*= 2 print(ans,end=" ") for i in range(1,ohh+1): print(ans+i,end=" ") for i in range(n-ohh-wow-1): print(1,end=" ") ```
output
1
36,320
14
72,641
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. «Next please», — the princess called and cast an estimating glance at the next groom. The princess intends to choose the most worthy groom, this is, the richest one. Whenever she sees a groom who is more rich than each of the previous ones, she says a measured «Oh...». Whenever the groom is richer than all previous ones added together, she exclaims «Wow!» (no «Oh...» in this case). At the sight of the first groom the princess stays calm and says nothing. The fortune of each groom is described with an integer between 1 and 50000. You know that during the day the princess saw n grooms, said «Oh...» exactly a times and exclaimed «Wow!» exactly b times. Your task is to output a sequence of n integers t1, t2, ..., tn, where ti describes the fortune of i-th groom. If several sequences are possible, output any of them. If no sequence exists that would satisfy all the requirements, output a single number -1. Input The only line of input data contains three integer numbers n, a and b (1 ≤ n ≤ 100, 0 ≤ a, b ≤ 15, n > a + b), separated with single spaces. Output Output any sequence of integers t1, t2, ..., tn, where ti (1 ≤ ti ≤ 50000) is the fortune of i-th groom, that satisfies the given constraints. If no sequence exists that would satisfy all the requirements, output a single number -1. Examples Input 10 2 3 Output 5 1 3 6 16 35 46 4 200 99 Input 5 0 0 Output 10 10 6 6 5 Note Let's have a closer look at the answer for the first sample test. * The princess said «Oh...» (highlighted in bold): 5 1 3 6 16 35 46 4 200 99. * The princess exclaimed «Wow!» (highlighted in bold): 5 1 3 6 16 35 46 4 200 99. Submitted Solution: ``` n,ohh,wow= list(map(int , input().split())) if(wow==0): if(n>=ohh+2): print(1,end=" ") print(1,end=" ") for i in range(1,ohh+1): print(i+1,end=" ") for i in range(n-ohh-2): print(ohh+1,end=" ") elif(ohh==0): for i in range(n): print(1,end=" ") else: print(-1) else: ans=1 print(ans,end=" ") for i in range(wow): ans*= 2 print(ans,end=" ") for i in range(1,ohh+1): print(ans+i,end=" ") for i in range(n-ohh-wow-1): print(1,end=" ") ```
instruction
0
36,321
14
72,642
Yes
output
1
36,321
14
72,643
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. «Next please», — the princess called and cast an estimating glance at the next groom. The princess intends to choose the most worthy groom, this is, the richest one. Whenever she sees a groom who is more rich than each of the previous ones, she says a measured «Oh...». Whenever the groom is richer than all previous ones added together, she exclaims «Wow!» (no «Oh...» in this case). At the sight of the first groom the princess stays calm and says nothing. The fortune of each groom is described with an integer between 1 and 50000. You know that during the day the princess saw n grooms, said «Oh...» exactly a times and exclaimed «Wow!» exactly b times. Your task is to output a sequence of n integers t1, t2, ..., tn, where ti describes the fortune of i-th groom. If several sequences are possible, output any of them. If no sequence exists that would satisfy all the requirements, output a single number -1. Input The only line of input data contains three integer numbers n, a and b (1 ≤ n ≤ 100, 0 ≤ a, b ≤ 15, n > a + b), separated with single spaces. Output Output any sequence of integers t1, t2, ..., tn, where ti (1 ≤ ti ≤ 50000) is the fortune of i-th groom, that satisfies the given constraints. If no sequence exists that would satisfy all the requirements, output a single number -1. Examples Input 10 2 3 Output 5 1 3 6 16 35 46 4 200 99 Input 5 0 0 Output 10 10 6 6 5 Note Let's have a closer look at the answer for the first sample test. * The princess said «Oh...» (highlighted in bold): 5 1 3 6 16 35 46 4 200 99. * The princess exclaimed «Wow!» (highlighted in bold): 5 1 3 6 16 35 46 4 200 99. Submitted Solution: ``` #------------------------template--------------------------# import os import sys from math import * from collections import * from fractions import * from bisect import * from heapq import* from io import BytesIO, IOBase def vsInput(): sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w') 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") ALPHA='abcdefghijklmnopqrstuvwxyz' MOD=1000000007 def value():return tuple(map(int,input().split())) def array():return [int(i) for i in input().split()] def Int():return int(input()) def Str():return input() def arrayS():return [i for i in input().split()] #-------------------------code---------------------------# # vsInput() n,a,b=value() ans=[1] cur=sum(ans) for i in range(b): ans.append(cur+1) cur+=cur+1 for i in range(a+b+1,n): ans.append(1) ma=max(ans) for i in range(a): ans.append(ma+1) ma+=1 cur=1 ma=1 wow=0 oh=0 for i in range(1,n): if(ans[i]>cur): wow+=1 elif(ans[i]>ma): oh+=1 ma=max(ma,ans[i]) cur+=ans[i] if(wow==b and oh==a): print(*ans) else: print(-1) ```
instruction
0
36,322
14
72,644
Yes
output
1
36,322
14
72,645
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. «Next please», — the princess called and cast an estimating glance at the next groom. The princess intends to choose the most worthy groom, this is, the richest one. Whenever she sees a groom who is more rich than each of the previous ones, she says a measured «Oh...». Whenever the groom is richer than all previous ones added together, she exclaims «Wow!» (no «Oh...» in this case). At the sight of the first groom the princess stays calm and says nothing. The fortune of each groom is described with an integer between 1 and 50000. You know that during the day the princess saw n grooms, said «Oh...» exactly a times and exclaimed «Wow!» exactly b times. Your task is to output a sequence of n integers t1, t2, ..., tn, where ti describes the fortune of i-th groom. If several sequences are possible, output any of them. If no sequence exists that would satisfy all the requirements, output a single number -1. Input The only line of input data contains three integer numbers n, a and b (1 ≤ n ≤ 100, 0 ≤ a, b ≤ 15, n > a + b), separated with single spaces. Output Output any sequence of integers t1, t2, ..., tn, where ti (1 ≤ ti ≤ 50000) is the fortune of i-th groom, that satisfies the given constraints. If no sequence exists that would satisfy all the requirements, output a single number -1. Examples Input 10 2 3 Output 5 1 3 6 16 35 46 4 200 99 Input 5 0 0 Output 10 10 6 6 5 Note Let's have a closer look at the answer for the first sample test. * The princess said «Oh...» (highlighted in bold): 5 1 3 6 16 35 46 4 200 99. * The princess exclaimed «Wow!» (highlighted in bold): 5 1 3 6 16 35 46 4 200 99. Submitted Solution: ``` n,a,b=map(int,input().split()) x=1 buf=[1] sum=1 t=n-a-b-1 if a+b==n: print(-1) exit() for i in range(a+b): if b: x=sum+1 buf.append(x) sum+=x b-=1 else: if x+1>sum: if t: buf.append(1) t-=1 sum+=1 else: print(-1) exit() x+=1 sum+=x buf.append(x) a-=1 for i in range(t): buf.append(x) if buf[-1]>50000: print(-1) else: print(buf[0],end='') for i in range(1,len(buf)): print('',buf[i],end='') print('') ```
instruction
0
36,323
14
72,646
Yes
output
1
36,323
14
72,647
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. «Next please», — the princess called and cast an estimating glance at the next groom. The princess intends to choose the most worthy groom, this is, the richest one. Whenever she sees a groom who is more rich than each of the previous ones, she says a measured «Oh...». Whenever the groom is richer than all previous ones added together, she exclaims «Wow!» (no «Oh...» in this case). At the sight of the first groom the princess stays calm and says nothing. The fortune of each groom is described with an integer between 1 and 50000. You know that during the day the princess saw n grooms, said «Oh...» exactly a times and exclaimed «Wow!» exactly b times. Your task is to output a sequence of n integers t1, t2, ..., tn, where ti describes the fortune of i-th groom. If several sequences are possible, output any of them. If no sequence exists that would satisfy all the requirements, output a single number -1. Input The only line of input data contains three integer numbers n, a and b (1 ≤ n ≤ 100, 0 ≤ a, b ≤ 15, n > a + b), separated with single spaces. Output Output any sequence of integers t1, t2, ..., tn, where ti (1 ≤ ti ≤ 50000) is the fortune of i-th groom, that satisfies the given constraints. If no sequence exists that would satisfy all the requirements, output a single number -1. Examples Input 10 2 3 Output 5 1 3 6 16 35 46 4 200 99 Input 5 0 0 Output 10 10 6 6 5 Note Let's have a closer look at the answer for the first sample test. * The princess said «Oh...» (highlighted in bold): 5 1 3 6 16 35 46 4 200 99. * The princess exclaimed «Wow!» (highlighted in bold): 5 1 3 6 16 35 46 4 200 99. Submitted Solution: ``` n,a,b = map(int, input().split()) answer=[1] if a==0 and b==0: print("1 "*n) exit(0) if n<= a+b or (b==0 and n<= a+1): print(-1) exit(0) for i in range(b): answer.append(2**(i+1)) if b == 0: answer.append(1) for i in range(a): answer.append(answer[-1]+1) z=len(answer) for i in range(n-z): answer.append(answer[-1]) print(" ".join(str(el) for el in answer)) ```
instruction
0
36,324
14
72,648
Yes
output
1
36,324
14
72,649
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. «Next please», — the princess called and cast an estimating glance at the next groom. The princess intends to choose the most worthy groom, this is, the richest one. Whenever she sees a groom who is more rich than each of the previous ones, she says a measured «Oh...». Whenever the groom is richer than all previous ones added together, she exclaims «Wow!» (no «Oh...» in this case). At the sight of the first groom the princess stays calm and says nothing. The fortune of each groom is described with an integer between 1 and 50000. You know that during the day the princess saw n grooms, said «Oh...» exactly a times and exclaimed «Wow!» exactly b times. Your task is to output a sequence of n integers t1, t2, ..., tn, where ti describes the fortune of i-th groom. If several sequences are possible, output any of them. If no sequence exists that would satisfy all the requirements, output a single number -1. Input The only line of input data contains three integer numbers n, a and b (1 ≤ n ≤ 100, 0 ≤ a, b ≤ 15, n > a + b), separated with single spaces. Output Output any sequence of integers t1, t2, ..., tn, where ti (1 ≤ ti ≤ 50000) is the fortune of i-th groom, that satisfies the given constraints. If no sequence exists that would satisfy all the requirements, output a single number -1. Examples Input 10 2 3 Output 5 1 3 6 16 35 46 4 200 99 Input 5 0 0 Output 10 10 6 6 5 Note Let's have a closer look at the answer for the first sample test. * The princess said «Oh...» (highlighted in bold): 5 1 3 6 16 35 46 4 200 99. * The princess exclaimed «Wow!» (highlighted in bold): 5 1 3 6 16 35 46 4 200 99. Submitted Solution: ``` def simple(n, a): if a == n - 1: print(-1) return ret = [50000] * n for i in range(a - 1, -1, -1): ret[i] = ret[i + 1] - 1 for i in range(a + 1, n): ret[i] = 1 print(' '.join(str(x) for x in ret)) def score(v): a, b = 0, 0 last = v[0] s = v[0] for x in v[1:]: if x > s: b += 1 elif x > last: a += 1 last = max(last, x) s += x return a, b def main(): n, a, b = map(int, input().split()) if b == 0: simple(n, a) ret = [1] s = 1 for _ in range(b): ret.append(s + 1) s += ret[-1] for _ in range(a): ret.append(ret[-1] + 1) if len(ret) > n or any(x > 50000 for x in ret): print(-1) return while len(ret) < n: ret.append(1) ga, gb = score(ret) assert(all(1 <= x <= 50000 for x in ret)) assert(len(ret) == n) assert(a == ga) assert(b == gb) print(' '.join(str(x) for x in ret)) main() ```
instruction
0
36,325
14
72,650
No
output
1
36,325
14
72,651
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. «Next please», — the princess called and cast an estimating glance at the next groom. The princess intends to choose the most worthy groom, this is, the richest one. Whenever she sees a groom who is more rich than each of the previous ones, she says a measured «Oh...». Whenever the groom is richer than all previous ones added together, she exclaims «Wow!» (no «Oh...» in this case). At the sight of the first groom the princess stays calm and says nothing. The fortune of each groom is described with an integer between 1 and 50000. You know that during the day the princess saw n grooms, said «Oh...» exactly a times and exclaimed «Wow!» exactly b times. Your task is to output a sequence of n integers t1, t2, ..., tn, where ti describes the fortune of i-th groom. If several sequences are possible, output any of them. If no sequence exists that would satisfy all the requirements, output a single number -1. Input The only line of input data contains three integer numbers n, a and b (1 ≤ n ≤ 100, 0 ≤ a, b ≤ 15, n > a + b), separated with single spaces. Output Output any sequence of integers t1, t2, ..., tn, where ti (1 ≤ ti ≤ 50000) is the fortune of i-th groom, that satisfies the given constraints. If no sequence exists that would satisfy all the requirements, output a single number -1. Examples Input 10 2 3 Output 5 1 3 6 16 35 46 4 200 99 Input 5 0 0 Output 10 10 6 6 5 Note Let's have a closer look at the answer for the first sample test. * The princess said «Oh...» (highlighted in bold): 5 1 3 6 16 35 46 4 200 99. * The princess exclaimed «Wow!» (highlighted in bold): 5 1 3 6 16 35 46 4 200 99. Submitted Solution: ``` t=1 for you in range(t): l=input().split() n=int(l[0]) a=int(l[1]) b=int(l[2]) if(b==15): print(-1) else: ans=1 print(ans,end=" ") for i in range(b): ans=2*ans print(ans,end=" ") for i in range(1,a+1): print(ans+i,end=" ") for i in range(n-a-b-1): print(1,end=" ") print() ```
instruction
0
36,326
14
72,652
No
output
1
36,326
14
72,653
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. «Next please», — the princess called and cast an estimating glance at the next groom. The princess intends to choose the most worthy groom, this is, the richest one. Whenever she sees a groom who is more rich than each of the previous ones, she says a measured «Oh...». Whenever the groom is richer than all previous ones added together, she exclaims «Wow!» (no «Oh...» in this case). At the sight of the first groom the princess stays calm and says nothing. The fortune of each groom is described with an integer between 1 and 50000. You know that during the day the princess saw n grooms, said «Oh...» exactly a times and exclaimed «Wow!» exactly b times. Your task is to output a sequence of n integers t1, t2, ..., tn, where ti describes the fortune of i-th groom. If several sequences are possible, output any of them. If no sequence exists that would satisfy all the requirements, output a single number -1. Input The only line of input data contains three integer numbers n, a and b (1 ≤ n ≤ 100, 0 ≤ a, b ≤ 15, n > a + b), separated with single spaces. Output Output any sequence of integers t1, t2, ..., tn, where ti (1 ≤ ti ≤ 50000) is the fortune of i-th groom, that satisfies the given constraints. If no sequence exists that would satisfy all the requirements, output a single number -1. Examples Input 10 2 3 Output 5 1 3 6 16 35 46 4 200 99 Input 5 0 0 Output 10 10 6 6 5 Note Let's have a closer look at the answer for the first sample test. * The princess said «Oh...» (highlighted in bold): 5 1 3 6 16 35 46 4 200 99. * The princess exclaimed «Wow!» (highlighted in bold): 5 1 3 6 16 35 46 4 200 99. Submitted Solution: ``` def simple(n, a): ret = [50000] * n for i in range(a - 1, -1, -1): ret[i] = ret[i + 1] - 1 for i in range(a + 1, n): ret[i] = 1 print(' '.join(str(x) for x in ret)) def main(): n, a, b = map(int, input().split()) if b == 0: simple(n, a) return ret = [1] s = 1 for _ in range(b): ret.append(s + 1) s += s + 1 for _ in range(a): ret.append(ret[-1] + 1) ret[-1] = max(ret[-1], 50000) if len(ret) > n or any(x > 50000 for x in ret): print(-1) return while len(ret) < n: ret.append(1) print(' '.join(str(x) for x in ret)) main() ```
instruction
0
36,327
14
72,654
No
output
1
36,327
14
72,655