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. Akari has n kinds of flowers, one of each kind. She is going to choose one or more of these flowers to make a bouquet. However, she hates two numbers a and b, so the number of flowers in the bouquet cannot be a or b. How many different bouquets are there that Akari can make? Find the count modulo (10^9 + 7). Here, two bouquets are considered different when there is a flower that is used in one of the bouquets but not in the other bouquet. Constraints * All values in input are integers. * 2 \leq n \leq 10^9 * 1 \leq a < b \leq \textrm{min}(n, 2 \times 10^5) Input Input is given from Standard Input in the following format: n a b Output Print the number of bouquets that Akari can make, modulo (10^9 + 7). (If there are no such bouquets, print `0`.) Examples Input 4 1 3 Output 7 Input 1000000000 141421 173205 Output 34076506 Submitted Solution: ``` import math n, a, b = map(int, input().split()) def c_c(n, r): return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) ans = 0 for i in range(1,n+1): if i == a or i == b: continue else: ans += c_c(n,i) print(ans % 1000000007) ```
instruction
0
48,573
14
97,146
No
output
1
48,573
14
97,147
Provide tags and a correct Python 3 solution for this coding contest problem. A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are m containers, in the i-th container there are ai matchboxes, and each matchbox contains bi matches. All the matchboxes are of the same size. The burglar's rucksack can hold n matchboxes exactly. Your task is to find out the maximum amount of matches that a burglar can carry away. He has no time to rearrange matches in the matchboxes, that's why he just chooses not more than n matchboxes so that the total amount of matches in them is maximal. Input The first line of the input contains integer n (1 ≤ n ≤ 2·108) and integer m (1 ≤ m ≤ 20). The i + 1-th line contains a pair of numbers ai and bi (1 ≤ ai ≤ 108, 1 ≤ bi ≤ 10). All the input numbers are integer. Output Output the only number — answer to the problem. Examples Input 7 3 5 10 2 5 3 6 Output 62 Input 3 3 1 3 2 2 3 1 Output 7
instruction
0
49,106
14
98,212
Tags: greedy, implementation, sortings Correct Solution: ``` n, m = map(int, input().split(' ')) match = {} bs = [] for i in range (m): a,b = map(int, input().split(' ')) if b in bs: match[b] = match[b] + a else: match[b] = a bs.append(b) sizes = list(match.keys()) sizes.sort(reverse=True) boxes = [] for i in sizes: boxes.append(match[i]) left = n ans = 0 for i in range (len(boxes)): if boxes[i] < left: left = left - boxes[i] ans = ans + boxes[i] * sizes[i] else: if boxes[i] == left: ans = ans + boxes[i]*sizes[i] break else: if boxes[i] > left: ans = ans + left*sizes[i] break print(ans) ```
output
1
49,106
14
98,213
Provide tags and a correct Python 3 solution for this coding contest problem. A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are m containers, in the i-th container there are ai matchboxes, and each matchbox contains bi matches. All the matchboxes are of the same size. The burglar's rucksack can hold n matchboxes exactly. Your task is to find out the maximum amount of matches that a burglar can carry away. He has no time to rearrange matches in the matchboxes, that's why he just chooses not more than n matchboxes so that the total amount of matches in them is maximal. Input The first line of the input contains integer n (1 ≤ n ≤ 2·108) and integer m (1 ≤ m ≤ 20). The i + 1-th line contains a pair of numbers ai and bi (1 ≤ ai ≤ 108, 1 ≤ bi ≤ 10). All the input numbers are integer. Output Output the only number — answer to the problem. Examples Input 7 3 5 10 2 5 3 6 Output 62 Input 3 3 1 3 2 2 3 1 Output 7
instruction
0
49,107
14
98,214
Tags: greedy, implementation, sortings Correct Solution: ``` n,m=map(int,input().split()) l=[] for i in range(m): a,b=map(int,input().split()) l.append((a,b)) l.sort(key=lambda x: x[1],reverse=True) ans=0 for i in range(m): if n==0: break x=min(l[i][0],n) ans+=x*l[i][1] n-=x print(ans) ```
output
1
49,107
14
98,215
Provide tags and a correct Python 3 solution for this coding contest problem. A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are m containers, in the i-th container there are ai matchboxes, and each matchbox contains bi matches. All the matchboxes are of the same size. The burglar's rucksack can hold n matchboxes exactly. Your task is to find out the maximum amount of matches that a burglar can carry away. He has no time to rearrange matches in the matchboxes, that's why he just chooses not more than n matchboxes so that the total amount of matches in them is maximal. Input The first line of the input contains integer n (1 ≤ n ≤ 2·108) and integer m (1 ≤ m ≤ 20). The i + 1-th line contains a pair of numbers ai and bi (1 ≤ ai ≤ 108, 1 ≤ bi ≤ 10). All the input numbers are integer. Output Output the only number — answer to the problem. Examples Input 7 3 5 10 2 5 3 6 Output 62 Input 3 3 1 3 2 2 3 1 Output 7
instruction
0
49,108
14
98,216
Tags: greedy, implementation, sortings Correct Solution: ``` import os import math box_cont = input().rstrip().split() n=int(box_cont[0]) m=int(box_cont[1]) hah=[0]*11 for i in range(m): a_b=input().rstrip().split() a=int(a_b[0]) b=int(a_b[1]) hah[b]+=a total=0 for i in range(10,0,-1): if hah[i]!= 0: if n-hah[i]>=0: total+=(hah[i]*i) n=n-hah[i] else: total+=i*n break print(total) ```
output
1
49,108
14
98,217
Provide tags and a correct Python 3 solution for this coding contest problem. A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are m containers, in the i-th container there are ai matchboxes, and each matchbox contains bi matches. All the matchboxes are of the same size. The burglar's rucksack can hold n matchboxes exactly. Your task is to find out the maximum amount of matches that a burglar can carry away. He has no time to rearrange matches in the matchboxes, that's why he just chooses not more than n matchboxes so that the total amount of matches in them is maximal. Input The first line of the input contains integer n (1 ≤ n ≤ 2·108) and integer m (1 ≤ m ≤ 20). The i + 1-th line contains a pair of numbers ai and bi (1 ≤ ai ≤ 108, 1 ≤ bi ≤ 10). All the input numbers are integer. Output Output the only number — answer to the problem. Examples Input 7 3 5 10 2 5 3 6 Output 62 Input 3 3 1 3 2 2 3 1 Output 7
instruction
0
49,109
14
98,218
Tags: greedy, implementation, sortings Correct Solution: ``` n, m = map(int, input().split()) cnt = [0] * 11 for _ in range(m): a, b = map(int, input().split()) cnt[b] += a ans = 0 for i in range(10, 0, -1): if n - cnt[i] >= 0: ans += i * cnt[i] n -= cnt[i] else: ans += i * n break print(ans) ```
output
1
49,109
14
98,219
Provide tags and a correct Python 3 solution for this coding contest problem. A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are m containers, in the i-th container there are ai matchboxes, and each matchbox contains bi matches. All the matchboxes are of the same size. The burglar's rucksack can hold n matchboxes exactly. Your task is to find out the maximum amount of matches that a burglar can carry away. He has no time to rearrange matches in the matchboxes, that's why he just chooses not more than n matchboxes so that the total amount of matches in them is maximal. Input The first line of the input contains integer n (1 ≤ n ≤ 2·108) and integer m (1 ≤ m ≤ 20). The i + 1-th line contains a pair of numbers ai and bi (1 ≤ ai ≤ 108, 1 ≤ bi ≤ 10). All the input numbers are integer. Output Output the only number — answer to the problem. Examples Input 7 3 5 10 2 5 3 6 Output 62 Input 3 3 1 3 2 2 3 1 Output 7
instruction
0
49,110
14
98,220
Tags: greedy, implementation, sortings Correct Solution: ``` n, m = map(int, input().split()) info = [] for _ in range(m): info.append(list(map(int, input().split()))) info_sorted = info.copy() for i in range(m-1): for j in range(m)[i+1:]: if info_sorted[i][1]<info_sorted[j][1]: info_sorted[j],info_sorted[i] = info_sorted[i],info_sorted[j] sum = 0 cnt = 0 for a,b in info_sorted: sum=sum+a if sum<=n: cnt = cnt + a*b else: cnt = cnt + (n-(sum-a))*b break print(cnt) ```
output
1
49,110
14
98,221
Provide tags and a correct Python 3 solution for this coding contest problem. A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are m containers, in the i-th container there are ai matchboxes, and each matchbox contains bi matches. All the matchboxes are of the same size. The burglar's rucksack can hold n matchboxes exactly. Your task is to find out the maximum amount of matches that a burglar can carry away. He has no time to rearrange matches in the matchboxes, that's why he just chooses not more than n matchboxes so that the total amount of matches in them is maximal. Input The first line of the input contains integer n (1 ≤ n ≤ 2·108) and integer m (1 ≤ m ≤ 20). The i + 1-th line contains a pair of numbers ai and bi (1 ≤ ai ≤ 108, 1 ≤ bi ≤ 10). All the input numbers are integer. Output Output the only number — answer to the problem. Examples Input 7 3 5 10 2 5 3 6 Output 62 Input 3 3 1 3 2 2 3 1 Output 7
instruction
0
49,111
14
98,222
Tags: greedy, implementation, sortings Correct Solution: ``` n,m=map(int,input().split()) k=[] for i in range(m): k.append(tuple(map(int,input().split()))) k=tuple(sorted(k,key=lambda x:x[1],reverse=True)) ans=0 i=0 while n>0: try: if n>k[i][0]: ans+=k[i][0]*k[i][1] n-=k[i][0] else: ans+=n*k[i][1] n-=k[i][0] i+=1 except: break print(ans) ```
output
1
49,111
14
98,223
Provide tags and a correct Python 3 solution for this coding contest problem. A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are m containers, in the i-th container there are ai matchboxes, and each matchbox contains bi matches. All the matchboxes are of the same size. The burglar's rucksack can hold n matchboxes exactly. Your task is to find out the maximum amount of matches that a burglar can carry away. He has no time to rearrange matches in the matchboxes, that's why he just chooses not more than n matchboxes so that the total amount of matches in them is maximal. Input The first line of the input contains integer n (1 ≤ n ≤ 2·108) and integer m (1 ≤ m ≤ 20). The i + 1-th line contains a pair of numbers ai and bi (1 ≤ ai ≤ 108, 1 ≤ bi ≤ 10). All the input numbers are integer. Output Output the only number — answer to the problem. Examples Input 7 3 5 10 2 5 3 6 Output 62 Input 3 3 1 3 2 2 3 1 Output 7
instruction
0
49,112
14
98,224
Tags: greedy, implementation, sortings Correct Solution: ``` n, m = input().split() n = int(n); m = int(m) a = [] for i in range(m): b = [int(j) for j in input().split()] a.append(b) a.sort(key = lambda x: x[1], reverse=True) count = 0 l = 0 # print(a) for i in range(m): if a[i][0] > n-l: count += (n-l)*a[i][1] break else: l += a[i][0] count += a[i][0]*a[i][1] print(count) ```
output
1
49,112
14
98,225
Provide tags and a correct Python 3 solution for this coding contest problem. A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are m containers, in the i-th container there are ai matchboxes, and each matchbox contains bi matches. All the matchboxes are of the same size. The burglar's rucksack can hold n matchboxes exactly. Your task is to find out the maximum amount of matches that a burglar can carry away. He has no time to rearrange matches in the matchboxes, that's why he just chooses not more than n matchboxes so that the total amount of matches in them is maximal. Input The first line of the input contains integer n (1 ≤ n ≤ 2·108) and integer m (1 ≤ m ≤ 20). The i + 1-th line contains a pair of numbers ai and bi (1 ≤ ai ≤ 108, 1 ≤ bi ≤ 10). All the input numbers are integer. Output Output the only number — answer to the problem. Examples Input 7 3 5 10 2 5 3 6 Output 62 Input 3 3 1 3 2 2 3 1 Output 7
instruction
0
49,113
14
98,226
Tags: greedy, implementation, sortings Correct Solution: ``` # Author : nitish420 -------------------------------------------------------------------- import os import sys from io import BytesIO, IOBase # mod=10**9+7 # sys.setrecursionlimit(10**6) # mxm=sys.maxsize # from functools import lru_cache def main(): n,m=map(int,input().split()) arr=[] for _ in range(m): arr.append(list(map(int,input().split()))) arr.sort(key=lambda x: x[1]) arr=arr[::-1] # print(arr) ans=0 for item in arr: if item[0]<=n: ans+=item[1]*(item[0]) n-=item[0] else: ans+=item[1]*n break print(ans) # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = 'x' in file.mode or 'r' not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b'\n') + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode('ascii')) self.read = lambda: self.buffer.read().decode('ascii') self.readline = lambda: self.buffer.readline().decode('ascii') sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip('\r\n') def nouse3(): # This is to save my code from plag due to use of FAST IO template in it. a=420 b=420 print(f'i am nitish{(a+b)//2}') def nouse4(): # This is to save my code from plag due to use of FAST IO template in it. a=420 b=420 print(f'i am nitish{(a+b)//2}') def nouse5(): # This is to save my code from plag due to use of FAST IO template in it. a=420 b=420 print(f'i am nitish{(a+b)//2}') # endregion if __name__ == '__main__': main() ```
output
1
49,113
14
98,227
Provide tags and a correct Python 3 solution for this coding contest problem. Dima took up the biology of bacteria, as a result of his experiments, he invented k types of bacteria. Overall, there are n bacteria at his laboratory right now, and the number of bacteria of type i equals ci. For convenience, we will assume that all the bacteria are numbered from 1 to n. The bacteria of type ci are numbered from <image> to <image>. With the help of special equipment Dima can move energy from some bacteria into some other one. Of course, the use of such equipment is not free. Dima knows m ways to move energy from some bacteria to another one. The way with number i can be described with integers ui, vi and xi mean that this way allows moving energy from bacteria with number ui to bacteria with number vi or vice versa for xi dollars. Dima's Chef (Inna) calls the type-distribution correct if there is a way (may be non-direct) to move energy from any bacteria of the particular type to any other bacteria of the same type (between any two bacteria of the same type) for zero cost. As for correct type-distribution the cost of moving the energy depends only on the types of bacteria help Inna to determine is the type-distribution correct? If it is, print the matrix d with size k × k. Cell d[i][j] of this matrix must be equal to the minimal possible cost of energy-moving from bacteria with type i to bacteria with type j. Input The first line contains three integers n, m, k (1 ≤ n ≤ 105; 0 ≤ m ≤ 105; 1 ≤ k ≤ 500). The next line contains k integers c1, c2, ..., ck (1 ≤ ci ≤ n). Each of the next m lines contains three integers ui, vi, xi (1 ≤ ui, vi ≤ 105; 0 ≤ xi ≤ 104). It is guaranteed that <image>. Output If Dima's type-distribution is correct, print string «Yes», and then k lines: in the i-th line print integers d[i][1], d[i][2], ..., d[i][k] (d[i][i] = 0). If there is no way to move energy from bacteria i to bacteria j appropriate d[i][j] must equal to -1. If the type-distribution isn't correct print «No». Examples Input 4 4 2 1 3 2 3 0 3 4 0 2 4 1 2 1 2 Output Yes 0 2 2 0 Input 3 1 2 2 1 1 2 0 Output Yes 0 -1 -1 0 Input 3 2 2 2 1 1 2 0 2 3 1 Output Yes 0 1 1 0 Input 3 0 2 1 2 Output No
instruction
0
49,176
14
98,352
Tags: dsu, graphs, shortest paths Correct Solution: ``` #!/usr/bin/env python3 from sys import stdin from bisect import bisect_left, bisect_right INF = int(1e9) def find(par, a): if par[a] == a: return a par[a] = find(par, par[a]) return par[a] def union(par, rnk, a, b): a = find(par,a) b = find(par,b) if a==b: return if rnk[a]<rnk[b]: par[a] = b else: par[b] = a if rnk[a]==rnk[b]: rnk[a] += 1 def solve(): n, m, k = map(int, stdin.readline().split()) cnts = list(map(int, stdin.readline().split())) for i in range(1,k): cnts[i] += cnts[i-1] group = list(range(n)) rnk = [0 for i in range(n)] adj = [[INF for j in range(k)] for i in range(k)] for i in range(m): u, v, x = map(int, stdin.readline().split()) if x==0: union(group, rnk, u-1, v-1) tu = bisect_left(cnts, u) tv = bisect_left(cnts, v) adj[tu][tv] = min(adj[tu][tv], x) adj[tv][tu] = min(adj[tv][tu], x) p = 0 for i in range(k): cur = group[p] while p<cnts[i]: if group[p]!=cur: print("No") return p += 1 print("Yes") for p in range(k): for i in range(k): for j in range(k): adj[i][j] = min(adj[i][j], adj[i][p]+adj[p][j]) for i in range(k): adj[i][i] = 0 for j in range(k): if adj[i][j] == INF: adj[i][j] = -1 for i in range(k): print(' '.join(map(lambda x: str(x), adj[i]))) solve() ```
output
1
49,176
14
98,353
Provide tags and a correct Python 3 solution for this coding contest problem. As everyone knows, bears love fish. But Mike is a strange bear; He hates fish! The even more strange thing about him is he has an infinite number of blue and red fish. <image> He has marked n distinct points in the plane. i-th point is point (xi, yi). He wants to put exactly one fish in each of these points such that the difference between the number of red fish and the blue fish on each horizontal or vertical line is at most 1. He can't find a way to perform that! Please help him. Input The first line of input contains integer n (1 ≤ n ≤ 2 × 105). The next n lines contain the information about the points, i-th line contains two integers xi and yi (1 ≤ xi, yi ≤ 2 × 105), the i-th point coordinates. It is guaranteed that there is at least one valid answer. Output Print the answer as a sequence of n characters 'r' (for red) or 'b' (for blue) where i-th character denotes the color of the fish in the i-th point. Examples Input 4 1 1 1 2 2 1 2 2 Output brrb Input 3 1 1 1 2 2 1 Output brr
instruction
0
49,223
14
98,446
Tags: constructive algorithms, dfs and similar, graphs Correct Solution: ``` n = int(input()) edges = [] from collections import defaultdict edges_dico = {} count = defaultdict(int) graph = defaultdict(lambda: defaultdict(int)) edges = [] for _ in range(n): u, v = map(int, input().split()) count[u] += 1 count[-v] += 1 graph[u][-v] = 1 graph[-v][u] = 1 edges.append((u, -v)) edges_dico[(u, -v)] = True # we need to transform the graph to do find an eulerian circuit odds = [] for u in count: if count[u] % 2 == 1: odds.append(u) A = 2 * 10 ** 6 + 1 B = 2 * 10 ** 6 + 2 for u in odds: if u > 0: graph[A][u] = 1 graph[u][A] = 1 count[A] += 1 else: graph[B][u] = 1 graph[u][B] = 1 count[B] += 1 if count[A] % 2 == 1: graph[A][B] = 1 graph[B][A] = 1 # Now we do kind of hierholtzer... i = 0 import sys count_deleted = 0 j = 0 nodes = graph.keys() for u in nodes: current = u color = "r" while True: color = "b" if color == "r" else "r" end = True edge_to_delete = None for neighbour in graph[current]: if graph[current][neighbour] == 1: edge_to_delete = (current, neighbour) if (neighbour, current) in edges_dico: edges_dico[(neighbour, current)] = color if (current, neighbour) in edges_dico: edges_dico[(current, neighbour)] = color count_deleted += 1 current = neighbour end = False break if end: break else: u, v = edge_to_delete del graph[u][v] del graph[v][u] print("".join([edges_dico[edge] for edge in edges])) ```
output
1
49,223
14
98,447
Provide tags and a correct Python 3 solution for this coding contest problem. As everyone knows, bears love fish. But Mike is a strange bear; He hates fish! The even more strange thing about him is he has an infinite number of blue and red fish. <image> He has marked n distinct points in the plane. i-th point is point (xi, yi). He wants to put exactly one fish in each of these points such that the difference between the number of red fish and the blue fish on each horizontal or vertical line is at most 1. He can't find a way to perform that! Please help him. Input The first line of input contains integer n (1 ≤ n ≤ 2 × 105). The next n lines contain the information about the points, i-th line contains two integers xi and yi (1 ≤ xi, yi ≤ 2 × 105), the i-th point coordinates. It is guaranteed that there is at least one valid answer. Output Print the answer as a sequence of n characters 'r' (for red) or 'b' (for blue) where i-th character denotes the color of the fish in the i-th point. Examples Input 4 1 1 1 2 2 1 2 2 Output brrb Input 3 1 1 1 2 2 1 Output brr
instruction
0
49,224
14
98,448
Tags: constructive algorithms, dfs and similar, graphs Correct Solution: ``` from sys import stdin, stdout from collections import defaultdict time = 0 c = 2*10**5 n = 4*10**5+2 col = 0 finished= [0]*n for_node = [0]*n f_range=range f_len=len def dfs_euler_tour(node: int, graph): stack = [] global colour global col global time stack.append((node, -1)) while stack: s, ind = stack.pop() if ind > -1: if ind < f_len(colour): colour[ind] = col col = col ^ 1 index = for_node[s] while(index < f_len(graph[s])): v,i=graph[s][index] if not visited[i]: stack.append((v, i)) visited[i] = True index += 1 for_node[s] = index break index += 1 finished[s]+1 m = int(stdin.readline()) graph =defaultdict(list) edges=[] debug=[] for i in f_range(m): u, v = stdin.readline().split() u, v = (int(u)-1, int(v)-1 + c+1) edges.append((u, v)) graph[u].append((v, i)) graph[v].append((u, i)) if u == 30630-1 and m == 199809: debug.append(i) colour = [-1]*m odds= [i for i in graph.keys() if f_len(graph[i]) % 2] if odds: for i in f_range(f_len(odds)): u = odds[i] ind=f_len(edges) if u<c: v = n-1 else: v = c edges.append((u, v)) graph[u].append((v, ind)) graph[v].append((u, ind)) if f_len(graph[n-1]) % 2: u=n-1 v=c ind = f_len(edges) edges.append((u, v)) graph[u].append((v, ind)) graph[v].append((u, ind)) visited = [False]*f_len(edges) for i in graph.keys(): if not finished[i]: dfs_euler_tour(i, graph) sol = ''.join(['b' if i == 1 else 'r' for i in colour]) sol += '\n' stdout.write(sol) ```
output
1
49,224
14
98,449
Provide tags and a correct Python 3 solution for this coding contest problem. As everyone knows, bears love fish. But Mike is a strange bear; He hates fish! The even more strange thing about him is he has an infinite number of blue and red fish. <image> He has marked n distinct points in the plane. i-th point is point (xi, yi). He wants to put exactly one fish in each of these points such that the difference between the number of red fish and the blue fish on each horizontal or vertical line is at most 1. He can't find a way to perform that! Please help him. Input The first line of input contains integer n (1 ≤ n ≤ 2 × 105). The next n lines contain the information about the points, i-th line contains two integers xi and yi (1 ≤ xi, yi ≤ 2 × 105), the i-th point coordinates. It is guaranteed that there is at least one valid answer. Output Print the answer as a sequence of n characters 'r' (for red) or 'b' (for blue) where i-th character denotes the color of the fish in the i-th point. Examples Input 4 1 1 1 2 2 1 2 2 Output brrb Input 3 1 1 1 2 2 1 Output brr
instruction
0
49,225
14
98,450
Tags: constructive algorithms, dfs and similar, graphs Correct Solution: ``` from sys import stdin, stdout from collections import defaultdict time = 0 c = 2*10**5 n = 4*10**5+2 col = 0 finished= [0]*n for_node = [0]*n f_range=range f_len=len def dfs_euler_tour(node: int, graph): stack = [] global colour global col global time stack.append((node, -1)) while stack: s, ind = stack.pop() if ind > -1: if ind < f_len(colour): colour[ind] = col col = col ^ 1 index = for_node[s] while(index < f_len(graph[s])): v,i=graph[s][index] if not visited[i]: stack.append((v, i)) visited[i] = True index += 1 for_node[s] = index break index += 1 finished[s]+1 m = int(stdin.readline()) graph =defaultdict(list) edges=[] debug=[] for i in f_range(m): u, v = stdin.readline().split() u, v = (int(u)-1, int(v)-1 + c+1) edges.append((u, v)) graph[u].append((v, i)) graph[v].append((u, i)) if u == 30630-1 and m == 199809: debug.append(i) colour = [-1]*m odds= [i for i in graph.keys() if f_len(graph[i]) % 2] if odds: for i in f_range(f_len(odds)): u = odds[i] ind=f_len(edges) if u<c: v = n-1 else: v = c edges.append((u, v)) graph[u].append((v, ind)) graph[v].append((u, ind)) if f_len(graph[n-1]) % 2: u=n-1 v=c ind = f_len(edges) edges.append((u, v)) graph[u].append((v, ind)) graph[v].append((u, ind)) visited = [False]*f_len(edges) size=[(f_len(graph[i]),i) for i in graph.keys()] size.sort(reverse=True) order=[c,n-1] for i in size: if i[1]!=c and i[1]!=n-1: order.append(i[1]) for i in order: if not finished[i]: dfs_euler_tour(i, graph) debug=[] if debug: stdout.write(f'{f_len(debug)} ') for i in debug: if colour[i]==-1: stdout.write(f'{colour[i]},{visited[i]} ') sol = ''.join(['b' if i == 1 else 'r' for i in colour]) sol += '\n' stdout.write(sol) ```
output
1
49,225
14
98,451
Provide tags and a correct Python 3 solution for this coding contest problem. Limak is a grizzly bear who desires power and adoration. He wants to win in upcoming elections and rule over the Bearland. There are n candidates, including Limak. We know how many citizens are going to vote for each candidate. Now i-th candidate would get ai votes. Limak is candidate number 1. To win in elections, he must get strictly more votes than any other candidate. Victory is more important than everything else so Limak decided to cheat. He will steal votes from his opponents by bribing some citizens. To bribe a citizen, Limak must give him or her one candy - citizens are bears and bears like candies. Limak doesn't have many candies and wonders - how many citizens does he have to bribe? Input The first line contains single integer n (2 ≤ n ≤ 100) - number of candidates. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 1000) - number of votes for each candidate. Limak is candidate number 1. Note that after bribing number of votes for some candidate might be zero or might be greater than 1000. Output Print the minimum number of citizens Limak must bribe to have strictly more votes than any other candidate. Examples Input 5 5 1 11 2 8 Output 4 Input 4 1 8 8 8 Output 6 Input 2 7 6 Output 0 Note In the first sample Limak has 5 votes. One of the ways to achieve victory is to bribe 4 citizens who want to vote for the third candidate. Then numbers of votes would be 9, 1, 7, 2, 8 (Limak would have 9 votes). Alternatively, Limak could steal only 3 votes from the third candidate and 1 vote from the second candidate to get situation 9, 0, 8, 2, 8. In the second sample Limak will steal 2 votes from each candidate. Situation will be 7, 6, 6, 6. In the third sample Limak is a winner without bribing any citizen.
instruction
0
49,230
14
98,460
Tags: greedy, implementation Correct Solution: ``` import bisect import collections import copy import functools import heapq import itertools import math import random import re import sys import time import string from typing import List, Mapping sys.setrecursionlimit(999999) n = int(input()) arr = list(map(int,input().split())) a = arr.pop(0) arr.sort() ans = 0 while a<=arr[-1]: t = arr.pop() bisect.insort(arr,t-1) a+=1 ans+=1 print(ans) ```
output
1
49,230
14
98,461
Provide tags and a correct Python 3 solution for this coding contest problem. Limak is a grizzly bear who desires power and adoration. He wants to win in upcoming elections and rule over the Bearland. There are n candidates, including Limak. We know how many citizens are going to vote for each candidate. Now i-th candidate would get ai votes. Limak is candidate number 1. To win in elections, he must get strictly more votes than any other candidate. Victory is more important than everything else so Limak decided to cheat. He will steal votes from his opponents by bribing some citizens. To bribe a citizen, Limak must give him or her one candy - citizens are bears and bears like candies. Limak doesn't have many candies and wonders - how many citizens does he have to bribe? Input The first line contains single integer n (2 ≤ n ≤ 100) - number of candidates. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 1000) - number of votes for each candidate. Limak is candidate number 1. Note that after bribing number of votes for some candidate might be zero or might be greater than 1000. Output Print the minimum number of citizens Limak must bribe to have strictly more votes than any other candidate. Examples Input 5 5 1 11 2 8 Output 4 Input 4 1 8 8 8 Output 6 Input 2 7 6 Output 0 Note In the first sample Limak has 5 votes. One of the ways to achieve victory is to bribe 4 citizens who want to vote for the third candidate. Then numbers of votes would be 9, 1, 7, 2, 8 (Limak would have 9 votes). Alternatively, Limak could steal only 3 votes from the third candidate and 1 vote from the second candidate to get situation 9, 0, 8, 2, 8. In the second sample Limak will steal 2 votes from each candidate. Situation will be 7, 6, 6, 6. In the third sample Limak is a winner without bribing any citizen.
instruction
0
49,231
14
98,462
Tags: greedy, implementation Correct Solution: ``` _,a=input(),list(map(int,input().split())); l=a[0] b=[0]*1001 s=l for i in range(1,len(a)): b[a[i]]+=1 for i in range(len(b)-1,-1,-1): if l>i: print(0) break elif b[i]>0: if s+b[i]>i: print(i-l+1) break s+=b[i] b[i-1]+=b[i] ```
output
1
49,231
14
98,463
Provide tags and a correct Python 3 solution for this coding contest problem. Limak is a grizzly bear who desires power and adoration. He wants to win in upcoming elections and rule over the Bearland. There are n candidates, including Limak. We know how many citizens are going to vote for each candidate. Now i-th candidate would get ai votes. Limak is candidate number 1. To win in elections, he must get strictly more votes than any other candidate. Victory is more important than everything else so Limak decided to cheat. He will steal votes from his opponents by bribing some citizens. To bribe a citizen, Limak must give him or her one candy - citizens are bears and bears like candies. Limak doesn't have many candies and wonders - how many citizens does he have to bribe? Input The first line contains single integer n (2 ≤ n ≤ 100) - number of candidates. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 1000) - number of votes for each candidate. Limak is candidate number 1. Note that after bribing number of votes for some candidate might be zero or might be greater than 1000. Output Print the minimum number of citizens Limak must bribe to have strictly more votes than any other candidate. Examples Input 5 5 1 11 2 8 Output 4 Input 4 1 8 8 8 Output 6 Input 2 7 6 Output 0 Note In the first sample Limak has 5 votes. One of the ways to achieve victory is to bribe 4 citizens who want to vote for the third candidate. Then numbers of votes would be 9, 1, 7, 2, 8 (Limak would have 9 votes). Alternatively, Limak could steal only 3 votes from the third candidate and 1 vote from the second candidate to get situation 9, 0, 8, 2, 8. In the second sample Limak will steal 2 votes from each candidate. Situation will be 7, 6, 6, 6. In the third sample Limak is a winner without bribing any citizen.
instruction
0
49,232
14
98,464
Tags: greedy, implementation Correct Solution: ``` from collections import * def li():return [int(i) for i in input().rstrip('\n').split(' ')] def st():return input().rstrip('\n') def val():return int(input()) n = val() l = li() tot = 0 for i in range(n): l[i] = [l[i],i] l.sort(reverse = 1) while l[0][1] != 0: ind = 0 for i in range(len(l)): if l[i][1] == 0: ind = i break l[ind][0]+=1 l[0][0]-=1 tot += 1 l.sort(reverse = 1) print(tot) ```
output
1
49,232
14
98,465
Provide tags and a correct Python 3 solution for this coding contest problem. Limak is a grizzly bear who desires power and adoration. He wants to win in upcoming elections and rule over the Bearland. There are n candidates, including Limak. We know how many citizens are going to vote for each candidate. Now i-th candidate would get ai votes. Limak is candidate number 1. To win in elections, he must get strictly more votes than any other candidate. Victory is more important than everything else so Limak decided to cheat. He will steal votes from his opponents by bribing some citizens. To bribe a citizen, Limak must give him or her one candy - citizens are bears and bears like candies. Limak doesn't have many candies and wonders - how many citizens does he have to bribe? Input The first line contains single integer n (2 ≤ n ≤ 100) - number of candidates. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 1000) - number of votes for each candidate. Limak is candidate number 1. Note that after bribing number of votes for some candidate might be zero or might be greater than 1000. Output Print the minimum number of citizens Limak must bribe to have strictly more votes than any other candidate. Examples Input 5 5 1 11 2 8 Output 4 Input 4 1 8 8 8 Output 6 Input 2 7 6 Output 0 Note In the first sample Limak has 5 votes. One of the ways to achieve victory is to bribe 4 citizens who want to vote for the third candidate. Then numbers of votes would be 9, 1, 7, 2, 8 (Limak would have 9 votes). Alternatively, Limak could steal only 3 votes from the third candidate and 1 vote from the second candidate to get situation 9, 0, 8, 2, 8. In the second sample Limak will steal 2 votes from each candidate. Situation will be 7, 6, 6, 6. In the third sample Limak is a winner without bribing any citizen.
instruction
0
49,233
14
98,466
Tags: greedy, implementation Correct Solution: ``` n = int(input()) c = list(map(int, input().split())) count = 0 while True: maxx = c[0] point = 0 for i in range(len(c)): if c[i] >= maxx: maxx = c[i] point = i if point != 0: c[0] += 1 c[point] -= 1 count += 1 else: break print(count) ```
output
1
49,233
14
98,467
Provide tags and a correct Python 3 solution for this coding contest problem. Limak is a grizzly bear who desires power and adoration. He wants to win in upcoming elections and rule over the Bearland. There are n candidates, including Limak. We know how many citizens are going to vote for each candidate. Now i-th candidate would get ai votes. Limak is candidate number 1. To win in elections, he must get strictly more votes than any other candidate. Victory is more important than everything else so Limak decided to cheat. He will steal votes from his opponents by bribing some citizens. To bribe a citizen, Limak must give him or her one candy - citizens are bears and bears like candies. Limak doesn't have many candies and wonders - how many citizens does he have to bribe? Input The first line contains single integer n (2 ≤ n ≤ 100) - number of candidates. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 1000) - number of votes for each candidate. Limak is candidate number 1. Note that after bribing number of votes for some candidate might be zero or might be greater than 1000. Output Print the minimum number of citizens Limak must bribe to have strictly more votes than any other candidate. Examples Input 5 5 1 11 2 8 Output 4 Input 4 1 8 8 8 Output 6 Input 2 7 6 Output 0 Note In the first sample Limak has 5 votes. One of the ways to achieve victory is to bribe 4 citizens who want to vote for the third candidate. Then numbers of votes would be 9, 1, 7, 2, 8 (Limak would have 9 votes). Alternatively, Limak could steal only 3 votes from the third candidate and 1 vote from the second candidate to get situation 9, 0, 8, 2, 8. In the second sample Limak will steal 2 votes from each candidate. Situation will be 7, 6, 6, 6. In the third sample Limak is a winner without bribing any citizen.
instruction
0
49,234
14
98,468
Tags: greedy, implementation Correct Solution: ``` import heapq n = map(int, input().split()) votes = list(map(int, input().split())) limak = votes[0] votes = [-x for x in votes[1:]] heapq.heapify(votes) ans = 0 while limak <= -votes[0]: vote = -heapq.heappop(votes) vote -= 1 limak += 1 ans += 1 heapq.heappush(votes, -vote) print(ans) ```
output
1
49,234
14
98,469
Provide tags and a correct Python 3 solution for this coding contest problem. Limak is a grizzly bear who desires power and adoration. He wants to win in upcoming elections and rule over the Bearland. There are n candidates, including Limak. We know how many citizens are going to vote for each candidate. Now i-th candidate would get ai votes. Limak is candidate number 1. To win in elections, he must get strictly more votes than any other candidate. Victory is more important than everything else so Limak decided to cheat. He will steal votes from his opponents by bribing some citizens. To bribe a citizen, Limak must give him or her one candy - citizens are bears and bears like candies. Limak doesn't have many candies and wonders - how many citizens does he have to bribe? Input The first line contains single integer n (2 ≤ n ≤ 100) - number of candidates. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 1000) - number of votes for each candidate. Limak is candidate number 1. Note that after bribing number of votes for some candidate might be zero or might be greater than 1000. Output Print the minimum number of citizens Limak must bribe to have strictly more votes than any other candidate. Examples Input 5 5 1 11 2 8 Output 4 Input 4 1 8 8 8 Output 6 Input 2 7 6 Output 0 Note In the first sample Limak has 5 votes. One of the ways to achieve victory is to bribe 4 citizens who want to vote for the third candidate. Then numbers of votes would be 9, 1, 7, 2, 8 (Limak would have 9 votes). Alternatively, Limak could steal only 3 votes from the third candidate and 1 vote from the second candidate to get situation 9, 0, 8, 2, 8. In the second sample Limak will steal 2 votes from each candidate. Situation will be 7, 6, 6, 6. In the third sample Limak is a winner without bribing any citizen.
instruction
0
49,235
14
98,470
Tags: greedy, implementation Correct Solution: ``` input() A, k = list(map(int, input().split())), 0 while True: i = A.index(max(A)) if i == 0: print(k + (A.count(A[0]) > 1)) break A[0], A[i], k = A[0] + 1, A[i] - 1, k + 1 ```
output
1
49,235
14
98,471
Provide tags and a correct Python 3 solution for this coding contest problem. Limak is a grizzly bear who desires power and adoration. He wants to win in upcoming elections and rule over the Bearland. There are n candidates, including Limak. We know how many citizens are going to vote for each candidate. Now i-th candidate would get ai votes. Limak is candidate number 1. To win in elections, he must get strictly more votes than any other candidate. Victory is more important than everything else so Limak decided to cheat. He will steal votes from his opponents by bribing some citizens. To bribe a citizen, Limak must give him or her one candy - citizens are bears and bears like candies. Limak doesn't have many candies and wonders - how many citizens does he have to bribe? Input The first line contains single integer n (2 ≤ n ≤ 100) - number of candidates. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 1000) - number of votes for each candidate. Limak is candidate number 1. Note that after bribing number of votes for some candidate might be zero or might be greater than 1000. Output Print the minimum number of citizens Limak must bribe to have strictly more votes than any other candidate. Examples Input 5 5 1 11 2 8 Output 4 Input 4 1 8 8 8 Output 6 Input 2 7 6 Output 0 Note In the first sample Limak has 5 votes. One of the ways to achieve victory is to bribe 4 citizens who want to vote for the third candidate. Then numbers of votes would be 9, 1, 7, 2, 8 (Limak would have 9 votes). Alternatively, Limak could steal only 3 votes from the third candidate and 1 vote from the second candidate to get situation 9, 0, 8, 2, 8. In the second sample Limak will steal 2 votes from each candidate. Situation will be 7, 6, 6, 6. In the third sample Limak is a winner without bribing any citizen.
instruction
0
49,236
14
98,472
Tags: greedy, implementation Correct Solution: ``` n = int(input()) mylist = list(map(int,input().split())) count = 0 while(mylist[0] <= max(mylist[1:])): mylist[mylist[1:].index(max(mylist)) + 1 ] -= 1 mylist[0] += 1 count += 1 print(count) ```
output
1
49,236
14
98,473
Provide tags and a correct Python 3 solution for this coding contest problem. Limak is a grizzly bear who desires power and adoration. He wants to win in upcoming elections and rule over the Bearland. There are n candidates, including Limak. We know how many citizens are going to vote for each candidate. Now i-th candidate would get ai votes. Limak is candidate number 1. To win in elections, he must get strictly more votes than any other candidate. Victory is more important than everything else so Limak decided to cheat. He will steal votes from his opponents by bribing some citizens. To bribe a citizen, Limak must give him or her one candy - citizens are bears and bears like candies. Limak doesn't have many candies and wonders - how many citizens does he have to bribe? Input The first line contains single integer n (2 ≤ n ≤ 100) - number of candidates. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 1000) - number of votes for each candidate. Limak is candidate number 1. Note that after bribing number of votes for some candidate might be zero or might be greater than 1000. Output Print the minimum number of citizens Limak must bribe to have strictly more votes than any other candidate. Examples Input 5 5 1 11 2 8 Output 4 Input 4 1 8 8 8 Output 6 Input 2 7 6 Output 0 Note In the first sample Limak has 5 votes. One of the ways to achieve victory is to bribe 4 citizens who want to vote for the third candidate. Then numbers of votes would be 9, 1, 7, 2, 8 (Limak would have 9 votes). Alternatively, Limak could steal only 3 votes from the third candidate and 1 vote from the second candidate to get situation 9, 0, 8, 2, 8. In the second sample Limak will steal 2 votes from each candidate. Situation will be 7, 6, 6, 6. In the third sample Limak is a winner without bribing any citizen.
instruction
0
49,237
14
98,474
Tags: greedy, implementation Correct Solution: ``` u = [0]*10000 a = int(input()) b = input().split() start = int(b[0]) me = int(b[0]) mx = 0 for i in b[1:]: i = int(i) u[i]+=1 mx=max(mx,i) i = mx while me<i: z = u[i] while u[i] and me<=i: me+=1 u[i]-=1 u[i-1]+=z i-=1 if me == i: me+=1 print(me-start) ```
output
1
49,237
14
98,475
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Limak is a grizzly bear who desires power and adoration. He wants to win in upcoming elections and rule over the Bearland. There are n candidates, including Limak. We know how many citizens are going to vote for each candidate. Now i-th candidate would get ai votes. Limak is candidate number 1. To win in elections, he must get strictly more votes than any other candidate. Victory is more important than everything else so Limak decided to cheat. He will steal votes from his opponents by bribing some citizens. To bribe a citizen, Limak must give him or her one candy - citizens are bears and bears like candies. Limak doesn't have many candies and wonders - how many citizens does he have to bribe? Input The first line contains single integer n (2 ≤ n ≤ 100) - number of candidates. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 1000) - number of votes for each candidate. Limak is candidate number 1. Note that after bribing number of votes for some candidate might be zero or might be greater than 1000. Output Print the minimum number of citizens Limak must bribe to have strictly more votes than any other candidate. Examples Input 5 5 1 11 2 8 Output 4 Input 4 1 8 8 8 Output 6 Input 2 7 6 Output 0 Note In the first sample Limak has 5 votes. One of the ways to achieve victory is to bribe 4 citizens who want to vote for the third candidate. Then numbers of votes would be 9, 1, 7, 2, 8 (Limak would have 9 votes). Alternatively, Limak could steal only 3 votes from the third candidate and 1 vote from the second candidate to get situation 9, 0, 8, 2, 8. In the second sample Limak will steal 2 votes from each candidate. Situation will be 7, 6, 6, 6. In the third sample Limak is a winner without bribing any citizen. Submitted Solution: ``` n = int(input()) a = list(map(int, input().split())) q = a.pop(0) a.sort() sum = 0 while q <= a[-1]: a[-1] -= 1 a.sort() q += 1 sum += 1 print(sum) ```
instruction
0
49,238
14
98,476
Yes
output
1
49,238
14
98,477
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Limak is a grizzly bear who desires power and adoration. He wants to win in upcoming elections and rule over the Bearland. There are n candidates, including Limak. We know how many citizens are going to vote for each candidate. Now i-th candidate would get ai votes. Limak is candidate number 1. To win in elections, he must get strictly more votes than any other candidate. Victory is more important than everything else so Limak decided to cheat. He will steal votes from his opponents by bribing some citizens. To bribe a citizen, Limak must give him or her one candy - citizens are bears and bears like candies. Limak doesn't have many candies and wonders - how many citizens does he have to bribe? Input The first line contains single integer n (2 ≤ n ≤ 100) - number of candidates. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 1000) - number of votes for each candidate. Limak is candidate number 1. Note that after bribing number of votes for some candidate might be zero or might be greater than 1000. Output Print the minimum number of citizens Limak must bribe to have strictly more votes than any other candidate. Examples Input 5 5 1 11 2 8 Output 4 Input 4 1 8 8 8 Output 6 Input 2 7 6 Output 0 Note In the first sample Limak has 5 votes. One of the ways to achieve victory is to bribe 4 citizens who want to vote for the third candidate. Then numbers of votes would be 9, 1, 7, 2, 8 (Limak would have 9 votes). Alternatively, Limak could steal only 3 votes from the third candidate and 1 vote from the second candidate to get situation 9, 0, 8, 2, 8. In the second sample Limak will steal 2 votes from each candidate. Situation will be 7, 6, 6, 6. In the third sample Limak is a winner without bribing any citizen. Submitted Solution: ``` n = input() me, *cans = list(map(int, input().split(' '))) c = 0 while True: m = max(enumerate(cans), key=lambda x: x[1]) if m[1] < me: break cans[m[0]] -= 1 me += 1 c += 1 print(c) ```
instruction
0
49,239
14
98,478
Yes
output
1
49,239
14
98,479
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Limak is a grizzly bear who desires power and adoration. He wants to win in upcoming elections and rule over the Bearland. There are n candidates, including Limak. We know how many citizens are going to vote for each candidate. Now i-th candidate would get ai votes. Limak is candidate number 1. To win in elections, he must get strictly more votes than any other candidate. Victory is more important than everything else so Limak decided to cheat. He will steal votes from his opponents by bribing some citizens. To bribe a citizen, Limak must give him or her one candy - citizens are bears and bears like candies. Limak doesn't have many candies and wonders - how many citizens does he have to bribe? Input The first line contains single integer n (2 ≤ n ≤ 100) - number of candidates. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 1000) - number of votes for each candidate. Limak is candidate number 1. Note that after bribing number of votes for some candidate might be zero or might be greater than 1000. Output Print the minimum number of citizens Limak must bribe to have strictly more votes than any other candidate. Examples Input 5 5 1 11 2 8 Output 4 Input 4 1 8 8 8 Output 6 Input 2 7 6 Output 0 Note In the first sample Limak has 5 votes. One of the ways to achieve victory is to bribe 4 citizens who want to vote for the third candidate. Then numbers of votes would be 9, 1, 7, 2, 8 (Limak would have 9 votes). Alternatively, Limak could steal only 3 votes from the third candidate and 1 vote from the second candidate to get situation 9, 0, 8, 2, 8. In the second sample Limak will steal 2 votes from each candidate. Situation will be 7, 6, 6, 6. In the third sample Limak is a winner without bribing any citizen. Submitted Solution: ``` n = int(input()) cands= input() cands = cands.split(" ") cands = list(map(int, cands)) ##print(cands) counter = 0 while cands[0] <= max(cands[1:]): idxMax = cands.index(max(cands[1:])) if cands[0] == max(cands[1:]): cands[0] += 1 cands[idxMax] -= 1 counter += 1 break else: cands[idxMax] -= 1 cands[0] += 1 counter += 1 print(counter) ```
instruction
0
49,240
14
98,480
Yes
output
1
49,240
14
98,481
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Limak is a grizzly bear who desires power and adoration. He wants to win in upcoming elections and rule over the Bearland. There are n candidates, including Limak. We know how many citizens are going to vote for each candidate. Now i-th candidate would get ai votes. Limak is candidate number 1. To win in elections, he must get strictly more votes than any other candidate. Victory is more important than everything else so Limak decided to cheat. He will steal votes from his opponents by bribing some citizens. To bribe a citizen, Limak must give him or her one candy - citizens are bears and bears like candies. Limak doesn't have many candies and wonders - how many citizens does he have to bribe? Input The first line contains single integer n (2 ≤ n ≤ 100) - number of candidates. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 1000) - number of votes for each candidate. Limak is candidate number 1. Note that after bribing number of votes for some candidate might be zero or might be greater than 1000. Output Print the minimum number of citizens Limak must bribe to have strictly more votes than any other candidate. Examples Input 5 5 1 11 2 8 Output 4 Input 4 1 8 8 8 Output 6 Input 2 7 6 Output 0 Note In the first sample Limak has 5 votes. One of the ways to achieve victory is to bribe 4 citizens who want to vote for the third candidate. Then numbers of votes would be 9, 1, 7, 2, 8 (Limak would have 9 votes). Alternatively, Limak could steal only 3 votes from the third candidate and 1 vote from the second candidate to get situation 9, 0, 8, 2, 8. In the second sample Limak will steal 2 votes from each candidate. Situation will be 7, 6, 6, 6. In the third sample Limak is a winner without bribing any citizen. Submitted Solution: ``` n = int(input()) a = list(map(int, input().split())) ans = 0 limak = a[0] a = a[1:] a.sort() mx_add = sum(a) for i in range(mx_add + 1): cur_add = 0 for j in range(len(a)): if a[j] >= limak + i: cur_add += a[j] - (limak + i - 1) if cur_add <= i: print(i) exit(0) ```
instruction
0
49,241
14
98,482
Yes
output
1
49,241
14
98,483
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Limak is a grizzly bear who desires power and adoration. He wants to win in upcoming elections and rule over the Bearland. There are n candidates, including Limak. We know how many citizens are going to vote for each candidate. Now i-th candidate would get ai votes. Limak is candidate number 1. To win in elections, he must get strictly more votes than any other candidate. Victory is more important than everything else so Limak decided to cheat. He will steal votes from his opponents by bribing some citizens. To bribe a citizen, Limak must give him or her one candy - citizens are bears and bears like candies. Limak doesn't have many candies and wonders - how many citizens does he have to bribe? Input The first line contains single integer n (2 ≤ n ≤ 100) - number of candidates. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 1000) - number of votes for each candidate. Limak is candidate number 1. Note that after bribing number of votes for some candidate might be zero or might be greater than 1000. Output Print the minimum number of citizens Limak must bribe to have strictly more votes than any other candidate. Examples Input 5 5 1 11 2 8 Output 4 Input 4 1 8 8 8 Output 6 Input 2 7 6 Output 0 Note In the first sample Limak has 5 votes. One of the ways to achieve victory is to bribe 4 citizens who want to vote for the third candidate. Then numbers of votes would be 9, 1, 7, 2, 8 (Limak would have 9 votes). Alternatively, Limak could steal only 3 votes from the third candidate and 1 vote from the second candidate to get situation 9, 0, 8, 2, 8. In the second sample Limak will steal 2 votes from each candidate. Situation will be 7, 6, 6, 6. In the third sample Limak is a winner without bribing any citizen. Submitted Solution: ``` n = int(input()) j = 0 s = input() a = s.split() for i in range(n): a[i] = int(a[i]) def findmax(): #import pdb; pdb.set_trace() global max1, max2, imax1, imax2, a max2 = 0 imax2 = 0 max1 = max(a) imax1 = a.index(max(a)) for i in range(n): if (max1>=a[i]>=max2)&(i != imax1): max2 = a[i] imax2 = i return 1 c = 1 findmax() if (max1 == a[0])&(max1 not in a[1:n]): pass else: while c==1: #import pdb; pdb.set_trace() findmax() while (max1 >= max2)&(max1 >= a[0]): max1-=1 a[imax1]-=1 a[0]+=1 j+=1 print(a) else: if (a[0]>max1)&(a[0]>max2): c=0 print(j) ```
instruction
0
49,242
14
98,484
No
output
1
49,242
14
98,485
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Limak is a grizzly bear who desires power and adoration. He wants to win in upcoming elections and rule over the Bearland. There are n candidates, including Limak. We know how many citizens are going to vote for each candidate. Now i-th candidate would get ai votes. Limak is candidate number 1. To win in elections, he must get strictly more votes than any other candidate. Victory is more important than everything else so Limak decided to cheat. He will steal votes from his opponents by bribing some citizens. To bribe a citizen, Limak must give him or her one candy - citizens are bears and bears like candies. Limak doesn't have many candies and wonders - how many citizens does he have to bribe? Input The first line contains single integer n (2 ≤ n ≤ 100) - number of candidates. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 1000) - number of votes for each candidate. Limak is candidate number 1. Note that after bribing number of votes for some candidate might be zero or might be greater than 1000. Output Print the minimum number of citizens Limak must bribe to have strictly more votes than any other candidate. Examples Input 5 5 1 11 2 8 Output 4 Input 4 1 8 8 8 Output 6 Input 2 7 6 Output 0 Note In the first sample Limak has 5 votes. One of the ways to achieve victory is to bribe 4 citizens who want to vote for the third candidate. Then numbers of votes would be 9, 1, 7, 2, 8 (Limak would have 9 votes). Alternatively, Limak could steal only 3 votes from the third candidate and 1 vote from the second candidate to get situation 9, 0, 8, 2, 8. In the second sample Limak will steal 2 votes from each candidate. Situation will be 7, 6, 6, 6. In the third sample Limak is a winner without bribing any citizen. Submitted Solution: ``` from math import ceil n = int(input()) a = list(map(int, input().split())) s = 0 k = 0 for i in range(0, n): if a[i] >= a[0]: k += 1 s += a[i] if k != 1: print((s + 1) // (k) - a[0] + 1) else: print(0) ```
instruction
0
49,243
14
98,486
No
output
1
49,243
14
98,487
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Limak is a grizzly bear who desires power and adoration. He wants to win in upcoming elections and rule over the Bearland. There are n candidates, including Limak. We know how many citizens are going to vote for each candidate. Now i-th candidate would get ai votes. Limak is candidate number 1. To win in elections, he must get strictly more votes than any other candidate. Victory is more important than everything else so Limak decided to cheat. He will steal votes from his opponents by bribing some citizens. To bribe a citizen, Limak must give him or her one candy - citizens are bears and bears like candies. Limak doesn't have many candies and wonders - how many citizens does he have to bribe? Input The first line contains single integer n (2 ≤ n ≤ 100) - number of candidates. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 1000) - number of votes for each candidate. Limak is candidate number 1. Note that after bribing number of votes for some candidate might be zero or might be greater than 1000. Output Print the minimum number of citizens Limak must bribe to have strictly more votes than any other candidate. Examples Input 5 5 1 11 2 8 Output 4 Input 4 1 8 8 8 Output 6 Input 2 7 6 Output 0 Note In the first sample Limak has 5 votes. One of the ways to achieve victory is to bribe 4 citizens who want to vote for the third candidate. Then numbers of votes would be 9, 1, 7, 2, 8 (Limak would have 9 votes). Alternatively, Limak could steal only 3 votes from the third candidate and 1 vote from the second candidate to get situation 9, 0, 8, 2, 8. In the second sample Limak will steal 2 votes from each candidate. Situation will be 7, 6, 6, 6. In the third sample Limak is a winner without bribing any citizen. Submitted Solution: ``` def main(n, a): def s(n, a, i): a[0] += i amt = 0 for j in range(1, n): while a[j] >= a[0] and amt < i: a[j] -= 1 amt += 1 return a[1:] a[1:] = reversed(sorted(a[1:])) for i in range(100): x = list(filter(lambda x: x >= a[0] + i, s(n, list(a), i))) if len(x) == 0: return i return -1 print(main(int(input()), list(map(int, input().split(' '))))) ```
instruction
0
49,244
14
98,488
No
output
1
49,244
14
98,489
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Limak is a grizzly bear who desires power and adoration. He wants to win in upcoming elections and rule over the Bearland. There are n candidates, including Limak. We know how many citizens are going to vote for each candidate. Now i-th candidate would get ai votes. Limak is candidate number 1. To win in elections, he must get strictly more votes than any other candidate. Victory is more important than everything else so Limak decided to cheat. He will steal votes from his opponents by bribing some citizens. To bribe a citizen, Limak must give him or her one candy - citizens are bears and bears like candies. Limak doesn't have many candies and wonders - how many citizens does he have to bribe? Input The first line contains single integer n (2 ≤ n ≤ 100) - number of candidates. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 1000) - number of votes for each candidate. Limak is candidate number 1. Note that after bribing number of votes for some candidate might be zero or might be greater than 1000. Output Print the minimum number of citizens Limak must bribe to have strictly more votes than any other candidate. Examples Input 5 5 1 11 2 8 Output 4 Input 4 1 8 8 8 Output 6 Input 2 7 6 Output 0 Note In the first sample Limak has 5 votes. One of the ways to achieve victory is to bribe 4 citizens who want to vote for the third candidate. Then numbers of votes would be 9, 1, 7, 2, 8 (Limak would have 9 votes). Alternatively, Limak could steal only 3 votes from the third candidate and 1 vote from the second candidate to get situation 9, 0, 8, 2, 8. In the second sample Limak will steal 2 votes from each candidate. Situation will be 7, 6, 6, 6. In the third sample Limak is a winner without bribing any citizen. Submitted Solution: ``` n=int(input()) a= list(map(int, input().split())) t1,i=a[0],0 b=sorted(a,reverse=True) while t1<=b[0]: if t1==b[0] and t1>b[1]:break t1+=1 b[0]-=1 b=sorted(b,reverse=True) i+=1 print(b,t1) print(i) ```
instruction
0
49,245
14
98,490
No
output
1
49,245
14
98,491
Provide tags and a correct Python 3 solution for this coding contest problem. Nastya received a gift on New Year — a magic wardrobe. It is magic because in the end of each month the number of dresses in it doubles (i.e. the number of dresses becomes twice as large as it is in the beginning of the month). Unfortunately, right after the doubling the wardrobe eats one of the dresses (if any) with the 50% probability. It happens every month except the last one in the year. Nastya owns x dresses now, so she became interested in the [expected number](https://en.wikipedia.org/wiki/Expected_value) of dresses she will have in one year. Nastya lives in Byteland, so the year lasts for k + 1 months. Nastya is really busy, so she wants you to solve this problem. You are the programmer, after all. Also, you should find the answer modulo 109 + 7, because it is easy to see that it is always integer. Input The only line contains two integers x and k (0 ≤ x, k ≤ 1018), where x is the initial number of dresses and k + 1 is the number of months in a year in Byteland. Output In the only line print a single integer — the expected number of dresses Nastya will own one year later modulo 109 + 7. Examples Input 2 0 Output 4 Input 2 1 Output 7 Input 3 2 Output 21 Note In the first example a year consists on only one month, so the wardrobe does not eat dresses at all. In the second example after the first month there are 3 dresses with 50% probability and 4 dresses with 50% probability. Thus, in the end of the year there are 6 dresses with 50% probability and 8 dresses with 50% probability. This way the answer for this test is (6 + 8) / 2 = 7.
instruction
0
49,381
14
98,762
Tags: math Correct Solution: ``` x, k = map(int, input().strip().split()) MOD = 10**9 + 7 def pow2(k): if k == 0: return 1 if k == 1: return 2 r = pow2(k // 2) r = r * r if k % 2 != 0: r *= 2 return r % MOD def calc(x, k): if x == 0: return 0 if k == 0: return (2 * x) % MOD r = pow2(k) * (2 * x - 1) + 1 return r % MOD print(calc(x, k)) ```
output
1
49,381
14
98,763
Provide tags and a correct Python 3 solution for this coding contest problem. Nastya received a gift on New Year — a magic wardrobe. It is magic because in the end of each month the number of dresses in it doubles (i.e. the number of dresses becomes twice as large as it is in the beginning of the month). Unfortunately, right after the doubling the wardrobe eats one of the dresses (if any) with the 50% probability. It happens every month except the last one in the year. Nastya owns x dresses now, so she became interested in the [expected number](https://en.wikipedia.org/wiki/Expected_value) of dresses she will have in one year. Nastya lives in Byteland, so the year lasts for k + 1 months. Nastya is really busy, so she wants you to solve this problem. You are the programmer, after all. Also, you should find the answer modulo 109 + 7, because it is easy to see that it is always integer. Input The only line contains two integers x and k (0 ≤ x, k ≤ 1018), where x is the initial number of dresses and k + 1 is the number of months in a year in Byteland. Output In the only line print a single integer — the expected number of dresses Nastya will own one year later modulo 109 + 7. Examples Input 2 0 Output 4 Input 2 1 Output 7 Input 3 2 Output 21 Note In the first example a year consists on only one month, so the wardrobe does not eat dresses at all. In the second example after the first month there are 3 dresses with 50% probability and 4 dresses with 50% probability. Thus, in the end of the year there are 6 dresses with 50% probability and 8 dresses with 50% probability. This way the answer for this test is (6 + 8) / 2 = 7.
instruction
0
49,382
14
98,764
Tags: math Correct Solution: ``` #import math M = 10**9 + 7 R = lambda: map(int, input().split()) x,k = R() if x == 0: print(0) quit() print(((pow(2,k+1,M)*x)%M - pow(2,k,M) +1 ) % M) ```
output
1
49,382
14
98,765
Provide tags and a correct Python 3 solution for this coding contest problem. Nastya received a gift on New Year — a magic wardrobe. It is magic because in the end of each month the number of dresses in it doubles (i.e. the number of dresses becomes twice as large as it is in the beginning of the month). Unfortunately, right after the doubling the wardrobe eats one of the dresses (if any) with the 50% probability. It happens every month except the last one in the year. Nastya owns x dresses now, so she became interested in the [expected number](https://en.wikipedia.org/wiki/Expected_value) of dresses she will have in one year. Nastya lives in Byteland, so the year lasts for k + 1 months. Nastya is really busy, so she wants you to solve this problem. You are the programmer, after all. Also, you should find the answer modulo 109 + 7, because it is easy to see that it is always integer. Input The only line contains two integers x and k (0 ≤ x, k ≤ 1018), where x is the initial number of dresses and k + 1 is the number of months in a year in Byteland. Output In the only line print a single integer — the expected number of dresses Nastya will own one year later modulo 109 + 7. Examples Input 2 0 Output 4 Input 2 1 Output 7 Input 3 2 Output 21 Note In the first example a year consists on only one month, so the wardrobe does not eat dresses at all. In the second example after the first month there are 3 dresses with 50% probability and 4 dresses with 50% probability. Thus, in the end of the year there are 6 dresses with 50% probability and 8 dresses with 50% probability. This way the answer for this test is (6 + 8) / 2 = 7.
instruction
0
49,383
14
98,766
Tags: math Correct Solution: ``` x, k = list(map(int,input().split())) m = 1000000000 +7 if x!=0: p1 = x*2 - 1 p2 = x*2 p = (p1 + p2)//2 print((p*pow(2,k,m) + 1 + m)%m) else: print(x*2) ```
output
1
49,383
14
98,767
Provide tags and a correct Python 3 solution for this coding contest problem. Nastya received a gift on New Year — a magic wardrobe. It is magic because in the end of each month the number of dresses in it doubles (i.e. the number of dresses becomes twice as large as it is in the beginning of the month). Unfortunately, right after the doubling the wardrobe eats one of the dresses (if any) with the 50% probability. It happens every month except the last one in the year. Nastya owns x dresses now, so she became interested in the [expected number](https://en.wikipedia.org/wiki/Expected_value) of dresses she will have in one year. Nastya lives in Byteland, so the year lasts for k + 1 months. Nastya is really busy, so she wants you to solve this problem. You are the programmer, after all. Also, you should find the answer modulo 109 + 7, because it is easy to see that it is always integer. Input The only line contains two integers x and k (0 ≤ x, k ≤ 1018), where x is the initial number of dresses and k + 1 is the number of months in a year in Byteland. Output In the only line print a single integer — the expected number of dresses Nastya will own one year later modulo 109 + 7. Examples Input 2 0 Output 4 Input 2 1 Output 7 Input 3 2 Output 21 Note In the first example a year consists on only one month, so the wardrobe does not eat dresses at all. In the second example after the first month there are 3 dresses with 50% probability and 4 dresses with 50% probability. Thus, in the end of the year there are 6 dresses with 50% probability and 8 dresses with 50% probability. This way the answer for this test is (6 + 8) / 2 = 7.
instruction
0
49,384
14
98,768
Tags: math Correct Solution: ``` x, k = map(int, input().split()) if x == 0: print(0) exit(0) res = pow(2, k + 1, 10 ** 9 + 7) * x - pow(2, k, 10 ** 9 + 7) + 1 res %= 10 ** 9 + 7 print(res) ```
output
1
49,384
14
98,769
Provide tags and a correct Python 3 solution for this coding contest problem. Nastya received a gift on New Year — a magic wardrobe. It is magic because in the end of each month the number of dresses in it doubles (i.e. the number of dresses becomes twice as large as it is in the beginning of the month). Unfortunately, right after the doubling the wardrobe eats one of the dresses (if any) with the 50% probability. It happens every month except the last one in the year. Nastya owns x dresses now, so she became interested in the [expected number](https://en.wikipedia.org/wiki/Expected_value) of dresses she will have in one year. Nastya lives in Byteland, so the year lasts for k + 1 months. Nastya is really busy, so she wants you to solve this problem. You are the programmer, after all. Also, you should find the answer modulo 109 + 7, because it is easy to see that it is always integer. Input The only line contains two integers x and k (0 ≤ x, k ≤ 1018), where x is the initial number of dresses and k + 1 is the number of months in a year in Byteland. Output In the only line print a single integer — the expected number of dresses Nastya will own one year later modulo 109 + 7. Examples Input 2 0 Output 4 Input 2 1 Output 7 Input 3 2 Output 21 Note In the first example a year consists on only one month, so the wardrobe does not eat dresses at all. In the second example after the first month there are 3 dresses with 50% probability and 4 dresses with 50% probability. Thus, in the end of the year there are 6 dresses with 50% probability and 8 dresses with 50% probability. This way the answer for this test is (6 + 8) / 2 = 7.
instruction
0
49,385
14
98,770
Tags: math Correct Solution: ``` a,b = input().split() x = int(a) k = int(b) mod = 10**9 + 7 if(x == 0 ): print(0) elif( k == 0): print( (2*x)%mod ) else: print( (((pow(2,k,mod)*x - pow(2,k-1,mod))%mod)*2 + 3*mod + 1)%mod) ```
output
1
49,385
14
98,771
Provide tags and a correct Python 3 solution for this coding contest problem. Nastya received a gift on New Year — a magic wardrobe. It is magic because in the end of each month the number of dresses in it doubles (i.e. the number of dresses becomes twice as large as it is in the beginning of the month). Unfortunately, right after the doubling the wardrobe eats one of the dresses (if any) with the 50% probability. It happens every month except the last one in the year. Nastya owns x dresses now, so she became interested in the [expected number](https://en.wikipedia.org/wiki/Expected_value) of dresses she will have in one year. Nastya lives in Byteland, so the year lasts for k + 1 months. Nastya is really busy, so she wants you to solve this problem. You are the programmer, after all. Also, you should find the answer modulo 109 + 7, because it is easy to see that it is always integer. Input The only line contains two integers x and k (0 ≤ x, k ≤ 1018), where x is the initial number of dresses and k + 1 is the number of months in a year in Byteland. Output In the only line print a single integer — the expected number of dresses Nastya will own one year later modulo 109 + 7. Examples Input 2 0 Output 4 Input 2 1 Output 7 Input 3 2 Output 21 Note In the first example a year consists on only one month, so the wardrobe does not eat dresses at all. In the second example after the first month there are 3 dresses with 50% probability and 4 dresses with 50% probability. Thus, in the end of the year there are 6 dresses with 50% probability and 8 dresses with 50% probability. This way the answer for this test is (6 + 8) / 2 = 7.
instruction
0
49,386
14
98,772
Tags: math Correct Solution: ``` # your code goes here MOD = 1000000007 def modpow(x, p): result = 1 while p > 0: if p % 2 == 1: result = (result * x) % MOD p = p // 2 x = (x * x) % MOD return result n, k = map(int, input().split()) k+=1 if n == 0: print(0) else: ans = (((modpow(2, k))*(n%MOD))%MOD-(modpow(2, k-1)-1)%MOD)%MOD print(ans) ```
output
1
49,386
14
98,773
Provide tags and a correct Python 3 solution for this coding contest problem. Nastya received a gift on New Year — a magic wardrobe. It is magic because in the end of each month the number of dresses in it doubles (i.e. the number of dresses becomes twice as large as it is in the beginning of the month). Unfortunately, right after the doubling the wardrobe eats one of the dresses (if any) with the 50% probability. It happens every month except the last one in the year. Nastya owns x dresses now, so she became interested in the [expected number](https://en.wikipedia.org/wiki/Expected_value) of dresses she will have in one year. Nastya lives in Byteland, so the year lasts for k + 1 months. Nastya is really busy, so she wants you to solve this problem. You are the programmer, after all. Also, you should find the answer modulo 109 + 7, because it is easy to see that it is always integer. Input The only line contains two integers x and k (0 ≤ x, k ≤ 1018), where x is the initial number of dresses and k + 1 is the number of months in a year in Byteland. Output In the only line print a single integer — the expected number of dresses Nastya will own one year later modulo 109 + 7. Examples Input 2 0 Output 4 Input 2 1 Output 7 Input 3 2 Output 21 Note In the first example a year consists on only one month, so the wardrobe does not eat dresses at all. In the second example after the first month there are 3 dresses with 50% probability and 4 dresses with 50% probability. Thus, in the end of the year there are 6 dresses with 50% probability and 8 dresses with 50% probability. This way the answer for this test is (6 + 8) / 2 = 7.
instruction
0
49,387
14
98,774
Tags: math Correct Solution: ``` mod=1000000007 def fast(a,b): if (b==0): return 1 if((b%2)==1): return ((a%mod)*(fast(a,b-1)%mod))%mod x=fast(a,b//2)%mod return (x*x)%mod x,k=map(int,input().split()) if(x==0): print(0) else: z= (((x%mod)*(fast(2,k+1)%mod))%mod-fast(2,k)%mod+mod+1)%mod print (z) ```
output
1
49,387
14
98,775
Provide tags and a correct Python 3 solution for this coding contest problem. Nastya received a gift on New Year — a magic wardrobe. It is magic because in the end of each month the number of dresses in it doubles (i.e. the number of dresses becomes twice as large as it is in the beginning of the month). Unfortunately, right after the doubling the wardrobe eats one of the dresses (if any) with the 50% probability. It happens every month except the last one in the year. Nastya owns x dresses now, so she became interested in the [expected number](https://en.wikipedia.org/wiki/Expected_value) of dresses she will have in one year. Nastya lives in Byteland, so the year lasts for k + 1 months. Nastya is really busy, so she wants you to solve this problem. You are the programmer, after all. Also, you should find the answer modulo 109 + 7, because it is easy to see that it is always integer. Input The only line contains two integers x and k (0 ≤ x, k ≤ 1018), where x is the initial number of dresses and k + 1 is the number of months in a year in Byteland. Output In the only line print a single integer — the expected number of dresses Nastya will own one year later modulo 109 + 7. Examples Input 2 0 Output 4 Input 2 1 Output 7 Input 3 2 Output 21 Note In the first example a year consists on only one month, so the wardrobe does not eat dresses at all. In the second example after the first month there are 3 dresses with 50% probability and 4 dresses with 50% probability. Thus, in the end of the year there are 6 dresses with 50% probability and 8 dresses with 50% probability. This way the answer for this test is (6 + 8) / 2 = 7.
instruction
0
49,388
14
98,776
Tags: math Correct Solution: ``` x, k = map(int, input().split(" ")) M = 10 ** 9 + 7 def get(x, k): if k == 0: return x else: a = pow(2, k - 1, M) b = (2 * x - 1) * pow(2, k, M) + 1 c = pow(pow(2, k, M), M - 2, M) ans = a * b * c % M return ans if k == 0 or x == 0: print(x * 2 % M) else: ans = get(x, k) * 2 % M print(ans) ```
output
1
49,388
14
98,777
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Nastya received a gift on New Year — a magic wardrobe. It is magic because in the end of each month the number of dresses in it doubles (i.e. the number of dresses becomes twice as large as it is in the beginning of the month). Unfortunately, right after the doubling the wardrobe eats one of the dresses (if any) with the 50% probability. It happens every month except the last one in the year. Nastya owns x dresses now, so she became interested in the [expected number](https://en.wikipedia.org/wiki/Expected_value) of dresses she will have in one year. Nastya lives in Byteland, so the year lasts for k + 1 months. Nastya is really busy, so she wants you to solve this problem. You are the programmer, after all. Also, you should find the answer modulo 109 + 7, because it is easy to see that it is always integer. Input The only line contains two integers x and k (0 ≤ x, k ≤ 1018), where x is the initial number of dresses and k + 1 is the number of months in a year in Byteland. Output In the only line print a single integer — the expected number of dresses Nastya will own one year later modulo 109 + 7. Examples Input 2 0 Output 4 Input 2 1 Output 7 Input 3 2 Output 21 Note In the first example a year consists on only one month, so the wardrobe does not eat dresses at all. In the second example after the first month there are 3 dresses with 50% probability and 4 dresses with 50% probability. Thus, in the end of the year there are 6 dresses with 50% probability and 8 dresses with 50% probability. This way the answer for this test is (6 + 8) / 2 = 7. Submitted Solution: ``` x, k = map(int, input().split()) mod = 1000 * 1000 * 1000 + 7 if x == 0: print(0) else: mul = pow(2, k + 1, mod) cnt = pow(2, k, mod) s1 = mul * cnt * x s2 = cnt * (cnt - 1) ans = (s1 - s2) % mod rev = pow(cnt, mod - 2, mod) assert rev * cnt % mod == 1 ans *= rev print(ans % mod) ```
instruction
0
49,389
14
98,778
Yes
output
1
49,389
14
98,779
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Nastya received a gift on New Year — a magic wardrobe. It is magic because in the end of each month the number of dresses in it doubles (i.e. the number of dresses becomes twice as large as it is in the beginning of the month). Unfortunately, right after the doubling the wardrobe eats one of the dresses (if any) with the 50% probability. It happens every month except the last one in the year. Nastya owns x dresses now, so she became interested in the [expected number](https://en.wikipedia.org/wiki/Expected_value) of dresses she will have in one year. Nastya lives in Byteland, so the year lasts for k + 1 months. Nastya is really busy, so she wants you to solve this problem. You are the programmer, after all. Also, you should find the answer modulo 109 + 7, because it is easy to see that it is always integer. Input The only line contains two integers x and k (0 ≤ x, k ≤ 1018), where x is the initial number of dresses and k + 1 is the number of months in a year in Byteland. Output In the only line print a single integer — the expected number of dresses Nastya will own one year later modulo 109 + 7. Examples Input 2 0 Output 4 Input 2 1 Output 7 Input 3 2 Output 21 Note In the first example a year consists on only one month, so the wardrobe does not eat dresses at all. In the second example after the first month there are 3 dresses with 50% probability and 4 dresses with 50% probability. Thus, in the end of the year there are 6 dresses with 50% probability and 8 dresses with 50% probability. This way the answer for this test is (6 + 8) / 2 = 7. Submitted Solution: ``` x, k = list(map(int, input().split())) mod = 1000000007 print((pow(2, k+1, mod) * x - pow(2, k, mod) + 1) % mod if x > 0 else 0) ```
instruction
0
49,390
14
98,780
Yes
output
1
49,390
14
98,781
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Nastya received a gift on New Year — a magic wardrobe. It is magic because in the end of each month the number of dresses in it doubles (i.e. the number of dresses becomes twice as large as it is in the beginning of the month). Unfortunately, right after the doubling the wardrobe eats one of the dresses (if any) with the 50% probability. It happens every month except the last one in the year. Nastya owns x dresses now, so she became interested in the [expected number](https://en.wikipedia.org/wiki/Expected_value) of dresses she will have in one year. Nastya lives in Byteland, so the year lasts for k + 1 months. Nastya is really busy, so she wants you to solve this problem. You are the programmer, after all. Also, you should find the answer modulo 109 + 7, because it is easy to see that it is always integer. Input The only line contains two integers x and k (0 ≤ x, k ≤ 1018), where x is the initial number of dresses and k + 1 is the number of months in a year in Byteland. Output In the only line print a single integer — the expected number of dresses Nastya will own one year later modulo 109 + 7. Examples Input 2 0 Output 4 Input 2 1 Output 7 Input 3 2 Output 21 Note In the first example a year consists on only one month, so the wardrobe does not eat dresses at all. In the second example after the first month there are 3 dresses with 50% probability and 4 dresses with 50% probability. Thus, in the end of the year there are 6 dresses with 50% probability and 8 dresses with 50% probability. This way the answer for this test is (6 + 8) / 2 = 7. Submitted Solution: ``` M = 10 ** 9 + 7 x, k = map(int, input().split()) if x == 0: print(0); exit(0) P = pow(2, k, M) r = (P * x) % M - (0.5 * (-1 + P)) % M print(int((2 * r + M) % M)) ```
instruction
0
49,391
14
98,782
Yes
output
1
49,391
14
98,783
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Nastya received a gift on New Year — a magic wardrobe. It is magic because in the end of each month the number of dresses in it doubles (i.e. the number of dresses becomes twice as large as it is in the beginning of the month). Unfortunately, right after the doubling the wardrobe eats one of the dresses (if any) with the 50% probability. It happens every month except the last one in the year. Nastya owns x dresses now, so she became interested in the [expected number](https://en.wikipedia.org/wiki/Expected_value) of dresses she will have in one year. Nastya lives in Byteland, so the year lasts for k + 1 months. Nastya is really busy, so she wants you to solve this problem. You are the programmer, after all. Also, you should find the answer modulo 109 + 7, because it is easy to see that it is always integer. Input The only line contains two integers x and k (0 ≤ x, k ≤ 1018), where x is the initial number of dresses and k + 1 is the number of months in a year in Byteland. Output In the only line print a single integer — the expected number of dresses Nastya will own one year later modulo 109 + 7. Examples Input 2 0 Output 4 Input 2 1 Output 7 Input 3 2 Output 21 Note In the first example a year consists on only one month, so the wardrobe does not eat dresses at all. In the second example after the first month there are 3 dresses with 50% probability and 4 dresses with 50% probability. Thus, in the end of the year there are 6 dresses with 50% probability and 8 dresses with 50% probability. This way the answer for this test is (6 + 8) / 2 = 7. Submitted Solution: ``` x, k = map(int, input().split()) mod = 10**9+7 if x==0: print(0) else: p = pow(2, k, mod) res = (((2*x)%mod + mod - 1)%mod) res = ((res*p)%mod + 1)%mod print(res) ```
instruction
0
49,392
14
98,784
Yes
output
1
49,392
14
98,785
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Nastya received a gift on New Year — a magic wardrobe. It is magic because in the end of each month the number of dresses in it doubles (i.e. the number of dresses becomes twice as large as it is in the beginning of the month). Unfortunately, right after the doubling the wardrobe eats one of the dresses (if any) with the 50% probability. It happens every month except the last one in the year. Nastya owns x dresses now, so she became interested in the [expected number](https://en.wikipedia.org/wiki/Expected_value) of dresses she will have in one year. Nastya lives in Byteland, so the year lasts for k + 1 months. Nastya is really busy, so she wants you to solve this problem. You are the programmer, after all. Also, you should find the answer modulo 109 + 7, because it is easy to see that it is always integer. Input The only line contains two integers x and k (0 ≤ x, k ≤ 1018), where x is the initial number of dresses and k + 1 is the number of months in a year in Byteland. Output In the only line print a single integer — the expected number of dresses Nastya will own one year later modulo 109 + 7. Examples Input 2 0 Output 4 Input 2 1 Output 7 Input 3 2 Output 21 Note In the first example a year consists on only one month, so the wardrobe does not eat dresses at all. In the second example after the first month there are 3 dresses with 50% probability and 4 dresses with 50% probability. Thus, in the end of the year there are 6 dresses with 50% probability and 8 dresses with 50% probability. This way the answer for this test is (6 + 8) / 2 = 7. Submitted Solution: ``` def modInverse(a, m) : g = gcd(a, m) return power(a, m - 2, m) def power(x, y, m) : if (y == 0) : return 1 p = power(x, y // 2, m) % m p = (p * p) % m if(y % 2 == 0) : return p else : return ((x * p) % m) def gcd(a, b) : if (a == 0) : return b return gcd(b % a, a) x,k = map(int,input().split()) MOD = 10**9 + 7 if k==0: print(2*x) exit() lst = x hst = x hst = ((2**k) * (hst))%MOD lst = (hst - (2**k-1))%MOD hsum = (hst * (hst+1)) //2 lst -=1 lsum = (lst*(lst+1))//2 ans = (hsum%MOD-lsum%MOD + MOD)%MOD ans = (2*ans)%MOD #MIV = modInverse(2**k,MOD) #ans = ((ans%MOD)*(MIV%MOD))%MOD ans = ans//(2**k) ans = ans%MOD print(ans) ```
instruction
0
49,393
14
98,786
No
output
1
49,393
14
98,787
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Nastya received a gift on New Year — a magic wardrobe. It is magic because in the end of each month the number of dresses in it doubles (i.e. the number of dresses becomes twice as large as it is in the beginning of the month). Unfortunately, right after the doubling the wardrobe eats one of the dresses (if any) with the 50% probability. It happens every month except the last one in the year. Nastya owns x dresses now, so she became interested in the [expected number](https://en.wikipedia.org/wiki/Expected_value) of dresses she will have in one year. Nastya lives in Byteland, so the year lasts for k + 1 months. Nastya is really busy, so she wants you to solve this problem. You are the programmer, after all. Also, you should find the answer modulo 109 + 7, because it is easy to see that it is always integer. Input The only line contains two integers x and k (0 ≤ x, k ≤ 1018), where x is the initial number of dresses and k + 1 is the number of months in a year in Byteland. Output In the only line print a single integer — the expected number of dresses Nastya will own one year later modulo 109 + 7. Examples Input 2 0 Output 4 Input 2 1 Output 7 Input 3 2 Output 21 Note In the first example a year consists on only one month, so the wardrobe does not eat dresses at all. In the second example after the first month there are 3 dresses with 50% probability and 4 dresses with 50% probability. Thus, in the end of the year there are 6 dresses with 50% probability and 8 dresses with 50% probability. This way the answer for this test is (6 + 8) / 2 = 7. Submitted Solution: ``` def go(): x, k = [int(i) for i in input().split(' ')] if x == 0: return 0 if k == 0: return (x * 2) % (10 ** 9 + 7) x1 = x * (2 ** (k + 1)) x2 = x for i in range(0, k): x2 = x2 * 2 - 1 x2 *= 2 import code code.interact(local=locals()) return ((x1 + x2) // 2) % (10 ** 9 + 7) print(go()) ```
instruction
0
49,394
14
98,788
No
output
1
49,394
14
98,789
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Nastya received a gift on New Year — a magic wardrobe. It is magic because in the end of each month the number of dresses in it doubles (i.e. the number of dresses becomes twice as large as it is in the beginning of the month). Unfortunately, right after the doubling the wardrobe eats one of the dresses (if any) with the 50% probability. It happens every month except the last one in the year. Nastya owns x dresses now, so she became interested in the [expected number](https://en.wikipedia.org/wiki/Expected_value) of dresses she will have in one year. Nastya lives in Byteland, so the year lasts for k + 1 months. Nastya is really busy, so she wants you to solve this problem. You are the programmer, after all. Also, you should find the answer modulo 109 + 7, because it is easy to see that it is always integer. Input The only line contains two integers x and k (0 ≤ x, k ≤ 1018), where x is the initial number of dresses and k + 1 is the number of months in a year in Byteland. Output In the only line print a single integer — the expected number of dresses Nastya will own one year later modulo 109 + 7. Examples Input 2 0 Output 4 Input 2 1 Output 7 Input 3 2 Output 21 Note In the first example a year consists on only one month, so the wardrobe does not eat dresses at all. In the second example after the first month there are 3 dresses with 50% probability and 4 dresses with 50% probability. Thus, in the end of the year there are 6 dresses with 50% probability and 8 dresses with 50% probability. This way the answer for this test is (6 + 8) / 2 = 7. Submitted Solution: ``` x, k = list(map(int,input().split())) def power(x, y, p) : res = 1 x = x % p while (y > 0) : if ((y & 1) == 1) : res = (res * x) % p y = y >> 1 x = (x * x) % p return res p = 1e9 + 7 val = power(2,k,p) ans = (2 * val * (x%p) - val + 1)%p print(ans) ```
instruction
0
49,395
14
98,790
No
output
1
49,395
14
98,791
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Nastya received a gift on New Year — a magic wardrobe. It is magic because in the end of each month the number of dresses in it doubles (i.e. the number of dresses becomes twice as large as it is in the beginning of the month). Unfortunately, right after the doubling the wardrobe eats one of the dresses (if any) with the 50% probability. It happens every month except the last one in the year. Nastya owns x dresses now, so she became interested in the [expected number](https://en.wikipedia.org/wiki/Expected_value) of dresses she will have in one year. Nastya lives in Byteland, so the year lasts for k + 1 months. Nastya is really busy, so she wants you to solve this problem. You are the programmer, after all. Also, you should find the answer modulo 109 + 7, because it is easy to see that it is always integer. Input The only line contains two integers x and k (0 ≤ x, k ≤ 1018), where x is the initial number of dresses and k + 1 is the number of months in a year in Byteland. Output In the only line print a single integer — the expected number of dresses Nastya will own one year later modulo 109 + 7. Examples Input 2 0 Output 4 Input 2 1 Output 7 Input 3 2 Output 21 Note In the first example a year consists on only one month, so the wardrobe does not eat dresses at all. In the second example after the first month there are 3 dresses with 50% probability and 4 dresses with 50% probability. Thus, in the end of the year there are 6 dresses with 50% probability and 8 dresses with 50% probability. This way the answer for this test is (6 + 8) / 2 = 7. Submitted Solution: ``` a = str(input()) b = a.split(' ') z0 = int(b[0])%(10**9+7) z1 = int(b[0])%(10**9+7) k = int(b[1])%(10**9+7) z0 = z0*2**(k+1) if z0 != 0: for i in range (0,k+1): if i != k: z1 = z1*2-1 else: z1 *= 2 print(((z0+z1)//2)%(10**9+7)) ```
instruction
0
49,396
14
98,792
No
output
1
49,396
14
98,793
Provide tags and a correct Python 3 solution for this coding contest problem. One day Ms Swan bought an orange in a shop. The orange consisted of n·k segments, numbered with integers from 1 to n·k. There were k children waiting for Ms Swan at home. The children have recently learned about the orange and they decided to divide it between them. For that each child took a piece of paper and wrote the number of the segment that he would like to get: the i-th (1 ≤ i ≤ k) child wrote the number ai (1 ≤ ai ≤ n·k). All numbers ai accidentally turned out to be different. Now the children wonder, how to divide the orange so as to meet these conditions: * each child gets exactly n orange segments; * the i-th child gets the segment with number ai for sure; * no segment goes to two children simultaneously. Help the children, divide the orange and fulfill the requirements, described above. Input The first line contains two integers n, k (1 ≤ n, k ≤ 30). The second line contains k space-separated integers a1, a2, ..., ak (1 ≤ ai ≤ n·k), where ai is the number of the orange segment that the i-th child would like to get. It is guaranteed that all numbers ai are distinct. Output Print exactly n·k distinct integers. The first n integers represent the indexes of the segments the first child will get, the second n integers represent the indexes of the segments the second child will get, and so on. Separate the printed numbers with whitespaces. You can print a child's segment indexes in any order. It is guaranteed that the answer always exists. If there are multiple correct answers, print any of them. Examples Input 2 2 4 1 Output 2 4 1 3 Input 3 1 2 Output 3 2 1
instruction
0
49,944
14
99,888
Tags: implementation Correct Solution: ``` n,k=map(int,input().split()) s=set() for i in range((n*k)+1): s.add(i) s.pop() li=list(map(int,input().split())) for i in range(k): s.remove(li[i]) for i in range(k): print(li[i],end=' ') for j in range(n-1): print(s.pop(),end=' ') print() ```
output
1
49,944
14
99,889
Provide tags and a correct Python 3 solution for this coding contest problem. One day Ms Swan bought an orange in a shop. The orange consisted of n·k segments, numbered with integers from 1 to n·k. There were k children waiting for Ms Swan at home. The children have recently learned about the orange and they decided to divide it between them. For that each child took a piece of paper and wrote the number of the segment that he would like to get: the i-th (1 ≤ i ≤ k) child wrote the number ai (1 ≤ ai ≤ n·k). All numbers ai accidentally turned out to be different. Now the children wonder, how to divide the orange so as to meet these conditions: * each child gets exactly n orange segments; * the i-th child gets the segment with number ai for sure; * no segment goes to two children simultaneously. Help the children, divide the orange and fulfill the requirements, described above. Input The first line contains two integers n, k (1 ≤ n, k ≤ 30). The second line contains k space-separated integers a1, a2, ..., ak (1 ≤ ai ≤ n·k), where ai is the number of the orange segment that the i-th child would like to get. It is guaranteed that all numbers ai are distinct. Output Print exactly n·k distinct integers. The first n integers represent the indexes of the segments the first child will get, the second n integers represent the indexes of the segments the second child will get, and so on. Separate the printed numbers with whitespaces. You can print a child's segment indexes in any order. It is guaranteed that the answer always exists. If there are multiple correct answers, print any of them. Examples Input 2 2 4 1 Output 2 4 1 3 Input 3 1 2 Output 3 2 1
instruction
0
49,945
14
99,890
Tags: implementation Correct Solution: ``` n,k=map(int,input().split()) arr=list(map(int,input().split())) var=1 for i in range(k): cnt=1 print(arr[i],end=' ') while cnt!=n: if var not in arr: print(var,end=' ') cnt=cnt+1 var=var+1 print('\n',end='') ```
output
1
49,945
14
99,891
Provide tags and a correct Python 3 solution for this coding contest problem. One day Ms Swan bought an orange in a shop. The orange consisted of n·k segments, numbered with integers from 1 to n·k. There were k children waiting for Ms Swan at home. The children have recently learned about the orange and they decided to divide it between them. For that each child took a piece of paper and wrote the number of the segment that he would like to get: the i-th (1 ≤ i ≤ k) child wrote the number ai (1 ≤ ai ≤ n·k). All numbers ai accidentally turned out to be different. Now the children wonder, how to divide the orange so as to meet these conditions: * each child gets exactly n orange segments; * the i-th child gets the segment with number ai for sure; * no segment goes to two children simultaneously. Help the children, divide the orange and fulfill the requirements, described above. Input The first line contains two integers n, k (1 ≤ n, k ≤ 30). The second line contains k space-separated integers a1, a2, ..., ak (1 ≤ ai ≤ n·k), where ai is the number of the orange segment that the i-th child would like to get. It is guaranteed that all numbers ai are distinct. Output Print exactly n·k distinct integers. The first n integers represent the indexes of the segments the first child will get, the second n integers represent the indexes of the segments the second child will get, and so on. Separate the printed numbers with whitespaces. You can print a child's segment indexes in any order. It is guaranteed that the answer always exists. If there are multiple correct answers, print any of them. Examples Input 2 2 4 1 Output 2 4 1 3 Input 3 1 2 Output 3 2 1
instruction
0
49,946
14
99,892
Tags: implementation Correct Solution: ``` n,k=map(int,input().split()) l=list(map(int,input().split())) s=1 for i in range(k) : p=n-1 print(l[i],end=' ') while(p>0): if s not in l: print(s,end=' ') p=p-1 s=s+1 print() ```
output
1
49,946
14
99,893
Provide tags and a correct Python 3 solution for this coding contest problem. One day Ms Swan bought an orange in a shop. The orange consisted of n·k segments, numbered with integers from 1 to n·k. There were k children waiting for Ms Swan at home. The children have recently learned about the orange and they decided to divide it between them. For that each child took a piece of paper and wrote the number of the segment that he would like to get: the i-th (1 ≤ i ≤ k) child wrote the number ai (1 ≤ ai ≤ n·k). All numbers ai accidentally turned out to be different. Now the children wonder, how to divide the orange so as to meet these conditions: * each child gets exactly n orange segments; * the i-th child gets the segment with number ai for sure; * no segment goes to two children simultaneously. Help the children, divide the orange and fulfill the requirements, described above. Input The first line contains two integers n, k (1 ≤ n, k ≤ 30). The second line contains k space-separated integers a1, a2, ..., ak (1 ≤ ai ≤ n·k), where ai is the number of the orange segment that the i-th child would like to get. It is guaranteed that all numbers ai are distinct. Output Print exactly n·k distinct integers. The first n integers represent the indexes of the segments the first child will get, the second n integers represent the indexes of the segments the second child will get, and so on. Separate the printed numbers with whitespaces. You can print a child's segment indexes in any order. It is guaranteed that the answer always exists. If there are multiple correct answers, print any of them. Examples Input 2 2 4 1 Output 2 4 1 3 Input 3 1 2 Output 3 2 1
instruction
0
49,947
14
99,894
Tags: implementation Correct Solution: ``` n, k = map(int, input().split()) arr = list(map(int, input().split())) lst = [i for i in range(1, n*k+1) if i not in arr] for num in arr: ans = [num] cases = n -1 while cases: ans.append(lst.pop()) cases -= 1 print(*ans) ```
output
1
49,947
14
99,895
Provide tags and a correct Python 3 solution for this coding contest problem. One day Ms Swan bought an orange in a shop. The orange consisted of n·k segments, numbered with integers from 1 to n·k. There were k children waiting for Ms Swan at home. The children have recently learned about the orange and they decided to divide it between them. For that each child took a piece of paper and wrote the number of the segment that he would like to get: the i-th (1 ≤ i ≤ k) child wrote the number ai (1 ≤ ai ≤ n·k). All numbers ai accidentally turned out to be different. Now the children wonder, how to divide the orange so as to meet these conditions: * each child gets exactly n orange segments; * the i-th child gets the segment with number ai for sure; * no segment goes to two children simultaneously. Help the children, divide the orange and fulfill the requirements, described above. Input The first line contains two integers n, k (1 ≤ n, k ≤ 30). The second line contains k space-separated integers a1, a2, ..., ak (1 ≤ ai ≤ n·k), where ai is the number of the orange segment that the i-th child would like to get. It is guaranteed that all numbers ai are distinct. Output Print exactly n·k distinct integers. The first n integers represent the indexes of the segments the first child will get, the second n integers represent the indexes of the segments the second child will get, and so on. Separate the printed numbers with whitespaces. You can print a child's segment indexes in any order. It is guaranteed that the answer always exists. If there are multiple correct answers, print any of them. Examples Input 2 2 4 1 Output 2 4 1 3 Input 3 1 2 Output 3 2 1
instruction
0
49,948
14
99,896
Tags: implementation Correct Solution: ``` n,k=[int(i) for i in input().split()] segment=list(range(1,n*k+1)) for i in range(n*k): segment[i]=str(segment[i]) num=[int(i) for i in input().split()] for i in num: segment.remove(str(i)) t=0 for i in num: print(i,' '.join(segment[t:t+n-1])) t+=n-1 ```
output
1
49,948
14
99,897