message stringlengths 2 48.6k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 318 108k | cluster float64 8 8 | __index_level_0__ int64 636 217k |
|---|---|---|---|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house.
Karlsson's gaze immediately fell on n wooden cupboards, standing in the kitchen. He immediately realized that these cupboards have hidden jam stocks. Karlsson began to fly greedily around the kitchen, opening and closing the cupboards' doors, grab and empty all the jars of jam that he could find.
And now all jars of jam are empty, Karlsson has had enough and does not want to leave traces of his stay, so as not to let down his friend. Each of the cupboards has two doors: the left one and the right one. Karlsson remembers that when he rushed to the kitchen, all the cupboards' left doors were in the same position (open or closed), similarly, all the cupboards' right doors were in the same position (open or closed). Karlsson wants the doors to meet this condition as well by the time the family returns. Karlsson does not remember the position of all the left doors, also, he cannot remember the position of all the right doors. Therefore, it does not matter to him in what position will be all left or right doors. It is important to leave all the left doors in the same position, and all the right doors in the same position. For example, all the left doors may be closed, and all the right ones may be open.
Karlsson needs one second to open or close a door of a cupboard. He understands that he has very little time before the family returns, so he wants to know the minimum number of seconds t, in which he is able to bring all the cupboard doors in the required position.
Your task is to write a program that will determine the required number of seconds t.
Input
The first input line contains a single integer n β the number of cupboards in the kitchen (2 β€ n β€ 104). Then follow n lines, each containing two integers li and ri (0 β€ li, ri β€ 1). Number li equals one, if the left door of the i-th cupboard is opened, otherwise number li equals zero. Similarly, number ri equals one, if the right door of the i-th cupboard is opened, otherwise number ri equals zero.
The numbers in the lines are separated by single spaces.
Output
In the only output line print a single integer t β the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs.
Examples
Input
5
0 1
1 0
0 1
1 1
0 1
Output
3 | instruction | 0 | 60,041 | 8 | 120,082 |
Tags: implementation
Correct Solution:
```
l1 = 0
l0 = 0
r1 = 0
r0 = 0
n = int(input())
for i in range(n):
a,b = map(int,input().split())
if a == 0:
l0 += 1
else:
l1 += 1
if b == 0:
r0 += 1
else:
r1 += 1
print(min(l0,l1) + min(r0,r1))
``` | output | 1 | 60,041 | 8 | 120,083 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house.
Karlsson's gaze immediately fell on n wooden cupboards, standing in the kitchen. He immediately realized that these cupboards have hidden jam stocks. Karlsson began to fly greedily around the kitchen, opening and closing the cupboards' doors, grab and empty all the jars of jam that he could find.
And now all jars of jam are empty, Karlsson has had enough and does not want to leave traces of his stay, so as not to let down his friend. Each of the cupboards has two doors: the left one and the right one. Karlsson remembers that when he rushed to the kitchen, all the cupboards' left doors were in the same position (open or closed), similarly, all the cupboards' right doors were in the same position (open or closed). Karlsson wants the doors to meet this condition as well by the time the family returns. Karlsson does not remember the position of all the left doors, also, he cannot remember the position of all the right doors. Therefore, it does not matter to him in what position will be all left or right doors. It is important to leave all the left doors in the same position, and all the right doors in the same position. For example, all the left doors may be closed, and all the right ones may be open.
Karlsson needs one second to open or close a door of a cupboard. He understands that he has very little time before the family returns, so he wants to know the minimum number of seconds t, in which he is able to bring all the cupboard doors in the required position.
Your task is to write a program that will determine the required number of seconds t.
Input
The first input line contains a single integer n β the number of cupboards in the kitchen (2 β€ n β€ 104). Then follow n lines, each containing two integers li and ri (0 β€ li, ri β€ 1). Number li equals one, if the left door of the i-th cupboard is opened, otherwise number li equals zero. Similarly, number ri equals one, if the right door of the i-th cupboard is opened, otherwise number ri equals zero.
The numbers in the lines are separated by single spaces.
Output
In the only output line print a single integer t β the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs.
Examples
Input
5
0 1
1 0
0 1
1 1
0 1
Output
3 | instruction | 0 | 60,042 | 8 | 120,084 |
Tags: implementation
Correct Solution:
```
n=int(input())
list1=[]
list2=[]
for i in range(n):
x,y=map(int,input().split())
list1.append(x)
list2.append(y)
count1=list1.count(0)
count2=list1.count(1)
result1=0
if count1 >= count2:
result1=count2
else:
result1=count1
count3=list2.count(0)
count4=list2.count(1)
result2=0
if count3 >= count4:
result2=count4
else:
result2=count3
print(result1+result2)
``` | output | 1 | 60,042 | 8 | 120,085 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house.
Karlsson's gaze immediately fell on n wooden cupboards, standing in the kitchen. He immediately realized that these cupboards have hidden jam stocks. Karlsson began to fly greedily around the kitchen, opening and closing the cupboards' doors, grab and empty all the jars of jam that he could find.
And now all jars of jam are empty, Karlsson has had enough and does not want to leave traces of his stay, so as not to let down his friend. Each of the cupboards has two doors: the left one and the right one. Karlsson remembers that when he rushed to the kitchen, all the cupboards' left doors were in the same position (open or closed), similarly, all the cupboards' right doors were in the same position (open or closed). Karlsson wants the doors to meet this condition as well by the time the family returns. Karlsson does not remember the position of all the left doors, also, he cannot remember the position of all the right doors. Therefore, it does not matter to him in what position will be all left or right doors. It is important to leave all the left doors in the same position, and all the right doors in the same position. For example, all the left doors may be closed, and all the right ones may be open.
Karlsson needs one second to open or close a door of a cupboard. He understands that he has very little time before the family returns, so he wants to know the minimum number of seconds t, in which he is able to bring all the cupboard doors in the required position.
Your task is to write a program that will determine the required number of seconds t.
Input
The first input line contains a single integer n β the number of cupboards in the kitchen (2 β€ n β€ 104). Then follow n lines, each containing two integers li and ri (0 β€ li, ri β€ 1). Number li equals one, if the left door of the i-th cupboard is opened, otherwise number li equals zero. Similarly, number ri equals one, if the right door of the i-th cupboard is opened, otherwise number ri equals zero.
The numbers in the lines are separated by single spaces.
Output
In the only output line print a single integer t β the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs.
Examples
Input
5
0 1
1 0
0 1
1 1
0 1
Output
3 | instruction | 0 | 60,043 | 8 | 120,086 |
Tags: implementation
Correct Solution:
```
n=int(input())
l=[]
r=[]
for i in range(n):
e1,e2=map(int,input().split())
l.append(e1)
r.append(e2)
a=l.count(0)
b=l.count(1)
c=r.count(0)
d=r.count(1)
ans=0
if a>b:
ans+=b
else:
ans+=a
if c>d:
ans+=d
else:
ans+=c
print(ans)
``` | output | 1 | 60,043 | 8 | 120,087 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house.
Karlsson's gaze immediately fell on n wooden cupboards, standing in the kitchen. He immediately realized that these cupboards have hidden jam stocks. Karlsson began to fly greedily around the kitchen, opening and closing the cupboards' doors, grab and empty all the jars of jam that he could find.
And now all jars of jam are empty, Karlsson has had enough and does not want to leave traces of his stay, so as not to let down his friend. Each of the cupboards has two doors: the left one and the right one. Karlsson remembers that when he rushed to the kitchen, all the cupboards' left doors were in the same position (open or closed), similarly, all the cupboards' right doors were in the same position (open or closed). Karlsson wants the doors to meet this condition as well by the time the family returns. Karlsson does not remember the position of all the left doors, also, he cannot remember the position of all the right doors. Therefore, it does not matter to him in what position will be all left or right doors. It is important to leave all the left doors in the same position, and all the right doors in the same position. For example, all the left doors may be closed, and all the right ones may be open.
Karlsson needs one second to open or close a door of a cupboard. He understands that he has very little time before the family returns, so he wants to know the minimum number of seconds t, in which he is able to bring all the cupboard doors in the required position.
Your task is to write a program that will determine the required number of seconds t.
Input
The first input line contains a single integer n β the number of cupboards in the kitchen (2 β€ n β€ 104). Then follow n lines, each containing two integers li and ri (0 β€ li, ri β€ 1). Number li equals one, if the left door of the i-th cupboard is opened, otherwise number li equals zero. Similarly, number ri equals one, if the right door of the i-th cupboard is opened, otherwise number ri equals zero.
The numbers in the lines are separated by single spaces.
Output
In the only output line print a single integer t β the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs.
Examples
Input
5
0 1
1 0
0 1
1 1
0 1
Output
3 | instruction | 0 | 60,044 | 8 | 120,088 |
Tags: implementation
Correct Solution:
```
import sys
f = sys.stdin
#f = open("input.txt", "r")
f.readline()
l, r = [], []
res = 0
for line in f:
l += line.strip().split()[0]
r += line.strip().split()[1]
if l.count('0') < l.count('1'):
res += l.count('0')
else:
res += l.count('1')
if r.count('0') < r.count('1'):
res += r.count('0')
else:
res += r.count('1')
print(res)
``` | output | 1 | 60,044 | 8 | 120,089 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house.
Karlsson's gaze immediately fell on n wooden cupboards, standing in the kitchen. He immediately realized that these cupboards have hidden jam stocks. Karlsson began to fly greedily around the kitchen, opening and closing the cupboards' doors, grab and empty all the jars of jam that he could find.
And now all jars of jam are empty, Karlsson has had enough and does not want to leave traces of his stay, so as not to let down his friend. Each of the cupboards has two doors: the left one and the right one. Karlsson remembers that when he rushed to the kitchen, all the cupboards' left doors were in the same position (open or closed), similarly, all the cupboards' right doors were in the same position (open or closed). Karlsson wants the doors to meet this condition as well by the time the family returns. Karlsson does not remember the position of all the left doors, also, he cannot remember the position of all the right doors. Therefore, it does not matter to him in what position will be all left or right doors. It is important to leave all the left doors in the same position, and all the right doors in the same position. For example, all the left doors may be closed, and all the right ones may be open.
Karlsson needs one second to open or close a door of a cupboard. He understands that he has very little time before the family returns, so he wants to know the minimum number of seconds t, in which he is able to bring all the cupboard doors in the required position.
Your task is to write a program that will determine the required number of seconds t.
Input
The first input line contains a single integer n β the number of cupboards in the kitchen (2 β€ n β€ 104). Then follow n lines, each containing two integers li and ri (0 β€ li, ri β€ 1). Number li equals one, if the left door of the i-th cupboard is opened, otherwise number li equals zero. Similarly, number ri equals one, if the right door of the i-th cupboard is opened, otherwise number ri equals zero.
The numbers in the lines are separated by single spaces.
Output
In the only output line print a single integer t β the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs.
Examples
Input
5
0 1
1 0
0 1
1 1
0 1
Output
3 | instruction | 0 | 60,045 | 8 | 120,090 |
Tags: implementation
Correct Solution:
```
n = int(input())
L = []
R = []
countL = [0, 0]
countR = [0, 0]
for _ in range(n):
x, y = map(int, input().split())
L.append(x)
R.append(y)
countL[x]+=1
countR[y]+=1
maxL = countL.index(max(countL))
maxR = countR.index(max(countR))
count = 0
for i in range(n):
if(L[i] != maxL):
count+=1
if(R[i] != maxR):
count+=1
print(count)
``` | output | 1 | 60,045 | 8 | 120,091 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house.
Karlsson's gaze immediately fell on n wooden cupboards, standing in the kitchen. He immediately realized that these cupboards have hidden jam stocks. Karlsson began to fly greedily around the kitchen, opening and closing the cupboards' doors, grab and empty all the jars of jam that he could find.
And now all jars of jam are empty, Karlsson has had enough and does not want to leave traces of his stay, so as not to let down his friend. Each of the cupboards has two doors: the left one and the right one. Karlsson remembers that when he rushed to the kitchen, all the cupboards' left doors were in the same position (open or closed), similarly, all the cupboards' right doors were in the same position (open or closed). Karlsson wants the doors to meet this condition as well by the time the family returns. Karlsson does not remember the position of all the left doors, also, he cannot remember the position of all the right doors. Therefore, it does not matter to him in what position will be all left or right doors. It is important to leave all the left doors in the same position, and all the right doors in the same position. For example, all the left doors may be closed, and all the right ones may be open.
Karlsson needs one second to open or close a door of a cupboard. He understands that he has very little time before the family returns, so he wants to know the minimum number of seconds t, in which he is able to bring all the cupboard doors in the required position.
Your task is to write a program that will determine the required number of seconds t.
Input
The first input line contains a single integer n β the number of cupboards in the kitchen (2 β€ n β€ 104). Then follow n lines, each containing two integers li and ri (0 β€ li, ri β€ 1). Number li equals one, if the left door of the i-th cupboard is opened, otherwise number li equals zero. Similarly, number ri equals one, if the right door of the i-th cupboard is opened, otherwise number ri equals zero.
The numbers in the lines are separated by single spaces.
Output
In the only output line print a single integer t β the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs.
Examples
Input
5
0 1
1 0
0 1
1 1
0 1
Output
3 | instruction | 0 | 60,046 | 8 | 120,092 |
Tags: implementation
Correct Solution:
```
def main():
n = int(input())
left1 = 0
right1 = 0
for _ in range(n):
[l, r] = input().split()
left1 += 1 if l == '1' else 0
right1 += 1 if r == '1' else 0
left1 = min(left1, n - left1)
right1 = min(right1, n - right1)
print(left1 + right1)
if __name__ == '__main__':
main()
``` | output | 1 | 60,046 | 8 | 120,093 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house.
Karlsson's gaze immediately fell on n wooden cupboards, standing in the kitchen. He immediately realized that these cupboards have hidden jam stocks. Karlsson began to fly greedily around the kitchen, opening and closing the cupboards' doors, grab and empty all the jars of jam that he could find.
And now all jars of jam are empty, Karlsson has had enough and does not want to leave traces of his stay, so as not to let down his friend. Each of the cupboards has two doors: the left one and the right one. Karlsson remembers that when he rushed to the kitchen, all the cupboards' left doors were in the same position (open or closed), similarly, all the cupboards' right doors were in the same position (open or closed). Karlsson wants the doors to meet this condition as well by the time the family returns. Karlsson does not remember the position of all the left doors, also, he cannot remember the position of all the right doors. Therefore, it does not matter to him in what position will be all left or right doors. It is important to leave all the left doors in the same position, and all the right doors in the same position. For example, all the left doors may be closed, and all the right ones may be open.
Karlsson needs one second to open or close a door of a cupboard. He understands that he has very little time before the family returns, so he wants to know the minimum number of seconds t, in which he is able to bring all the cupboard doors in the required position.
Your task is to write a program that will determine the required number of seconds t.
Input
The first input line contains a single integer n β the number of cupboards in the kitchen (2 β€ n β€ 104). Then follow n lines, each containing two integers li and ri (0 β€ li, ri β€ 1). Number li equals one, if the left door of the i-th cupboard is opened, otherwise number li equals zero. Similarly, number ri equals one, if the right door of the i-th cupboard is opened, otherwise number ri equals zero.
The numbers in the lines are separated by single spaces.
Output
In the only output line print a single integer t β the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs.
Examples
Input
5
0 1
1 0
0 1
1 1
0 1
Output
3
Submitted Solution:
```
n=int(input())
left=[]
right=[]
for i in range(n):
l,r=(int(j) for j in input().split())
left.append(l)
right.append(r)
l_close=left.count(0)
l_open=left.count(1)
r_close=right.count(0)
r_open=right.count(1)
value=min(l_close,l_open)+min(r_close,r_open)
print(value)
``` | instruction | 0 | 60,047 | 8 | 120,094 |
Yes | output | 1 | 60,047 | 8 | 120,095 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house.
Karlsson's gaze immediately fell on n wooden cupboards, standing in the kitchen. He immediately realized that these cupboards have hidden jam stocks. Karlsson began to fly greedily around the kitchen, opening and closing the cupboards' doors, grab and empty all the jars of jam that he could find.
And now all jars of jam are empty, Karlsson has had enough and does not want to leave traces of his stay, so as not to let down his friend. Each of the cupboards has two doors: the left one and the right one. Karlsson remembers that when he rushed to the kitchen, all the cupboards' left doors were in the same position (open or closed), similarly, all the cupboards' right doors were in the same position (open or closed). Karlsson wants the doors to meet this condition as well by the time the family returns. Karlsson does not remember the position of all the left doors, also, he cannot remember the position of all the right doors. Therefore, it does not matter to him in what position will be all left or right doors. It is important to leave all the left doors in the same position, and all the right doors in the same position. For example, all the left doors may be closed, and all the right ones may be open.
Karlsson needs one second to open or close a door of a cupboard. He understands that he has very little time before the family returns, so he wants to know the minimum number of seconds t, in which he is able to bring all the cupboard doors in the required position.
Your task is to write a program that will determine the required number of seconds t.
Input
The first input line contains a single integer n β the number of cupboards in the kitchen (2 β€ n β€ 104). Then follow n lines, each containing two integers li and ri (0 β€ li, ri β€ 1). Number li equals one, if the left door of the i-th cupboard is opened, otherwise number li equals zero. Similarly, number ri equals one, if the right door of the i-th cupboard is opened, otherwise number ri equals zero.
The numbers in the lines are separated by single spaces.
Output
In the only output line print a single integer t β the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs.
Examples
Input
5
0 1
1 0
0 1
1 1
0 1
Output
3
Submitted Solution:
```
p=input
N=int(p())
L=0
R=0
for _ in'.'*N:
l,r=map(int,p().split())
L+=l
R+=r
print(min(L,N-L)+min(R,N-R))
``` | instruction | 0 | 60,048 | 8 | 120,096 |
Yes | output | 1 | 60,048 | 8 | 120,097 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house.
Karlsson's gaze immediately fell on n wooden cupboards, standing in the kitchen. He immediately realized that these cupboards have hidden jam stocks. Karlsson began to fly greedily around the kitchen, opening and closing the cupboards' doors, grab and empty all the jars of jam that he could find.
And now all jars of jam are empty, Karlsson has had enough and does not want to leave traces of his stay, so as not to let down his friend. Each of the cupboards has two doors: the left one and the right one. Karlsson remembers that when he rushed to the kitchen, all the cupboards' left doors were in the same position (open or closed), similarly, all the cupboards' right doors were in the same position (open or closed). Karlsson wants the doors to meet this condition as well by the time the family returns. Karlsson does not remember the position of all the left doors, also, he cannot remember the position of all the right doors. Therefore, it does not matter to him in what position will be all left or right doors. It is important to leave all the left doors in the same position, and all the right doors in the same position. For example, all the left doors may be closed, and all the right ones may be open.
Karlsson needs one second to open or close a door of a cupboard. He understands that he has very little time before the family returns, so he wants to know the minimum number of seconds t, in which he is able to bring all the cupboard doors in the required position.
Your task is to write a program that will determine the required number of seconds t.
Input
The first input line contains a single integer n β the number of cupboards in the kitchen (2 β€ n β€ 104). Then follow n lines, each containing two integers li and ri (0 β€ li, ri β€ 1). Number li equals one, if the left door of the i-th cupboard is opened, otherwise number li equals zero. Similarly, number ri equals one, if the right door of the i-th cupboard is opened, otherwise number ri equals zero.
The numbers in the lines are separated by single spaces.
Output
In the only output line print a single integer t β the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs.
Examples
Input
5
0 1
1 0
0 1
1 1
0 1
Output
3
Submitted Solution:
```
def cupboards(nums):
l, r = 0,0
for pair in nums:
l += pair[0]
r += pair[1]
return min(l, len(nums) - l) + min(r, len(nums) - r)
arr = []
for _ in range(int(input())):
a, b = map(int, input().split())
arr.append([a, b])
print(cupboards(arr))
``` | instruction | 0 | 60,049 | 8 | 120,098 |
Yes | output | 1 | 60,049 | 8 | 120,099 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house.
Karlsson's gaze immediately fell on n wooden cupboards, standing in the kitchen. He immediately realized that these cupboards have hidden jam stocks. Karlsson began to fly greedily around the kitchen, opening and closing the cupboards' doors, grab and empty all the jars of jam that he could find.
And now all jars of jam are empty, Karlsson has had enough and does not want to leave traces of his stay, so as not to let down his friend. Each of the cupboards has two doors: the left one and the right one. Karlsson remembers that when he rushed to the kitchen, all the cupboards' left doors were in the same position (open or closed), similarly, all the cupboards' right doors were in the same position (open or closed). Karlsson wants the doors to meet this condition as well by the time the family returns. Karlsson does not remember the position of all the left doors, also, he cannot remember the position of all the right doors. Therefore, it does not matter to him in what position will be all left or right doors. It is important to leave all the left doors in the same position, and all the right doors in the same position. For example, all the left doors may be closed, and all the right ones may be open.
Karlsson needs one second to open or close a door of a cupboard. He understands that he has very little time before the family returns, so he wants to know the minimum number of seconds t, in which he is able to bring all the cupboard doors in the required position.
Your task is to write a program that will determine the required number of seconds t.
Input
The first input line contains a single integer n β the number of cupboards in the kitchen (2 β€ n β€ 104). Then follow n lines, each containing two integers li and ri (0 β€ li, ri β€ 1). Number li equals one, if the left door of the i-th cupboard is opened, otherwise number li equals zero. Similarly, number ri equals one, if the right door of the i-th cupboard is opened, otherwise number ri equals zero.
The numbers in the lines are separated by single spaces.
Output
In the only output line print a single integer t β the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs.
Examples
Input
5
0 1
1 0
0 1
1 1
0 1
Output
3
Submitted Solution:
```
def cupboard(n, l, r):
lcount = l.count(1)
rcount = r.count(1)
li = min(lcount, n-lcount)
ri = min(rcount, n-rcount)
return li+ri
n = int(input())
larr = []
rarr = []
for i in range(n):
l, r = map(int, input().split())
larr.append(l)
rarr.append(r)
print(cupboard(n, larr, rarr))
``` | instruction | 0 | 60,050 | 8 | 120,100 |
Yes | output | 1 | 60,050 | 8 | 120,101 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house.
Karlsson's gaze immediately fell on n wooden cupboards, standing in the kitchen. He immediately realized that these cupboards have hidden jam stocks. Karlsson began to fly greedily around the kitchen, opening and closing the cupboards' doors, grab and empty all the jars of jam that he could find.
And now all jars of jam are empty, Karlsson has had enough and does not want to leave traces of his stay, so as not to let down his friend. Each of the cupboards has two doors: the left one and the right one. Karlsson remembers that when he rushed to the kitchen, all the cupboards' left doors were in the same position (open or closed), similarly, all the cupboards' right doors were in the same position (open or closed). Karlsson wants the doors to meet this condition as well by the time the family returns. Karlsson does not remember the position of all the left doors, also, he cannot remember the position of all the right doors. Therefore, it does not matter to him in what position will be all left or right doors. It is important to leave all the left doors in the same position, and all the right doors in the same position. For example, all the left doors may be closed, and all the right ones may be open.
Karlsson needs one second to open or close a door of a cupboard. He understands that he has very little time before the family returns, so he wants to know the minimum number of seconds t, in which he is able to bring all the cupboard doors in the required position.
Your task is to write a program that will determine the required number of seconds t.
Input
The first input line contains a single integer n β the number of cupboards in the kitchen (2 β€ n β€ 104). Then follow n lines, each containing two integers li and ri (0 β€ li, ri β€ 1). Number li equals one, if the left door of the i-th cupboard is opened, otherwise number li equals zero. Similarly, number ri equals one, if the right door of the i-th cupboard is opened, otherwise number ri equals zero.
The numbers in the lines are separated by single spaces.
Output
In the only output line print a single integer t β the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs.
Examples
Input
5
0 1
1 0
0 1
1 1
0 1
Output
3
Submitted Solution:
```
a=int(input())
count=0
for i in range(a):
c,d=map(int,input().split())
if c==1:
count+=1
if d==0:
count+=1
print(count)
``` | instruction | 0 | 60,051 | 8 | 120,102 |
No | output | 1 | 60,051 | 8 | 120,103 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house.
Karlsson's gaze immediately fell on n wooden cupboards, standing in the kitchen. He immediately realized that these cupboards have hidden jam stocks. Karlsson began to fly greedily around the kitchen, opening and closing the cupboards' doors, grab and empty all the jars of jam that he could find.
And now all jars of jam are empty, Karlsson has had enough and does not want to leave traces of his stay, so as not to let down his friend. Each of the cupboards has two doors: the left one and the right one. Karlsson remembers that when he rushed to the kitchen, all the cupboards' left doors were in the same position (open or closed), similarly, all the cupboards' right doors were in the same position (open or closed). Karlsson wants the doors to meet this condition as well by the time the family returns. Karlsson does not remember the position of all the left doors, also, he cannot remember the position of all the right doors. Therefore, it does not matter to him in what position will be all left or right doors. It is important to leave all the left doors in the same position, and all the right doors in the same position. For example, all the left doors may be closed, and all the right ones may be open.
Karlsson needs one second to open or close a door of a cupboard. He understands that he has very little time before the family returns, so he wants to know the minimum number of seconds t, in which he is able to bring all the cupboard doors in the required position.
Your task is to write a program that will determine the required number of seconds t.
Input
The first input line contains a single integer n β the number of cupboards in the kitchen (2 β€ n β€ 104). Then follow n lines, each containing two integers li and ri (0 β€ li, ri β€ 1). Number li equals one, if the left door of the i-th cupboard is opened, otherwise number li equals zero. Similarly, number ri equals one, if the right door of the i-th cupboard is opened, otherwise number ri equals zero.
The numbers in the lines are separated by single spaces.
Output
In the only output line print a single integer t β the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs.
Examples
Input
5
0 1
1 0
0 1
1 1
0 1
Output
3
Submitted Solution:
```
n = int(input())
s = []
c = [0]*4
for i in range(n):
s.append(list(map(int, input().split())))
for i in range(n):
if s[i][0] == 0 and s[i][1] == 0:
c[0] += 1
elif s[i][0] == 0 and s[i][1] == 1:
c[1] += 1
elif s[i][0] == 1 and s[i][1] == 0:
c[2] += 1
else:
c[3] += 1
maxc = max(c)
for i in range(4):
if s.count(s[i]) == maxc:
temp = s[i]
break
ans = 0
for i in range(n):
ans += abs(temp[0] - s[i][0]) + abs(temp[1] - s[i][1])
print(ans)
``` | instruction | 0 | 60,052 | 8 | 120,104 |
No | output | 1 | 60,052 | 8 | 120,105 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house.
Karlsson's gaze immediately fell on n wooden cupboards, standing in the kitchen. He immediately realized that these cupboards have hidden jam stocks. Karlsson began to fly greedily around the kitchen, opening and closing the cupboards' doors, grab and empty all the jars of jam that he could find.
And now all jars of jam are empty, Karlsson has had enough and does not want to leave traces of his stay, so as not to let down his friend. Each of the cupboards has two doors: the left one and the right one. Karlsson remembers that when he rushed to the kitchen, all the cupboards' left doors were in the same position (open or closed), similarly, all the cupboards' right doors were in the same position (open or closed). Karlsson wants the doors to meet this condition as well by the time the family returns. Karlsson does not remember the position of all the left doors, also, he cannot remember the position of all the right doors. Therefore, it does not matter to him in what position will be all left or right doors. It is important to leave all the left doors in the same position, and all the right doors in the same position. For example, all the left doors may be closed, and all the right ones may be open.
Karlsson needs one second to open or close a door of a cupboard. He understands that he has very little time before the family returns, so he wants to know the minimum number of seconds t, in which he is able to bring all the cupboard doors in the required position.
Your task is to write a program that will determine the required number of seconds t.
Input
The first input line contains a single integer n β the number of cupboards in the kitchen (2 β€ n β€ 104). Then follow n lines, each containing two integers li and ri (0 β€ li, ri β€ 1). Number li equals one, if the left door of the i-th cupboard is opened, otherwise number li equals zero. Similarly, number ri equals one, if the right door of the i-th cupboard is opened, otherwise number ri equals zero.
The numbers in the lines are separated by single spaces.
Output
In the only output line print a single integer t β the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs.
Examples
Input
5
0 1
1 0
0 1
1 1
0 1
Output
3
Submitted Solution:
```
n = int(input())
l = []
r = []
for i in range(n):
a,b = input().split()
l.append(a)
r.append(b)
ans1 = 0
ans2 = 0
if l.count('1')>=r.count('1'):
ans1 = l.count('0')
ans2 = r.count('1')
else:
ans2 = r.count('0')
ans1 = l.count('1')
print(ans1+ans2)
``` | instruction | 0 | 60,053 | 8 | 120,106 |
No | output | 1 | 60,053 | 8 | 120,107 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house.
Karlsson's gaze immediately fell on n wooden cupboards, standing in the kitchen. He immediately realized that these cupboards have hidden jam stocks. Karlsson began to fly greedily around the kitchen, opening and closing the cupboards' doors, grab and empty all the jars of jam that he could find.
And now all jars of jam are empty, Karlsson has had enough and does not want to leave traces of his stay, so as not to let down his friend. Each of the cupboards has two doors: the left one and the right one. Karlsson remembers that when he rushed to the kitchen, all the cupboards' left doors were in the same position (open or closed), similarly, all the cupboards' right doors were in the same position (open or closed). Karlsson wants the doors to meet this condition as well by the time the family returns. Karlsson does not remember the position of all the left doors, also, he cannot remember the position of all the right doors. Therefore, it does not matter to him in what position will be all left or right doors. It is important to leave all the left doors in the same position, and all the right doors in the same position. For example, all the left doors may be closed, and all the right ones may be open.
Karlsson needs one second to open or close a door of a cupboard. He understands that he has very little time before the family returns, so he wants to know the minimum number of seconds t, in which he is able to bring all the cupboard doors in the required position.
Your task is to write a program that will determine the required number of seconds t.
Input
The first input line contains a single integer n β the number of cupboards in the kitchen (2 β€ n β€ 104). Then follow n lines, each containing two integers li and ri (0 β€ li, ri β€ 1). Number li equals one, if the left door of the i-th cupboard is opened, otherwise number li equals zero. Similarly, number ri equals one, if the right door of the i-th cupboard is opened, otherwise number ri equals zero.
The numbers in the lines are separated by single spaces.
Output
In the only output line print a single integer t β the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs.
Examples
Input
5
0 1
1 0
0 1
1 1
0 1
Output
3
Submitted Solution:
```
#
num = int(input())
lCount = 0
rCount = 0
for i in range(num):
l,r = input().split()
lCount += int(l)
rCount += int(r)
if lCount > rCount:
total = (num - lCount) + rCount
elif lCount == rCount:
total = lCount + rCount
else:
total = (num - rCount) + lCount
print(total)
``` | instruction | 0 | 60,054 | 8 | 120,108 |
No | output | 1 | 60,054 | 8 | 120,109 |
Provide tags and a correct Python 3 solution for this coding contest problem.
On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy.
The toy consists of n parts and m ropes. Each rope links two parts, but every pair of parts is linked by at most one rope. To split the toy, the child must remove all its parts. The child can remove a single part at a time, and each remove consume an energy. Let's define an energy value of part i as vi. The child spend vf1 + vf2 + ... + vfk energy for removing part i where f1, f2, ..., fk are the parts that are directly connected to the i-th and haven't been removed.
Help the child to find out, what is the minimum total energy he should spend to remove all n parts.
Input
The first line contains two integers n and m (1 β€ n β€ 1000; 0 β€ m β€ 2000). The second line contains n integers: v1, v2, ..., vn (0 β€ vi β€ 105). Then followed m lines, each line contains two integers xi and yi, representing a rope from part xi to part yi (1 β€ xi, yi β€ n; xi β yi).
Consider all the parts are numbered from 1 to n.
Output
Output the minimum total energy the child should spend to remove all n parts of the toy.
Examples
Input
4 3
10 20 30 40
1 4
1 2
2 3
Output
40
Input
4 4
100 100 100 100
1 2
2 3
2 4
3 4
Output
400
Input
7 10
40 10 20 10 20 80 40
1 5
4 7
4 5
5 2
5 7
6 4
1 6
1 3
4 3
1 4
Output
160
Note
One of the optimal sequence of actions in the first sample is:
* First, remove part 3, cost of the action is 20.
* Then, remove part 2, cost of the action is 10.
* Next, remove part 4, cost of the action is 10.
* At last, remove part 1, cost of the action is 0.
So the total energy the child paid is 20 + 10 + 10 + 0 = 40, which is the minimum.
In the second sample, the child will spend 400 no matter in what order he will remove the parts. | instruction | 0 | 60,134 | 8 | 120,268 |
Tags: graphs, greedy, sortings
Correct Solution:
```
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def main():
n,m = LI()
a = LI()
aa = [LI_() for _ in range(m)]
r = 0
for b,c in aa:
r += min(a[b], a[c])
return r
print(main())
``` | output | 1 | 60,134 | 8 | 120,269 |
Provide tags and a correct Python 3 solution for this coding contest problem.
On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy.
The toy consists of n parts and m ropes. Each rope links two parts, but every pair of parts is linked by at most one rope. To split the toy, the child must remove all its parts. The child can remove a single part at a time, and each remove consume an energy. Let's define an energy value of part i as vi. The child spend vf1 + vf2 + ... + vfk energy for removing part i where f1, f2, ..., fk are the parts that are directly connected to the i-th and haven't been removed.
Help the child to find out, what is the minimum total energy he should spend to remove all n parts.
Input
The first line contains two integers n and m (1 β€ n β€ 1000; 0 β€ m β€ 2000). The second line contains n integers: v1, v2, ..., vn (0 β€ vi β€ 105). Then followed m lines, each line contains two integers xi and yi, representing a rope from part xi to part yi (1 β€ xi, yi β€ n; xi β yi).
Consider all the parts are numbered from 1 to n.
Output
Output the minimum total energy the child should spend to remove all n parts of the toy.
Examples
Input
4 3
10 20 30 40
1 4
1 2
2 3
Output
40
Input
4 4
100 100 100 100
1 2
2 3
2 4
3 4
Output
400
Input
7 10
40 10 20 10 20 80 40
1 5
4 7
4 5
5 2
5 7
6 4
1 6
1 3
4 3
1 4
Output
160
Note
One of the optimal sequence of actions in the first sample is:
* First, remove part 3, cost of the action is 20.
* Then, remove part 2, cost of the action is 10.
* Next, remove part 4, cost of the action is 10.
* At last, remove part 1, cost of the action is 0.
So the total energy the child paid is 20 + 10 + 10 + 0 = 40, which is the minimum.
In the second sample, the child will spend 400 no matter in what order he will remove the parts. | instruction | 0 | 60,135 | 8 | 120,270 |
Tags: graphs, greedy, sortings
Correct Solution:
```
n, m = map(int, input().split())
w = list(map(int, input().split()))
ans = 0
for i in range(m):
x, y = map(int, input().split())
ans += min(w[x-1], w[y-1])
print(ans)
``` | output | 1 | 60,135 | 8 | 120,271 |
Provide tags and a correct Python 3 solution for this coding contest problem.
On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy.
The toy consists of n parts and m ropes. Each rope links two parts, but every pair of parts is linked by at most one rope. To split the toy, the child must remove all its parts. The child can remove a single part at a time, and each remove consume an energy. Let's define an energy value of part i as vi. The child spend vf1 + vf2 + ... + vfk energy for removing part i where f1, f2, ..., fk are the parts that are directly connected to the i-th and haven't been removed.
Help the child to find out, what is the minimum total energy he should spend to remove all n parts.
Input
The first line contains two integers n and m (1 β€ n β€ 1000; 0 β€ m β€ 2000). The second line contains n integers: v1, v2, ..., vn (0 β€ vi β€ 105). Then followed m lines, each line contains two integers xi and yi, representing a rope from part xi to part yi (1 β€ xi, yi β€ n; xi β yi).
Consider all the parts are numbered from 1 to n.
Output
Output the minimum total energy the child should spend to remove all n parts of the toy.
Examples
Input
4 3
10 20 30 40
1 4
1 2
2 3
Output
40
Input
4 4
100 100 100 100
1 2
2 3
2 4
3 4
Output
400
Input
7 10
40 10 20 10 20 80 40
1 5
4 7
4 5
5 2
5 7
6 4
1 6
1 3
4 3
1 4
Output
160
Note
One of the optimal sequence of actions in the first sample is:
* First, remove part 3, cost of the action is 20.
* Then, remove part 2, cost of the action is 10.
* Next, remove part 4, cost of the action is 10.
* At last, remove part 1, cost of the action is 0.
So the total energy the child paid is 20 + 10 + 10 + 0 = 40, which is the minimum.
In the second sample, the child will spend 400 no matter in what order he will remove the parts. | instruction | 0 | 60,136 | 8 | 120,272 |
Tags: graphs, greedy, sortings
Correct Solution:
```
n,m=map(int,input().split())
v=list(map(int,input().split()))
V=list(v)
Cost=[0]*n
Children=[]
for i in range(n):
V[i]=(v[i],i)
Children.append([])
V.sort(reverse=True)
for i in range(m):
x,y=map(int,input().split())
x-=1
y-=1
Children[x].append(y)
Children[y].append(x)
Cost[x]+=v[y]
Cost[y]+=v[x]
ans=0
for i in range(n):
z=V[i][0]
x=V[i][1]
ans+=Cost[x]
for child in Children[x]:
Cost[child]-=z
print(ans)
``` | output | 1 | 60,136 | 8 | 120,273 |
Provide tags and a correct Python 3 solution for this coding contest problem.
On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy.
The toy consists of n parts and m ropes. Each rope links two parts, but every pair of parts is linked by at most one rope. To split the toy, the child must remove all its parts. The child can remove a single part at a time, and each remove consume an energy. Let's define an energy value of part i as vi. The child spend vf1 + vf2 + ... + vfk energy for removing part i where f1, f2, ..., fk are the parts that are directly connected to the i-th and haven't been removed.
Help the child to find out, what is the minimum total energy he should spend to remove all n parts.
Input
The first line contains two integers n and m (1 β€ n β€ 1000; 0 β€ m β€ 2000). The second line contains n integers: v1, v2, ..., vn (0 β€ vi β€ 105). Then followed m lines, each line contains two integers xi and yi, representing a rope from part xi to part yi (1 β€ xi, yi β€ n; xi β yi).
Consider all the parts are numbered from 1 to n.
Output
Output the minimum total energy the child should spend to remove all n parts of the toy.
Examples
Input
4 3
10 20 30 40
1 4
1 2
2 3
Output
40
Input
4 4
100 100 100 100
1 2
2 3
2 4
3 4
Output
400
Input
7 10
40 10 20 10 20 80 40
1 5
4 7
4 5
5 2
5 7
6 4
1 6
1 3
4 3
1 4
Output
160
Note
One of the optimal sequence of actions in the first sample is:
* First, remove part 3, cost of the action is 20.
* Then, remove part 2, cost of the action is 10.
* Next, remove part 4, cost of the action is 10.
* At last, remove part 1, cost of the action is 0.
So the total energy the child paid is 20 + 10 + 10 + 0 = 40, which is the minimum.
In the second sample, the child will spend 400 no matter in what order he will remove the parts. | instruction | 0 | 60,137 | 8 | 120,274 |
Tags: graphs, greedy, sortings
Correct Solution:
```
R = lambda:map(int, input().split())
n, m = R()
v = [0] + list(R())
print(sum(min(v[x], v[y]) for x, y in (R() for i in range(m))))
# Made By Mostafa_Khaled
``` | output | 1 | 60,137 | 8 | 120,275 |
Provide tags and a correct Python 3 solution for this coding contest problem.
On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy.
The toy consists of n parts and m ropes. Each rope links two parts, but every pair of parts is linked by at most one rope. To split the toy, the child must remove all its parts. The child can remove a single part at a time, and each remove consume an energy. Let's define an energy value of part i as vi. The child spend vf1 + vf2 + ... + vfk energy for removing part i where f1, f2, ..., fk are the parts that are directly connected to the i-th and haven't been removed.
Help the child to find out, what is the minimum total energy he should spend to remove all n parts.
Input
The first line contains two integers n and m (1 β€ n β€ 1000; 0 β€ m β€ 2000). The second line contains n integers: v1, v2, ..., vn (0 β€ vi β€ 105). Then followed m lines, each line contains two integers xi and yi, representing a rope from part xi to part yi (1 β€ xi, yi β€ n; xi β yi).
Consider all the parts are numbered from 1 to n.
Output
Output the minimum total energy the child should spend to remove all n parts of the toy.
Examples
Input
4 3
10 20 30 40
1 4
1 2
2 3
Output
40
Input
4 4
100 100 100 100
1 2
2 3
2 4
3 4
Output
400
Input
7 10
40 10 20 10 20 80 40
1 5
4 7
4 5
5 2
5 7
6 4
1 6
1 3
4 3
1 4
Output
160
Note
One of the optimal sequence of actions in the first sample is:
* First, remove part 3, cost of the action is 20.
* Then, remove part 2, cost of the action is 10.
* Next, remove part 4, cost of the action is 10.
* At last, remove part 1, cost of the action is 0.
So the total energy the child paid is 20 + 10 + 10 + 0 = 40, which is the minimum.
In the second sample, the child will spend 400 no matter in what order he will remove the parts. | instruction | 0 | 60,138 | 8 | 120,276 |
Tags: graphs, greedy, sortings
Correct Solution:
```
n, m = map(int, input().split())
v =[0]+ list(map(int, input().split()))
r = 0
for i in range(m):
r += min(v[i] for i in map(int, input().split()))
print(r)
``` | output | 1 | 60,138 | 8 | 120,277 |
Provide tags and a correct Python 3 solution for this coding contest problem.
On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy.
The toy consists of n parts and m ropes. Each rope links two parts, but every pair of parts is linked by at most one rope. To split the toy, the child must remove all its parts. The child can remove a single part at a time, and each remove consume an energy. Let's define an energy value of part i as vi. The child spend vf1 + vf2 + ... + vfk energy for removing part i where f1, f2, ..., fk are the parts that are directly connected to the i-th and haven't been removed.
Help the child to find out, what is the minimum total energy he should spend to remove all n parts.
Input
The first line contains two integers n and m (1 β€ n β€ 1000; 0 β€ m β€ 2000). The second line contains n integers: v1, v2, ..., vn (0 β€ vi β€ 105). Then followed m lines, each line contains two integers xi and yi, representing a rope from part xi to part yi (1 β€ xi, yi β€ n; xi β yi).
Consider all the parts are numbered from 1 to n.
Output
Output the minimum total energy the child should spend to remove all n parts of the toy.
Examples
Input
4 3
10 20 30 40
1 4
1 2
2 3
Output
40
Input
4 4
100 100 100 100
1 2
2 3
2 4
3 4
Output
400
Input
7 10
40 10 20 10 20 80 40
1 5
4 7
4 5
5 2
5 7
6 4
1 6
1 3
4 3
1 4
Output
160
Note
One of the optimal sequence of actions in the first sample is:
* First, remove part 3, cost of the action is 20.
* Then, remove part 2, cost of the action is 10.
* Next, remove part 4, cost of the action is 10.
* At last, remove part 1, cost of the action is 0.
So the total energy the child paid is 20 + 10 + 10 + 0 = 40, which is the minimum.
In the second sample, the child will spend 400 no matter in what order he will remove the parts. | instruction | 0 | 60,139 | 8 | 120,278 |
Tags: graphs, greedy, sortings
Correct Solution:
```
(n, m) = list(map(int, input().split(' ')))
v = list(map(int, input().split(' ')))
r = 0
for mm in range(m):
(x, y) = list(map(int, input().split(' ')))
x -= 1
y -= 1
if(v[x] > v[y]):
r += v[y]
else:
r += v[x]
print(r)
``` | output | 1 | 60,139 | 8 | 120,279 |
Provide tags and a correct Python 3 solution for this coding contest problem.
On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy.
The toy consists of n parts and m ropes. Each rope links two parts, but every pair of parts is linked by at most one rope. To split the toy, the child must remove all its parts. The child can remove a single part at a time, and each remove consume an energy. Let's define an energy value of part i as vi. The child spend vf1 + vf2 + ... + vfk energy for removing part i where f1, f2, ..., fk are the parts that are directly connected to the i-th and haven't been removed.
Help the child to find out, what is the minimum total energy he should spend to remove all n parts.
Input
The first line contains two integers n and m (1 β€ n β€ 1000; 0 β€ m β€ 2000). The second line contains n integers: v1, v2, ..., vn (0 β€ vi β€ 105). Then followed m lines, each line contains two integers xi and yi, representing a rope from part xi to part yi (1 β€ xi, yi β€ n; xi β yi).
Consider all the parts are numbered from 1 to n.
Output
Output the minimum total energy the child should spend to remove all n parts of the toy.
Examples
Input
4 3
10 20 30 40
1 4
1 2
2 3
Output
40
Input
4 4
100 100 100 100
1 2
2 3
2 4
3 4
Output
400
Input
7 10
40 10 20 10 20 80 40
1 5
4 7
4 5
5 2
5 7
6 4
1 6
1 3
4 3
1 4
Output
160
Note
One of the optimal sequence of actions in the first sample is:
* First, remove part 3, cost of the action is 20.
* Then, remove part 2, cost of the action is 10.
* Next, remove part 4, cost of the action is 10.
* At last, remove part 1, cost of the action is 0.
So the total energy the child paid is 20 + 10 + 10 + 0 = 40, which is the minimum.
In the second sample, the child will spend 400 no matter in what order he will remove the parts. | instruction | 0 | 60,140 | 8 | 120,280 |
Tags: graphs, greedy, sortings
Correct Solution:
```
n,m = map(int, input().split(' '))
V = list(map(int, input().split(' ')))
edge = [set() for i in range(n)]
for i in range(m) :
a,b = map(int, input().split(' '))
a-=1;b-=1
edge[a].add(b)
edge[b].add(a)
L = [[V[i], i]for i in range(n)]
L.sort(key = lambda x:x[0])
ans = 0
for l in L :
ans += l[0]*len(edge[l[1]])
for i in edge[l[1]] :
edge[i].remove(l[1])
edge[l[1]].clear()
print(ans)
``` | output | 1 | 60,140 | 8 | 120,281 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy.
The toy consists of n parts and m ropes. Each rope links two parts, but every pair of parts is linked by at most one rope. To split the toy, the child must remove all its parts. The child can remove a single part at a time, and each remove consume an energy. Let's define an energy value of part i as vi. The child spend vf1 + vf2 + ... + vfk energy for removing part i where f1, f2, ..., fk are the parts that are directly connected to the i-th and haven't been removed.
Help the child to find out, what is the minimum total energy he should spend to remove all n parts.
Input
The first line contains two integers n and m (1 β€ n β€ 1000; 0 β€ m β€ 2000). The second line contains n integers: v1, v2, ..., vn (0 β€ vi β€ 105). Then followed m lines, each line contains two integers xi and yi, representing a rope from part xi to part yi (1 β€ xi, yi β€ n; xi β yi).
Consider all the parts are numbered from 1 to n.
Output
Output the minimum total energy the child should spend to remove all n parts of the toy.
Examples
Input
4 3
10 20 30 40
1 4
1 2
2 3
Output
40
Input
4 4
100 100 100 100
1 2
2 3
2 4
3 4
Output
400
Input
7 10
40 10 20 10 20 80 40
1 5
4 7
4 5
5 2
5 7
6 4
1 6
1 3
4 3
1 4
Output
160
Note
One of the optimal sequence of actions in the first sample is:
* First, remove part 3, cost of the action is 20.
* Then, remove part 2, cost of the action is 10.
* Next, remove part 4, cost of the action is 10.
* At last, remove part 1, cost of the action is 0.
So the total energy the child paid is 20 + 10 + 10 + 0 = 40, which is the minimum.
In the second sample, the child will spend 400 no matter in what order he will remove the parts.
Submitted Solution:
```
n, m = map(int, input().split())
v = [0] + list(map(int, input().split()))
r = 0
for i in range(m):
r += v[min(map(int, input().split()))]
print(r)
``` | instruction | 0 | 60,141 | 8 | 120,282 |
No | output | 1 | 60,141 | 8 | 120,283 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy.
The toy consists of n parts and m ropes. Each rope links two parts, but every pair of parts is linked by at most one rope. To split the toy, the child must remove all its parts. The child can remove a single part at a time, and each remove consume an energy. Let's define an energy value of part i as vi. The child spend vf1 + vf2 + ... + vfk energy for removing part i where f1, f2, ..., fk are the parts that are directly connected to the i-th and haven't been removed.
Help the child to find out, what is the minimum total energy he should spend to remove all n parts.
Input
The first line contains two integers n and m (1 β€ n β€ 1000; 0 β€ m β€ 2000). The second line contains n integers: v1, v2, ..., vn (0 β€ vi β€ 105). Then followed m lines, each line contains two integers xi and yi, representing a rope from part xi to part yi (1 β€ xi, yi β€ n; xi β yi).
Consider all the parts are numbered from 1 to n.
Output
Output the minimum total energy the child should spend to remove all n parts of the toy.
Examples
Input
4 3
10 20 30 40
1 4
1 2
2 3
Output
40
Input
4 4
100 100 100 100
1 2
2 3
2 4
3 4
Output
400
Input
7 10
40 10 20 10 20 80 40
1 5
4 7
4 5
5 2
5 7
6 4
1 6
1 3
4 3
1 4
Output
160
Note
One of the optimal sequence of actions in the first sample is:
* First, remove part 3, cost of the action is 20.
* Then, remove part 2, cost of the action is 10.
* Next, remove part 4, cost of the action is 10.
* At last, remove part 1, cost of the action is 0.
So the total energy the child paid is 20 + 10 + 10 + 0 = 40, which is the minimum.
In the second sample, the child will spend 400 no matter in what order he will remove the parts.
Submitted Solution:
```
n, m = map(int, input().split())
v = list(map(int, input().split()))
r = 0
for i in range(m):
r += min(map(int, input().split()))
print(r)
``` | instruction | 0 | 60,142 | 8 | 120,284 |
No | output | 1 | 60,142 | 8 | 120,285 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at the exhibition of contemporary art.
The main exhibit is a construction of n matryoshka dolls that can be nested one into another. The matryoshka dolls are numbered from 1 to n. A matryoshka with a smaller number can be nested in a matryoshka with a higher number, two matryoshkas can not be directly nested in the same doll, but there may be chain nestings, for example, 1 β 2 β 4 β 5.
In one second, you can perform one of the two following operations:
* Having a matryoshka a that isn't nested in any other matryoshka and a matryoshka b, such that b doesn't contain any other matryoshka and is not nested in any other matryoshka, you may put a in b;
* Having a matryoshka a directly contained in matryoshka b, such that b is not nested in any other matryoshka, you may get a out of b.
According to the modern aesthetic norms the matryoshka dolls on display were assembled in a specific configuration, i.e. as several separate chains of nested matryoshkas, but the criminal, following the mysterious plan, took out all the dolls and assembled them into a single large chain (1 β 2 β ... β n). In order to continue the investigation Andrewid needs to know in what minimum time it is possible to perform this action.
Input
The first line contains integers n (1 β€ n β€ 105) and k (1 β€ k β€ 105) β the number of matryoshkas and matryoshka chains in the initial configuration.
The next k lines contain the descriptions of the chains: the i-th line first contains number mi (1 β€ mi β€ n), and then mi numbers ai1, ai2, ..., aimi β the numbers of matryoshkas in the chain (matryoshka ai1 is nested into matryoshka ai2, that is nested into matryoshka ai3, and so on till the matryoshka aimi that isn't nested into any other matryoshka).
It is guaranteed that m1 + m2 + ... + mk = n, the numbers of matryoshkas in all the chains are distinct, in each chain the numbers of matryoshkas follow in the ascending order.
Output
In the single line print the minimum number of seconds needed to assemble one large chain from the initial configuration.
Examples
Input
3 2
2 1 2
1 3
Output
1
Input
7 3
3 1 3 7
2 2 5
2 4 6
Output
10
Note
In the first sample test there are two chains: 1 β 2 and 3. In one second you can nest the first chain into the second one and get 1 β 2 β 3.
In the second sample test you need to disassemble all the three chains into individual matryoshkas in 2 + 1 + 1 = 4 seconds and then assemble one big chain in 6 seconds. | instruction | 0 | 60,183 | 8 | 120,366 |
Tags: implementation
Correct Solution:
```
n, m = map(int, input().split())
c = {}
r = 0
for _ in range(m):
t = list(map(int, input().split()))
c[t[1]] = t[2:]
d = list(c.keys())
for v in d:
if v == 1:
if c[v]:
x = 0
for i in range(len(c[v])):
if c[v][i] != i + 2:
break
x += 1
r += len(c[v]) - x
else:
r += len(c[v])
print(len(d) + r * 2 - 1)
``` | output | 1 | 60,183 | 8 | 120,367 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at the exhibition of contemporary art.
The main exhibit is a construction of n matryoshka dolls that can be nested one into another. The matryoshka dolls are numbered from 1 to n. A matryoshka with a smaller number can be nested in a matryoshka with a higher number, two matryoshkas can not be directly nested in the same doll, but there may be chain nestings, for example, 1 β 2 β 4 β 5.
In one second, you can perform one of the two following operations:
* Having a matryoshka a that isn't nested in any other matryoshka and a matryoshka b, such that b doesn't contain any other matryoshka and is not nested in any other matryoshka, you may put a in b;
* Having a matryoshka a directly contained in matryoshka b, such that b is not nested in any other matryoshka, you may get a out of b.
According to the modern aesthetic norms the matryoshka dolls on display were assembled in a specific configuration, i.e. as several separate chains of nested matryoshkas, but the criminal, following the mysterious plan, took out all the dolls and assembled them into a single large chain (1 β 2 β ... β n). In order to continue the investigation Andrewid needs to know in what minimum time it is possible to perform this action.
Input
The first line contains integers n (1 β€ n β€ 105) and k (1 β€ k β€ 105) β the number of matryoshkas and matryoshka chains in the initial configuration.
The next k lines contain the descriptions of the chains: the i-th line first contains number mi (1 β€ mi β€ n), and then mi numbers ai1, ai2, ..., aimi β the numbers of matryoshkas in the chain (matryoshka ai1 is nested into matryoshka ai2, that is nested into matryoshka ai3, and so on till the matryoshka aimi that isn't nested into any other matryoshka).
It is guaranteed that m1 + m2 + ... + mk = n, the numbers of matryoshkas in all the chains are distinct, in each chain the numbers of matryoshkas follow in the ascending order.
Output
In the single line print the minimum number of seconds needed to assemble one large chain from the initial configuration.
Examples
Input
3 2
2 1 2
1 3
Output
1
Input
7 3
3 1 3 7
2 2 5
2 4 6
Output
10
Note
In the first sample test there are two chains: 1 β 2 and 3. In one second you can nest the first chain into the second one and get 1 β 2 β 3.
In the second sample test you need to disassemble all the three chains into individual matryoshkas in 2 + 1 + 1 = 4 seconds and then assemble one big chain in 6 seconds. | instruction | 0 | 60,184 | 8 | 120,368 |
Tags: implementation
Correct Solution:
```
#!/usr/bin/env python
# 556C_matr.py - Codeforces.com 556C Matr quiz
#
# Copyright (C) 2015 Sergey
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Input
The first line contains integers n and k the number of matryoshkas and
matryoshka chains in the initial configuration.
Output
In the single line print the minimum number of seconds needed to assemble
one large chain from the initial configuration.
"""
# Standard libraries
import unittest
import sys
import re
# Additional libraries
###############################################################################
# Matr Class
###############################################################################
class Matr:
""" Matr representation """
def __init__(self, args):
""" Default constructor """
self.n = args[0]
self.k = args[1]
self.list = args[2]
def turns(self):
result = 0
for l in self.list:
result += len(l) - 1
result += self.n - 1
return result
def reduce(self):
result = 0
for l in self.list:
max = 0
for i in range(len(l)):
if l[i] == i + 1:
max = i
result += max * 2
return result
def calculate(self):
""" Main calcualtion function of the class """
turns = self.turns()
reduce = self.reduce()
result = turns - reduce
return str(result)
###############################################################################
# Executable code
###############################################################################
def get_inputs(test_inputs=None):
it = iter(test_inputs.split("\n")) if test_inputs else None
def uinput():
""" Unit-testable input function wrapper """
if it:
return next(it)
else:
return input()
# Getting string inputs
nums = [int(s) for s in uinput().split()]
strs = []
for i in range(nums[1]):
list = [int(s) for s in uinput().split()]
list.pop(0)
strs.append(list)
# Decoding inputs
inputs = nums
inputs.append(strs)
return inputs
def calculate(test_inputs=None):
""" Base class calculate method wrapper """
return Matr(get_inputs(test_inputs)).calculate()
###############################################################################
# Unit Tests
###############################################################################
class unitTests(unittest.TestCase):
def test_sample_tests(self):
""" Quiz sample tests. Add \n to separate lines """
self.assertEqual(calculate("3 2\n2 1 2\n1 3"), "1")
self.assertEqual(calculate("7 3\n3 1 3 7\n2 2 5\n2 4 6"), "10")
def test_get_inputs(self):
""" Input string decoding testing """
self.assertEqual(
get_inputs("3 2\n2 1 2\n1 3"), [3, 2, [[1, 2], [3]]])
def test_Matr_class__basic_functions(self):
""" Matr class basic functions testing """
# Constructor test
d = Matr([3, 2, [[1, 2], [3]]])
self.assertEqual(d.turns(), 3)
self.assertEqual(d.reduce(), 2)
if __name__ == "__main__":
# Avoiding recursion limitaions
sys.setrecursionlimit(100000)
if sys.argv[-1] == "-ut":
unittest.main(argv=[" "])
# Print the result string
print(calculate())
``` | output | 1 | 60,184 | 8 | 120,369 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at the exhibition of contemporary art.
The main exhibit is a construction of n matryoshka dolls that can be nested one into another. The matryoshka dolls are numbered from 1 to n. A matryoshka with a smaller number can be nested in a matryoshka with a higher number, two matryoshkas can not be directly nested in the same doll, but there may be chain nestings, for example, 1 β 2 β 4 β 5.
In one second, you can perform one of the two following operations:
* Having a matryoshka a that isn't nested in any other matryoshka and a matryoshka b, such that b doesn't contain any other matryoshka and is not nested in any other matryoshka, you may put a in b;
* Having a matryoshka a directly contained in matryoshka b, such that b is not nested in any other matryoshka, you may get a out of b.
According to the modern aesthetic norms the matryoshka dolls on display were assembled in a specific configuration, i.e. as several separate chains of nested matryoshkas, but the criminal, following the mysterious plan, took out all the dolls and assembled them into a single large chain (1 β 2 β ... β n). In order to continue the investigation Andrewid needs to know in what minimum time it is possible to perform this action.
Input
The first line contains integers n (1 β€ n β€ 105) and k (1 β€ k β€ 105) β the number of matryoshkas and matryoshka chains in the initial configuration.
The next k lines contain the descriptions of the chains: the i-th line first contains number mi (1 β€ mi β€ n), and then mi numbers ai1, ai2, ..., aimi β the numbers of matryoshkas in the chain (matryoshka ai1 is nested into matryoshka ai2, that is nested into matryoshka ai3, and so on till the matryoshka aimi that isn't nested into any other matryoshka).
It is guaranteed that m1 + m2 + ... + mk = n, the numbers of matryoshkas in all the chains are distinct, in each chain the numbers of matryoshkas follow in the ascending order.
Output
In the single line print the minimum number of seconds needed to assemble one large chain from the initial configuration.
Examples
Input
3 2
2 1 2
1 3
Output
1
Input
7 3
3 1 3 7
2 2 5
2 4 6
Output
10
Note
In the first sample test there are two chains: 1 β 2 and 3. In one second you can nest the first chain into the second one and get 1 β 2 β 3.
In the second sample test you need to disassemble all the three chains into individual matryoshkas in 2 + 1 + 1 = 4 seconds and then assemble one big chain in 6 seconds. | instruction | 0 | 60,185 | 8 | 120,370 |
Tags: implementation
Correct Solution:
```
parts = 0
ans = 0
a, b = map(int, input().split(' '))
for i in range(b):
shw = list(map(int, input().split(' ')))
ded = shw[0]
pat = shw[1:]
if pat[0] == 1:
ones = 0
for i in range(ded):
if pat[i] == i+1:
ones += 1
parts += ded - 1
print(parts+a-1-(ones-1)*2)
``` | output | 1 | 60,185 | 8 | 120,371 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at the exhibition of contemporary art.
The main exhibit is a construction of n matryoshka dolls that can be nested one into another. The matryoshka dolls are numbered from 1 to n. A matryoshka with a smaller number can be nested in a matryoshka with a higher number, two matryoshkas can not be directly nested in the same doll, but there may be chain nestings, for example, 1 β 2 β 4 β 5.
In one second, you can perform one of the two following operations:
* Having a matryoshka a that isn't nested in any other matryoshka and a matryoshka b, such that b doesn't contain any other matryoshka and is not nested in any other matryoshka, you may put a in b;
* Having a matryoshka a directly contained in matryoshka b, such that b is not nested in any other matryoshka, you may get a out of b.
According to the modern aesthetic norms the matryoshka dolls on display were assembled in a specific configuration, i.e. as several separate chains of nested matryoshkas, but the criminal, following the mysterious plan, took out all the dolls and assembled them into a single large chain (1 β 2 β ... β n). In order to continue the investigation Andrewid needs to know in what minimum time it is possible to perform this action.
Input
The first line contains integers n (1 β€ n β€ 105) and k (1 β€ k β€ 105) β the number of matryoshkas and matryoshka chains in the initial configuration.
The next k lines contain the descriptions of the chains: the i-th line first contains number mi (1 β€ mi β€ n), and then mi numbers ai1, ai2, ..., aimi β the numbers of matryoshkas in the chain (matryoshka ai1 is nested into matryoshka ai2, that is nested into matryoshka ai3, and so on till the matryoshka aimi that isn't nested into any other matryoshka).
It is guaranteed that m1 + m2 + ... + mk = n, the numbers of matryoshkas in all the chains are distinct, in each chain the numbers of matryoshkas follow in the ascending order.
Output
In the single line print the minimum number of seconds needed to assemble one large chain from the initial configuration.
Examples
Input
3 2
2 1 2
1 3
Output
1
Input
7 3
3 1 3 7
2 2 5
2 4 6
Output
10
Note
In the first sample test there are two chains: 1 β 2 and 3. In one second you can nest the first chain into the second one and get 1 β 2 β 3.
In the second sample test you need to disassemble all the three chains into individual matryoshkas in 2 + 1 + 1 = 4 seconds and then assemble one big chain in 6 seconds. | instruction | 0 | 60,186 | 8 | 120,372 |
Tags: implementation
Correct Solution:
```
n, k = map(int, input().split())
m = [list(map(int, input().split())) for _ in range(k)]
x = [0] * (n + 1)
y = [0] * (n + 1)
res = 0
for i, row in enumerate(m):
for j, v in enumerate(row):
if j == 0:
continue
x[v] = j
y[v] = i
no = 1
for i, v in enumerate(m[y[1]]):
if i < 2:
continue
if v != m[y[1]][i-1] + 1:
no = i - 1
break
no = i
res += n - no
for i, row in enumerate(m):
if i != y[1]:
res += row[0] - 1
else:
res += row[0] - x[no]
print(res)
``` | output | 1 | 60,186 | 8 | 120,373 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at the exhibition of contemporary art.
The main exhibit is a construction of n matryoshka dolls that can be nested one into another. The matryoshka dolls are numbered from 1 to n. A matryoshka with a smaller number can be nested in a matryoshka with a higher number, two matryoshkas can not be directly nested in the same doll, but there may be chain nestings, for example, 1 β 2 β 4 β 5.
In one second, you can perform one of the two following operations:
* Having a matryoshka a that isn't nested in any other matryoshka and a matryoshka b, such that b doesn't contain any other matryoshka and is not nested in any other matryoshka, you may put a in b;
* Having a matryoshka a directly contained in matryoshka b, such that b is not nested in any other matryoshka, you may get a out of b.
According to the modern aesthetic norms the matryoshka dolls on display were assembled in a specific configuration, i.e. as several separate chains of nested matryoshkas, but the criminal, following the mysterious plan, took out all the dolls and assembled them into a single large chain (1 β 2 β ... β n). In order to continue the investigation Andrewid needs to know in what minimum time it is possible to perform this action.
Input
The first line contains integers n (1 β€ n β€ 105) and k (1 β€ k β€ 105) β the number of matryoshkas and matryoshka chains in the initial configuration.
The next k lines contain the descriptions of the chains: the i-th line first contains number mi (1 β€ mi β€ n), and then mi numbers ai1, ai2, ..., aimi β the numbers of matryoshkas in the chain (matryoshka ai1 is nested into matryoshka ai2, that is nested into matryoshka ai3, and so on till the matryoshka aimi that isn't nested into any other matryoshka).
It is guaranteed that m1 + m2 + ... + mk = n, the numbers of matryoshkas in all the chains are distinct, in each chain the numbers of matryoshkas follow in the ascending order.
Output
In the single line print the minimum number of seconds needed to assemble one large chain from the initial configuration.
Examples
Input
3 2
2 1 2
1 3
Output
1
Input
7 3
3 1 3 7
2 2 5
2 4 6
Output
10
Note
In the first sample test there are two chains: 1 β 2 and 3. In one second you can nest the first chain into the second one and get 1 β 2 β 3.
In the second sample test you need to disassemble all the three chains into individual matryoshkas in 2 + 1 + 1 = 4 seconds and then assemble one big chain in 6 seconds. | instruction | 0 | 60,187 | 8 | 120,374 |
Tags: implementation
Correct Solution:
```
'''
Created on Jun 27, 2015
@author: maged
'''
[n,k] = [int(i) for i in input().split()]
#print(n, k)
unnest = 0
chains = k
for mats in range(0, k):
arr = [int(i) for i in input().split()]
m = arr[0]
if m == 1:
continue
for i in range (2, m+1):
if arr[i]!=arr[i-1]+1 or arr[1]!=1:
unnest += m-i+1
chains+= m-i+1
break
#print(unnest, chains)
print(unnest + chains - 1)
``` | output | 1 | 60,187 | 8 | 120,375 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at the exhibition of contemporary art.
The main exhibit is a construction of n matryoshka dolls that can be nested one into another. The matryoshka dolls are numbered from 1 to n. A matryoshka with a smaller number can be nested in a matryoshka with a higher number, two matryoshkas can not be directly nested in the same doll, but there may be chain nestings, for example, 1 β 2 β 4 β 5.
In one second, you can perform one of the two following operations:
* Having a matryoshka a that isn't nested in any other matryoshka and a matryoshka b, such that b doesn't contain any other matryoshka and is not nested in any other matryoshka, you may put a in b;
* Having a matryoshka a directly contained in matryoshka b, such that b is not nested in any other matryoshka, you may get a out of b.
According to the modern aesthetic norms the matryoshka dolls on display were assembled in a specific configuration, i.e. as several separate chains of nested matryoshkas, but the criminal, following the mysterious plan, took out all the dolls and assembled them into a single large chain (1 β 2 β ... β n). In order to continue the investigation Andrewid needs to know in what minimum time it is possible to perform this action.
Input
The first line contains integers n (1 β€ n β€ 105) and k (1 β€ k β€ 105) β the number of matryoshkas and matryoshka chains in the initial configuration.
The next k lines contain the descriptions of the chains: the i-th line first contains number mi (1 β€ mi β€ n), and then mi numbers ai1, ai2, ..., aimi β the numbers of matryoshkas in the chain (matryoshka ai1 is nested into matryoshka ai2, that is nested into matryoshka ai3, and so on till the matryoshka aimi that isn't nested into any other matryoshka).
It is guaranteed that m1 + m2 + ... + mk = n, the numbers of matryoshkas in all the chains are distinct, in each chain the numbers of matryoshkas follow in the ascending order.
Output
In the single line print the minimum number of seconds needed to assemble one large chain from the initial configuration.
Examples
Input
3 2
2 1 2
1 3
Output
1
Input
7 3
3 1 3 7
2 2 5
2 4 6
Output
10
Note
In the first sample test there are two chains: 1 β 2 and 3. In one second you can nest the first chain into the second one and get 1 β 2 β 3.
In the second sample test you need to disassemble all the three chains into individual matryoshkas in 2 + 1 + 1 = 4 seconds and then assemble one big chain in 6 seconds. | instruction | 0 | 60,188 | 8 | 120,376 |
Tags: implementation
Correct Solution:
```
def open_doll(i):
global opened, time
opened[doll_num[i]] = i+1
time += doll_size[doll_num[i]] - 1 - doll_ind[i]
n, k = [int(i) for i in input().split(" ")]
doll_num, doll_ind, doll_size = [0] * n, [0] * n, [0] * k
opened = [0]*k
time = 0
for i in range(k):
s_doll = [int(i) for i in input().split(" ")]
doll_size[i] = s_doll[0]
for j in range(s_doll[0]):
doll_num[s_doll[j+1] - 1] = i
doll_ind[s_doll[j+1] - 1] = j
for i in range(n-1):
if (doll_num[i] != doll_num[i+1]):
if not opened[doll_num[i]]:
open_doll(i)
if not opened[doll_num[i+1]]:
open_doll(i+1)
if opened[doll_num[i+1]] == i+2 and doll_ind[i+1] != 0:
opened[doll_num[i+1]] = i+1
time += 1
time += 1
elif (doll_num[i] == doll_num[i+1]) and opened[doll_num[i]] > 0 and opened[doll_num[i]] < i+2:
time += 1
print(time)
``` | output | 1 | 60,188 | 8 | 120,377 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at the exhibition of contemporary art.
The main exhibit is a construction of n matryoshka dolls that can be nested one into another. The matryoshka dolls are numbered from 1 to n. A matryoshka with a smaller number can be nested in a matryoshka with a higher number, two matryoshkas can not be directly nested in the same doll, but there may be chain nestings, for example, 1 β 2 β 4 β 5.
In one second, you can perform one of the two following operations:
* Having a matryoshka a that isn't nested in any other matryoshka and a matryoshka b, such that b doesn't contain any other matryoshka and is not nested in any other matryoshka, you may put a in b;
* Having a matryoshka a directly contained in matryoshka b, such that b is not nested in any other matryoshka, you may get a out of b.
According to the modern aesthetic norms the matryoshka dolls on display were assembled in a specific configuration, i.e. as several separate chains of nested matryoshkas, but the criminal, following the mysterious plan, took out all the dolls and assembled them into a single large chain (1 β 2 β ... β n). In order to continue the investigation Andrewid needs to know in what minimum time it is possible to perform this action.
Input
The first line contains integers n (1 β€ n β€ 105) and k (1 β€ k β€ 105) β the number of matryoshkas and matryoshka chains in the initial configuration.
The next k lines contain the descriptions of the chains: the i-th line first contains number mi (1 β€ mi β€ n), and then mi numbers ai1, ai2, ..., aimi β the numbers of matryoshkas in the chain (matryoshka ai1 is nested into matryoshka ai2, that is nested into matryoshka ai3, and so on till the matryoshka aimi that isn't nested into any other matryoshka).
It is guaranteed that m1 + m2 + ... + mk = n, the numbers of matryoshkas in all the chains are distinct, in each chain the numbers of matryoshkas follow in the ascending order.
Output
In the single line print the minimum number of seconds needed to assemble one large chain from the initial configuration.
Examples
Input
3 2
2 1 2
1 3
Output
1
Input
7 3
3 1 3 7
2 2 5
2 4 6
Output
10
Note
In the first sample test there are two chains: 1 β 2 and 3. In one second you can nest the first chain into the second one and get 1 β 2 β 3.
In the second sample test you need to disassemble all the three chains into individual matryoshkas in 2 + 1 + 1 = 4 seconds and then assemble one big chain in 6 seconds. | instruction | 0 | 60,189 | 8 | 120,378 |
Tags: implementation
Correct Solution:
```
import sys
sys.setrecursionlimit(1000000000)
n,k=map(int,input().split())
t=[]
x=0
for i in range(k):
s=input().split()
h=[]
for j in range(len(s)-1):
h+=[int(s[j+1])]
if int(s[j+1])==1:x=i
t+=[h]
v=1
bb=True
while bb and len(t[x])>v:
if t[x][v]==t[x][v-1]+1:v+=1
else:bb=False
m=len(t[x])-v+(n-len(t[x]))-(k-1)+(n-v)
print(m)
``` | output | 1 | 60,189 | 8 | 120,379 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at the exhibition of contemporary art.
The main exhibit is a construction of n matryoshka dolls that can be nested one into another. The matryoshka dolls are numbered from 1 to n. A matryoshka with a smaller number can be nested in a matryoshka with a higher number, two matryoshkas can not be directly nested in the same doll, but there may be chain nestings, for example, 1 β 2 β 4 β 5.
In one second, you can perform one of the two following operations:
* Having a matryoshka a that isn't nested in any other matryoshka and a matryoshka b, such that b doesn't contain any other matryoshka and is not nested in any other matryoshka, you may put a in b;
* Having a matryoshka a directly contained in matryoshka b, such that b is not nested in any other matryoshka, you may get a out of b.
According to the modern aesthetic norms the matryoshka dolls on display were assembled in a specific configuration, i.e. as several separate chains of nested matryoshkas, but the criminal, following the mysterious plan, took out all the dolls and assembled them into a single large chain (1 β 2 β ... β n). In order to continue the investigation Andrewid needs to know in what minimum time it is possible to perform this action.
Input
The first line contains integers n (1 β€ n β€ 105) and k (1 β€ k β€ 105) β the number of matryoshkas and matryoshka chains in the initial configuration.
The next k lines contain the descriptions of the chains: the i-th line first contains number mi (1 β€ mi β€ n), and then mi numbers ai1, ai2, ..., aimi β the numbers of matryoshkas in the chain (matryoshka ai1 is nested into matryoshka ai2, that is nested into matryoshka ai3, and so on till the matryoshka aimi that isn't nested into any other matryoshka).
It is guaranteed that m1 + m2 + ... + mk = n, the numbers of matryoshkas in all the chains are distinct, in each chain the numbers of matryoshkas follow in the ascending order.
Output
In the single line print the minimum number of seconds needed to assemble one large chain from the initial configuration.
Examples
Input
3 2
2 1 2
1 3
Output
1
Input
7 3
3 1 3 7
2 2 5
2 4 6
Output
10
Note
In the first sample test there are two chains: 1 β 2 and 3. In one second you can nest the first chain into the second one and get 1 β 2 β 3.
In the second sample test you need to disassemble all the three chains into individual matryoshkas in 2 + 1 + 1 = 4 seconds and then assemble one big chain in 6 seconds. | instruction | 0 | 60,190 | 8 | 120,380 |
Tags: implementation
Correct Solution:
```
n, k = map(int, input().split())
arr = []
gc = 0
cus = 0
for i in range(k):
arr = list(map(int, input().split())) + [10 ** 5 + 2]
c = 0
if arr[1] == 1:
for j in range(1, arr[0] + 1):
if arr[j] + 1 == arr[j + 1]:
c += 1
else:
break
cus += arr[0] - c
gc += arr[0] - c - 1
print(gc + cus - 1)
``` | output | 1 | 60,190 | 8 | 120,381 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at the exhibition of contemporary art.
The main exhibit is a construction of n matryoshka dolls that can be nested one into another. The matryoshka dolls are numbered from 1 to n. A matryoshka with a smaller number can be nested in a matryoshka with a higher number, two matryoshkas can not be directly nested in the same doll, but there may be chain nestings, for example, 1 β 2 β 4 β 5.
In one second, you can perform one of the two following operations:
* Having a matryoshka a that isn't nested in any other matryoshka and a matryoshka b, such that b doesn't contain any other matryoshka and is not nested in any other matryoshka, you may put a in b;
* Having a matryoshka a directly contained in matryoshka b, such that b is not nested in any other matryoshka, you may get a out of b.
According to the modern aesthetic norms the matryoshka dolls on display were assembled in a specific configuration, i.e. as several separate chains of nested matryoshkas, but the criminal, following the mysterious plan, took out all the dolls and assembled them into a single large chain (1 β 2 β ... β n). In order to continue the investigation Andrewid needs to know in what minimum time it is possible to perform this action.
Input
The first line contains integers n (1 β€ n β€ 105) and k (1 β€ k β€ 105) β the number of matryoshkas and matryoshka chains in the initial configuration.
The next k lines contain the descriptions of the chains: the i-th line first contains number mi (1 β€ mi β€ n), and then mi numbers ai1, ai2, ..., aimi β the numbers of matryoshkas in the chain (matryoshka ai1 is nested into matryoshka ai2, that is nested into matryoshka ai3, and so on till the matryoshka aimi that isn't nested into any other matryoshka).
It is guaranteed that m1 + m2 + ... + mk = n, the numbers of matryoshkas in all the chains are distinct, in each chain the numbers of matryoshkas follow in the ascending order.
Output
In the single line print the minimum number of seconds needed to assemble one large chain from the initial configuration.
Examples
Input
3 2
2 1 2
1 3
Output
1
Input
7 3
3 1 3 7
2 2 5
2 4 6
Output
10
Note
In the first sample test there are two chains: 1 β 2 and 3. In one second you can nest the first chain into the second one and get 1 β 2 β 3.
In the second sample test you need to disassemble all the three chains into individual matryoshkas in 2 + 1 + 1 = 4 seconds and then assemble one big chain in 6 seconds.
Submitted Solution:
```
n,k = map(int,input().split(" "))
i=0
res=k
sh=0
while i<k:
i+=1
mas=list(map(int,input().split(" ")))[1:]
if mas[0]==1:
j=0
while j<(len(mas)-1):
if(mas[j]+1!=mas[j+1]):
break
else:
j+=1
sh+=len(mas)-j-1
res+=len(mas)-j-1
else:
res+=len(mas)-1
sh+=len(mas)-1
print(sh+res-1)
``` | instruction | 0 | 60,191 | 8 | 120,382 |
Yes | output | 1 | 60,191 | 8 | 120,383 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at the exhibition of contemporary art.
The main exhibit is a construction of n matryoshka dolls that can be nested one into another. The matryoshka dolls are numbered from 1 to n. A matryoshka with a smaller number can be nested in a matryoshka with a higher number, two matryoshkas can not be directly nested in the same doll, but there may be chain nestings, for example, 1 β 2 β 4 β 5.
In one second, you can perform one of the two following operations:
* Having a matryoshka a that isn't nested in any other matryoshka and a matryoshka b, such that b doesn't contain any other matryoshka and is not nested in any other matryoshka, you may put a in b;
* Having a matryoshka a directly contained in matryoshka b, such that b is not nested in any other matryoshka, you may get a out of b.
According to the modern aesthetic norms the matryoshka dolls on display were assembled in a specific configuration, i.e. as several separate chains of nested matryoshkas, but the criminal, following the mysterious plan, took out all the dolls and assembled them into a single large chain (1 β 2 β ... β n). In order to continue the investigation Andrewid needs to know in what minimum time it is possible to perform this action.
Input
The first line contains integers n (1 β€ n β€ 105) and k (1 β€ k β€ 105) β the number of matryoshkas and matryoshka chains in the initial configuration.
The next k lines contain the descriptions of the chains: the i-th line first contains number mi (1 β€ mi β€ n), and then mi numbers ai1, ai2, ..., aimi β the numbers of matryoshkas in the chain (matryoshka ai1 is nested into matryoshka ai2, that is nested into matryoshka ai3, and so on till the matryoshka aimi that isn't nested into any other matryoshka).
It is guaranteed that m1 + m2 + ... + mk = n, the numbers of matryoshkas in all the chains are distinct, in each chain the numbers of matryoshkas follow in the ascending order.
Output
In the single line print the minimum number of seconds needed to assemble one large chain from the initial configuration.
Examples
Input
3 2
2 1 2
1 3
Output
1
Input
7 3
3 1 3 7
2 2 5
2 4 6
Output
10
Note
In the first sample test there are two chains: 1 β 2 and 3. In one second you can nest the first chain into the second one and get 1 β 2 β 3.
In the second sample test you need to disassemble all the three chains into individual matryoshkas in 2 + 1 + 1 = 4 seconds and then assemble one big chain in 6 seconds.
Submitted Solution:
```
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright Β© 2015 missingdays <missingdays@missingdays>
#
# Distributed under terms of the MIT license.
"""
"""
def check(a):
s = 0
for i in range(1, len(a)):
if a[i]-1 == a[i-1]:
s += 1
else:
return s*2
return s*2
inp = list(map(int, input().split()))
n, k = inp[0], inp[1]
s = 0
for line in range(k):
inp = list(map(int, input().split()))
if inp[1] == 1:
s -= check(inp[1:])
s += (inp[0] - 1)
s += (n-1)
print(s)
``` | instruction | 0 | 60,192 | 8 | 120,384 |
Yes | output | 1 | 60,192 | 8 | 120,385 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at the exhibition of contemporary art.
The main exhibit is a construction of n matryoshka dolls that can be nested one into another. The matryoshka dolls are numbered from 1 to n. A matryoshka with a smaller number can be nested in a matryoshka with a higher number, two matryoshkas can not be directly nested in the same doll, but there may be chain nestings, for example, 1 β 2 β 4 β 5.
In one second, you can perform one of the two following operations:
* Having a matryoshka a that isn't nested in any other matryoshka and a matryoshka b, such that b doesn't contain any other matryoshka and is not nested in any other matryoshka, you may put a in b;
* Having a matryoshka a directly contained in matryoshka b, such that b is not nested in any other matryoshka, you may get a out of b.
According to the modern aesthetic norms the matryoshka dolls on display were assembled in a specific configuration, i.e. as several separate chains of nested matryoshkas, but the criminal, following the mysterious plan, took out all the dolls and assembled them into a single large chain (1 β 2 β ... β n). In order to continue the investigation Andrewid needs to know in what minimum time it is possible to perform this action.
Input
The first line contains integers n (1 β€ n β€ 105) and k (1 β€ k β€ 105) β the number of matryoshkas and matryoshka chains in the initial configuration.
The next k lines contain the descriptions of the chains: the i-th line first contains number mi (1 β€ mi β€ n), and then mi numbers ai1, ai2, ..., aimi β the numbers of matryoshkas in the chain (matryoshka ai1 is nested into matryoshka ai2, that is nested into matryoshka ai3, and so on till the matryoshka aimi that isn't nested into any other matryoshka).
It is guaranteed that m1 + m2 + ... + mk = n, the numbers of matryoshkas in all the chains are distinct, in each chain the numbers of matryoshkas follow in the ascending order.
Output
In the single line print the minimum number of seconds needed to assemble one large chain from the initial configuration.
Examples
Input
3 2
2 1 2
1 3
Output
1
Input
7 3
3 1 3 7
2 2 5
2 4 6
Output
10
Note
In the first sample test there are two chains: 1 β 2 and 3. In one second you can nest the first chain into the second one and get 1 β 2 β 3.
In the second sample test you need to disassemble all the three chains into individual matryoshkas in 2 + 1 + 1 = 4 seconds and then assemble one big chain in 6 seconds.
Submitted Solution:
```
def arr_inp(n):
if n == 1:
return [int(x) for x in stdin.readline().split()]
elif n == 2:
return [float(x) for x in stdin.readline().split()]
else:
return [str(x) for x in stdin.readline().split()]
from sys import stdin
n, k = arr_inp(1)
arr, ans = [arr_inp(1) for i in range(k)], 0
for i in range(k):
for j in range(2, arr[i][0] + 1):
if arr[i][j] == j and arr[i][j - 1] == j - 1:
continue
else:
ans += arr[i][0] - (j - 2) - 1
break
print(ans + ans + (k - 1))
``` | instruction | 0 | 60,193 | 8 | 120,386 |
Yes | output | 1 | 60,193 | 8 | 120,387 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at the exhibition of contemporary art.
The main exhibit is a construction of n matryoshka dolls that can be nested one into another. The matryoshka dolls are numbered from 1 to n. A matryoshka with a smaller number can be nested in a matryoshka with a higher number, two matryoshkas can not be directly nested in the same doll, but there may be chain nestings, for example, 1 β 2 β 4 β 5.
In one second, you can perform one of the two following operations:
* Having a matryoshka a that isn't nested in any other matryoshka and a matryoshka b, such that b doesn't contain any other matryoshka and is not nested in any other matryoshka, you may put a in b;
* Having a matryoshka a directly contained in matryoshka b, such that b is not nested in any other matryoshka, you may get a out of b.
According to the modern aesthetic norms the matryoshka dolls on display were assembled in a specific configuration, i.e. as several separate chains of nested matryoshkas, but the criminal, following the mysterious plan, took out all the dolls and assembled them into a single large chain (1 β 2 β ... β n). In order to continue the investigation Andrewid needs to know in what minimum time it is possible to perform this action.
Input
The first line contains integers n (1 β€ n β€ 105) and k (1 β€ k β€ 105) β the number of matryoshkas and matryoshka chains in the initial configuration.
The next k lines contain the descriptions of the chains: the i-th line first contains number mi (1 β€ mi β€ n), and then mi numbers ai1, ai2, ..., aimi β the numbers of matryoshkas in the chain (matryoshka ai1 is nested into matryoshka ai2, that is nested into matryoshka ai3, and so on till the matryoshka aimi that isn't nested into any other matryoshka).
It is guaranteed that m1 + m2 + ... + mk = n, the numbers of matryoshkas in all the chains are distinct, in each chain the numbers of matryoshkas follow in the ascending order.
Output
In the single line print the minimum number of seconds needed to assemble one large chain from the initial configuration.
Examples
Input
3 2
2 1 2
1 3
Output
1
Input
7 3
3 1 3 7
2 2 5
2 4 6
Output
10
Note
In the first sample test there are two chains: 1 β 2 and 3. In one second you can nest the first chain into the second one and get 1 β 2 β 3.
In the second sample test you need to disassemble all the three chains into individual matryoshkas in 2 + 1 + 1 = 4 seconds and then assemble one big chain in 6 seconds.
Submitted Solution:
```
n, m = list(map(int, input().split()))
a = [[0] for i in range(m)]
for i in range(m):
a[i] = list(map(int, input().split()))
b = [0] * (n + 1)
for i in range(m):
for j in range(1, a[i][0]):
b[a[i][j]] = a[i][j + 1]
b[a[i][a[i][0]]] = -2
for i in range(1, n + 1):
if b[i] != i + 1:
k = i
break
#print(k)
print(2 * n - m - 2 * k + 1)
``` | instruction | 0 | 60,194 | 8 | 120,388 |
Yes | output | 1 | 60,194 | 8 | 120,389 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at the exhibition of contemporary art.
The main exhibit is a construction of n matryoshka dolls that can be nested one into another. The matryoshka dolls are numbered from 1 to n. A matryoshka with a smaller number can be nested in a matryoshka with a higher number, two matryoshkas can not be directly nested in the same doll, but there may be chain nestings, for example, 1 β 2 β 4 β 5.
In one second, you can perform one of the two following operations:
* Having a matryoshka a that isn't nested in any other matryoshka and a matryoshka b, such that b doesn't contain any other matryoshka and is not nested in any other matryoshka, you may put a in b;
* Having a matryoshka a directly contained in matryoshka b, such that b is not nested in any other matryoshka, you may get a out of b.
According to the modern aesthetic norms the matryoshka dolls on display were assembled in a specific configuration, i.e. as several separate chains of nested matryoshkas, but the criminal, following the mysterious plan, took out all the dolls and assembled them into a single large chain (1 β 2 β ... β n). In order to continue the investigation Andrewid needs to know in what minimum time it is possible to perform this action.
Input
The first line contains integers n (1 β€ n β€ 105) and k (1 β€ k β€ 105) β the number of matryoshkas and matryoshka chains in the initial configuration.
The next k lines contain the descriptions of the chains: the i-th line first contains number mi (1 β€ mi β€ n), and then mi numbers ai1, ai2, ..., aimi β the numbers of matryoshkas in the chain (matryoshka ai1 is nested into matryoshka ai2, that is nested into matryoshka ai3, and so on till the matryoshka aimi that isn't nested into any other matryoshka).
It is guaranteed that m1 + m2 + ... + mk = n, the numbers of matryoshkas in all the chains are distinct, in each chain the numbers of matryoshkas follow in the ascending order.
Output
In the single line print the minimum number of seconds needed to assemble one large chain from the initial configuration.
Examples
Input
3 2
2 1 2
1 3
Output
1
Input
7 3
3 1 3 7
2 2 5
2 4 6
Output
10
Note
In the first sample test there are two chains: 1 β 2 and 3. In one second you can nest the first chain into the second one and get 1 β 2 β 3.
In the second sample test you need to disassemble all the three chains into individual matryoshkas in 2 + 1 + 1 = 4 seconds and then assemble one big chain in 6 seconds.
Submitted Solution:
```
n, k = map(int, input().split())
arr = []
gc = 0
cus = 0
for i in range(k):
arr = list(map(int, input().split())) + [10 ** 5 + 1]
c = 0
if arr[1] == 1:
for j in range(1, arr[0] + 1):
if arr[j] + 1 == arr[j + 1]:
c += 1
else:
break
cus += arr[0] - c
gc += arr[0] - c - 1
print(gc + cus - 1)
``` | instruction | 0 | 60,195 | 8 | 120,390 |
No | output | 1 | 60,195 | 8 | 120,391 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at the exhibition of contemporary art.
The main exhibit is a construction of n matryoshka dolls that can be nested one into another. The matryoshka dolls are numbered from 1 to n. A matryoshka with a smaller number can be nested in a matryoshka with a higher number, two matryoshkas can not be directly nested in the same doll, but there may be chain nestings, for example, 1 β 2 β 4 β 5.
In one second, you can perform one of the two following operations:
* Having a matryoshka a that isn't nested in any other matryoshka and a matryoshka b, such that b doesn't contain any other matryoshka and is not nested in any other matryoshka, you may put a in b;
* Having a matryoshka a directly contained in matryoshka b, such that b is not nested in any other matryoshka, you may get a out of b.
According to the modern aesthetic norms the matryoshka dolls on display were assembled in a specific configuration, i.e. as several separate chains of nested matryoshkas, but the criminal, following the mysterious plan, took out all the dolls and assembled them into a single large chain (1 β 2 β ... β n). In order to continue the investigation Andrewid needs to know in what minimum time it is possible to perform this action.
Input
The first line contains integers n (1 β€ n β€ 105) and k (1 β€ k β€ 105) β the number of matryoshkas and matryoshka chains in the initial configuration.
The next k lines contain the descriptions of the chains: the i-th line first contains number mi (1 β€ mi β€ n), and then mi numbers ai1, ai2, ..., aimi β the numbers of matryoshkas in the chain (matryoshka ai1 is nested into matryoshka ai2, that is nested into matryoshka ai3, and so on till the matryoshka aimi that isn't nested into any other matryoshka).
It is guaranteed that m1 + m2 + ... + mk = n, the numbers of matryoshkas in all the chains are distinct, in each chain the numbers of matryoshkas follow in the ascending order.
Output
In the single line print the minimum number of seconds needed to assemble one large chain from the initial configuration.
Examples
Input
3 2
2 1 2
1 3
Output
1
Input
7 3
3 1 3 7
2 2 5
2 4 6
Output
10
Note
In the first sample test there are two chains: 1 β 2 and 3. In one second you can nest the first chain into the second one and get 1 β 2 β 3.
In the second sample test you need to disassemble all the three chains into individual matryoshkas in 2 + 1 + 1 = 4 seconds and then assemble one big chain in 6 seconds.
Submitted Solution:
```
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright Β© 2015 missingdays <missingdays@missingdays>
#
# Distributed under terms of the MIT license.
"""
"""
def check(a):
s = 0
for i in range(1, len(a)):
if a[i]-1 == a[i-1]:
s += 1
return s*2
inp = list(map(int, input().split()))
n, k = inp[0], inp[1]
s = 0
for line in range(k):
inp = list(map(int, input().split()))
s += (inp[0] - 1)
s -= check(inp[1:])
s += (n-1)
print(s)
``` | instruction | 0 | 60,196 | 8 | 120,392 |
No | output | 1 | 60,196 | 8 | 120,393 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at the exhibition of contemporary art.
The main exhibit is a construction of n matryoshka dolls that can be nested one into another. The matryoshka dolls are numbered from 1 to n. A matryoshka with a smaller number can be nested in a matryoshka with a higher number, two matryoshkas can not be directly nested in the same doll, but there may be chain nestings, for example, 1 β 2 β 4 β 5.
In one second, you can perform one of the two following operations:
* Having a matryoshka a that isn't nested in any other matryoshka and a matryoshka b, such that b doesn't contain any other matryoshka and is not nested in any other matryoshka, you may put a in b;
* Having a matryoshka a directly contained in matryoshka b, such that b is not nested in any other matryoshka, you may get a out of b.
According to the modern aesthetic norms the matryoshka dolls on display were assembled in a specific configuration, i.e. as several separate chains of nested matryoshkas, but the criminal, following the mysterious plan, took out all the dolls and assembled them into a single large chain (1 β 2 β ... β n). In order to continue the investigation Andrewid needs to know in what minimum time it is possible to perform this action.
Input
The first line contains integers n (1 β€ n β€ 105) and k (1 β€ k β€ 105) β the number of matryoshkas and matryoshka chains in the initial configuration.
The next k lines contain the descriptions of the chains: the i-th line first contains number mi (1 β€ mi β€ n), and then mi numbers ai1, ai2, ..., aimi β the numbers of matryoshkas in the chain (matryoshka ai1 is nested into matryoshka ai2, that is nested into matryoshka ai3, and so on till the matryoshka aimi that isn't nested into any other matryoshka).
It is guaranteed that m1 + m2 + ... + mk = n, the numbers of matryoshkas in all the chains are distinct, in each chain the numbers of matryoshkas follow in the ascending order.
Output
In the single line print the minimum number of seconds needed to assemble one large chain from the initial configuration.
Examples
Input
3 2
2 1 2
1 3
Output
1
Input
7 3
3 1 3 7
2 2 5
2 4 6
Output
10
Note
In the first sample test there are two chains: 1 β 2 and 3. In one second you can nest the first chain into the second one and get 1 β 2 β 3.
In the second sample test you need to disassemble all the three chains into individual matryoshkas in 2 + 1 + 1 = 4 seconds and then assemble one big chain in 6 seconds.
Submitted Solution:
```
#===========Template===============
from io import BytesIO, IOBase
from math import sqrt
import sys,os
from os import path
inpl=lambda:list(map(int,input().split()))
inpm=lambda:map(int,input().split())
inpi=lambda:int(input())
inp=lambda:input()
rev,ra,l=reversed,range,len
P=print
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
def input(): return sys.stdin.readline().rstrip("\r\n")
def B(n):
return bin(n).replace("0b","")
def factors(n):
arr=[]
for i in ra(2,int(sqrt(n))+1):
if n%i==0:
arr.append(i)
if i*i!=n:
arr.append(int(n/i))
return arr
def dfs(arr,n):
pairs=[[i+1] for i in ra(n)]
vis=[0]*(n+1)
for i in ra(l(arr)):
pairs[arr[i][0]-1].append(arr[i][1])
pairs[arr[i][1]-1].append(arr[i][0])
comp=[]
for i in ra(n):
stack=[pairs[i]]
temp=[]
if vis[stack[-1][0]]==0:
while len(stack)>0:
if vis[stack[-1][0]]==0:
temp.append(stack[-1][0])
vis[stack[-1][0]]=1
s=stack.pop()
for j in s[1:]:
if vis[j]==0:
stack.append(pairs[j-1])
else:
stack.pop()
comp.append(temp)
return comp
#=========I/p O/p ========================================#
from bisect import bisect_left as bl
from bisect import bisect_right as br
import sys,operator,math,operator
from collections import Counter
if(path.exists('input.txt')):
sys.stdin = open("input.txt","r")
sys.stdout = open("output.txt","w")
import random
#==============To chaliye shuru krte he ====================#
n,k=inpm()
li=[]
for i in ra(k):li.append(inpl()[1:])
part,tot=0,0
for i in ra(k):
temp=li[i]
c=0
p=0
while c<l(temp):
while c+1<l(temp) and temp[c]+1==temp[c+1]:
c+=1
p+=1
c+=1
part+=p
tot+=p
P(tot-1+(part-k))
``` | instruction | 0 | 60,197 | 8 | 120,394 |
No | output | 1 | 60,197 | 8 | 120,395 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at the exhibition of contemporary art.
The main exhibit is a construction of n matryoshka dolls that can be nested one into another. The matryoshka dolls are numbered from 1 to n. A matryoshka with a smaller number can be nested in a matryoshka with a higher number, two matryoshkas can not be directly nested in the same doll, but there may be chain nestings, for example, 1 β 2 β 4 β 5.
In one second, you can perform one of the two following operations:
* Having a matryoshka a that isn't nested in any other matryoshka and a matryoshka b, such that b doesn't contain any other matryoshka and is not nested in any other matryoshka, you may put a in b;
* Having a matryoshka a directly contained in matryoshka b, such that b is not nested in any other matryoshka, you may get a out of b.
According to the modern aesthetic norms the matryoshka dolls on display were assembled in a specific configuration, i.e. as several separate chains of nested matryoshkas, but the criminal, following the mysterious plan, took out all the dolls and assembled them into a single large chain (1 β 2 β ... β n). In order to continue the investigation Andrewid needs to know in what minimum time it is possible to perform this action.
Input
The first line contains integers n (1 β€ n β€ 105) and k (1 β€ k β€ 105) β the number of matryoshkas and matryoshka chains in the initial configuration.
The next k lines contain the descriptions of the chains: the i-th line first contains number mi (1 β€ mi β€ n), and then mi numbers ai1, ai2, ..., aimi β the numbers of matryoshkas in the chain (matryoshka ai1 is nested into matryoshka ai2, that is nested into matryoshka ai3, and so on till the matryoshka aimi that isn't nested into any other matryoshka).
It is guaranteed that m1 + m2 + ... + mk = n, the numbers of matryoshkas in all the chains are distinct, in each chain the numbers of matryoshkas follow in the ascending order.
Output
In the single line print the minimum number of seconds needed to assemble one large chain from the initial configuration.
Examples
Input
3 2
2 1 2
1 3
Output
1
Input
7 3
3 1 3 7
2 2 5
2 4 6
Output
10
Note
In the first sample test there are two chains: 1 β 2 and 3. In one second you can nest the first chain into the second one and get 1 β 2 β 3.
In the second sample test you need to disassemble all the three chains into individual matryoshkas in 2 + 1 + 1 = 4 seconds and then assemble one big chain in 6 seconds.
Submitted Solution:
```
n, k = map(int, input().split())
time = 0
part = 0
for i in range(k):
m = list(map(int, input().split()))
p = m[0]
d = set(m[1:])
cou = 1
if 1 in d:
i = 1
while i < p and m[i] == m[i + 1] - 1:
i += 1
cou += 1
if cou != 1:
part += p - i + 1
time += part - 1
else:
part += p
time += p - 1
else:
part += p
time += p - 1
time += part - 1
print(time)
``` | instruction | 0 | 60,198 | 8 | 120,396 |
No | output | 1 | 60,198 | 8 | 120,397 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity.
There are n columns of toy cubes in the box arranged in a line. The i-th column contains ai cubes. At first, the gravity in the box is pulling the cubes downwards. When Chris switches the gravity, it begins to pull all the cubes to the right side of the box. The figure shows the initial and final configurations of the cubes in the box: the cubes that have changed their position are highlighted with orange.
<image>
Given the initial configuration of the toy cubes in the box, find the amounts of cubes in each of the n columns after the gravity switch!
Input
The first line of input contains an integer n (1 β€ n β€ 100), the number of the columns in the box. The next line contains n space-separated integer numbers. The i-th number ai (1 β€ ai β€ 100) denotes the number of cubes in the i-th column.
Output
Output n integer numbers separated by spaces, where the i-th number is the amount of cubes in the i-th column after the gravity switch.
Examples
Input
4
3 2 1 2
Output
1 2 2 3
Input
3
2 3 8
Output
2 3 8
Note
The first example case is shown on the figure. The top cube of the first column falls to the top of the last column; the top cube of the second column falls to the top of the third column; the middle cube of the first column falls to the top of the second column.
In the second example case the gravity switch does not change the heights of the columns. | instruction | 0 | 61,015 | 8 | 122,030 |
Tags: greedy, implementation, sortings
Correct Solution:
```
a = int(input())
c = input()
b = c.split()
b = [int(c) for c in b]
b.sort()
d = ''
for i in b:
d += str(i)+' '
d = d.rstrip()
print(d)
``` | output | 1 | 61,015 | 8 | 122,031 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity.
There are n columns of toy cubes in the box arranged in a line. The i-th column contains ai cubes. At first, the gravity in the box is pulling the cubes downwards. When Chris switches the gravity, it begins to pull all the cubes to the right side of the box. The figure shows the initial and final configurations of the cubes in the box: the cubes that have changed their position are highlighted with orange.
<image>
Given the initial configuration of the toy cubes in the box, find the amounts of cubes in each of the n columns after the gravity switch!
Input
The first line of input contains an integer n (1 β€ n β€ 100), the number of the columns in the box. The next line contains n space-separated integer numbers. The i-th number ai (1 β€ ai β€ 100) denotes the number of cubes in the i-th column.
Output
Output n integer numbers separated by spaces, where the i-th number is the amount of cubes in the i-th column after the gravity switch.
Examples
Input
4
3 2 1 2
Output
1 2 2 3
Input
3
2 3 8
Output
2 3 8
Note
The first example case is shown on the figure. The top cube of the first column falls to the top of the last column; the top cube of the second column falls to the top of the third column; the middle cube of the first column falls to the top of the second column.
In the second example case the gravity switch does not change the heights of the columns. | instruction | 0 | 61,016 | 8 | 122,032 |
Tags: greedy, implementation, sortings
Correct Solution:
```
from sys import stdin,stdout
input = stdin.readline
def write(n,sep="\n"):
stdout.write(str(n))
stdout.write(sep)
def gil():
return list(map(int, input().split()))
n=gil()
lis=gil()
lis.sort()
print(' '.join(map(str,lis)))
``` | output | 1 | 61,016 | 8 | 122,033 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity.
There are n columns of toy cubes in the box arranged in a line. The i-th column contains ai cubes. At first, the gravity in the box is pulling the cubes downwards. When Chris switches the gravity, it begins to pull all the cubes to the right side of the box. The figure shows the initial and final configurations of the cubes in the box: the cubes that have changed their position are highlighted with orange.
<image>
Given the initial configuration of the toy cubes in the box, find the amounts of cubes in each of the n columns after the gravity switch!
Input
The first line of input contains an integer n (1 β€ n β€ 100), the number of the columns in the box. The next line contains n space-separated integer numbers. The i-th number ai (1 β€ ai β€ 100) denotes the number of cubes in the i-th column.
Output
Output n integer numbers separated by spaces, where the i-th number is the amount of cubes in the i-th column after the gravity switch.
Examples
Input
4
3 2 1 2
Output
1 2 2 3
Input
3
2 3 8
Output
2 3 8
Note
The first example case is shown on the figure. The top cube of the first column falls to the top of the last column; the top cube of the second column falls to the top of the third column; the middle cube of the first column falls to the top of the second column.
In the second example case the gravity switch does not change the heights of the columns. | instruction | 0 | 61,017 | 8 | 122,034 |
Tags: greedy, implementation, sortings
Correct Solution:
```
num_column = int(input())
line = [int(i) for i in input().split()]
line = sorted(line)
A = []
for i in range(num_column):
line[i] = str(line[i])
A.append(line[i])
print(' '.join(A))
``` | output | 1 | 61,017 | 8 | 122,035 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity.
There are n columns of toy cubes in the box arranged in a line. The i-th column contains ai cubes. At first, the gravity in the box is pulling the cubes downwards. When Chris switches the gravity, it begins to pull all the cubes to the right side of the box. The figure shows the initial and final configurations of the cubes in the box: the cubes that have changed their position are highlighted with orange.
<image>
Given the initial configuration of the toy cubes in the box, find the amounts of cubes in each of the n columns after the gravity switch!
Input
The first line of input contains an integer n (1 β€ n β€ 100), the number of the columns in the box. The next line contains n space-separated integer numbers. The i-th number ai (1 β€ ai β€ 100) denotes the number of cubes in the i-th column.
Output
Output n integer numbers separated by spaces, where the i-th number is the amount of cubes in the i-th column after the gravity switch.
Examples
Input
4
3 2 1 2
Output
1 2 2 3
Input
3
2 3 8
Output
2 3 8
Note
The first example case is shown on the figure. The top cube of the first column falls to the top of the last column; the top cube of the second column falls to the top of the third column; the middle cube of the first column falls to the top of the second column.
In the second example case the gravity switch does not change the heights of the columns. | instruction | 0 | 61,018 | 8 | 122,036 |
Tags: greedy, implementation, sortings
Correct Solution:
```
n = int(input())
cubes = [int(num) for num in input().split()]
for x in range(0, n-1):
minimum = x
for y in range(x+1, n):
if cubes[y] < cubes[minimum]:
minimum = y
prev_val = cubes[x]
cubes[x] = cubes[minimum]
cubes[minimum] = prev_val
result = str(cubes[0])
for column in range(1, n):
result = result + " " + str(cubes[column])
print(result)
``` | output | 1 | 61,018 | 8 | 122,037 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity.
There are n columns of toy cubes in the box arranged in a line. The i-th column contains ai cubes. At first, the gravity in the box is pulling the cubes downwards. When Chris switches the gravity, it begins to pull all the cubes to the right side of the box. The figure shows the initial and final configurations of the cubes in the box: the cubes that have changed their position are highlighted with orange.
<image>
Given the initial configuration of the toy cubes in the box, find the amounts of cubes in each of the n columns after the gravity switch!
Input
The first line of input contains an integer n (1 β€ n β€ 100), the number of the columns in the box. The next line contains n space-separated integer numbers. The i-th number ai (1 β€ ai β€ 100) denotes the number of cubes in the i-th column.
Output
Output n integer numbers separated by spaces, where the i-th number is the amount of cubes in the i-th column after the gravity switch.
Examples
Input
4
3 2 1 2
Output
1 2 2 3
Input
3
2 3 8
Output
2 3 8
Note
The first example case is shown on the figure. The top cube of the first column falls to the top of the last column; the top cube of the second column falls to the top of the third column; the middle cube of the first column falls to the top of the second column.
In the second example case the gravity switch does not change the heights of the columns. | instruction | 0 | 61,019 | 8 | 122,038 |
Tags: greedy, implementation, sortings
Correct Solution:
```
n = int(input())
coluna = [int(x) for x in input().split()]
while True:
colunasFaltando = 0
for i in range(n-1, -1, -1):
if i != 0:
if coluna[i] < coluna[i-1]:
colunasFaltando += 1
dif = abs(coluna[i] - coluna[i-1])
coluna[i] += dif
coluna[i-1] -= dif
if colunasFaltando == 0:
break
s = ""
for e in coluna:
s += str(e) + " "
print(s[:len(s)-1])
``` | output | 1 | 61,019 | 8 | 122,039 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity.
There are n columns of toy cubes in the box arranged in a line. The i-th column contains ai cubes. At first, the gravity in the box is pulling the cubes downwards. When Chris switches the gravity, it begins to pull all the cubes to the right side of the box. The figure shows the initial and final configurations of the cubes in the box: the cubes that have changed their position are highlighted with orange.
<image>
Given the initial configuration of the toy cubes in the box, find the amounts of cubes in each of the n columns after the gravity switch!
Input
The first line of input contains an integer n (1 β€ n β€ 100), the number of the columns in the box. The next line contains n space-separated integer numbers. The i-th number ai (1 β€ ai β€ 100) denotes the number of cubes in the i-th column.
Output
Output n integer numbers separated by spaces, where the i-th number is the amount of cubes in the i-th column after the gravity switch.
Examples
Input
4
3 2 1 2
Output
1 2 2 3
Input
3
2 3 8
Output
2 3 8
Note
The first example case is shown on the figure. The top cube of the first column falls to the top of the last column; the top cube of the second column falls to the top of the third column; the middle cube of the first column falls to the top of the second column.
In the second example case the gravity switch does not change the heights of the columns. | instruction | 0 | 61,020 | 8 | 122,040 |
Tags: greedy, implementation, sortings
Correct Solution:
```
n=int(input())
lst=list(map(int,input().split()))[:n]
lst.sort()
s=""
for i in range (len(lst)):
s=s+str(lst[i])
s=s+" "
print(s)
``` | output | 1 | 61,020 | 8 | 122,041 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity.
There are n columns of toy cubes in the box arranged in a line. The i-th column contains ai cubes. At first, the gravity in the box is pulling the cubes downwards. When Chris switches the gravity, it begins to pull all the cubes to the right side of the box. The figure shows the initial and final configurations of the cubes in the box: the cubes that have changed their position are highlighted with orange.
<image>
Given the initial configuration of the toy cubes in the box, find the amounts of cubes in each of the n columns after the gravity switch!
Input
The first line of input contains an integer n (1 β€ n β€ 100), the number of the columns in the box. The next line contains n space-separated integer numbers. The i-th number ai (1 β€ ai β€ 100) denotes the number of cubes in the i-th column.
Output
Output n integer numbers separated by spaces, where the i-th number is the amount of cubes in the i-th column after the gravity switch.
Examples
Input
4
3 2 1 2
Output
1 2 2 3
Input
3
2 3 8
Output
2 3 8
Note
The first example case is shown on the figure. The top cube of the first column falls to the top of the last column; the top cube of the second column falls to the top of the third column; the middle cube of the first column falls to the top of the second column.
In the second example case the gravity switch does not change the heights of the columns. | instruction | 0 | 61,021 | 8 | 122,042 |
Tags: greedy, implementation, sortings
Correct Solution:
```
num_cols = input()
boxes = input().split(' ')
boxes = sorted(list(map(int, boxes)))
boxes = ' '.join(list(map(str, boxes)))
print(boxes)
``` | output | 1 | 61,021 | 8 | 122,043 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity.
There are n columns of toy cubes in the box arranged in a line. The i-th column contains ai cubes. At first, the gravity in the box is pulling the cubes downwards. When Chris switches the gravity, it begins to pull all the cubes to the right side of the box. The figure shows the initial and final configurations of the cubes in the box: the cubes that have changed their position are highlighted with orange.
<image>
Given the initial configuration of the toy cubes in the box, find the amounts of cubes in each of the n columns after the gravity switch!
Input
The first line of input contains an integer n (1 β€ n β€ 100), the number of the columns in the box. The next line contains n space-separated integer numbers. The i-th number ai (1 β€ ai β€ 100) denotes the number of cubes in the i-th column.
Output
Output n integer numbers separated by spaces, where the i-th number is the amount of cubes in the i-th column after the gravity switch.
Examples
Input
4
3 2 1 2
Output
1 2 2 3
Input
3
2 3 8
Output
2 3 8
Note
The first example case is shown on the figure. The top cube of the first column falls to the top of the last column; the top cube of the second column falls to the top of the third column; the middle cube of the first column falls to the top of the second column.
In the second example case the gravity switch does not change the heights of the columns. | instruction | 0 | 61,022 | 8 | 122,044 |
Tags: greedy, implementation, sortings
Correct Solution:
```
def handleInput():
n = input()
columns = input()
columns = columns.split(" ")
for i in range(len(columns)):
columns[i] = int(columns[i])
return [n, columns]
def mergeSort(arr):
if len(arr) > 1:
mid = len(arr)//2 #Finding the mid of the array
L = arr[:mid] # Dividing the array elements
R = arr[mid:] # into 2 halves
mergeSort(L) # Sorting the first half
mergeSort(R) # Sorting the second half
i = j = k = 0
# Copy data to temp arrays L[] and R[]
while i < len(L) and j < len(R):
if L[i] < R[j]:
arr[k] = L[i]
i+=1
else:
arr[k] = R[j]
j+=1
k+=1
# Checking if any element was left
while i < len(L):
arr[k] = L[i]
i+=1
k+=1
while j < len(R):
arr[k] = R[j]
j+=1
k+=1
def output(col):
for el in col:
print(str(el) + " ", end='')
inp = handleInput()
col = inp[1]
mergeSort(col)
output(col)
``` | output | 1 | 61,022 | 8 | 122,045 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity.
There are n columns of toy cubes in the box arranged in a line. The i-th column contains ai cubes. At first, the gravity in the box is pulling the cubes downwards. When Chris switches the gravity, it begins to pull all the cubes to the right side of the box. The figure shows the initial and final configurations of the cubes in the box: the cubes that have changed their position are highlighted with orange.
<image>
Given the initial configuration of the toy cubes in the box, find the amounts of cubes in each of the n columns after the gravity switch!
Input
The first line of input contains an integer n (1 β€ n β€ 100), the number of the columns in the box. The next line contains n space-separated integer numbers. The i-th number ai (1 β€ ai β€ 100) denotes the number of cubes in the i-th column.
Output
Output n integer numbers separated by spaces, where the i-th number is the amount of cubes in the i-th column after the gravity switch.
Examples
Input
4
3 2 1 2
Output
1 2 2 3
Input
3
2 3 8
Output
2 3 8
Note
The first example case is shown on the figure. The top cube of the first column falls to the top of the last column; the top cube of the second column falls to the top of the third column; the middle cube of the first column falls to the top of the second column.
In the second example case the gravity switch does not change the heights of the columns.
Submitted Solution:
```
n = int(input())
nm = list(map(int,input().split(" ")))
nm.sort()
print(" ".join(map(str,nm)))
``` | instruction | 0 | 61,023 | 8 | 122,046 |
Yes | output | 1 | 61,023 | 8 | 122,047 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity.
There are n columns of toy cubes in the box arranged in a line. The i-th column contains ai cubes. At first, the gravity in the box is pulling the cubes downwards. When Chris switches the gravity, it begins to pull all the cubes to the right side of the box. The figure shows the initial and final configurations of the cubes in the box: the cubes that have changed their position are highlighted with orange.
<image>
Given the initial configuration of the toy cubes in the box, find the amounts of cubes in each of the n columns after the gravity switch!
Input
The first line of input contains an integer n (1 β€ n β€ 100), the number of the columns in the box. The next line contains n space-separated integer numbers. The i-th number ai (1 β€ ai β€ 100) denotes the number of cubes in the i-th column.
Output
Output n integer numbers separated by spaces, where the i-th number is the amount of cubes in the i-th column after the gravity switch.
Examples
Input
4
3 2 1 2
Output
1 2 2 3
Input
3
2 3 8
Output
2 3 8
Note
The first example case is shown on the figure. The top cube of the first column falls to the top of the last column; the top cube of the second column falls to the top of the third column; the middle cube of the first column falls to the top of the second column.
In the second example case the gravity switch does not change the heights of the columns.
Submitted Solution:
```
#entrada
x = int(input())
li = list(map(int,input().split()))
li.sort()
for i in li:
print(i,end = " ")
``` | instruction | 0 | 61,024 | 8 | 122,048 |
Yes | output | 1 | 61,024 | 8 | 122,049 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity.
There are n columns of toy cubes in the box arranged in a line. The i-th column contains ai cubes. At first, the gravity in the box is pulling the cubes downwards. When Chris switches the gravity, it begins to pull all the cubes to the right side of the box. The figure shows the initial and final configurations of the cubes in the box: the cubes that have changed their position are highlighted with orange.
<image>
Given the initial configuration of the toy cubes in the box, find the amounts of cubes in each of the n columns after the gravity switch!
Input
The first line of input contains an integer n (1 β€ n β€ 100), the number of the columns in the box. The next line contains n space-separated integer numbers. The i-th number ai (1 β€ ai β€ 100) denotes the number of cubes in the i-th column.
Output
Output n integer numbers separated by spaces, where the i-th number is the amount of cubes in the i-th column after the gravity switch.
Examples
Input
4
3 2 1 2
Output
1 2 2 3
Input
3
2 3 8
Output
2 3 8
Note
The first example case is shown on the figure. The top cube of the first column falls to the top of the last column; the top cube of the second column falls to the top of the third column; the middle cube of the first column falls to the top of the second column.
In the second example case the gravity switch does not change the heights of the columns.
Submitted Solution:
```
def gravity(line1, line2):
heights = [int(num) for num in line2.split(' ')]
rows = max(heights)
A = []
for height in heights:
column = [0] * rows
for i in range(height):
column[rows - 1 - i] = 1
A.append(column)
cols = len(heights)
for row in range(rows):
for k in range(cols):
for col in range(cols - 1):
if A[col][row] == 1 and A[col + 1][row] == 0:
A[col + 1][row] = 1
A[col][row] = 0
sums = []
for col in A:
sums.append(str(sum(col)))
print(' '.join(sums))
gravity(input(), input())
``` | instruction | 0 | 61,025 | 8 | 122,050 |
Yes | output | 1 | 61,025 | 8 | 122,051 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.