message
stringlengths
2
43.5k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
853
107k
cluster
float64
24
24
__index_level_0__
int64
1.71k
214k
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This problem uses a simplified network topology model, please read the problem statement carefully and use it as a formal document as you develop the solution. Polycarpus continues working as a system administrator in a large corporation. The computer network of this corporation consists of n computers, some of them are connected by a cable. The computers are indexed by integers from 1 to n. It's known that any two computers connected by cable directly or through other computers Polycarpus decided to find out the network's topology. A network topology is the way of describing the network configuration, the scheme that shows the location and the connections of network devices. Polycarpus knows three main network topologies: bus, ring and star. A bus is the topology that represents a shared cable with all computers connected with it. In the ring topology the cable connects each computer only with two other ones. A star is the topology where all computers of a network are connected to the single central node. Let's represent each of these network topologies as a connected non-directed graph. A bus is a connected graph that is the only path, that is, the graph where all nodes are connected with two other ones except for some two nodes that are the beginning and the end of the path. A ring is a connected graph, where all nodes are connected with two other ones. A star is a connected graph, where a single central node is singled out and connected with all other nodes. For clarifications, see the picture. <image> (1) — bus, (2) — ring, (3) — star You've got a connected non-directed graph that characterizes the computer network in Polycarpus' corporation. Help him find out, which topology type the given network is. If that is impossible to do, say that the network's topology is unknown. Input The first line contains two space-separated integers n and m (4 ≤ n ≤ 105; 3 ≤ m ≤ 105) — the number of nodes and edges in the graph, correspondingly. Next m lines contain the description of the graph's edges. The i-th line contains a space-separated pair of integers xi, yi (1 ≤ xi, yi ≤ n) — the numbers of nodes that are connected by the i-the edge. It is guaranteed that the given graph is connected. There is at most one edge between any two nodes. No edge connects a node with itself. Output In a single line print the network topology name of the given graph. If the answer is the bus, print "bus topology" (without the quotes), if the answer is the ring, print "ring topology" (without the quotes), if the answer is the star, print "star topology" (without the quotes). If no answer fits, print "unknown topology" (without the quotes). Examples Input 4 3 1 2 2 3 3 4 Output bus topology Input 4 4 1 2 2 3 3 4 4 1 Output ring topology Input 4 3 1 2 1 3 1 4 Output star topology Input 4 4 1 2 2 3 3 1 1 4 Output unknown topology Submitted Solution: ``` n,m = map(int, input().split()) adj = [[] for i in range(n+1)] for i in range(m): a,b = map(int, input().split()) adj[a].append(b) adj[b].append(a) edgeCount = [0] for i in range(1,n+1): edgeCount.append(len(adj[i])) edgeCountCount = [0 for i in range(n+1)] for i in edgeCount: edgeCountCount[i] += 1 if edgeCountCount[1] == 2 and edgeCountCount[2] == n-2: print('bus topology') elif edgeCountCount[2] == m: print('ring topology') elif edgeCountCount[1] == m and edgeCountCount[m] == 1: print('star topology') else: print('unknown topology') ```
instruction
0
90,445
24
180,890
Yes
output
1
90,445
24
180,891
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This problem uses a simplified network topology model, please read the problem statement carefully and use it as a formal document as you develop the solution. Polycarpus continues working as a system administrator in a large corporation. The computer network of this corporation consists of n computers, some of them are connected by a cable. The computers are indexed by integers from 1 to n. It's known that any two computers connected by cable directly or through other computers Polycarpus decided to find out the network's topology. A network topology is the way of describing the network configuration, the scheme that shows the location and the connections of network devices. Polycarpus knows three main network topologies: bus, ring and star. A bus is the topology that represents a shared cable with all computers connected with it. In the ring topology the cable connects each computer only with two other ones. A star is the topology where all computers of a network are connected to the single central node. Let's represent each of these network topologies as a connected non-directed graph. A bus is a connected graph that is the only path, that is, the graph where all nodes are connected with two other ones except for some two nodes that are the beginning and the end of the path. A ring is a connected graph, where all nodes are connected with two other ones. A star is a connected graph, where a single central node is singled out and connected with all other nodes. For clarifications, see the picture. <image> (1) — bus, (2) — ring, (3) — star You've got a connected non-directed graph that characterizes the computer network in Polycarpus' corporation. Help him find out, which topology type the given network is. If that is impossible to do, say that the network's topology is unknown. Input The first line contains two space-separated integers n and m (4 ≤ n ≤ 105; 3 ≤ m ≤ 105) — the number of nodes and edges in the graph, correspondingly. Next m lines contain the description of the graph's edges. The i-th line contains a space-separated pair of integers xi, yi (1 ≤ xi, yi ≤ n) — the numbers of nodes that are connected by the i-the edge. It is guaranteed that the given graph is connected. There is at most one edge between any two nodes. No edge connects a node with itself. Output In a single line print the network topology name of the given graph. If the answer is the bus, print "bus topology" (without the quotes), if the answer is the ring, print "ring topology" (without the quotes), if the answer is the star, print "star topology" (without the quotes). If no answer fits, print "unknown topology" (without the quotes). Examples Input 4 3 1 2 2 3 3 4 Output bus topology Input 4 4 1 2 2 3 3 4 4 1 Output ring topology Input 4 3 1 2 1 3 1 4 Output star topology Input 4 4 1 2 2 3 3 1 1 4 Output unknown topology Submitted Solution: ``` n,m=map(int,input().split()) graph={} for i in range(1,n+1): graph[i]=[] for i in range(m): u,v=map(int,input().split()) graph[u].append(v) graph[v].append(u) c=0 d=0 #print(graph) for i in range(1,n+1): if len(graph[i])==1: c=c+1 elif len(graph[i])>=2: d=d+1 if m==n-1 and c==2 and d==n-2: print("bus topology") elif c==0 and d==n and m==n: print("ring topology") elif c==n-1 and d==1: print("star topology") else: print("unknown topology") ```
instruction
0
90,446
24
180,892
Yes
output
1
90,446
24
180,893
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This problem uses a simplified network topology model, please read the problem statement carefully and use it as a formal document as you develop the solution. Polycarpus continues working as a system administrator in a large corporation. The computer network of this corporation consists of n computers, some of them are connected by a cable. The computers are indexed by integers from 1 to n. It's known that any two computers connected by cable directly or through other computers Polycarpus decided to find out the network's topology. A network topology is the way of describing the network configuration, the scheme that shows the location and the connections of network devices. Polycarpus knows three main network topologies: bus, ring and star. A bus is the topology that represents a shared cable with all computers connected with it. In the ring topology the cable connects each computer only with two other ones. A star is the topology where all computers of a network are connected to the single central node. Let's represent each of these network topologies as a connected non-directed graph. A bus is a connected graph that is the only path, that is, the graph where all nodes are connected with two other ones except for some two nodes that are the beginning and the end of the path. A ring is a connected graph, where all nodes are connected with two other ones. A star is a connected graph, where a single central node is singled out and connected with all other nodes. For clarifications, see the picture. <image> (1) — bus, (2) — ring, (3) — star You've got a connected non-directed graph that characterizes the computer network in Polycarpus' corporation. Help him find out, which topology type the given network is. If that is impossible to do, say that the network's topology is unknown. Input The first line contains two space-separated integers n and m (4 ≤ n ≤ 105; 3 ≤ m ≤ 105) — the number of nodes and edges in the graph, correspondingly. Next m lines contain the description of the graph's edges. The i-th line contains a space-separated pair of integers xi, yi (1 ≤ xi, yi ≤ n) — the numbers of nodes that are connected by the i-the edge. It is guaranteed that the given graph is connected. There is at most one edge between any two nodes. No edge connects a node with itself. Output In a single line print the network topology name of the given graph. If the answer is the bus, print "bus topology" (without the quotes), if the answer is the ring, print "ring topology" (without the quotes), if the answer is the star, print "star topology" (without the quotes). If no answer fits, print "unknown topology" (without the quotes). Examples Input 4 3 1 2 2 3 3 4 Output bus topology Input 4 4 1 2 2 3 3 4 4 1 Output ring topology Input 4 3 1 2 1 3 1 4 Output star topology Input 4 4 1 2 2 3 3 1 1 4 Output unknown topology Submitted Solution: ``` from collections import defaultdict I = lambda: list(map(int, input().split())) degrees = defaultdict(int) for _ in range(I()[1]): u, v = I() degrees[u] += 1 degrees[v] += 1 values = set(degrees.values()) if values == {1, 2}: print('bus topology') elif values == {2}: print('ring topology') elif len(values) == 2 and 1 in values: print('star topology') else: print('unknown topology') ```
instruction
0
90,447
24
180,894
No
output
1
90,447
24
180,895
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This problem uses a simplified network topology model, please read the problem statement carefully and use it as a formal document as you develop the solution. Polycarpus continues working as a system administrator in a large corporation. The computer network of this corporation consists of n computers, some of them are connected by a cable. The computers are indexed by integers from 1 to n. It's known that any two computers connected by cable directly or through other computers Polycarpus decided to find out the network's topology. A network topology is the way of describing the network configuration, the scheme that shows the location and the connections of network devices. Polycarpus knows three main network topologies: bus, ring and star. A bus is the topology that represents a shared cable with all computers connected with it. In the ring topology the cable connects each computer only with two other ones. A star is the topology where all computers of a network are connected to the single central node. Let's represent each of these network topologies as a connected non-directed graph. A bus is a connected graph that is the only path, that is, the graph where all nodes are connected with two other ones except for some two nodes that are the beginning and the end of the path. A ring is a connected graph, where all nodes are connected with two other ones. A star is a connected graph, where a single central node is singled out and connected with all other nodes. For clarifications, see the picture. <image> (1) — bus, (2) — ring, (3) — star You've got a connected non-directed graph that characterizes the computer network in Polycarpus' corporation. Help him find out, which topology type the given network is. If that is impossible to do, say that the network's topology is unknown. Input The first line contains two space-separated integers n and m (4 ≤ n ≤ 105; 3 ≤ m ≤ 105) — the number of nodes and edges in the graph, correspondingly. Next m lines contain the description of the graph's edges. The i-th line contains a space-separated pair of integers xi, yi (1 ≤ xi, yi ≤ n) — the numbers of nodes that are connected by the i-the edge. It is guaranteed that the given graph is connected. There is at most one edge between any two nodes. No edge connects a node with itself. Output In a single line print the network topology name of the given graph. If the answer is the bus, print "bus topology" (without the quotes), if the answer is the ring, print "ring topology" (without the quotes), if the answer is the star, print "star topology" (without the quotes). If no answer fits, print "unknown topology" (without the quotes). Examples Input 4 3 1 2 2 3 3 4 Output bus topology Input 4 4 1 2 2 3 3 4 4 1 Output ring topology Input 4 3 1 2 1 3 1 4 Output star topology Input 4 4 1 2 2 3 3 1 1 4 Output unknown topology Submitted Solution: ``` from collections import defaultdict n, m = map(int, input().split()) h = defaultdict(set) nums = [0] * n for i in range(m): u, v = map(int, input().split()) h[u].add(v) h[v].add(u) full = 0 one = 0 two = 0 for key, value in h.items(): if len(value) == n - 1: full += 1 if len(value) == 1: one += 1 if len(value) == 2: two += 1 if full == 1 and full + one == n: print('star topology') elif two == n: print('ring topology') elif two == n - 2 and one == 2: print('bus topology') else: print('unkown topology') ```
instruction
0
90,448
24
180,896
No
output
1
90,448
24
180,897
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This problem uses a simplified network topology model, please read the problem statement carefully and use it as a formal document as you develop the solution. Polycarpus continues working as a system administrator in a large corporation. The computer network of this corporation consists of n computers, some of them are connected by a cable. The computers are indexed by integers from 1 to n. It's known that any two computers connected by cable directly or through other computers Polycarpus decided to find out the network's topology. A network topology is the way of describing the network configuration, the scheme that shows the location and the connections of network devices. Polycarpus knows three main network topologies: bus, ring and star. A bus is the topology that represents a shared cable with all computers connected with it. In the ring topology the cable connects each computer only with two other ones. A star is the topology where all computers of a network are connected to the single central node. Let's represent each of these network topologies as a connected non-directed graph. A bus is a connected graph that is the only path, that is, the graph where all nodes are connected with two other ones except for some two nodes that are the beginning and the end of the path. A ring is a connected graph, where all nodes are connected with two other ones. A star is a connected graph, where a single central node is singled out and connected with all other nodes. For clarifications, see the picture. <image> (1) — bus, (2) — ring, (3) — star You've got a connected non-directed graph that characterizes the computer network in Polycarpus' corporation. Help him find out, which topology type the given network is. If that is impossible to do, say that the network's topology is unknown. Input The first line contains two space-separated integers n and m (4 ≤ n ≤ 105; 3 ≤ m ≤ 105) — the number of nodes and edges in the graph, correspondingly. Next m lines contain the description of the graph's edges. The i-th line contains a space-separated pair of integers xi, yi (1 ≤ xi, yi ≤ n) — the numbers of nodes that are connected by the i-the edge. It is guaranteed that the given graph is connected. There is at most one edge between any two nodes. No edge connects a node with itself. Output In a single line print the network topology name of the given graph. If the answer is the bus, print "bus topology" (without the quotes), if the answer is the ring, print "ring topology" (without the quotes), if the answer is the star, print "star topology" (without the quotes). If no answer fits, print "unknown topology" (without the quotes). Examples Input 4 3 1 2 2 3 3 4 Output bus topology Input 4 4 1 2 2 3 3 4 4 1 Output ring topology Input 4 3 1 2 1 3 1 4 Output star topology Input 4 4 1 2 2 3 3 1 1 4 Output unknown topology Submitted Solution: ``` n, m = [int(i) for i in input().split()] nodes = [] edges = [] x = 0 for i in range(m): nums = [int(i) for i in input().split()] nodes.append(nums[0]) edges.append(nums[1]) if sum(nodes) == len(nodes): print('star topology') elif sum(nodes) == sum(edges): print('ring topology') elif x == 0: for i in range(m): if nodes[i] + 1 == edges[i]: x += 1 if x == m: print('bus topology') else: print('unknown topology') ```
instruction
0
90,449
24
180,898
No
output
1
90,449
24
180,899
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This problem uses a simplified network topology model, please read the problem statement carefully and use it as a formal document as you develop the solution. Polycarpus continues working as a system administrator in a large corporation. The computer network of this corporation consists of n computers, some of them are connected by a cable. The computers are indexed by integers from 1 to n. It's known that any two computers connected by cable directly or through other computers Polycarpus decided to find out the network's topology. A network topology is the way of describing the network configuration, the scheme that shows the location and the connections of network devices. Polycarpus knows three main network topologies: bus, ring and star. A bus is the topology that represents a shared cable with all computers connected with it. In the ring topology the cable connects each computer only with two other ones. A star is the topology where all computers of a network are connected to the single central node. Let's represent each of these network topologies as a connected non-directed graph. A bus is a connected graph that is the only path, that is, the graph where all nodes are connected with two other ones except for some two nodes that are the beginning and the end of the path. A ring is a connected graph, where all nodes are connected with two other ones. A star is a connected graph, where a single central node is singled out and connected with all other nodes. For clarifications, see the picture. <image> (1) — bus, (2) — ring, (3) — star You've got a connected non-directed graph that characterizes the computer network in Polycarpus' corporation. Help him find out, which topology type the given network is. If that is impossible to do, say that the network's topology is unknown. Input The first line contains two space-separated integers n and m (4 ≤ n ≤ 105; 3 ≤ m ≤ 105) — the number of nodes and edges in the graph, correspondingly. Next m lines contain the description of the graph's edges. The i-th line contains a space-separated pair of integers xi, yi (1 ≤ xi, yi ≤ n) — the numbers of nodes that are connected by the i-the edge. It is guaranteed that the given graph is connected. There is at most one edge between any two nodes. No edge connects a node with itself. Output In a single line print the network topology name of the given graph. If the answer is the bus, print "bus topology" (without the quotes), if the answer is the ring, print "ring topology" (without the quotes), if the answer is the star, print "star topology" (without the quotes). If no answer fits, print "unknown topology" (without the quotes). Examples Input 4 3 1 2 2 3 3 4 Output bus topology Input 4 4 1 2 2 3 3 4 4 1 Output ring topology Input 4 3 1 2 1 3 1 4 Output star topology Input 4 4 1 2 2 3 3 1 1 4 Output unknown topology Submitted Solution: ``` n, m = map(int, input().split()) s = [set() for _ in range(n+1)] for _ in range(m): a, b = map(int, input().split()) s[a].add(b) s[b].add(a) x = set() for i in range(1, n+1): if len(s[i]) == 1: x.add(i) if len(x) == 0: print("ring topology") elif x == {1, n}: print("bus topology") elif len(x) == m: print("star topology") else: print("unknown topology") ```
instruction
0
90,450
24
180,900
No
output
1
90,450
24
180,901
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp invited all his friends to the tea party to celebrate the holiday. He has n cups, one for each of his n friends, with volumes a1, a2, ..., an. His teapot stores w milliliters of tea (w ≤ a1 + a2 + ... + an). Polycarp wants to pour tea in cups in such a way that: * Every cup will contain tea for at least half of its volume * Every cup will contain integer number of milliliters of tea * All the tea from the teapot will be poured into cups * All friends will be satisfied. Friend with cup i won't be satisfied, if there exists such cup j that cup i contains less tea than cup j but ai > aj. For each cup output how many milliliters of tea should be poured in it. If it's impossible to pour all the tea and satisfy all conditions then output -1. Input The first line contains two integer numbers n and w (1 ≤ n ≤ 100, <image>). The second line contains n numbers a1, a2, ..., an (1 ≤ ai ≤ 100). Output Output how many milliliters of tea every cup should contain. If there are multiple answers, print any of them. If it's impossible to pour all the tea and satisfy all conditions then output -1. Examples Input 2 10 8 7 Output 6 4 Input 4 4 1 1 1 1 Output 1 1 1 1 Input 3 10 9 8 10 Output -1 Note In the third example you should pour to the first cup at least 5 milliliters, to the second one at least 4, to the third one at least 5. It sums up to 14, which is greater than 10 milliliters available.
instruction
0
91,349
24
182,698
Tags: constructive algorithms, greedy, sortings Correct Solution: ``` #!/usr/bin/env python3 [n, w] = map(int, input().strip().split()) ais = list(map(int, input().strip().split())) ni = list(range(n)) ni.sort(key=lambda i: ais[i], reverse=True) vis = [-((-a) // 2) for a in ais] # ceil s = sum(vis) if s > w: print (-1) else: w -= s for i in ni: d = ais[i] - vis[i] d = min(d, w) vis[i] += d w -= d if w == 0: break print (' '.join(map(str, vis))) ```
output
1
91,349
24
182,699
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp invited all his friends to the tea party to celebrate the holiday. He has n cups, one for each of his n friends, with volumes a1, a2, ..., an. His teapot stores w milliliters of tea (w ≤ a1 + a2 + ... + an). Polycarp wants to pour tea in cups in such a way that: * Every cup will contain tea for at least half of its volume * Every cup will contain integer number of milliliters of tea * All the tea from the teapot will be poured into cups * All friends will be satisfied. Friend with cup i won't be satisfied, if there exists such cup j that cup i contains less tea than cup j but ai > aj. For each cup output how many milliliters of tea should be poured in it. If it's impossible to pour all the tea and satisfy all conditions then output -1. Input The first line contains two integer numbers n and w (1 ≤ n ≤ 100, <image>). The second line contains n numbers a1, a2, ..., an (1 ≤ ai ≤ 100). Output Output how many milliliters of tea every cup should contain. If there are multiple answers, print any of them. If it's impossible to pour all the tea and satisfy all conditions then output -1. Examples Input 2 10 8 7 Output 6 4 Input 4 4 1 1 1 1 Output 1 1 1 1 Input 3 10 9 8 10 Output -1 Note In the third example you should pour to the first cup at least 5 milliliters, to the second one at least 4, to the third one at least 5. It sums up to 14, which is greater than 10 milliliters available.
instruction
0
91,350
24
182,700
Tags: constructive algorithms, greedy, sortings Correct Solution: ``` from collections import deque import math n,k=map(int,input().split()) arr=list(map(int,input().split())) q=deque() v=[False]*n for i in range(n): var=int(math.ceil(arr[i]/2)) if k>=var: q.append(var) k-=var else: print(-1) exit() #print(q) for _ in range(n): m=0 ind=0 for i in range(n): if v[i]==True: continue else: if arr[i]>m: ind=i m = max(m, arr[i]) v[ind] = True if k>=(arr[ind]-q[ind]): k-=arr[ind]-q[ind] q[ind]=arr[ind] #print(q) else: q[ind]+=k print(*q) exit() print(*q) ```
output
1
91,350
24
182,701
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp invited all his friends to the tea party to celebrate the holiday. He has n cups, one for each of his n friends, with volumes a1, a2, ..., an. His teapot stores w milliliters of tea (w ≤ a1 + a2 + ... + an). Polycarp wants to pour tea in cups in such a way that: * Every cup will contain tea for at least half of its volume * Every cup will contain integer number of milliliters of tea * All the tea from the teapot will be poured into cups * All friends will be satisfied. Friend with cup i won't be satisfied, if there exists such cup j that cup i contains less tea than cup j but ai > aj. For each cup output how many milliliters of tea should be poured in it. If it's impossible to pour all the tea and satisfy all conditions then output -1. Input The first line contains two integer numbers n and w (1 ≤ n ≤ 100, <image>). The second line contains n numbers a1, a2, ..., an (1 ≤ ai ≤ 100). Output Output how many milliliters of tea every cup should contain. If there are multiple answers, print any of them. If it's impossible to pour all the tea and satisfy all conditions then output -1. Examples Input 2 10 8 7 Output 6 4 Input 4 4 1 1 1 1 Output 1 1 1 1 Input 3 10 9 8 10 Output -1 Note In the third example you should pour to the first cup at least 5 milliliters, to the second one at least 4, to the third one at least 5. It sums up to 14, which is greater than 10 milliliters available.
instruction
0
91,351
24
182,702
Tags: constructive algorithms, greedy, sortings Correct Solution: ``` n, w = [int(x) for x in input().split()] a = [int(x) for x in input().split()] a_index = [(x, i) for i, x in enumerate(a)] a_index.sort(reverse=True) res = [0] * len(a) for x, i in a_index: need = (x+1) // 2 res[i] = need w -= need if w < 0: print(-1) exit(0) if w > 0: for x, i in a_index: if w == 0: break need = min(w, x-res[i]) res[i] += need w -= need print(res[0], end="") for i in range(1, len(res)): print(" " + str(res[i]), end="") print() ```
output
1
91,351
24
182,703
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp invited all his friends to the tea party to celebrate the holiday. He has n cups, one for each of his n friends, with volumes a1, a2, ..., an. His teapot stores w milliliters of tea (w ≤ a1 + a2 + ... + an). Polycarp wants to pour tea in cups in such a way that: * Every cup will contain tea for at least half of its volume * Every cup will contain integer number of milliliters of tea * All the tea from the teapot will be poured into cups * All friends will be satisfied. Friend with cup i won't be satisfied, if there exists such cup j that cup i contains less tea than cup j but ai > aj. For each cup output how many milliliters of tea should be poured in it. If it's impossible to pour all the tea and satisfy all conditions then output -1. Input The first line contains two integer numbers n and w (1 ≤ n ≤ 100, <image>). The second line contains n numbers a1, a2, ..., an (1 ≤ ai ≤ 100). Output Output how many milliliters of tea every cup should contain. If there are multiple answers, print any of them. If it's impossible to pour all the tea and satisfy all conditions then output -1. Examples Input 2 10 8 7 Output 6 4 Input 4 4 1 1 1 1 Output 1 1 1 1 Input 3 10 9 8 10 Output -1 Note In the third example you should pour to the first cup at least 5 milliliters, to the second one at least 4, to the third one at least 5. It sums up to 14, which is greater than 10 milliliters available.
instruction
0
91,352
24
182,704
Tags: constructive algorithms, greedy, sortings Correct Solution: ``` from sys import stdin, stdout from math import ceil n, w = map(int, stdin.readline().split()) values = list(map(int, stdin.readline().split())) fill = [0 for i in range(n)] for i in range(n): values[i] = (values[i], i) values.sort() label = 1 for i in range(n - 1, -1, -1): if ceil(values[i][0] / 2) <= w: fill[i] = ceil(values[i][0] / 2) w -= ceil(values[i][0] / 2) else: label = 0 if not label: stdout.write(str('-1')) else: for i in range(n - 1, -1, -1): cnt = min(w, values[i][0] - fill[i]) fill[i] += min(w, values[i][0] - fill[i]) w -= cnt ans = [0 for i in range(n)] if w: stdout.write('-1') else: for i in range(n): ans[values[i][1]] = fill[i] stdout.write(' '.join(list(map(str, ans)))) ```
output
1
91,352
24
182,705
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp invited all his friends to the tea party to celebrate the holiday. He has n cups, one for each of his n friends, with volumes a1, a2, ..., an. His teapot stores w milliliters of tea (w ≤ a1 + a2 + ... + an). Polycarp wants to pour tea in cups in such a way that: * Every cup will contain tea for at least half of its volume * Every cup will contain integer number of milliliters of tea * All the tea from the teapot will be poured into cups * All friends will be satisfied. Friend with cup i won't be satisfied, if there exists such cup j that cup i contains less tea than cup j but ai > aj. For each cup output how many milliliters of tea should be poured in it. If it's impossible to pour all the tea and satisfy all conditions then output -1. Input The first line contains two integer numbers n and w (1 ≤ n ≤ 100, <image>). The second line contains n numbers a1, a2, ..., an (1 ≤ ai ≤ 100). Output Output how many milliliters of tea every cup should contain. If there are multiple answers, print any of them. If it's impossible to pour all the tea and satisfy all conditions then output -1. Examples Input 2 10 8 7 Output 6 4 Input 4 4 1 1 1 1 Output 1 1 1 1 Input 3 10 9 8 10 Output -1 Note In the third example you should pour to the first cup at least 5 milliliters, to the second one at least 4, to the third one at least 5. It sums up to 14, which is greater than 10 milliliters available.
instruction
0
91,353
24
182,706
Tags: constructive algorithms, greedy, sortings Correct Solution: ``` desc = input().split() num = int(desc[0]) w = int(desc[1]) cups = list(map(int, input().split())) halfsums = 0 resmilk = [] maxel = cups[0] maxin = 0 maxls = [] for i in range(num): if cups[i] > maxel: maxel = cups[i] maxin = i if cups[i] % 2 == 0: thiscup = cups[i]//2 else: thiscup = (cups[i]//2) + 1 halfsums += thiscup resmilk.append(thiscup) if halfsums > w: print(-1) else: while(halfsums != w): if cups[maxin] - resmilk[maxin] < w - halfsums: halfsums += cups[maxin] - resmilk[maxin] resmilk[maxin] = cups[maxin] maxls.append(maxin) for i in range(num): if i not in maxls: maxin = i maxel = cups[i] break for i in range(num): if i not in maxls and cups[i] > maxel: maxin = i maxel = cups[i] else: resmilk[maxin] += w - halfsums halfsums = w for e in resmilk: print(e, end=' ') ```
output
1
91,353
24
182,707
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp invited all his friends to the tea party to celebrate the holiday. He has n cups, one for each of his n friends, with volumes a1, a2, ..., an. His teapot stores w milliliters of tea (w ≤ a1 + a2 + ... + an). Polycarp wants to pour tea in cups in such a way that: * Every cup will contain tea for at least half of its volume * Every cup will contain integer number of milliliters of tea * All the tea from the teapot will be poured into cups * All friends will be satisfied. Friend with cup i won't be satisfied, if there exists such cup j that cup i contains less tea than cup j but ai > aj. For each cup output how many milliliters of tea should be poured in it. If it's impossible to pour all the tea and satisfy all conditions then output -1. Input The first line contains two integer numbers n and w (1 ≤ n ≤ 100, <image>). The second line contains n numbers a1, a2, ..., an (1 ≤ ai ≤ 100). Output Output how many milliliters of tea every cup should contain. If there are multiple answers, print any of them. If it's impossible to pour all the tea and satisfy all conditions then output -1. Examples Input 2 10 8 7 Output 6 4 Input 4 4 1 1 1 1 Output 1 1 1 1 Input 3 10 9 8 10 Output -1 Note In the third example you should pour to the first cup at least 5 milliliters, to the second one at least 4, to the third one at least 5. It sums up to 14, which is greater than 10 milliliters available.
instruction
0
91,354
24
182,708
Tags: constructive algorithms, greedy, sortings Correct Solution: ``` #Mamma don't raises quitter................................................. from collections import deque as de import math from math import sqrt as sq from math import floor as fl from math import ceil as ce from sys import stdin, stdout import re from collections import Counter as cnt from functools import reduce from itertools import groupby as gb #from fractions import Fraction as fr from bisect import bisect_left as bl, bisect_right as br def factors(n): return set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0))) class My_stack(): def __init__(self): self.data = [] def my_push(self, x): return (self.data.append(x)) def my_pop(self): return (self.data.pop()) def my_peak(self): return (self.data[-1]) def my_contains(self, x): return (self.data.count(x)) def my_show_all(self): return (self.data) def isEmpty(self): return len(self.data)==0 arrStack = My_stack() #decimal to binary def decimalToBinary(n): return bin(n).replace("0b", "") #binary to decimal def binarytodecimal(n): return int(n,2) def isPrime(n) : if (n <= 1) : return False if (n <= 3) : return True if (n % 2 == 0 or n % 3 == 0) : return False i = 5 while(i * i <= n) : if (n % i == 0 or n % (i + 2) == 0) : return False i = i + 6 return True def get_prime_factors(number): prime_factors = [] while number % 2 == 0: prime_factors.append(2) number = number / 2 for i in range(3, int(math.sqrt(number)) + 1, 2): while number % i == 0: prime_factors.append(int(i)) number = number / i if number > 2: prime_factors.append(int(number)) return prime_factors def get_frequency(list): dic={} for ele in list: if ele in dic: dic[ele] += 1 else: dic[ele] = 1 return dic def Log2(x): return (math.log10(x) / math.log10(2)); # Function to get product of digits def getProduct(n): product = 1 while (n != 0): product = product * (n % 10) n = n // 10 return product #function to find LCM of two numbers def lcm(x,y): lcm = (x*y)//math.gcd(x,y) return lcm def isPowerOfTwo(n): return (math.ceil(Log2(n)) == math.floor(Log2(n))); #to check whether the given sorted sequnce is forming an AP or not.... def checkisap(list): d=list[1]-list[0] for i in range(2,len(list)): temp=list[i]-list[i-1] if temp !=d: return False return True #seive of erathanos def primes_method5(n): out ={} sieve = [True] * (n+1) for p in range(2, n+1): if (sieve[p]): out[p]=1 for i in range(p, n+1, p): sieve[i] = False return out #function to get the sum of digits def getSum(n): strr = str(n) list_of_number = list(map(int, strr.strip())) return sum(list_of_number) #ceil function gives wrong answer after 10^17 so i have to create my own :) # because i don't want to doubt on my solution of 900-1000 problem set. def ceildiv(x,y): return (x+y-1)//y def di():return map(int, input().split()) def ii():return int(input()) def li():return list(map(int, input().split())) def si():return list(map(str, input())) def indict(): dic = {} for index, value in enumerate(input().split()): dic[int(value)] = int(index)+1 return dic def frqdict(): # by default it is for integer input. :) dic={} for index, value in enumerate(input()): if value not in dic: dic[value] =1 else: dic[value] +=1 return dic #inp = open("input.txt","r") #out = open("output.txt","w") #Here we go...................... #practice like your never won #perform like you never lost n,w=di() a=[] fuls=0 halfs=0 for index,value in enumerate(input().split()): fuls+=int(value) halfs+=ce(int(value)/2) a.append(int(value)) if w < halfs: print(-1) else: if w==halfs: for i in range(n): print(ce(a[i]/2), end=" ") elif w==fuls: print(*a, sep=" ") else: ans=[] for i in range(n): ans.append([a[i],ce(a[i]/2),i]) ans.sort(reverse=True) diff=w-halfs ch=1 ans2=[] for i in range(n): if ch: halfele = ans[i][1] fulfele = ans[i][0] elediff=fulfele-halfele if diff > elediff : diff-=elediff ans[i][1]=fulfele elif diff ==elediff: ans[i][1]=fulfele ch=0 else: ans[i][1]+=diff ch=0 ans2.append([ans[i][2], ans[i][1]]) ans2.sort() for i in range(n): print(ans2[i][1], end=" ") ```
output
1
91,354
24
182,709
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp invited all his friends to the tea party to celebrate the holiday. He has n cups, one for each of his n friends, with volumes a1, a2, ..., an. His teapot stores w milliliters of tea (w ≤ a1 + a2 + ... + an). Polycarp wants to pour tea in cups in such a way that: * Every cup will contain tea for at least half of its volume * Every cup will contain integer number of milliliters of tea * All the tea from the teapot will be poured into cups * All friends will be satisfied. Friend with cup i won't be satisfied, if there exists such cup j that cup i contains less tea than cup j but ai > aj. For each cup output how many milliliters of tea should be poured in it. If it's impossible to pour all the tea and satisfy all conditions then output -1. Input The first line contains two integer numbers n and w (1 ≤ n ≤ 100, <image>). The second line contains n numbers a1, a2, ..., an (1 ≤ ai ≤ 100). Output Output how many milliliters of tea every cup should contain. If there are multiple answers, print any of them. If it's impossible to pour all the tea and satisfy all conditions then output -1. Examples Input 2 10 8 7 Output 6 4 Input 4 4 1 1 1 1 Output 1 1 1 1 Input 3 10 9 8 10 Output -1 Note In the third example you should pour to the first cup at least 5 milliliters, to the second one at least 4, to the third one at least 5. It sums up to 14, which is greater than 10 milliliters available.
instruction
0
91,355
24
182,710
Tags: constructive algorithms, greedy, sortings Correct Solution: ``` n, w = [int(inp) for inp in input().split()] cap = [int(a) for a in input().split(" ")] val = [0] * n for i in range(n): cap[i] = (cap[i], i) cap.sort() cap.reverse() for i in range(n): val[i] = cap[i][0]//2 + int(cap[i][0] % 2 != 0) w -= val[i] if w < 0: print(-1) exit() for i in range(n): v = min(w, cap[i][0] - val[i]) val[i] += v w -= v res = [0] * n for i in range(n): res[cap[i][1]] = val[i] for r in res: print(r, end=" ") ```
output
1
91,355
24
182,711
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp invited all his friends to the tea party to celebrate the holiday. He has n cups, one for each of his n friends, with volumes a1, a2, ..., an. His teapot stores w milliliters of tea (w ≤ a1 + a2 + ... + an). Polycarp wants to pour tea in cups in such a way that: * Every cup will contain tea for at least half of its volume * Every cup will contain integer number of milliliters of tea * All the tea from the teapot will be poured into cups * All friends will be satisfied. Friend with cup i won't be satisfied, if there exists such cup j that cup i contains less tea than cup j but ai > aj. For each cup output how many milliliters of tea should be poured in it. If it's impossible to pour all the tea and satisfy all conditions then output -1. Input The first line contains two integer numbers n and w (1 ≤ n ≤ 100, <image>). The second line contains n numbers a1, a2, ..., an (1 ≤ ai ≤ 100). Output Output how many milliliters of tea every cup should contain. If there are multiple answers, print any of them. If it's impossible to pour all the tea and satisfy all conditions then output -1. Examples Input 2 10 8 7 Output 6 4 Input 4 4 1 1 1 1 Output 1 1 1 1 Input 3 10 9 8 10 Output -1 Note In the third example you should pour to the first cup at least 5 milliliters, to the second one at least 4, to the third one at least 5. It sums up to 14, which is greater than 10 milliliters available.
instruction
0
91,356
24
182,712
Tags: constructive algorithms, greedy, sortings Correct Solution: ``` import sys,math Tests=1 for _ in range(Tests): n,w=map(int,sys.stdin.readline().split()) a=list(map(int,sys.stdin.readline().split())) s=0 for i in range(n): s+=(a[i]+1)//2 if w<s: print(-1) else: ans=[0]*n for i in range(n): ans[i]=(a[i]+1)//2 w-=s while(w>0): ind=a.index(max(a)) t=min(w,a[ind]-ans[ind]) ans[ind]+=t w-=t a[ind]=0 print(*ans) ```
output
1
91,356
24
182,713
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp invited all his friends to the tea party to celebrate the holiday. He has n cups, one for each of his n friends, with volumes a1, a2, ..., an. His teapot stores w milliliters of tea (w ≤ a1 + a2 + ... + an). Polycarp wants to pour tea in cups in such a way that: * Every cup will contain tea for at least half of its volume * Every cup will contain integer number of milliliters of tea * All the tea from the teapot will be poured into cups * All friends will be satisfied. Friend with cup i won't be satisfied, if there exists such cup j that cup i contains less tea than cup j but ai > aj. For each cup output how many milliliters of tea should be poured in it. If it's impossible to pour all the tea and satisfy all conditions then output -1. Input The first line contains two integer numbers n and w (1 ≤ n ≤ 100, <image>). The second line contains n numbers a1, a2, ..., an (1 ≤ ai ≤ 100). Output Output how many milliliters of tea every cup should contain. If there are multiple answers, print any of them. If it's impossible to pour all the tea and satisfy all conditions then output -1. Examples Input 2 10 8 7 Output 6 4 Input 4 4 1 1 1 1 Output 1 1 1 1 Input 3 10 9 8 10 Output -1 Note In the third example you should pour to the first cup at least 5 milliliters, to the second one at least 4, to the third one at least 5. It sums up to 14, which is greater than 10 milliliters available. Submitted Solution: ``` n, w = list(map(int,input().split())) a = list(map(int,input().split())) b = [(x + 1) // 2 for x in a] w -= sum(b) if w > 0: a = [(a[i], i) for i in range(n)] a.sort(reverse=True) for i in range(n): x = min(a[i][0] - b[a[i][1]], w) w -= x b[a[i][1]] += x if w == 0: break if w >= 0: print(*b) else: print(-1) ```
instruction
0
91,357
24
182,714
Yes
output
1
91,357
24
182,715
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp invited all his friends to the tea party to celebrate the holiday. He has n cups, one for each of his n friends, with volumes a1, a2, ..., an. His teapot stores w milliliters of tea (w ≤ a1 + a2 + ... + an). Polycarp wants to pour tea in cups in such a way that: * Every cup will contain tea for at least half of its volume * Every cup will contain integer number of milliliters of tea * All the tea from the teapot will be poured into cups * All friends will be satisfied. Friend with cup i won't be satisfied, if there exists such cup j that cup i contains less tea than cup j but ai > aj. For each cup output how many milliliters of tea should be poured in it. If it's impossible to pour all the tea and satisfy all conditions then output -1. Input The first line contains two integer numbers n and w (1 ≤ n ≤ 100, <image>). The second line contains n numbers a1, a2, ..., an (1 ≤ ai ≤ 100). Output Output how many milliliters of tea every cup should contain. If there are multiple answers, print any of them. If it's impossible to pour all the tea and satisfy all conditions then output -1. Examples Input 2 10 8 7 Output 6 4 Input 4 4 1 1 1 1 Output 1 1 1 1 Input 3 10 9 8 10 Output -1 Note In the third example you should pour to the first cup at least 5 milliliters, to the second one at least 4, to the third one at least 5. It sums up to 14, which is greater than 10 milliliters available. Submitted Solution: ``` import math n, w = map(int, input().split()) volumes = [] possible = True teacups = [0] * n vals = list(map(int, input().split())) for i in range(n): poured = math.ceil(vals[i] / 2) w -= poured if w < 0: possible = False break volumes.append((vals[i], i)) teacups[i] = poured if not possible: print(-1) else: svolumes = sorted(volumes, reverse=True) for j in svolumes: extra = j[0] - teacups[volumes.index(j)] if w - extra < 0: teacups[j[1]] += w break w -= extra teacups[j[1]] += extra print(' '.join(str(t) for t in teacups)) ```
instruction
0
91,358
24
182,716
Yes
output
1
91,358
24
182,717
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp invited all his friends to the tea party to celebrate the holiday. He has n cups, one for each of his n friends, with volumes a1, a2, ..., an. His teapot stores w milliliters of tea (w ≤ a1 + a2 + ... + an). Polycarp wants to pour tea in cups in such a way that: * Every cup will contain tea for at least half of its volume * Every cup will contain integer number of milliliters of tea * All the tea from the teapot will be poured into cups * All friends will be satisfied. Friend with cup i won't be satisfied, if there exists such cup j that cup i contains less tea than cup j but ai > aj. For each cup output how many milliliters of tea should be poured in it. If it's impossible to pour all the tea and satisfy all conditions then output -1. Input The first line contains two integer numbers n and w (1 ≤ n ≤ 100, <image>). The second line contains n numbers a1, a2, ..., an (1 ≤ ai ≤ 100). Output Output how many milliliters of tea every cup should contain. If there are multiple answers, print any of them. If it's impossible to pour all the tea and satisfy all conditions then output -1. Examples Input 2 10 8 7 Output 6 4 Input 4 4 1 1 1 1 Output 1 1 1 1 Input 3 10 9 8 10 Output -1 Note In the third example you should pour to the first cup at least 5 milliliters, to the second one at least 4, to the third one at least 5. It sums up to 14, which is greater than 10 milliliters available. Submitted Solution: ``` import math n, w = [int(x) for x in input().split()] s = input().split() a = sorted([[int(s[x]), x] for x in range(n)], key=lambda x: x[0], reverse=True) b = [[math.ceil(x[0]/2), x[1]] for x in a] sm = sum([x[0] for x in b]) if sm > w: print(-1) else: w -= sm i = 0 while w: if b[i][0] < a[i][0]: b[i][0] += 1 w -= 1 else: i += 1 for i in [x[0] for x in sorted(b, key=lambda x: x[1])]: print(i, end=' ') ```
instruction
0
91,359
24
182,718
Yes
output
1
91,359
24
182,719
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp invited all his friends to the tea party to celebrate the holiday. He has n cups, one for each of his n friends, with volumes a1, a2, ..., an. His teapot stores w milliliters of tea (w ≤ a1 + a2 + ... + an). Polycarp wants to pour tea in cups in such a way that: * Every cup will contain tea for at least half of its volume * Every cup will contain integer number of milliliters of tea * All the tea from the teapot will be poured into cups * All friends will be satisfied. Friend with cup i won't be satisfied, if there exists such cup j that cup i contains less tea than cup j but ai > aj. For each cup output how many milliliters of tea should be poured in it. If it's impossible to pour all the tea and satisfy all conditions then output -1. Input The first line contains two integer numbers n and w (1 ≤ n ≤ 100, <image>). The second line contains n numbers a1, a2, ..., an (1 ≤ ai ≤ 100). Output Output how many milliliters of tea every cup should contain. If there are multiple answers, print any of them. If it's impossible to pour all the tea and satisfy all conditions then output -1. Examples Input 2 10 8 7 Output 6 4 Input 4 4 1 1 1 1 Output 1 1 1 1 Input 3 10 9 8 10 Output -1 Note In the third example you should pour to the first cup at least 5 milliliters, to the second one at least 4, to the third one at least 5. It sums up to 14, which is greater than 10 milliliters available. Submitted Solution: ``` # Author: Boonnithi Jiaramaneepinit # Python Interpreter Version: Python 3.5.2 # # Note: Educational Codeforces Round 21 import math def fillTea(water, cups): curW = water for i in range(len(cups)): curW -= math.ceil(cups[i]/2) cups[i] = [cups[i], i, math.ceil(cups[i]/2)] cups = sorted(cups, key=lambda l:l[0], reverse=True) if curW < 0: return ['-1'] # eqLeft = math.floor(curW/len(cups)) # uneqLeft = curW % len(cups) # print(curW, cups) # for i in range(len(cups)): # if i < uneqLeft: # cups[i][2] += 1 # cups[i][2] = cups[i][2] + eqLeft curCup = 0 while curW > 0: curP = min(cups[curCup][0] - cups[curCup][2], curW) cups[curCup][2] += curP curW -= curP curCup += 1 cups = sorted(cups, key=lambda l:l[1], reverse=False) for i in range(len(cups)): cups[i] = str(cups[i][2]) # print(curW, cups) if curW < 0: return ['-1'] return cups ''' 3 20 22 2 1 ''' if __name__ == '__main__': [n, w] = [int(x) for x in input().split()] cups = [int(x) for x in input().split()] # [n, w] = [3, 20] # cups = [22, 2, 1] print(' '.join(fillTea(w, cups))) ```
instruction
0
91,360
24
182,720
Yes
output
1
91,360
24
182,721
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp invited all his friends to the tea party to celebrate the holiday. He has n cups, one for each of his n friends, with volumes a1, a2, ..., an. His teapot stores w milliliters of tea (w ≤ a1 + a2 + ... + an). Polycarp wants to pour tea in cups in such a way that: * Every cup will contain tea for at least half of its volume * Every cup will contain integer number of milliliters of tea * All the tea from the teapot will be poured into cups * All friends will be satisfied. Friend with cup i won't be satisfied, if there exists such cup j that cup i contains less tea than cup j but ai > aj. For each cup output how many milliliters of tea should be poured in it. If it's impossible to pour all the tea and satisfy all conditions then output -1. Input The first line contains two integer numbers n and w (1 ≤ n ≤ 100, <image>). The second line contains n numbers a1, a2, ..., an (1 ≤ ai ≤ 100). Output Output how many milliliters of tea every cup should contain. If there are multiple answers, print any of them. If it's impossible to pour all the tea and satisfy all conditions then output -1. Examples Input 2 10 8 7 Output 6 4 Input 4 4 1 1 1 1 Output 1 1 1 1 Input 3 10 9 8 10 Output -1 Note In the third example you should pour to the first cup at least 5 milliliters, to the second one at least 4, to the third one at least 5. It sums up to 14, which is greater than 10 milliliters available. Submitted Solution: ``` n, w = map(int, input().split()) a = list(map(int, input().split())) b = [(ai + 1) // 2 for ai in a] r = w - sum(b) if r < 0: print(-1) else: ind = sorted(range(n), key=lambda i: a[i], reverse=True) for i in ind: if r <= a[i] - b[i]: b[i] += r break b[i] = a[i] r -= a[i] - b[i] print(*b) ```
instruction
0
91,361
24
182,722
No
output
1
91,361
24
182,723
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp invited all his friends to the tea party to celebrate the holiday. He has n cups, one for each of his n friends, with volumes a1, a2, ..., an. His teapot stores w milliliters of tea (w ≤ a1 + a2 + ... + an). Polycarp wants to pour tea in cups in such a way that: * Every cup will contain tea for at least half of its volume * Every cup will contain integer number of milliliters of tea * All the tea from the teapot will be poured into cups * All friends will be satisfied. Friend with cup i won't be satisfied, if there exists such cup j that cup i contains less tea than cup j but ai > aj. For each cup output how many milliliters of tea should be poured in it. If it's impossible to pour all the tea and satisfy all conditions then output -1. Input The first line contains two integer numbers n and w (1 ≤ n ≤ 100, <image>). The second line contains n numbers a1, a2, ..., an (1 ≤ ai ≤ 100). Output Output how many milliliters of tea every cup should contain. If there are multiple answers, print any of them. If it's impossible to pour all the tea and satisfy all conditions then output -1. Examples Input 2 10 8 7 Output 6 4 Input 4 4 1 1 1 1 Output 1 1 1 1 Input 3 10 9 8 10 Output -1 Note In the third example you should pour to the first cup at least 5 milliliters, to the second one at least 4, to the third one at least 5. It sums up to 14, which is greater than 10 milliliters available. Submitted Solution: ``` q, w = map(int, input().split()) s = list(map(int, input().split())) p = list(map(lambda x: ((x + (x % 2)) // 2), s)) lp = sum(p) o = 0 if lp > w: print(-1) else: k = (w - lp) // len(p) p = list(map(lambda x: x + k, p)) h = sorted(p, reverse=True) w -= lp w %= len(p) while w > 0: k = p.index(h[o]) h[o] += 1 p[k] += 1 if p[k] == s[k]: o += 1 w -= 1 print(*p) ```
instruction
0
91,362
24
182,724
No
output
1
91,362
24
182,725
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp invited all his friends to the tea party to celebrate the holiday. He has n cups, one for each of his n friends, with volumes a1, a2, ..., an. His teapot stores w milliliters of tea (w ≤ a1 + a2 + ... + an). Polycarp wants to pour tea in cups in such a way that: * Every cup will contain tea for at least half of its volume * Every cup will contain integer number of milliliters of tea * All the tea from the teapot will be poured into cups * All friends will be satisfied. Friend with cup i won't be satisfied, if there exists such cup j that cup i contains less tea than cup j but ai > aj. For each cup output how many milliliters of tea should be poured in it. If it's impossible to pour all the tea and satisfy all conditions then output -1. Input The first line contains two integer numbers n and w (1 ≤ n ≤ 100, <image>). The second line contains n numbers a1, a2, ..., an (1 ≤ ai ≤ 100). Output Output how many milliliters of tea every cup should contain. If there are multiple answers, print any of them. If it's impossible to pour all the tea and satisfy all conditions then output -1. Examples Input 2 10 8 7 Output 6 4 Input 4 4 1 1 1 1 Output 1 1 1 1 Input 3 10 9 8 10 Output -1 Note In the third example you should pour to the first cup at least 5 milliliters, to the second one at least 4, to the third one at least 5. It sums up to 14, which is greater than 10 milliliters available. Submitted Solution: ``` import math n, w = map(int, input().split()) arr = list(map(int, input().split())) minNeed = 0 ans = [] for i in range(n): minNeed += math.ceil(arr[i]/2) ans.append(math.ceil(arr[i]/2)) if minNeed > w: print(-1) else: ans[arr.index(max(arr))] += (w - minNeed) print(*ans) ```
instruction
0
91,363
24
182,726
No
output
1
91,363
24
182,727
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp invited all his friends to the tea party to celebrate the holiday. He has n cups, one for each of his n friends, with volumes a1, a2, ..., an. His teapot stores w milliliters of tea (w ≤ a1 + a2 + ... + an). Polycarp wants to pour tea in cups in such a way that: * Every cup will contain tea for at least half of its volume * Every cup will contain integer number of milliliters of tea * All the tea from the teapot will be poured into cups * All friends will be satisfied. Friend with cup i won't be satisfied, if there exists such cup j that cup i contains less tea than cup j but ai > aj. For each cup output how many milliliters of tea should be poured in it. If it's impossible to pour all the tea and satisfy all conditions then output -1. Input The first line contains two integer numbers n and w (1 ≤ n ≤ 100, <image>). The second line contains n numbers a1, a2, ..., an (1 ≤ ai ≤ 100). Output Output how many milliliters of tea every cup should contain. If there are multiple answers, print any of them. If it's impossible to pour all the tea and satisfy all conditions then output -1. Examples Input 2 10 8 7 Output 6 4 Input 4 4 1 1 1 1 Output 1 1 1 1 Input 3 10 9 8 10 Output -1 Note In the third example you should pour to the first cup at least 5 milliliters, to the second one at least 4, to the third one at least 5. It sums up to 14, which is greater than 10 milliliters available. Submitted Solution: ``` n,totaltea=map(int,input().split()) ar=list(map(int,input().split())) ans=[0]*n for i in range(n):ans[i]=(ar[i]+1)//2 if sum(ans)>totaltea:print(-1) else: for i in range(n): ar[i]=[ar[i],i] ar=sorted(ar)[::-1] remain=totaltea-sum(ans) for i in range(n): if remain==40:break k=min(remain,ar[i][0]-ans[ar[i][1]]) ans[ar[i][1]]+=k remain-=k if remain!=0:print(-1) else:print(*ans) ```
instruction
0
91,364
24
182,728
No
output
1
91,364
24
182,729
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp wants to cook a soup. To do it, he needs to buy exactly n liters of water. There are only two types of water bottles in the nearby shop — 1-liter bottles and 2-liter bottles. There are infinitely many bottles of these two types in the shop. The bottle of the first type costs a burles and the bottle of the second type costs b burles correspondingly. Polycarp wants to spend as few money as possible. Your task is to find the minimum amount of money (in burles) Polycarp needs to buy exactly n liters of water in the nearby shop if the bottle of the first type costs a burles and the bottle of the second type costs b burles. You also have to answer q independent queries. Input The first line of the input contains one integer q (1 ≤ q ≤ 500) — the number of queries. The next q lines contain queries. The i-th query is given as three space-separated integers n_i, a_i and b_i (1 ≤ n_i ≤ 10^{12}, 1 ≤ a_i, b_i ≤ 1000) — how many liters Polycarp needs in the i-th query, the cost (in burles) of the bottle of the first type in the i-th query and the cost (in burles) of the bottle of the second type in the i-th query, respectively. Output Print q integers. The i-th integer should be equal to the minimum amount of money (in burles) Polycarp needs to buy exactly n_i liters of water in the nearby shop if the bottle of the first type costs a_i burles and the bottle of the second type costs b_i burles. Example Input 4 10 1 3 7 3 2 1 1000 1 1000000000000 42 88 Output 10 9 1000 42000000000000
instruction
0
91,745
24
183,490
Tags: math Correct Solution: ``` for i in range(int(input())): n, a, b = map(int, input().split()) print(min(n * a, n // 2 * b + a * ((n + 1) // 2 - n // 2))) ```
output
1
91,745
24
183,491
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp wants to cook a soup. To do it, he needs to buy exactly n liters of water. There are only two types of water bottles in the nearby shop — 1-liter bottles and 2-liter bottles. There are infinitely many bottles of these two types in the shop. The bottle of the first type costs a burles and the bottle of the second type costs b burles correspondingly. Polycarp wants to spend as few money as possible. Your task is to find the minimum amount of money (in burles) Polycarp needs to buy exactly n liters of water in the nearby shop if the bottle of the first type costs a burles and the bottle of the second type costs b burles. You also have to answer q independent queries. Input The first line of the input contains one integer q (1 ≤ q ≤ 500) — the number of queries. The next q lines contain queries. The i-th query is given as three space-separated integers n_i, a_i and b_i (1 ≤ n_i ≤ 10^{12}, 1 ≤ a_i, b_i ≤ 1000) — how many liters Polycarp needs in the i-th query, the cost (in burles) of the bottle of the first type in the i-th query and the cost (in burles) of the bottle of the second type in the i-th query, respectively. Output Print q integers. The i-th integer should be equal to the minimum amount of money (in burles) Polycarp needs to buy exactly n_i liters of water in the nearby shop if the bottle of the first type costs a_i burles and the bottle of the second type costs b_i burles. Example Input 4 10 1 3 7 3 2 1 1000 1 1000000000000 42 88 Output 10 9 1000 42000000000000
instruction
0
91,746
24
183,492
Tags: math Correct Solution: ``` q = int(input()) for i in range(q): n, a, b = list(map(int, input().split())) if 2 * a <= b: print(n * a) else: print((n // 2) * b + (n % 2) * a) ```
output
1
91,746
24
183,493
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp wants to cook a soup. To do it, he needs to buy exactly n liters of water. There are only two types of water bottles in the nearby shop — 1-liter bottles and 2-liter bottles. There are infinitely many bottles of these two types in the shop. The bottle of the first type costs a burles and the bottle of the second type costs b burles correspondingly. Polycarp wants to spend as few money as possible. Your task is to find the minimum amount of money (in burles) Polycarp needs to buy exactly n liters of water in the nearby shop if the bottle of the first type costs a burles and the bottle of the second type costs b burles. You also have to answer q independent queries. Input The first line of the input contains one integer q (1 ≤ q ≤ 500) — the number of queries. The next q lines contain queries. The i-th query is given as three space-separated integers n_i, a_i and b_i (1 ≤ n_i ≤ 10^{12}, 1 ≤ a_i, b_i ≤ 1000) — how many liters Polycarp needs in the i-th query, the cost (in burles) of the bottle of the first type in the i-th query and the cost (in burles) of the bottle of the second type in the i-th query, respectively. Output Print q integers. The i-th integer should be equal to the minimum amount of money (in burles) Polycarp needs to buy exactly n_i liters of water in the nearby shop if the bottle of the first type costs a_i burles and the bottle of the second type costs b_i burles. Example Input 4 10 1 3 7 3 2 1 1000 1 1000000000000 42 88 Output 10 9 1000 42000000000000
instruction
0
91,747
24
183,494
Tags: math Correct Solution: ``` q=int(input()) for i in range(q): l=list(map(int,input().split())) n=l[0] a=l[1] b=l[2] if 2*a<=b: print(a*n) else: print((n//2)*b+(n%2)*a) ```
output
1
91,747
24
183,495
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp wants to cook a soup. To do it, he needs to buy exactly n liters of water. There are only two types of water bottles in the nearby shop — 1-liter bottles and 2-liter bottles. There are infinitely many bottles of these two types in the shop. The bottle of the first type costs a burles and the bottle of the second type costs b burles correspondingly. Polycarp wants to spend as few money as possible. Your task is to find the minimum amount of money (in burles) Polycarp needs to buy exactly n liters of water in the nearby shop if the bottle of the first type costs a burles and the bottle of the second type costs b burles. You also have to answer q independent queries. Input The first line of the input contains one integer q (1 ≤ q ≤ 500) — the number of queries. The next q lines contain queries. The i-th query is given as three space-separated integers n_i, a_i and b_i (1 ≤ n_i ≤ 10^{12}, 1 ≤ a_i, b_i ≤ 1000) — how many liters Polycarp needs in the i-th query, the cost (in burles) of the bottle of the first type in the i-th query and the cost (in burles) of the bottle of the second type in the i-th query, respectively. Output Print q integers. The i-th integer should be equal to the minimum amount of money (in burles) Polycarp needs to buy exactly n_i liters of water in the nearby shop if the bottle of the first type costs a_i burles and the bottle of the second type costs b_i burles. Example Input 4 10 1 3 7 3 2 1 1000 1 1000000000000 42 88 Output 10 9 1000 42000000000000
instruction
0
91,748
24
183,496
Tags: math Correct Solution: ``` q = int(input()) ans = [] for i in range(q): summ = 0 n , a , b = map(int , input().split()) if a * 2 < b : x = 2 * a else : x = b summ += (n // 2) * x if (n % 2) : summ += a ans += [str(summ)] print("\n".join(ans)) ```
output
1
91,748
24
183,497
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp wants to cook a soup. To do it, he needs to buy exactly n liters of water. There are only two types of water bottles in the nearby shop — 1-liter bottles and 2-liter bottles. There are infinitely many bottles of these two types in the shop. The bottle of the first type costs a burles and the bottle of the second type costs b burles correspondingly. Polycarp wants to spend as few money as possible. Your task is to find the minimum amount of money (in burles) Polycarp needs to buy exactly n liters of water in the nearby shop if the bottle of the first type costs a burles and the bottle of the second type costs b burles. You also have to answer q independent queries. Input The first line of the input contains one integer q (1 ≤ q ≤ 500) — the number of queries. The next q lines contain queries. The i-th query is given as three space-separated integers n_i, a_i and b_i (1 ≤ n_i ≤ 10^{12}, 1 ≤ a_i, b_i ≤ 1000) — how many liters Polycarp needs in the i-th query, the cost (in burles) of the bottle of the first type in the i-th query and the cost (in burles) of the bottle of the second type in the i-th query, respectively. Output Print q integers. The i-th integer should be equal to the minimum amount of money (in burles) Polycarp needs to buy exactly n_i liters of water in the nearby shop if the bottle of the first type costs a_i burles and the bottle of the second type costs b_i burles. Example Input 4 10 1 3 7 3 2 1 1000 1 1000000000000 42 88 Output 10 9 1000 42000000000000
instruction
0
91,749
24
183,498
Tags: math Correct Solution: ``` amount = int(input()) for i in range(amount): n,a,b = [int(s) for s in input().split()] if 2 * a <= b: print(n * a) else: print(a * (n % 2) + (n // 2) * b) ```
output
1
91,749
24
183,499
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp wants to cook a soup. To do it, he needs to buy exactly n liters of water. There are only two types of water bottles in the nearby shop — 1-liter bottles and 2-liter bottles. There are infinitely many bottles of these two types in the shop. The bottle of the first type costs a burles and the bottle of the second type costs b burles correspondingly. Polycarp wants to spend as few money as possible. Your task is to find the minimum amount of money (in burles) Polycarp needs to buy exactly n liters of water in the nearby shop if the bottle of the first type costs a burles and the bottle of the second type costs b burles. You also have to answer q independent queries. Input The first line of the input contains one integer q (1 ≤ q ≤ 500) — the number of queries. The next q lines contain queries. The i-th query is given as three space-separated integers n_i, a_i and b_i (1 ≤ n_i ≤ 10^{12}, 1 ≤ a_i, b_i ≤ 1000) — how many liters Polycarp needs in the i-th query, the cost (in burles) of the bottle of the first type in the i-th query and the cost (in burles) of the bottle of the second type in the i-th query, respectively. Output Print q integers. The i-th integer should be equal to the minimum amount of money (in burles) Polycarp needs to buy exactly n_i liters of water in the nearby shop if the bottle of the first type costs a_i burles and the bottle of the second type costs b_i burles. Example Input 4 10 1 3 7 3 2 1 1000 1 1000000000000 42 88 Output 10 9 1000 42000000000000
instruction
0
91,750
24
183,500
Tags: math Correct Solution: ``` def run(n1, a1, b1): if 2 * a1 < b1: res = n1 * a1 else: res = b1 * int(n1 / 2) + a1 * (n1 % 2) return res q = int(input()) for i in range(0, q): s = input() n = int(s.split(" ")[0]) a = int(s.split(" ")[1]) b = int(s.split(" ")[2]) print(run(n, a, b)) ```
output
1
91,750
24
183,501
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp wants to cook a soup. To do it, he needs to buy exactly n liters of water. There are only two types of water bottles in the nearby shop — 1-liter bottles and 2-liter bottles. There are infinitely many bottles of these two types in the shop. The bottle of the first type costs a burles and the bottle of the second type costs b burles correspondingly. Polycarp wants to spend as few money as possible. Your task is to find the minimum amount of money (in burles) Polycarp needs to buy exactly n liters of water in the nearby shop if the bottle of the first type costs a burles and the bottle of the second type costs b burles. You also have to answer q independent queries. Input The first line of the input contains one integer q (1 ≤ q ≤ 500) — the number of queries. The next q lines contain queries. The i-th query is given as three space-separated integers n_i, a_i and b_i (1 ≤ n_i ≤ 10^{12}, 1 ≤ a_i, b_i ≤ 1000) — how many liters Polycarp needs in the i-th query, the cost (in burles) of the bottle of the first type in the i-th query and the cost (in burles) of the bottle of the second type in the i-th query, respectively. Output Print q integers. The i-th integer should be equal to the minimum amount of money (in burles) Polycarp needs to buy exactly n_i liters of water in the nearby shop if the bottle of the first type costs a_i burles and the bottle of the second type costs b_i burles. Example Input 4 10 1 3 7 3 2 1 1000 1 1000000000000 42 88 Output 10 9 1000 42000000000000
instruction
0
91,751
24
183,502
Tags: math Correct Solution: ``` for _ in range(int(input())): n,a,b=map(int, input().split()) print(min((n//2)*b+(n%2)*a,a*n)) ```
output
1
91,751
24
183,503
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp wants to cook a soup. To do it, he needs to buy exactly n liters of water. There are only two types of water bottles in the nearby shop — 1-liter bottles and 2-liter bottles. There are infinitely many bottles of these two types in the shop. The bottle of the first type costs a burles and the bottle of the second type costs b burles correspondingly. Polycarp wants to spend as few money as possible. Your task is to find the minimum amount of money (in burles) Polycarp needs to buy exactly n liters of water in the nearby shop if the bottle of the first type costs a burles and the bottle of the second type costs b burles. You also have to answer q independent queries. Input The first line of the input contains one integer q (1 ≤ q ≤ 500) — the number of queries. The next q lines contain queries. The i-th query is given as three space-separated integers n_i, a_i and b_i (1 ≤ n_i ≤ 10^{12}, 1 ≤ a_i, b_i ≤ 1000) — how many liters Polycarp needs in the i-th query, the cost (in burles) of the bottle of the first type in the i-th query and the cost (in burles) of the bottle of the second type in the i-th query, respectively. Output Print q integers. The i-th integer should be equal to the minimum amount of money (in burles) Polycarp needs to buy exactly n_i liters of water in the nearby shop if the bottle of the first type costs a_i burles and the bottle of the second type costs b_i burles. Example Input 4 10 1 3 7 3 2 1 1000 1 1000000000000 42 88 Output 10 9 1000 42000000000000
instruction
0
91,752
24
183,504
Tags: math Correct Solution: ``` import sys def main(n, a, b): d = b - 2*a if d < 0: return n//2*b + n%2*a else: return n*a if __name__ == "__main__": first = True for line in sys.stdin: if first: first = False continue l = line.strip().split(' ') l = [int(x) for x in l] print(main(l[0], l[1], l[2])) ```
output
1
91,752
24
183,505
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp wants to cook a soup. To do it, he needs to buy exactly n liters of water. There are only two types of water bottles in the nearby shop — 1-liter bottles and 2-liter bottles. There are infinitely many bottles of these two types in the shop. The bottle of the first type costs a burles and the bottle of the second type costs b burles correspondingly. Polycarp wants to spend as few money as possible. Your task is to find the minimum amount of money (in burles) Polycarp needs to buy exactly n liters of water in the nearby shop if the bottle of the first type costs a burles and the bottle of the second type costs b burles. You also have to answer q independent queries. Input The first line of the input contains one integer q (1 ≤ q ≤ 500) — the number of queries. The next q lines contain queries. The i-th query is given as three space-separated integers n_i, a_i and b_i (1 ≤ n_i ≤ 10^{12}, 1 ≤ a_i, b_i ≤ 1000) — how many liters Polycarp needs in the i-th query, the cost (in burles) of the bottle of the first type in the i-th query and the cost (in burles) of the bottle of the second type in the i-th query, respectively. Output Print q integers. The i-th integer should be equal to the minimum amount of money (in burles) Polycarp needs to buy exactly n_i liters of water in the nearby shop if the bottle of the first type costs a_i burles and the bottle of the second type costs b_i burles. Example Input 4 10 1 3 7 3 2 1 1000 1 1000000000000 42 88 Output 10 9 1000 42000000000000 Submitted Solution: ``` def A(): q = int(input()) for i in range(q): n , a , b = map(int , input().split()) if(2*a<b): print(n*a) continue else: print(n//2*b+(n%2)*a) A() ```
instruction
0
91,753
24
183,506
Yes
output
1
91,753
24
183,507
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp wants to cook a soup. To do it, he needs to buy exactly n liters of water. There are only two types of water bottles in the nearby shop — 1-liter bottles and 2-liter bottles. There are infinitely many bottles of these two types in the shop. The bottle of the first type costs a burles and the bottle of the second type costs b burles correspondingly. Polycarp wants to spend as few money as possible. Your task is to find the minimum amount of money (in burles) Polycarp needs to buy exactly n liters of water in the nearby shop if the bottle of the first type costs a burles and the bottle of the second type costs b burles. You also have to answer q independent queries. Input The first line of the input contains one integer q (1 ≤ q ≤ 500) — the number of queries. The next q lines contain queries. The i-th query is given as three space-separated integers n_i, a_i and b_i (1 ≤ n_i ≤ 10^{12}, 1 ≤ a_i, b_i ≤ 1000) — how many liters Polycarp needs in the i-th query, the cost (in burles) of the bottle of the first type in the i-th query and the cost (in burles) of the bottle of the second type in the i-th query, respectively. Output Print q integers. The i-th integer should be equal to the minimum amount of money (in burles) Polycarp needs to buy exactly n_i liters of water in the nearby shop if the bottle of the first type costs a_i burles and the bottle of the second type costs b_i burles. Example Input 4 10 1 3 7 3 2 1 1000 1 1000000000000 42 88 Output 10 9 1000 42000000000000 Submitted Solution: ``` q = int(input()) ans = [] for i in range(q): n,a,b = map(int, input().split()) costs = [] costs.append(n*a) costs.append(((n//2)*b) + ((n % 2) * a)) ans.append(min(costs)) for i in range(q): print(ans[i],end="\n") ```
instruction
0
91,754
24
183,508
Yes
output
1
91,754
24
183,509
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp wants to cook a soup. To do it, he needs to buy exactly n liters of water. There are only two types of water bottles in the nearby shop — 1-liter bottles and 2-liter bottles. There are infinitely many bottles of these two types in the shop. The bottle of the first type costs a burles and the bottle of the second type costs b burles correspondingly. Polycarp wants to spend as few money as possible. Your task is to find the minimum amount of money (in burles) Polycarp needs to buy exactly n liters of water in the nearby shop if the bottle of the first type costs a burles and the bottle of the second type costs b burles. You also have to answer q independent queries. Input The first line of the input contains one integer q (1 ≤ q ≤ 500) — the number of queries. The next q lines contain queries. The i-th query is given as three space-separated integers n_i, a_i and b_i (1 ≤ n_i ≤ 10^{12}, 1 ≤ a_i, b_i ≤ 1000) — how many liters Polycarp needs in the i-th query, the cost (in burles) of the bottle of the first type in the i-th query and the cost (in burles) of the bottle of the second type in the i-th query, respectively. Output Print q integers. The i-th integer should be equal to the minimum amount of money (in burles) Polycarp needs to buy exactly n_i liters of water in the nearby shop if the bottle of the first type costs a_i burles and the bottle of the second type costs b_i burles. Example Input 4 10 1 3 7 3 2 1 1000 1 1000000000000 42 88 Output 10 9 1000 42000000000000 Submitted Solution: ``` n=int(input()) for i in range(n): n,a,b=map(int,input().split()) k=min(2*a,b) print((n//2)*k+(n%2)*a) ```
instruction
0
91,755
24
183,510
Yes
output
1
91,755
24
183,511
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp wants to cook a soup. To do it, he needs to buy exactly n liters of water. There are only two types of water bottles in the nearby shop — 1-liter bottles and 2-liter bottles. There are infinitely many bottles of these two types in the shop. The bottle of the first type costs a burles and the bottle of the second type costs b burles correspondingly. Polycarp wants to spend as few money as possible. Your task is to find the minimum amount of money (in burles) Polycarp needs to buy exactly n liters of water in the nearby shop if the bottle of the first type costs a burles and the bottle of the second type costs b burles. You also have to answer q independent queries. Input The first line of the input contains one integer q (1 ≤ q ≤ 500) — the number of queries. The next q lines contain queries. The i-th query is given as three space-separated integers n_i, a_i and b_i (1 ≤ n_i ≤ 10^{12}, 1 ≤ a_i, b_i ≤ 1000) — how many liters Polycarp needs in the i-th query, the cost (in burles) of the bottle of the first type in the i-th query and the cost (in burles) of the bottle of the second type in the i-th query, respectively. Output Print q integers. The i-th integer should be equal to the minimum amount of money (in burles) Polycarp needs to buy exactly n_i liters of water in the nearby shop if the bottle of the first type costs a_i burles and the bottle of the second type costs b_i burles. Example Input 4 10 1 3 7 3 2 1 1000 1 1000000000000 42 88 Output 10 9 1000 42000000000000 Submitted Solution: ``` def mi(): return map(int, input().split()) ''' 4 10 1 3 7 3 2 1 1000 1 1000000000000 42 88 ''' for _ in range(int(input())): n,a,b = mi() if 2*a<b: print (n*a) else: print ((n//2)*b+(n%2)*a) ```
instruction
0
91,756
24
183,512
Yes
output
1
91,756
24
183,513
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp wants to cook a soup. To do it, he needs to buy exactly n liters of water. There are only two types of water bottles in the nearby shop — 1-liter bottles and 2-liter bottles. There are infinitely many bottles of these two types in the shop. The bottle of the first type costs a burles and the bottle of the second type costs b burles correspondingly. Polycarp wants to spend as few money as possible. Your task is to find the minimum amount of money (in burles) Polycarp needs to buy exactly n liters of water in the nearby shop if the bottle of the first type costs a burles and the bottle of the second type costs b burles. You also have to answer q independent queries. Input The first line of the input contains one integer q (1 ≤ q ≤ 500) — the number of queries. The next q lines contain queries. The i-th query is given as three space-separated integers n_i, a_i and b_i (1 ≤ n_i ≤ 10^{12}, 1 ≤ a_i, b_i ≤ 1000) — how many liters Polycarp needs in the i-th query, the cost (in burles) of the bottle of the first type in the i-th query and the cost (in burles) of the bottle of the second type in the i-th query, respectively. Output Print q integers. The i-th integer should be equal to the minimum amount of money (in burles) Polycarp needs to buy exactly n_i liters of water in the nearby shop if the bottle of the first type costs a_i burles and the bottle of the second type costs b_i burles. Example Input 4 10 1 3 7 3 2 1 1000 1 1000000000000 42 88 Output 10 9 1000 42000000000000 Submitted Solution: ``` q = int(input()) for i in' '*q: n, a, b = map(int, input().split()) print(min(a * n, n // 2 * b if n // 2 else n // 2 * b + a)) ```
instruction
0
91,757
24
183,514
No
output
1
91,757
24
183,515
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp wants to cook a soup. To do it, he needs to buy exactly n liters of water. There are only two types of water bottles in the nearby shop — 1-liter bottles and 2-liter bottles. There are infinitely many bottles of these two types in the shop. The bottle of the first type costs a burles and the bottle of the second type costs b burles correspondingly. Polycarp wants to spend as few money as possible. Your task is to find the minimum amount of money (in burles) Polycarp needs to buy exactly n liters of water in the nearby shop if the bottle of the first type costs a burles and the bottle of the second type costs b burles. You also have to answer q independent queries. Input The first line of the input contains one integer q (1 ≤ q ≤ 500) — the number of queries. The next q lines contain queries. The i-th query is given as three space-separated integers n_i, a_i and b_i (1 ≤ n_i ≤ 10^{12}, 1 ≤ a_i, b_i ≤ 1000) — how many liters Polycarp needs in the i-th query, the cost (in burles) of the bottle of the first type in the i-th query and the cost (in burles) of the bottle of the second type in the i-th query, respectively. Output Print q integers. The i-th integer should be equal to the minimum amount of money (in burles) Polycarp needs to buy exactly n_i liters of water in the nearby shop if the bottle of the first type costs a_i burles and the bottle of the second type costs b_i burles. Example Input 4 10 1 3 7 3 2 1 1000 1 1000000000000 42 88 Output 10 9 1000 42000000000000 Submitted Solution: ``` for i in range(int(input())): b = list(map(int, input().split())) if b[0] % 2 == 0: print(b[0]*b[1]) if b[1] <= b[2]//2 else print(b[0]*(b[2]//2)) else: print(b[1]+(b[0]-1)* min(b[1], b[2]//2)) ```
instruction
0
91,758
24
183,516
No
output
1
91,758
24
183,517
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp wants to cook a soup. To do it, he needs to buy exactly n liters of water. There are only two types of water bottles in the nearby shop — 1-liter bottles and 2-liter bottles. There are infinitely many bottles of these two types in the shop. The bottle of the first type costs a burles and the bottle of the second type costs b burles correspondingly. Polycarp wants to spend as few money as possible. Your task is to find the minimum amount of money (in burles) Polycarp needs to buy exactly n liters of water in the nearby shop if the bottle of the first type costs a burles and the bottle of the second type costs b burles. You also have to answer q independent queries. Input The first line of the input contains one integer q (1 ≤ q ≤ 500) — the number of queries. The next q lines contain queries. The i-th query is given as three space-separated integers n_i, a_i and b_i (1 ≤ n_i ≤ 10^{12}, 1 ≤ a_i, b_i ≤ 1000) — how many liters Polycarp needs in the i-th query, the cost (in burles) of the bottle of the first type in the i-th query and the cost (in burles) of the bottle of the second type in the i-th query, respectively. Output Print q integers. The i-th integer should be equal to the minimum amount of money (in burles) Polycarp needs to buy exactly n_i liters of water in the nearby shop if the bottle of the first type costs a_i burles and the bottle of the second type costs b_i burles. Example Input 4 10 1 3 7 3 2 1 1000 1 1000000000000 42 88 Output 10 9 1000 42000000000000 Submitted Solution: ``` def water_problem(): query_num = eval(input()) output_buffer = [] for i in range(query_num): water_liter, price1liter, price2liter = input().split(' ') water_liter, price1liter, price2liter = eval(water_liter), eval(price1liter), eval(price2liter) if price2liter / 2 >= price1liter: num_of_1liter, num_of_2liter = water_liter, 0 else: num_of_2liter = water_liter // 2 num_of_1liter = water_liter % 2 output_buffer.append(str(num_of_1liter) + ' ' + str(num_of_2liter)) for output in output_buffer: print(output) return if __name__ == '__main__': water_problem() ```
instruction
0
91,759
24
183,518
No
output
1
91,759
24
183,519
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp wants to cook a soup. To do it, he needs to buy exactly n liters of water. There are only two types of water bottles in the nearby shop — 1-liter bottles and 2-liter bottles. There are infinitely many bottles of these two types in the shop. The bottle of the first type costs a burles and the bottle of the second type costs b burles correspondingly. Polycarp wants to spend as few money as possible. Your task is to find the minimum amount of money (in burles) Polycarp needs to buy exactly n liters of water in the nearby shop if the bottle of the first type costs a burles and the bottle of the second type costs b burles. You also have to answer q independent queries. Input The first line of the input contains one integer q (1 ≤ q ≤ 500) — the number of queries. The next q lines contain queries. The i-th query is given as three space-separated integers n_i, a_i and b_i (1 ≤ n_i ≤ 10^{12}, 1 ≤ a_i, b_i ≤ 1000) — how many liters Polycarp needs in the i-th query, the cost (in burles) of the bottle of the first type in the i-th query and the cost (in burles) of the bottle of the second type in the i-th query, respectively. Output Print q integers. The i-th integer should be equal to the minimum amount of money (in burles) Polycarp needs to buy exactly n_i liters of water in the nearby shop if the bottle of the first type costs a_i burles and the bottle of the second type costs b_i burles. Example Input 4 10 1 3 7 3 2 1 1000 1 1000000000000 42 88 Output 10 9 1000 42000000000000 Submitted Solution: ``` q = int(input()) n=[];a=[];b=[] for i in range(q): t1,t2,t3 = map(int, input().split()) n.append(t1) a.append(t2) b.append(t3) for i in range(q): ans=0 if 2*a[i] < b[i]: ans=n[i]*a[i] else: if n[i]%2==0: ans=n[i]*b[i]/2 else: ans=n[i]//2*b[i]+a[i] print(ans) ```
instruction
0
91,760
24
183,520
No
output
1
91,760
24
183,521
Provide tags and a correct Python 3 solution for this coding contest problem. Two pirates Polycarpus and Vasily play a very interesting game. They have n chests with coins, the chests are numbered with integers from 1 to n. Chest number i has ai coins. Polycarpus and Vasily move in turns. Polycarpus moves first. During a move a player is allowed to choose a positive integer x (2·x + 1 ≤ n) and take a coin from each chest with numbers x, 2·x, 2·x + 1. It may turn out that some chest has no coins, in this case the player doesn't take a coin from this chest. The game finishes when all chests get emptied. Polycarpus isn't a greedy scrooge. Polycarpys is a lazy slob. So he wonders in what minimum number of moves the game can finish. Help Polycarpus, determine the minimum number of moves in which the game can finish. Note that Polycarpus counts not only his moves, he also counts Vasily's moves. Input The first line contains a single integer n (1 ≤ n ≤ 100) — the number of chests with coins. The second line contains a sequence of space-separated integers: a1, a2, ..., an (1 ≤ ai ≤ 1000), where ai is the number of coins in the chest number i at the beginning of the game. Output Print a single integer — the minimum number of moves needed to finish the game. If no sequence of turns leads to finishing the game, print -1. Examples Input 1 1 Output -1 Input 3 1 2 3 Output 3 Note In the first test case there isn't a single move that can be made. That's why the players won't be able to empty the chests. In the second sample there is only one possible move x = 1. This move should be repeated at least 3 times to empty the third chest.
instruction
0
92,945
24
185,890
Tags: greedy Correct Solution: ``` n = int(input()) if n == 1 or n & 1 == 0: print(-1) else: t = list(map(int, input().split())) s, k = 0, n // 2 - 1 for i in range(n - 1, 1, -2): p = max(t[i], t[i - 1]) t[k] = max(0, t[k] - p) s += p k -= 1 print(s + t[0]) ```
output
1
92,945
24
185,891
Provide tags and a correct Python 3 solution for this coding contest problem. Two pirates Polycarpus and Vasily play a very interesting game. They have n chests with coins, the chests are numbered with integers from 1 to n. Chest number i has ai coins. Polycarpus and Vasily move in turns. Polycarpus moves first. During a move a player is allowed to choose a positive integer x (2·x + 1 ≤ n) and take a coin from each chest with numbers x, 2·x, 2·x + 1. It may turn out that some chest has no coins, in this case the player doesn't take a coin from this chest. The game finishes when all chests get emptied. Polycarpus isn't a greedy scrooge. Polycarpys is a lazy slob. So he wonders in what minimum number of moves the game can finish. Help Polycarpus, determine the minimum number of moves in which the game can finish. Note that Polycarpus counts not only his moves, he also counts Vasily's moves. Input The first line contains a single integer n (1 ≤ n ≤ 100) — the number of chests with coins. The second line contains a sequence of space-separated integers: a1, a2, ..., an (1 ≤ ai ≤ 1000), where ai is the number of coins in the chest number i at the beginning of the game. Output Print a single integer — the minimum number of moves needed to finish the game. If no sequence of turns leads to finishing the game, print -1. Examples Input 1 1 Output -1 Input 3 1 2 3 Output 3 Note In the first test case there isn't a single move that can be made. That's why the players won't be able to empty the chests. In the second sample there is only one possible move x = 1. This move should be repeated at least 3 times to empty the third chest.
instruction
0
92,946
24
185,892
Tags: greedy Correct Solution: ``` t = int(input()) line = input() lis = line.split() lis = [int(i) for i in lis] if t==1 or t%2==0 : print("-1") quit() count = 0 i = t while i >= 4 : if i%2 == 1 : p = i-1 q = int(p/2) count = count + lis[i-1] lis[p-1] = lis[p-1] - lis[i-1] if lis[p-1] < 0 : lis[p-1] = 0 lis[q-1] = lis[q-1] - lis[i-1] if lis[q-1] < 0 : lis[q-1] = 0 lis[i-1] = 0 else : p = i+1 q = int(i/2) count = count + lis[i-1] lis[p-1] = lis[p-1] - lis[i-1] if lis[p-1] < 0 : lis[p-1] = 0 lis[q-1] = lis[q-1] - lis[i-1] if lis[q-1] < 0 : lis[q-1] = 0 lis[i-1] = 0 i = i-1 m = max(lis[0], lis[1], lis[2]) count = count + m print(count) ```
output
1
92,946
24
185,893
Provide tags and a correct Python 3 solution for this coding contest problem. Two pirates Polycarpus and Vasily play a very interesting game. They have n chests with coins, the chests are numbered with integers from 1 to n. Chest number i has ai coins. Polycarpus and Vasily move in turns. Polycarpus moves first. During a move a player is allowed to choose a positive integer x (2·x + 1 ≤ n) and take a coin from each chest with numbers x, 2·x, 2·x + 1. It may turn out that some chest has no coins, in this case the player doesn't take a coin from this chest. The game finishes when all chests get emptied. Polycarpus isn't a greedy scrooge. Polycarpys is a lazy slob. So he wonders in what minimum number of moves the game can finish. Help Polycarpus, determine the minimum number of moves in which the game can finish. Note that Polycarpus counts not only his moves, he also counts Vasily's moves. Input The first line contains a single integer n (1 ≤ n ≤ 100) — the number of chests with coins. The second line contains a sequence of space-separated integers: a1, a2, ..., an (1 ≤ ai ≤ 1000), where ai is the number of coins in the chest number i at the beginning of the game. Output Print a single integer — the minimum number of moves needed to finish the game. If no sequence of turns leads to finishing the game, print -1. Examples Input 1 1 Output -1 Input 3 1 2 3 Output 3 Note In the first test case there isn't a single move that can be made. That's why the players won't be able to empty the chests. In the second sample there is only one possible move x = 1. This move should be repeated at least 3 times to empty the third chest.
instruction
0
92,947
24
185,894
Tags: greedy Correct Solution: ``` ''' Auther: ghoshashis545 Ashis Ghosh College: Jalpaiguri Govt Enggineering College ''' from os import path from io import BytesIO, IOBase import sys from heapq import heappush,heappop from functools import cmp_to_key as ctk from collections import deque,Counter,defaultdict as dd from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right from itertools import permutations from datetime import datetime from math import ceil,sqrt,log,gcd def ii():return int(input()) def si():return input().rstrip() def mi():return map(int,input().split()) def li():return list(mi()) abc='abcdefghijklmnopqrstuvwxyz' mod=1000000007 #mod=998244353 inf = float("inf") vow=['a','e','i','o','u'] dx,dy=[-1,1,0,0],[0,0,1,-1] def bo(i): return ord(i)-ord('0') file = 1 def ceil(a,b): return (a+b-1)//b def solve(): # for _ in range(1,ii()+1): n = ii() a = li() if n == 1 or n%2==0: print('-1') return cnt = 0 for i in range(n//2-1,-1,-1): x = max(a[2*i+1],a[2*i+2]) cnt += x a[i] = max(0,a[i]-x) print(cnt + a[0]) if __name__ =="__main__": if(file): if path.exists('input.txt'): sys.stdin=open('input.txt', 'r') sys.stdout=open('output.txt','w') else: input=sys.stdin.readline solve() ```
output
1
92,947
24
185,895
Provide tags and a correct Python 3 solution for this coding contest problem. Two pirates Polycarpus and Vasily play a very interesting game. They have n chests with coins, the chests are numbered with integers from 1 to n. Chest number i has ai coins. Polycarpus and Vasily move in turns. Polycarpus moves first. During a move a player is allowed to choose a positive integer x (2·x + 1 ≤ n) and take a coin from each chest with numbers x, 2·x, 2·x + 1. It may turn out that some chest has no coins, in this case the player doesn't take a coin from this chest. The game finishes when all chests get emptied. Polycarpus isn't a greedy scrooge. Polycarpys is a lazy slob. So he wonders in what minimum number of moves the game can finish. Help Polycarpus, determine the minimum number of moves in which the game can finish. Note that Polycarpus counts not only his moves, he also counts Vasily's moves. Input The first line contains a single integer n (1 ≤ n ≤ 100) — the number of chests with coins. The second line contains a sequence of space-separated integers: a1, a2, ..., an (1 ≤ ai ≤ 1000), where ai is the number of coins in the chest number i at the beginning of the game. Output Print a single integer — the minimum number of moves needed to finish the game. If no sequence of turns leads to finishing the game, print -1. Examples Input 1 1 Output -1 Input 3 1 2 3 Output 3 Note In the first test case there isn't a single move that can be made. That's why the players won't be able to empty the chests. In the second sample there is only one possible move x = 1. This move should be repeated at least 3 times to empty the third chest.
instruction
0
92,948
24
185,896
Tags: greedy Correct Solution: ``` n=int(input()) if n==1 or n%2==0: print(-1) exit() A=[0]*(n+1) A[1:n+1]=list(map(int,input().split())) ans=0 for i in range(n,0,-1): if(A[i]<=0):continue x=int(i/2) A[x]-=A[i] ans+=A[i] if i%2==1: A[i-1]-=A[i] A[i]=0 print(ans) ```
output
1
92,948
24
185,897
Provide tags and a correct Python 3 solution for this coding contest problem. Two pirates Polycarpus and Vasily play a very interesting game. They have n chests with coins, the chests are numbered with integers from 1 to n. Chest number i has ai coins. Polycarpus and Vasily move in turns. Polycarpus moves first. During a move a player is allowed to choose a positive integer x (2·x + 1 ≤ n) and take a coin from each chest with numbers x, 2·x, 2·x + 1. It may turn out that some chest has no coins, in this case the player doesn't take a coin from this chest. The game finishes when all chests get emptied. Polycarpus isn't a greedy scrooge. Polycarpys is a lazy slob. So he wonders in what minimum number of moves the game can finish. Help Polycarpus, determine the minimum number of moves in which the game can finish. Note that Polycarpus counts not only his moves, he also counts Vasily's moves. Input The first line contains a single integer n (1 ≤ n ≤ 100) — the number of chests with coins. The second line contains a sequence of space-separated integers: a1, a2, ..., an (1 ≤ ai ≤ 1000), where ai is the number of coins in the chest number i at the beginning of the game. Output Print a single integer — the minimum number of moves needed to finish the game. If no sequence of turns leads to finishing the game, print -1. Examples Input 1 1 Output -1 Input 3 1 2 3 Output 3 Note In the first test case there isn't a single move that can be made. That's why the players won't be able to empty the chests. In the second sample there is only one possible move x = 1. This move should be repeated at least 3 times to empty the third chest.
instruction
0
92,949
24
185,898
Tags: greedy Correct Solution: ``` n, s = int(input()), 0 a = [0] + list(map(int, input().split())) if n % 2 == 0 or n == 1: print(-1) else: for i in range(n, 1, -2): mx = max(a[i], a[i - 1]) s += mx a[i // 2] = max(0, a[i // 2] - mx) print(s + a[1]) ```
output
1
92,949
24
185,899
Provide tags and a correct Python 3 solution for this coding contest problem. Two pirates Polycarpus and Vasily play a very interesting game. They have n chests with coins, the chests are numbered with integers from 1 to n. Chest number i has ai coins. Polycarpus and Vasily move in turns. Polycarpus moves first. During a move a player is allowed to choose a positive integer x (2·x + 1 ≤ n) and take a coin from each chest with numbers x, 2·x, 2·x + 1. It may turn out that some chest has no coins, in this case the player doesn't take a coin from this chest. The game finishes when all chests get emptied. Polycarpus isn't a greedy scrooge. Polycarpys is a lazy slob. So he wonders in what minimum number of moves the game can finish. Help Polycarpus, determine the minimum number of moves in which the game can finish. Note that Polycarpus counts not only his moves, he also counts Vasily's moves. Input The first line contains a single integer n (1 ≤ n ≤ 100) — the number of chests with coins. The second line contains a sequence of space-separated integers: a1, a2, ..., an (1 ≤ ai ≤ 1000), where ai is the number of coins in the chest number i at the beginning of the game. Output Print a single integer — the minimum number of moves needed to finish the game. If no sequence of turns leads to finishing the game, print -1. Examples Input 1 1 Output -1 Input 3 1 2 3 Output 3 Note In the first test case there isn't a single move that can be made. That's why the players won't be able to empty the chests. In the second sample there is only one possible move x = 1. This move should be repeated at least 3 times to empty the third chest.
instruction
0
92,950
24
185,900
Tags: greedy Correct Solution: ``` n = int(input()) A = [int(i) for i in input().split()] if n == 1 or n % 2 == 0: print(-1) exit() ans = 0 for i in range(n-1, 3, -2): diff = max(A[i], A[i-1]) ans += diff A[(i-1)//2] -= diff A[(i-1)//2] = max(0, A[(i-1)//2]) ans += max(A[:3]) print(ans) ```
output
1
92,950
24
185,901
Provide tags and a correct Python 3 solution for this coding contest problem. Two pirates Polycarpus and Vasily play a very interesting game. They have n chests with coins, the chests are numbered with integers from 1 to n. Chest number i has ai coins. Polycarpus and Vasily move in turns. Polycarpus moves first. During a move a player is allowed to choose a positive integer x (2·x + 1 ≤ n) and take a coin from each chest with numbers x, 2·x, 2·x + 1. It may turn out that some chest has no coins, in this case the player doesn't take a coin from this chest. The game finishes when all chests get emptied. Polycarpus isn't a greedy scrooge. Polycarpys is a lazy slob. So he wonders in what minimum number of moves the game can finish. Help Polycarpus, determine the minimum number of moves in which the game can finish. Note that Polycarpus counts not only his moves, he also counts Vasily's moves. Input The first line contains a single integer n (1 ≤ n ≤ 100) — the number of chests with coins. The second line contains a sequence of space-separated integers: a1, a2, ..., an (1 ≤ ai ≤ 1000), where ai is the number of coins in the chest number i at the beginning of the game. Output Print a single integer — the minimum number of moves needed to finish the game. If no sequence of turns leads to finishing the game, print -1. Examples Input 1 1 Output -1 Input 3 1 2 3 Output 3 Note In the first test case there isn't a single move that can be made. That's why the players won't be able to empty the chests. In the second sample there is only one possible move x = 1. This move should be repeated at least 3 times to empty the third chest.
instruction
0
92,951
24
185,902
Tags: greedy Correct Solution: ``` #!/usr/bin/python3 n = int(input()) a = [0] + list(map(int, input().split())) if len(a) < 3 or n % 2 == 0: print(-1) else: ans = 0 for x in range(n // 2, 0, -1): d = max(0, a[2 * x], a[2 * x + 1]) ans += d a[x] -= d print(ans + max(0, a[1])) ```
output
1
92,951
24
185,903
Provide tags and a correct Python 3 solution for this coding contest problem. Two pirates Polycarpus and Vasily play a very interesting game. They have n chests with coins, the chests are numbered with integers from 1 to n. Chest number i has ai coins. Polycarpus and Vasily move in turns. Polycarpus moves first. During a move a player is allowed to choose a positive integer x (2·x + 1 ≤ n) and take a coin from each chest with numbers x, 2·x, 2·x + 1. It may turn out that some chest has no coins, in this case the player doesn't take a coin from this chest. The game finishes when all chests get emptied. Polycarpus isn't a greedy scrooge. Polycarpys is a lazy slob. So he wonders in what minimum number of moves the game can finish. Help Polycarpus, determine the minimum number of moves in which the game can finish. Note that Polycarpus counts not only his moves, he also counts Vasily's moves. Input The first line contains a single integer n (1 ≤ n ≤ 100) — the number of chests with coins. The second line contains a sequence of space-separated integers: a1, a2, ..., an (1 ≤ ai ≤ 1000), where ai is the number of coins in the chest number i at the beginning of the game. Output Print a single integer — the minimum number of moves needed to finish the game. If no sequence of turns leads to finishing the game, print -1. Examples Input 1 1 Output -1 Input 3 1 2 3 Output 3 Note In the first test case there isn't a single move that can be made. That's why the players won't be able to empty the chests. In the second sample there is only one possible move x = 1. This move should be repeated at least 3 times to empty the third chest.
instruction
0
92,952
24
185,904
Tags: greedy Correct Solution: ``` n=int(input()) if n==1 or n%2==0: print(-1) exit() A=[0]*(n+1) A[1:n+1]=list(map(int,input().split())) ans=0 for i in range(n,0,-1): if(A[i]<=0):continue x=int(i/2) A[x]-=A[i] ans+=A[i] if i%2==1: A[i-1]-=A[i] A[i]=0 print(ans) # Made By Mostafa_Khaled ```
output
1
92,952
24
185,905
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two pirates Polycarpus and Vasily play a very interesting game. They have n chests with coins, the chests are numbered with integers from 1 to n. Chest number i has ai coins. Polycarpus and Vasily move in turns. Polycarpus moves first. During a move a player is allowed to choose a positive integer x (2·x + 1 ≤ n) and take a coin from each chest with numbers x, 2·x, 2·x + 1. It may turn out that some chest has no coins, in this case the player doesn't take a coin from this chest. The game finishes when all chests get emptied. Polycarpus isn't a greedy scrooge. Polycarpys is a lazy slob. So he wonders in what minimum number of moves the game can finish. Help Polycarpus, determine the minimum number of moves in which the game can finish. Note that Polycarpus counts not only his moves, he also counts Vasily's moves. Input The first line contains a single integer n (1 ≤ n ≤ 100) — the number of chests with coins. The second line contains a sequence of space-separated integers: a1, a2, ..., an (1 ≤ ai ≤ 1000), where ai is the number of coins in the chest number i at the beginning of the game. Output Print a single integer — the minimum number of moves needed to finish the game. If no sequence of turns leads to finishing the game, print -1. Examples Input 1 1 Output -1 Input 3 1 2 3 Output 3 Note In the first test case there isn't a single move that can be made. That's why the players won't be able to empty the chests. In the second sample there is only one possible move x = 1. This move should be repeated at least 3 times to empty the third chest. Submitted Solution: ``` # it was stupid to think using brute intuitions, like pick first or last greedily, # greddy must follow observation, so you also had the observation that have to do it from last # instead you picked in random all order, those greedy after thought solutions never work!,its not cp n=int(input()) if n==1 or n%2==0: # print("ghe") print(-1) exit(0) a=list(map(int,input().split(' '))) # so the last element, has to be made 0, greedily, first, so by induction, it has proof, a=[0]+a # this is very ine elegant implementation ans=0 for j in range(n,0,-1): if j%2==1: i=(j-1)//2 ans+=a[2*i+1] mina=min(a[i],a[2*i],a[2*i+1]) a[i],a[2*i],a[2*i+1]=a[i]-mina,a[2*i]-mina,a[2*i+1]-mina if a[2*i+1]>0: nonzero=0 if a[i]>0: a[i]=max(0,a[i]-a[2*i+1]) else: a[2*i]=max(0,a[2*i]-a[2*i+1]) a[2*i+1]=0 else: i=(j)//2 if 2*i+1>n: # print("hemlo") print(-1) exit(0) ans+=a[2*i] mina=min(a[i],a[2*i],a[2*i+1]) a[i],a[2*i],a[2*i+1]=a[i]-mina,a[2*i]-mina,a[2*i+1]-mina if a[2*i]>0: a[i]=max(0,a[i]-a[2*i]) a[2*i]=0 # print(a)/ if any(a): print(-1) else: print(ans) ```
instruction
0
92,953
24
185,906
Yes
output
1
92,953
24
185,907
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two pirates Polycarpus and Vasily play a very interesting game. They have n chests with coins, the chests are numbered with integers from 1 to n. Chest number i has ai coins. Polycarpus and Vasily move in turns. Polycarpus moves first. During a move a player is allowed to choose a positive integer x (2·x + 1 ≤ n) and take a coin from each chest with numbers x, 2·x, 2·x + 1. It may turn out that some chest has no coins, in this case the player doesn't take a coin from this chest. The game finishes when all chests get emptied. Polycarpus isn't a greedy scrooge. Polycarpys is a lazy slob. So he wonders in what minimum number of moves the game can finish. Help Polycarpus, determine the minimum number of moves in which the game can finish. Note that Polycarpus counts not only his moves, he also counts Vasily's moves. Input The first line contains a single integer n (1 ≤ n ≤ 100) — the number of chests with coins. The second line contains a sequence of space-separated integers: a1, a2, ..., an (1 ≤ ai ≤ 1000), where ai is the number of coins in the chest number i at the beginning of the game. Output Print a single integer — the minimum number of moves needed to finish the game. If no sequence of turns leads to finishing the game, print -1. Examples Input 1 1 Output -1 Input 3 1 2 3 Output 3 Note In the first test case there isn't a single move that can be made. That's why the players won't be able to empty the chests. In the second sample there is only one possible move x = 1. This move should be repeated at least 3 times to empty the third chest. Submitted Solution: ``` import math a_sum = 0 n = int(input()) a = [0]+[int(i) for i in input().split()] if n%2 ==0 or n==1: print(-1) exit() else: i = n while i>3: if a[i] >= a[i-1]: if a[i]>0: a_sum += a[i] a[(i - 1) // 2] = a[(i - 1) // 2] - a[i] else: if a[i-1]>0: a_sum += a[i-1] a[(i - 1) // 2] = a[(i - 1) // 2] - a[i - 1] a[n] =0 a[n-1]=0 i -= 1 i-=1 a_max = a[3] if a[2]> a[3]: a_max = a[2] if a[1]>a_max: a_max = a[1] if a_max>0: a_sum+=a_max print(a_sum) exit() ```
instruction
0
92,954
24
185,908
Yes
output
1
92,954
24
185,909
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two pirates Polycarpus and Vasily play a very interesting game. They have n chests with coins, the chests are numbered with integers from 1 to n. Chest number i has ai coins. Polycarpus and Vasily move in turns. Polycarpus moves first. During a move a player is allowed to choose a positive integer x (2·x + 1 ≤ n) and take a coin from each chest with numbers x, 2·x, 2·x + 1. It may turn out that some chest has no coins, in this case the player doesn't take a coin from this chest. The game finishes when all chests get emptied. Polycarpus isn't a greedy scrooge. Polycarpys is a lazy slob. So he wonders in what minimum number of moves the game can finish. Help Polycarpus, determine the minimum number of moves in which the game can finish. Note that Polycarpus counts not only his moves, he also counts Vasily's moves. Input The first line contains a single integer n (1 ≤ n ≤ 100) — the number of chests with coins. The second line contains a sequence of space-separated integers: a1, a2, ..., an (1 ≤ ai ≤ 1000), where ai is the number of coins in the chest number i at the beginning of the game. Output Print a single integer — the minimum number of moves needed to finish the game. If no sequence of turns leads to finishing the game, print -1. Examples Input 1 1 Output -1 Input 3 1 2 3 Output 3 Note In the first test case there isn't a single move that can be made. That's why the players won't be able to empty the chests. In the second sample there is only one possible move x = 1. This move should be repeated at least 3 times to empty the third chest. Submitted Solution: ``` #!/usr/bin/python3 n = int(input()) a = [0] + list(map(int, input().split())) if len(a) < 3 or n % 2 == 0: print(-1) else: ans = 0 for x in range(n // 2, 0, -1): d = max(a[2 * x], a[2 * x + 1]) if d > 0: ans += d a[x] -= d print(ans) ```
instruction
0
92,955
24
185,910
No
output
1
92,955
24
185,911
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two pirates Polycarpus and Vasily play a very interesting game. They have n chests with coins, the chests are numbered with integers from 1 to n. Chest number i has ai coins. Polycarpus and Vasily move in turns. Polycarpus moves first. During a move a player is allowed to choose a positive integer x (2·x + 1 ≤ n) and take a coin from each chest with numbers x, 2·x, 2·x + 1. It may turn out that some chest has no coins, in this case the player doesn't take a coin from this chest. The game finishes when all chests get emptied. Polycarpus isn't a greedy scrooge. Polycarpys is a lazy slob. So he wonders in what minimum number of moves the game can finish. Help Polycarpus, determine the minimum number of moves in which the game can finish. Note that Polycarpus counts not only his moves, he also counts Vasily's moves. Input The first line contains a single integer n (1 ≤ n ≤ 100) — the number of chests with coins. The second line contains a sequence of space-separated integers: a1, a2, ..., an (1 ≤ ai ≤ 1000), where ai is the number of coins in the chest number i at the beginning of the game. Output Print a single integer — the minimum number of moves needed to finish the game. If no sequence of turns leads to finishing the game, print -1. Examples Input 1 1 Output -1 Input 3 1 2 3 Output 3 Note In the first test case there isn't a single move that can be made. That's why the players won't be able to empty the chests. In the second sample there is only one possible move x = 1. This move should be repeated at least 3 times to empty the third chest. Submitted Solution: ``` t = int(input()) line = input() ar = line.split() ar = [int(i) for i in ar] ar = sorted(ar) f = int((t-1)/2) p = (2*f)+1 count = 0 i = p while i > 0 and f != 0 : if sum(ar) == 0 : break j = t-1 while j >= 0 : if ar[j] >= i : count = count + int(ar[j]/i) ar[j] = ar[j]%i j = j-1 i = i-1 if sum(ar) == 0 : print(count) else : print(-1) ```
instruction
0
92,956
24
185,912
No
output
1
92,956
24
185,913