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. Fox Ciel is participating in a party in Prime Kingdom. There are n foxes there (include Fox Ciel). The i-th fox is ai years old. They will have dinner around some round tables. You want to distribute foxes such that: 1. Each fox is sitting at some table. 2. Each table has at least 3 foxes sitting around it. 3. The sum of ages of any two adjacent foxes around each table should be a prime number. If k foxes f1, f2, ..., fk are sitting around table in clockwise order, then for 1 ≤ i ≤ k - 1: fi and fi + 1 are adjacent, and f1 and fk are also adjacent. If it is possible to distribute the foxes in the desired manner, find out a way to do that. Input The first line contains single integer n (3 ≤ n ≤ 200): the number of foxes in this party. The second line contains n integers ai (2 ≤ ai ≤ 104). Output If it is impossible to do this, output "Impossible". Otherwise, in the first line output an integer m (<image>): the number of tables. Then output m lines, each line should start with an integer k -=– the number of foxes around that table, and then k numbers — indices of fox sitting around that table in clockwise order. If there are several possible arrangements, output any of them. Examples Input 4 3 4 8 9 Output 1 4 1 2 4 3 Input 5 2 2 2 2 2 Output Impossible Input 12 2 3 4 5 6 7 8 9 10 11 12 13 Output 1 12 1 2 3 6 5 12 9 8 7 10 11 4 Input 24 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 Output 3 6 1 2 3 6 5 4 10 7 8 9 12 15 14 13 16 11 10 8 17 18 23 22 19 20 21 24 Note In example 1, they can sit around one table, their ages are: 3-8-9-4, adjacent sums are: 11, 17, 13 and 7, all those integers are primes. In example 2, it is not possible: the sum of 2+2 = 4 is not a prime number. Submitted Solution: ``` from collections import deque class Dinic(): def __init__(self, listEdge, s, t): self.s = s self.t = t self.graph = {} self.maxCap = 1000000 # dict các node lân cận # e[0]: from, e[1]: to, e[2]: dung luong for e in listEdge: if e[0] not in self.graph: self.graph[e[0]] = [] if e[1] not in self.graph: self.graph[e[1]] = [] #to #cap #reveser edge self.graph[e[0]].append([e[1], e[2], len(self.graph[e[1]])]) self.graph[e[1]].append([e[0], 0, len(self.graph[e[0]])-1]) self.N = len(self.graph.keys()) def bfs(self): self.dist = {} self.dist[self.s] = 0 self.curIter = {node:[] for node in self.graph} Q = deque([self.s]) while(len(Q) > 0): cur = Q.popleft() for index,e in enumerate(self.graph[cur]): # Chỉ add vào các node kế tiếp nếu dung lượng cạnh > 0 và chưa được visit trước đấy if e[1] > 0 and e[0] not in self.dist: self.dist[e[0]] = self.dist[cur] + 1 # add vào danh sách node kế tiếp của node hiện tại self.curIter[cur].append(index) Q.append(e[0]) def findPath(self, cur, f): if cur == self.t: return f while len(self.curIter[cur]) > 0: indexEdge = self.curIter[cur][-1] nextNode = self.graph[cur][indexEdge][0] remainCap = self.graph[cur][indexEdge][1] indexPreEdge = self.graph[cur][indexEdge][2] if remainCap > 0 and self.dist[nextNode] > self.dist[cur]: #self.next[cur] = indexEdge flow = self.findPath(nextNode, min(f, remainCap)) if flow > 0: self.path.append(cur) self.graph[cur][indexEdge][1] -= flow self.graph[nextNode][indexPreEdge][1] += flow #if cur == self.s: # print(self.path, flow) return flow #else: #self.path.pop() self.curIter[cur].pop() return 0 def maxFlow(self): maxflow = 0 flow = [] while(True): self.bfs() if self.t not in self.dist: break while(True): self.path = [] f = self.findPath(self.s, self.maxCap) #print('iter', self.curIter) if f == 0: break flow.append(f) maxflow += f return maxflow # Tìm tập node thuộc S và T # sau khi đã tìm được max flow def residualBfs(self): Q = deque([self.s]) side = {self.s:'s'} while(len(Q) > 0): cur = Q.popleft() for index,e in enumerate(self.graph[cur]): if e[1] > 0 and e[0] not in side: Q.append(e[0]) side[e[0]] = 's' S = [] T = [] for x in self.graph: if x in side: S.append(x) else: T.append(x) return set(S), set(T) def push(G, u, v): if u not in G: G[u]=[] if v not in G: G[v]=[] G[u].append(v) G[v].append(u) def bfs(u, used, G): used[u]=1 S=[u] i=0 while i < len(S): cur=S[i] if cur in G: for v in G[cur]: if used[v]==0: used[v]=1 S.append(v) i+=1 return S max_ = 20001 prime = [1] * max_ for i in range(2, max_): if prime[i] == 1: for j in range(2*i, max_, i): prime[j] = 0 n = int(input()) a = list(map(int, input().split())) diff = 0 for x in a: if x%2==0: diff+=1 else: diff-=1 flg=True if diff != 0: flg=False else: edge = [] for i in range(n): if a[i]%2==1: edge.append([i,'t', 2]) continue edge.append(['s', i, 2]) for j in range(n): if a[j]%2==1 and prime[a[i]+a[j]] == 1: edge.append([i, j, 1]) g = Dinic(edge, 's', 't') F = g.maxFlow() if F != n: flg=False else: G = {} for u, es in g.graph.items(): if u in ['s', 't'] or a[u] % 2 == 1: continue for e in es: v, remain = e[0], e[1] if isinstance(v, int) == True and remain == 0: push(G, u, v) used = [0]*n comp = [] for i in range(0, n, 2): if a[i]%2==0 and used[i]==0: comp.append(bfs(i, used, G)) if flg==False: print('Impossible') else: print(len(comp)) for nodes in comp: for i in range(len(nodes)): nodes[i] += 1 arr = [len(nodes)] + nodes print(' '.join([str(x) for x in arr])) ```
instruction
0
83,792
14
167,584
No
output
1
83,792
14
167,585
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Fox Ciel is participating in a party in Prime Kingdom. There are n foxes there (include Fox Ciel). The i-th fox is ai years old. They will have dinner around some round tables. You want to distribute foxes such that: 1. Each fox is sitting at some table. 2. Each table has at least 3 foxes sitting around it. 3. The sum of ages of any two adjacent foxes around each table should be a prime number. If k foxes f1, f2, ..., fk are sitting around table in clockwise order, then for 1 ≤ i ≤ k - 1: fi and fi + 1 are adjacent, and f1 and fk are also adjacent. If it is possible to distribute the foxes in the desired manner, find out a way to do that. Input The first line contains single integer n (3 ≤ n ≤ 200): the number of foxes in this party. The second line contains n integers ai (2 ≤ ai ≤ 104). Output If it is impossible to do this, output "Impossible". Otherwise, in the first line output an integer m (<image>): the number of tables. Then output m lines, each line should start with an integer k -=– the number of foxes around that table, and then k numbers — indices of fox sitting around that table in clockwise order. If there are several possible arrangements, output any of them. Examples Input 4 3 4 8 9 Output 1 4 1 2 4 3 Input 5 2 2 2 2 2 Output Impossible Input 12 2 3 4 5 6 7 8 9 10 11 12 13 Output 1 12 1 2 3 6 5 12 9 8 7 10 11 4 Input 24 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 Output 3 6 1 2 3 6 5 4 10 7 8 9 12 15 14 13 16 11 10 8 17 18 23 22 19 20 21 24 Note In example 1, they can sit around one table, their ages are: 3-8-9-4, adjacent sums are: 11, 17, 13 and 7, all those integers are primes. In example 2, it is not possible: the sum of 2+2 = 4 is not a prime number. Submitted Solution: ``` print("I cannot do it QAQ") ```
instruction
0
83,793
14
167,586
No
output
1
83,793
14
167,587
Provide tags and a correct Python 3 solution for this coding contest problem. In the school computer room there are n servers which are responsible for processing several computing tasks. You know the number of scheduled tasks for each server: there are mi tasks assigned to the i-th server. In order to balance the load for each server, you want to reassign some tasks to make the difference between the most loaded server and the least loaded server as small as possible. In other words you want to minimize expression ma - mb, where a is the most loaded server and b is the least loaded one. In one second you can reassign a single task. Thus in one second you can choose any pair of servers and move a single task from one server to another. Write a program to find the minimum number of seconds needed to balance the load of servers. Input The first line contains positive number n (1 ≤ n ≤ 105) — the number of the servers. The second line contains the sequence of non-negative integers m1, m2, ..., mn (0 ≤ mi ≤ 2·104), where mi is the number of tasks assigned to the i-th server. Output Print the minimum number of seconds required to balance the load. Examples Input 2 1 6 Output 2 Input 7 10 11 10 11 10 11 11 Output 0 Input 5 1 2 3 4 5 Output 3 Note In the first example two seconds are needed. In each second, a single task from server #2 should be moved to server #1. After two seconds there should be 3 tasks on server #1 and 4 tasks on server #2. In the second example the load is already balanced. A possible sequence of task movements for the third example is: 1. move a task from server #4 to server #1 (the sequence m becomes: 2 2 3 3 5); 2. then move task from server #5 to server #1 (the sequence m becomes: 3 2 3 3 4); 3. then move task from server #5 to server #2 (the sequence m becomes: 3 3 3 3 3). The above sequence is one of several possible ways to balance the load of servers in three seconds.
instruction
0
83,811
14
167,622
Tags: implementation, math Correct Solution: ``` n = int(input()) m = list(map(int,input().split())) a, b = sum(m) // n, (sum(m) + n - 1) // n print(max(sum(a - x for x in m if x < a), sum(x - b for x in m if x > b))) ```
output
1
83,811
14
167,623
Provide tags and a correct Python 3 solution for this coding contest problem. In the school computer room there are n servers which are responsible for processing several computing tasks. You know the number of scheduled tasks for each server: there are mi tasks assigned to the i-th server. In order to balance the load for each server, you want to reassign some tasks to make the difference between the most loaded server and the least loaded server as small as possible. In other words you want to minimize expression ma - mb, where a is the most loaded server and b is the least loaded one. In one second you can reassign a single task. Thus in one second you can choose any pair of servers and move a single task from one server to another. Write a program to find the minimum number of seconds needed to balance the load of servers. Input The first line contains positive number n (1 ≤ n ≤ 105) — the number of the servers. The second line contains the sequence of non-negative integers m1, m2, ..., mn (0 ≤ mi ≤ 2·104), where mi is the number of tasks assigned to the i-th server. Output Print the minimum number of seconds required to balance the load. Examples Input 2 1 6 Output 2 Input 7 10 11 10 11 10 11 11 Output 0 Input 5 1 2 3 4 5 Output 3 Note In the first example two seconds are needed. In each second, a single task from server #2 should be moved to server #1. After two seconds there should be 3 tasks on server #1 and 4 tasks on server #2. In the second example the load is already balanced. A possible sequence of task movements for the third example is: 1. move a task from server #4 to server #1 (the sequence m becomes: 2 2 3 3 5); 2. then move task from server #5 to server #1 (the sequence m becomes: 3 2 3 3 4); 3. then move task from server #5 to server #2 (the sequence m becomes: 3 3 3 3 3). The above sequence is one of several possible ways to balance the load of servers in three seconds.
instruction
0
83,812
14
167,624
Tags: implementation, math Correct Solution: ``` n = int(input()) a = list(map(int, input().split())) cur = 0 for i in a: cur += i; b = [] for i in range(cur % n): b.append((cur + n - 1) // n) for i in range(n - cur % n): b.append(cur // n) b.sort() a.sort() ans = 0 for i in range(n): ans += abs(a[i] - b[i]) print(ans // 2) ```
output
1
83,812
14
167,625
Provide tags and a correct Python 3 solution for this coding contest problem. In the school computer room there are n servers which are responsible for processing several computing tasks. You know the number of scheduled tasks for each server: there are mi tasks assigned to the i-th server. In order to balance the load for each server, you want to reassign some tasks to make the difference between the most loaded server and the least loaded server as small as possible. In other words you want to minimize expression ma - mb, where a is the most loaded server and b is the least loaded one. In one second you can reassign a single task. Thus in one second you can choose any pair of servers and move a single task from one server to another. Write a program to find the minimum number of seconds needed to balance the load of servers. Input The first line contains positive number n (1 ≤ n ≤ 105) — the number of the servers. The second line contains the sequence of non-negative integers m1, m2, ..., mn (0 ≤ mi ≤ 2·104), where mi is the number of tasks assigned to the i-th server. Output Print the minimum number of seconds required to balance the load. Examples Input 2 1 6 Output 2 Input 7 10 11 10 11 10 11 11 Output 0 Input 5 1 2 3 4 5 Output 3 Note In the first example two seconds are needed. In each second, a single task from server #2 should be moved to server #1. After two seconds there should be 3 tasks on server #1 and 4 tasks on server #2. In the second example the load is already balanced. A possible sequence of task movements for the third example is: 1. move a task from server #4 to server #1 (the sequence m becomes: 2 2 3 3 5); 2. then move task from server #5 to server #1 (the sequence m becomes: 3 2 3 3 4); 3. then move task from server #5 to server #2 (the sequence m becomes: 3 3 3 3 3). The above sequence is one of several possible ways to balance the load of servers in three seconds.
instruction
0
83,813
14
167,626
Tags: implementation, math Correct Solution: ``` diff=0 x = int(input()) l = list(map(int, input().split(' '))) s = sum(l) k = s//x knum = (k+1)*x-s kpnum = x - knum a = knum * [k] + [k+1] * kpnum a.sort() l.sort() for i in range(len(a)): diff += abs(a[i]-l[i]) print(int(diff/2)) ```
output
1
83,813
14
167,627
Provide tags and a correct Python 3 solution for this coding contest problem. In the school computer room there are n servers which are responsible for processing several computing tasks. You know the number of scheduled tasks for each server: there are mi tasks assigned to the i-th server. In order to balance the load for each server, you want to reassign some tasks to make the difference between the most loaded server and the least loaded server as small as possible. In other words you want to minimize expression ma - mb, where a is the most loaded server and b is the least loaded one. In one second you can reassign a single task. Thus in one second you can choose any pair of servers and move a single task from one server to another. Write a program to find the minimum number of seconds needed to balance the load of servers. Input The first line contains positive number n (1 ≤ n ≤ 105) — the number of the servers. The second line contains the sequence of non-negative integers m1, m2, ..., mn (0 ≤ mi ≤ 2·104), where mi is the number of tasks assigned to the i-th server. Output Print the minimum number of seconds required to balance the load. Examples Input 2 1 6 Output 2 Input 7 10 11 10 11 10 11 11 Output 0 Input 5 1 2 3 4 5 Output 3 Note In the first example two seconds are needed. In each second, a single task from server #2 should be moved to server #1. After two seconds there should be 3 tasks on server #1 and 4 tasks on server #2. In the second example the load is already balanced. A possible sequence of task movements for the third example is: 1. move a task from server #4 to server #1 (the sequence m becomes: 2 2 3 3 5); 2. then move task from server #5 to server #1 (the sequence m becomes: 3 2 3 3 4); 3. then move task from server #5 to server #2 (the sequence m becomes: 3 3 3 3 3). The above sequence is one of several possible ways to balance the load of servers in three seconds.
instruction
0
83,814
14
167,628
Tags: implementation, math Correct Solution: ``` import sys input = sys.stdin.readline n = int(input()) m = list(map(int, input().split())) m.sort() s = sum(m) l = [] for i in range(n): if i<s%n: l.append(s//n+1) else: l.append(s//n) l = l[::-1] ans = 0 for mi, li in zip(m, l): ans += abs(mi-li) print(ans//2) ```
output
1
83,814
14
167,629
Provide tags and a correct Python 3 solution for this coding contest problem. In the school computer room there are n servers which are responsible for processing several computing tasks. You know the number of scheduled tasks for each server: there are mi tasks assigned to the i-th server. In order to balance the load for each server, you want to reassign some tasks to make the difference between the most loaded server and the least loaded server as small as possible. In other words you want to minimize expression ma - mb, where a is the most loaded server and b is the least loaded one. In one second you can reassign a single task. Thus in one second you can choose any pair of servers and move a single task from one server to another. Write a program to find the minimum number of seconds needed to balance the load of servers. Input The first line contains positive number n (1 ≤ n ≤ 105) — the number of the servers. The second line contains the sequence of non-negative integers m1, m2, ..., mn (0 ≤ mi ≤ 2·104), where mi is the number of tasks assigned to the i-th server. Output Print the minimum number of seconds required to balance the load. Examples Input 2 1 6 Output 2 Input 7 10 11 10 11 10 11 11 Output 0 Input 5 1 2 3 4 5 Output 3 Note In the first example two seconds are needed. In each second, a single task from server #2 should be moved to server #1. After two seconds there should be 3 tasks on server #1 and 4 tasks on server #2. In the second example the load is already balanced. A possible sequence of task movements for the third example is: 1. move a task from server #4 to server #1 (the sequence m becomes: 2 2 3 3 5); 2. then move task from server #5 to server #1 (the sequence m becomes: 3 2 3 3 4); 3. then move task from server #5 to server #2 (the sequence m becomes: 3 3 3 3 3). The above sequence is one of several possible ways to balance the load of servers in three seconds.
instruction
0
83,815
14
167,630
Tags: implementation, math Correct Solution: ``` n, m = int(input()), list(map(int, input().split())) a, b = sum(m) // n, (sum(m) + n - 1) // n print(max(sum(a - x for x in m if x < a), sum(x - b for x in m if x > b))) # Made By Mostafa_Khaled ```
output
1
83,815
14
167,631
Provide tags and a correct Python 3 solution for this coding contest problem. In the school computer room there are n servers which are responsible for processing several computing tasks. You know the number of scheduled tasks for each server: there are mi tasks assigned to the i-th server. In order to balance the load for each server, you want to reassign some tasks to make the difference between the most loaded server and the least loaded server as small as possible. In other words you want to minimize expression ma - mb, where a is the most loaded server and b is the least loaded one. In one second you can reassign a single task. Thus in one second you can choose any pair of servers and move a single task from one server to another. Write a program to find the minimum number of seconds needed to balance the load of servers. Input The first line contains positive number n (1 ≤ n ≤ 105) — the number of the servers. The second line contains the sequence of non-negative integers m1, m2, ..., mn (0 ≤ mi ≤ 2·104), where mi is the number of tasks assigned to the i-th server. Output Print the minimum number of seconds required to balance the load. Examples Input 2 1 6 Output 2 Input 7 10 11 10 11 10 11 11 Output 0 Input 5 1 2 3 4 5 Output 3 Note In the first example two seconds are needed. In each second, a single task from server #2 should be moved to server #1. After two seconds there should be 3 tasks on server #1 and 4 tasks on server #2. In the second example the load is already balanced. A possible sequence of task movements for the third example is: 1. move a task from server #4 to server #1 (the sequence m becomes: 2 2 3 3 5); 2. then move task from server #5 to server #1 (the sequence m becomes: 3 2 3 3 4); 3. then move task from server #5 to server #2 (the sequence m becomes: 3 3 3 3 3). The above sequence is one of several possible ways to balance the load of servers in three seconds.
instruction
0
83,816
14
167,632
Tags: implementation, math Correct Solution: ``` import math n = int(input()) l = list(map(int,input().split())) if n == 1: print(0) exit() l.sort() som = sum(l) if som%n == 0: ans = 0 i = 0 j = n-1 target = som//n rem = 0 while i < j: x = l[j] diff = x-target l[j] -= diff diff2 = target-l[i] ans += diff ans += diff2 i = i+1 j = j-1 print(ans//2) else: ans = 0 target = math.ceil(som/n) cnt1 = som%n cnt2 = n-cnt1 c = 0 i = 0 while i < n: x = l[i] if c < cnt2: diff = abs(x - (target-1)) ans += diff c += 1 else: diff = abs(x-target) ans += diff i += 1 print(ans//2) ```
output
1
83,816
14
167,633
Provide tags and a correct Python 3 solution for this coding contest problem. In the school computer room there are n servers which are responsible for processing several computing tasks. You know the number of scheduled tasks for each server: there are mi tasks assigned to the i-th server. In order to balance the load for each server, you want to reassign some tasks to make the difference between the most loaded server and the least loaded server as small as possible. In other words you want to minimize expression ma - mb, where a is the most loaded server and b is the least loaded one. In one second you can reassign a single task. Thus in one second you can choose any pair of servers and move a single task from one server to another. Write a program to find the minimum number of seconds needed to balance the load of servers. Input The first line contains positive number n (1 ≤ n ≤ 105) — the number of the servers. The second line contains the sequence of non-negative integers m1, m2, ..., mn (0 ≤ mi ≤ 2·104), where mi is the number of tasks assigned to the i-th server. Output Print the minimum number of seconds required to balance the load. Examples Input 2 1 6 Output 2 Input 7 10 11 10 11 10 11 11 Output 0 Input 5 1 2 3 4 5 Output 3 Note In the first example two seconds are needed. In each second, a single task from server #2 should be moved to server #1. After two seconds there should be 3 tasks on server #1 and 4 tasks on server #2. In the second example the load is already balanced. A possible sequence of task movements for the third example is: 1. move a task from server #4 to server #1 (the sequence m becomes: 2 2 3 3 5); 2. then move task from server #5 to server #1 (the sequence m becomes: 3 2 3 3 4); 3. then move task from server #5 to server #2 (the sequence m becomes: 3 3 3 3 3). The above sequence is one of several possible ways to balance the load of servers in three seconds.
instruction
0
83,817
14
167,634
Tags: implementation, math Correct Solution: ``` n = int(input()) mas = list(map(int, input().split())) mas.sort() d = sum(mas) // n #print (sum(mas)) #print (n) a = n - sum(mas) % n b = n - a #print (a) #print (b) #print (d) ans = 0 for i in range(a): #print (mas[i]) ans += abs(mas[i] - d) for i in range(a, a + b): ans += abs(mas[i] - d - 1) print (ans // 2) ```
output
1
83,817
14
167,635
Provide tags and a correct Python 3 solution for this coding contest problem. In the school computer room there are n servers which are responsible for processing several computing tasks. You know the number of scheduled tasks for each server: there are mi tasks assigned to the i-th server. In order to balance the load for each server, you want to reassign some tasks to make the difference between the most loaded server and the least loaded server as small as possible. In other words you want to minimize expression ma - mb, where a is the most loaded server and b is the least loaded one. In one second you can reassign a single task. Thus in one second you can choose any pair of servers and move a single task from one server to another. Write a program to find the minimum number of seconds needed to balance the load of servers. Input The first line contains positive number n (1 ≤ n ≤ 105) — the number of the servers. The second line contains the sequence of non-negative integers m1, m2, ..., mn (0 ≤ mi ≤ 2·104), where mi is the number of tasks assigned to the i-th server. Output Print the minimum number of seconds required to balance the load. Examples Input 2 1 6 Output 2 Input 7 10 11 10 11 10 11 11 Output 0 Input 5 1 2 3 4 5 Output 3 Note In the first example two seconds are needed. In each second, a single task from server #2 should be moved to server #1. After two seconds there should be 3 tasks on server #1 and 4 tasks on server #2. In the second example the load is already balanced. A possible sequence of task movements for the third example is: 1. move a task from server #4 to server #1 (the sequence m becomes: 2 2 3 3 5); 2. then move task from server #5 to server #1 (the sequence m becomes: 3 2 3 3 4); 3. then move task from server #5 to server #2 (the sequence m becomes: 3 3 3 3 3). The above sequence is one of several possible ways to balance the load of servers in three seconds.
instruction
0
83,818
14
167,636
Tags: implementation, math Correct Solution: ``` n = int(input()) servers = list(map(int, input().split())) Sum = sum(servers) average = Sum//n flag = Sum%n == 0 ans = 0 cnt = 0 for i in range(n): if servers[i] <= average: ans += average - servers[i] cnt += 1 left = n - cnt if not flag: ans += max(Sum%n - left, 0) print(ans) ```
output
1
83,818
14
167,637
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In the school computer room there are n servers which are responsible for processing several computing tasks. You know the number of scheduled tasks for each server: there are mi tasks assigned to the i-th server. In order to balance the load for each server, you want to reassign some tasks to make the difference between the most loaded server and the least loaded server as small as possible. In other words you want to minimize expression ma - mb, where a is the most loaded server and b is the least loaded one. In one second you can reassign a single task. Thus in one second you can choose any pair of servers and move a single task from one server to another. Write a program to find the minimum number of seconds needed to balance the load of servers. Input The first line contains positive number n (1 ≤ n ≤ 105) — the number of the servers. The second line contains the sequence of non-negative integers m1, m2, ..., mn (0 ≤ mi ≤ 2·104), where mi is the number of tasks assigned to the i-th server. Output Print the minimum number of seconds required to balance the load. Examples Input 2 1 6 Output 2 Input 7 10 11 10 11 10 11 11 Output 0 Input 5 1 2 3 4 5 Output 3 Note In the first example two seconds are needed. In each second, a single task from server #2 should be moved to server #1. After two seconds there should be 3 tasks on server #1 and 4 tasks on server #2. In the second example the load is already balanced. A possible sequence of task movements for the third example is: 1. move a task from server #4 to server #1 (the sequence m becomes: 2 2 3 3 5); 2. then move task from server #5 to server #1 (the sequence m becomes: 3 2 3 3 4); 3. then move task from server #5 to server #2 (the sequence m becomes: 3 3 3 3 3). The above sequence is one of several possible ways to balance the load of servers in three seconds. Submitted Solution: ``` n = int(input()) m = sorted([int(x) for x in input().split()]) avg = sum(m)//(len(m)) rem = sum(m) - avg*n lst= [avg]*(n-rem) + [avg+1] * rem print(sum([abs(lst[i]-m[i]) for i in range(n)])//2) ```
instruction
0
83,821
14
167,642
Yes
output
1
83,821
14
167,643
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In the school computer room there are n servers which are responsible for processing several computing tasks. You know the number of scheduled tasks for each server: there are mi tasks assigned to the i-th server. In order to balance the load for each server, you want to reassign some tasks to make the difference between the most loaded server and the least loaded server as small as possible. In other words you want to minimize expression ma - mb, where a is the most loaded server and b is the least loaded one. In one second you can reassign a single task. Thus in one second you can choose any pair of servers and move a single task from one server to another. Write a program to find the minimum number of seconds needed to balance the load of servers. Input The first line contains positive number n (1 ≤ n ≤ 105) — the number of the servers. The second line contains the sequence of non-negative integers m1, m2, ..., mn (0 ≤ mi ≤ 2·104), where mi is the number of tasks assigned to the i-th server. Output Print the minimum number of seconds required to balance the load. Examples Input 2 1 6 Output 2 Input 7 10 11 10 11 10 11 11 Output 0 Input 5 1 2 3 4 5 Output 3 Note In the first example two seconds are needed. In each second, a single task from server #2 should be moved to server #1. After two seconds there should be 3 tasks on server #1 and 4 tasks on server #2. In the second example the load is already balanced. A possible sequence of task movements for the third example is: 1. move a task from server #4 to server #1 (the sequence m becomes: 2 2 3 3 5); 2. then move task from server #5 to server #1 (the sequence m becomes: 3 2 3 3 4); 3. then move task from server #5 to server #2 (the sequence m becomes: 3 3 3 3 3). The above sequence is one of several possible ways to balance the load of servers in three seconds. Submitted Solution: ``` a = input() l = list(map(int, input().split())) avg = 0 s = 0 for i in l: avg += i avg /= len(l) for i in l: s+=(int(abs(i-avg))) print(int(s/2)) ```
instruction
0
83,825
14
167,650
No
output
1
83,825
14
167,651
Provide tags and a correct Python 3 solution for this coding contest problem. In Summer Informatics School, if a student doesn't behave well, teachers make a hole in his badge. And today one of the teachers caught a group of n students doing yet another trick. Let's assume that all these students are numbered from 1 to n. The teacher came to student a and put a hole in his badge. The student, however, claimed that the main culprit is some other student p_a. After that, the teacher came to student p_a and made a hole in his badge as well. The student in reply said that the main culprit was student p_{p_a}. This process went on for a while, but, since the number of students was finite, eventually the teacher came to the student, who already had a hole in his badge. After that, the teacher put a second hole in the student's badge and decided that he is done with this process, and went to the sauna. You don't know the first student who was caught by the teacher. However, you know all the numbers p_i. Your task is to find out for every student a, who would be the student with two holes in the badge if the first caught student was a. Input The first line of the input contains the only integer n (1 ≤ n ≤ 1000) — the number of the naughty students. The second line contains n integers p_1, ..., p_n (1 ≤ p_i ≤ n), where p_i indicates the student who was reported to the teacher by student i. Output For every student a from 1 to n print which student would receive two holes in the badge, if a was the first student caught by the teacher. Examples Input 3 2 3 2 Output 2 2 3 Input 3 1 2 3 Output 1 2 3 Note The picture corresponds to the first example test case. <image> When a = 1, the teacher comes to students 1, 2, 3, 2, in this order, and the student 2 is the one who receives a second hole in his badge. When a = 2, the teacher comes to students 2, 3, 2, and the student 2 gets a second hole in his badge. When a = 3, the teacher will visit students 3, 2, 3 with student 3 getting a second hole in his badge. For the second example test case it's clear that no matter with whom the teacher starts, that student would be the one who gets the second hole in his badge.
instruction
0
84,211
14
168,422
Tags: brute force, dfs and similar, graphs Correct Solution: ``` n = int(input()) arr = list(map(int, input().split())) arr.insert(0, 0) visited = [False for i in range(len(arr))] visited[0] = True res = [-1 for i in range(len(arr))] def travel(p, arr, res): start = p while not visited[p]: visited[p] = True p = arr[p] pp = p while res[pp] < 0: res[pp] = pp pp = arr[pp] if p != start: while res[start] < 0: res[start] = res[p] start = arr[start] for i in range(1, len(arr)): if visited[i]: continue travel(i, arr, res) print(' '.join(map(str, res[1:]))) ```
output
1
84,211
14
168,423
Provide tags and a correct Python 3 solution for this coding contest problem. In Summer Informatics School, if a student doesn't behave well, teachers make a hole in his badge. And today one of the teachers caught a group of n students doing yet another trick. Let's assume that all these students are numbered from 1 to n. The teacher came to student a and put a hole in his badge. The student, however, claimed that the main culprit is some other student p_a. After that, the teacher came to student p_a and made a hole in his badge as well. The student in reply said that the main culprit was student p_{p_a}. This process went on for a while, but, since the number of students was finite, eventually the teacher came to the student, who already had a hole in his badge. After that, the teacher put a second hole in the student's badge and decided that he is done with this process, and went to the sauna. You don't know the first student who was caught by the teacher. However, you know all the numbers p_i. Your task is to find out for every student a, who would be the student with two holes in the badge if the first caught student was a. Input The first line of the input contains the only integer n (1 ≤ n ≤ 1000) — the number of the naughty students. The second line contains n integers p_1, ..., p_n (1 ≤ p_i ≤ n), where p_i indicates the student who was reported to the teacher by student i. Output For every student a from 1 to n print which student would receive two holes in the badge, if a was the first student caught by the teacher. Examples Input 3 2 3 2 Output 2 2 3 Input 3 1 2 3 Output 1 2 3 Note The picture corresponds to the first example test case. <image> When a = 1, the teacher comes to students 1, 2, 3, 2, in this order, and the student 2 is the one who receives a second hole in his badge. When a = 2, the teacher comes to students 2, 3, 2, and the student 2 gets a second hole in his badge. When a = 3, the teacher will visit students 3, 2, 3 with student 3 getting a second hole in his badge. For the second example test case it's clear that no matter with whom the teacher starts, that student would be the one who gets the second hole in his badge.
instruction
0
84,212
14
168,424
Tags: brute force, dfs and similar, graphs Correct Solution: ``` blamed = {} n = int(input()) p = list(map(int, input().split())) for i in range(len(p)): blamed[i+1] = p[i] for i in range(1, n+1): hole = {i:1} blame = blamed[i] while blame not in hole: hole[blame]=1 blame = blamed[blame] print(blame, end=' ') ```
output
1
84,212
14
168,425
Provide tags and a correct Python 3 solution for this coding contest problem. In Summer Informatics School, if a student doesn't behave well, teachers make a hole in his badge. And today one of the teachers caught a group of n students doing yet another trick. Let's assume that all these students are numbered from 1 to n. The teacher came to student a and put a hole in his badge. The student, however, claimed that the main culprit is some other student p_a. After that, the teacher came to student p_a and made a hole in his badge as well. The student in reply said that the main culprit was student p_{p_a}. This process went on for a while, but, since the number of students was finite, eventually the teacher came to the student, who already had a hole in his badge. After that, the teacher put a second hole in the student's badge and decided that he is done with this process, and went to the sauna. You don't know the first student who was caught by the teacher. However, you know all the numbers p_i. Your task is to find out for every student a, who would be the student with two holes in the badge if the first caught student was a. Input The first line of the input contains the only integer n (1 ≤ n ≤ 1000) — the number of the naughty students. The second line contains n integers p_1, ..., p_n (1 ≤ p_i ≤ n), where p_i indicates the student who was reported to the teacher by student i. Output For every student a from 1 to n print which student would receive two holes in the badge, if a was the first student caught by the teacher. Examples Input 3 2 3 2 Output 2 2 3 Input 3 1 2 3 Output 1 2 3 Note The picture corresponds to the first example test case. <image> When a = 1, the teacher comes to students 1, 2, 3, 2, in this order, and the student 2 is the one who receives a second hole in his badge. When a = 2, the teacher comes to students 2, 3, 2, and the student 2 gets a second hole in his badge. When a = 3, the teacher will visit students 3, 2, 3 with student 3 getting a second hole in his badge. For the second example test case it's clear that no matter with whom the teacher starts, that student would be the one who gets the second hole in his badge.
instruction
0
84,213
14
168,426
Tags: brute force, dfs and similar, graphs Correct Solution: ``` n = int(input()) #cantidad de estudiantes A = [] # entradas S = [] # salidas A =(list(map(int,input().split()))) for a in range( 1, n+1): #se deben hacer n ciclos para cada estudiante "a" times = [0]*(n+1) #lista de tamaño n+1 p = a #partimos en estudiante i while (times[p]==0): #si ya tiene un hoyo, se rompe times[p]=1 #agregamos un hoyo p = A[p-1] #vamos a la persona acusada por p S.append(p) #agregamos al con 2 hoyos for i in S: print(i) ```
output
1
84,213
14
168,427
Provide tags and a correct Python 3 solution for this coding contest problem. In Summer Informatics School, if a student doesn't behave well, teachers make a hole in his badge. And today one of the teachers caught a group of n students doing yet another trick. Let's assume that all these students are numbered from 1 to n. The teacher came to student a and put a hole in his badge. The student, however, claimed that the main culprit is some other student p_a. After that, the teacher came to student p_a and made a hole in his badge as well. The student in reply said that the main culprit was student p_{p_a}. This process went on for a while, but, since the number of students was finite, eventually the teacher came to the student, who already had a hole in his badge. After that, the teacher put a second hole in the student's badge and decided that he is done with this process, and went to the sauna. You don't know the first student who was caught by the teacher. However, you know all the numbers p_i. Your task is to find out for every student a, who would be the student with two holes in the badge if the first caught student was a. Input The first line of the input contains the only integer n (1 ≤ n ≤ 1000) — the number of the naughty students. The second line contains n integers p_1, ..., p_n (1 ≤ p_i ≤ n), where p_i indicates the student who was reported to the teacher by student i. Output For every student a from 1 to n print which student would receive two holes in the badge, if a was the first student caught by the teacher. Examples Input 3 2 3 2 Output 2 2 3 Input 3 1 2 3 Output 1 2 3 Note The picture corresponds to the first example test case. <image> When a = 1, the teacher comes to students 1, 2, 3, 2, in this order, and the student 2 is the one who receives a second hole in his badge. When a = 2, the teacher comes to students 2, 3, 2, and the student 2 gets a second hole in his badge. When a = 3, the teacher will visit students 3, 2, 3 with student 3 getting a second hole in his badge. For the second example test case it's clear that no matter with whom the teacher starts, that student would be the one who gets the second hole in his badge.
instruction
0
84,214
14
168,428
Tags: brute force, dfs and similar, graphs Correct Solution: ``` n = int(input()) arr = list(map(int, input().split())) arr3 = [] for k in range(1, n+1): #print(k) arr2 = [] z = k while k: if k in arr2: #print(arr2) arr3.append(k) break else: arr2.append(k) k = arr[k-1] print(*arr3) ```
output
1
84,214
14
168,429
Provide tags and a correct Python 3 solution for this coding contest problem. In Summer Informatics School, if a student doesn't behave well, teachers make a hole in his badge. And today one of the teachers caught a group of n students doing yet another trick. Let's assume that all these students are numbered from 1 to n. The teacher came to student a and put a hole in his badge. The student, however, claimed that the main culprit is some other student p_a. After that, the teacher came to student p_a and made a hole in his badge as well. The student in reply said that the main culprit was student p_{p_a}. This process went on for a while, but, since the number of students was finite, eventually the teacher came to the student, who already had a hole in his badge. After that, the teacher put a second hole in the student's badge and decided that he is done with this process, and went to the sauna. You don't know the first student who was caught by the teacher. However, you know all the numbers p_i. Your task is to find out for every student a, who would be the student with two holes in the badge if the first caught student was a. Input The first line of the input contains the only integer n (1 ≤ n ≤ 1000) — the number of the naughty students. The second line contains n integers p_1, ..., p_n (1 ≤ p_i ≤ n), where p_i indicates the student who was reported to the teacher by student i. Output For every student a from 1 to n print which student would receive two holes in the badge, if a was the first student caught by the teacher. Examples Input 3 2 3 2 Output 2 2 3 Input 3 1 2 3 Output 1 2 3 Note The picture corresponds to the first example test case. <image> When a = 1, the teacher comes to students 1, 2, 3, 2, in this order, and the student 2 is the one who receives a second hole in his badge. When a = 2, the teacher comes to students 2, 3, 2, and the student 2 gets a second hole in his badge. When a = 3, the teacher will visit students 3, 2, 3 with student 3 getting a second hole in his badge. For the second example test case it's clear that no matter with whom the teacher starts, that student would be the one who gets the second hole in his badge.
instruction
0
84,215
14
168,430
Tags: brute force, dfs and similar, graphs Correct Solution: ``` if __name__ == "__main__": n = int(input()) p = tuple(map(int, input().split())) for i in range(n): st = set() ref = i+1 while ref not in st: st.add(ref) ref = p[ref - 1] print(ref, end=' ') ```
output
1
84,215
14
168,431
Provide tags and a correct Python 3 solution for this coding contest problem. In Summer Informatics School, if a student doesn't behave well, teachers make a hole in his badge. And today one of the teachers caught a group of n students doing yet another trick. Let's assume that all these students are numbered from 1 to n. The teacher came to student a and put a hole in his badge. The student, however, claimed that the main culprit is some other student p_a. After that, the teacher came to student p_a and made a hole in his badge as well. The student in reply said that the main culprit was student p_{p_a}. This process went on for a while, but, since the number of students was finite, eventually the teacher came to the student, who already had a hole in his badge. After that, the teacher put a second hole in the student's badge and decided that he is done with this process, and went to the sauna. You don't know the first student who was caught by the teacher. However, you know all the numbers p_i. Your task is to find out for every student a, who would be the student with two holes in the badge if the first caught student was a. Input The first line of the input contains the only integer n (1 ≤ n ≤ 1000) — the number of the naughty students. The second line contains n integers p_1, ..., p_n (1 ≤ p_i ≤ n), where p_i indicates the student who was reported to the teacher by student i. Output For every student a from 1 to n print which student would receive two holes in the badge, if a was the first student caught by the teacher. Examples Input 3 2 3 2 Output 2 2 3 Input 3 1 2 3 Output 1 2 3 Note The picture corresponds to the first example test case. <image> When a = 1, the teacher comes to students 1, 2, 3, 2, in this order, and the student 2 is the one who receives a second hole in his badge. When a = 2, the teacher comes to students 2, 3, 2, and the student 2 gets a second hole in his badge. When a = 3, the teacher will visit students 3, 2, 3 with student 3 getting a second hole in his badge. For the second example test case it's clear that no matter with whom the teacher starts, that student would be the one who gets the second hole in his badge.
instruction
0
84,216
14
168,432
Tags: brute force, dfs and similar, graphs Correct Solution: ``` n= int(input()) x = list(map(int,input().split())) for i in range(len(x)): final = [0]*n j=i while final[j]!=2: final[j]+=1 j=x[j]-1 print(j+1,end=" ") ```
output
1
84,216
14
168,433
Provide tags and a correct Python 3 solution for this coding contest problem. In Summer Informatics School, if a student doesn't behave well, teachers make a hole in his badge. And today one of the teachers caught a group of n students doing yet another trick. Let's assume that all these students are numbered from 1 to n. The teacher came to student a and put a hole in his badge. The student, however, claimed that the main culprit is some other student p_a. After that, the teacher came to student p_a and made a hole in his badge as well. The student in reply said that the main culprit was student p_{p_a}. This process went on for a while, but, since the number of students was finite, eventually the teacher came to the student, who already had a hole in his badge. After that, the teacher put a second hole in the student's badge and decided that he is done with this process, and went to the sauna. You don't know the first student who was caught by the teacher. However, you know all the numbers p_i. Your task is to find out for every student a, who would be the student with two holes in the badge if the first caught student was a. Input The first line of the input contains the only integer n (1 ≤ n ≤ 1000) — the number of the naughty students. The second line contains n integers p_1, ..., p_n (1 ≤ p_i ≤ n), where p_i indicates the student who was reported to the teacher by student i. Output For every student a from 1 to n print which student would receive two holes in the badge, if a was the first student caught by the teacher. Examples Input 3 2 3 2 Output 2 2 3 Input 3 1 2 3 Output 1 2 3 Note The picture corresponds to the first example test case. <image> When a = 1, the teacher comes to students 1, 2, 3, 2, in this order, and the student 2 is the one who receives a second hole in his badge. When a = 2, the teacher comes to students 2, 3, 2, and the student 2 gets a second hole in his badge. When a = 3, the teacher will visit students 3, 2, 3 with student 3 getting a second hole in his badge. For the second example test case it's clear that no matter with whom the teacher starts, that student would be the one who gets the second hole in his badge.
instruction
0
84,217
14
168,434
Tags: brute force, dfs and similar, graphs Correct Solution: ``` from collections import defaultdict def addEdge(g, u, v): g[u].append(v) def helper(v, black, gray): black[v] = True gray[v] = True for neigh in g[v]: if black[neigh] == False: if helper(neigh, black, gray): return True elif gray[neigh] == True: global ans ans = neigh return True gray[neigh] = False return False def detectCycle(res): for i in range(len(res)): black, gray = [False]*len(res), [False]*len(res) helper(i, black, gray) global ans res[i] = ans+1 ans = -1 n = int(input()) arr = list(map(int, input().split())) g = defaultdict(list) for i in range(len(arr)): addEdge(g,i,arr[i]-1) #print (g) #exit () ans = -1 res = [False] * len(arr) detectCycle(res) print (' '.join([str(i) for i in res])) ```
output
1
84,217
14
168,435
Provide tags and a correct Python 3 solution for this coding contest problem. In Summer Informatics School, if a student doesn't behave well, teachers make a hole in his badge. And today one of the teachers caught a group of n students doing yet another trick. Let's assume that all these students are numbered from 1 to n. The teacher came to student a and put a hole in his badge. The student, however, claimed that the main culprit is some other student p_a. After that, the teacher came to student p_a and made a hole in his badge as well. The student in reply said that the main culprit was student p_{p_a}. This process went on for a while, but, since the number of students was finite, eventually the teacher came to the student, who already had a hole in his badge. After that, the teacher put a second hole in the student's badge and decided that he is done with this process, and went to the sauna. You don't know the first student who was caught by the teacher. However, you know all the numbers p_i. Your task is to find out for every student a, who would be the student with two holes in the badge if the first caught student was a. Input The first line of the input contains the only integer n (1 ≤ n ≤ 1000) — the number of the naughty students. The second line contains n integers p_1, ..., p_n (1 ≤ p_i ≤ n), where p_i indicates the student who was reported to the teacher by student i. Output For every student a from 1 to n print which student would receive two holes in the badge, if a was the first student caught by the teacher. Examples Input 3 2 3 2 Output 2 2 3 Input 3 1 2 3 Output 1 2 3 Note The picture corresponds to the first example test case. <image> When a = 1, the teacher comes to students 1, 2, 3, 2, in this order, and the student 2 is the one who receives a second hole in his badge. When a = 2, the teacher comes to students 2, 3, 2, and the student 2 gets a second hole in his badge. When a = 3, the teacher will visit students 3, 2, 3 with student 3 getting a second hole in his badge. For the second example test case it's clear that no matter with whom the teacher starts, that student would be the one who gets the second hole in his badge.
instruction
0
84,218
14
168,436
Tags: brute force, dfs and similar, graphs Correct Solution: ``` n=int(input()) lst = [int(i) for i in input().split()][:n] ans=[] a=0 while(a<n): visited=[] visited.append(a+1) while True: ele=int(visited[-1])-1 if(lst[ele] not in visited): visited.append(lst[ele]) else: ans.append(lst[ele]) break a=a+1 print(*ans) ```
output
1
84,218
14
168,437
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Manao's friends often send him new songs. He never listens to them right away. Instead, he compiles them into a playlist. When he feels that his mind is open to new music, he opens the playlist and starts to listen to the songs. Of course, there are some songs that Manao doesn't particuarly enjoy. To get more pleasure from the received songs, he invented the following procedure of listening to the playlist: * If after listening to some song Manao realizes that he liked it, then he remembers it and starts to listen to the next unlistened song. * If after listening to some song Manao realizes that he did not like it, he listens to all the songs he liked up to this point and then begins to listen to the next unlistened song. For example, if Manao has four songs in the playlist, A, B, C, D (in the corresponding order) and he is going to like songs A and C in the end, then the order of listening is the following: 1. Manao listens to A, he likes it, he remembers it. 2. Manao listens to B, he does not like it, so he listens to A, again. 3. Manao listens to C, he likes the song and he remembers it, too. 4. Manao listens to D, but does not enjoy it and re-listens to songs A and C. That is, in the end Manao listens to song A three times, to song C twice and songs B and D once. Note that if Manao once liked a song, he will never dislike it on a subsequent listening. Manao has received n songs: the i-th of them is li seconds long and Manao may like it with a probability of pi percents. The songs could get on Manao's playlist in any order, so Manao wants to know the maximum expected value of the number of seconds after which the listening process will be over, for all possible permutations of the songs in the playlist. Input The first line contains a single integer n (1 ≤ n ≤ 50000). The i-th of the following n lines contains two integers, separated by a single space — li and pi (15 ≤ li ≤ 1000, 0 ≤ pi ≤ 100) — the length of the i-th song in seconds and the probability that Manao will like the song, in percents. Output In a single line print a single real number — the maximum expected listening time over all permutations of songs. The answer will be considered valid if the absolute or relative error does not exceed 10 - 9. Examples Input 3 150 20 150 50 100 50 Output 537.500000000 Input 4 300 0 300 50 240 50 360 80 Output 2121.000000000 Note Consider the first test case. If Manao listens to the songs in the order in which they were originally compiled, the mathematical expectation will be equal to 467.5 seconds. The maximum expected value is obtained by putting the first song at the end of the playlist. Consider the second test case. The song which is 360 seconds long should be listened to first. The song 300 seconds long which Manao will dislike for sure should be put in the end. Submitted Solution: ``` n=int(input("")) L=[] l=[] a=1 for k in range(n): T=input("") if(not T in L): print("OK") L.append(T) l.append(1) else: a=L.index(T) print(L[a]+str(l[a])) l[a]+=1 ```
instruction
0
84,512
14
169,024
No
output
1
84,512
14
169,025
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Xenia the horse breeder has n (n > 1) horses that stand in a row. Each horse has its own unique number. Initially, the i-th left horse has number i. That is, the sequence of numbers of horses in a row looks as follows (from left to right): 1, 2, 3, ..., n. Xenia trains horses before the performance. During the practice sessions, she consistently gives them commands. Each command is a pair of numbers l, r (1 ≤ l < r ≤ n). The command l, r means that the horses that are on the l-th, (l + 1)-th, (l + 2)-th, ..., r-th places from the left must be rearranged. The horses that initially stand on the l-th and r-th places will swap. The horses on the (l + 1)-th and (r - 1)-th places will swap. The horses on the (l + 2)-th and (r - 2)-th places will swap and so on. In other words, the horses that were on the segment [l, r] change their order to the reverse one. For example, if Xenia commanded l = 2, r = 5, and the sequence of numbers of horses before the command looked as (2, 1, 3, 4, 5, 6), then after the command the sequence will be (2, 5, 4, 3, 1, 6). We know that during the practice Xenia gave at most three commands of the described form. You have got the final sequence of numbers of horses by the end of the practice. Find what commands Xenia gave during the practice. Note that you do not need to minimize the number of commands in the solution, find any valid sequence of at most three commands. Input The first line contains an integer n (2 ≤ n ≤ 1000) — the number of horses in the row. The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ n), where ai is the number of the i-th left horse in the row after the practice. Output The first line should contain integer k (0 ≤ k ≤ 3) — the number of commads Xenia gave during the practice. In each of the next k lines print two integers. In the i-th line print numbers li, ri (1 ≤ li < ri ≤ n) — Xenia's i-th command during the practice. It is guaranteed that a solution exists. If there are several solutions, you are allowed to print any of them. Examples Input 5 1 4 3 2 5 Output 1 2 4 Input 6 2 1 4 3 6 5 Output 3 1 2 3 4 5 6 Submitted Solution: ``` import sys data = [x.rstrip() for x in sys.stdin] x = str(data[0].rstrip()) y = str(data[1].rstrip()) y=y.split(" ") temp = [] for i in y: temp.append(i) def compare(x): x = x.split(" ") x.sort() return x temp.sort() counter = 0 probDict = {} probDict2 = {} for i in range(0, len(temp)): if temp[i] == y[i]: pass if temp[i] != y[i] and compare((temp[i]+" "+y[i]))[0] not in probDict2: counter += 1 probDict2[compare((temp[i]+" "+y[i]))[0]] = "" probDict[counter]=(temp[i]+" "+y[i]) print(counter) for i in range(0, counter): print(probDict[i+1]) ```
instruction
0
84,529
14
169,058
No
output
1
84,529
14
169,059
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Xenia the horse breeder has n (n > 1) horses that stand in a row. Each horse has its own unique number. Initially, the i-th left horse has number i. That is, the sequence of numbers of horses in a row looks as follows (from left to right): 1, 2, 3, ..., n. Xenia trains horses before the performance. During the practice sessions, she consistently gives them commands. Each command is a pair of numbers l, r (1 ≤ l < r ≤ n). The command l, r means that the horses that are on the l-th, (l + 1)-th, (l + 2)-th, ..., r-th places from the left must be rearranged. The horses that initially stand on the l-th and r-th places will swap. The horses on the (l + 1)-th and (r - 1)-th places will swap. The horses on the (l + 2)-th and (r - 2)-th places will swap and so on. In other words, the horses that were on the segment [l, r] change their order to the reverse one. For example, if Xenia commanded l = 2, r = 5, and the sequence of numbers of horses before the command looked as (2, 1, 3, 4, 5, 6), then after the command the sequence will be (2, 5, 4, 3, 1, 6). We know that during the practice Xenia gave at most three commands of the described form. You have got the final sequence of numbers of horses by the end of the practice. Find what commands Xenia gave during the practice. Note that you do not need to minimize the number of commands in the solution, find any valid sequence of at most three commands. Input The first line contains an integer n (2 ≤ n ≤ 1000) — the number of horses in the row. The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ n), where ai is the number of the i-th left horse in the row after the practice. Output The first line should contain integer k (0 ≤ k ≤ 3) — the number of commads Xenia gave during the practice. In each of the next k lines print two integers. In the i-th line print numbers li, ri (1 ≤ li < ri ≤ n) — Xenia's i-th command during the practice. It is guaranteed that a solution exists. If there are several solutions, you are allowed to print any of them. Examples Input 5 1 4 3 2 5 Output 1 2 4 Input 6 2 1 4 3 6 5 Output 3 1 2 3 4 5 6 Submitted Solution: ``` n = int(input()) a = list(map(int, input().split())) i = 1 l, r = [], [] for i in range(1,n): if a[i - 1] != i: if i == 1: l.append(1) r.append(a[0]) a[0:a[0]] = a[a[0] - 1::-1] else: # print(i, a[i - 1],123) l.append(i) r.append(a[i - 1]) a[i - 1:a[i - 1]] = a[a[i - 1] - 1:i - 2:-1] # print(i, a) for r1 in range(len(l)): print(l[r1],r[r1]) ```
instruction
0
84,530
14
169,060
No
output
1
84,530
14
169,061
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Xenia the horse breeder has n (n > 1) horses that stand in a row. Each horse has its own unique number. Initially, the i-th left horse has number i. That is, the sequence of numbers of horses in a row looks as follows (from left to right): 1, 2, 3, ..., n. Xenia trains horses before the performance. During the practice sessions, she consistently gives them commands. Each command is a pair of numbers l, r (1 ≤ l < r ≤ n). The command l, r means that the horses that are on the l-th, (l + 1)-th, (l + 2)-th, ..., r-th places from the left must be rearranged. The horses that initially stand on the l-th and r-th places will swap. The horses on the (l + 1)-th and (r - 1)-th places will swap. The horses on the (l + 2)-th and (r - 2)-th places will swap and so on. In other words, the horses that were on the segment [l, r] change their order to the reverse one. For example, if Xenia commanded l = 2, r = 5, and the sequence of numbers of horses before the command looked as (2, 1, 3, 4, 5, 6), then after the command the sequence will be (2, 5, 4, 3, 1, 6). We know that during the practice Xenia gave at most three commands of the described form. You have got the final sequence of numbers of horses by the end of the practice. Find what commands Xenia gave during the practice. Note that you do not need to minimize the number of commands in the solution, find any valid sequence of at most three commands. Input The first line contains an integer n (2 ≤ n ≤ 1000) — the number of horses in the row. The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ n), where ai is the number of the i-th left horse in the row after the practice. Output The first line should contain integer k (0 ≤ k ≤ 3) — the number of commads Xenia gave during the practice. In each of the next k lines print two integers. In the i-th line print numbers li, ri (1 ≤ li < ri ≤ n) — Xenia's i-th command during the practice. It is guaranteed that a solution exists. If there are several solutions, you are allowed to print any of them. Examples Input 5 1 4 3 2 5 Output 1 2 4 Input 6 2 1 4 3 6 5 Output 3 1 2 3 4 5 6 Submitted Solution: ``` if __name__=='__main__': inp =input() n = inp inp = input() arr = inp.split(' ') L = [] for a in arr: L.append(int(a)) st = 0 ret = [] stp = 0 while st<len(L) and L[st]==st+1: st+=1 if st==len(L): print(stp) else: tof=st+1 for i in range(len(L)): if L[i]==tof: ret.append((tof,i+1)) st=i+1 while st<len(L) and L[st]==st+1: st+=1 if st<len(L): tof = st+1 for i in range(len(L)): if L[i]==tof: ret.append((tof,i+1)) st=i+1 while st<len(L) and L[st]==st+1: st+=1 if st<len(L): tof=st+1 for i in range(len(L)): if L[i]==tof: ret.append((tof,i+1)) st=i+1 print(len(ret)) for (x,y) in ret: print(x,end=' ') print(y) ```
instruction
0
84,531
14
169,062
No
output
1
84,531
14
169,063
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Xenia the horse breeder has n (n > 1) horses that stand in a row. Each horse has its own unique number. Initially, the i-th left horse has number i. That is, the sequence of numbers of horses in a row looks as follows (from left to right): 1, 2, 3, ..., n. Xenia trains horses before the performance. During the practice sessions, she consistently gives them commands. Each command is a pair of numbers l, r (1 ≤ l < r ≤ n). The command l, r means that the horses that are on the l-th, (l + 1)-th, (l + 2)-th, ..., r-th places from the left must be rearranged. The horses that initially stand on the l-th and r-th places will swap. The horses on the (l + 1)-th and (r - 1)-th places will swap. The horses on the (l + 2)-th and (r - 2)-th places will swap and so on. In other words, the horses that were on the segment [l, r] change their order to the reverse one. For example, if Xenia commanded l = 2, r = 5, and the sequence of numbers of horses before the command looked as (2, 1, 3, 4, 5, 6), then after the command the sequence will be (2, 5, 4, 3, 1, 6). We know that during the practice Xenia gave at most three commands of the described form. You have got the final sequence of numbers of horses by the end of the practice. Find what commands Xenia gave during the practice. Note that you do not need to minimize the number of commands in the solution, find any valid sequence of at most three commands. Input The first line contains an integer n (2 ≤ n ≤ 1000) — the number of horses in the row. The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ n), where ai is the number of the i-th left horse in the row after the practice. Output The first line should contain integer k (0 ≤ k ≤ 3) — the number of commads Xenia gave during the practice. In each of the next k lines print two integers. In the i-th line print numbers li, ri (1 ≤ li < ri ≤ n) — Xenia's i-th command during the practice. It is guaranteed that a solution exists. If there are several solutions, you are allowed to print any of them. Examples Input 5 1 4 3 2 5 Output 1 2 4 Input 6 2 1 4 3 6 5 Output 3 1 2 3 4 5 6 Submitted Solution: ``` from math import * horses = int(input()) horses_order = [] horses_order_c = [] horses_order = input().split() horses_order_c = horses_order.copy() horses_order_c.sort() i = int(0) count = horses temp = "" i_values = [] j_values = [] val = int(0) while count != 0: if horses_order[i] == horses_order_c[i]: val += 1 else: temp = horses_order[i] count2 = horses j = int(0) while count2 != 0: if temp == horses_order_c[j]: i_values.append(i) j_values.append(j) j += 1 count2 -= 1 count -= 1 i += 1 final_val = len(i_values)/2 count = final_val i = int(0) print(int(final_val)) while count != 0: print(str(i_values[i]+1)+" "+str(j_values[i]+1)) i += 2 count -= 1 ```
instruction
0
84,532
14
169,064
No
output
1
84,532
14
169,065
Provide tags and a correct Python 3 solution for this coding contest problem. You are a lover of bacteria. You want to raise some bacteria in a box. Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly x bacteria in the box at some moment. What is the minimum number of bacteria you need to put into the box across those days? Input The only line containing one integer x (1 ≤ x ≤ 109). Output The only line containing one integer: the answer. Examples Input 5 Output 2 Input 8 Output 1 Note For the first sample, we can add one bacterium in the box in the first day morning and at the third morning there will be 4 bacteria in the box. Now we put one more resulting 5 in the box. We added 2 bacteria in the process so the answer is 2. For the second sample, we can put one in the first morning and in the 4-th morning there will be 8 in the box. So the answer is 1.
instruction
0
84,595
14
169,190
Tags: bitmasks Correct Solution: ``` n=int(input()) binary=bin(n) cnt=0 for i in range(2,len(binary)): if binary[i]=='1': #print(binary[i]) cnt+=1 print(cnt) ```
output
1
84,595
14
169,191
Provide tags and a correct Python 3 solution for this coding contest problem. You are a lover of bacteria. You want to raise some bacteria in a box. Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly x bacteria in the box at some moment. What is the minimum number of bacteria you need to put into the box across those days? Input The only line containing one integer x (1 ≤ x ≤ 109). Output The only line containing one integer: the answer. Examples Input 5 Output 2 Input 8 Output 1 Note For the first sample, we can add one bacterium in the box in the first day morning and at the third morning there will be 4 bacteria in the box. Now we put one more resulting 5 in the box. We added 2 bacteria in the process so the answer is 2. For the second sample, we can put one in the first morning and in the 4-th morning there will be 8 in the box. So the answer is 1.
instruction
0
84,596
14
169,192
Tags: bitmasks Correct Solution: ``` def main(): n, res = int(input()), 0 while n: res += n & 1 n >>= 1 print(res) if __name__ == '__main__': main() ```
output
1
84,596
14
169,193
Provide tags and a correct Python 3 solution for this coding contest problem. You are a lover of bacteria. You want to raise some bacteria in a box. Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly x bacteria in the box at some moment. What is the minimum number of bacteria you need to put into the box across those days? Input The only line containing one integer x (1 ≤ x ≤ 109). Output The only line containing one integer: the answer. Examples Input 5 Output 2 Input 8 Output 1 Note For the first sample, we can add one bacterium in the box in the first day morning and at the third morning there will be 4 bacteria in the box. Now we put one more resulting 5 in the box. We added 2 bacteria in the process so the answer is 2. For the second sample, we can put one in the first morning and in the 4-th morning there will be 8 in the box. So the answer is 1.
instruction
0
84,597
14
169,194
Tags: bitmasks Correct Solution: ``` t=int(input()) count=1 while t!=1: if t%2!=0: count+=1 t=t//2 print(count) ```
output
1
84,597
14
169,195
Provide tags and a correct Python 3 solution for this coding contest problem. You are a lover of bacteria. You want to raise some bacteria in a box. Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly x bacteria in the box at some moment. What is the minimum number of bacteria you need to put into the box across those days? Input The only line containing one integer x (1 ≤ x ≤ 109). Output The only line containing one integer: the answer. Examples Input 5 Output 2 Input 8 Output 1 Note For the first sample, we can add one bacterium in the box in the first day morning and at the third morning there will be 4 bacteria in the box. Now we put one more resulting 5 in the box. We added 2 bacteria in the process so the answer is 2. For the second sample, we can put one in the first morning and in the 4-th morning there will be 8 in the box. So the answer is 1.
instruction
0
84,598
14
169,196
Tags: bitmasks Correct Solution: ``` n = int(input()) c = 0 while n > 0: if n % 2 == 1: c = c + 1 n = n // 2 print(c) ```
output
1
84,598
14
169,197
Provide tags and a correct Python 3 solution for this coding contest problem. You are a lover of bacteria. You want to raise some bacteria in a box. Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly x bacteria in the box at some moment. What is the minimum number of bacteria you need to put into the box across those days? Input The only line containing one integer x (1 ≤ x ≤ 109). Output The only line containing one integer: the answer. Examples Input 5 Output 2 Input 8 Output 1 Note For the first sample, we can add one bacterium in the box in the first day morning and at the third morning there will be 4 bacteria in the box. Now we put one more resulting 5 in the box. We added 2 bacteria in the process so the answer is 2. For the second sample, we can put one in the first morning and in the 4-th morning there will be 8 in the box. So the answer is 1.
instruction
0
84,599
14
169,198
Tags: bitmasks Correct Solution: ``` x=int(input()) bacteria=0 while(x>0): k=0 while(2**k<=x): k+=1 k-=1 x=x-(2**k) bacteria+=1 print(bacteria) ```
output
1
84,599
14
169,199
Provide tags and a correct Python 3 solution for this coding contest problem. You are a lover of bacteria. You want to raise some bacteria in a box. Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly x bacteria in the box at some moment. What is the minimum number of bacteria you need to put into the box across those days? Input The only line containing one integer x (1 ≤ x ≤ 109). Output The only line containing one integer: the answer. Examples Input 5 Output 2 Input 8 Output 1 Note For the first sample, we can add one bacterium in the box in the first day morning and at the third morning there will be 4 bacteria in the box. Now we put one more resulting 5 in the box. We added 2 bacteria in the process so the answer is 2. For the second sample, we can put one in the first morning and in the 4-th morning there will be 8 in the box. So the answer is 1.
instruction
0
84,600
14
169,200
Tags: bitmasks Correct Solution: ``` x = int(input()) k = 0 while x > 0: if x % 2 == 0: x = x // 2 else: k += 1 x -= 1 print(k) ```
output
1
84,600
14
169,201
Provide tags and a correct Python 3 solution for this coding contest problem. You are a lover of bacteria. You want to raise some bacteria in a box. Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly x bacteria in the box at some moment. What is the minimum number of bacteria you need to put into the box across those days? Input The only line containing one integer x (1 ≤ x ≤ 109). Output The only line containing one integer: the answer. Examples Input 5 Output 2 Input 8 Output 1 Note For the first sample, we can add one bacterium in the box in the first day morning and at the third morning there will be 4 bacteria in the box. Now we put one more resulting 5 in the box. We added 2 bacteria in the process so the answer is 2. For the second sample, we can put one in the first morning and in the 4-th morning there will be 8 in the box. So the answer is 1.
instruction
0
84,601
14
169,202
Tags: bitmasks Correct Solution: ``` def binary(n): while n > 0: yield n % 2 n //= 2 def main(): n = int(input()) print(sum(binary(n))) if __name__ == '__main__': main() ```
output
1
84,601
14
169,203
Provide tags and a correct Python 3 solution for this coding contest problem. You are a lover of bacteria. You want to raise some bacteria in a box. Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly x bacteria in the box at some moment. What is the minimum number of bacteria you need to put into the box across those days? Input The only line containing one integer x (1 ≤ x ≤ 109). Output The only line containing one integer: the answer. Examples Input 5 Output 2 Input 8 Output 1 Note For the first sample, we can add one bacterium in the box in the first day morning and at the third morning there will be 4 bacteria in the box. Now we put one more resulting 5 in the box. We added 2 bacteria in the process so the answer is 2. For the second sample, we can put one in the first morning and in the 4-th morning there will be 8 in the box. So the answer is 1.
instruction
0
84,602
14
169,204
Tags: bitmasks Correct Solution: ``` n=int(input()) c=0 while n>1: if n%2==1: c=c+1 n=n//2 print(c+1) ```
output
1
84,602
14
169,205
Provide tags and a correct Python 3 solution for this coding contest problem. Harry Water, Ronaldo, Her-my-oh-knee and their friends have started a new school year at their MDCS School of Speechcraft and Misery. At the time, they are very happy to have seen each other after a long time. The sun is shining, birds are singing, flowers are blooming, and their Potions class teacher, professor Snipe is sulky as usual. Due to his angst fueled by disappointment in his own life, he has given them a lot of homework in Potions class. Each of the n students has been assigned a single task. Some students do certain tasks faster than others. Thus, they want to redistribute the tasks so that each student still does exactly one task, and that all tasks are finished. Each student has their own laziness level, and each task has its own difficulty level. Professor Snipe is trying hard to improve their work ethics, so each student’s laziness level is equal to their task’s difficulty level. Both sets of values are given by the sequence a, where ai represents both the laziness level of the i-th student and the difficulty of his task. The time a student needs to finish a task is equal to the product of their laziness level and the task’s difficulty. They are wondering, what is the minimum possible total time they must spend to finish all tasks if they distribute them in the optimal way. Each person should receive one task and each task should be given to one person. Print the answer modulo 10 007. Input The first line of input contains integer n (1 ≤ n ≤ 100 000) — the number of tasks. The next n lines contain exactly one integer number ai (1 ≤ ai ≤ 100 000) — both the difficulty of the initial task and the laziness of the i-th students. Output Print the minimum total time to finish all tasks modulo 10 007. Example Input 2 1 3 Output 6 Note In the first sample, if the students switch their tasks, they will be able to finish them in 3 + 3 = 6 time units.
instruction
0
84,663
14
169,326
Tags: implementation, sortings Correct Solution: ``` n=int(input()) l=[] for i in range(n): x=int(input()) l.append(x) l.sort() s=0 for i in range(n): s+=l[i]*l[n-i-1] print(s%10007) ```
output
1
84,663
14
169,327
Provide tags and a correct Python 3 solution for this coding contest problem. Harry Water, Ronaldo, Her-my-oh-knee and their friends have started a new school year at their MDCS School of Speechcraft and Misery. At the time, they are very happy to have seen each other after a long time. The sun is shining, birds are singing, flowers are blooming, and their Potions class teacher, professor Snipe is sulky as usual. Due to his angst fueled by disappointment in his own life, he has given them a lot of homework in Potions class. Each of the n students has been assigned a single task. Some students do certain tasks faster than others. Thus, they want to redistribute the tasks so that each student still does exactly one task, and that all tasks are finished. Each student has their own laziness level, and each task has its own difficulty level. Professor Snipe is trying hard to improve their work ethics, so each student’s laziness level is equal to their task’s difficulty level. Both sets of values are given by the sequence a, where ai represents both the laziness level of the i-th student and the difficulty of his task. The time a student needs to finish a task is equal to the product of their laziness level and the task’s difficulty. They are wondering, what is the minimum possible total time they must spend to finish all tasks if they distribute them in the optimal way. Each person should receive one task and each task should be given to one person. Print the answer modulo 10 007. Input The first line of input contains integer n (1 ≤ n ≤ 100 000) — the number of tasks. The next n lines contain exactly one integer number ai (1 ≤ ai ≤ 100 000) — both the difficulty of the initial task and the laziness of the i-th students. Output Print the minimum total time to finish all tasks modulo 10 007. Example Input 2 1 3 Output 6 Note In the first sample, if the students switch their tasks, they will be able to finish them in 3 + 3 = 6 time units.
instruction
0
84,664
14
169,328
Tags: implementation, sortings Correct Solution: ``` n=int(input()) l=[] for i in range(n): l.append(int(input())) l.sort() r=l[:]; r.reverse() res=0; for i in range(n): res=(res+l[i]*r[i])%10007 print(res) ```
output
1
84,664
14
169,329
Provide tags and a correct Python 3 solution for this coding contest problem. Harry Water, Ronaldo, Her-my-oh-knee and their friends have started a new school year at their MDCS School of Speechcraft and Misery. At the time, they are very happy to have seen each other after a long time. The sun is shining, birds are singing, flowers are blooming, and their Potions class teacher, professor Snipe is sulky as usual. Due to his angst fueled by disappointment in his own life, he has given them a lot of homework in Potions class. Each of the n students has been assigned a single task. Some students do certain tasks faster than others. Thus, they want to redistribute the tasks so that each student still does exactly one task, and that all tasks are finished. Each student has their own laziness level, and each task has its own difficulty level. Professor Snipe is trying hard to improve their work ethics, so each student’s laziness level is equal to their task’s difficulty level. Both sets of values are given by the sequence a, where ai represents both the laziness level of the i-th student and the difficulty of his task. The time a student needs to finish a task is equal to the product of their laziness level and the task’s difficulty. They are wondering, what is the minimum possible total time they must spend to finish all tasks if they distribute them in the optimal way. Each person should receive one task and each task should be given to one person. Print the answer modulo 10 007. Input The first line of input contains integer n (1 ≤ n ≤ 100 000) — the number of tasks. The next n lines contain exactly one integer number ai (1 ≤ ai ≤ 100 000) — both the difficulty of the initial task and the laziness of the i-th students. Output Print the minimum total time to finish all tasks modulo 10 007. Example Input 2 1 3 Output 6 Note In the first sample, if the students switch their tasks, they will be able to finish them in 3 + 3 = 6 time units.
instruction
0
84,665
14
169,330
Tags: implementation, sortings Correct Solution: ``` n = int(input()) lazy = [] tasks = [] for x in range(n): k = int(input()) lazy.append(k) tasks.append(k) lazy.sort() tasks.sort(reverse = True) thing = list(zip(lazy, tasks)) total = 0 for x in thing: total += x[0] * x[1] print(int(total%10007)) ```
output
1
84,665
14
169,331
Provide tags and a correct Python 3 solution for this coding contest problem. Harry Water, Ronaldo, Her-my-oh-knee and their friends have started a new school year at their MDCS School of Speechcraft and Misery. At the time, they are very happy to have seen each other after a long time. The sun is shining, birds are singing, flowers are blooming, and their Potions class teacher, professor Snipe is sulky as usual. Due to his angst fueled by disappointment in his own life, he has given them a lot of homework in Potions class. Each of the n students has been assigned a single task. Some students do certain tasks faster than others. Thus, they want to redistribute the tasks so that each student still does exactly one task, and that all tasks are finished. Each student has their own laziness level, and each task has its own difficulty level. Professor Snipe is trying hard to improve their work ethics, so each student’s laziness level is equal to their task’s difficulty level. Both sets of values are given by the sequence a, where ai represents both the laziness level of the i-th student and the difficulty of his task. The time a student needs to finish a task is equal to the product of their laziness level and the task’s difficulty. They are wondering, what is the minimum possible total time they must spend to finish all tasks if they distribute them in the optimal way. Each person should receive one task and each task should be given to one person. Print the answer modulo 10 007. Input The first line of input contains integer n (1 ≤ n ≤ 100 000) — the number of tasks. The next n lines contain exactly one integer number ai (1 ≤ ai ≤ 100 000) — both the difficulty of the initial task and the laziness of the i-th students. Output Print the minimum total time to finish all tasks modulo 10 007. Example Input 2 1 3 Output 6 Note In the first sample, if the students switch their tasks, they will be able to finish them in 3 + 3 = 6 time units.
instruction
0
84,666
14
169,332
Tags: implementation, sortings Correct Solution: ``` n = int(input()) dt = sorted([int(input()) for i in range(n)]) ans = 0 for i in range(n): ans += dt[i] * dt[-i-1] print(ans%10007) ```
output
1
84,666
14
169,333
Provide tags and a correct Python 3 solution for this coding contest problem. Harry Water, Ronaldo, Her-my-oh-knee and their friends have started a new school year at their MDCS School of Speechcraft and Misery. At the time, they are very happy to have seen each other after a long time. The sun is shining, birds are singing, flowers are blooming, and their Potions class teacher, professor Snipe is sulky as usual. Due to his angst fueled by disappointment in his own life, he has given them a lot of homework in Potions class. Each of the n students has been assigned a single task. Some students do certain tasks faster than others. Thus, they want to redistribute the tasks so that each student still does exactly one task, and that all tasks are finished. Each student has their own laziness level, and each task has its own difficulty level. Professor Snipe is trying hard to improve their work ethics, so each student’s laziness level is equal to their task’s difficulty level. Both sets of values are given by the sequence a, where ai represents both the laziness level of the i-th student and the difficulty of his task. The time a student needs to finish a task is equal to the product of their laziness level and the task’s difficulty. They are wondering, what is the minimum possible total time they must spend to finish all tasks if they distribute them in the optimal way. Each person should receive one task and each task should be given to one person. Print the answer modulo 10 007. Input The first line of input contains integer n (1 ≤ n ≤ 100 000) — the number of tasks. The next n lines contain exactly one integer number ai (1 ≤ ai ≤ 100 000) — both the difficulty of the initial task and the laziness of the i-th students. Output Print the minimum total time to finish all tasks modulo 10 007. Example Input 2 1 3 Output 6 Note In the first sample, if the students switch their tasks, they will be able to finish them in 3 + 3 = 6 time units.
instruction
0
84,667
14
169,334
Tags: implementation, sortings Correct Solution: ``` n = int(input()) a = sorted([int(input()) for i in range(n)]) time = 0 for i in range(n): time += a[i] * a[n - 1 - i] print(time % 10007) ```
output
1
84,667
14
169,335
Provide tags and a correct Python 3 solution for this coding contest problem. Harry Water, Ronaldo, Her-my-oh-knee and their friends have started a new school year at their MDCS School of Speechcraft and Misery. At the time, they are very happy to have seen each other after a long time. The sun is shining, birds are singing, flowers are blooming, and their Potions class teacher, professor Snipe is sulky as usual. Due to his angst fueled by disappointment in his own life, he has given them a lot of homework in Potions class. Each of the n students has been assigned a single task. Some students do certain tasks faster than others. Thus, they want to redistribute the tasks so that each student still does exactly one task, and that all tasks are finished. Each student has their own laziness level, and each task has its own difficulty level. Professor Snipe is trying hard to improve their work ethics, so each student’s laziness level is equal to their task’s difficulty level. Both sets of values are given by the sequence a, where ai represents both the laziness level of the i-th student and the difficulty of his task. The time a student needs to finish a task is equal to the product of their laziness level and the task’s difficulty. They are wondering, what is the minimum possible total time they must spend to finish all tasks if they distribute them in the optimal way. Each person should receive one task and each task should be given to one person. Print the answer modulo 10 007. Input The first line of input contains integer n (1 ≤ n ≤ 100 000) — the number of tasks. The next n lines contain exactly one integer number ai (1 ≤ ai ≤ 100 000) — both the difficulty of the initial task and the laziness of the i-th students. Output Print the minimum total time to finish all tasks modulo 10 007. Example Input 2 1 3 Output 6 Note In the first sample, if the students switch their tasks, they will be able to finish them in 3 + 3 = 6 time units.
instruction
0
84,668
14
169,336
Tags: implementation, sortings Correct Solution: ``` n=int(input()) a=[] for i in range(n): a.append(int(input())) a.sort() p1=0 p2=n-1 t=0 while p1<p2: t+=a[p1]*a[p2] p1+=1 p2-=1 t*=2 if n%2==1: t+=a[n//2]**2 print(t%10007) ```
output
1
84,668
14
169,337
Provide tags and a correct Python 3 solution for this coding contest problem. Harry Water, Ronaldo, Her-my-oh-knee and their friends have started a new school year at their MDCS School of Speechcraft and Misery. At the time, they are very happy to have seen each other after a long time. The sun is shining, birds are singing, flowers are blooming, and their Potions class teacher, professor Snipe is sulky as usual. Due to his angst fueled by disappointment in his own life, he has given them a lot of homework in Potions class. Each of the n students has been assigned a single task. Some students do certain tasks faster than others. Thus, they want to redistribute the tasks so that each student still does exactly one task, and that all tasks are finished. Each student has their own laziness level, and each task has its own difficulty level. Professor Snipe is trying hard to improve their work ethics, so each student’s laziness level is equal to their task’s difficulty level. Both sets of values are given by the sequence a, where ai represents both the laziness level of the i-th student and the difficulty of his task. The time a student needs to finish a task is equal to the product of their laziness level and the task’s difficulty. They are wondering, what is the minimum possible total time they must spend to finish all tasks if they distribute them in the optimal way. Each person should receive one task and each task should be given to one person. Print the answer modulo 10 007. Input The first line of input contains integer n (1 ≤ n ≤ 100 000) — the number of tasks. The next n lines contain exactly one integer number ai (1 ≤ ai ≤ 100 000) — both the difficulty of the initial task and the laziness of the i-th students. Output Print the minimum total time to finish all tasks modulo 10 007. Example Input 2 1 3 Output 6 Note In the first sample, if the students switch their tasks, they will be able to finish them in 3 + 3 = 6 time units.
instruction
0
84,669
14
169,338
Tags: implementation, sortings Correct Solution: ``` n=int(input()) a = [] for _ in range(n): a.append(int(input())) a = sorted(a) b = sorted(a, reverse=True) print (sum([i*j for i,j in zip(a,b)]) % 10007) ```
output
1
84,669
14
169,339
Provide tags and a correct Python 3 solution for this coding contest problem. Harry Water, Ronaldo, Her-my-oh-knee and their friends have started a new school year at their MDCS School of Speechcraft and Misery. At the time, they are very happy to have seen each other after a long time. The sun is shining, birds are singing, flowers are blooming, and their Potions class teacher, professor Snipe is sulky as usual. Due to his angst fueled by disappointment in his own life, he has given them a lot of homework in Potions class. Each of the n students has been assigned a single task. Some students do certain tasks faster than others. Thus, they want to redistribute the tasks so that each student still does exactly one task, and that all tasks are finished. Each student has their own laziness level, and each task has its own difficulty level. Professor Snipe is trying hard to improve their work ethics, so each student’s laziness level is equal to their task’s difficulty level. Both sets of values are given by the sequence a, where ai represents both the laziness level of the i-th student and the difficulty of his task. The time a student needs to finish a task is equal to the product of their laziness level and the task’s difficulty. They are wondering, what is the minimum possible total time they must spend to finish all tasks if they distribute them in the optimal way. Each person should receive one task and each task should be given to one person. Print the answer modulo 10 007. Input The first line of input contains integer n (1 ≤ n ≤ 100 000) — the number of tasks. The next n lines contain exactly one integer number ai (1 ≤ ai ≤ 100 000) — both the difficulty of the initial task and the laziness of the i-th students. Output Print the minimum total time to finish all tasks modulo 10 007. Example Input 2 1 3 Output 6 Note In the first sample, if the students switch their tasks, they will be able to finish them in 3 + 3 = 6 time units.
instruction
0
84,670
14
169,340
Tags: implementation, sortings Correct Solution: ``` # link: https://codeforces.com/problemset/problem/717/C from sys import stdin, stdout if __name__ == "__main__": n = int(stdin.readline()) difficulties = [0] * (n) for i in range(n): difficulties[i] = int(stdin.readline()) difficulties.sort() start = 0 end = n-1 result = 0 while start < n: result += (difficulties[start] * difficulties[end]) start += 1 end -= 1 print(result % 10007) ```
output
1
84,670
14
169,341
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Harry Water, Ronaldo, Her-my-oh-knee and their friends have started a new school year at their MDCS School of Speechcraft and Misery. At the time, they are very happy to have seen each other after a long time. The sun is shining, birds are singing, flowers are blooming, and their Potions class teacher, professor Snipe is sulky as usual. Due to his angst fueled by disappointment in his own life, he has given them a lot of homework in Potions class. Each of the n students has been assigned a single task. Some students do certain tasks faster than others. Thus, they want to redistribute the tasks so that each student still does exactly one task, and that all tasks are finished. Each student has their own laziness level, and each task has its own difficulty level. Professor Snipe is trying hard to improve their work ethics, so each student’s laziness level is equal to their task’s difficulty level. Both sets of values are given by the sequence a, where ai represents both the laziness level of the i-th student and the difficulty of his task. The time a student needs to finish a task is equal to the product of their laziness level and the task’s difficulty. They are wondering, what is the minimum possible total time they must spend to finish all tasks if they distribute them in the optimal way. Each person should receive one task and each task should be given to one person. Print the answer modulo 10 007. Input The first line of input contains integer n (1 ≤ n ≤ 100 000) — the number of tasks. The next n lines contain exactly one integer number ai (1 ≤ ai ≤ 100 000) — both the difficulty of the initial task and the laziness of the i-th students. Output Print the minimum total time to finish all tasks modulo 10 007. Example Input 2 1 3 Output 6 Note In the first sample, if the students switch their tasks, they will be able to finish them in 3 + 3 = 6 time units. Submitted Solution: ``` import math from collections import * from heapq import * def intlist(): return list(map(int, input().split())) class Solution: def solve(self): n = int(input()) nums = [0] * n for i in range(n): nums[i] = int(input()) ans = 0 nums.sort() for i in range(n): ans += nums[i] * nums[-(i + 1)] return ans % 10007 aa = Solution() def go(x=1): for _ in range(x): print((aa.solve())) go() ```
instruction
0
84,671
14
169,342
Yes
output
1
84,671
14
169,343
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Harry Water, Ronaldo, Her-my-oh-knee and their friends have started a new school year at their MDCS School of Speechcraft and Misery. At the time, they are very happy to have seen each other after a long time. The sun is shining, birds are singing, flowers are blooming, and their Potions class teacher, professor Snipe is sulky as usual. Due to his angst fueled by disappointment in his own life, he has given them a lot of homework in Potions class. Each of the n students has been assigned a single task. Some students do certain tasks faster than others. Thus, they want to redistribute the tasks so that each student still does exactly one task, and that all tasks are finished. Each student has their own laziness level, and each task has its own difficulty level. Professor Snipe is trying hard to improve their work ethics, so each student’s laziness level is equal to their task’s difficulty level. Both sets of values are given by the sequence a, where ai represents both the laziness level of the i-th student and the difficulty of his task. The time a student needs to finish a task is equal to the product of their laziness level and the task’s difficulty. They are wondering, what is the minimum possible total time they must spend to finish all tasks if they distribute them in the optimal way. Each person should receive one task and each task should be given to one person. Print the answer modulo 10 007. Input The first line of input contains integer n (1 ≤ n ≤ 100 000) — the number of tasks. The next n lines contain exactly one integer number ai (1 ≤ ai ≤ 100 000) — both the difficulty of the initial task and the laziness of the i-th students. Output Print the minimum total time to finish all tasks modulo 10 007. Example Input 2 1 3 Output 6 Note In the first sample, if the students switch their tasks, they will be able to finish them in 3 + 3 = 6 time units. Submitted Solution: ``` n = int(input()) A = [0] * n for i in range(n): per = int(input()) A[i] = per A.sort() answer = 0 for i in range(n): answer = (answer + A[i] * A[n - i - 1]) % 10007 print(answer) ```
instruction
0
84,672
14
169,344
Yes
output
1
84,672
14
169,345
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Harry Water, Ronaldo, Her-my-oh-knee and their friends have started a new school year at their MDCS School of Speechcraft and Misery. At the time, they are very happy to have seen each other after a long time. The sun is shining, birds are singing, flowers are blooming, and their Potions class teacher, professor Snipe is sulky as usual. Due to his angst fueled by disappointment in his own life, he has given them a lot of homework in Potions class. Each of the n students has been assigned a single task. Some students do certain tasks faster than others. Thus, they want to redistribute the tasks so that each student still does exactly one task, and that all tasks are finished. Each student has their own laziness level, and each task has its own difficulty level. Professor Snipe is trying hard to improve their work ethics, so each student’s laziness level is equal to their task’s difficulty level. Both sets of values are given by the sequence a, where ai represents both the laziness level of the i-th student and the difficulty of his task. The time a student needs to finish a task is equal to the product of their laziness level and the task’s difficulty. They are wondering, what is the minimum possible total time they must spend to finish all tasks if they distribute them in the optimal way. Each person should receive one task and each task should be given to one person. Print the answer modulo 10 007. Input The first line of input contains integer n (1 ≤ n ≤ 100 000) — the number of tasks. The next n lines contain exactly one integer number ai (1 ≤ ai ≤ 100 000) — both the difficulty of the initial task and the laziness of the i-th students. Output Print the minimum total time to finish all tasks modulo 10 007. Example Input 2 1 3 Output 6 Note In the first sample, if the students switch their tasks, they will be able to finish them in 3 + 3 = 6 time units. Submitted Solution: ``` n=int(input()) array=[] for i in range(0,n): x=int(input()) array.append(x) array.sort() sum=0 for i in range(0,n): sum=sum+array[i]*array[n-1-i] print(sum%10007) ```
instruction
0
84,674
14
169,348
Yes
output
1
84,674
14
169,349
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Harry Water, Ronaldo, Her-my-oh-knee and their friends have started a new school year at their MDCS School of Speechcraft and Misery. At the time, they are very happy to have seen each other after a long time. The sun is shining, birds are singing, flowers are blooming, and their Potions class teacher, professor Snipe is sulky as usual. Due to his angst fueled by disappointment in his own life, he has given them a lot of homework in Potions class. Each of the n students has been assigned a single task. Some students do certain tasks faster than others. Thus, they want to redistribute the tasks so that each student still does exactly one task, and that all tasks are finished. Each student has their own laziness level, and each task has its own difficulty level. Professor Snipe is trying hard to improve their work ethics, so each student’s laziness level is equal to their task’s difficulty level. Both sets of values are given by the sequence a, where ai represents both the laziness level of the i-th student and the difficulty of his task. The time a student needs to finish a task is equal to the product of their laziness level and the task’s difficulty. They are wondering, what is the minimum possible total time they must spend to finish all tasks if they distribute them in the optimal way. Each person should receive one task and each task should be given to one person. Print the answer modulo 10 007. Input The first line of input contains integer n (1 ≤ n ≤ 100 000) — the number of tasks. The next n lines contain exactly one integer number ai (1 ≤ ai ≤ 100 000) — both the difficulty of the initial task and the laziness of the i-th students. Output Print the minimum total time to finish all tasks modulo 10 007. Example Input 2 1 3 Output 6 Note In the first sample, if the students switch their tasks, they will be able to finish them in 3 + 3 = 6 time units. Submitted Solution: ``` n = int(input()) sp = [] for i in range(n): sp.append(int(input())) sp.sort() sp1 = sp[::-1] s = 0 for i in range(n): s = s + sp[i] * sp1[i] print(s) ```
instruction
0
84,675
14
169,350
No
output
1
84,675
14
169,351
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Harry Water, Ronaldo, Her-my-oh-knee and their friends have started a new school year at their MDCS School of Speechcraft and Misery. At the time, they are very happy to have seen each other after a long time. The sun is shining, birds are singing, flowers are blooming, and their Potions class teacher, professor Snipe is sulky as usual. Due to his angst fueled by disappointment in his own life, he has given them a lot of homework in Potions class. Each of the n students has been assigned a single task. Some students do certain tasks faster than others. Thus, they want to redistribute the tasks so that each student still does exactly one task, and that all tasks are finished. Each student has their own laziness level, and each task has its own difficulty level. Professor Snipe is trying hard to improve their work ethics, so each student’s laziness level is equal to their task’s difficulty level. Both sets of values are given by the sequence a, where ai represents both the laziness level of the i-th student and the difficulty of his task. The time a student needs to finish a task is equal to the product of their laziness level and the task’s difficulty. They are wondering, what is the minimum possible total time they must spend to finish all tasks if they distribute them in the optimal way. Each person should receive one task and each task should be given to one person. Print the answer modulo 10 007. Input The first line of input contains integer n (1 ≤ n ≤ 100 000) — the number of tasks. The next n lines contain exactly one integer number ai (1 ≤ ai ≤ 100 000) — both the difficulty of the initial task and the laziness of the i-th students. Output Print the minimum total time to finish all tasks modulo 10 007. Example Input 2 1 3 Output 6 Note In the first sample, if the students switch their tasks, they will be able to finish them in 3 + 3 = 6 time units. Submitted Solution: ``` import sys input = sys.stdin.readline n = int(input()) tasks = [] for i in range(n): tasks.append(int(input())) tasks.sort() time = 0 for i in range(n//2): time+=(tasks[i]*tasks[-(i+1)]*2) print(time) ```
instruction
0
84,676
14
169,352
No
output
1
84,676
14
169,353
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Harry Water, Ronaldo, Her-my-oh-knee and their friends have started a new school year at their MDCS School of Speechcraft and Misery. At the time, they are very happy to have seen each other after a long time. The sun is shining, birds are singing, flowers are blooming, and their Potions class teacher, professor Snipe is sulky as usual. Due to his angst fueled by disappointment in his own life, he has given them a lot of homework in Potions class. Each of the n students has been assigned a single task. Some students do certain tasks faster than others. Thus, they want to redistribute the tasks so that each student still does exactly one task, and that all tasks are finished. Each student has their own laziness level, and each task has its own difficulty level. Professor Snipe is trying hard to improve their work ethics, so each student’s laziness level is equal to their task’s difficulty level. Both sets of values are given by the sequence a, where ai represents both the laziness level of the i-th student and the difficulty of his task. The time a student needs to finish a task is equal to the product of their laziness level and the task’s difficulty. They are wondering, what is the minimum possible total time they must spend to finish all tasks if they distribute them in the optimal way. Each person should receive one task and each task should be given to one person. Print the answer modulo 10 007. Input The first line of input contains integer n (1 ≤ n ≤ 100 000) — the number of tasks. The next n lines contain exactly one integer number ai (1 ≤ ai ≤ 100 000) — both the difficulty of the initial task and the laziness of the i-th students. Output Print the minimum total time to finish all tasks modulo 10 007. Example Input 2 1 3 Output 6 Note In the first sample, if the students switch their tasks, they will be able to finish them in 3 + 3 = 6 time units. Submitted Solution: ``` n=int(input()) a = [] for _ in range(n): a.append(int(input())) a = sorted(a) b = sorted(a, reverse=True) print (sum([i*j for i,j in zip(a,b)])) ```
instruction
0
84,677
14
169,354
No
output
1
84,677
14
169,355
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Harry Water, Ronaldo, Her-my-oh-knee and their friends have started a new school year at their MDCS School of Speechcraft and Misery. At the time, they are very happy to have seen each other after a long time. The sun is shining, birds are singing, flowers are blooming, and their Potions class teacher, professor Snipe is sulky as usual. Due to his angst fueled by disappointment in his own life, he has given them a lot of homework in Potions class. Each of the n students has been assigned a single task. Some students do certain tasks faster than others. Thus, they want to redistribute the tasks so that each student still does exactly one task, and that all tasks are finished. Each student has their own laziness level, and each task has its own difficulty level. Professor Snipe is trying hard to improve their work ethics, so each student’s laziness level is equal to their task’s difficulty level. Both sets of values are given by the sequence a, where ai represents both the laziness level of the i-th student and the difficulty of his task. The time a student needs to finish a task is equal to the product of their laziness level and the task’s difficulty. They are wondering, what is the minimum possible total time they must spend to finish all tasks if they distribute them in the optimal way. Each person should receive one task and each task should be given to one person. Print the answer modulo 10 007. Input The first line of input contains integer n (1 ≤ n ≤ 100 000) — the number of tasks. The next n lines contain exactly one integer number ai (1 ≤ ai ≤ 100 000) — both the difficulty of the initial task and the laziness of the i-th students. Output Print the minimum total time to finish all tasks modulo 10 007. Example Input 2 1 3 Output 6 Note In the first sample, if the students switch their tasks, they will be able to finish them in 3 + 3 = 6 time units. Submitted Solution: ``` import sys import string from heapq import * from bisect import * from collections import Counter, defaultdict from math import fsum, sqrt, gcd, ceil, factorial from operator import * from itertools import accumulate inf = float("inf") # input = sys.stdin.readline flush = lambda: sys.stdout.flush comb = lambda x, y: (factorial(x) // factorial(y)) // factorial(x - y) en = lambda x: list(enumerate(x)) # inputs # ip = lambda : input().rstrip() ip = lambda: input() ii = lambda: int(input()) r = lambda: map(int, input().split()) rr = lambda: list(r()) n = ii() arr = [ii() for _ in range(n)] c = 0 for i in range(n): c = c + arr[i] * arr[n - i - 1] print(c % 10007) ```
instruction
0
84,678
14
169,356
No
output
1
84,678
14
169,357
Provide tags and a correct Python 3 solution for this coding contest problem. Imp likes his plush toy a lot. <image> Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies. Initially, Imp has only one original toy. He wants to know if it is possible to use machine to get exactly x copied toys and y original toys? He can't throw toys away, and he can't apply the machine to a copy if he doesn't currently have any copies. Input The only line contains two integers x and y (0 ≤ x, y ≤ 109) — the number of copies and the number of original toys Imp wants to get (including the initial one). Output Print "Yes", if the desired configuration is possible, and "No" otherwise. You can print each letter in arbitrary case (upper or lower). Examples Input 6 3 Output Yes Input 4 2 Output No Input 1000 1001 Output Yes Note In the first example, Imp has to apply the machine twice to original toys and then twice to copies.
instruction
0
84,750
14
169,500
Tags: implementation Correct Solution: ``` x, y = list(map(int, input().split())) if x < y - 1 or (x - y - 1) % 2 != 0 or (y == 1 and x != 0) or y == 0: print("NO") else: print("YES") ```
output
1
84,750
14
169,501
Provide tags and a correct Python 3 solution for this coding contest problem. Imp likes his plush toy a lot. <image> Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies. Initially, Imp has only one original toy. He wants to know if it is possible to use machine to get exactly x copied toys and y original toys? He can't throw toys away, and he can't apply the machine to a copy if he doesn't currently have any copies. Input The only line contains two integers x and y (0 ≤ x, y ≤ 109) — the number of copies and the number of original toys Imp wants to get (including the initial one). Output Print "Yes", if the desired configuration is possible, and "No" otherwise. You can print each letter in arbitrary case (upper or lower). Examples Input 6 3 Output Yes Input 4 2 Output No Input 1000 1001 Output Yes Note In the first example, Imp has to apply the machine twice to original toys and then twice to copies.
instruction
0
84,751
14
169,502
Tags: implementation Correct Solution: ``` x,y = map(int, input().split()) if y > 0 and x >= 0: if (y == 1 and x > 0) or x == y: print('No') elif y == 1 and x == 0 : print('Yes') elif x < y and y > 1: if x == y - 1: print('Yes') else: print('No') elif x > y: x -= y - 1 if x % 2 == 0: print('Yes') else: print('No') else: print('No') ```
output
1
84,751
14
169,503