message stringlengths 2 65.1k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 0 108k | cluster float64 14 14 | __index_level_0__ int64 0 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Statistics claims that students sleep no more than three hours a day. But even in the world of their dreams, while they are snoring peacefully, the sense of impending doom is still upon them.
A poor student is dreaming that he is sitting the mathematical analysis exam. And he is examined by the most formidable professor of all times, a three times Soviet Union Hero, a Noble Prize laureate in student expulsion, venerable Petr Palych.
The poor student couldn't answer a single question. Thus, instead of a large spacious office he is going to apply for a job to thorium mines. But wait a minute! Petr Palych decided to give the student the last chance! Yes, that is possible only in dreams.
So the professor began: "Once a Venusian girl and a Marsian boy met on the Earth and decided to take a walk holding hands. But the problem is the girl has al fingers on her left hand and ar fingers on the right one. The boy correspondingly has bl and br fingers. They can only feel comfortable when holding hands, when no pair of the girl's fingers will touch each other. That is, they are comfortable when between any two girl's fingers there is a boy's finger. And in addition, no three fingers of the boy should touch each other. Determine if they can hold hands so that the both were comfortable."
The boy any the girl don't care who goes to the left and who goes to the right. The difference is only that if the boy goes to the left of the girl, he will take her left hand with his right one, and if he goes to the right of the girl, then it is vice versa.
Input
The first line contains two positive integers not exceeding 100. They are the number of fingers on the Venusian girl's left and right hand correspondingly. The second line contains two integers not exceeding 100. They are the number of fingers on the Marsian boy's left and right hands correspondingly.
Output
Print YES or NO, that is, the answer to Petr Palych's question.
Examples
Input
5 1
10 5
Output
YES
Input
4 5
3 3
Output
YES
Input
1 2
11 6
Output
NO
Note
The boy and the girl don't really care who goes to the left.
Submitted Solution:
```
m,n=map(int,input().split())
k,p=map(int,input().split())
l=0
if ((m - p)<2)and((p - m)<=(p+1)*2):
l+=1
if (n -k<2)or(k - n<=(n+1)*2):
l+=1
if l<1:
print('YES')
else:print('NO')
``` | instruction | 0 | 34,762 | 14 | 69,524 |
No | output | 1 | 34,762 | 14 | 69,525 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Statistics claims that students sleep no more than three hours a day. But even in the world of their dreams, while they are snoring peacefully, the sense of impending doom is still upon them.
A poor student is dreaming that he is sitting the mathematical analysis exam. And he is examined by the most formidable professor of all times, a three times Soviet Union Hero, a Noble Prize laureate in student expulsion, venerable Petr Palych.
The poor student couldn't answer a single question. Thus, instead of a large spacious office he is going to apply for a job to thorium mines. But wait a minute! Petr Palych decided to give the student the last chance! Yes, that is possible only in dreams.
So the professor began: "Once a Venusian girl and a Marsian boy met on the Earth and decided to take a walk holding hands. But the problem is the girl has al fingers on her left hand and ar fingers on the right one. The boy correspondingly has bl and br fingers. They can only feel comfortable when holding hands, when no pair of the girl's fingers will touch each other. That is, they are comfortable when between any two girl's fingers there is a boy's finger. And in addition, no three fingers of the boy should touch each other. Determine if they can hold hands so that the both were comfortable."
The boy any the girl don't care who goes to the left and who goes to the right. The difference is only that if the boy goes to the left of the girl, he will take her left hand with his right one, and if he goes to the right of the girl, then it is vice versa.
Input
The first line contains two positive integers not exceeding 100. They are the number of fingers on the Venusian girl's left and right hand correspondingly. The second line contains two integers not exceeding 100. They are the number of fingers on the Marsian boy's left and right hands correspondingly.
Output
Print YES or NO, that is, the answer to Petr Palych's question.
Examples
Input
5 1
10 5
Output
YES
Input
4 5
3 3
Output
YES
Input
1 2
11 6
Output
NO
Note
The boy and the girl don't really care who goes to the left.
Submitted Solution:
```
m,n=map(int,input().split())
k,p=map(int,input().split())
l=0
if ((m // p)>=1)or((p // m)>=3):
l+=1
if (n // k>=1)or(k // n>=3):
l+=1
if l>1:
print('NO')
else:print('YES')
``` | instruction | 0 | 34,763 | 14 | 69,526 |
No | output | 1 | 34,763 | 14 | 69,527 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In Arcady's garden there grows a peculiar apple-tree that fruits one time per year. Its peculiarity can be explained in following way: there are n inflorescences, numbered from 1 to n. Inflorescence number 1 is situated near base of tree and any other inflorescence with number i (i > 1) is situated at the top of branch, which bottom is pi-th inflorescence and pi < i.
Once tree starts fruiting, there appears exactly one apple in each inflorescence. The same moment as apples appear, they start to roll down along branches to the very base of tree. Each second all apples, except ones in first inflorescence simultaneously roll down one branch closer to tree base, e.g. apple in a-th inflorescence gets to pa-th inflorescence. Apples that end up in first inflorescence are gathered by Arcady in exactly the same moment. Second peculiarity of this tree is that once two apples are in same inflorescence they annihilate. This happens with each pair of apples, e.g. if there are 5 apples in same inflorescence in same time, only one will not be annihilated and if there are 8 apples, all apples will be annihilated. Thus, there can be no more than one apple in each inflorescence in each moment of time.
Help Arcady with counting number of apples he will be able to collect from first inflorescence during one harvest.
Input
First line of input contains single integer number n (2 β€ n β€ 100 000) β number of inflorescences.
Second line of input contains sequence of n - 1 integer numbers p2, p3, ..., pn (1 β€ pi < i), where pi is number of inflorescence into which the apple from i-th inflorescence rolls down.
Output
Single line of output should contain one integer number: amount of apples that Arcady will be able to collect from first inflorescence during one harvest.
Examples
Input
3
1 1
Output
1
Input
5
1 2 2 2
Output
3
Input
18
1 1 1 4 4 3 2 2 2 10 8 9 9 9 10 10 4
Output
4
Note
In first example Arcady will be able to collect only one apple, initially situated in 1st inflorescence. In next second apples from 2nd and 3rd inflorescences will roll down and annihilate, and Arcady won't be able to collect them.
In the second example Arcady will be able to collect 3 apples. First one is one initially situated in first inflorescence. In a second apple from 2nd inflorescence will roll down to 1st (Arcady will collect it) and apples from 3rd, 4th, 5th inflorescences will roll down to 2nd. Two of them will annihilate and one not annihilated will roll down from 2-nd inflorescence to 1st one in the next second and Arcady will collect it. | instruction | 0 | 34,865 | 14 | 69,730 |
Tags: dfs and similar, graphs, trees
Correct Solution:
```
from collections import deque
n = int(input())
parents = [0, 0] + [int(x) for x in input().split()]
children = [set([]) for _ in range(n + 1)]
for i, p in enumerate(parents):
children[p].add(i)
q = deque([(0, 1)])
levels = [0 for _ in range(n + 1)]
maxLevel = 0
while len(q) > 0:
level, node = q.popleft()
levels[node] = level
maxLevel = max(maxLevel, level)
for i in children[node]:
q.append((level + 1, i))
levels2 = [0 for _ in range(maxLevel + 1)]
for i in levels[1:]:
levels2[i] += 1
print(sum([i % 2 for i in levels2]))
``` | output | 1 | 34,865 | 14 | 69,731 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In Arcady's garden there grows a peculiar apple-tree that fruits one time per year. Its peculiarity can be explained in following way: there are n inflorescences, numbered from 1 to n. Inflorescence number 1 is situated near base of tree and any other inflorescence with number i (i > 1) is situated at the top of branch, which bottom is pi-th inflorescence and pi < i.
Once tree starts fruiting, there appears exactly one apple in each inflorescence. The same moment as apples appear, they start to roll down along branches to the very base of tree. Each second all apples, except ones in first inflorescence simultaneously roll down one branch closer to tree base, e.g. apple in a-th inflorescence gets to pa-th inflorescence. Apples that end up in first inflorescence are gathered by Arcady in exactly the same moment. Second peculiarity of this tree is that once two apples are in same inflorescence they annihilate. This happens with each pair of apples, e.g. if there are 5 apples in same inflorescence in same time, only one will not be annihilated and if there are 8 apples, all apples will be annihilated. Thus, there can be no more than one apple in each inflorescence in each moment of time.
Help Arcady with counting number of apples he will be able to collect from first inflorescence during one harvest.
Input
First line of input contains single integer number n (2 β€ n β€ 100 000) β number of inflorescences.
Second line of input contains sequence of n - 1 integer numbers p2, p3, ..., pn (1 β€ pi < i), where pi is number of inflorescence into which the apple from i-th inflorescence rolls down.
Output
Single line of output should contain one integer number: amount of apples that Arcady will be able to collect from first inflorescence during one harvest.
Examples
Input
3
1 1
Output
1
Input
5
1 2 2 2
Output
3
Input
18
1 1 1 4 4 3 2 2 2 10 8 9 9 9 10 10 4
Output
4
Note
In first example Arcady will be able to collect only one apple, initially situated in 1st inflorescence. In next second apples from 2nd and 3rd inflorescences will roll down and annihilate, and Arcady won't be able to collect them.
In the second example Arcady will be able to collect 3 apples. First one is one initially situated in first inflorescence. In a second apple from 2nd inflorescence will roll down to 1st (Arcady will collect it) and apples from 3rd, 4th, 5th inflorescences will roll down to 2nd. Two of them will annihilate and one not annihilated will roll down from 2-nd inflorescence to 1st one in the next second and Arcady will collect it. | instruction | 0 | 34,866 | 14 | 69,732 |
Tags: dfs and similar, graphs, trees
Correct Solution:
```
import sys
import threading
from collections import defaultdict,deque
n=int(input())
arr=list(map(int,input().split()))
adj=defaultdict(list)
for i,j in enumerate(arr):
adj[j].append(i+2)
#print(adj)
def fun():
ans=0
q=deque([None,1])
while(len(q)>1):
x=q.popleft()
if x:
if adj.get(x,None):
for ch in adj[x]:
q.append(ch)
else:
if len(q)&1:
ans+=1
q.append(x)
return ans
def main():
# print()
print(fun())
if __name__=="__main__":
sys.setrecursionlimit(10**6)
threading.stack_size(10**8)
t = threading.Thread(target=main)
t.start()
t.join()
``` | output | 1 | 34,866 | 14 | 69,733 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In Arcady's garden there grows a peculiar apple-tree that fruits one time per year. Its peculiarity can be explained in following way: there are n inflorescences, numbered from 1 to n. Inflorescence number 1 is situated near base of tree and any other inflorescence with number i (i > 1) is situated at the top of branch, which bottom is pi-th inflorescence and pi < i.
Once tree starts fruiting, there appears exactly one apple in each inflorescence. The same moment as apples appear, they start to roll down along branches to the very base of tree. Each second all apples, except ones in first inflorescence simultaneously roll down one branch closer to tree base, e.g. apple in a-th inflorescence gets to pa-th inflorescence. Apples that end up in first inflorescence are gathered by Arcady in exactly the same moment. Second peculiarity of this tree is that once two apples are in same inflorescence they annihilate. This happens with each pair of apples, e.g. if there are 5 apples in same inflorescence in same time, only one will not be annihilated and if there are 8 apples, all apples will be annihilated. Thus, there can be no more than one apple in each inflorescence in each moment of time.
Help Arcady with counting number of apples he will be able to collect from first inflorescence during one harvest.
Input
First line of input contains single integer number n (2 β€ n β€ 100 000) β number of inflorescences.
Second line of input contains sequence of n - 1 integer numbers p2, p3, ..., pn (1 β€ pi < i), where pi is number of inflorescence into which the apple from i-th inflorescence rolls down.
Output
Single line of output should contain one integer number: amount of apples that Arcady will be able to collect from first inflorescence during one harvest.
Examples
Input
3
1 1
Output
1
Input
5
1 2 2 2
Output
3
Input
18
1 1 1 4 4 3 2 2 2 10 8 9 9 9 10 10 4
Output
4
Note
In first example Arcady will be able to collect only one apple, initially situated in 1st inflorescence. In next second apples from 2nd and 3rd inflorescences will roll down and annihilate, and Arcady won't be able to collect them.
In the second example Arcady will be able to collect 3 apples. First one is one initially situated in first inflorescence. In a second apple from 2nd inflorescence will roll down to 1st (Arcady will collect it) and apples from 3rd, 4th, 5th inflorescences will roll down to 2nd. Two of them will annihilate and one not annihilated will roll down from 2-nd inflorescence to 1st one in the next second and Arcady will collect it. | instruction | 0 | 34,867 | 14 | 69,734 |
Tags: dfs and similar, graphs, trees
Correct Solution:
```
inflos = int(input())
parent = tuple(int(x) - 1 for x in input().split())
depth = [0]
for v in range(inflos - 1):
depth.append(depth[parent[v]] + 1)
freq = {}
for d in depth:
if d in freq:
freq[d] += 1
else:
freq[d] = 1
res = 0
for d in freq:
res+= freq[d]%2
print(res)
``` | output | 1 | 34,867 | 14 | 69,735 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In Arcady's garden there grows a peculiar apple-tree that fruits one time per year. Its peculiarity can be explained in following way: there are n inflorescences, numbered from 1 to n. Inflorescence number 1 is situated near base of tree and any other inflorescence with number i (i > 1) is situated at the top of branch, which bottom is pi-th inflorescence and pi < i.
Once tree starts fruiting, there appears exactly one apple in each inflorescence. The same moment as apples appear, they start to roll down along branches to the very base of tree. Each second all apples, except ones in first inflorescence simultaneously roll down one branch closer to tree base, e.g. apple in a-th inflorescence gets to pa-th inflorescence. Apples that end up in first inflorescence are gathered by Arcady in exactly the same moment. Second peculiarity of this tree is that once two apples are in same inflorescence they annihilate. This happens with each pair of apples, e.g. if there are 5 apples in same inflorescence in same time, only one will not be annihilated and if there are 8 apples, all apples will be annihilated. Thus, there can be no more than one apple in each inflorescence in each moment of time.
Help Arcady with counting number of apples he will be able to collect from first inflorescence during one harvest.
Input
First line of input contains single integer number n (2 β€ n β€ 100 000) β number of inflorescences.
Second line of input contains sequence of n - 1 integer numbers p2, p3, ..., pn (1 β€ pi < i), where pi is number of inflorescence into which the apple from i-th inflorescence rolls down.
Output
Single line of output should contain one integer number: amount of apples that Arcady will be able to collect from first inflorescence during one harvest.
Examples
Input
3
1 1
Output
1
Input
5
1 2 2 2
Output
3
Input
18
1 1 1 4 4 3 2 2 2 10 8 9 9 9 10 10 4
Output
4
Note
In first example Arcady will be able to collect only one apple, initially situated in 1st inflorescence. In next second apples from 2nd and 3rd inflorescences will roll down and annihilate, and Arcady won't be able to collect them.
In the second example Arcady will be able to collect 3 apples. First one is one initially situated in first inflorescence. In a second apple from 2nd inflorescence will roll down to 1st (Arcady will collect it) and apples from 3rd, 4th, 5th inflorescences will roll down to 2nd. Two of them will annihilate and one not annihilated will roll down from 2-nd inflorescence to 1st one in the next second and Arcady will collect it. | instruction | 0 | 34,868 | 14 | 69,736 |
Tags: dfs and similar, graphs, trees
Correct Solution:
```
import sys
from collections import defaultdict
from collections import deque
input = sys.stdin.readline
def solve(parents, n):
childs = defaultdict(list)
for i in range(n-1):
childs[parents[i]].append(i+1)
root = 0
nodes = [root]
cnt = 0
while nodes:
cnt += len(nodes) % 2
temp_nodes = []
for node in nodes:
for child in childs[node]:
temp_nodes.append(child)
nodes = temp_nodes
return cnt
if __name__ == "__main__":
n = int(input())
parents = [int(el)-1 for el in input().split()]
print(solve(parents, n))
``` | output | 1 | 34,868 | 14 | 69,737 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In Arcady's garden there grows a peculiar apple-tree that fruits one time per year. Its peculiarity can be explained in following way: there are n inflorescences, numbered from 1 to n. Inflorescence number 1 is situated near base of tree and any other inflorescence with number i (i > 1) is situated at the top of branch, which bottom is pi-th inflorescence and pi < i.
Once tree starts fruiting, there appears exactly one apple in each inflorescence. The same moment as apples appear, they start to roll down along branches to the very base of tree. Each second all apples, except ones in first inflorescence simultaneously roll down one branch closer to tree base, e.g. apple in a-th inflorescence gets to pa-th inflorescence. Apples that end up in first inflorescence are gathered by Arcady in exactly the same moment. Second peculiarity of this tree is that once two apples are in same inflorescence they annihilate. This happens with each pair of apples, e.g. if there are 5 apples in same inflorescence in same time, only one will not be annihilated and if there are 8 apples, all apples will be annihilated. Thus, there can be no more than one apple in each inflorescence in each moment of time.
Help Arcady with counting number of apples he will be able to collect from first inflorescence during one harvest.
Input
First line of input contains single integer number n (2 β€ n β€ 100 000) β number of inflorescences.
Second line of input contains sequence of n - 1 integer numbers p2, p3, ..., pn (1 β€ pi < i), where pi is number of inflorescence into which the apple from i-th inflorescence rolls down.
Output
Single line of output should contain one integer number: amount of apples that Arcady will be able to collect from first inflorescence during one harvest.
Examples
Input
3
1 1
Output
1
Input
5
1 2 2 2
Output
3
Input
18
1 1 1 4 4 3 2 2 2 10 8 9 9 9 10 10 4
Output
4
Note
In first example Arcady will be able to collect only one apple, initially situated in 1st inflorescence. In next second apples from 2nd and 3rd inflorescences will roll down and annihilate, and Arcady won't be able to collect them.
In the second example Arcady will be able to collect 3 apples. First one is one initially situated in first inflorescence. In a second apple from 2nd inflorescence will roll down to 1st (Arcady will collect it) and apples from 3rd, 4th, 5th inflorescences will roll down to 2nd. Two of them will annihilate and one not annihilated will roll down from 2-nd inflorescence to 1st one in the next second and Arcady will collect it. | instruction | 0 | 34,869 | 14 | 69,738 |
Tags: dfs and similar, graphs, trees
Correct Solution:
```
import threading
import sys
threading.stack_size(2 ** 26)
sys.setrecursionlimit(10 ** 9)
n = int(input())
graph = [[] for i in range(n)]
prev = list(map(int, input().split()))
s = [0] * n
def dfs(v, level):
for u in graph[v]:
dfs(u, level + 1)
s[level] += 1
def main():
ans = 0
for i in range(n - 1):
graph[prev[i] - 1].append(i + 1)
dfs(0, 0)
for i in s:
if i % 2 != 0:
ans += 1
print(ans)
tread = threading.Thread(target=main)
tread.start()
``` | output | 1 | 34,869 | 14 | 69,739 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In Arcady's garden there grows a peculiar apple-tree that fruits one time per year. Its peculiarity can be explained in following way: there are n inflorescences, numbered from 1 to n. Inflorescence number 1 is situated near base of tree and any other inflorescence with number i (i > 1) is situated at the top of branch, which bottom is pi-th inflorescence and pi < i.
Once tree starts fruiting, there appears exactly one apple in each inflorescence. The same moment as apples appear, they start to roll down along branches to the very base of tree. Each second all apples, except ones in first inflorescence simultaneously roll down one branch closer to tree base, e.g. apple in a-th inflorescence gets to pa-th inflorescence. Apples that end up in first inflorescence are gathered by Arcady in exactly the same moment. Second peculiarity of this tree is that once two apples are in same inflorescence they annihilate. This happens with each pair of apples, e.g. if there are 5 apples in same inflorescence in same time, only one will not be annihilated and if there are 8 apples, all apples will be annihilated. Thus, there can be no more than one apple in each inflorescence in each moment of time.
Help Arcady with counting number of apples he will be able to collect from first inflorescence during one harvest.
Input
First line of input contains single integer number n (2 β€ n β€ 100 000) β number of inflorescences.
Second line of input contains sequence of n - 1 integer numbers p2, p3, ..., pn (1 β€ pi < i), where pi is number of inflorescence into which the apple from i-th inflorescence rolls down.
Output
Single line of output should contain one integer number: amount of apples that Arcady will be able to collect from first inflorescence during one harvest.
Examples
Input
3
1 1
Output
1
Input
5
1 2 2 2
Output
3
Input
18
1 1 1 4 4 3 2 2 2 10 8 9 9 9 10 10 4
Output
4
Note
In first example Arcady will be able to collect only one apple, initially situated in 1st inflorescence. In next second apples from 2nd and 3rd inflorescences will roll down and annihilate, and Arcady won't be able to collect them.
In the second example Arcady will be able to collect 3 apples. First one is one initially situated in first inflorescence. In a second apple from 2nd inflorescence will roll down to 1st (Arcady will collect it) and apples from 3rd, 4th, 5th inflorescences will roll down to 2nd. Two of them will annihilate and one not annihilated will roll down from 2-nd inflorescence to 1st one in the next second and Arcady will collect it. | instruction | 0 | 34,870 | 14 | 69,740 |
Tags: dfs and similar, graphs, trees
Correct Solution:
```
tree = []
class Node:
def __init__(self, num):
self.parent = num - 1
self.length = 0
def add_to_tree(self):
if self.parent < 0:
return
self.length = tree[self.parent].length + 1
def main():
n = int(input())
global tree
tree = [Node(0)] + [Node(int(x)) for x in input().split()]
for i in tree:
i.add_to_tree()
amount = [0] * n
for i in [x.length for x in tree]:
amount[i] += 1
print(sum([x & 1 for x in amount]))
if __name__ == "__main__":
main()
``` | output | 1 | 34,870 | 14 | 69,741 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In Arcady's garden there grows a peculiar apple-tree that fruits one time per year. Its peculiarity can be explained in following way: there are n inflorescences, numbered from 1 to n. Inflorescence number 1 is situated near base of tree and any other inflorescence with number i (i > 1) is situated at the top of branch, which bottom is pi-th inflorescence and pi < i.
Once tree starts fruiting, there appears exactly one apple in each inflorescence. The same moment as apples appear, they start to roll down along branches to the very base of tree. Each second all apples, except ones in first inflorescence simultaneously roll down one branch closer to tree base, e.g. apple in a-th inflorescence gets to pa-th inflorescence. Apples that end up in first inflorescence are gathered by Arcady in exactly the same moment. Second peculiarity of this tree is that once two apples are in same inflorescence they annihilate. This happens with each pair of apples, e.g. if there are 5 apples in same inflorescence in same time, only one will not be annihilated and if there are 8 apples, all apples will be annihilated. Thus, there can be no more than one apple in each inflorescence in each moment of time.
Help Arcady with counting number of apples he will be able to collect from first inflorescence during one harvest.
Input
First line of input contains single integer number n (2 β€ n β€ 100 000) β number of inflorescences.
Second line of input contains sequence of n - 1 integer numbers p2, p3, ..., pn (1 β€ pi < i), where pi is number of inflorescence into which the apple from i-th inflorescence rolls down.
Output
Single line of output should contain one integer number: amount of apples that Arcady will be able to collect from first inflorescence during one harvest.
Examples
Input
3
1 1
Output
1
Input
5
1 2 2 2
Output
3
Input
18
1 1 1 4 4 3 2 2 2 10 8 9 9 9 10 10 4
Output
4
Note
In first example Arcady will be able to collect only one apple, initially situated in 1st inflorescence. In next second apples from 2nd and 3rd inflorescences will roll down and annihilate, and Arcady won't be able to collect them.
In the second example Arcady will be able to collect 3 apples. First one is one initially situated in first inflorescence. In a second apple from 2nd inflorescence will roll down to 1st (Arcady will collect it) and apples from 3rd, 4th, 5th inflorescences will roll down to 2nd. Two of them will annihilate and one not annihilated will roll down from 2-nd inflorescence to 1st one in the next second and Arcady will collect it. | instruction | 0 | 34,871 | 14 | 69,742 |
Tags: dfs and similar, graphs, trees
Correct Solution:
```
from collections import deque
n = int(input())
dist = [-1] * n
cnt = [1] + [0] * (n - 1)
sl = [[] for i in range(n)]
a = [int(x) - 1 for x in input().split()]
for i in range(n - 1):
sl[a[i]] += [i + 1]
queue = deque()
queue.append(0)
dist[0] = 0
while queue:
v = queue.popleft()
for u in sl[v]:
if dist[u] == -1:
dist[u] = dist[v] + 1
cnt[dist[u]] += 1
queue.append(u)
ans = 0
for i in cnt:
ans += i % 2
print(ans)
``` | output | 1 | 34,871 | 14 | 69,743 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In Arcady's garden there grows a peculiar apple-tree that fruits one time per year. Its peculiarity can be explained in following way: there are n inflorescences, numbered from 1 to n. Inflorescence number 1 is situated near base of tree and any other inflorescence with number i (i > 1) is situated at the top of branch, which bottom is pi-th inflorescence and pi < i.
Once tree starts fruiting, there appears exactly one apple in each inflorescence. The same moment as apples appear, they start to roll down along branches to the very base of tree. Each second all apples, except ones in first inflorescence simultaneously roll down one branch closer to tree base, e.g. apple in a-th inflorescence gets to pa-th inflorescence. Apples that end up in first inflorescence are gathered by Arcady in exactly the same moment. Second peculiarity of this tree is that once two apples are in same inflorescence they annihilate. This happens with each pair of apples, e.g. if there are 5 apples in same inflorescence in same time, only one will not be annihilated and if there are 8 apples, all apples will be annihilated. Thus, there can be no more than one apple in each inflorescence in each moment of time.
Help Arcady with counting number of apples he will be able to collect from first inflorescence during one harvest.
Input
First line of input contains single integer number n (2 β€ n β€ 100 000) β number of inflorescences.
Second line of input contains sequence of n - 1 integer numbers p2, p3, ..., pn (1 β€ pi < i), where pi is number of inflorescence into which the apple from i-th inflorescence rolls down.
Output
Single line of output should contain one integer number: amount of apples that Arcady will be able to collect from first inflorescence during one harvest.
Examples
Input
3
1 1
Output
1
Input
5
1 2 2 2
Output
3
Input
18
1 1 1 4 4 3 2 2 2 10 8 9 9 9 10 10 4
Output
4
Note
In first example Arcady will be able to collect only one apple, initially situated in 1st inflorescence. In next second apples from 2nd and 3rd inflorescences will roll down and annihilate, and Arcady won't be able to collect them.
In the second example Arcady will be able to collect 3 apples. First one is one initially situated in first inflorescence. In a second apple from 2nd inflorescence will roll down to 1st (Arcady will collect it) and apples from 3rd, 4th, 5th inflorescences will roll down to 2nd. Two of them will annihilate and one not annihilated will roll down from 2-nd inflorescence to 1st one in the next second and Arcady will collect it. | instruction | 0 | 34,872 | 14 | 69,744 |
Tags: dfs and similar, graphs, trees
Correct Solution:
```
#import sys
from collections import defaultdict
#from io import StringIO
#sys.stdin = StringIO(open(__file__.replace('.py', '.in')).read())
n = int(input())
a = list(map(int, input().split()))
d = {1: 1}
ls = defaultdict(int)
ls[1] = 1
for i in range(n-1):
d[i + 2] = d[a[i]] + 1
ls[d[a[i]] + 1] += 1
print(sum(1 for k, v in ls.items() if v % 2 == 1))
``` | output | 1 | 34,872 | 14 | 69,745 |
Provide a correct Python 3 solution for this coding contest problem.
I am a pipe tie craftsman. As long as you get the joints and pipes that connect the pipes, you can connect any pipe. Every day, my master gives me pipes and joints, which I connect and give to my master. But if you have too many pipes, you can't connect them all in one day. Even in such a case, the master smiles and gives me a salary.
By the way, I noticed something strange at one point. Often, the salary is higher when all the pipes are not connected than when they are all connected. It's so weird that one day when my boss came, I secretly saw a memo that describes how to calculate my salary. Then, how
"The salary is paid by" the number of pipes x the total length of pipes ". However, if they are connected by a joint and become one, it is regarded as one pipe. "
It was written. Now I understand why the salary may be cheaper if you connect them all. For example, as shown in the figure below, if you connect all three pipes of length 1 and two joints of length 2 to make one pipe of length 1 + 2 + 1 + 2 + 1 = 7, 1 Γ (7) ) = 7. However, if you use only one joint and make two pipes with a length of 1 + 2 + 1 = 4 and a pipe with a length of 1, 2 Γ (4 + 1) = 10, so you will get more salary than connecting all of them. ..
<image>
I don't know why my boss decides my salary this way, but I know how I can get more salary!
Now, create a program that calculates the maximum amount of salary you can get given the number of pipes.
input
The input consists of multiple datasets. The end of the input is indicated by a single zero line. Each dataset is given in the following format.
n
p1 ... pn
j1 ... jn-1
The number of pipes n (2 β€ n β€ 65000) is given in the first line. The second line consists of n integers separated by a single space. pi (1 β€ pi β€ 1000) indicates the length of the i-th pipe. The third line consists of n-1 integers separated by one space. ji (1 β€ ji β€ 1000) indicates the length of the i-th joint.
The i-th joint can connect only the i-th and i + 1-th pipes. The length of the connected pipe is pi + ji + pi + 1.
The number of datasets does not exceed 100.
output
For each dataset, print the maximum amount of salary you can get on one line. For datasets given as input, the output value must always fall within the range of 32-bit unsigned integers.
Example
Input
3
1 1 1
3 3
4
3 3 3 3
1 1 1
5
1 2 3 4 5
4 3 2 1
0
Output
12
48
76 | instruction | 0 | 35,075 | 14 | 70,150 |
"Correct Solution:
```
while 1:
n = int(input())
if n == 0:break
l = sum(map(int, input().split()))
j = sorted(map(int, input().split()), reverse = True)
d = [0] * n
for i in range(n):
d[i] = (l + sum(j[:i])) * (n - i)
if d[i] < d[i - 1]:
print(d[i - 1])
break
else:print(d[-1])
``` | output | 1 | 35,075 | 14 | 70,151 |
Provide a correct Python 3 solution for this coding contest problem.
I am a pipe tie craftsman. As long as you get the joints and pipes that connect the pipes, you can connect any pipe. Every day, my master gives me pipes and joints, which I connect and give to my master. But if you have too many pipes, you can't connect them all in one day. Even in such a case, the master smiles and gives me a salary.
By the way, I noticed something strange at one point. Often, the salary is higher when all the pipes are not connected than when they are all connected. It's so weird that one day when my boss came, I secretly saw a memo that describes how to calculate my salary. Then, how
"The salary is paid by" the number of pipes x the total length of pipes ". However, if they are connected by a joint and become one, it is regarded as one pipe. "
It was written. Now I understand why the salary may be cheaper if you connect them all. For example, as shown in the figure below, if you connect all three pipes of length 1 and two joints of length 2 to make one pipe of length 1 + 2 + 1 + 2 + 1 = 7, 1 Γ (7) ) = 7. However, if you use only one joint and make two pipes with a length of 1 + 2 + 1 = 4 and a pipe with a length of 1, 2 Γ (4 + 1) = 10, so you will get more salary than connecting all of them. ..
<image>
I don't know why my boss decides my salary this way, but I know how I can get more salary!
Now, create a program that calculates the maximum amount of salary you can get given the number of pipes.
input
The input consists of multiple datasets. The end of the input is indicated by a single zero line. Each dataset is given in the following format.
n
p1 ... pn
j1 ... jn-1
The number of pipes n (2 β€ n β€ 65000) is given in the first line. The second line consists of n integers separated by a single space. pi (1 β€ pi β€ 1000) indicates the length of the i-th pipe. The third line consists of n-1 integers separated by one space. ji (1 β€ ji β€ 1000) indicates the length of the i-th joint.
The i-th joint can connect only the i-th and i + 1-th pipes. The length of the connected pipe is pi + ji + pi + 1.
The number of datasets does not exceed 100.
output
For each dataset, print the maximum amount of salary you can get on one line. For datasets given as input, the output value must always fall within the range of 32-bit unsigned integers.
Example
Input
3
1 1 1
3 3
4
3 3 3 3
1 1 1
5
1 2 3 4 5
4 3 2 1
0
Output
12
48
76 | instruction | 0 | 35,076 | 14 | 70,152 |
"Correct Solution:
```
while True:
n = int(input())
if n == 0:
break
p = [int(i) for i in input().split()]
j = [int(i) for i in input().split()]
s = 0
for i in range(len(p)):
s += p[i]
for i in range(len(j)):
s += j[i]
ans = s
j.sort()
for i in range(len(j)):
s -= j[i]
ans = max(ans, s*(i+2))
print(ans)
``` | output | 1 | 35,076 | 14 | 70,153 |
Provide a correct Python 3 solution for this coding contest problem.
I am a pipe tie craftsman. As long as you get the joints and pipes that connect the pipes, you can connect any pipe. Every day, my master gives me pipes and joints, which I connect and give to my master. But if you have too many pipes, you can't connect them all in one day. Even in such a case, the master smiles and gives me a salary.
By the way, I noticed something strange at one point. Often, the salary is higher when all the pipes are not connected than when they are all connected. It's so weird that one day when my boss came, I secretly saw a memo that describes how to calculate my salary. Then, how
"The salary is paid by" the number of pipes x the total length of pipes ". However, if they are connected by a joint and become one, it is regarded as one pipe. "
It was written. Now I understand why the salary may be cheaper if you connect them all. For example, as shown in the figure below, if you connect all three pipes of length 1 and two joints of length 2 to make one pipe of length 1 + 2 + 1 + 2 + 1 = 7, 1 Γ (7) ) = 7. However, if you use only one joint and make two pipes with a length of 1 + 2 + 1 = 4 and a pipe with a length of 1, 2 Γ (4 + 1) = 10, so you will get more salary than connecting all of them. ..
<image>
I don't know why my boss decides my salary this way, but I know how I can get more salary!
Now, create a program that calculates the maximum amount of salary you can get given the number of pipes.
input
The input consists of multiple datasets. The end of the input is indicated by a single zero line. Each dataset is given in the following format.
n
p1 ... pn
j1 ... jn-1
The number of pipes n (2 β€ n β€ 65000) is given in the first line. The second line consists of n integers separated by a single space. pi (1 β€ pi β€ 1000) indicates the length of the i-th pipe. The third line consists of n-1 integers separated by one space. ji (1 β€ ji β€ 1000) indicates the length of the i-th joint.
The i-th joint can connect only the i-th and i + 1-th pipes. The length of the connected pipe is pi + ji + pi + 1.
The number of datasets does not exceed 100.
output
For each dataset, print the maximum amount of salary you can get on one line. For datasets given as input, the output value must always fall within the range of 32-bit unsigned integers.
Example
Input
3
1 1 1
3 3
4
3 3 3 3
1 1 1
5
1 2 3 4 5
4 3 2 1
0
Output
12
48
76 | instruction | 0 | 35,077 | 14 | 70,154 |
"Correct Solution:
```
while True:
n = int(input())
if n == 0: break
totalp = 0
P = list(map(int, input().split()))
for p in P:
totalp += p
J = list(map(int, input().split()))
maxv = 0
J.sort(reverse=True)
J.append(0); # nazo
totalj = 0
t = n
j = 0
while t >= 1:
v = t*(totalj + totalp)
totalj += J[j]
maxv = max(v, maxv)
t = t - 1
j = j + 1
print(maxv)
``` | output | 1 | 35,077 | 14 | 70,155 |
Provide a correct Python 3 solution for this coding contest problem.
I am a pipe tie craftsman. As long as you get the joints and pipes that connect the pipes, you can connect any pipe. Every day, my master gives me pipes and joints, which I connect and give to my master. But if you have too many pipes, you can't connect them all in one day. Even in such a case, the master smiles and gives me a salary.
By the way, I noticed something strange at one point. Often, the salary is higher when all the pipes are not connected than when they are all connected. It's so weird that one day when my boss came, I secretly saw a memo that describes how to calculate my salary. Then, how
"The salary is paid by" the number of pipes x the total length of pipes ". However, if they are connected by a joint and become one, it is regarded as one pipe. "
It was written. Now I understand why the salary may be cheaper if you connect them all. For example, as shown in the figure below, if you connect all three pipes of length 1 and two joints of length 2 to make one pipe of length 1 + 2 + 1 + 2 + 1 = 7, 1 Γ (7) ) = 7. However, if you use only one joint and make two pipes with a length of 1 + 2 + 1 = 4 and a pipe with a length of 1, 2 Γ (4 + 1) = 10, so you will get more salary than connecting all of them. ..
<image>
I don't know why my boss decides my salary this way, but I know how I can get more salary!
Now, create a program that calculates the maximum amount of salary you can get given the number of pipes.
input
The input consists of multiple datasets. The end of the input is indicated by a single zero line. Each dataset is given in the following format.
n
p1 ... pn
j1 ... jn-1
The number of pipes n (2 β€ n β€ 65000) is given in the first line. The second line consists of n integers separated by a single space. pi (1 β€ pi β€ 1000) indicates the length of the i-th pipe. The third line consists of n-1 integers separated by one space. ji (1 β€ ji β€ 1000) indicates the length of the i-th joint.
The i-th joint can connect only the i-th and i + 1-th pipes. The length of the connected pipe is pi + ji + pi + 1.
The number of datasets does not exceed 100.
output
For each dataset, print the maximum amount of salary you can get on one line. For datasets given as input, the output value must always fall within the range of 32-bit unsigned integers.
Example
Input
3
1 1 1
3 3
4
3 3 3 3
1 1 1
5
1 2 3 4 5
4 3 2 1
0
Output
12
48
76 | instruction | 0 | 35,078 | 14 | 70,156 |
"Correct Solution:
```
# -*- coding: utf-8 -*-
"""
Salary for a Plumber
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0260
"""
import sys
def solve(n):
pipes = [int(p) for p in input().split()]
joints = sorted([int(j) for j in input().split()])
total_length = sum(pipes)
record = total_length * n
while joints:
total_length += joints.pop()
n -= 1
if total_length * n > record:
record = total_length * n
else:
break
return record
def main(args):
while True:
n = int(input())
if n == 0:
break
ans = solve(n)
print(ans)
if __name__ == '__main__':
main(sys.argv[1:])
``` | output | 1 | 35,078 | 14 | 70,157 |
Provide a correct Python 3 solution for this coding contest problem.
I am a pipe tie craftsman. As long as you get the joints and pipes that connect the pipes, you can connect any pipe. Every day, my master gives me pipes and joints, which I connect and give to my master. But if you have too many pipes, you can't connect them all in one day. Even in such a case, the master smiles and gives me a salary.
By the way, I noticed something strange at one point. Often, the salary is higher when all the pipes are not connected than when they are all connected. It's so weird that one day when my boss came, I secretly saw a memo that describes how to calculate my salary. Then, how
"The salary is paid by" the number of pipes x the total length of pipes ". However, if they are connected by a joint and become one, it is regarded as one pipe. "
It was written. Now I understand why the salary may be cheaper if you connect them all. For example, as shown in the figure below, if you connect all three pipes of length 1 and two joints of length 2 to make one pipe of length 1 + 2 + 1 + 2 + 1 = 7, 1 Γ (7) ) = 7. However, if you use only one joint and make two pipes with a length of 1 + 2 + 1 = 4 and a pipe with a length of 1, 2 Γ (4 + 1) = 10, so you will get more salary than connecting all of them. ..
<image>
I don't know why my boss decides my salary this way, but I know how I can get more salary!
Now, create a program that calculates the maximum amount of salary you can get given the number of pipes.
input
The input consists of multiple datasets. The end of the input is indicated by a single zero line. Each dataset is given in the following format.
n
p1 ... pn
j1 ... jn-1
The number of pipes n (2 β€ n β€ 65000) is given in the first line. The second line consists of n integers separated by a single space. pi (1 β€ pi β€ 1000) indicates the length of the i-th pipe. The third line consists of n-1 integers separated by one space. ji (1 β€ ji β€ 1000) indicates the length of the i-th joint.
The i-th joint can connect only the i-th and i + 1-th pipes. The length of the connected pipe is pi + ji + pi + 1.
The number of datasets does not exceed 100.
output
For each dataset, print the maximum amount of salary you can get on one line. For datasets given as input, the output value must always fall within the range of 32-bit unsigned integers.
Example
Input
3
1 1 1
3 3
4
3 3 3 3
1 1 1
5
1 2 3 4 5
4 3 2 1
0
Output
12
48
76 | instruction | 0 | 35,079 | 14 | 70,158 |
"Correct Solution:
```
import sys
from itertools import accumulate
f = sys.stdin
while True:
n = int(f.readline())
if n == 0:
break
p = list(map(int, f.readline().split()))
j = list(map(int, f.readline().split()))
j.sort(reverse=True)
j.insert(0, 0)
total_length = sum(p)
num_of_pipe = len(p)
print(max((num_of_pipe - i) * (total_length + ji) for i, ji in enumerate(accumulate(j))))
``` | output | 1 | 35,079 | 14 | 70,159 |
Provide a correct Python 3 solution for this coding contest problem.
I am a pipe tie craftsman. As long as you get the joints and pipes that connect the pipes, you can connect any pipe. Every day, my master gives me pipes and joints, which I connect and give to my master. But if you have too many pipes, you can't connect them all in one day. Even in such a case, the master smiles and gives me a salary.
By the way, I noticed something strange at one point. Often, the salary is higher when all the pipes are not connected than when they are all connected. It's so weird that one day when my boss came, I secretly saw a memo that describes how to calculate my salary. Then, how
"The salary is paid by" the number of pipes x the total length of pipes ". However, if they are connected by a joint and become one, it is regarded as one pipe. "
It was written. Now I understand why the salary may be cheaper if you connect them all. For example, as shown in the figure below, if you connect all three pipes of length 1 and two joints of length 2 to make one pipe of length 1 + 2 + 1 + 2 + 1 = 7, 1 Γ (7) ) = 7. However, if you use only one joint and make two pipes with a length of 1 + 2 + 1 = 4 and a pipe with a length of 1, 2 Γ (4 + 1) = 10, so you will get more salary than connecting all of them. ..
<image>
I don't know why my boss decides my salary this way, but I know how I can get more salary!
Now, create a program that calculates the maximum amount of salary you can get given the number of pipes.
input
The input consists of multiple datasets. The end of the input is indicated by a single zero line. Each dataset is given in the following format.
n
p1 ... pn
j1 ... jn-1
The number of pipes n (2 β€ n β€ 65000) is given in the first line. The second line consists of n integers separated by a single space. pi (1 β€ pi β€ 1000) indicates the length of the i-th pipe. The third line consists of n-1 integers separated by one space. ji (1 β€ ji β€ 1000) indicates the length of the i-th joint.
The i-th joint can connect only the i-th and i + 1-th pipes. The length of the connected pipe is pi + ji + pi + 1.
The number of datasets does not exceed 100.
output
For each dataset, print the maximum amount of salary you can get on one line. For datasets given as input, the output value must always fall within the range of 32-bit unsigned integers.
Example
Input
3
1 1 1
3 3
4
3 3 3 3
1 1 1
5
1 2 3 4 5
4 3 2 1
0
Output
12
48
76 | instruction | 0 | 35,080 | 14 | 70,160 |
"Correct Solution:
```
while True:
n = int(input())
if n == 0:
break
plst = list(map(int, input().split()))
jlst = sorted(list(map(int, input().split())), reverse=True)
sump = sum(plst)
ans = sump * n
for i in range(n - 1):
sump += jlst[i]
n -= 1
ans = max(ans, sump * n)
print(ans)
``` | output | 1 | 35,080 | 14 | 70,161 |
Provide a correct Python 3 solution for this coding contest problem.
I am a pipe tie craftsman. As long as you get the joints and pipes that connect the pipes, you can connect any pipe. Every day, my master gives me pipes and joints, which I connect and give to my master. But if you have too many pipes, you can't connect them all in one day. Even in such a case, the master smiles and gives me a salary.
By the way, I noticed something strange at one point. Often, the salary is higher when all the pipes are not connected than when they are all connected. It's so weird that one day when my boss came, I secretly saw a memo that describes how to calculate my salary. Then, how
"The salary is paid by" the number of pipes x the total length of pipes ". However, if they are connected by a joint and become one, it is regarded as one pipe. "
It was written. Now I understand why the salary may be cheaper if you connect them all. For example, as shown in the figure below, if you connect all three pipes of length 1 and two joints of length 2 to make one pipe of length 1 + 2 + 1 + 2 + 1 = 7, 1 Γ (7) ) = 7. However, if you use only one joint and make two pipes with a length of 1 + 2 + 1 = 4 and a pipe with a length of 1, 2 Γ (4 + 1) = 10, so you will get more salary than connecting all of them. ..
<image>
I don't know why my boss decides my salary this way, but I know how I can get more salary!
Now, create a program that calculates the maximum amount of salary you can get given the number of pipes.
input
The input consists of multiple datasets. The end of the input is indicated by a single zero line. Each dataset is given in the following format.
n
p1 ... pn
j1 ... jn-1
The number of pipes n (2 β€ n β€ 65000) is given in the first line. The second line consists of n integers separated by a single space. pi (1 β€ pi β€ 1000) indicates the length of the i-th pipe. The third line consists of n-1 integers separated by one space. ji (1 β€ ji β€ 1000) indicates the length of the i-th joint.
The i-th joint can connect only the i-th and i + 1-th pipes. The length of the connected pipe is pi + ji + pi + 1.
The number of datasets does not exceed 100.
output
For each dataset, print the maximum amount of salary you can get on one line. For datasets given as input, the output value must always fall within the range of 32-bit unsigned integers.
Example
Input
3
1 1 1
3 3
4
3 3 3 3
1 1 1
5
1 2 3 4 5
4 3 2 1
0
Output
12
48
76 | instruction | 0 | 35,081 | 14 | 70,162 |
"Correct Solution:
```
# AOJ 0260: Salary for a Plumber
# Python3 2018.6.26 bal4u
while True:
n = int(input())
if n == 0: break
p = list(map(int, input().split()))
s = sum(p)
j = list(map(int, input().split()))
j.sort(reverse=True)
ans = s*n
for i in range(n-1):
s += j[i]
ans = max(ans, s*(n-1-i))
print(ans)
``` | output | 1 | 35,081 | 14 | 70,163 |
Provide a correct Python 3 solution for this coding contest problem.
I am a pipe tie craftsman. As long as you get the joints and pipes that connect the pipes, you can connect any pipe. Every day, my master gives me pipes and joints, which I connect and give to my master. But if you have too many pipes, you can't connect them all in one day. Even in such a case, the master smiles and gives me a salary.
By the way, I noticed something strange at one point. Often, the salary is higher when all the pipes are not connected than when they are all connected. It's so weird that one day when my boss came, I secretly saw a memo that describes how to calculate my salary. Then, how
"The salary is paid by" the number of pipes x the total length of pipes ". However, if they are connected by a joint and become one, it is regarded as one pipe. "
It was written. Now I understand why the salary may be cheaper if you connect them all. For example, as shown in the figure below, if you connect all three pipes of length 1 and two joints of length 2 to make one pipe of length 1 + 2 + 1 + 2 + 1 = 7, 1 Γ (7) ) = 7. However, if you use only one joint and make two pipes with a length of 1 + 2 + 1 = 4 and a pipe with a length of 1, 2 Γ (4 + 1) = 10, so you will get more salary than connecting all of them. ..
<image>
I don't know why my boss decides my salary this way, but I know how I can get more salary!
Now, create a program that calculates the maximum amount of salary you can get given the number of pipes.
input
The input consists of multiple datasets. The end of the input is indicated by a single zero line. Each dataset is given in the following format.
n
p1 ... pn
j1 ... jn-1
The number of pipes n (2 β€ n β€ 65000) is given in the first line. The second line consists of n integers separated by a single space. pi (1 β€ pi β€ 1000) indicates the length of the i-th pipe. The third line consists of n-1 integers separated by one space. ji (1 β€ ji β€ 1000) indicates the length of the i-th joint.
The i-th joint can connect only the i-th and i + 1-th pipes. The length of the connected pipe is pi + ji + pi + 1.
The number of datasets does not exceed 100.
output
For each dataset, print the maximum amount of salary you can get on one line. For datasets given as input, the output value must always fall within the range of 32-bit unsigned integers.
Example
Input
3
1 1 1
3 3
4
3 3 3 3
1 1 1
5
1 2 3 4 5
4 3 2 1
0
Output
12
48
76 | instruction | 0 | 35,082 | 14 | 70,164 |
"Correct Solution:
```
while True:
n = int(input())
if n == 0:
break
p = list(map(int,input().split()))
j = list(map(int,input().split()))
j.sort()
j.reverse()
s = sum(p)
ans = s*n
for i in range(n-1):
s += j[i]
if ans < s*(n-1-i):
ans = s*(n-1-i)
print(ans)
``` | output | 1 | 35,082 | 14 | 70,165 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You received a notebook which is called Death Note. This notebook has infinite number of pages. A rule is written on the last page (huh) of this notebook. It says: "You have to write names in this notebook during n consecutive days. During the i-th day you have to write exactly a_i names.". You got scared (of course you got scared, who wouldn't get scared if he just receive a notebook which is named Death Note with a some strange rule written in it?).
Of course, you decided to follow this rule. When you calmed down, you came up with a strategy how you will write names in the notebook. You have calculated that each page of the notebook can contain exactly m names. You will start writing names from the first page. You will write names on the current page as long as the limit on the number of names on this page is not exceeded. When the current page is over, you turn the page. Note that you always turn the page when it ends, it doesn't matter if it is the last day or not. If after some day the current page still can hold at least one name, during the next day you will continue writing the names from the current page.
Now you are interested in the following question: how many times will you turn the page during each day? You are interested in the number of pages you will turn each day from 1 to n.
Input
The first line of the input contains two integers n, m (1 β€ n β€ 2 β
10^5, 1 β€ m β€ 10^9) β the number of days you will write names in the notebook and the number of names which can be written on each page of the notebook.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i means the number of names you will write in the notebook during the i-th day.
Output
Print exactly n integers t_1, t_2, ..., t_n, where t_i is the number of times you will turn the page during the i-th day.
Examples
Input
3 5
3 7 9
Output
0 2 1
Input
4 20
10 9 19 2
Output
0 0 1 1
Input
1 100
99
Output
0
Note
In the first example pages of the Death Note will look like this [1, 1, 1, 2, 2], [2, 2, 2, 2, 2], [3, 3, 3, 3, 3], [3, 3, 3, 3]. Each number of the array describes during which day name on the corresponding position will be written. It is easy to see that you should turn the first and the second page during the second day and the third page during the third day. | instruction | 0 | 35,123 | 14 | 70,246 |
Tags: greedy, implementation, math
Correct Solution:
```
days, page_names = list(map(int, input().split(" ")))
names = list(map(int, input().split(" ")))
res = [0] * days
total = [0] * days
for i in range(days):
res[i] = (res[i-1] + names[i])
print((res[i] // page_names) - (total[i-1]), end=" ")
total[i] = res[i] // page_names
``` | output | 1 | 35,123 | 14 | 70,247 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You received a notebook which is called Death Note. This notebook has infinite number of pages. A rule is written on the last page (huh) of this notebook. It says: "You have to write names in this notebook during n consecutive days. During the i-th day you have to write exactly a_i names.". You got scared (of course you got scared, who wouldn't get scared if he just receive a notebook which is named Death Note with a some strange rule written in it?).
Of course, you decided to follow this rule. When you calmed down, you came up with a strategy how you will write names in the notebook. You have calculated that each page of the notebook can contain exactly m names. You will start writing names from the first page. You will write names on the current page as long as the limit on the number of names on this page is not exceeded. When the current page is over, you turn the page. Note that you always turn the page when it ends, it doesn't matter if it is the last day or not. If after some day the current page still can hold at least one name, during the next day you will continue writing the names from the current page.
Now you are interested in the following question: how many times will you turn the page during each day? You are interested in the number of pages you will turn each day from 1 to n.
Input
The first line of the input contains two integers n, m (1 β€ n β€ 2 β
10^5, 1 β€ m β€ 10^9) β the number of days you will write names in the notebook and the number of names which can be written on each page of the notebook.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i means the number of names you will write in the notebook during the i-th day.
Output
Print exactly n integers t_1, t_2, ..., t_n, where t_i is the number of times you will turn the page during the i-th day.
Examples
Input
3 5
3 7 9
Output
0 2 1
Input
4 20
10 9 19 2
Output
0 0 1 1
Input
1 100
99
Output
0
Note
In the first example pages of the Death Note will look like this [1, 1, 1, 2, 2], [2, 2, 2, 2, 2], [3, 3, 3, 3, 3], [3, 3, 3, 3]. Each number of the array describes during which day name on the corresponding position will be written. It is easy to see that you should turn the first and the second page during the second day and the third page during the third day. | instruction | 0 | 35,124 | 14 | 70,248 |
Tags: greedy, implementation, math
Correct Solution:
```
n, m = tuple(map(int, input().split()))
A = list(map(int, input().split()))
count = 0
for i in range(n):
count += A[i]
print(count // m, end = ' ')
count = count % m
``` | output | 1 | 35,124 | 14 | 70,249 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You received a notebook which is called Death Note. This notebook has infinite number of pages. A rule is written on the last page (huh) of this notebook. It says: "You have to write names in this notebook during n consecutive days. During the i-th day you have to write exactly a_i names.". You got scared (of course you got scared, who wouldn't get scared if he just receive a notebook which is named Death Note with a some strange rule written in it?).
Of course, you decided to follow this rule. When you calmed down, you came up with a strategy how you will write names in the notebook. You have calculated that each page of the notebook can contain exactly m names. You will start writing names from the first page. You will write names on the current page as long as the limit on the number of names on this page is not exceeded. When the current page is over, you turn the page. Note that you always turn the page when it ends, it doesn't matter if it is the last day or not. If after some day the current page still can hold at least one name, during the next day you will continue writing the names from the current page.
Now you are interested in the following question: how many times will you turn the page during each day? You are interested in the number of pages you will turn each day from 1 to n.
Input
The first line of the input contains two integers n, m (1 β€ n β€ 2 β
10^5, 1 β€ m β€ 10^9) β the number of days you will write names in the notebook and the number of names which can be written on each page of the notebook.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i means the number of names you will write in the notebook during the i-th day.
Output
Print exactly n integers t_1, t_2, ..., t_n, where t_i is the number of times you will turn the page during the i-th day.
Examples
Input
3 5
3 7 9
Output
0 2 1
Input
4 20
10 9 19 2
Output
0 0 1 1
Input
1 100
99
Output
0
Note
In the first example pages of the Death Note will look like this [1, 1, 1, 2, 2], [2, 2, 2, 2, 2], [3, 3, 3, 3, 3], [3, 3, 3, 3]. Each number of the array describes during which day name on the corresponding position will be written. It is easy to see that you should turn the first and the second page during the second day and the third page during the third day. | instruction | 0 | 35,125 | 14 | 70,250 |
Tags: greedy, implementation, math
Correct Solution:
```
n, m = map(int, input().split())
res = 0
for a in list(map(int, input().split())):
print((res + a) // m, end = ' ')
res = (res + a) % m
'''
x = 5, k = 1
12 11 10 -- a
0 1 2 -- r(sort)
2 2 2 -- c(sort)
d = 6 == (sum(c)) - οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½ οΏ½οΏ½οΏ½οΏ½ (οΏ½οΏ½οΏ½οΏ½)
οΏ½οΏ½οΏ½οΏ½ sum(r) / k >= d:
οΏ½οΏ½οΏ½οΏ½οΏ½ d οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½ οΏ½οΏ½οΏ½οΏ½ οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½ οΏ½οΏ½ r (οΏ½ οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½) -- for οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½
οΏ½οΏ½οΏ½οΏ½οΏ½
οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½ οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½ οΏ½οΏ½οΏ½οΏ½οΏ½ οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½ οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½ x (οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½ οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½ οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½ οΏ½οΏ½οΏ½οΏ½)
14 14 14
4 4 4
0 2 4
0 1 0
0 0 0
'''
``` | output | 1 | 35,125 | 14 | 70,251 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You received a notebook which is called Death Note. This notebook has infinite number of pages. A rule is written on the last page (huh) of this notebook. It says: "You have to write names in this notebook during n consecutive days. During the i-th day you have to write exactly a_i names.". You got scared (of course you got scared, who wouldn't get scared if he just receive a notebook which is named Death Note with a some strange rule written in it?).
Of course, you decided to follow this rule. When you calmed down, you came up with a strategy how you will write names in the notebook. You have calculated that each page of the notebook can contain exactly m names. You will start writing names from the first page. You will write names on the current page as long as the limit on the number of names on this page is not exceeded. When the current page is over, you turn the page. Note that you always turn the page when it ends, it doesn't matter if it is the last day or not. If after some day the current page still can hold at least one name, during the next day you will continue writing the names from the current page.
Now you are interested in the following question: how many times will you turn the page during each day? You are interested in the number of pages you will turn each day from 1 to n.
Input
The first line of the input contains two integers n, m (1 β€ n β€ 2 β
10^5, 1 β€ m β€ 10^9) β the number of days you will write names in the notebook and the number of names which can be written on each page of the notebook.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i means the number of names you will write in the notebook during the i-th day.
Output
Print exactly n integers t_1, t_2, ..., t_n, where t_i is the number of times you will turn the page during the i-th day.
Examples
Input
3 5
3 7 9
Output
0 2 1
Input
4 20
10 9 19 2
Output
0 0 1 1
Input
1 100
99
Output
0
Note
In the first example pages of the Death Note will look like this [1, 1, 1, 2, 2], [2, 2, 2, 2, 2], [3, 3, 3, 3, 3], [3, 3, 3, 3]. Each number of the array describes during which day name on the corresponding position will be written. It is easy to see that you should turn the first and the second page during the second day and the third page during the third day. | instruction | 0 | 35,126 | 14 | 70,252 |
Tags: greedy, implementation, math
Correct Solution:
```
numDays, m = map(int, input().split())
a = list(map(int, input().split()))
t = []
numOnPage = 0
for i in range(numDays):
pages = (numOnPage + a[i]) // m
t.append(pages)
numOnPage = (numOnPage + a[i]) % m
print(' '.join(map(str,t)))
``` | output | 1 | 35,126 | 14 | 70,253 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You received a notebook which is called Death Note. This notebook has infinite number of pages. A rule is written on the last page (huh) of this notebook. It says: "You have to write names in this notebook during n consecutive days. During the i-th day you have to write exactly a_i names.". You got scared (of course you got scared, who wouldn't get scared if he just receive a notebook which is named Death Note with a some strange rule written in it?).
Of course, you decided to follow this rule. When you calmed down, you came up with a strategy how you will write names in the notebook. You have calculated that each page of the notebook can contain exactly m names. You will start writing names from the first page. You will write names on the current page as long as the limit on the number of names on this page is not exceeded. When the current page is over, you turn the page. Note that you always turn the page when it ends, it doesn't matter if it is the last day or not. If after some day the current page still can hold at least one name, during the next day you will continue writing the names from the current page.
Now you are interested in the following question: how many times will you turn the page during each day? You are interested in the number of pages you will turn each day from 1 to n.
Input
The first line of the input contains two integers n, m (1 β€ n β€ 2 β
10^5, 1 β€ m β€ 10^9) β the number of days you will write names in the notebook and the number of names which can be written on each page of the notebook.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i means the number of names you will write in the notebook during the i-th day.
Output
Print exactly n integers t_1, t_2, ..., t_n, where t_i is the number of times you will turn the page during the i-th day.
Examples
Input
3 5
3 7 9
Output
0 2 1
Input
4 20
10 9 19 2
Output
0 0 1 1
Input
1 100
99
Output
0
Note
In the first example pages of the Death Note will look like this [1, 1, 1, 2, 2], [2, 2, 2, 2, 2], [3, 3, 3, 3, 3], [3, 3, 3, 3]. Each number of the array describes during which day name on the corresponding position will be written. It is easy to see that you should turn the first and the second page during the second day and the third page during the third day. | instruction | 0 | 35,127 | 14 | 70,254 |
Tags: greedy, implementation, math
Correct Solution:
```
n, m = (int(x) for x in input().split())
count = 0
ans = 0
a = [int(x) for x in input().split()]
for i in range(n):
ans = 0
count += a[i]
if count > m:
dl = count // m
ans+= dl
count -= dl*m
print(ans,end=" ")
elif count < m:
print(ans,end=" ")
else:
ans += 1
count = 0
print(ans,end=" ")
``` | output | 1 | 35,127 | 14 | 70,255 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You received a notebook which is called Death Note. This notebook has infinite number of pages. A rule is written on the last page (huh) of this notebook. It says: "You have to write names in this notebook during n consecutive days. During the i-th day you have to write exactly a_i names.". You got scared (of course you got scared, who wouldn't get scared if he just receive a notebook which is named Death Note with a some strange rule written in it?).
Of course, you decided to follow this rule. When you calmed down, you came up with a strategy how you will write names in the notebook. You have calculated that each page of the notebook can contain exactly m names. You will start writing names from the first page. You will write names on the current page as long as the limit on the number of names on this page is not exceeded. When the current page is over, you turn the page. Note that you always turn the page when it ends, it doesn't matter if it is the last day or not. If after some day the current page still can hold at least one name, during the next day you will continue writing the names from the current page.
Now you are interested in the following question: how many times will you turn the page during each day? You are interested in the number of pages you will turn each day from 1 to n.
Input
The first line of the input contains two integers n, m (1 β€ n β€ 2 β
10^5, 1 β€ m β€ 10^9) β the number of days you will write names in the notebook and the number of names which can be written on each page of the notebook.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i means the number of names you will write in the notebook during the i-th day.
Output
Print exactly n integers t_1, t_2, ..., t_n, where t_i is the number of times you will turn the page during the i-th day.
Examples
Input
3 5
3 7 9
Output
0 2 1
Input
4 20
10 9 19 2
Output
0 0 1 1
Input
1 100
99
Output
0
Note
In the first example pages of the Death Note will look like this [1, 1, 1, 2, 2], [2, 2, 2, 2, 2], [3, 3, 3, 3, 3], [3, 3, 3, 3]. Each number of the array describes during which day name on the corresponding position will be written. It is easy to see that you should turn the first and the second page during the second day and the third page during the third day. | instruction | 0 | 35,128 | 14 | 70,256 |
Tags: greedy, implementation, math
Correct Solution:
```
#Death Note
def main():
from sys import stdin, stdout
import math
n, m = map(int, stdin.readline().rstrip().split())
A = [int(x) for x in stdin.readline().rstrip().split()]
s = 0
for x in range(n):
v = math.floor((s+A[x])/m) - math.floor(s/m)
stdout.write(str(v) + ' ')
s = s + A[x]
if __name__ == '__main__':
main()
``` | output | 1 | 35,128 | 14 | 70,257 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You received a notebook which is called Death Note. This notebook has infinite number of pages. A rule is written on the last page (huh) of this notebook. It says: "You have to write names in this notebook during n consecutive days. During the i-th day you have to write exactly a_i names.". You got scared (of course you got scared, who wouldn't get scared if he just receive a notebook which is named Death Note with a some strange rule written in it?).
Of course, you decided to follow this rule. When you calmed down, you came up with a strategy how you will write names in the notebook. You have calculated that each page of the notebook can contain exactly m names. You will start writing names from the first page. You will write names on the current page as long as the limit on the number of names on this page is not exceeded. When the current page is over, you turn the page. Note that you always turn the page when it ends, it doesn't matter if it is the last day or not. If after some day the current page still can hold at least one name, during the next day you will continue writing the names from the current page.
Now you are interested in the following question: how many times will you turn the page during each day? You are interested in the number of pages you will turn each day from 1 to n.
Input
The first line of the input contains two integers n, m (1 β€ n β€ 2 β
10^5, 1 β€ m β€ 10^9) β the number of days you will write names in the notebook and the number of names which can be written on each page of the notebook.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i means the number of names you will write in the notebook during the i-th day.
Output
Print exactly n integers t_1, t_2, ..., t_n, where t_i is the number of times you will turn the page during the i-th day.
Examples
Input
3 5
3 7 9
Output
0 2 1
Input
4 20
10 9 19 2
Output
0 0 1 1
Input
1 100
99
Output
0
Note
In the first example pages of the Death Note will look like this [1, 1, 1, 2, 2], [2, 2, 2, 2, 2], [3, 3, 3, 3, 3], [3, 3, 3, 3]. Each number of the array describes during which day name on the corresponding position will be written. It is easy to see that you should turn the first and the second page during the second day and the third page during the third day. | instruction | 0 | 35,129 | 14 | 70,258 |
Tags: greedy, implementation, math
Correct Solution:
```
n,m=map(int,input().split())
l=list(map(int,input().split()))
c=0
for i in range(n):
l[i]+=c
print(l[i]//m)
c=l[i]%m
``` | output | 1 | 35,129 | 14 | 70,259 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You received a notebook which is called Death Note. This notebook has infinite number of pages. A rule is written on the last page (huh) of this notebook. It says: "You have to write names in this notebook during n consecutive days. During the i-th day you have to write exactly a_i names.". You got scared (of course you got scared, who wouldn't get scared if he just receive a notebook which is named Death Note with a some strange rule written in it?).
Of course, you decided to follow this rule. When you calmed down, you came up with a strategy how you will write names in the notebook. You have calculated that each page of the notebook can contain exactly m names. You will start writing names from the first page. You will write names on the current page as long as the limit on the number of names on this page is not exceeded. When the current page is over, you turn the page. Note that you always turn the page when it ends, it doesn't matter if it is the last day or not. If after some day the current page still can hold at least one name, during the next day you will continue writing the names from the current page.
Now you are interested in the following question: how many times will you turn the page during each day? You are interested in the number of pages you will turn each day from 1 to n.
Input
The first line of the input contains two integers n, m (1 β€ n β€ 2 β
10^5, 1 β€ m β€ 10^9) β the number of days you will write names in the notebook and the number of names which can be written on each page of the notebook.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i means the number of names you will write in the notebook during the i-th day.
Output
Print exactly n integers t_1, t_2, ..., t_n, where t_i is the number of times you will turn the page during the i-th day.
Examples
Input
3 5
3 7 9
Output
0 2 1
Input
4 20
10 9 19 2
Output
0 0 1 1
Input
1 100
99
Output
0
Note
In the first example pages of the Death Note will look like this [1, 1, 1, 2, 2], [2, 2, 2, 2, 2], [3, 3, 3, 3, 3], [3, 3, 3, 3]. Each number of the array describes during which day name on the corresponding position will be written. It is easy to see that you should turn the first and the second page during the second day and the third page during the third day. | instruction | 0 | 35,130 | 14 | 70,260 |
Tags: greedy, implementation, math
Correct Solution:
```
A = input()
B = input()
listA = A.split()
listB = B.split()
rA = []
c = 0
for i in range(len(listB)):
rA.append(int(listB[i]))
for i in range(int(listA[0])):
rA[i] = rA[i]+c
d = rA[i]// int(listA[1])
print(d,end=" ")
c = rA[i] % int(listA[1])
``` | output | 1 | 35,130 | 14 | 70,261 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You received a notebook which is called Death Note. This notebook has infinite number of pages. A rule is written on the last page (huh) of this notebook. It says: "You have to write names in this notebook during n consecutive days. During the i-th day you have to write exactly a_i names.". You got scared (of course you got scared, who wouldn't get scared if he just receive a notebook which is named Death Note with a some strange rule written in it?).
Of course, you decided to follow this rule. When you calmed down, you came up with a strategy how you will write names in the notebook. You have calculated that each page of the notebook can contain exactly m names. You will start writing names from the first page. You will write names on the current page as long as the limit on the number of names on this page is not exceeded. When the current page is over, you turn the page. Note that you always turn the page when it ends, it doesn't matter if it is the last day or not. If after some day the current page still can hold at least one name, during the next day you will continue writing the names from the current page.
Now you are interested in the following question: how many times will you turn the page during each day? You are interested in the number of pages you will turn each day from 1 to n.
Input
The first line of the input contains two integers n, m (1 β€ n β€ 2 β
10^5, 1 β€ m β€ 10^9) β the number of days you will write names in the notebook and the number of names which can be written on each page of the notebook.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i means the number of names you will write in the notebook during the i-th day.
Output
Print exactly n integers t_1, t_2, ..., t_n, where t_i is the number of times you will turn the page during the i-th day.
Examples
Input
3 5
3 7 9
Output
0 2 1
Input
4 20
10 9 19 2
Output
0 0 1 1
Input
1 100
99
Output
0
Note
In the first example pages of the Death Note will look like this [1, 1, 1, 2, 2], [2, 2, 2, 2, 2], [3, 3, 3, 3, 3], [3, 3, 3, 3]. Each number of the array describes during which day name on the corresponding position will be written. It is easy to see that you should turn the first and the second page during the second day and the third page during the third day.
Submitted Solution:
```
n, m = map(int, input().split())
x = list(map(int, input().split()))
r = 0
for each in x:
r += each
print(r // m, end=" ")
r %= m
``` | instruction | 0 | 35,131 | 14 | 70,262 |
Yes | output | 1 | 35,131 | 14 | 70,263 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You received a notebook which is called Death Note. This notebook has infinite number of pages. A rule is written on the last page (huh) of this notebook. It says: "You have to write names in this notebook during n consecutive days. During the i-th day you have to write exactly a_i names.". You got scared (of course you got scared, who wouldn't get scared if he just receive a notebook which is named Death Note with a some strange rule written in it?).
Of course, you decided to follow this rule. When you calmed down, you came up with a strategy how you will write names in the notebook. You have calculated that each page of the notebook can contain exactly m names. You will start writing names from the first page. You will write names on the current page as long as the limit on the number of names on this page is not exceeded. When the current page is over, you turn the page. Note that you always turn the page when it ends, it doesn't matter if it is the last day or not. If after some day the current page still can hold at least one name, during the next day you will continue writing the names from the current page.
Now you are interested in the following question: how many times will you turn the page during each day? You are interested in the number of pages you will turn each day from 1 to n.
Input
The first line of the input contains two integers n, m (1 β€ n β€ 2 β
10^5, 1 β€ m β€ 10^9) β the number of days you will write names in the notebook and the number of names which can be written on each page of the notebook.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i means the number of names you will write in the notebook during the i-th day.
Output
Print exactly n integers t_1, t_2, ..., t_n, where t_i is the number of times you will turn the page during the i-th day.
Examples
Input
3 5
3 7 9
Output
0 2 1
Input
4 20
10 9 19 2
Output
0 0 1 1
Input
1 100
99
Output
0
Note
In the first example pages of the Death Note will look like this [1, 1, 1, 2, 2], [2, 2, 2, 2, 2], [3, 3, 3, 3, 3], [3, 3, 3, 3]. Each number of the array describes during which day name on the corresponding position will be written. It is easy to see that you should turn the first and the second page during the second day and the third page during the third day.
Submitted Solution:
```
def read():
return int(input())
def readlist():
return list(map(int, input().split()))
def readmap():
return map(int, input().split())
n, m = readmap()
A = readlist()
T = [0] * n
res = 0
for i in range(n):
res += A[i]
T[i] = res // m
res = res % m
print(" ".join(list(map(str, T))))
``` | instruction | 0 | 35,132 | 14 | 70,264 |
Yes | output | 1 | 35,132 | 14 | 70,265 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You received a notebook which is called Death Note. This notebook has infinite number of pages. A rule is written on the last page (huh) of this notebook. It says: "You have to write names in this notebook during n consecutive days. During the i-th day you have to write exactly a_i names.". You got scared (of course you got scared, who wouldn't get scared if he just receive a notebook which is named Death Note with a some strange rule written in it?).
Of course, you decided to follow this rule. When you calmed down, you came up with a strategy how you will write names in the notebook. You have calculated that each page of the notebook can contain exactly m names. You will start writing names from the first page. You will write names on the current page as long as the limit on the number of names on this page is not exceeded. When the current page is over, you turn the page. Note that you always turn the page when it ends, it doesn't matter if it is the last day or not. If after some day the current page still can hold at least one name, during the next day you will continue writing the names from the current page.
Now you are interested in the following question: how many times will you turn the page during each day? You are interested in the number of pages you will turn each day from 1 to n.
Input
The first line of the input contains two integers n, m (1 β€ n β€ 2 β
10^5, 1 β€ m β€ 10^9) β the number of days you will write names in the notebook and the number of names which can be written on each page of the notebook.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i means the number of names you will write in the notebook during the i-th day.
Output
Print exactly n integers t_1, t_2, ..., t_n, where t_i is the number of times you will turn the page during the i-th day.
Examples
Input
3 5
3 7 9
Output
0 2 1
Input
4 20
10 9 19 2
Output
0 0 1 1
Input
1 100
99
Output
0
Note
In the first example pages of the Death Note will look like this [1, 1, 1, 2, 2], [2, 2, 2, 2, 2], [3, 3, 3, 3, 3], [3, 3, 3, 3]. Each number of the array describes during which day name on the corresponding position will be written. It is easy to see that you should turn the first and the second page during the second day and the third page during the third day.
Submitted Solution:
```
import sys
from array import array
def readline(): return sys.stdin.buffer.readline().decode('utf-8')
n, m = map(int, readline().split())
a = list(map(int, readline().split()))
rem = 0
ans = [0]*n
for i, x in enumerate(a):
ans[i] = (rem + x) // m
rem = (rem + x) % m
print(*ans)
``` | instruction | 0 | 35,133 | 14 | 70,266 |
Yes | output | 1 | 35,133 | 14 | 70,267 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You received a notebook which is called Death Note. This notebook has infinite number of pages. A rule is written on the last page (huh) of this notebook. It says: "You have to write names in this notebook during n consecutive days. During the i-th day you have to write exactly a_i names.". You got scared (of course you got scared, who wouldn't get scared if he just receive a notebook which is named Death Note with a some strange rule written in it?).
Of course, you decided to follow this rule. When you calmed down, you came up with a strategy how you will write names in the notebook. You have calculated that each page of the notebook can contain exactly m names. You will start writing names from the first page. You will write names on the current page as long as the limit on the number of names on this page is not exceeded. When the current page is over, you turn the page. Note that you always turn the page when it ends, it doesn't matter if it is the last day or not. If after some day the current page still can hold at least one name, during the next day you will continue writing the names from the current page.
Now you are interested in the following question: how many times will you turn the page during each day? You are interested in the number of pages you will turn each day from 1 to n.
Input
The first line of the input contains two integers n, m (1 β€ n β€ 2 β
10^5, 1 β€ m β€ 10^9) β the number of days you will write names in the notebook and the number of names which can be written on each page of the notebook.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i means the number of names you will write in the notebook during the i-th day.
Output
Print exactly n integers t_1, t_2, ..., t_n, where t_i is the number of times you will turn the page during the i-th day.
Examples
Input
3 5
3 7 9
Output
0 2 1
Input
4 20
10 9 19 2
Output
0 0 1 1
Input
1 100
99
Output
0
Note
In the first example pages of the Death Note will look like this [1, 1, 1, 2, 2], [2, 2, 2, 2, 2], [3, 3, 3, 3, 3], [3, 3, 3, 3]. Each number of the array describes during which day name on the corresponding position will be written. It is easy to see that you should turn the first and the second page during the second day and the third page during the third day.
Submitted Solution:
```
import sys
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(sys.stdin.readline())
def ria(): return list(map(int, sys.stdin.readline().split()))
def ws(s): sys.stdout.write(s); sys.stdout.write('\n')
def wi(n): sys.stdout.write(str(n)); sys.stdout.write('\n')
def wia(a, sep=' '): sys.stdout.write(sep.join([str(x) for x in a])); sys.stdout.write('\n')
def main():
n, m = ria()
a = ria()
res = []
offset = 0
for i in range(n):
t = (offset + a[i]) // m
offset = (offset + a[i]) % m
res.append(t)
wia(res)
if __name__ == '__main__':
main()
``` | instruction | 0 | 35,134 | 14 | 70,268 |
Yes | output | 1 | 35,134 | 14 | 70,269 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You received a notebook which is called Death Note. This notebook has infinite number of pages. A rule is written on the last page (huh) of this notebook. It says: "You have to write names in this notebook during n consecutive days. During the i-th day you have to write exactly a_i names.". You got scared (of course you got scared, who wouldn't get scared if he just receive a notebook which is named Death Note with a some strange rule written in it?).
Of course, you decided to follow this rule. When you calmed down, you came up with a strategy how you will write names in the notebook. You have calculated that each page of the notebook can contain exactly m names. You will start writing names from the first page. You will write names on the current page as long as the limit on the number of names on this page is not exceeded. When the current page is over, you turn the page. Note that you always turn the page when it ends, it doesn't matter if it is the last day or not. If after some day the current page still can hold at least one name, during the next day you will continue writing the names from the current page.
Now you are interested in the following question: how many times will you turn the page during each day? You are interested in the number of pages you will turn each day from 1 to n.
Input
The first line of the input contains two integers n, m (1 β€ n β€ 2 β
10^5, 1 β€ m β€ 10^9) β the number of days you will write names in the notebook and the number of names which can be written on each page of the notebook.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i means the number of names you will write in the notebook during the i-th day.
Output
Print exactly n integers t_1, t_2, ..., t_n, where t_i is the number of times you will turn the page during the i-th day.
Examples
Input
3 5
3 7 9
Output
0 2 1
Input
4 20
10 9 19 2
Output
0 0 1 1
Input
1 100
99
Output
0
Note
In the first example pages of the Death Note will look like this [1, 1, 1, 2, 2], [2, 2, 2, 2, 2], [3, 3, 3, 3, 3], [3, 3, 3, 3]. Each number of the array describes during which day name on the corresponding position will be written. It is easy to see that you should turn the first and the second page during the second day and the third page during the third day.
Submitted Solution:
```
n,m = map(int,input().split())
A = list(map(int,input().split()))
D = [];prev = []
if(A[0]<m):
D.append(0)
prev.append(m-A[0])
else:
D.append(A[0]//m)
prev.append(m-A[0]%m)
i = A[0]//m
j=1
while(j<n and i<n):
if(A[j]<prev[-1]):
D.append(0)
prev.append(prev[-1]-A[j])
else:
A[j]-=prev[-1]
D.append(A[j]//m+(prev[-1]!=0))
prev.append(m-A[j]%m)
i+=A[j]//m+1
j+=1
print(*D)
``` | instruction | 0 | 35,135 | 14 | 70,270 |
No | output | 1 | 35,135 | 14 | 70,271 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You received a notebook which is called Death Note. This notebook has infinite number of pages. A rule is written on the last page (huh) of this notebook. It says: "You have to write names in this notebook during n consecutive days. During the i-th day you have to write exactly a_i names.". You got scared (of course you got scared, who wouldn't get scared if he just receive a notebook which is named Death Note with a some strange rule written in it?).
Of course, you decided to follow this rule. When you calmed down, you came up with a strategy how you will write names in the notebook. You have calculated that each page of the notebook can contain exactly m names. You will start writing names from the first page. You will write names on the current page as long as the limit on the number of names on this page is not exceeded. When the current page is over, you turn the page. Note that you always turn the page when it ends, it doesn't matter if it is the last day or not. If after some day the current page still can hold at least one name, during the next day you will continue writing the names from the current page.
Now you are interested in the following question: how many times will you turn the page during each day? You are interested in the number of pages you will turn each day from 1 to n.
Input
The first line of the input contains two integers n, m (1 β€ n β€ 2 β
10^5, 1 β€ m β€ 10^9) β the number of days you will write names in the notebook and the number of names which can be written on each page of the notebook.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i means the number of names you will write in the notebook during the i-th day.
Output
Print exactly n integers t_1, t_2, ..., t_n, where t_i is the number of times you will turn the page during the i-th day.
Examples
Input
3 5
3 7 9
Output
0 2 1
Input
4 20
10 9 19 2
Output
0 0 1 1
Input
1 100
99
Output
0
Note
In the first example pages of the Death Note will look like this [1, 1, 1, 2, 2], [2, 2, 2, 2, 2], [3, 3, 3, 3, 3], [3, 3, 3, 3]. Each number of the array describes during which day name on the corresponding position will be written. It is easy to see that you should turn the first and the second page during the second day and the third page during the third day.
Submitted Solution:
```
import sys
fir = list(map(int, input().split()))
day = fir[0]
volume = fir[1]
note = list(map(int, input().split()))
d=0
for a in range(day):
d=note[a]+d
note[a]=d
for a in range(day):
if a==day-1 and note[a]%volume==0:
note[a]=int(note[a]/volume)-1
else:
note[a]=int(note[a]/volume)
for a in range(1, day):
note[a]= note[a]-note[a-1]
for a in range(day):
sys.stdout.write(str(note[a]))
if a != day:
sys.stdout.write(' ')
``` | instruction | 0 | 35,136 | 14 | 70,272 |
No | output | 1 | 35,136 | 14 | 70,273 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You received a notebook which is called Death Note. This notebook has infinite number of pages. A rule is written on the last page (huh) of this notebook. It says: "You have to write names in this notebook during n consecutive days. During the i-th day you have to write exactly a_i names.". You got scared (of course you got scared, who wouldn't get scared if he just receive a notebook which is named Death Note with a some strange rule written in it?).
Of course, you decided to follow this rule. When you calmed down, you came up with a strategy how you will write names in the notebook. You have calculated that each page of the notebook can contain exactly m names. You will start writing names from the first page. You will write names on the current page as long as the limit on the number of names on this page is not exceeded. When the current page is over, you turn the page. Note that you always turn the page when it ends, it doesn't matter if it is the last day or not. If after some day the current page still can hold at least one name, during the next day you will continue writing the names from the current page.
Now you are interested in the following question: how many times will you turn the page during each day? You are interested in the number of pages you will turn each day from 1 to n.
Input
The first line of the input contains two integers n, m (1 β€ n β€ 2 β
10^5, 1 β€ m β€ 10^9) β the number of days you will write names in the notebook and the number of names which can be written on each page of the notebook.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i means the number of names you will write in the notebook during the i-th day.
Output
Print exactly n integers t_1, t_2, ..., t_n, where t_i is the number of times you will turn the page during the i-th day.
Examples
Input
3 5
3 7 9
Output
0 2 1
Input
4 20
10 9 19 2
Output
0 0 1 1
Input
1 100
99
Output
0
Note
In the first example pages of the Death Note will look like this [1, 1, 1, 2, 2], [2, 2, 2, 2, 2], [3, 3, 3, 3, 3], [3, 3, 3, 3]. Each number of the array describes during which day name on the corresponding position will be written. It is easy to see that you should turn the first and the second page during the second day and the third page during the third day.
Submitted Solution:
```
import sys
data = sys.stdin.readlines()
m = int(data[0].split()[1])
a = list(map(int, data[1].split()))
n = m
for i in a:
w = 0
if n < m:
if i >= n:
i -= n
w += 1
n = m
else: n -= i
if i > 0:
w += (i // n)
n -= i % n
print(w)
``` | instruction | 0 | 35,137 | 14 | 70,274 |
No | output | 1 | 35,137 | 14 | 70,275 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You received a notebook which is called Death Note. This notebook has infinite number of pages. A rule is written on the last page (huh) of this notebook. It says: "You have to write names in this notebook during n consecutive days. During the i-th day you have to write exactly a_i names.". You got scared (of course you got scared, who wouldn't get scared if he just receive a notebook which is named Death Note with a some strange rule written in it?).
Of course, you decided to follow this rule. When you calmed down, you came up with a strategy how you will write names in the notebook. You have calculated that each page of the notebook can contain exactly m names. You will start writing names from the first page. You will write names on the current page as long as the limit on the number of names on this page is not exceeded. When the current page is over, you turn the page. Note that you always turn the page when it ends, it doesn't matter if it is the last day or not. If after some day the current page still can hold at least one name, during the next day you will continue writing the names from the current page.
Now you are interested in the following question: how many times will you turn the page during each day? You are interested in the number of pages you will turn each day from 1 to n.
Input
The first line of the input contains two integers n, m (1 β€ n β€ 2 β
10^5, 1 β€ m β€ 10^9) β the number of days you will write names in the notebook and the number of names which can be written on each page of the notebook.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i means the number of names you will write in the notebook during the i-th day.
Output
Print exactly n integers t_1, t_2, ..., t_n, where t_i is the number of times you will turn the page during the i-th day.
Examples
Input
3 5
3 7 9
Output
0 2 1
Input
4 20
10 9 19 2
Output
0 0 1 1
Input
1 100
99
Output
0
Note
In the first example pages of the Death Note will look like this [1, 1, 1, 2, 2], [2, 2, 2, 2, 2], [3, 3, 3, 3, 3], [3, 3, 3, 3]. Each number of the array describes during which day name on the corresponding position will be written. It is easy to see that you should turn the first and the second page during the second day and the third page during the third day.
Submitted Solution:
```
import math
line=input().split(" ")
n_Days=int(line[0])
n_Names=int(line[1])
num=[int(i) for i in input().split(" ")]
ans=[]
for i in range(len(num)):
if i == 0:
if num[i]<n_Names:
ans.append(0)
j=num[i]
else:
j=num[i]-n_Names
ans.append(math.floor(num[i]/n_Names))
else:
if num[i]+j>n_Names:
if j%5==0:
ans.append(math.floor((j+num[i])/n_Names)-1)
else:
ans.append(math.floor((j+num[i])/n_Names))
j=j+num[i]-n_Names
else:
ans.append(0)
j+=num[i]
print([str(i) for i in ans])
``` | instruction | 0 | 35,138 | 14 | 70,276 |
No | output | 1 | 35,138 | 14 | 70,277 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness".
The test consists of n questions; the questions are to be answered strictly in the order in which they are given, from question 1 to question n. Question i contains ai answer variants, exactly one of them is correct.
A click is regarded as selecting any answer in any question. The goal is to select the correct answer for each of the n questions. If Vaganych selects a wrong answer for some question, then all selected answers become unselected and the test starts from the very beginning, from question 1 again. But Vaganych remembers everything. The order of answers for each question and the order of questions remain unchanged, as well as the question and answers themselves.
Vaganych is very smart and his memory is superb, yet he is unbelievably unlucky and knows nothing whatsoever about the test's theme. How many clicks will he have to perform in the worst case?
Input
The first line contains a positive integer n (1 β€ n β€ 100). It is the number of questions in the test. The second line contains space-separated n positive integers ai (1 β€ ai β€ 109), the number of answer variants to question i.
Output
Print a single number β the minimal number of clicks needed to pass the test it the worst-case scenario.
Please do not use the %lld specificator to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specificator.
Examples
Input
2
1 1
Output
2
Input
2
2 2
Output
5
Input
1
10
Output
10
Note
Note to the second sample. In the worst-case scenario you will need five clicks:
* the first click selects the first variant to the first question, this answer turns out to be wrong.
* the second click selects the second variant to the first question, it proves correct and we move on to the second question;
* the third click selects the first variant to the second question, it is wrong and we go back to question 1;
* the fourth click selects the second variant to the first question, it proves as correct as it was and we move on to the second question;
* the fifth click selects the second variant to the second question, it proves correct, the test is finished. | instruction | 0 | 35,139 | 14 | 70,278 |
Tags: greedy, implementation, math
Correct Solution:
```
n = int(input())
a = list(map(int,input().split()))
ans=0
for i in range(n):
ans+=a[i]*(i+1)-i
print(ans)
``` | output | 1 | 35,139 | 14 | 70,279 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness".
The test consists of n questions; the questions are to be answered strictly in the order in which they are given, from question 1 to question n. Question i contains ai answer variants, exactly one of them is correct.
A click is regarded as selecting any answer in any question. The goal is to select the correct answer for each of the n questions. If Vaganych selects a wrong answer for some question, then all selected answers become unselected and the test starts from the very beginning, from question 1 again. But Vaganych remembers everything. The order of answers for each question and the order of questions remain unchanged, as well as the question and answers themselves.
Vaganych is very smart and his memory is superb, yet he is unbelievably unlucky and knows nothing whatsoever about the test's theme. How many clicks will he have to perform in the worst case?
Input
The first line contains a positive integer n (1 β€ n β€ 100). It is the number of questions in the test. The second line contains space-separated n positive integers ai (1 β€ ai β€ 109), the number of answer variants to question i.
Output
Print a single number β the minimal number of clicks needed to pass the test it the worst-case scenario.
Please do not use the %lld specificator to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specificator.
Examples
Input
2
1 1
Output
2
Input
2
2 2
Output
5
Input
1
10
Output
10
Note
Note to the second sample. In the worst-case scenario you will need five clicks:
* the first click selects the first variant to the first question, this answer turns out to be wrong.
* the second click selects the second variant to the first question, it proves correct and we move on to the second question;
* the third click selects the first variant to the second question, it is wrong and we go back to question 1;
* the fourth click selects the second variant to the first question, it proves as correct as it was and we move on to the second question;
* the fifth click selects the second variant to the second question, it proves correct, the test is finished. | instruction | 0 | 35,140 | 14 | 70,280 |
Tags: greedy, implementation, math
Correct Solution:
```
input()
print(sum(i * x - i + x for i, x in enumerate(map(int, input().split()))))
``` | output | 1 | 35,140 | 14 | 70,281 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness".
The test consists of n questions; the questions are to be answered strictly in the order in which they are given, from question 1 to question n. Question i contains ai answer variants, exactly one of them is correct.
A click is regarded as selecting any answer in any question. The goal is to select the correct answer for each of the n questions. If Vaganych selects a wrong answer for some question, then all selected answers become unselected and the test starts from the very beginning, from question 1 again. But Vaganych remembers everything. The order of answers for each question and the order of questions remain unchanged, as well as the question and answers themselves.
Vaganych is very smart and his memory is superb, yet he is unbelievably unlucky and knows nothing whatsoever about the test's theme. How many clicks will he have to perform in the worst case?
Input
The first line contains a positive integer n (1 β€ n β€ 100). It is the number of questions in the test. The second line contains space-separated n positive integers ai (1 β€ ai β€ 109), the number of answer variants to question i.
Output
Print a single number β the minimal number of clicks needed to pass the test it the worst-case scenario.
Please do not use the %lld specificator to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specificator.
Examples
Input
2
1 1
Output
2
Input
2
2 2
Output
5
Input
1
10
Output
10
Note
Note to the second sample. In the worst-case scenario you will need five clicks:
* the first click selects the first variant to the first question, this answer turns out to be wrong.
* the second click selects the second variant to the first question, it proves correct and we move on to the second question;
* the third click selects the first variant to the second question, it is wrong and we go back to question 1;
* the fourth click selects the second variant to the first question, it proves as correct as it was and we move on to the second question;
* the fifth click selects the second variant to the second question, it proves correct, the test is finished. | instruction | 0 | 35,141 | 14 | 70,282 |
Tags: greedy, implementation, math
Correct Solution:
```
n=int(input())
ar=list(map(int,input().split()))
ans=0
for i in range(n):
ans+=(i+1)*(ar[i]-1)+(i+1)-i
print(ans)
``` | output | 1 | 35,141 | 14 | 70,283 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness".
The test consists of n questions; the questions are to be answered strictly in the order in which they are given, from question 1 to question n. Question i contains ai answer variants, exactly one of them is correct.
A click is regarded as selecting any answer in any question. The goal is to select the correct answer for each of the n questions. If Vaganych selects a wrong answer for some question, then all selected answers become unselected and the test starts from the very beginning, from question 1 again. But Vaganych remembers everything. The order of answers for each question and the order of questions remain unchanged, as well as the question and answers themselves.
Vaganych is very smart and his memory is superb, yet he is unbelievably unlucky and knows nothing whatsoever about the test's theme. How many clicks will he have to perform in the worst case?
Input
The first line contains a positive integer n (1 β€ n β€ 100). It is the number of questions in the test. The second line contains space-separated n positive integers ai (1 β€ ai β€ 109), the number of answer variants to question i.
Output
Print a single number β the minimal number of clicks needed to pass the test it the worst-case scenario.
Please do not use the %lld specificator to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specificator.
Examples
Input
2
1 1
Output
2
Input
2
2 2
Output
5
Input
1
10
Output
10
Note
Note to the second sample. In the worst-case scenario you will need five clicks:
* the first click selects the first variant to the first question, this answer turns out to be wrong.
* the second click selects the second variant to the first question, it proves correct and we move on to the second question;
* the third click selects the first variant to the second question, it is wrong and we go back to question 1;
* the fourth click selects the second variant to the first question, it proves as correct as it was and we move on to the second question;
* the fifth click selects the second variant to the second question, it proves correct, the test is finished. | instruction | 0 | 35,142 | 14 | 70,284 |
Tags: greedy, implementation, math
Correct Solution:
```
n=int(input())
a=list(map(int,input().split()))
s=a[0]
for i in range(1,len(a)):
s=s+(a[i]-1)*i+a[i]
print(s)
``` | output | 1 | 35,142 | 14 | 70,285 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness".
The test consists of n questions; the questions are to be answered strictly in the order in which they are given, from question 1 to question n. Question i contains ai answer variants, exactly one of them is correct.
A click is regarded as selecting any answer in any question. The goal is to select the correct answer for each of the n questions. If Vaganych selects a wrong answer for some question, then all selected answers become unselected and the test starts from the very beginning, from question 1 again. But Vaganych remembers everything. The order of answers for each question and the order of questions remain unchanged, as well as the question and answers themselves.
Vaganych is very smart and his memory is superb, yet he is unbelievably unlucky and knows nothing whatsoever about the test's theme. How many clicks will he have to perform in the worst case?
Input
The first line contains a positive integer n (1 β€ n β€ 100). It is the number of questions in the test. The second line contains space-separated n positive integers ai (1 β€ ai β€ 109), the number of answer variants to question i.
Output
Print a single number β the minimal number of clicks needed to pass the test it the worst-case scenario.
Please do not use the %lld specificator to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specificator.
Examples
Input
2
1 1
Output
2
Input
2
2 2
Output
5
Input
1
10
Output
10
Note
Note to the second sample. In the worst-case scenario you will need five clicks:
* the first click selects the first variant to the first question, this answer turns out to be wrong.
* the second click selects the second variant to the first question, it proves correct and we move on to the second question;
* the third click selects the first variant to the second question, it is wrong and we go back to question 1;
* the fourth click selects the second variant to the first question, it proves as correct as it was and we move on to the second question;
* the fifth click selects the second variant to the second question, it proves correct, the test is finished. | instruction | 0 | 35,143 | 14 | 70,286 |
Tags: greedy, implementation, math
Correct Solution:
```
n = int(input())
a = list(map(int,input().split()))
s = 0
for i in range(1, n+1):
s+=(a[i-1]-1)*i+1
print(s)
``` | output | 1 | 35,143 | 14 | 70,287 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness".
The test consists of n questions; the questions are to be answered strictly in the order in which they are given, from question 1 to question n. Question i contains ai answer variants, exactly one of them is correct.
A click is regarded as selecting any answer in any question. The goal is to select the correct answer for each of the n questions. If Vaganych selects a wrong answer for some question, then all selected answers become unselected and the test starts from the very beginning, from question 1 again. But Vaganych remembers everything. The order of answers for each question and the order of questions remain unchanged, as well as the question and answers themselves.
Vaganych is very smart and his memory is superb, yet he is unbelievably unlucky and knows nothing whatsoever about the test's theme. How many clicks will he have to perform in the worst case?
Input
The first line contains a positive integer n (1 β€ n β€ 100). It is the number of questions in the test. The second line contains space-separated n positive integers ai (1 β€ ai β€ 109), the number of answer variants to question i.
Output
Print a single number β the minimal number of clicks needed to pass the test it the worst-case scenario.
Please do not use the %lld specificator to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specificator.
Examples
Input
2
1 1
Output
2
Input
2
2 2
Output
5
Input
1
10
Output
10
Note
Note to the second sample. In the worst-case scenario you will need five clicks:
* the first click selects the first variant to the first question, this answer turns out to be wrong.
* the second click selects the second variant to the first question, it proves correct and we move on to the second question;
* the third click selects the first variant to the second question, it is wrong and we go back to question 1;
* the fourth click selects the second variant to the first question, it proves as correct as it was and we move on to the second question;
* the fifth click selects the second variant to the second question, it proves correct, the test is finished. | instruction | 0 | 35,144 | 14 | 70,288 |
Tags: greedy, implementation, math
Correct Solution:
```
n = int(input())
l = list(map(int,input().split()))
ans = 0
for i in range(n):
if l[i] == 1:
ans+=1
elif i == 0 and l[0]!=1:
ans+=l[i]
else:
ans+=(l[i]-1)*i + l[i]
print(ans)
``` | output | 1 | 35,144 | 14 | 70,289 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness".
The test consists of n questions; the questions are to be answered strictly in the order in which they are given, from question 1 to question n. Question i contains ai answer variants, exactly one of them is correct.
A click is regarded as selecting any answer in any question. The goal is to select the correct answer for each of the n questions. If Vaganych selects a wrong answer for some question, then all selected answers become unselected and the test starts from the very beginning, from question 1 again. But Vaganych remembers everything. The order of answers for each question and the order of questions remain unchanged, as well as the question and answers themselves.
Vaganych is very smart and his memory is superb, yet he is unbelievably unlucky and knows nothing whatsoever about the test's theme. How many clicks will he have to perform in the worst case?
Input
The first line contains a positive integer n (1 β€ n β€ 100). It is the number of questions in the test. The second line contains space-separated n positive integers ai (1 β€ ai β€ 109), the number of answer variants to question i.
Output
Print a single number β the minimal number of clicks needed to pass the test it the worst-case scenario.
Please do not use the %lld specificator to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specificator.
Examples
Input
2
1 1
Output
2
Input
2
2 2
Output
5
Input
1
10
Output
10
Note
Note to the second sample. In the worst-case scenario you will need five clicks:
* the first click selects the first variant to the first question, this answer turns out to be wrong.
* the second click selects the second variant to the first question, it proves correct and we move on to the second question;
* the third click selects the first variant to the second question, it is wrong and we go back to question 1;
* the fourth click selects the second variant to the first question, it proves as correct as it was and we move on to the second question;
* the fifth click selects the second variant to the second question, it proves correct, the test is finished. | instruction | 0 | 35,145 | 14 | 70,290 |
Tags: greedy, implementation, math
Correct Solution:
```
n=int(input())
l=list(map(int,input().split()))
s=0
for i in range(len(l)):
if l[i]==1:
s=s+1
else:
s=s+l[i]+((l[i]-1)*i)
print(s)
``` | output | 1 | 35,145 | 14 | 70,291 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness".
The test consists of n questions; the questions are to be answered strictly in the order in which they are given, from question 1 to question n. Question i contains ai answer variants, exactly one of them is correct.
A click is regarded as selecting any answer in any question. The goal is to select the correct answer for each of the n questions. If Vaganych selects a wrong answer for some question, then all selected answers become unselected and the test starts from the very beginning, from question 1 again. But Vaganych remembers everything. The order of answers for each question and the order of questions remain unchanged, as well as the question and answers themselves.
Vaganych is very smart and his memory is superb, yet he is unbelievably unlucky and knows nothing whatsoever about the test's theme. How many clicks will he have to perform in the worst case?
Input
The first line contains a positive integer n (1 β€ n β€ 100). It is the number of questions in the test. The second line contains space-separated n positive integers ai (1 β€ ai β€ 109), the number of answer variants to question i.
Output
Print a single number β the minimal number of clicks needed to pass the test it the worst-case scenario.
Please do not use the %lld specificator to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specificator.
Examples
Input
2
1 1
Output
2
Input
2
2 2
Output
5
Input
1
10
Output
10
Note
Note to the second sample. In the worst-case scenario you will need five clicks:
* the first click selects the first variant to the first question, this answer turns out to be wrong.
* the second click selects the second variant to the first question, it proves correct and we move on to the second question;
* the third click selects the first variant to the second question, it is wrong and we go back to question 1;
* the fourth click selects the second variant to the first question, it proves as correct as it was and we move on to the second question;
* the fifth click selects the second variant to the second question, it proves correct, the test is finished. | instruction | 0 | 35,146 | 14 | 70,292 |
Tags: greedy, implementation, math
Correct Solution:
```
n = int(input())
a = list(map(int,input().split()))
s=0
for i in range(n):
s+=(i+1)*(a[i]-1)
s+=n
print(s)
``` | output | 1 | 35,146 | 14 | 70,293 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Cowboy Vlad has a birthday today! There are n children who came to the celebration. In order to greet Vlad, the children decided to form a circle around him. Among the children who came, there are both tall and low, so if they stand in a circle arbitrarily, it may turn out, that there is a tall and low child standing next to each other, and it will be difficult for them to hold hands. Therefore, children want to stand in a circle so that the maximum difference between the growth of two neighboring children would be minimal possible.
Formally, let's number children from 1 to n in a circle order, that is, for every i child with number i will stand next to the child with number i+1, also the child with number 1 stands next to the child with number n. Then we will call the discomfort of the circle the maximum absolute difference of heights of the children, who stand next to each other.
Please help children to find out how they should reorder themselves, so that the resulting discomfort is smallest possible.
Input
The first line contains a single integer n (2 β€ n β€ 100) β the number of the children who came to the cowboy Vlad's birthday.
The second line contains integers a_1, a_2, β¦, a_n (1 β€ a_i β€ 10^9) denoting heights of every child.
Output
Print exactly n integers β heights of the children in the order in which they should stand in a circle. You can start printing a circle with any child.
If there are multiple possible answers, print any of them.
Examples
Input
5
2 1 1 3 2
Output
1 2 3 2 1
Input
3
30 10 20
Output
10 20 30
Note
In the first example, the discomfort of the circle is equal to 1, since the corresponding absolute differences are 1, 1, 1 and 0. Note, that sequences [2, 3, 2, 1, 1] and [3, 2, 1, 1, 2] form the same circles and differ only by the selection of the starting point.
In the second example, the discomfort of the circle is equal to 20, since the absolute difference of 10 and 30 is equal to 20. | instruction | 0 | 35,187 | 14 | 70,374 |
Tags: binary search, greedy, sortings
Correct Solution:
```
n = int(input())
m = sorted(map(int, input().split()))
print(*(m[0::2]+list(reversed(m[1::2]))))
``` | output | 1 | 35,187 | 14 | 70,375 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Cowboy Vlad has a birthday today! There are n children who came to the celebration. In order to greet Vlad, the children decided to form a circle around him. Among the children who came, there are both tall and low, so if they stand in a circle arbitrarily, it may turn out, that there is a tall and low child standing next to each other, and it will be difficult for them to hold hands. Therefore, children want to stand in a circle so that the maximum difference between the growth of two neighboring children would be minimal possible.
Formally, let's number children from 1 to n in a circle order, that is, for every i child with number i will stand next to the child with number i+1, also the child with number 1 stands next to the child with number n. Then we will call the discomfort of the circle the maximum absolute difference of heights of the children, who stand next to each other.
Please help children to find out how they should reorder themselves, so that the resulting discomfort is smallest possible.
Input
The first line contains a single integer n (2 β€ n β€ 100) β the number of the children who came to the cowboy Vlad's birthday.
The second line contains integers a_1, a_2, β¦, a_n (1 β€ a_i β€ 10^9) denoting heights of every child.
Output
Print exactly n integers β heights of the children in the order in which they should stand in a circle. You can start printing a circle with any child.
If there are multiple possible answers, print any of them.
Examples
Input
5
2 1 1 3 2
Output
1 2 3 2 1
Input
3
30 10 20
Output
10 20 30
Note
In the first example, the discomfort of the circle is equal to 1, since the corresponding absolute differences are 1, 1, 1 and 0. Note, that sequences [2, 3, 2, 1, 1] and [3, 2, 1, 1, 2] form the same circles and differ only by the selection of the starting point.
In the second example, the discomfort of the circle is equal to 20, since the absolute difference of 10 and 30 is equal to 20. | instruction | 0 | 35,188 | 14 | 70,376 |
Tags: binary search, greedy, sortings
Correct Solution:
```
def main():
from collections import deque
n = int(input())
a = sorted([int(i) for i in input().split()])
d = deque()
for i in range(n):
if i % 2:
d.appendleft(a[i])
else:
d.append(a[i])
print(*d)
main()
``` | output | 1 | 35,188 | 14 | 70,377 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Cowboy Vlad has a birthday today! There are n children who came to the celebration. In order to greet Vlad, the children decided to form a circle around him. Among the children who came, there are both tall and low, so if they stand in a circle arbitrarily, it may turn out, that there is a tall and low child standing next to each other, and it will be difficult for them to hold hands. Therefore, children want to stand in a circle so that the maximum difference between the growth of two neighboring children would be minimal possible.
Formally, let's number children from 1 to n in a circle order, that is, for every i child with number i will stand next to the child with number i+1, also the child with number 1 stands next to the child with number n. Then we will call the discomfort of the circle the maximum absolute difference of heights of the children, who stand next to each other.
Please help children to find out how they should reorder themselves, so that the resulting discomfort is smallest possible.
Input
The first line contains a single integer n (2 β€ n β€ 100) β the number of the children who came to the cowboy Vlad's birthday.
The second line contains integers a_1, a_2, β¦, a_n (1 β€ a_i β€ 10^9) denoting heights of every child.
Output
Print exactly n integers β heights of the children in the order in which they should stand in a circle. You can start printing a circle with any child.
If there are multiple possible answers, print any of them.
Examples
Input
5
2 1 1 3 2
Output
1 2 3 2 1
Input
3
30 10 20
Output
10 20 30
Note
In the first example, the discomfort of the circle is equal to 1, since the corresponding absolute differences are 1, 1, 1 and 0. Note, that sequences [2, 3, 2, 1, 1] and [3, 2, 1, 1, 2] form the same circles and differ only by the selection of the starting point.
In the second example, the discomfort of the circle is equal to 20, since the absolute difference of 10 and 30 is equal to 20. | instruction | 0 | 35,189 | 14 | 70,378 |
Tags: binary search, greedy, sortings
Correct Solution:
```
if __name__ == '__main__':
n = int(input())
a = list(map(int, input().split()))
a.sort()
p1 = a[::2]
p2 = a[1::2]
p2 = p2[::-1]
for i in p2 + p1:
print(i, end =' ')
``` | output | 1 | 35,189 | 14 | 70,379 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Cowboy Vlad has a birthday today! There are n children who came to the celebration. In order to greet Vlad, the children decided to form a circle around him. Among the children who came, there are both tall and low, so if they stand in a circle arbitrarily, it may turn out, that there is a tall and low child standing next to each other, and it will be difficult for them to hold hands. Therefore, children want to stand in a circle so that the maximum difference between the growth of two neighboring children would be minimal possible.
Formally, let's number children from 1 to n in a circle order, that is, for every i child with number i will stand next to the child with number i+1, also the child with number 1 stands next to the child with number n. Then we will call the discomfort of the circle the maximum absolute difference of heights of the children, who stand next to each other.
Please help children to find out how they should reorder themselves, so that the resulting discomfort is smallest possible.
Input
The first line contains a single integer n (2 β€ n β€ 100) β the number of the children who came to the cowboy Vlad's birthday.
The second line contains integers a_1, a_2, β¦, a_n (1 β€ a_i β€ 10^9) denoting heights of every child.
Output
Print exactly n integers β heights of the children in the order in which they should stand in a circle. You can start printing a circle with any child.
If there are multiple possible answers, print any of them.
Examples
Input
5
2 1 1 3 2
Output
1 2 3 2 1
Input
3
30 10 20
Output
10 20 30
Note
In the first example, the discomfort of the circle is equal to 1, since the corresponding absolute differences are 1, 1, 1 and 0. Note, that sequences [2, 3, 2, 1, 1] and [3, 2, 1, 1, 2] form the same circles and differ only by the selection of the starting point.
In the second example, the discomfort of the circle is equal to 20, since the absolute difference of 10 and 30 is equal to 20. | instruction | 0 | 35,190 | 14 | 70,380 |
Tags: binary search, greedy, sortings
Correct Solution:
```
n = int(input())
arr = list(map(int, input().split()))
brr = [max(arr)]
arr.sort(reverse = True)
flag = 0
for i in range(1, len(arr)):
if flag==0:
brr = [arr[i]] + brr
flag = 1
elif flag==1:
brr += [arr[i]]
flag = 0
print(*brr)
####arr = [[0, 0]]
####for _ in range(int(input())):
#### arr.append([int(i) for i in input().split()])
####
####if len(arr)==2:
#### print(1 + min(arr[1]))
####else:
#### cnt = 1
#### last = None
#### for i in range(1, len(arr)):
#### a, b = arr[i-1]
#### c, d = arr[i]
#### if arr[i-1]==arr[i]:
#### continue
#### else:
#### flag = min(c, d) - max(a, b)
#### if flag==0 and i!=1:
#### cnt += 1
#### elif flag>0:
#### if last==max(a, b):
#### cnt += flag
#### else:
#### cnt += flag+1
#### last = min(c, d)
#### print(cnt)
####
####
``` | output | 1 | 35,190 | 14 | 70,381 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Cowboy Vlad has a birthday today! There are n children who came to the celebration. In order to greet Vlad, the children decided to form a circle around him. Among the children who came, there are both tall and low, so if they stand in a circle arbitrarily, it may turn out, that there is a tall and low child standing next to each other, and it will be difficult for them to hold hands. Therefore, children want to stand in a circle so that the maximum difference between the growth of two neighboring children would be minimal possible.
Formally, let's number children from 1 to n in a circle order, that is, for every i child with number i will stand next to the child with number i+1, also the child with number 1 stands next to the child with number n. Then we will call the discomfort of the circle the maximum absolute difference of heights of the children, who stand next to each other.
Please help children to find out how they should reorder themselves, so that the resulting discomfort is smallest possible.
Input
The first line contains a single integer n (2 β€ n β€ 100) β the number of the children who came to the cowboy Vlad's birthday.
The second line contains integers a_1, a_2, β¦, a_n (1 β€ a_i β€ 10^9) denoting heights of every child.
Output
Print exactly n integers β heights of the children in the order in which they should stand in a circle. You can start printing a circle with any child.
If there are multiple possible answers, print any of them.
Examples
Input
5
2 1 1 3 2
Output
1 2 3 2 1
Input
3
30 10 20
Output
10 20 30
Note
In the first example, the discomfort of the circle is equal to 1, since the corresponding absolute differences are 1, 1, 1 and 0. Note, that sequences [2, 3, 2, 1, 1] and [3, 2, 1, 1, 2] form the same circles and differ only by the selection of the starting point.
In the second example, the discomfort of the circle is equal to 20, since the absolute difference of 10 and 30 is equal to 20. | instruction | 0 | 35,191 | 14 | 70,382 |
Tags: binary search, greedy, sortings
Correct Solution:
```
n=int(input())
a=list(map(int,input().split()))
a.sort()
ans=[0]*n
start=0
end=n-1
for i in range(n):
if(i%2==0):
ans[start]=a[i]
start+=1
else:
ans[end]=a[i]
end-=1
print(*ans)
``` | output | 1 | 35,191 | 14 | 70,383 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Cowboy Vlad has a birthday today! There are n children who came to the celebration. In order to greet Vlad, the children decided to form a circle around him. Among the children who came, there are both tall and low, so if they stand in a circle arbitrarily, it may turn out, that there is a tall and low child standing next to each other, and it will be difficult for them to hold hands. Therefore, children want to stand in a circle so that the maximum difference between the growth of two neighboring children would be minimal possible.
Formally, let's number children from 1 to n in a circle order, that is, for every i child with number i will stand next to the child with number i+1, also the child with number 1 stands next to the child with number n. Then we will call the discomfort of the circle the maximum absolute difference of heights of the children, who stand next to each other.
Please help children to find out how they should reorder themselves, so that the resulting discomfort is smallest possible.
Input
The first line contains a single integer n (2 β€ n β€ 100) β the number of the children who came to the cowboy Vlad's birthday.
The second line contains integers a_1, a_2, β¦, a_n (1 β€ a_i β€ 10^9) denoting heights of every child.
Output
Print exactly n integers β heights of the children in the order in which they should stand in a circle. You can start printing a circle with any child.
If there are multiple possible answers, print any of them.
Examples
Input
5
2 1 1 3 2
Output
1 2 3 2 1
Input
3
30 10 20
Output
10 20 30
Note
In the first example, the discomfort of the circle is equal to 1, since the corresponding absolute differences are 1, 1, 1 and 0. Note, that sequences [2, 3, 2, 1, 1] and [3, 2, 1, 1, 2] form the same circles and differ only by the selection of the starting point.
In the second example, the discomfort of the circle is equal to 20, since the absolute difference of 10 and 30 is equal to 20. | instruction | 0 | 35,192 | 14 | 70,384 |
Tags: binary search, greedy, sortings
Correct Solution:
```
n=int(input())
arr=list(map(int,input().split()))
arr.sort()
arr1=arr[::2]
arr2=arr[1::2]
arr2=arr2[::-1]
for i in arr1:
print(i,end=' ')
for j in arr2:
print(j,end=' ')
print('\n',end='')
``` | output | 1 | 35,192 | 14 | 70,385 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Cowboy Vlad has a birthday today! There are n children who came to the celebration. In order to greet Vlad, the children decided to form a circle around him. Among the children who came, there are both tall and low, so if they stand in a circle arbitrarily, it may turn out, that there is a tall and low child standing next to each other, and it will be difficult for them to hold hands. Therefore, children want to stand in a circle so that the maximum difference between the growth of two neighboring children would be minimal possible.
Formally, let's number children from 1 to n in a circle order, that is, for every i child with number i will stand next to the child with number i+1, also the child with number 1 stands next to the child with number n. Then we will call the discomfort of the circle the maximum absolute difference of heights of the children, who stand next to each other.
Please help children to find out how they should reorder themselves, so that the resulting discomfort is smallest possible.
Input
The first line contains a single integer n (2 β€ n β€ 100) β the number of the children who came to the cowboy Vlad's birthday.
The second line contains integers a_1, a_2, β¦, a_n (1 β€ a_i β€ 10^9) denoting heights of every child.
Output
Print exactly n integers β heights of the children in the order in which they should stand in a circle. You can start printing a circle with any child.
If there are multiple possible answers, print any of them.
Examples
Input
5
2 1 1 3 2
Output
1 2 3 2 1
Input
3
30 10 20
Output
10 20 30
Note
In the first example, the discomfort of the circle is equal to 1, since the corresponding absolute differences are 1, 1, 1 and 0. Note, that sequences [2, 3, 2, 1, 1] and [3, 2, 1, 1, 2] form the same circles and differ only by the selection of the starting point.
In the second example, the discomfort of the circle is equal to 20, since the absolute difference of 10 and 30 is equal to 20. | instruction | 0 | 35,193 | 14 | 70,386 |
Tags: binary search, greedy, sortings
Correct Solution:
```
n = int(input())
kids = [0] * n
heights = list(map(int, input().split()))
heights.sort()
# print(heights)
pos = 0
for i in range(len(heights)):
if i % 2 == 0:
kids[i // 2] = heights[i]
else:
kids[n - pos - 1] = heights[i]
pos += 1
print(*kids)
``` | output | 1 | 35,193 | 14 | 70,387 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Cowboy Vlad has a birthday today! There are n children who came to the celebration. In order to greet Vlad, the children decided to form a circle around him. Among the children who came, there are both tall and low, so if they stand in a circle arbitrarily, it may turn out, that there is a tall and low child standing next to each other, and it will be difficult for them to hold hands. Therefore, children want to stand in a circle so that the maximum difference between the growth of two neighboring children would be minimal possible.
Formally, let's number children from 1 to n in a circle order, that is, for every i child with number i will stand next to the child with number i+1, also the child with number 1 stands next to the child with number n. Then we will call the discomfort of the circle the maximum absolute difference of heights of the children, who stand next to each other.
Please help children to find out how they should reorder themselves, so that the resulting discomfort is smallest possible.
Input
The first line contains a single integer n (2 β€ n β€ 100) β the number of the children who came to the cowboy Vlad's birthday.
The second line contains integers a_1, a_2, β¦, a_n (1 β€ a_i β€ 10^9) denoting heights of every child.
Output
Print exactly n integers β heights of the children in the order in which they should stand in a circle. You can start printing a circle with any child.
If there are multiple possible answers, print any of them.
Examples
Input
5
2 1 1 3 2
Output
1 2 3 2 1
Input
3
30 10 20
Output
10 20 30
Note
In the first example, the discomfort of the circle is equal to 1, since the corresponding absolute differences are 1, 1, 1 and 0. Note, that sequences [2, 3, 2, 1, 1] and [3, 2, 1, 1, 2] form the same circles and differ only by the selection of the starting point.
In the second example, the discomfort of the circle is equal to 20, since the absolute difference of 10 and 30 is equal to 20. | instruction | 0 | 35,194 | 14 | 70,388 |
Tags: binary search, greedy, sortings
Correct Solution:
```
n = int(input())
a = list(map(int,input().split()))
a = sorted(a)
p = a[::2]
q = a[1::2][::-1]
print(*(p + q))
``` | output | 1 | 35,194 | 14 | 70,389 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.