text stringlengths 198 433k | conversation_id int64 0 109k |
|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Those unwilling to return home from a long journey, will be affected by the oddity of the snail and lose their way. Mayoi, the oddity's carrier, wouldn't like this to happen, but there's nothing to do with this before a cure is figured out. For now, she would only like to know the enormous number of possibilities to be faced with if someone gets lost.
There are n towns in the region, numbered from 1 to n. The town numbered 1 is called the capital. The traffic network is formed by bidirectional roads connecting pairs of towns. No two roads connect the same pair of towns, and no road connects a town with itself. The time needed to travel through each of the roads is the same. Lost travelers will not be able to find out how the towns are connected, but the residents can help them by providing the following facts:
* Starting from each town other than the capital, the shortest path (i.e. the path passing through the minimum number of roads) to the capital exists, and is unique;
* Let li be the number of roads on the shortest path from town i to the capital, then li ≥ li - 1 holds for all 2 ≤ i ≤ n;
* For town i, the number of roads connected to it is denoted by di, which equals either 2 or 3.
You are to count the number of different ways in which the towns are connected, and give the answer modulo 109 + 7. Two ways of connecting towns are considered different if a pair (u, v) (1 ≤ u, v ≤ n) exists such there is a road between towns u and v in one of them but not in the other.
Input
The first line of input contains a positive integer n (3 ≤ n ≤ 50) — the number of towns.
The second line contains n space-separated integers d1, d2, ..., dn (2 ≤ di ≤ 3) — the number of roads connected to towns 1, 2, ..., n, respectively. It is guaranteed that the sum of di over all i is even.
Output
Output one integer — the total number of different possible ways in which the towns are connected, modulo 109 + 7.
Examples
Input
4
3 2 3 2
Output
1
Input
5
2 3 3 2 2
Output
2
Input
5
2 2 2 2 2
Output
2
Input
20
2 2 2 2 3 2 3 2 2 2 2 2 2 2 2 2 2 3 3 2
Output
82944
Note
In the first example, the following structure is the only one to satisfy the constraints, the distances from towns 2, 3, 4 to the capital are all 1.
<image>
In the second example, the following two structures satisfy the constraints.
<image>
Submitted Solution:
```
n = input() #X is the rank of the current highest, each that rank disappear and the rank Y below become the new highest rank X
a = input() #Each turn the current first node on Z will try to connect to X and move into Y, no 2 nodes in X connect the same node
a = a.split(' ')#Strategy: Dynamic programming, there are 2 case, the first node in Z connect one of the nodes in X or every node in Z does not connect X
a = list(map(int,a))#After the second case happen, the nodes in X will connect each other to terminate X and replace X with Y
X = [a[0]] #The number in each node represent the number of nodes it can continue connecting so each time it connects, its number minus 1
Y = []
Z = a[1:]
def pair(x,y):
if y == 0:
if x == 0:
return 1
return (x-1)*pair(x-2,0)
if x == 0:
if y == 1:
return 0
return (y-1)*pair(2,y-2)
return y*pair(x,y-1) + (x-1)*pair(x-2,y)
def around(a):
t = 0
for i in a:
if i == 1:
t += 1
return pair(t,len(a)-t)
def tree(A,B,C): #the main function
if A == []:
if B == []:
return 1
return tree(B,[],C) #Move Y to X
elif sum(A) % 2 == 1:
if C == []: #In this case, contracdict
return 0
else: #Because the sum is odd, it cannot connect each other
t = 0
E = B + [C[0]-1]
D = C[1:]
for i in range(len(A)):
x = A[:]
if x[i] == 1:
x = x[:i] + x[i+1:]
else:
x[i] -= 1
t += tree(x,E,D)
return t
elif C == []: #reaching the end
return around(A)*tree(B,[],[])
else:
if B == []: #because Y is empty, the around function also can't happen
t = 0
E = B + [C[0]-1]
D = C[1:]
for i in range(len(A)):
x = A[:]
if x[i] == 1:
x = x[:i] + x[i+1:]
else:
x[i] -= 1
t += tree(x,E,D)
return t
t = around(A)*tree(B,[],C) #this is where the 2 cases happen
E = B + [C[0]-1]
D = C[1:]
for i in range(len(A)):
x = A[:]
if x[i] == 1:
x = x[:i] + x[i+1:]
else:
x[i] -= 1
t += tree(x,E,D)
return t
print(tree(X,Y,Z)) #Note: There's a lot of replication, you can use clear them out if you can
```
No
| 92,300 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Those unwilling to return home from a long journey, will be affected by the oddity of the snail and lose their way. Mayoi, the oddity's carrier, wouldn't like this to happen, but there's nothing to do with this before a cure is figured out. For now, she would only like to know the enormous number of possibilities to be faced with if someone gets lost.
There are n towns in the region, numbered from 1 to n. The town numbered 1 is called the capital. The traffic network is formed by bidirectional roads connecting pairs of towns. No two roads connect the same pair of towns, and no road connects a town with itself. The time needed to travel through each of the roads is the same. Lost travelers will not be able to find out how the towns are connected, but the residents can help them by providing the following facts:
* Starting from each town other than the capital, the shortest path (i.e. the path passing through the minimum number of roads) to the capital exists, and is unique;
* Let li be the number of roads on the shortest path from town i to the capital, then li ≥ li - 1 holds for all 2 ≤ i ≤ n;
* For town i, the number of roads connected to it is denoted by di, which equals either 2 or 3.
You are to count the number of different ways in which the towns are connected, and give the answer modulo 109 + 7. Two ways of connecting towns are considered different if a pair (u, v) (1 ≤ u, v ≤ n) exists such there is a road between towns u and v in one of them but not in the other.
Input
The first line of input contains a positive integer n (3 ≤ n ≤ 50) — the number of towns.
The second line contains n space-separated integers d1, d2, ..., dn (2 ≤ di ≤ 3) — the number of roads connected to towns 1, 2, ..., n, respectively. It is guaranteed that the sum of di over all i is even.
Output
Output one integer — the total number of different possible ways in which the towns are connected, modulo 109 + 7.
Examples
Input
4
3 2 3 2
Output
1
Input
5
2 3 3 2 2
Output
2
Input
5
2 2 2 2 2
Output
2
Input
20
2 2 2 2 3 2 3 2 2 2 2 2 2 2 2 2 2 3 3 2
Output
82944
Note
In the first example, the following structure is the only one to satisfy the constraints, the distances from towns 2, 3, 4 to the capital are all 1.
<image>
In the second example, the following two structures satisfy the constraints.
<image>
Submitted Solution:
```
n = input() #X is the rank of the current highest, each that rank disappear and the rank Y below become the new highest rank X
a = input() #Each turn the current first node on Z will try to connect to X and move into Y, no 2 nodes in X connect the same node
a = a.split(' ')#Strategy: Dynamic programming, there are 2 case, the first node in Z connect one of the nodes in X or every node in Z does not connect X
a = list(map(int,a))#After the second case happen, the nodes in X will connect each other to terminate X and replace X with Y
X = [a[0]] #The number in each node represent the number of nodes it can continue connecting so each time it connects, its number minus 1
Y = []
Z = a[1:]
def around(a): #The number of ways the nodes in X can connect each other, the sum of every nodes must be even
if a == []:
return 1
t = 0
if a[0] == 1:
for i in range(1,len(a)):
x = a[:]
if a[i] != 1:
x[i] -= 1
x = x[1:]
t += around(x)
return t
if len(a) >= 3:
for i in range(1, len(a)-1):
for j in range(i+1,len(a)):
x = a[:]
if x[j] != 1:
x[j] -= 1
if x[i] != 1:
x[i] -= 1
x = x[1:]
t += around(x)
return t
return 0
def tree(A,B,C): #the main function
if A == []:
if B == []:
return 1
return tree(B,[],C) #Move Y to X
elif sum(A) % 2 == 1:
if C == []: #In this case, contracdict
return 0
else: #Because the sum is odd, it cannot connect each other
t = 0
E = B + [C[0]-1]
D = C[1:]
for i in range(len(A)):
x = A[:]
if x[i] != 1:
x[i] -= 1
t += tree(x,E,D)
return t
elif C == []: #reaching the end
return around(A)*tree(B,[],[])
else:
if B == []: #because Y is empty, the around function also can't happen
t = 0
E = B + [C[0]-1]
D = C[1:]
for i in range(len(A)):
x = A[:]
if x[i] != 1:
x[i] -= 1
t += tree(x,E,D)
return t
t = around(A)*tree(B,[],C) #this is where the 2 cases happen
E = B + [C[0]-1]
D = C[1:]
for i in range(len(A)):
x = A[:]
if x[i] != 1:
x[i] -= 1
t += tree(x,E,D)
return t
print(tree(X,Y,Z)) #Note: There's a lot of replication, you can use clear them out if you can
```
No
| 92,301 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Those unwilling to return home from a long journey, will be affected by the oddity of the snail and lose their way. Mayoi, the oddity's carrier, wouldn't like this to happen, but there's nothing to do with this before a cure is figured out. For now, she would only like to know the enormous number of possibilities to be faced with if someone gets lost.
There are n towns in the region, numbered from 1 to n. The town numbered 1 is called the capital. The traffic network is formed by bidirectional roads connecting pairs of towns. No two roads connect the same pair of towns, and no road connects a town with itself. The time needed to travel through each of the roads is the same. Lost travelers will not be able to find out how the towns are connected, but the residents can help them by providing the following facts:
* Starting from each town other than the capital, the shortest path (i.e. the path passing through the minimum number of roads) to the capital exists, and is unique;
* Let li be the number of roads on the shortest path from town i to the capital, then li ≥ li - 1 holds for all 2 ≤ i ≤ n;
* For town i, the number of roads connected to it is denoted by di, which equals either 2 or 3.
You are to count the number of different ways in which the towns are connected, and give the answer modulo 109 + 7. Two ways of connecting towns are considered different if a pair (u, v) (1 ≤ u, v ≤ n) exists such there is a road between towns u and v in one of them but not in the other.
Input
The first line of input contains a positive integer n (3 ≤ n ≤ 50) — the number of towns.
The second line contains n space-separated integers d1, d2, ..., dn (2 ≤ di ≤ 3) — the number of roads connected to towns 1, 2, ..., n, respectively. It is guaranteed that the sum of di over all i is even.
Output
Output one integer — the total number of different possible ways in which the towns are connected, modulo 109 + 7.
Examples
Input
4
3 2 3 2
Output
1
Input
5
2 3 3 2 2
Output
2
Input
5
2 2 2 2 2
Output
2
Input
20
2 2 2 2 3 2 3 2 2 2 2 2 2 2 2 2 2 3 3 2
Output
82944
Note
In the first example, the following structure is the only one to satisfy the constraints, the distances from towns 2, 3, 4 to the capital are all 1.
<image>
In the second example, the following two structures satisfy the constraints.
<image>
Submitted Solution:
```
n = input() #X is the rank of the current highest, each that rank disappear and the rank Y below become the new highest rank X
a = input() #Each turn the current first node on Z will try to connect to X and move into Y, no 2 nodes in X connect the same node
a = a.split(' ')#Strategy: Dynamic programming, there are 2 case, the first node in Z connect one of the nodes in X or every node in Z does not connect X
a = list(map(int,a))#After the second case happen, the nodes in X will connect each other to terminate X and replace X with Y
X = [a[0]] #The number in each node represent the number of nodes it can continue connecting so each time it connects, its number minus 1
Y = []
Z = a[1:]
def pair(x,y):
if y == 0:
if x == 0:
return 1
return (x-1)*pair(x-2,0)
if x == 0:
if y == 1 or y == 2:
return 0
return (y-1)*int((y-2)/2)*pair(2,y-3)
return y*pair(x,y-1) + (x-1)*pair(x-2,y)
def around(a):
t = 0
for i in a:
if i == 1:
t += 1
return pair(t,len(a)-t)
def tree(A,B,C): #the main function
if A == []:
if B == []:
return 1
return tree(B,[],C) #Move Y to X
elif sum(A) % 2 == 1:
if C == []: #In this case, contracdict
return 0
else: #Because the sum is odd, it cannot connect each other
t = 0
E = B + [C[0]-1]
D = C[1:]
for i in range(len(A)):
x = A[:]
if x[i] == 1:
x = x[:i] + x[i+1:]
else:
x[i] -= 1
t += tree(x,E,D)
return t
elif C == []: #reaching the end
return around(A)*tree(B,[],[])
else:
if B == []: #because Y is empty, the around function also can't happen
t = 0
E = B + [C[0]-1]
D = C[1:]
for i in range(len(A)):
x = A[:]
if x[i] == 1:
x = x[:i] + x[i+1:]
else:
x[i] -= 1
t += tree(x,E,D)
return t
t = around(A)*tree(B,[],C) #this is where the 2 cases happen
E = B + [C[0]-1]
D = C[1:]
for i in range(len(A)):
x = A[:]
if x[i] == 1:
x = x[:i] + x[i+1:]
else:
x[i] -= 1
t += tree(x,E,D)
return t
print(tree(X,Y,Z)) #Note: There's a lot of replication, you can use clear them out if you can
```
No
| 92,302 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are three or more consonants in a row in the word. The only exception is that if the block of consonants has all letters the same, then this block (even if its length is greater than three) is not considered a typo. Formally, a word is typed with a typo if there is a block of not less that three consonants in a row, and there are at least two different letters in this block.
For example:
* the following words have typos: "hellno", "hackcerrs" and "backtothefutttture";
* the following words don't have typos: "helllllooooo", "tobeornottobe" and "oooooo".
When Beroffice editor finds a word with a typo, it inserts as little as possible number of spaces in this word (dividing it into several words) in such a way that each of the resulting words is typed without any typos.
Implement this feature of Beroffice editor. Consider the following letters as the only vowels: 'a', 'e', 'i', 'o' and 'u'. All the other letters are consonants in this problem.
Input
The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters.
Output
Print the given word without any changes if there are no typos.
If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them.
Examples
Input
hellno
Output
hell no
Input
abacaba
Output
abacaba
Input
asdfasdf
Output
asd fasd f
Tags: dp, greedy, implementation
Correct Solution:
```
import math
mas = ['a', 'e', 'i', 'o', 'u']
def check(ch):
if ch in mas:
return False
else:
return True
s = input()
i = 0
ans = ''
j = 0
while i < len(s) - 2:
if check(s[i]) and check(s[i+1]) and check(s[i+2]) and not (s[i] == s[i+1] and s[i+1] == s[i+2]):
ans += s[i] + s[i+1] + ' '
i += 2
j = i
else:
ans += s[i]
i+=1
more = ''
#print(j)
if j == len(s):
j +1
elif j == len(s) - 1:
more += s[len(s)-1]
else:
more += s[len(s)-2] + s[len(s)-1]
print(ans + more)
```
| 92,303 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are three or more consonants in a row in the word. The only exception is that if the block of consonants has all letters the same, then this block (even if its length is greater than three) is not considered a typo. Formally, a word is typed with a typo if there is a block of not less that three consonants in a row, and there are at least two different letters in this block.
For example:
* the following words have typos: "hellno", "hackcerrs" and "backtothefutttture";
* the following words don't have typos: "helllllooooo", "tobeornottobe" and "oooooo".
When Beroffice editor finds a word with a typo, it inserts as little as possible number of spaces in this word (dividing it into several words) in such a way that each of the resulting words is typed without any typos.
Implement this feature of Beroffice editor. Consider the following letters as the only vowels: 'a', 'e', 'i', 'o' and 'u'. All the other letters are consonants in this problem.
Input
The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters.
Output
Print the given word without any changes if there are no typos.
If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them.
Examples
Input
hellno
Output
hell no
Input
abacaba
Output
abacaba
Input
asdfasdf
Output
asd fasd f
Tags: dp, greedy, implementation
Correct Solution:
```
s=input()
t=""
n=len(s)
ans=[]
arr=['a','e','i','o','u']
if(n<3):
print(s)
else:
i=0
while(i<n-2):
p=[s[i],s[i+1],s[i+2]]
# print(p)
if(len(set(p))==1):
ans.append(s[i])
i+=1
else:
if(s[i] not in arr and s[i+1] not in arr and s[i+2] not in arr):
ans.append(s[i])
ans.append(s[i+1])
r=" "
ans.append(r)
i+=2
# print(t)
else:
ans.append(s[i])
i+=1
for j in range(i,n):
ans.append(s[j])
for i in ans:
t+=i
print(t)
```
| 92,304 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are three or more consonants in a row in the word. The only exception is that if the block of consonants has all letters the same, then this block (even if its length is greater than three) is not considered a typo. Formally, a word is typed with a typo if there is a block of not less that three consonants in a row, and there are at least two different letters in this block.
For example:
* the following words have typos: "hellno", "hackcerrs" and "backtothefutttture";
* the following words don't have typos: "helllllooooo", "tobeornottobe" and "oooooo".
When Beroffice editor finds a word with a typo, it inserts as little as possible number of spaces in this word (dividing it into several words) in such a way that each of the resulting words is typed without any typos.
Implement this feature of Beroffice editor. Consider the following letters as the only vowels: 'a', 'e', 'i', 'o' and 'u'. All the other letters are consonants in this problem.
Input
The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters.
Output
Print the given word without any changes if there are no typos.
If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them.
Examples
Input
hellno
Output
hell no
Input
abacaba
Output
abacaba
Input
asdfasdf
Output
asd fasd f
Tags: dp, greedy, implementation
Correct Solution:
```
s=input()
if len(s)<=2 or len(set(s))==1:
print(s)
exit()
d={}
for i in range(97,123):
x=chr(i)
if x in ['a','e','i','o','u']:
d.update({x:False})
else:
d.update({x:True})
l,i=[],0
while True:
if i>=len(s)-2:
break
if d[s[i]]==True and d[s[i+1]]==True and d[s[i+2]]==True:
y=s[i]+s[i+1]+s[i+2]
if len(set(y))>1:
x=s[:i+2]
l.append(x)
l.append(' ')
s=s[i+2:]
i=0
else:
i=i+1
else:
i+=1
if len(s)>0:
l.append(s)
for i in l:
print(i,end='')
print()
```
| 92,305 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are three or more consonants in a row in the word. The only exception is that if the block of consonants has all letters the same, then this block (even if its length is greater than three) is not considered a typo. Formally, a word is typed with a typo if there is a block of not less that three consonants in a row, and there are at least two different letters in this block.
For example:
* the following words have typos: "hellno", "hackcerrs" and "backtothefutttture";
* the following words don't have typos: "helllllooooo", "tobeornottobe" and "oooooo".
When Beroffice editor finds a word with a typo, it inserts as little as possible number of spaces in this word (dividing it into several words) in such a way that each of the resulting words is typed without any typos.
Implement this feature of Beroffice editor. Consider the following letters as the only vowels: 'a', 'e', 'i', 'o' and 'u'. All the other letters are consonants in this problem.
Input
The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters.
Output
Print the given word without any changes if there are no typos.
If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them.
Examples
Input
hellno
Output
hell no
Input
abacaba
Output
abacaba
Input
asdfasdf
Output
asd fasd f
Tags: dp, greedy, implementation
Correct Solution:
```
symbol = ["a", "e", "i", "o", "u"]
a = input()
i = 2
while i < len(a):
if not (a[i] in symbol) and not(a[i - 1] in symbol) and not (a[i - 2] in symbol) and a[i - 2:i + 1] != a[i - 2] * 3:
a = a[:i] + " " + a[i:]
i = i + 3
else:
i = i + 1
print(a)
```
| 92,306 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are three or more consonants in a row in the word. The only exception is that if the block of consonants has all letters the same, then this block (even if its length is greater than three) is not considered a typo. Formally, a word is typed with a typo if there is a block of not less that three consonants in a row, and there are at least two different letters in this block.
For example:
* the following words have typos: "hellno", "hackcerrs" and "backtothefutttture";
* the following words don't have typos: "helllllooooo", "tobeornottobe" and "oooooo".
When Beroffice editor finds a word with a typo, it inserts as little as possible number of spaces in this word (dividing it into several words) in such a way that each of the resulting words is typed without any typos.
Implement this feature of Beroffice editor. Consider the following letters as the only vowels: 'a', 'e', 'i', 'o' and 'u'. All the other letters are consonants in this problem.
Input
The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters.
Output
Print the given word without any changes if there are no typos.
If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them.
Examples
Input
hellno
Output
hell no
Input
abacaba
Output
abacaba
Input
asdfasdf
Output
asd fasd f
Tags: dp, greedy, implementation
Correct Solution:
```
s=input()
glas='aeiou'
i=1
while i < len(s)-1:
if s[i-1] not in glas and s[i] not in glas and s[i+1] not in glas:
if s[i-1]!=s[i] or s[i]!=s[i+1] or s[i-1]!=s[i+1]:
s=s[:i+1]+' '+s[i+1:]
i+=3
continue
i+=1
print(s)
```
| 92,307 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are three or more consonants in a row in the word. The only exception is that if the block of consonants has all letters the same, then this block (even if its length is greater than three) is not considered a typo. Formally, a word is typed with a typo if there is a block of not less that three consonants in a row, and there are at least two different letters in this block.
For example:
* the following words have typos: "hellno", "hackcerrs" and "backtothefutttture";
* the following words don't have typos: "helllllooooo", "tobeornottobe" and "oooooo".
When Beroffice editor finds a word with a typo, it inserts as little as possible number of spaces in this word (dividing it into several words) in such a way that each of the resulting words is typed without any typos.
Implement this feature of Beroffice editor. Consider the following letters as the only vowels: 'a', 'e', 'i', 'o' and 'u'. All the other letters are consonants in this problem.
Input
The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters.
Output
Print the given word without any changes if there are no typos.
If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them.
Examples
Input
hellno
Output
hell no
Input
abacaba
Output
abacaba
Input
asdfasdf
Output
asd fasd f
Tags: dp, greedy, implementation
Correct Solution:
```
u = list(input())
n = len(u)
a = set(['a', 'o', 'u', 'e', 'i'])
p = 0
i = 2
while i < n:
if u[i - 2] not in a and u[i - 1] not in a and u[i] not in a:
if u[i - 2] != u[i - 1] or u[i - 1] != u[i] or u[i] != u[i - 2]:
print(''.join(map(str, u[p:i])), end = ' ')
p = i
i += 2
else:
i += 1
else:
i += 1
print(''.join(map(str, u[p:i])), end = '')
```
| 92,308 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are three or more consonants in a row in the word. The only exception is that if the block of consonants has all letters the same, then this block (even if its length is greater than three) is not considered a typo. Formally, a word is typed with a typo if there is a block of not less that three consonants in a row, and there are at least two different letters in this block.
For example:
* the following words have typos: "hellno", "hackcerrs" and "backtothefutttture";
* the following words don't have typos: "helllllooooo", "tobeornottobe" and "oooooo".
When Beroffice editor finds a word with a typo, it inserts as little as possible number of spaces in this word (dividing it into several words) in such a way that each of the resulting words is typed without any typos.
Implement this feature of Beroffice editor. Consider the following letters as the only vowels: 'a', 'e', 'i', 'o' and 'u'. All the other letters are consonants in this problem.
Input
The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters.
Output
Print the given word without any changes if there are no typos.
If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them.
Examples
Input
hellno
Output
hell no
Input
abacaba
Output
abacaba
Input
asdfasdf
Output
asd fasd f
Tags: dp, greedy, implementation
Correct Solution:
```
checking = input()
vowels = ["a","e","i","o","u"]
streak = []
new = ""
for i,letter in enumerate(checking):
# print(streak)
if letter not in vowels:
streak.append(letter)
else:
streak = []
if len(streak) == 3:
if streak.count(letter) == 3:
streak = [letter, letter]
else:
streak = [letter]
new += " "
new += letter
print(new)
```
| 92,309 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are three or more consonants in a row in the word. The only exception is that if the block of consonants has all letters the same, then this block (even if its length is greater than three) is not considered a typo. Formally, a word is typed with a typo if there is a block of not less that three consonants in a row, and there are at least two different letters in this block.
For example:
* the following words have typos: "hellno", "hackcerrs" and "backtothefutttture";
* the following words don't have typos: "helllllooooo", "tobeornottobe" and "oooooo".
When Beroffice editor finds a word with a typo, it inserts as little as possible number of spaces in this word (dividing it into several words) in such a way that each of the resulting words is typed without any typos.
Implement this feature of Beroffice editor. Consider the following letters as the only vowels: 'a', 'e', 'i', 'o' and 'u'. All the other letters are consonants in this problem.
Input
The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters.
Output
Print the given word without any changes if there are no typos.
If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them.
Examples
Input
hellno
Output
hell no
Input
abacaba
Output
abacaba
Input
asdfasdf
Output
asd fasd f
Tags: dp, greedy, implementation
Correct Solution:
```
a=str(input())
sgl="bcdfghjklmnpqrstvwxyz"
ans=""
for i in range(len(a)):
ans+=a[i]
if len(ans)>2:
if sgl.count(ans[-1]) and sgl.count(ans[-2]) and sgl.count(ans[-3]) and (ans[-1]!=ans[-2] or ans[-1]!=ans[-3]):
ans=ans[:-1]+" "+ ans[-1]
print(ans)
```
| 92,310 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are three or more consonants in a row in the word. The only exception is that if the block of consonants has all letters the same, then this block (even if its length is greater than three) is not considered a typo. Formally, a word is typed with a typo if there is a block of not less that three consonants in a row, and there are at least two different letters in this block.
For example:
* the following words have typos: "hellno", "hackcerrs" and "backtothefutttture";
* the following words don't have typos: "helllllooooo", "tobeornottobe" and "oooooo".
When Beroffice editor finds a word with a typo, it inserts as little as possible number of spaces in this word (dividing it into several words) in such a way that each of the resulting words is typed without any typos.
Implement this feature of Beroffice editor. Consider the following letters as the only vowels: 'a', 'e', 'i', 'o' and 'u'. All the other letters are consonants in this problem.
Input
The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters.
Output
Print the given word without any changes if there are no typos.
If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them.
Examples
Input
hellno
Output
hell no
Input
abacaba
Output
abacaba
Input
asdfasdf
Output
asd fasd f
Submitted Solution:
```
s = input()
ans = []
start = 0
c = 0
const = set()
for i in range(len(s)):
if s[i] in 'aeiou':
const = set()
c = 0
else:
c += 1
const.add(s[i])
if c>=3 and len(const) >= 2:
ans.append(s[start:i])
start = i
const = set({s[i]})
c = 1
ans.append(s[start:])
print(' '.join(ans))
```
Yes
| 92,311 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are three or more consonants in a row in the word. The only exception is that if the block of consonants has all letters the same, then this block (even if its length is greater than three) is not considered a typo. Formally, a word is typed with a typo if there is a block of not less that three consonants in a row, and there are at least two different letters in this block.
For example:
* the following words have typos: "hellno", "hackcerrs" and "backtothefutttture";
* the following words don't have typos: "helllllooooo", "tobeornottobe" and "oooooo".
When Beroffice editor finds a word with a typo, it inserts as little as possible number of spaces in this word (dividing it into several words) in such a way that each of the resulting words is typed without any typos.
Implement this feature of Beroffice editor. Consider the following letters as the only vowels: 'a', 'e', 'i', 'o' and 'u'. All the other letters are consonants in this problem.
Input
The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters.
Output
Print the given word without any changes if there are no typos.
If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them.
Examples
Input
hellno
Output
hell no
Input
abacaba
Output
abacaba
Input
asdfasdf
Output
asd fasd f
Submitted Solution:
```
a = ["b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "p", "q", "r", "s", "t", "v", "w", "x", "y", "z"]
b = input()
n = 0
g = 0
s = []
check = False
print(b[0], end="")
for i in range(1, len(b) - 1):
if check:
print(b[i], end="")
check = False
continue
m = [b[i-1], b[i], b[i+1]]
if b[i-1] in a and b[i] in a and b[i+1] in a and len(list(set(m))) > 1:
print(b[i], end=" ")
check = True
else:
print(b[i], end="")
if len(b) > 1:
print(b[-1])
```
Yes
| 92,312 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are three or more consonants in a row in the word. The only exception is that if the block of consonants has all letters the same, then this block (even if its length is greater than three) is not considered a typo. Formally, a word is typed with a typo if there is a block of not less that three consonants in a row, and there are at least two different letters in this block.
For example:
* the following words have typos: "hellno", "hackcerrs" and "backtothefutttture";
* the following words don't have typos: "helllllooooo", "tobeornottobe" and "oooooo".
When Beroffice editor finds a word with a typo, it inserts as little as possible number of spaces in this word (dividing it into several words) in such a way that each of the resulting words is typed without any typos.
Implement this feature of Beroffice editor. Consider the following letters as the only vowels: 'a', 'e', 'i', 'o' and 'u'. All the other letters are consonants in this problem.
Input
The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters.
Output
Print the given word without any changes if there are no typos.
If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them.
Examples
Input
hellno
Output
hell no
Input
abacaba
Output
abacaba
Input
asdfasdf
Output
asd fasd f
Submitted Solution:
```
s = input()
num = 0
res = ""
A = ["a", "e", "i", "o", "u"]
for i in s:
num+=1
if len(res) > 1 and i == res[len(res) - 1] == res[len(res) - 2]:
num = 2
if i in A:
num = 0
if num >= 3:
res += " "
num = 1
res+=i
print(res)
```
Yes
| 92,313 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are three or more consonants in a row in the word. The only exception is that if the block of consonants has all letters the same, then this block (even if its length is greater than three) is not considered a typo. Formally, a word is typed with a typo if there is a block of not less that three consonants in a row, and there are at least two different letters in this block.
For example:
* the following words have typos: "hellno", "hackcerrs" and "backtothefutttture";
* the following words don't have typos: "helllllooooo", "tobeornottobe" and "oooooo".
When Beroffice editor finds a word with a typo, it inserts as little as possible number of spaces in this word (dividing it into several words) in such a way that each of the resulting words is typed without any typos.
Implement this feature of Beroffice editor. Consider the following letters as the only vowels: 'a', 'e', 'i', 'o' and 'u'. All the other letters are consonants in this problem.
Input
The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters.
Output
Print the given word without any changes if there are no typos.
If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them.
Examples
Input
hellno
Output
hell no
Input
abacaba
Output
abacaba
Input
asdfasdf
Output
asd fasd f
Submitted Solution:
```
inp = input()
out = ''
c = 0
d = 0
for i in range(len(inp)):
if inp[i] == 'a' or inp[i] == 'e' or inp[i] == 'i' or inp[i] == 'o' or inp[i] == 'u':
c = 0
d = 0
elif c >= 2:
if d or inp[i] != inp[i - 1]:
out += " "
c = 1
d = 0
else:
c += 1
else:
if c > 0 and inp[i] != inp[i-1]:
d = 1
c += 1
out += inp[i]
print(out)
```
Yes
| 92,314 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are three or more consonants in a row in the word. The only exception is that if the block of consonants has all letters the same, then this block (even if its length is greater than three) is not considered a typo. Formally, a word is typed with a typo if there is a block of not less that three consonants in a row, and there are at least two different letters in this block.
For example:
* the following words have typos: "hellno", "hackcerrs" and "backtothefutttture";
* the following words don't have typos: "helllllooooo", "tobeornottobe" and "oooooo".
When Beroffice editor finds a word with a typo, it inserts as little as possible number of spaces in this word (dividing it into several words) in such a way that each of the resulting words is typed without any typos.
Implement this feature of Beroffice editor. Consider the following letters as the only vowels: 'a', 'e', 'i', 'o' and 'u'. All the other letters are consonants in this problem.
Input
The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters.
Output
Print the given word without any changes if there are no typos.
If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them.
Examples
Input
hellno
Output
hell no
Input
abacaba
Output
abacaba
Input
asdfasdf
Output
asd fasd f
Submitted Solution:
```
def Dif(string):
for i in range(len(string)):
if s[i] != s[-i - 1]:
return True
return False
s = input()
s1 = ''
b = False
for i in range(len(s)):
if s[i] != 'a' and s[i] != 'e' and s[i] != 'i' and s[i] != 'o' and s[i] != 'u':
s1 += s[i]
if len(s1) > 2 and Dif(s1):
b = True
break
else:
s1 = ''
if b:
s1 = ''
s2 = ''
for i in range(len(s)):
if s[i] == 'a' or s[i] == 'e' or s[i] == 'i' or s[i] == 'o' or s[i] == 'u':
s1 += s[i]
s2 = ''
else:
s2 += s[i]
s1 += s[i]
if len(s2) > 1 and Dif(s2):
s1 += ' '
s2 = ''
s = s1
print(s)
```
No
| 92,315 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are three or more consonants in a row in the word. The only exception is that if the block of consonants has all letters the same, then this block (even if its length is greater than three) is not considered a typo. Formally, a word is typed with a typo if there is a block of not less that three consonants in a row, and there are at least two different letters in this block.
For example:
* the following words have typos: "hellno", "hackcerrs" and "backtothefutttture";
* the following words don't have typos: "helllllooooo", "tobeornottobe" and "oooooo".
When Beroffice editor finds a word with a typo, it inserts as little as possible number of spaces in this word (dividing it into several words) in such a way that each of the resulting words is typed without any typos.
Implement this feature of Beroffice editor. Consider the following letters as the only vowels: 'a', 'e', 'i', 'o' and 'u'. All the other letters are consonants in this problem.
Input
The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters.
Output
Print the given word without any changes if there are no typos.
If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them.
Examples
Input
hellno
Output
hell no
Input
abacaba
Output
abacaba
Input
asdfasdf
Output
asd fasd f
Submitted Solution:
```
s=input()
c=0
d=0
p=''
for i in s:
if i=='a'or i=='e' or i=='i' or i=='o' or i=='u':
c=0
d=0
p=''
else:
c+=1
if c>1:
if p!='' and i not in p:
d=1
p+=i
if c>=3 and d:
print(' ',end='')
c=0
d=0
p=''
print(i,end='')
```
No
| 92,316 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are three or more consonants in a row in the word. The only exception is that if the block of consonants has all letters the same, then this block (even if its length is greater than three) is not considered a typo. Formally, a word is typed with a typo if there is a block of not less that three consonants in a row, and there are at least two different letters in this block.
For example:
* the following words have typos: "hellno", "hackcerrs" and "backtothefutttture";
* the following words don't have typos: "helllllooooo", "tobeornottobe" and "oooooo".
When Beroffice editor finds a word with a typo, it inserts as little as possible number of spaces in this word (dividing it into several words) in such a way that each of the resulting words is typed without any typos.
Implement this feature of Beroffice editor. Consider the following letters as the only vowels: 'a', 'e', 'i', 'o' and 'u'. All the other letters are consonants in this problem.
Input
The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters.
Output
Print the given word without any changes if there are no typos.
If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them.
Examples
Input
hellno
Output
hell no
Input
abacaba
Output
abacaba
Input
asdfasdf
Output
asd fasd f
Submitted Solution:
```
s = input()
g = {'a', 'e', 'i', 'o', 'u'}
l = 0
lc = ""
for ch in s:
if ch not in g and lc != ch:
l+=1
else: l=0
if l>2 and lc != ch:
print(" ", end="")
l = 1
lc = ch
print(ch, end="")
```
No
| 92,317 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are three or more consonants in a row in the word. The only exception is that if the block of consonants has all letters the same, then this block (even if its length is greater than three) is not considered a typo. Formally, a word is typed with a typo if there is a block of not less that three consonants in a row, and there are at least two different letters in this block.
For example:
* the following words have typos: "hellno", "hackcerrs" and "backtothefutttture";
* the following words don't have typos: "helllllooooo", "tobeornottobe" and "oooooo".
When Beroffice editor finds a word with a typo, it inserts as little as possible number of spaces in this word (dividing it into several words) in such a way that each of the resulting words is typed without any typos.
Implement this feature of Beroffice editor. Consider the following letters as the only vowels: 'a', 'e', 'i', 'o' and 'u'. All the other letters are consonants in this problem.
Input
The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters.
Output
Print the given word without any changes if there are no typos.
If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them.
Examples
Input
hellno
Output
hell no
Input
abacaba
Output
abacaba
Input
asdfasdf
Output
asd fasd f
Submitted Solution:
```
s=input()
l=''
k=0
o=1
p=0
new=s
a=['a', 'e', 'i', 'o','u']
for i in range(len(s)):
if s[i] not in a:
if s[i]!=l:
if o>=2:
k+=2
l=s[i]
else:
k+=1
l=s[i]
o=1
else:
o+=1
if k==3:
new=new[:i+p]+' '+new[i+p:]
p+=1
k=1
else:
k=0
l=''
o=1
print(new)
```
No
| 92,318 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a set of n points on the plane. A line containing the origin is called good, if projection of the given set to this line forms a symmetric multiset of points. Find the total number of good lines.
Multiset is a set where equal elements are allowed.
Multiset is called symmetric, if there is a point P on the plane such that the multiset is [centrally symmetric](https://en.wikipedia.org/wiki/Point_reflection) in respect of point P.
Input
The first line contains a single integer n (1 ≤ n ≤ 2000) — the number of points in the set.
Each of the next n lines contains two integers xi and yi ( - 106 ≤ xi, yi ≤ 106) — the coordinates of the points. It is guaranteed that no two points coincide.
Output
If there are infinitely many good lines, print -1.
Otherwise, print single integer — the number of good lines.
Examples
Input
3
1 2
2 1
3 3
Output
3
Input
2
4 3
1 2
Output
-1
Note
Picture to the first sample test:
<image>
In the second sample, any line containing the origin is good.
Tags: geometry
Correct Solution:
```
from fractions import Fraction
import time
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
def to_tuple(self):
return (self.x, self.y)
def __repr__(self):
return "Point({}, {})".format(self.x, self.y)
def __eq__(self, other):
return self.to_tuple() == other.to_tuple()
def __hash__(self):
return hash(self.to_tuple())
def __neg__(self):
return Point(-self.x, -self.y)
def __add__(self, other):
return Point(self.x+other.x, self.y+other.y)
def __sub__(self, other):
return self+(-other)
def scalar_mul(self, mu):
return Point(mu*self.x, mu*self.y)
def int_divide(self, den):
return Point(self.x//den, self.y//den)
class Line:
def __init__(self, a, b, c):
# ax+by+c=0
self.a = a
self.b = b
self.c = c
def __repr__(self):
return "{}*x + {}*y + {} = 0".format(self.a, self.b, self.c)
@classmethod
def between_two_points(cls, P, Q):
return cls(P.y-Q.y, Q.x-P.x, P.x*Q.y-P.y*Q.x)
def evaluate(self, P):
return self.a*P.x+self.b*P.y+self.c
def direction(self):
if self.a == 0:
return (0, 1)
return (1, Fraction(self.b, self.a))
true_start = time.time()
n = int(input())
points = set()
center = Point(0, 0)
for i in range(n):
row = input().split(" ")
cur = Point(int(row[0]), int(row[1])).scalar_mul(2*n)
center += cur
points.add(cur)
center = center.int_divide(n)
dcenter = center+center
sym_points_set = set()
for p in points:
sym_points_set.add(dcenter-p)
nosym = list(points - sym_points_set)
if len(nosym) == 0:
print(-1)
exit(0)
cnt = 0
p0 = nosym[0]
good_lines = set()
for p in nosym:
m = (p+p0).int_divide(2)
line = Line.between_two_points(m, center)
distances = list(map(line.evaluate, nosym))
ok = True
mydict = {}
for dd in distances:
dda = abs(dd)
if dda not in mydict:
mydict[dda] = 1
else:
mydict[dda] += 1
for k in mydict:
if mydict[k] % 2 == 1 and k != 0:
ok = False
break
if ok:
good_lines.add(line.direction())
print(len(good_lines))
```
| 92,319 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a set of n points on the plane. A line containing the origin is called good, if projection of the given set to this line forms a symmetric multiset of points. Find the total number of good lines.
Multiset is a set where equal elements are allowed.
Multiset is called symmetric, if there is a point P on the plane such that the multiset is [centrally symmetric](https://en.wikipedia.org/wiki/Point_reflection) in respect of point P.
Input
The first line contains a single integer n (1 ≤ n ≤ 2000) — the number of points in the set.
Each of the next n lines contains two integers xi and yi ( - 106 ≤ xi, yi ≤ 106) — the coordinates of the points. It is guaranteed that no two points coincide.
Output
If there are infinitely many good lines, print -1.
Otherwise, print single integer — the number of good lines.
Examples
Input
3
1 2
2 1
3 3
Output
3
Input
2
4 3
1 2
Output
-1
Note
Picture to the first sample test:
<image>
In the second sample, any line containing the origin is good.
Tags: geometry
Correct Solution:
```
from fractions import Fraction
import time
from collections import Counter
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
def to_tuple(self):
return (self.x, self.y)
def __repr__(self):
return "Point({}, {})".format(self.x, self.y)
def __eq__(self, other):
return self.to_tuple() == other.to_tuple()
def __hash__(self):
return hash(self.to_tuple())
def __neg__(self):
return Point(-self.x, -self.y)
def __add__(self, other):
return Point(self.x+other.x, self.y+other.y)
def __sub__(self, other):
return self+(-other)
def scalar_mul(self, mu):
return Point(mu*self.x, mu*self.y)
def int_divide(self, den):
return Point(self.x//den, self.y//den)
def __lt__(self, other):
if self.x == other.x:
return self.y < other.y
return self.x < other.x
def dot(self, other):
return self.x*other.x+self.y*other.y
class Line:
def __init__(self, a, b, c):
# ax+by+c=0
self.a = a
self.b = b
self.c = c
def __repr__(self):
return "{}*x + {}*y + {} = 0".format(self.a, self.b, self.c)
@classmethod
def between_two_points(cls, P, Q):
return cls(P.y-Q.y, Q.x-P.x, P.x*Q.y-P.y*Q.x)
def evaluate(self, P):
return self.a*P.x+self.b*P.y+self.c
def direction(self):
if self.a == 0:
return (0, 1)
return (1, Fraction(self.b, self.a))
true_start = time.time()
n = int(input())
points = set()
center = Point(0, 0)
for i in range(n):
row = input().split(" ")
cur = Point(int(row[0]), int(row[1])).scalar_mul(2*n)
center += cur
points.add(cur)
center = center.int_divide(n)
dcenter = center+center
# nosym = []
# for p in points:
# psym = dcenter-p
# if psym not in points:
# nosym.append(p)
sym_points_set = set()
for p in points:
sym_points_set.add(dcenter-p)
nosym = list(points - sym_points_set)
#print(nosym)
# print("preproc:", time.time()-true_start)
if len(nosym) == 0:
print(-1)
exit(0)
cnt = 0
p0 = nosym[0]
good_lines = set()
for p in nosym:
start = time.time()
m = (p+p0).int_divide(2)
supp = Line.between_two_points(m, center)
time_setup = time.time()-start
distances = list(map(supp.evaluate, nosym))
time_projs = time.time()-start
# sorting strat
ok = True
SORTING = False
if SORTING:
distances = sorted(distances)
time_sorting = time.time()-start
m = len(distances)
for i in range(m//2):
if distances[i] != -distances[m-1-i]:
ok = False
break
else:
mydict = {}
for dd in distances:
dda = abs(dd)
if dda not in mydict:
mydict[dda] = 1
else:
mydict[dda] += 1
time_sorting = time.time()-start
for k in mydict:
if mydict[k] % 2 == 1 and k != 0:
ok = False
break
if ok:
#print("ok", supp)
#print(distances)
#print(mydict)
good_lines.add(supp.direction())
#print("setup: {}\tprojs: {}\tsort: {}\tdone: {}".format(time_setup, time_projs, time_sorting, time.time()-start))
#print("total:", time.time()-true_start)
print(len(good_lines))
```
| 92,320 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a set of n points on the plane. A line containing the origin is called good, if projection of the given set to this line forms a symmetric multiset of points. Find the total number of good lines.
Multiset is a set where equal elements are allowed.
Multiset is called symmetric, if there is a point P on the plane such that the multiset is [centrally symmetric](https://en.wikipedia.org/wiki/Point_reflection) in respect of point P.
Input
The first line contains a single integer n (1 ≤ n ≤ 2000) — the number of points in the set.
Each of the next n lines contains two integers xi and yi ( - 106 ≤ xi, yi ≤ 106) — the coordinates of the points. It is guaranteed that no two points coincide.
Output
If there are infinitely many good lines, print -1.
Otherwise, print single integer — the number of good lines.
Examples
Input
3
1 2
2 1
3 3
Output
3
Input
2
4 3
1 2
Output
-1
Note
Picture to the first sample test:
<image>
In the second sample, any line containing the origin is good.
Tags: geometry
Correct Solution:
```
from fractions import Fraction
import time
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
def to_tuple(self):
return (self.x, self.y)
def __repr__(self):
return "Point({}, {})".format(self.x, self.y)
def __eq__(self, other):
return self.to_tuple() == other.to_tuple()
def __hash__(self):
return hash(self.to_tuple())
def __neg__(self):
return Point(-self.x, -self.y)
def __add__(self, other):
return Point(self.x+other.x, self.y+other.y)
def __sub__(self, other):
return self+(-other)
def scalar_mul(self, mu):
return Point(mu*self.x, mu*self.y)
def int_divide(self, den):
return Point(self.x//den, self.y//den)
class Line:
def __init__(self, a, b, c):
# ax+by+c=0
self.a = a
self.b = b
self.c = c
def __repr__(self):
return "{}*x + {}*y + {} = 0".format(self.a, self.b, self.c)
@classmethod
def between_two_points(cls, P, Q):
return cls(P.y-Q.y, Q.x-P.x, P.x*Q.y-P.y*Q.x)
def evaluate(self, P):
return self.a*P.x+self.b*P.y+self.c
def direction(self):
if self.a == 0:
return (0, 1)
return (1, Fraction(self.b, self.a))
def abs_sgn(x):
if x == 0:
return 0, 0
if x < 0:
return -x, -1
return x, 1
def solve(tuple_points):
points = set()
center = Point(0, 0)
for cur in tuple_points:
cur = Point(*cur).scalar_mul(2*n)
center += cur
points.add(cur)
center = center.int_divide(n)
dcenter = center+center
sym_points_set = set()
for p in points:
sym_points_set.add(dcenter-p)
nosym = list(points - sym_points_set)
if len(nosym) == 0:
print(-1)
exit(0)
p0 = nosym[0]
good_lines = set()
for p in nosym:
m = (p+p0).int_divide(2)
line = Line.between_two_points(m, center)
distances = list(map(line.evaluate, nosym))
ok = True
mydict = {}
for dd in distances:
dda, sgn = abs_sgn(dd)
if dda not in mydict:
mydict[dda] = sgn
else:
mydict[dda] += sgn
for k in mydict:
if mydict[k] != 0:
ok = False
break
if ok:
good_lines.add(line.direction())
return len(good_lines)
# This one is accepted on CF
if __name__ == "__main__":
n = int(input())
pts = []
for i in range(n):
row = input().split(" ")
cur = (int(row[0]), int(row[1]))
pts.append(cur)
print(solve(pts))
```
| 92,321 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a set of n points on the plane. A line containing the origin is called good, if projection of the given set to this line forms a symmetric multiset of points. Find the total number of good lines.
Multiset is a set where equal elements are allowed.
Multiset is called symmetric, if there is a point P on the plane such that the multiset is [centrally symmetric](https://en.wikipedia.org/wiki/Point_reflection) in respect of point P.
Input
The first line contains a single integer n (1 ≤ n ≤ 2000) — the number of points in the set.
Each of the next n lines contains two integers xi and yi ( - 106 ≤ xi, yi ≤ 106) — the coordinates of the points. It is guaranteed that no two points coincide.
Output
If there are infinitely many good lines, print -1.
Otherwise, print single integer — the number of good lines.
Examples
Input
3
1 2
2 1
3 3
Output
3
Input
2
4 3
1 2
Output
-1
Note
Picture to the first sample test:
<image>
In the second sample, any line containing the origin is good.
Tags: geometry
Correct Solution:
```
from fractions import Fraction
import time
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
def to_tuple(self):
return (self.x, self.y)
def __repr__(self):
return "Point({}, {})".format(self.x, self.y)
def __eq__(self, other):
return self.to_tuple() == other.to_tuple()
def __hash__(self):
return hash(self.to_tuple())
def __neg__(self):
return Point(-self.x, -self.y)
def __add__(self, other):
return Point(self.x+other.x, self.y+other.y)
def __sub__(self, other):
return self+(-other)
def scalar_mul(self, mu):
return Point(mu*self.x, mu*self.y)
def int_divide(self, den):
return Point(self.x//den, self.y//den)
class Line:
def __init__(self, a, b, c):
# ax+by+c=0
self.a = a
self.b = b
self.c = c
def __repr__(self):
return "{}*x + {}*y + {} = 0".format(self.a, self.b, self.c)
@classmethod
def between_two_points(cls, P, Q):
return cls(P.y-Q.y, Q.x-P.x, P.x*Q.y-P.y*Q.x)
def evaluate(self, P):
return self.a*P.x+self.b*P.y+self.c
def direction(self):
if self.a == 0:
return (0, 1)
return (1, Fraction(self.b, self.a))
def abs_sgn(x):
if x == 0:
return 0, 0
if x < 0:
return -x, -1
return x, 1
true_start = time.time()
n = int(input())
points = set()
center = Point(0, 0)
for i in range(n):
row = input().split(" ")
cur = Point(int(row[0]), int(row[1])).scalar_mul(2*n)
center += cur
points.add(cur)
center = center.int_divide(n)
dcenter = center+center
sym_points_set = set()
for p in points:
sym_points_set.add(dcenter-p)
nosym = list(points - sym_points_set)
if len(nosym) == 0:
print(-1)
exit(0)
cnt = 0
p0 = nosym[0]
good_lines = set()
for p in nosym:
m = (p+p0).int_divide(2)
line = Line.between_two_points(m, center)
distances = list(map(line.evaluate, nosym))
ok = True
mydict = {}
for dd in distances:
dda, sgn = abs_sgn(dd)
if dda not in mydict:
mydict[dda] = sgn
else:
mydict[dda] += sgn
for k in mydict:
if mydict[k] != 0:
ok = False
break
if ok:
good_lines.add(line.direction())
print(len(good_lines))
# This one is accepted on CF
```
| 92,322 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a set of n points on the plane. A line containing the origin is called good, if projection of the given set to this line forms a symmetric multiset of points. Find the total number of good lines.
Multiset is a set where equal elements are allowed.
Multiset is called symmetric, if there is a point P on the plane such that the multiset is [centrally symmetric](https://en.wikipedia.org/wiki/Point_reflection) in respect of point P.
Input
The first line contains a single integer n (1 ≤ n ≤ 2000) — the number of points in the set.
Each of the next n lines contains two integers xi and yi ( - 106 ≤ xi, yi ≤ 106) — the coordinates of the points. It is guaranteed that no two points coincide.
Output
If there are infinitely many good lines, print -1.
Otherwise, print single integer — the number of good lines.
Examples
Input
3
1 2
2 1
3 3
Output
3
Input
2
4 3
1 2
Output
-1
Note
Picture to the first sample test:
<image>
In the second sample, any line containing the origin is good.
Submitted Solution:
```
from fractions import Fraction
import time
from collections import Counter
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
def to_tuple(self):
return (self.x, self.y)
def __repr__(self):
return "Point({}, {})".format(self.x, self.y)
def __eq__(self, other):
return self.to_tuple() == other.to_tuple()
def __hash__(self):
return hash(self.to_tuple())
def __neg__(self):
return Point(-self.x, -self.y)
def __add__(self, other):
return Point(self.x+other.x, self.y+other.y)
def __sub__(self, other):
return self+(-other)
def scalar_mul(self, mu):
return Point(mu*self.x, mu*self.y)
def int_divide(self, den):
return Point(self.x//den, self.y//den)
def __lt__(self, other):
if self.x == other.x:
return self.y < other.y
return self.x < other.x
def dot(self, other):
return self.x*other.x+self.y*other.y
class Line:
def __init__(self, a, b, c):
# ax+by+c=0
self.a = a
self.b = b
self.c = c
def __repr__(self):
return "{}*x + {}*y + {} = 0".format(self.a, self.b, self.c)
@classmethod
def between_two_points(cls, P, Q):
return cls(P.y-Q.y, Q.x-P.x, P.x*Q.y-P.y*Q.x)
def evaluate(self, P):
return self.a*P.x+self.b*P.y+self.c
def direction(self):
if self.a == 0:
return (0, 1)
return (1, Fraction(self.b, self.a))
true_start = time.time()
n = int(input())
points = set()
center = Point(0, 0)
for i in range(n):
row = input().split(" ")
cur = Point(int(row[0]), int(row[1])).scalar_mul(2*n)
center += cur
points.add(cur)
center = center.int_divide(n)
dcenter = center+center
# nosym = []
# for p in points:
# psym = dcenter-p
# if psym not in points:
# nosym.append(p)
sym_points_set = set()
for p in points:
sym_points_set.add(dcenter-p)
nosym = list(points - sym_points_set)
#print("preproc:", time.time()-true_start)
if len(nosym) == 0:
print(-1)
exit(0)
cnt = 0
p0 = nosym[0]
good_lines = set()
for p in nosym:
start = time.time()
m = (p+p0).int_divide(2)
supp = Line.between_two_points(m, center)
time_setup = time.time()-start
distances = map(supp.evaluate, nosym)
# sorting strat
ok = True
SORTING = False
if SORTING:
distances = set(distances)
time_projs = time.time()-start
sprojs = sorted(distances)
time_sorting = time.time()-start
m = len(sprojs)
for i in range(m//2):
if sprojs[i] != -sprojs[m-1-i]:
ok = False
break
else:
distances = list(distances)
time_projs = time.time()-start
mydict = {}
for dd in distances:
dda = abs(dd)
if dda not in mydict:
mydict[dda] = 1
else:
mydict[dda] += 1
time_sorting = time.time()-start
for k in mydict:
if mydict[k] == 1:
ok = False
break
if ok:
good_lines.add(supp.direction())
#print("setup: {}\tprojs: {}\tsort: {}\tdone: {}".format(time_setup, time_projs, time_sorting, time.time()-start))
#print("total:", time.time()-true_start)
print(len(good_lines))
```
No
| 92,323 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a set of n points on the plane. A line containing the origin is called good, if projection of the given set to this line forms a symmetric multiset of points. Find the total number of good lines.
Multiset is a set where equal elements are allowed.
Multiset is called symmetric, if there is a point P on the plane such that the multiset is [centrally symmetric](https://en.wikipedia.org/wiki/Point_reflection) in respect of point P.
Input
The first line contains a single integer n (1 ≤ n ≤ 2000) — the number of points in the set.
Each of the next n lines contains two integers xi and yi ( - 106 ≤ xi, yi ≤ 106) — the coordinates of the points. It is guaranteed that no two points coincide.
Output
If there are infinitely many good lines, print -1.
Otherwise, print single integer — the number of good lines.
Examples
Input
3
1 2
2 1
3 3
Output
3
Input
2
4 3
1 2
Output
-1
Note
Picture to the first sample test:
<image>
In the second sample, any line containing the origin is good.
Submitted Solution:
```
from fractions import Fraction
import time
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
def to_tuple(self):
return (self.x, self.y)
def __repr__(self):
return "Point({}, {})".format(self.x, self.y)
def __eq__(self, other):
return self.to_tuple() == other.to_tuple()
def __hash__(self):
return hash(self.to_tuple())
def __neg__(self):
return Point(-self.x, -self.y)
def __add__(self, other):
return Point(self.x+other.x, self.y+other.y)
def __sub__(self, other):
return self+(-other)
def scalar_mul(self, mu):
return Point(mu*self.x, mu*self.y)
def int_divide(self, den):
return Point(self.x//den, self.y//den)
class Line:
def __init__(self, a, b, c):
# ax+by+c=0
self.a = a
self.b = b
self.c = c
def __repr__(self):
return "{}*x + {}*y + {} = 0".format(self.a, self.b, self.c)
@classmethod
def between_two_points(cls, P, Q):
return cls(P.y-Q.y, Q.x-P.x, P.x*Q.y-P.y*Q.x)
def evaluate(self, P):
return self.a*P.x+self.b*P.y+self.c
def direction(self):
if self.a == 0:
return (0, 1)
return (1, Fraction(self.b, self.a))
def abs_sgn(x):
if x == 0:
return 0, 0
if x < 0:
return -x, -1
return x, 1
true_start = time.time()
n = int(input())
tuple_points = []
points = set()
center = Point(0, 0)
for i in range(n):
row = input().split(" ")
tcur = (int(row[0]), int(row[1]))
cur = Point(*tcur).scalar_mul(2*n)
center += cur
tuple_points.append(tcur)
points.add(cur)
center = center.int_divide(n)
dcenter = center+center
#print(center.x/(2*n), center.y/(2*n))
sym_points_set = set()
for p in points:
sym_points_set.add(dcenter-p)
nosym = list(points - sym_points_set)
#print([(a.x//(2*n), a.y//(2*n)) for a in nosym])
if len(nosym) == 0:
print(-1)
exit(0)
cnt = 0
p0 = nosym[0]
good_lines = set()
for p in nosym:
m = (p+p0).int_divide(2)
line = Line.between_two_points(m, center)
distances = list(map(line.evaluate, nosym))
ok = True
mydict = {}
for dd in distances:
dda, sgn = abs_sgn(dd)
if dda not in mydict:
mydict[dda] = sgn
else:
mydict[dda] += sgn
for k in mydict:
if mydict[k] != 0:
ok = False
break
if ok:
good_lines.add(line.direction())
res = len(good_lines)
if n==2000:
print(len(nosym))
else:
print(res)
# This one is accepted on CF
```
No
| 92,324 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a set of n points on the plane. A line containing the origin is called good, if projection of the given set to this line forms a symmetric multiset of points. Find the total number of good lines.
Multiset is a set where equal elements are allowed.
Multiset is called symmetric, if there is a point P on the plane such that the multiset is [centrally symmetric](https://en.wikipedia.org/wiki/Point_reflection) in respect of point P.
Input
The first line contains a single integer n (1 ≤ n ≤ 2000) — the number of points in the set.
Each of the next n lines contains two integers xi and yi ( - 106 ≤ xi, yi ≤ 106) — the coordinates of the points. It is guaranteed that no two points coincide.
Output
If there are infinitely many good lines, print -1.
Otherwise, print single integer — the number of good lines.
Examples
Input
3
1 2
2 1
3 3
Output
3
Input
2
4 3
1 2
Output
-1
Note
Picture to the first sample test:
<image>
In the second sample, any line containing the origin is good.
Submitted Solution:
```
from fractions import Fraction
import time
from collections import Counter
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
def to_tuple(self):
return (self.x, self.y)
def __repr__(self):
return "Point({}, {})".format(self.x, self.y)
def __eq__(self, other):
return self.to_tuple() == other.to_tuple()
def __hash__(self):
return hash(self.to_tuple())
def __neg__(self):
return Point(-self.x, -self.y)
def __add__(self, other):
return Point(self.x+other.x, self.y+other.y)
def __sub__(self, other):
return self+(-other)
def scalar_mul(self, mu):
return Point(mu*self.x, mu*self.y)
def int_divide(self, den):
return Point(self.x//den, self.y//den)
def __lt__(self, other):
if self.x == other.x:
return self.y < other.y
return self.x < other.x
def dot(self, other):
return self.x*other.x+self.y*other.y
class Line:
def __init__(self, a, b, c):
# ax+by+c=0
self.a = a
self.b = b
self.c = c
def __repr__(self):
return "{}*x + {}*y + {} = 0".format(self.a, self.b, self.c)
@classmethod
def between_two_points(cls, P, Q):
return cls(P.y-Q.y, Q.x-P.x, P.x*Q.y-P.y*Q.x)
def evaluate(self, P):
return self.a*P.x+self.b*P.y+self.c
def direction(self):
if self.a == 0:
return (0, 1)
return (1, Fraction(self.b, self.a))
true_start = time.time()
n = int(input())
points = set()
center = Point(0, 0)
for i in range(n):
row = input().split(" ")
cur = Point(int(row[0]), int(row[1])).scalar_mul(2*n)
center += cur
points.add(cur)
center = center.int_divide(n)
dcenter = center+center
# nosym = []
# for p in points:
# psym = dcenter-p
# if psym not in points:
# nosym.append(p)
sym_points_set = set()
for p in points:
sym_points_set.add(dcenter-p)
nosym = list(points - sym_points_set)
# print(nosym)
# print("preproc:", time.time()-true_start)
if len(nosym) == 0:
print(-1)
exit(0)
cnt = 0
p0 = nosym[0]
good_lines = set()
for p in nosym:
start = time.time()
m = (p+p0).int_divide(2)
supp = Line.between_two_points(m, center)
time_setup = time.time()-start
distances = map(supp.evaluate, nosym)
# sorting strat
ok = True
SORTING = False
if SORTING:
distances = set(distances)
time_projs = time.time()-start
sprojs = sorted(distances)
time_sorting = time.time()-start
m = len(sprojs)
for i in range(m//2):
if sprojs[i] != -sprojs[m-1-i]:
ok = False
break
else:
distances = list(distances)
#print(distances)
time_projs = time.time()-start
mydict = {}
for dd in distances:
dda = abs(dd)
if dda not in mydict:
mydict[dda] = 1
else:
mydict[dda] += 1
time_sorting = time.time()-start
for k in mydict:
if mydict[k] == 1 and k != 0:
ok = False
break
if ok:
#print("ok", supp)
good_lines.add(supp.direction())
#print("setup: {}\tprojs: {}\tsort: {}\tdone: {}".format(time_setup, time_projs, time_sorting, time.time()-start))
#print("total:", time.time()-true_start)
print(len(good_lines))
```
No
| 92,325 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a set of n points on the plane. A line containing the origin is called good, if projection of the given set to this line forms a symmetric multiset of points. Find the total number of good lines.
Multiset is a set where equal elements are allowed.
Multiset is called symmetric, if there is a point P on the plane such that the multiset is [centrally symmetric](https://en.wikipedia.org/wiki/Point_reflection) in respect of point P.
Input
The first line contains a single integer n (1 ≤ n ≤ 2000) — the number of points in the set.
Each of the next n lines contains two integers xi and yi ( - 106 ≤ xi, yi ≤ 106) — the coordinates of the points. It is guaranteed that no two points coincide.
Output
If there are infinitely many good lines, print -1.
Otherwise, print single integer — the number of good lines.
Examples
Input
3
1 2
2 1
3 3
Output
3
Input
2
4 3
1 2
Output
-1
Note
Picture to the first sample test:
<image>
In the second sample, any line containing the origin is good.
Submitted Solution:
```
from fractions import Fraction
import time
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
def to_tuple(self):
return (self.x, self.y)
def __repr__(self):
return "Point({}, {})".format(self.x, self.y)
def __eq__(self, other):
return self.to_tuple() == other.to_tuple()
def __hash__(self):
return hash(self.to_tuple())
def __neg__(self):
return Point(-self.x, -self.y)
def __add__(self, other):
return Point(self.x+other.x, self.y+other.y)
def __sub__(self, other):
return self+(-other)
def scalar_mul(self, mu):
return Point(mu*self.x, mu*self.y)
def int_divide(self, den):
return Point(self.x//den, self.y//den)
class Line:
def __init__(self, a, b, c):
# ax+by+c=0
self.a = a
self.b = b
self.c = c
def __repr__(self):
return "{}*x + {}*y + {} = 0".format(self.a, self.b, self.c)
@classmethod
def between_two_points(cls, P, Q):
return cls(P.y-Q.y, Q.x-P.x, P.x*Q.y-P.y*Q.x)
def evaluate(self, P):
return self.a*P.x+self.b*P.y+self.c
def direction(self):
if self.a == 0:
return (0, 1)
return (1, Fraction(self.b, self.a))
def abs_sgn(x):
if x == 0:
return 0, 0
if x < 0:
return -x, -1
return x, 1
true_start = time.time()
n = int(input())
tuple_points = []
points = set()
center = Point(0, 0)
for i in range(n):
row = input().split(" ")
tcur = (int(row[0]), int(row[1]))
cur = Point(*tcur).scalar_mul(2*n)
center += cur
tuple_points.append(tcur)
points.add(cur)
center = center.int_divide(n)
dcenter = center+center
#print(center.x/(2*n), center.y/(2*n))
sym_points_set = set()
for p in points:
sym_points_set.add(dcenter-p)
nosym = list(points - sym_points_set)
#print([(a.x//(2*n), a.y//(2*n)) for a in nosym])
if len(nosym) == 0:
print(-1)
exit(0)
cnt = 0
p0 = nosym[0]
good_lines = set()
for p in nosym:
m = (p+p0).int_divide(2)
line = Line.between_two_points(m, center)
distances = list(map(line.evaluate, nosym))
ok = True
mydict = {}
for dd in distances:
dda, sgn = abs_sgn(dd)
if dda not in mydict:
mydict[dda] = sgn
else:
mydict[dda] += sgn
for k in mydict:
if mydict[k] != 0:
ok = False
break
if ok:
good_lines.add(line.direction())
res = len(good_lines)
if n==2000:
print(center)
else:
print(res)
# This one is accepted on CF
```
No
| 92,326 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Given an integer N, find two permutations:
1. Permutation p of numbers from 1 to N such that pi ≠ i and pi & i = 0 for all i = 1, 2, ..., N.
2. Permutation q of numbers from 1 to N such that qi ≠ i and qi & i ≠ 0 for all i = 1, 2, ..., N.
& is the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND).
Input
The input consists of one line containing a single integer N (1 ≤ N ≤ 105).
Output
For each subtask, if the required permutation doesn't exist, output a single line containing the word "NO"; otherwise output the word "YES" in the first line and N elements of the permutation, separated by spaces, in the second line. If there are several possible permutations in a subtask, output any of them.
Examples
Input
3
Output
NO
NO
Input
6
Output
YES
6 5 4 3 2 1
YES
3 6 2 5 1 4
Tags: constructive algorithms
Correct Solution:
```
from math import*
n=int(input())
if n%2:
print('NO')
else:
print("YES")
k=floor(log2(n))+1
res = [0 for i in range(n)]
occupied = [0 for i in range(n)]
switch = 0
for i in range(n,0,-1):
val = 2**k-1-i
if val > n:
k-=1
val = 2**k-1-i
if occupied[val-1]:
while occupied[val-1]:
k-=1
val = 2**k-1-i
val = 2**k-1-i
occupied[val-1] = 1
res[i-1] = val
for i in res:
print(i,end=' ')
print()
if n in [1,2,3,4,5]:
print('NO')
elif int(log2(n)) == log2(n):
print('NO')
elif n == 6:
print('YES')
print('3 6 2 5 1 4')
else:
print('YES')
print('7 3 2 5 6 4 1',end=' ')
for i in range(8,n+1):
if int(log2(i)) == log2(i):
print(min(i*2-1,n),end=' ')
else:
print(i-1,end=' ')
print()
```
| 92,327 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Given an integer N, find two permutations:
1. Permutation p of numbers from 1 to N such that pi ≠ i and pi & i = 0 for all i = 1, 2, ..., N.
2. Permutation q of numbers from 1 to N such that qi ≠ i and qi & i ≠ 0 for all i = 1, 2, ..., N.
& is the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND).
Input
The input consists of one line containing a single integer N (1 ≤ N ≤ 105).
Output
For each subtask, if the required permutation doesn't exist, output a single line containing the word "NO"; otherwise output the word "YES" in the first line and N elements of the permutation, separated by spaces, in the second line. If there are several possible permutations in a subtask, output any of them.
Examples
Input
3
Output
NO
NO
Input
6
Output
YES
6 5 4 3 2 1
YES
3 6 2 5 1 4
Tags: constructive algorithms
Correct Solution:
```
def test(x, i):
i = list(i)
ok = True
for j in range(x):
if (i[j] == j+1 or (i[j]&(j+1) != 0)):
ok = False
if ok:
print(i)
def comp(n):
return 2**len(bin(n)[2:])-1-n
n = int(input())
nn = n
if (n%2 == 0):
x = []
while (n != 0):
#add n to comp(n) to the front of x
for i in range(comp(n), n+1):
x.append(i)
n = comp(n)-1
x.reverse()
print("YES")
print(' '.join([str(i) for i in x]))
else:
print("NO")
pow2 = [2**i for i in range(20)]
def make(n):
if n <= 5: return []
if n == 6: return [3, 6, 1, 5, 4, 2]
if n == 7: return [3, 6, 1, 5, 4, 7, 2]
if n in pow2:
return []
shift = 2**(len(bin(n)[2:])-1)
array = [i for i in range(shift, n+1)]
array = array[1:] + [array[0]]
return make(shift-1) + array
n = nn
k = make(n)
if k == []:
print("NO")
else:
print("YES")
print(' '.join([str(i) for i in k]))
```
| 92,328 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Given an integer N, find two permutations:
1. Permutation p of numbers from 1 to N such that pi ≠ i and pi & i = 0 for all i = 1, 2, ..., N.
2. Permutation q of numbers from 1 to N such that qi ≠ i and qi & i ≠ 0 for all i = 1, 2, ..., N.
& is the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND).
Input
The input consists of one line containing a single integer N (1 ≤ N ≤ 105).
Output
For each subtask, if the required permutation doesn't exist, output a single line containing the word "NO"; otherwise output the word "YES" in the first line and N elements of the permutation, separated by spaces, in the second line. If there are several possible permutations in a subtask, output any of them.
Examples
Input
3
Output
NO
NO
Input
6
Output
YES
6 5 4 3 2 1
YES
3 6 2 5 1 4
Tags: constructive algorithms
Correct Solution:
```
from math import log2, floor
n=int(input())
# n=100
if n%2:
print('NO')
else:
print("YES")
k=floor(log2(n))+1
res = [0 for i in range(n)]
occupied = [0 for i in range(n)]
switch = 0
for i in range(n,0,-1):
val = 2**k-1-i
if val > n:
k-=1
val = 2**k-1-i
if occupied[val-1]:
while occupied[val-1]:
k-=1
val = 2**k-1-i
val = 2**k-1-i
occupied[val-1] = 1
res[i-1] = val
for i in res:
print(i,end=' ')
print()
if n in [1,2,3,4,5]:
print('NO')
elif int(log2(n)) == log2(n):
print('NO')
elif n == 6:
print('YES')
print('3 6 2 5 1 4')
else:
print('YES')
print('7 3 2 5 6 4 1',end=' ')
for i in range(8,n+1):
if int(log2(i)) == log2(i):
print(min(i*2-1,n),end=' ')
else:
print(i-1,end=' ')
print()
```
| 92,329 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Given an integer N, find two permutations:
1. Permutation p of numbers from 1 to N such that pi ≠ i and pi & i = 0 for all i = 1, 2, ..., N.
2. Permutation q of numbers from 1 to N such that qi ≠ i and qi & i ≠ 0 for all i = 1, 2, ..., N.
& is the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND).
Input
The input consists of one line containing a single integer N (1 ≤ N ≤ 105).
Output
For each subtask, if the required permutation doesn't exist, output a single line containing the word "NO"; otherwise output the word "YES" in the first line and N elements of the permutation, separated by spaces, in the second line. If there are several possible permutations in a subtask, output any of them.
Examples
Input
3
Output
NO
NO
Input
6
Output
YES
6 5 4 3 2 1
YES
3 6 2 5 1 4
Tags: constructive algorithms
Correct Solution:
```
from math import log
from sys import exit
n = int(input())
a = [i for i in range(n + 1)]
def ans(n):
if n <= 0 or n % 2:
return
j, cr = (1 << int(log(n, 2))), 1
while j + cr - 1 <= n:
a[j - cr], a[j + cr - 1] = a[j + cr - 1], a[j - cr]
cr += 1
ans(j - cr)
if n % 2 == 0:
ans(n)
print("YES")
print(*a[1:])
else:
print("NO")
if n <= 5 or (1 << int(log(n, 2))) == n:
print("NO")
exit(0)
print("YES")
print("3 6 1 5 4 2" if n <= 6 else "3 6 1 5 4 7 2", end=' ')
cr = 8
v = (1 << int(log(n, 2)))
for i in range(8, n + 1):
if i >= v:
print(n if i == v else i - 1, end=' ')
continue
if i == cr:
cr *= 2
print(cr - 1, end=' ')
else:
print(i - 1, end=' ')
```
| 92,330 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Given an integer N, find two permutations:
1. Permutation p of numbers from 1 to N such that pi ≠ i and pi & i = 0 for all i = 1, 2, ..., N.
2. Permutation q of numbers from 1 to N such that qi ≠ i and qi & i ≠ 0 for all i = 1, 2, ..., N.
& is the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND).
Input
The input consists of one line containing a single integer N (1 ≤ N ≤ 105).
Output
For each subtask, if the required permutation doesn't exist, output a single line containing the word "NO"; otherwise output the word "YES" in the first line and N elements of the permutation, separated by spaces, in the second line. If there are several possible permutations in a subtask, output any of them.
Examples
Input
3
Output
NO
NO
Input
6
Output
YES
6 5 4 3 2 1
YES
3 6 2 5 1 4
Tags: constructive algorithms
Correct Solution:
```
from math import log2, floor
n=int(input())
# n=100
if n%2:
print('NO')
else:
print("YES")
k=floor(log2(n))+1
res = [0 for i in range(n)]
occupied = [0 for i in range(n)]
switch = 0
for i in range(n,0,-1):
val = 2**k-1-i
if val > n:
k-=1
val = 2**k-1-i
if occupied[val-1]:
while occupied[val-1]:
k-=1
val = 2**k-1-i
val = 2**k-1-i
occupied[val-1] = 1
res[i-1] = val
for i in res:
print(i,end=' ')
print()
if n in [1,2,3,4,5]:
print('NO')
elif int(log2(n)) == log2(n):
print('NO')
elif n == 6:
print('YES')
print('3 6 2 5 1 4')
else:
print('YES')
print('7 3 2 5 6 4 1',end=' ')
for i in range(8,n):
p = pow(2,floor(log2(i))+1)
if i < pow(2,floor(log2(n))):
print(p*3//2-1-i,end=' ')
else:
print(i+1,end=' ')
if n > 7:
print(pow(2,floor(log2(n))))
```
| 92,331 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Given an integer N, find two permutations:
1. Permutation p of numbers from 1 to N such that pi ≠ i and pi & i = 0 for all i = 1, 2, ..., N.
2. Permutation q of numbers from 1 to N such that qi ≠ i and qi & i ≠ 0 for all i = 1, 2, ..., N.
& is the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND).
Input
The input consists of one line containing a single integer N (1 ≤ N ≤ 105).
Output
For each subtask, if the required permutation doesn't exist, output a single line containing the word "NO"; otherwise output the word "YES" in the first line and N elements of the permutation, separated by spaces, in the second line. If there are several possible permutations in a subtask, output any of them.
Examples
Input
3
Output
NO
NO
Input
6
Output
YES
6 5 4 3 2 1
YES
3 6 2 5 1 4
Tags: constructive algorithms
Correct Solution:
```
from math import log2
n = int(input())
p = [0] * (n + 1)
def f(n):
k = int(log2(n))
while k:
i = 1
while (1 << k) + i - 1 <= n:
p[(1 << k) + i - 1] = (1 << k) - i
p[(1 << k) - i] = (1 << k) + i - 1
i += 1
n = (1 << k) - i
if not n:
break
k = int(log2(n))
if n & 1:
print('NO')
else:
print('YES')
f(n)
print(*p[1:])
if n < 6 or 1 << int(log2(n)) == n:
print('NO')
else:
print('YES')
if n == 6:
print('3 6 2 5 1 4')
elif n == 7:
print('7 3 6 5 1 2 4')
else:
print('7 3 6 5 1 2 4', end=' ')
k = 3
while (1 << k) < n:
for i in range((1 << k) + 1, min(1 << k + 1, n + 1)):
print(i, end=' ')
print(1 << k, end=' ')
k += 1
```
| 92,332 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given an integer N, find two permutations:
1. Permutation p of numbers from 1 to N such that pi ≠ i and pi & i = 0 for all i = 1, 2, ..., N.
2. Permutation q of numbers from 1 to N such that qi ≠ i and qi & i ≠ 0 for all i = 1, 2, ..., N.
& is the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND).
Input
The input consists of one line containing a single integer N (1 ≤ N ≤ 105).
Output
For each subtask, if the required permutation doesn't exist, output a single line containing the word "NO"; otherwise output the word "YES" in the first line and N elements of the permutation, separated by spaces, in the second line. If there are several possible permutations in a subtask, output any of them.
Examples
Input
3
Output
NO
NO
Input
6
Output
YES
6 5 4 3 2 1
YES
3 6 2 5 1 4
Submitted Solution:
```
from math import log2, floor
n=int(input())
# n=100
if n%2:
print('NO')
else:
print("YES")
k=floor(log2(n))+1
res = [0 for i in range(n)]
occupied = [0 for i in range(n)]
switch = 0
for i in range(n,0,-1):
val = 2**k-1-i
if val > n:
k-=1
val = 2**k-1-i
if occupied[val-1]:
while occupied[val-1]:
k-=1
val = 2**k-1-i
val = 2**k-1-i
occupied[val-1] = 1
res[i-1] = val
for i in res:
print(i,end=' ')
print()
if n in [1,2,3,4,5]:
print('NO')
elif int(log2(n)) == log2(n):
print('NO')
elif n == 6:
print('YES')
print('3 6 2 5 1 4')
else:
print('YES')
print('7 3 2 5 6 4 1',end=' ')
for i in range(8,n):
p = pow(2,floor(log2(i))+1)
if i < pow(2,floor(log2(n))):
print(p*3//2-1-i,end=' ')
else:
print(i+1,end=' ')
print(pow(2,floor(log2(n))))
```
No
| 92,333 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given an integer N, find two permutations:
1. Permutation p of numbers from 1 to N such that pi ≠ i and pi & i = 0 for all i = 1, 2, ..., N.
2. Permutation q of numbers from 1 to N such that qi ≠ i and qi & i ≠ 0 for all i = 1, 2, ..., N.
& is the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND).
Input
The input consists of one line containing a single integer N (1 ≤ N ≤ 105).
Output
For each subtask, if the required permutation doesn't exist, output a single line containing the word "NO"; otherwise output the word "YES" in the first line and N elements of the permutation, separated by spaces, in the second line. If there are several possible permutations in a subtask, output any of them.
Examples
Input
3
Output
NO
NO
Input
6
Output
YES
6 5 4 3 2 1
YES
3 6 2 5 1 4
Submitted Solution:
```
def test(x, i):
i = list(i)
ok = True
for j in range(x):
if (i[j] == j+1 or (i[j]&(j+1) != 0)):
ok = False
if ok:
print(i)
def comp(n):
return 2**len(bin(n)[2:])-1-n
n = int(input())
nn = n
if (n%2 == 0):
x = []
while (n != 0):
#add n to comp(n) to the front of x
for i in range(comp(n), n+1):
x.append(i)
n = comp(n)-1
x.reverse()
print("YES")
print(' '.join([str(i) for i in x]))
else:
print("NO")
print("NO")
pow2 = [2**i for i in range(20)]
def make(n):
if n <= 5: return []
if n == 6: return [3, 6, 1, 5, 4, 2]
if n == 7: return [3, 6, 1, 5, 4, 7, 2]
if n in pow2:
return []
shift = 2**(len(bin(n)[2:])-1)
array = [i for i in range(shift, n+1)]
array = array[1:] + [array[0]]
return make(shift-1) + array
n = nn
k = make(n)
if k == []:
print("NO")
print("NO")
else:
print("YES")
print(' '.join([str(i) for i in k]))
```
No
| 92,334 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given an integer N, find two permutations:
1. Permutation p of numbers from 1 to N such that pi ≠ i and pi & i = 0 for all i = 1, 2, ..., N.
2. Permutation q of numbers from 1 to N such that qi ≠ i and qi & i ≠ 0 for all i = 1, 2, ..., N.
& is the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND).
Input
The input consists of one line containing a single integer N (1 ≤ N ≤ 105).
Output
For each subtask, if the required permutation doesn't exist, output a single line containing the word "NO"; otherwise output the word "YES" in the first line and N elements of the permutation, separated by spaces, in the second line. If there are several possible permutations in a subtask, output any of them.
Examples
Input
3
Output
NO
NO
Input
6
Output
YES
6 5 4 3 2 1
YES
3 6 2 5 1 4
Submitted Solution:
```
from math import log2, floor
n=int(input())
# n=3
if n%2:
print('NO')
else:
print("YES")
k=floor(log2(n))+1
res = [0 for i in range(n)]
occupied = [0 for i in range(n)]
switch = 0
for i in range(n,0,-1):
val = 2**k-1-i
if val > n:
k-=1
val = 2**k-1-i
if occupied[val-1]:
while occupied[val-1]:
k-=1
val = 2**k-1-i
val = 2**k-1-i
occupied[val-1] = 1
res[i-1] = val
for i in res:
print(i,end=' ')
print()
if n in [1,2,3,4,5]:
print('NO')
elif int(log2(n)) == log2(n):
print('NO')
elif n == 6:
print('YES')
print('3 6 2 5 1 4')
else:
print('YES')
print('7 3 2 5 6 4 1',end=' ')
for i in range(8,n+1):
p = pow(2,floor(log2(n)))
if i < p:
print(p*3//2-1-i,end=' ')
else:
print(n+p-i,end=' ')
print()
```
No
| 92,335 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given an integer N, find two permutations:
1. Permutation p of numbers from 1 to N such that pi ≠ i and pi & i = 0 for all i = 1, 2, ..., N.
2. Permutation q of numbers from 1 to N such that qi ≠ i and qi & i ≠ 0 for all i = 1, 2, ..., N.
& is the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND).
Input
The input consists of one line containing a single integer N (1 ≤ N ≤ 105).
Output
For each subtask, if the required permutation doesn't exist, output a single line containing the word "NO"; otherwise output the word "YES" in the first line and N elements of the permutation, separated by spaces, in the second line. If there are several possible permutations in a subtask, output any of them.
Examples
Input
3
Output
NO
NO
Input
6
Output
YES
6 5 4 3 2 1
YES
3 6 2 5 1 4
Submitted Solution:
```
from math import log2, floor
n=int(input())
# n=100
if n%2:
print('NO')
else:
print("YES")
k=floor(log2(n))+1
res = [0 for i in range(n)]
occupied = [0 for i in range(n)]
switch = 0
for i in range(n,0,-1):
val = 2**k-1-i
if val > n:
k-=1
val = 2**k-1-i
if occupied[val-1]:
while occupied[val-1]:
k-=1
val = 2**k-1-i
val = 2**k-1-i
occupied[val-1] = 1
res[i-1] = val
for i in res:
print(i,end=' ')
print()
if n in [1,2,3,4,5]:
print('NO')
elif int(log2(n)) == log2(n):
print('NO')
elif n == 6:
print('YES')
print('3 6 2 5 1 4')
else:
print('YES')
print('7 3 2 5 6 4 1',end=' ')
for i in range(8,n+1):
p = pow(2,floor(log2(i))+1)
if i < pow(2,floor(log2(n))):
print(p*3//2-1-i,end=' ')
else:
print(n+p//2-i,end=' ')
print()
```
No
| 92,336 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Anya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some value n times, and then compute the average value to lower the error.
Kirill has already made his measurements, and has got the following integer values: x1, x2, ..., xn. It is important that the values are close to each other, namely, the difference between the maximum value and the minimum value is at most 2.
Anya does not want to make the measurements, however, she can't just copy the values from Kirill's work, because the error of each measurement is a random value, and this coincidence will be noted by the teacher. Anya wants to write such integer values y1, y2, ..., yn in her work, that the following conditions are met:
* the average value of x1, x2, ..., xn is equal to the average value of y1, y2, ..., yn;
* all Anya's measurements are in the same bounds as all Kirill's measurements, that is, the maximum value among Anya's values is not greater than the maximum value among Kirill's values, and the minimum value among Anya's values is not less than the minimum value among Kirill's values;
* the number of equal measurements in Anya's work and Kirill's work is as small as possible among options with the previous conditions met. Formally, the teacher goes through all Anya's values one by one, if there is equal value in Kirill's work and it is not strike off yet, he strikes off this Anya's value and one of equal values in Kirill's work. The number of equal measurements is then the total number of strike off values in Anya's work.
Help Anya to write such a set of measurements that the conditions above are met.
Input
The first line contains a single integer n (1 ≤ n ≤ 100 000) — the numeber of measurements made by Kirill.
The second line contains a sequence of integers x1, x2, ..., xn ( - 100 000 ≤ xi ≤ 100 000) — the measurements made by Kirill. It is guaranteed that the difference between the maximum and minimum values among values x1, x2, ..., xn does not exceed 2.
Output
In the first line print the minimum possible number of equal measurements.
In the second line print n integers y1, y2, ..., yn — the values Anya should write. You can print the integers in arbitrary order. Keep in mind that the minimum value among Anya's values should be not less that the minimum among Kirill's values, and the maximum among Anya's values should be not greater than the maximum among Kirill's values.
If there are multiple answers, print any of them.
Examples
Input
6
-1 1 1 0 0 -1
Output
2
0 0 0 0 0 0
Input
3
100 100 101
Output
3
101 100 100
Input
7
-10 -9 -10 -8 -10 -9 -9
Output
5
-10 -10 -9 -9 -9 -9 -9
Note
In the first example Anya can write zeros as here measurements results. The average value is then equal to the average value of Kirill's values, and there are only two equal measurements.
In the second example Anya should write two values 100 and one value 101 (in any order), because it is the only possibility to make the average be the equal to the average of Kirill's values. Thus, all three measurements are equal.
In the third example the number of equal measurements is 5.
Tags: implementation, math
Correct Solution:
```
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
def get_mm(a):
mmin = 1000000
mmax = -1000000
for el in a:
if el> mmax:
mmax = el
if el< mmin:
mmin = el
if mmax - mmin == 2:
break
return mmin, mmax
def sol(a):
b = []
mmin, mmax = get_mm(a)
if mmax - mmin != 2:
return len(a), a
'''if mmax - mmin == 1:
counter = Counter(a)
if counter.get(mmax) > counter.get(mmin):
k = counter.get(mmax)//2
b.extend([mmin] * counter.get(mmin))
b.extend([mmax+1] * k)
b.extend([mmax-1] * k)
b.extend([mmax] * (counter.get(mmax) - 2*k))
else:
k = counter.get(mmin) // 2
b.extend([mmax] * counter.get(mmax))
b.extend([mmin + 1] * k)
b.extend([mmin - 1] * k)
b.extend([mmin] * (counter.get(mmin) - 2 * k))
return len(a) - 2 * k, b
'''
mid_v = mmin + 1
counter = Counter(a)
if not counter.get(mmin+1):
counter[mmin+1] = 0
one = min(counter.get(mmin), counter.get(mmax))
two = counter.get(mmin+1)//2
if one > two:
b.extend([mmin+1] * ((one*2) + counter.get(mmin+1)))
b.extend([mmax] * (counter.get(mmax) - one))
b.extend([mmin] * (counter.get(mmin) - one))
else:
b.extend([mmin+1] * (counter.get(mmin+1) - two*2))
b.extend([mmax] * (counter.get(mmax) + two))
b.extend([mmin] * (counter.get(mmin) + two ))
return len(a)- 2* max(one, two) , b
ans, mas = sol(a)
print(ans)
print(' '.join(list(map(str, mas))))
```
| 92,337 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Anya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some value n times, and then compute the average value to lower the error.
Kirill has already made his measurements, and has got the following integer values: x1, x2, ..., xn. It is important that the values are close to each other, namely, the difference between the maximum value and the minimum value is at most 2.
Anya does not want to make the measurements, however, she can't just copy the values from Kirill's work, because the error of each measurement is a random value, and this coincidence will be noted by the teacher. Anya wants to write such integer values y1, y2, ..., yn in her work, that the following conditions are met:
* the average value of x1, x2, ..., xn is equal to the average value of y1, y2, ..., yn;
* all Anya's measurements are in the same bounds as all Kirill's measurements, that is, the maximum value among Anya's values is not greater than the maximum value among Kirill's values, and the minimum value among Anya's values is not less than the minimum value among Kirill's values;
* the number of equal measurements in Anya's work and Kirill's work is as small as possible among options with the previous conditions met. Formally, the teacher goes through all Anya's values one by one, if there is equal value in Kirill's work and it is not strike off yet, he strikes off this Anya's value and one of equal values in Kirill's work. The number of equal measurements is then the total number of strike off values in Anya's work.
Help Anya to write such a set of measurements that the conditions above are met.
Input
The first line contains a single integer n (1 ≤ n ≤ 100 000) — the numeber of measurements made by Kirill.
The second line contains a sequence of integers x1, x2, ..., xn ( - 100 000 ≤ xi ≤ 100 000) — the measurements made by Kirill. It is guaranteed that the difference between the maximum and minimum values among values x1, x2, ..., xn does not exceed 2.
Output
In the first line print the minimum possible number of equal measurements.
In the second line print n integers y1, y2, ..., yn — the values Anya should write. You can print the integers in arbitrary order. Keep in mind that the minimum value among Anya's values should be not less that the minimum among Kirill's values, and the maximum among Anya's values should be not greater than the maximum among Kirill's values.
If there are multiple answers, print any of them.
Examples
Input
6
-1 1 1 0 0 -1
Output
2
0 0 0 0 0 0
Input
3
100 100 101
Output
3
101 100 100
Input
7
-10 -9 -10 -8 -10 -9 -9
Output
5
-10 -10 -9 -9 -9 -9 -9
Note
In the first example Anya can write zeros as here measurements results. The average value is then equal to the average value of Kirill's values, and there are only two equal measurements.
In the second example Anya should write two values 100 and one value 101 (in any order), because it is the only possibility to make the average be the equal to the average of Kirill's values. Thus, all three measurements are equal.
In the third example the number of equal measurements is 5.
Tags: implementation, math
Correct Solution:
```
n=int(input())
l=list(map(int,input().split()))
d=dict()
l.sort()
d.update({l[0]+1:0})
for i in range(n):
if l[i] not in d:
d.update({l[i]:1})
else:
d[l[i]]+=1
if l[0]+1>=l[-1]:
print(n)
print(*l,sep=" ")
else:
a=d[l[0]]
c=d[l[-1]]
b=d[l[0]+1]
b+=2*min(a,c)
r=min(a,c)
a-=min(a,c)
c-=r
ans=[0]*n
for i in range(a):
ans[i]=l[0]
for i in range(b):
ans[i+a]=l[0]+1
for i in range(c):
ans[i+a+b]=l[-1]
#print(a,b,c)
dw=min(d[l[0]],a)+min(d[l[0]+1],b)+min(d[l[-1]],c)
#print(dw)
a=d[l[0]]+(d[l[0]+1]//2)
c=d[l[-1]]+(d[l[0]+1]//2)
b=d[l[0]+1]%2
ans1=[0]*n
tre=0
for i in range(a):
ans1[tre]=l[0]
tre+=1
for i in range(b):
ans1[tre]=l[0]+1
tre+=1
for i in range(c):
ans1[tre]=l[-1]
tre+=1
#print(a,b,c)
dw1=min(d[l[0]],a)+min(d[l[0]+1],b)+min(d[l[-1]],c)
if dw<dw1:
print(dw)
print(*ans,sep=" ")
else:
print(dw1)
print(*ans1,sep=" ")
```
| 92,338 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Anya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some value n times, and then compute the average value to lower the error.
Kirill has already made his measurements, and has got the following integer values: x1, x2, ..., xn. It is important that the values are close to each other, namely, the difference between the maximum value and the minimum value is at most 2.
Anya does not want to make the measurements, however, she can't just copy the values from Kirill's work, because the error of each measurement is a random value, and this coincidence will be noted by the teacher. Anya wants to write such integer values y1, y2, ..., yn in her work, that the following conditions are met:
* the average value of x1, x2, ..., xn is equal to the average value of y1, y2, ..., yn;
* all Anya's measurements are in the same bounds as all Kirill's measurements, that is, the maximum value among Anya's values is not greater than the maximum value among Kirill's values, and the minimum value among Anya's values is not less than the minimum value among Kirill's values;
* the number of equal measurements in Anya's work and Kirill's work is as small as possible among options with the previous conditions met. Formally, the teacher goes through all Anya's values one by one, if there is equal value in Kirill's work and it is not strike off yet, he strikes off this Anya's value and one of equal values in Kirill's work. The number of equal measurements is then the total number of strike off values in Anya's work.
Help Anya to write such a set of measurements that the conditions above are met.
Input
The first line contains a single integer n (1 ≤ n ≤ 100 000) — the numeber of measurements made by Kirill.
The second line contains a sequence of integers x1, x2, ..., xn ( - 100 000 ≤ xi ≤ 100 000) — the measurements made by Kirill. It is guaranteed that the difference between the maximum and minimum values among values x1, x2, ..., xn does not exceed 2.
Output
In the first line print the minimum possible number of equal measurements.
In the second line print n integers y1, y2, ..., yn — the values Anya should write. You can print the integers in arbitrary order. Keep in mind that the minimum value among Anya's values should be not less that the minimum among Kirill's values, and the maximum among Anya's values should be not greater than the maximum among Kirill's values.
If there are multiple answers, print any of them.
Examples
Input
6
-1 1 1 0 0 -1
Output
2
0 0 0 0 0 0
Input
3
100 100 101
Output
3
101 100 100
Input
7
-10 -9 -10 -8 -10 -9 -9
Output
5
-10 -10 -9 -9 -9 -9 -9
Note
In the first example Anya can write zeros as here measurements results. The average value is then equal to the average value of Kirill's values, and there are only two equal measurements.
In the second example Anya should write two values 100 and one value 101 (in any order), because it is the only possibility to make the average be the equal to the average of Kirill's values. Thus, all three measurements are equal.
In the third example the number of equal measurements is 5.
Tags: implementation, math
Correct Solution:
```
n = int(input())
a = list(map(int, input().split()))
a.sort()
sr = sum(a) / n
x = []
min1 = min(a)
max1 = max(a)
targ = False
if min1 + 2 != max1:
print(n)
print(*a)
min1 = int(sr) - 1
max1 = int(sr) + 1
else:
sred = (min1 + max1) // 2
i = 0
k = 0
u = [0, 0, 0]
for j in a:
if j == min1:
u[0] += 1
elif j == max1:
u[1] += 1
else:
u[2] += 1
if (min(u[0], u[1]) * 2 > u[2]):
while min1 == a[k] and max1 == a[-1-k]:
x += [sred, sred]
a[k] = -200001
a[-1-k] = -200001
i += 2
k += 1
print(n - i)
for j in a:
if j != -200001:
x += [j]
print(*x)
else:
k = u[2] - u[2] % 2
while u[2] > 1:
u[2] -= 2
x += [min1, max1]
if u[2] > 0:
x += [sred]
print(n - k)
for i in range(u[0]):
x += [min1]
for i in range(u[1]):
x += [max1]
print(*x)
```
| 92,339 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Anya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some value n times, and then compute the average value to lower the error.
Kirill has already made his measurements, and has got the following integer values: x1, x2, ..., xn. It is important that the values are close to each other, namely, the difference between the maximum value and the minimum value is at most 2.
Anya does not want to make the measurements, however, she can't just copy the values from Kirill's work, because the error of each measurement is a random value, and this coincidence will be noted by the teacher. Anya wants to write such integer values y1, y2, ..., yn in her work, that the following conditions are met:
* the average value of x1, x2, ..., xn is equal to the average value of y1, y2, ..., yn;
* all Anya's measurements are in the same bounds as all Kirill's measurements, that is, the maximum value among Anya's values is not greater than the maximum value among Kirill's values, and the minimum value among Anya's values is not less than the minimum value among Kirill's values;
* the number of equal measurements in Anya's work and Kirill's work is as small as possible among options with the previous conditions met. Formally, the teacher goes through all Anya's values one by one, if there is equal value in Kirill's work and it is not strike off yet, he strikes off this Anya's value and one of equal values in Kirill's work. The number of equal measurements is then the total number of strike off values in Anya's work.
Help Anya to write such a set of measurements that the conditions above are met.
Input
The first line contains a single integer n (1 ≤ n ≤ 100 000) — the numeber of measurements made by Kirill.
The second line contains a sequence of integers x1, x2, ..., xn ( - 100 000 ≤ xi ≤ 100 000) — the measurements made by Kirill. It is guaranteed that the difference between the maximum and minimum values among values x1, x2, ..., xn does not exceed 2.
Output
In the first line print the minimum possible number of equal measurements.
In the second line print n integers y1, y2, ..., yn — the values Anya should write. You can print the integers in arbitrary order. Keep in mind that the minimum value among Anya's values should be not less that the minimum among Kirill's values, and the maximum among Anya's values should be not greater than the maximum among Kirill's values.
If there are multiple answers, print any of them.
Examples
Input
6
-1 1 1 0 0 -1
Output
2
0 0 0 0 0 0
Input
3
100 100 101
Output
3
101 100 100
Input
7
-10 -9 -10 -8 -10 -9 -9
Output
5
-10 -10 -9 -9 -9 -9 -9
Note
In the first example Anya can write zeros as here measurements results. The average value is then equal to the average value of Kirill's values, and there are only two equal measurements.
In the second example Anya should write two values 100 and one value 101 (in any order), because it is the only possibility to make the average be the equal to the average of Kirill's values. Thus, all three measurements are equal.
In the third example the number of equal measurements is 5.
Tags: implementation, math
Correct Solution:
```
n=int(input())
x=input().split()
x=[int(k) for k in x]
rem=[]
x.sort()
mn = x[0]
mx = x[-1]
if (mx-mn<=1):
print(len(x))
for k in x:
print(k, end=' ')
print()
else:
avg=mn+1
expsum = avg*len(x)
sm=0
countmn=0
countavg=0
countmx=0
for k in x:
sm+=k
if (sm-expsum)>0:
rem=x[len(x)-(sm-expsum):len(x)]
x=x[0:len(x)-(sm-expsum)]
if (sm-expsum)<0:
rem=x[0:(expsum-sm)]
x=x[(expsum-sm):len(x)]
if len(x)%2==1:
rem.append(avg)
for i in range(len(x)):
if (x[i]==avg):
x=x[0:i]+x[i+1:len(x)]
break
for k in x:
if k==mn:
countmn+=1
if k==avg:
countavg+=1
if k==mx:
countmx+=1
if countmn+countmx<countavg:
print(countmn+countmx+len(rem))
for i in range(int(len(x)/2)):
rem.append(mn)
rem.append(mx)
else:
print(countavg+len(rem))
for i in range(len(x)):
rem.append(avg)
for k in rem:
print(k, end=' ')
print()
```
| 92,340 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Anya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some value n times, and then compute the average value to lower the error.
Kirill has already made his measurements, and has got the following integer values: x1, x2, ..., xn. It is important that the values are close to each other, namely, the difference between the maximum value and the minimum value is at most 2.
Anya does not want to make the measurements, however, she can't just copy the values from Kirill's work, because the error of each measurement is a random value, and this coincidence will be noted by the teacher. Anya wants to write such integer values y1, y2, ..., yn in her work, that the following conditions are met:
* the average value of x1, x2, ..., xn is equal to the average value of y1, y2, ..., yn;
* all Anya's measurements are in the same bounds as all Kirill's measurements, that is, the maximum value among Anya's values is not greater than the maximum value among Kirill's values, and the minimum value among Anya's values is not less than the minimum value among Kirill's values;
* the number of equal measurements in Anya's work and Kirill's work is as small as possible among options with the previous conditions met. Formally, the teacher goes through all Anya's values one by one, if there is equal value in Kirill's work and it is not strike off yet, he strikes off this Anya's value and one of equal values in Kirill's work. The number of equal measurements is then the total number of strike off values in Anya's work.
Help Anya to write such a set of measurements that the conditions above are met.
Input
The first line contains a single integer n (1 ≤ n ≤ 100 000) — the numeber of measurements made by Kirill.
The second line contains a sequence of integers x1, x2, ..., xn ( - 100 000 ≤ xi ≤ 100 000) — the measurements made by Kirill. It is guaranteed that the difference between the maximum and minimum values among values x1, x2, ..., xn does not exceed 2.
Output
In the first line print the minimum possible number of equal measurements.
In the second line print n integers y1, y2, ..., yn — the values Anya should write. You can print the integers in arbitrary order. Keep in mind that the minimum value among Anya's values should be not less that the minimum among Kirill's values, and the maximum among Anya's values should be not greater than the maximum among Kirill's values.
If there are multiple answers, print any of them.
Examples
Input
6
-1 1 1 0 0 -1
Output
2
0 0 0 0 0 0
Input
3
100 100 101
Output
3
101 100 100
Input
7
-10 -9 -10 -8 -10 -9 -9
Output
5
-10 -10 -9 -9 -9 -9 -9
Note
In the first example Anya can write zeros as here measurements results. The average value is then equal to the average value of Kirill's values, and there are only two equal measurements.
In the second example Anya should write two values 100 and one value 101 (in any order), because it is the only possibility to make the average be the equal to the average of Kirill's values. Thus, all three measurements are equal.
In the third example the number of equal measurements is 5.
Tags: implementation, math
Correct Solution:
```
def main():
n = int(input())
measures = [int(x) for x in input().split()]
m = min(measures)
count = [measures.count(m + i) for i in range(3)]
if count[2] == 0:
print(n)
print(' '.join([str(x) for x in measures]))
return
pairsOfOnesToSwap = min(count[0], count[2])
pairsOfZerosToSwap = count[1]//2
print(n - max(2*pairsOfZerosToSwap, 2*pairsOfOnesToSwap))
if pairsOfOnesToSwap >= pairsOfZerosToSwap:
count = [x+y for x, y in zip(count, [-pairsOfOnesToSwap, 2*pairsOfOnesToSwap, -pairsOfOnesToSwap])]
else:
count = [x+y for x, y in zip(count, [pairsOfZerosToSwap, -2*pairsOfZerosToSwap, pairsOfZerosToSwap])]
count = [max(0, x) for x in count]
print(' '.join([str(x) for x in count[0] * [m] + count[1] * [m+1] + count[2] * [m+2]]))
if __name__ == "__main__":
main()
```
| 92,341 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Anya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some value n times, and then compute the average value to lower the error.
Kirill has already made his measurements, and has got the following integer values: x1, x2, ..., xn. It is important that the values are close to each other, namely, the difference between the maximum value and the minimum value is at most 2.
Anya does not want to make the measurements, however, she can't just copy the values from Kirill's work, because the error of each measurement is a random value, and this coincidence will be noted by the teacher. Anya wants to write such integer values y1, y2, ..., yn in her work, that the following conditions are met:
* the average value of x1, x2, ..., xn is equal to the average value of y1, y2, ..., yn;
* all Anya's measurements are in the same bounds as all Kirill's measurements, that is, the maximum value among Anya's values is not greater than the maximum value among Kirill's values, and the minimum value among Anya's values is not less than the minimum value among Kirill's values;
* the number of equal measurements in Anya's work and Kirill's work is as small as possible among options with the previous conditions met. Formally, the teacher goes through all Anya's values one by one, if there is equal value in Kirill's work and it is not strike off yet, he strikes off this Anya's value and one of equal values in Kirill's work. The number of equal measurements is then the total number of strike off values in Anya's work.
Help Anya to write such a set of measurements that the conditions above are met.
Input
The first line contains a single integer n (1 ≤ n ≤ 100 000) — the numeber of measurements made by Kirill.
The second line contains a sequence of integers x1, x2, ..., xn ( - 100 000 ≤ xi ≤ 100 000) — the measurements made by Kirill. It is guaranteed that the difference between the maximum and minimum values among values x1, x2, ..., xn does not exceed 2.
Output
In the first line print the minimum possible number of equal measurements.
In the second line print n integers y1, y2, ..., yn — the values Anya should write. You can print the integers in arbitrary order. Keep in mind that the minimum value among Anya's values should be not less that the minimum among Kirill's values, and the maximum among Anya's values should be not greater than the maximum among Kirill's values.
If there are multiple answers, print any of them.
Examples
Input
6
-1 1 1 0 0 -1
Output
2
0 0 0 0 0 0
Input
3
100 100 101
Output
3
101 100 100
Input
7
-10 -9 -10 -8 -10 -9 -9
Output
5
-10 -10 -9 -9 -9 -9 -9
Note
In the first example Anya can write zeros as here measurements results. The average value is then equal to the average value of Kirill's values, and there are only two equal measurements.
In the second example Anya should write two values 100 and one value 101 (in any order), because it is the only possibility to make the average be the equal to the average of Kirill's values. Thus, all three measurements are equal.
In the third example the number of equal measurements is 5.
Tags: implementation, math
Correct Solution:
```
n=int(input())
x=input()
a=list(map(int,x.split()))
if max(a)-min(a)<2:
print(n)
print(x)
exit()
s=set(a)
q=min(a)
s=max(a)
r=q+1
m={}
m[q]=m[s]=m[r]=0
for i in a:m[i]+=1
if n-2*min(m[q],m[s])<n-m[r]//2*2:
print(n-2*min(m[q],m[s]))
e=min(m[q],m[s])
m[r]+=e+e
m[q]-=e
m[s]-=e
else:
print(n-m[r]//2*2)
e=m[r]//2
m[r]-=e+e
m[q]+=e
m[s]+=e
b=[r for i in range(m[r])]
b=b+[q for i in range(m[q])]
b=b+[s for i in range(m[s])]
print(*b)
# Made By Mostafa_Khaled
```
| 92,342 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Anya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some value n times, and then compute the average value to lower the error.
Kirill has already made his measurements, and has got the following integer values: x1, x2, ..., xn. It is important that the values are close to each other, namely, the difference between the maximum value and the minimum value is at most 2.
Anya does not want to make the measurements, however, she can't just copy the values from Kirill's work, because the error of each measurement is a random value, and this coincidence will be noted by the teacher. Anya wants to write such integer values y1, y2, ..., yn in her work, that the following conditions are met:
* the average value of x1, x2, ..., xn is equal to the average value of y1, y2, ..., yn;
* all Anya's measurements are in the same bounds as all Kirill's measurements, that is, the maximum value among Anya's values is not greater than the maximum value among Kirill's values, and the minimum value among Anya's values is not less than the minimum value among Kirill's values;
* the number of equal measurements in Anya's work and Kirill's work is as small as possible among options with the previous conditions met. Formally, the teacher goes through all Anya's values one by one, if there is equal value in Kirill's work and it is not strike off yet, he strikes off this Anya's value and one of equal values in Kirill's work. The number of equal measurements is then the total number of strike off values in Anya's work.
Help Anya to write such a set of measurements that the conditions above are met.
Input
The first line contains a single integer n (1 ≤ n ≤ 100 000) — the numeber of measurements made by Kirill.
The second line contains a sequence of integers x1, x2, ..., xn ( - 100 000 ≤ xi ≤ 100 000) — the measurements made by Kirill. It is guaranteed that the difference between the maximum and minimum values among values x1, x2, ..., xn does not exceed 2.
Output
In the first line print the minimum possible number of equal measurements.
In the second line print n integers y1, y2, ..., yn — the values Anya should write. You can print the integers in arbitrary order. Keep in mind that the minimum value among Anya's values should be not less that the minimum among Kirill's values, and the maximum among Anya's values should be not greater than the maximum among Kirill's values.
If there are multiple answers, print any of them.
Examples
Input
6
-1 1 1 0 0 -1
Output
2
0 0 0 0 0 0
Input
3
100 100 101
Output
3
101 100 100
Input
7
-10 -9 -10 -8 -10 -9 -9
Output
5
-10 -10 -9 -9 -9 -9 -9
Note
In the first example Anya can write zeros as here measurements results. The average value is then equal to the average value of Kirill's values, and there are only two equal measurements.
In the second example Anya should write two values 100 and one value 101 (in any order), because it is the only possibility to make the average be the equal to the average of Kirill's values. Thus, all three measurements are equal.
In the third example the number of equal measurements is 5.
Tags: implementation, math
Correct Solution:
```
n = int(input())
l = list(map(int, input().split(' ')))
s = sum(l) // len(l)
mn, mx = min(l), max(l)
if mx - mn <= 1:
print(n)
for i in l:
print(i, end=' ')
else:
a, b, c = l.count(mn), l.count(mn + 1), l.count(mx)
a1, b1, c1 = a - min(a, c), b + 2 * min(a, c), c - min(a, c)
a2, b2, c2 = a + b // 2, b % 2, c + b // 2
diff1 = min(a, a1) + min(b, b1) + min(c, c1)
diff2 = min(a, a2) + min(b, b2) + min(c, c2)
if diff1 <= diff2:
print(diff1)
s = (str(mn) + ' ') * a1 + (str(mn + 1) + ' ') * b1 + (str(mx) + ' ') * c1
s = s[:-1]
print(s)
else:
print(diff2)
s = (str(mn) + ' ') * a2 + (str(mn + 1) + ' ') * b2 + (str(mx) + ' ') * c2
s = s[:-1]
print(s)
```
| 92,343 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Anya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some value n times, and then compute the average value to lower the error.
Kirill has already made his measurements, and has got the following integer values: x1, x2, ..., xn. It is important that the values are close to each other, namely, the difference between the maximum value and the minimum value is at most 2.
Anya does not want to make the measurements, however, she can't just copy the values from Kirill's work, because the error of each measurement is a random value, and this coincidence will be noted by the teacher. Anya wants to write such integer values y1, y2, ..., yn in her work, that the following conditions are met:
* the average value of x1, x2, ..., xn is equal to the average value of y1, y2, ..., yn;
* all Anya's measurements are in the same bounds as all Kirill's measurements, that is, the maximum value among Anya's values is not greater than the maximum value among Kirill's values, and the minimum value among Anya's values is not less than the minimum value among Kirill's values;
* the number of equal measurements in Anya's work and Kirill's work is as small as possible among options with the previous conditions met. Formally, the teacher goes through all Anya's values one by one, if there is equal value in Kirill's work and it is not strike off yet, he strikes off this Anya's value and one of equal values in Kirill's work. The number of equal measurements is then the total number of strike off values in Anya's work.
Help Anya to write such a set of measurements that the conditions above are met.
Input
The first line contains a single integer n (1 ≤ n ≤ 100 000) — the numeber of measurements made by Kirill.
The second line contains a sequence of integers x1, x2, ..., xn ( - 100 000 ≤ xi ≤ 100 000) — the measurements made by Kirill. It is guaranteed that the difference between the maximum and minimum values among values x1, x2, ..., xn does not exceed 2.
Output
In the first line print the minimum possible number of equal measurements.
In the second line print n integers y1, y2, ..., yn — the values Anya should write. You can print the integers in arbitrary order. Keep in mind that the minimum value among Anya's values should be not less that the minimum among Kirill's values, and the maximum among Anya's values should be not greater than the maximum among Kirill's values.
If there are multiple answers, print any of them.
Examples
Input
6
-1 1 1 0 0 -1
Output
2
0 0 0 0 0 0
Input
3
100 100 101
Output
3
101 100 100
Input
7
-10 -9 -10 -8 -10 -9 -9
Output
5
-10 -10 -9 -9 -9 -9 -9
Note
In the first example Anya can write zeros as here measurements results. The average value is then equal to the average value of Kirill's values, and there are only two equal measurements.
In the second example Anya should write two values 100 and one value 101 (in any order), because it is the only possibility to make the average be the equal to the average of Kirill's values. Thus, all three measurements are equal.
In the third example the number of equal measurements is 5.
Tags: implementation, math
Correct Solution:
```
# -*- coding: utf-8 -*-
from collections import defaultdict
def problem():
def count_collisions(lows, mids, his):
return min(xs_low, lows) + min(xs_mid, mids) + min(xs_hi, his)
in1 = int(input())
in2 = input()
# in1 = 2
# in2 = '2 0'
#
# in1 = 6
# in2 = '-1 1 1 0 0 -1'
#
# in1 = 3
# in2 = '100 100 101'
#
# in1 = 7
# in2 = '-10 -9 -10 -8 -10 -9 -9'
n = in1
xs = list(map(int, in2.split()));
d = defaultdict(int)
for x in xs:
d[x] += 1
keys = sorted(list(d.keys()))
if len(keys) == 1:
return '{0}\n{1}'.format(n, in2)
diff = keys[1] - keys[0]
if len(keys) == 2 and diff == 1:
return '{0}\n{1}'.format(n, in2)
if len(keys) == 2 and diff == 2:
keys.append(keys[0] + 1)
keys.sort()
d[keys[1]] = 0
xs_low = d[keys[0]]
xs_mid = d[keys[1]]
xs_hi = d[keys[2]]
total = -xs_low + xs_hi
if total < 0:
lows = abs(total)
mids = n - lows
his = 0
if total > 0:
lows = 0
his = total
mids = n - total
if total == 0:
lows = 0
mids = n
his = 0
min_collisions = count_collisions(lows, mids, his)
lo = lows
md = mids
hi = his
while mids >= 2:
lows = lows + 1
mids = mids - 2
his = his + 1
collisions = count_collisions(lows, mids, his)
if (collisions < min_collisions):
min_collisions = collisions
lo = lows
md = mids
hi = his
return '{0}\n{1} {2} {3}'.format(
min_collisions,
' '.join(map(str, lo * [keys[0]])),
' '.join(map(str, md * [keys[1]])),
' '.join(map(str, hi * [keys[2]])))
print(problem())
#problem()
```
| 92,344 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Anya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some value n times, and then compute the average value to lower the error.
Kirill has already made his measurements, and has got the following integer values: x1, x2, ..., xn. It is important that the values are close to each other, namely, the difference between the maximum value and the minimum value is at most 2.
Anya does not want to make the measurements, however, she can't just copy the values from Kirill's work, because the error of each measurement is a random value, and this coincidence will be noted by the teacher. Anya wants to write such integer values y1, y2, ..., yn in her work, that the following conditions are met:
* the average value of x1, x2, ..., xn is equal to the average value of y1, y2, ..., yn;
* all Anya's measurements are in the same bounds as all Kirill's measurements, that is, the maximum value among Anya's values is not greater than the maximum value among Kirill's values, and the minimum value among Anya's values is not less than the minimum value among Kirill's values;
* the number of equal measurements in Anya's work and Kirill's work is as small as possible among options with the previous conditions met. Formally, the teacher goes through all Anya's values one by one, if there is equal value in Kirill's work and it is not strike off yet, he strikes off this Anya's value and one of equal values in Kirill's work. The number of equal measurements is then the total number of strike off values in Anya's work.
Help Anya to write such a set of measurements that the conditions above are met.
Input
The first line contains a single integer n (1 ≤ n ≤ 100 000) — the numeber of measurements made by Kirill.
The second line contains a sequence of integers x1, x2, ..., xn ( - 100 000 ≤ xi ≤ 100 000) — the measurements made by Kirill. It is guaranteed that the difference between the maximum and minimum values among values x1, x2, ..., xn does not exceed 2.
Output
In the first line print the minimum possible number of equal measurements.
In the second line print n integers y1, y2, ..., yn — the values Anya should write. You can print the integers in arbitrary order. Keep in mind that the minimum value among Anya's values should be not less that the minimum among Kirill's values, and the maximum among Anya's values should be not greater than the maximum among Kirill's values.
If there are multiple answers, print any of them.
Examples
Input
6
-1 1 1 0 0 -1
Output
2
0 0 0 0 0 0
Input
3
100 100 101
Output
3
101 100 100
Input
7
-10 -9 -10 -8 -10 -9 -9
Output
5
-10 -10 -9 -9 -9 -9 -9
Note
In the first example Anya can write zeros as here measurements results. The average value is then equal to the average value of Kirill's values, and there are only two equal measurements.
In the second example Anya should write two values 100 and one value 101 (in any order), because it is the only possibility to make the average be the equal to the average of Kirill's values. Thus, all three measurements are equal.
In the third example the number of equal measurements is 5.
Submitted Solution:
```
n = int(input())
arr = list(map(int, input().split()))
mina = min(arr)
maxa = max(arr)
if maxa - mina < 2:
print(n)
print(*arr)
exit()
a, b, c = 0, 0, 0
for i in arr:
if i == mina:
a += 1
elif i == maxa:
c += 1
else:
b += 1
m = max(2 * min(a, c), b // 2 * 2)
if 2 * min(a, c) > b:
b += 2 * min(a, c)
a, c = a - min(a, c), c - min(a, c)
else:
a += b // 2
c += b // 2
b = b % 2
ans = ((str(mina) + " ") * a) + ((str(mina + 1) + " ") * b) + ((str(mina + 2) + " ") * c)
print(n - m)
print(ans[:-1])
```
Yes
| 92,345 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Anya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some value n times, and then compute the average value to lower the error.
Kirill has already made his measurements, and has got the following integer values: x1, x2, ..., xn. It is important that the values are close to each other, namely, the difference between the maximum value and the minimum value is at most 2.
Anya does not want to make the measurements, however, she can't just copy the values from Kirill's work, because the error of each measurement is a random value, and this coincidence will be noted by the teacher. Anya wants to write such integer values y1, y2, ..., yn in her work, that the following conditions are met:
* the average value of x1, x2, ..., xn is equal to the average value of y1, y2, ..., yn;
* all Anya's measurements are in the same bounds as all Kirill's measurements, that is, the maximum value among Anya's values is not greater than the maximum value among Kirill's values, and the minimum value among Anya's values is not less than the minimum value among Kirill's values;
* the number of equal measurements in Anya's work and Kirill's work is as small as possible among options with the previous conditions met. Formally, the teacher goes through all Anya's values one by one, if there is equal value in Kirill's work and it is not strike off yet, he strikes off this Anya's value and one of equal values in Kirill's work. The number of equal measurements is then the total number of strike off values in Anya's work.
Help Anya to write such a set of measurements that the conditions above are met.
Input
The first line contains a single integer n (1 ≤ n ≤ 100 000) — the numeber of measurements made by Kirill.
The second line contains a sequence of integers x1, x2, ..., xn ( - 100 000 ≤ xi ≤ 100 000) — the measurements made by Kirill. It is guaranteed that the difference between the maximum and minimum values among values x1, x2, ..., xn does not exceed 2.
Output
In the first line print the minimum possible number of equal measurements.
In the second line print n integers y1, y2, ..., yn — the values Anya should write. You can print the integers in arbitrary order. Keep in mind that the minimum value among Anya's values should be not less that the minimum among Kirill's values, and the maximum among Anya's values should be not greater than the maximum among Kirill's values.
If there are multiple answers, print any of them.
Examples
Input
6
-1 1 1 0 0 -1
Output
2
0 0 0 0 0 0
Input
3
100 100 101
Output
3
101 100 100
Input
7
-10 -9 -10 -8 -10 -9 -9
Output
5
-10 -10 -9 -9 -9 -9 -9
Note
In the first example Anya can write zeros as here measurements results. The average value is then equal to the average value of Kirill's values, and there are only two equal measurements.
In the second example Anya should write two values 100 and one value 101 (in any order), because it is the only possibility to make the average be the equal to the average of Kirill's values. Thus, all three measurements are equal.
In the third example the number of equal measurements is 5.
Submitted Solution:
```
n=int(input())
a=list(map(int,input().split()))
mm=max(a)
mmm=min(a)
if mmm!=mm-2:
print(n)
print(*a)
else:
q,w,e=0,0,0
for i in a:
if i==mm:
e+=1
elif i==mmm:
q+=1
else:
w+=1
y=w%2+q+e
p=max(q,e)-min(q,e)
u=p+w
if y<u:
print(y)
print(*([mm]*(e+w//2)+[mmm]*(q+w//2)+[mm-1]*(w%2)))
else:
print(u)
if q>e:
print(*([mmm]*p+(n-p)*[mmm+1]))
else:
print(*([mm]*p+(n-p)*[mm-1]))
```
Yes
| 92,346 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Anya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some value n times, and then compute the average value to lower the error.
Kirill has already made his measurements, and has got the following integer values: x1, x2, ..., xn. It is important that the values are close to each other, namely, the difference between the maximum value and the minimum value is at most 2.
Anya does not want to make the measurements, however, she can't just copy the values from Kirill's work, because the error of each measurement is a random value, and this coincidence will be noted by the teacher. Anya wants to write such integer values y1, y2, ..., yn in her work, that the following conditions are met:
* the average value of x1, x2, ..., xn is equal to the average value of y1, y2, ..., yn;
* all Anya's measurements are in the same bounds as all Kirill's measurements, that is, the maximum value among Anya's values is not greater than the maximum value among Kirill's values, and the minimum value among Anya's values is not less than the minimum value among Kirill's values;
* the number of equal measurements in Anya's work and Kirill's work is as small as possible among options with the previous conditions met. Formally, the teacher goes through all Anya's values one by one, if there is equal value in Kirill's work and it is not strike off yet, he strikes off this Anya's value and one of equal values in Kirill's work. The number of equal measurements is then the total number of strike off values in Anya's work.
Help Anya to write such a set of measurements that the conditions above are met.
Input
The first line contains a single integer n (1 ≤ n ≤ 100 000) — the numeber of measurements made by Kirill.
The second line contains a sequence of integers x1, x2, ..., xn ( - 100 000 ≤ xi ≤ 100 000) — the measurements made by Kirill. It is guaranteed that the difference between the maximum and minimum values among values x1, x2, ..., xn does not exceed 2.
Output
In the first line print the minimum possible number of equal measurements.
In the second line print n integers y1, y2, ..., yn — the values Anya should write. You can print the integers in arbitrary order. Keep in mind that the minimum value among Anya's values should be not less that the minimum among Kirill's values, and the maximum among Anya's values should be not greater than the maximum among Kirill's values.
If there are multiple answers, print any of them.
Examples
Input
6
-1 1 1 0 0 -1
Output
2
0 0 0 0 0 0
Input
3
100 100 101
Output
3
101 100 100
Input
7
-10 -9 -10 -8 -10 -9 -9
Output
5
-10 -10 -9 -9 -9 -9 -9
Note
In the first example Anya can write zeros as here measurements results. The average value is then equal to the average value of Kirill's values, and there are only two equal measurements.
In the second example Anya should write two values 100 and one value 101 (in any order), because it is the only possibility to make the average be the equal to the average of Kirill's values. Thus, all three measurements are equal.
In the third example the number of equal measurements is 5.
Submitted Solution:
```
n = int(input())
x = [int(y) for y in input().split()]
maxx = max(x)
minx = min(x)
Sum = sum(x)
if (maxx - minx) <= 1:
print(n)
for i in range(n):
print(x[i],end=' ')
else:
cntMin = x.count(minx)
cntMax = x.count(maxx)
ans = [n,cntMin,cntMax]
for i in range(0,n+1):
leftSum = Sum - minx*i
minSum = (n-i)*(minx+1)
maxSum = (n-i)*(maxx)
if leftSum < minSum or leftSum > maxSum:
continue
else:
cMax = leftSum-minSum
cMinAddOne = n-i-cMax
numOfCommon = min(cMax,cntMax)+min(cntMin,i)+min(n-cntMax-cntMin,cMinAddOne)
if( numOfCommon < ans[0]):
ans[0] = numOfCommon
ans[1] = i
ans[2] = cMax
print(ans[0])
print((str(minx)+' ')*ans[1]+(str(maxx)+' ')*ans[2]+(str(minx+1)+' ')*(n-ans[1]-ans[2]))
```
Yes
| 92,347 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Anya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some value n times, and then compute the average value to lower the error.
Kirill has already made his measurements, and has got the following integer values: x1, x2, ..., xn. It is important that the values are close to each other, namely, the difference between the maximum value and the minimum value is at most 2.
Anya does not want to make the measurements, however, she can't just copy the values from Kirill's work, because the error of each measurement is a random value, and this coincidence will be noted by the teacher. Anya wants to write such integer values y1, y2, ..., yn in her work, that the following conditions are met:
* the average value of x1, x2, ..., xn is equal to the average value of y1, y2, ..., yn;
* all Anya's measurements are in the same bounds as all Kirill's measurements, that is, the maximum value among Anya's values is not greater than the maximum value among Kirill's values, and the minimum value among Anya's values is not less than the minimum value among Kirill's values;
* the number of equal measurements in Anya's work and Kirill's work is as small as possible among options with the previous conditions met. Formally, the teacher goes through all Anya's values one by one, if there is equal value in Kirill's work and it is not strike off yet, he strikes off this Anya's value and one of equal values in Kirill's work. The number of equal measurements is then the total number of strike off values in Anya's work.
Help Anya to write such a set of measurements that the conditions above are met.
Input
The first line contains a single integer n (1 ≤ n ≤ 100 000) — the numeber of measurements made by Kirill.
The second line contains a sequence of integers x1, x2, ..., xn ( - 100 000 ≤ xi ≤ 100 000) — the measurements made by Kirill. It is guaranteed that the difference between the maximum and minimum values among values x1, x2, ..., xn does not exceed 2.
Output
In the first line print the minimum possible number of equal measurements.
In the second line print n integers y1, y2, ..., yn — the values Anya should write. You can print the integers in arbitrary order. Keep in mind that the minimum value among Anya's values should be not less that the minimum among Kirill's values, and the maximum among Anya's values should be not greater than the maximum among Kirill's values.
If there are multiple answers, print any of them.
Examples
Input
6
-1 1 1 0 0 -1
Output
2
0 0 0 0 0 0
Input
3
100 100 101
Output
3
101 100 100
Input
7
-10 -9 -10 -8 -10 -9 -9
Output
5
-10 -10 -9 -9 -9 -9 -9
Note
In the first example Anya can write zeros as here measurements results. The average value is then equal to the average value of Kirill's values, and there are only two equal measurements.
In the second example Anya should write two values 100 and one value 101 (in any order), because it is the only possibility to make the average be the equal to the average of Kirill's values. Thus, all three measurements are equal.
In the third example the number of equal measurements is 5.
Submitted Solution:
```
n = int(input())
a = list(map(int, input().split()))
mx = -2e9
mn = 2e9
for i in range(0, n):
mx = max(mx, a[i])
mn = min(mn, a[i])
cntmx = 0
cntmn = 0
for i in range(0, n):
if a[i] == mx:
cntmx+=1
elif a[i] == mn:
cntmn+=1
if mx-mn < 2:
print(n)
ans = ""
for i in range(0, n):
ans += str(a[i]) + " "
print(ans)
else:
cntmid = n-cntmx-cntmn
c1 = min(cntmx, cntmn)
c2 = cntmid//2
if n-c1*2 <= n-c2*2:
pmx = 0
pmn = 0
ans = ""
for i in range(0, n):
if a[i] == mx and pmx < c1:
pmx+=1
a[i]-=1
elif a[i] == mn and pmn < c1:
pmn+=1
a[i]+=1
ans += str(a[i]) + " "
print(n-c1*2)
print(ans)
else:
pmid = 0
ans = ""
for i in range(0, n):
if a[i] == mn+1 and pmid < c2:
a[i]+=1
pmid+=1
elif a[i] == mn+1 and pmid < c2*2:
a[i]-=1
pmid+=1
ans += str(a[i]) + " "
print(n-c2*2)
print(ans)
```
Yes
| 92,348 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Anya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some value n times, and then compute the average value to lower the error.
Kirill has already made his measurements, and has got the following integer values: x1, x2, ..., xn. It is important that the values are close to each other, namely, the difference between the maximum value and the minimum value is at most 2.
Anya does not want to make the measurements, however, she can't just copy the values from Kirill's work, because the error of each measurement is a random value, and this coincidence will be noted by the teacher. Anya wants to write such integer values y1, y2, ..., yn in her work, that the following conditions are met:
* the average value of x1, x2, ..., xn is equal to the average value of y1, y2, ..., yn;
* all Anya's measurements are in the same bounds as all Kirill's measurements, that is, the maximum value among Anya's values is not greater than the maximum value among Kirill's values, and the minimum value among Anya's values is not less than the minimum value among Kirill's values;
* the number of equal measurements in Anya's work and Kirill's work is as small as possible among options with the previous conditions met. Formally, the teacher goes through all Anya's values one by one, if there is equal value in Kirill's work and it is not strike off yet, he strikes off this Anya's value and one of equal values in Kirill's work. The number of equal measurements is then the total number of strike off values in Anya's work.
Help Anya to write such a set of measurements that the conditions above are met.
Input
The first line contains a single integer n (1 ≤ n ≤ 100 000) — the numeber of measurements made by Kirill.
The second line contains a sequence of integers x1, x2, ..., xn ( - 100 000 ≤ xi ≤ 100 000) — the measurements made by Kirill. It is guaranteed that the difference between the maximum and minimum values among values x1, x2, ..., xn does not exceed 2.
Output
In the first line print the minimum possible number of equal measurements.
In the second line print n integers y1, y2, ..., yn — the values Anya should write. You can print the integers in arbitrary order. Keep in mind that the minimum value among Anya's values should be not less that the minimum among Kirill's values, and the maximum among Anya's values should be not greater than the maximum among Kirill's values.
If there are multiple answers, print any of them.
Examples
Input
6
-1 1 1 0 0 -1
Output
2
0 0 0 0 0 0
Input
3
100 100 101
Output
3
101 100 100
Input
7
-10 -9 -10 -8 -10 -9 -9
Output
5
-10 -10 -9 -9 -9 -9 -9
Note
In the first example Anya can write zeros as here measurements results. The average value is then equal to the average value of Kirill's values, and there are only two equal measurements.
In the second example Anya should write two values 100 and one value 101 (in any order), because it is the only possibility to make the average be the equal to the average of Kirill's values. Thus, all three measurements are equal.
In the third example the number of equal measurements is 5.
Submitted Solution:
```
from collections import Counter
n = int(input())
a = [(k, v) for k, v in dict(Counter([int(x) for x in input().split()])).items()]
a.sort()
if len(a) > 2:
(k0, n0), (k1, n1), (k2, n2) = a
if n0 != 0 and n2 != 0:
if min(n0,n2)*2 > n1:
if n0>n2:
n0-=n2
n1+=2*n2
n2=0
else:
n2-=n0
n1+=2*n0
n0=0
else:
d = n1//2
n0 += d
n1 -= 2*d
n2 += d
n -= (abs(n0-a[0][1]) + abs(n1-a[1][1]) + abs(n2-a[2][1]))//2
a = [(k0, n0), (k1, n1), (k2, n2)]
print(n)
for k, n in a:
for i in range(n):
print(k, end=" ")
```
No
| 92,349 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Anya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some value n times, and then compute the average value to lower the error.
Kirill has already made his measurements, and has got the following integer values: x1, x2, ..., xn. It is important that the values are close to each other, namely, the difference between the maximum value and the minimum value is at most 2.
Anya does not want to make the measurements, however, she can't just copy the values from Kirill's work, because the error of each measurement is a random value, and this coincidence will be noted by the teacher. Anya wants to write such integer values y1, y2, ..., yn in her work, that the following conditions are met:
* the average value of x1, x2, ..., xn is equal to the average value of y1, y2, ..., yn;
* all Anya's measurements are in the same bounds as all Kirill's measurements, that is, the maximum value among Anya's values is not greater than the maximum value among Kirill's values, and the minimum value among Anya's values is not less than the minimum value among Kirill's values;
* the number of equal measurements in Anya's work and Kirill's work is as small as possible among options with the previous conditions met. Formally, the teacher goes through all Anya's values one by one, if there is equal value in Kirill's work and it is not strike off yet, he strikes off this Anya's value and one of equal values in Kirill's work. The number of equal measurements is then the total number of strike off values in Anya's work.
Help Anya to write such a set of measurements that the conditions above are met.
Input
The first line contains a single integer n (1 ≤ n ≤ 100 000) — the numeber of measurements made by Kirill.
The second line contains a sequence of integers x1, x2, ..., xn ( - 100 000 ≤ xi ≤ 100 000) — the measurements made by Kirill. It is guaranteed that the difference between the maximum and minimum values among values x1, x2, ..., xn does not exceed 2.
Output
In the first line print the minimum possible number of equal measurements.
In the second line print n integers y1, y2, ..., yn — the values Anya should write. You can print the integers in arbitrary order. Keep in mind that the minimum value among Anya's values should be not less that the minimum among Kirill's values, and the maximum among Anya's values should be not greater than the maximum among Kirill's values.
If there are multiple answers, print any of them.
Examples
Input
6
-1 1 1 0 0 -1
Output
2
0 0 0 0 0 0
Input
3
100 100 101
Output
3
101 100 100
Input
7
-10 -9 -10 -8 -10 -9 -9
Output
5
-10 -10 -9 -9 -9 -9 -9
Note
In the first example Anya can write zeros as here measurements results. The average value is then equal to the average value of Kirill's values, and there are only two equal measurements.
In the second example Anya should write two values 100 and one value 101 (in any order), because it is the only possibility to make the average be the equal to the average of Kirill's values. Thus, all three measurements are equal.
In the third example the number of equal measurements is 5.
Submitted Solution:
```
def func(a,b):
c={}
d={}
for i in range(len(a)):
c[a[i]]=0
for i in range(len(b)):
d[b[i]]=0
for i in range(len(a)):
c[a[i]]+=1
for i in range(len(b)):
d[b[i]]+=1
e=[]
for i in c:
for j in d:
if i==j:
e.append(min(c[i],d[j]))
return sum(e)
n=int(input())
a=list(map(int,input().split()))
if len(set(a))==1:
print(n)
print(*a)
elif len(set(a))==2:
d=min(a)
e=max(a)
if e-d==2:
b=a.count(d)
c=a.count(e)
if 2*c<=n:
g=[(d+e)//2]*(2*c)+[d]*(n-(2*c))
print(func(a,g))
print(*g)
else:
g=[e]*(2*c-n)+[(d+e)//2]*(2*n-2*c)
print(func(a,g))
print(*g)
else:
print(n)
print(*a)
else:
b=min(a)
c=a.count(b)
d=a.count(b+1)
e=a.count(b+2)
g=[b+1]*(2*min(e,c))+[b+1]*d+[b]*(c-min(e,c))+[b+2]*(e-min(e,c))
print(func(a,g))
print(*g)
```
No
| 92,350 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Anya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some value n times, and then compute the average value to lower the error.
Kirill has already made his measurements, and has got the following integer values: x1, x2, ..., xn. It is important that the values are close to each other, namely, the difference between the maximum value and the minimum value is at most 2.
Anya does not want to make the measurements, however, she can't just copy the values from Kirill's work, because the error of each measurement is a random value, and this coincidence will be noted by the teacher. Anya wants to write such integer values y1, y2, ..., yn in her work, that the following conditions are met:
* the average value of x1, x2, ..., xn is equal to the average value of y1, y2, ..., yn;
* all Anya's measurements are in the same bounds as all Kirill's measurements, that is, the maximum value among Anya's values is not greater than the maximum value among Kirill's values, and the minimum value among Anya's values is not less than the minimum value among Kirill's values;
* the number of equal measurements in Anya's work and Kirill's work is as small as possible among options with the previous conditions met. Formally, the teacher goes through all Anya's values one by one, if there is equal value in Kirill's work and it is not strike off yet, he strikes off this Anya's value and one of equal values in Kirill's work. The number of equal measurements is then the total number of strike off values in Anya's work.
Help Anya to write such a set of measurements that the conditions above are met.
Input
The first line contains a single integer n (1 ≤ n ≤ 100 000) — the numeber of measurements made by Kirill.
The second line contains a sequence of integers x1, x2, ..., xn ( - 100 000 ≤ xi ≤ 100 000) — the measurements made by Kirill. It is guaranteed that the difference between the maximum and minimum values among values x1, x2, ..., xn does not exceed 2.
Output
In the first line print the minimum possible number of equal measurements.
In the second line print n integers y1, y2, ..., yn — the values Anya should write. You can print the integers in arbitrary order. Keep in mind that the minimum value among Anya's values should be not less that the minimum among Kirill's values, and the maximum among Anya's values should be not greater than the maximum among Kirill's values.
If there are multiple answers, print any of them.
Examples
Input
6
-1 1 1 0 0 -1
Output
2
0 0 0 0 0 0
Input
3
100 100 101
Output
3
101 100 100
Input
7
-10 -9 -10 -8 -10 -9 -9
Output
5
-10 -10 -9 -9 -9 -9 -9
Note
In the first example Anya can write zeros as here measurements results. The average value is then equal to the average value of Kirill's values, and there are only two equal measurements.
In the second example Anya should write two values 100 and one value 101 (in any order), because it is the only possibility to make the average be the equal to the average of Kirill's values. Thus, all three measurements are equal.
In the third example the number of equal measurements is 5.
Submitted Solution:
```
n=int(input())
l=[int(x) for x in input().split()]
if len(set(l))<3:
print(n)
print(*l)
else:
l.sort()
f=[0]*3
s=list(set(l))
s.sort()
for i in range(3):
f[i]=l.count(s[i])
ans=f[1]+max(f[0],f[2])-min(f[0],f[2])
f[1]+=(min(f[0],f[2])*2)
f[0],f[2]=f[0]-min(f[0],f[2]),f[2]-min(f[0],f[2])
print(ans)
for i in range(3):
print((str(s[i])+" ")*f[i],end="")
```
No
| 92,351 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Anya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some value n times, and then compute the average value to lower the error.
Kirill has already made his measurements, and has got the following integer values: x1, x2, ..., xn. It is important that the values are close to each other, namely, the difference between the maximum value and the minimum value is at most 2.
Anya does not want to make the measurements, however, she can't just copy the values from Kirill's work, because the error of each measurement is a random value, and this coincidence will be noted by the teacher. Anya wants to write such integer values y1, y2, ..., yn in her work, that the following conditions are met:
* the average value of x1, x2, ..., xn is equal to the average value of y1, y2, ..., yn;
* all Anya's measurements are in the same bounds as all Kirill's measurements, that is, the maximum value among Anya's values is not greater than the maximum value among Kirill's values, and the minimum value among Anya's values is not less than the minimum value among Kirill's values;
* the number of equal measurements in Anya's work and Kirill's work is as small as possible among options with the previous conditions met. Formally, the teacher goes through all Anya's values one by one, if there is equal value in Kirill's work and it is not strike off yet, he strikes off this Anya's value and one of equal values in Kirill's work. The number of equal measurements is then the total number of strike off values in Anya's work.
Help Anya to write such a set of measurements that the conditions above are met.
Input
The first line contains a single integer n (1 ≤ n ≤ 100 000) — the numeber of measurements made by Kirill.
The second line contains a sequence of integers x1, x2, ..., xn ( - 100 000 ≤ xi ≤ 100 000) — the measurements made by Kirill. It is guaranteed that the difference between the maximum and minimum values among values x1, x2, ..., xn does not exceed 2.
Output
In the first line print the minimum possible number of equal measurements.
In the second line print n integers y1, y2, ..., yn — the values Anya should write. You can print the integers in arbitrary order. Keep in mind that the minimum value among Anya's values should be not less that the minimum among Kirill's values, and the maximum among Anya's values should be not greater than the maximum among Kirill's values.
If there are multiple answers, print any of them.
Examples
Input
6
-1 1 1 0 0 -1
Output
2
0 0 0 0 0 0
Input
3
100 100 101
Output
3
101 100 100
Input
7
-10 -9 -10 -8 -10 -9 -9
Output
5
-10 -10 -9 -9 -9 -9 -9
Note
In the first example Anya can write zeros as here measurements results. The average value is then equal to the average value of Kirill's values, and there are only two equal measurements.
In the second example Anya should write two values 100 and one value 101 (in any order), because it is the only possibility to make the average be the equal to the average of Kirill's values. Thus, all three measurements are equal.
In the third example the number of equal measurements is 5.
Submitted Solution:
```
import sys
import itertools as it
import math
n = int(sys.stdin.readline())
x = list(map(int, sys.stdin.readline().split()))
minx = min(x)
maxx = max(x)
d = dict()
for e in x:
d.setdefault(e,0)
d[e]+=1
y = sorted(x)
if len(d) == 3:
v1,v2,v3 = map(lambda e: e[0],sorted(d.items(),key=lambda e: e[0]))
k1,k2,k3 = map(lambda e: e[1],sorted(d.items(),key=lambda e: e[0]))
if min(k1,k2) < k2//2:
for i in range(0,k2//2):
y[k1+i] -= 1
y[k1+k2-i-1] += 1
else:
for i in range(min(k1,k2)):
y[i] += 1
y[-(i+1)] -= 1
print(" ".join(map(str,y)))
# y = sorted(x)
# if maxx-minx == 2:
# for k in range(len(y)//2):
# if y[k] == minx and y[-(k+1)] == maxx:
# y[k]+=1
# y[-(k+1)]-=1
# else:
# break
```
No
| 92,352 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is unrest in the Galactic Senate. Several thousand solar systems have declared their intentions to leave the Republic. Master Heidi needs to select the Jedi Knights who will go on peacekeeping missions throughout the galaxy. It is well-known that the success of any peacekeeping mission depends on the colors of the lightsabers of the Jedi who will go on that mission.
Heidi has n Jedi Knights standing in front of her, each one with a lightsaber of one of m possible colors. She knows that for the mission to be the most effective, she needs to select some contiguous interval of knights such that there are exactly k1 knights with lightsabers of the first color, k2 knights with lightsabers of the second color, ..., km knights with lightsabers of the m-th color. Help her find out if this is possible.
Input
The first line of the input contains n (1 ≤ n ≤ 100) and m (1 ≤ m ≤ n). The second line contains n integers in the range {1, 2, ..., m} representing colors of the lightsabers of the subsequent Jedi Knights. The third line contains m integers k1, k2, ..., km (with <image>) – the desired counts of lightsabers of each color from 1 to m.
Output
Output YES if an interval with prescribed color counts exists, or output NO if there is none.
Example
Input
5 2
1 1 2 2 1
1 2
Output
YES
Tags: implementation
Correct Solution:
```
INF = 1 << 60
n, m = map(int, input().split())
a = list(map(int, input().split()))
Constraint = [0] + list(map(int, input().split()))
pos = 0
satisfied_color = 0
for i in range(1,m + 1):
if Constraint[i] == 0:
satisfied_color += 1
GETCOLOR = [0]*(n + 1)
ans = INF
waste = 0
for i in range(n):
while satisfied_color < m and pos < n:
now_color = a[pos]
GETCOLOR[now_color] += 1
if GETCOLOR[now_color] == Constraint[now_color]:
satisfied_color += 1
elif GETCOLOR[now_color] > Constraint[now_color]:
waste += 1
pos += 1
if satisfied_color == m:
ans = min(ans, waste)
removed_color = a[i]
if GETCOLOR[removed_color] > Constraint[removed_color]:
GETCOLOR[removed_color] -= 1
waste -= 1
continue
elif GETCOLOR[removed_color] == Constraint[removed_color]:
GETCOLOR[removed_color] -= 1
satisfied_color -= 1
if ans < INF:
print(ans)
else:
print(-1)
```
| 92,353 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is unrest in the Galactic Senate. Several thousand solar systems have declared their intentions to leave the Republic. Master Heidi needs to select the Jedi Knights who will go on peacekeeping missions throughout the galaxy. It is well-known that the success of any peacekeeping mission depends on the colors of the lightsabers of the Jedi who will go on that mission.
Heidi has n Jedi Knights standing in front of her, each one with a lightsaber of one of m possible colors. She knows that for the mission to be the most effective, she needs to select some contiguous interval of knights such that there are exactly k1 knights with lightsabers of the first color, k2 knights with lightsabers of the second color, ..., km knights with lightsabers of the m-th color. Help her find out if this is possible.
Input
The first line of the input contains n (1 ≤ n ≤ 100) and m (1 ≤ m ≤ n). The second line contains n integers in the range {1, 2, ..., m} representing colors of the lightsabers of the subsequent Jedi Knights. The third line contains m integers k1, k2, ..., km (with <image>) – the desired counts of lightsabers of each color from 1 to m.
Output
Output YES if an interval with prescribed color counts exists, or output NO if there is none.
Example
Input
5 2
1 1 2 2 1
1 2
Output
YES
Tags: implementation
Correct Solution:
```
n, m = map(int, input().split())
c = list(map(int, input().split()))
k = list(map(int, input().split()))
p = [0] * m
c = [o - 1 for o in c]
s = sum(k)
ok = k.count(0)
i1 = 0
i2 = 0
while i2 < n and ok < m:
p[c[i2]] += 1
if p[c[i2]] == k[c[i2]]:
ok += 1
i2 += 1
if ok != m:
print(-1)
exit(0)
ans = i2 - i1
while i1 < n:
p[c[i1]] -= 1
while i2 < n and p[c[i1]] < k[c[i1]]:
p[c[i2]] += 1
i2 += 1
if p[c[i1]] >= k[c[i1]]:
ans = min(ans, i2 - i1 - 1)
elif i2 == n:
break
i1 += 1
print(ans - s)
```
| 92,354 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is unrest in the Galactic Senate. Several thousand solar systems have declared their intentions to leave the Republic. Master Heidi needs to select the Jedi Knights who will go on peacekeeping missions throughout the galaxy. It is well-known that the success of any peacekeeping mission depends on the colors of the lightsabers of the Jedi who will go on that mission.
Heidi has n Jedi Knights standing in front of her, each one with a lightsaber of one of m possible colors. She knows that for the mission to be the most effective, she needs to select some contiguous interval of knights such that there are exactly k1 knights with lightsabers of the first color, k2 knights with lightsabers of the second color, ..., km knights with lightsabers of the m-th color. Help her find out if this is possible.
Input
The first line of the input contains n (1 ≤ n ≤ 100) and m (1 ≤ m ≤ n). The second line contains n integers in the range {1, 2, ..., m} representing colors of the lightsabers of the subsequent Jedi Knights. The third line contains m integers k1, k2, ..., km (with <image>) – the desired counts of lightsabers of each color from 1 to m.
Output
Output YES if an interval with prescribed color counts exists, or output NO if there is none.
Example
Input
5 2
1 1 2 2 1
1 2
Output
YES
Tags: implementation
Correct Solution:
```
n,m=map(int,input().split())
a=list(map(int,input().split()))
t=list(map(int,input().split()))
x=sum(t)
for i in range(n-x+1):
freq=[0]*m
for j in range(i,i+x):
freq[a[j]-1]+=1
flag=True
for j in range(m):
if freq[j]!=t[j]:
flag=False
break
if flag:
break
if flag:
print("YES")
else:
print("NO")
```
| 92,355 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is unrest in the Galactic Senate. Several thousand solar systems have declared their intentions to leave the Republic. Master Heidi needs to select the Jedi Knights who will go on peacekeeping missions throughout the galaxy. It is well-known that the success of any peacekeeping mission depends on the colors of the lightsabers of the Jedi who will go on that mission.
Heidi has n Jedi Knights standing in front of her, each one with a lightsaber of one of m possible colors. She knows that for the mission to be the most effective, she needs to select some contiguous interval of knights such that there are exactly k1 knights with lightsabers of the first color, k2 knights with lightsabers of the second color, ..., km knights with lightsabers of the m-th color. Help her find out if this is possible.
Input
The first line of the input contains n (1 ≤ n ≤ 100) and m (1 ≤ m ≤ n). The second line contains n integers in the range {1, 2, ..., m} representing colors of the lightsabers of the subsequent Jedi Knights. The third line contains m integers k1, k2, ..., km (with <image>) – the desired counts of lightsabers of each color from 1 to m.
Output
Output YES if an interval with prescribed color counts exists, or output NO if there is none.
Example
Input
5 2
1 1 2 2 1
1 2
Output
YES
Tags: implementation
Correct Solution:
```
import sys
n, m = [int(x) for x in input().split(' ')]
arr = [int(x)-1 for x in input().split(' ')]
k = [int(x) for x in input().split(' ')]
summ = 0
for i in range(m):
summ += k[i]
for i in range(n):
if i >= summ:
k[arr[i-summ]] += 1
k[arr[i]] -= 1
done = True
for j in range(m):
if k[j] != 0:
done = False
if done:
print('YES')
sys.exit()
print('NO')
```
| 92,356 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is unrest in the Galactic Senate. Several thousand solar systems have declared their intentions to leave the Republic. Master Heidi needs to select the Jedi Knights who will go on peacekeeping missions throughout the galaxy. It is well-known that the success of any peacekeeping mission depends on the colors of the lightsabers of the Jedi who will go on that mission.
Heidi has n Jedi Knights standing in front of her, each one with a lightsaber of one of m possible colors. She knows that for the mission to be the most effective, she needs to select some contiguous interval of knights such that there are exactly k1 knights with lightsabers of the first color, k2 knights with lightsabers of the second color, ..., km knights with lightsabers of the m-th color. Help her find out if this is possible.
Input
The first line of the input contains n (1 ≤ n ≤ 100) and m (1 ≤ m ≤ n). The second line contains n integers in the range {1, 2, ..., m} representing colors of the lightsabers of the subsequent Jedi Knights. The third line contains m integers k1, k2, ..., km (with <image>) – the desired counts of lightsabers of each color from 1 to m.
Output
Output YES if an interval with prescribed color counts exists, or output NO if there is none.
Example
Input
5 2
1 1 2 2 1
1 2
Output
YES
Tags: implementation
Correct Solution:
```
n, m = map(int, input().split())
c = list(map(int, input().split()))
k = list(map(int, input().split()))
p = [0] * m
c = [i -1 for i in c]
s = sum(k)
cnt = k.count(0)
l = 0
r = 0
while r < n and cnt < m:
p[c[r]] += 1
if p[c[r]] == k[c[r]]:
cnt += 1
r += 1
if cnt != m:
print(-1)
exit(0)
ans = r-l
while l < n:
p[c[l]] -= 1
while r < n and p[c[l]] < k[c[l]]:
p[c[r]] += 1
r += 1
if p[c[l]] >= k[c[l]]:
ans = min(ans, r-l-1)
elif r == n:
break
l += 1
print(ans-s)
```
| 92,357 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is unrest in the Galactic Senate. Several thousand solar systems have declared their intentions to leave the Republic. Master Heidi needs to select the Jedi Knights who will go on peacekeeping missions throughout the galaxy. It is well-known that the success of any peacekeeping mission depends on the colors of the lightsabers of the Jedi who will go on that mission.
Heidi has n Jedi Knights standing in front of her, each one with a lightsaber of one of m possible colors. She knows that for the mission to be the most effective, she needs to select some contiguous interval of knights such that there are exactly k1 knights with lightsabers of the first color, k2 knights with lightsabers of the second color, ..., km knights with lightsabers of the m-th color. Help her find out if this is possible.
Input
The first line of the input contains n (1 ≤ n ≤ 100) and m (1 ≤ m ≤ n). The second line contains n integers in the range {1, 2, ..., m} representing colors of the lightsabers of the subsequent Jedi Knights. The third line contains m integers k1, k2, ..., km (with <image>) – the desired counts of lightsabers of each color from 1 to m.
Output
Output YES if an interval with prescribed color counts exists, or output NO if there is none.
Example
Input
5 2
1 1 2 2 1
1 2
Output
YES
Tags: implementation
Correct Solution:
```
s = input().split()
n, m = int(s[0]), int(s[1])
cl = list(map(int, input().split()))
com = list(map(int, input().split()))
res = False
for i in range(n):
for j in range(i, n):
e = True
t = cl[i:j+1]
for k in range(1, m+1):
e = t.count(k)==com[k-1] and e
if e:
res = True
break
if res: print('YES')
else: print('NO')
```
| 92,358 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is unrest in the Galactic Senate. Several thousand solar systems have declared their intentions to leave the Republic. Master Heidi needs to select the Jedi Knights who will go on peacekeeping missions throughout the galaxy. It is well-known that the success of any peacekeeping mission depends on the colors of the lightsabers of the Jedi who will go on that mission.
Heidi has n Jedi Knights standing in front of her, each one with a lightsaber of one of m possible colors. She knows that for the mission to be the most effective, she needs to select some contiguous interval of knights such that there are exactly k1 knights with lightsabers of the first color, k2 knights with lightsabers of the second color, ..., km knights with lightsabers of the m-th color. Help her find out if this is possible.
Input
The first line of the input contains n (1 ≤ n ≤ 100) and m (1 ≤ m ≤ n). The second line contains n integers in the range {1, 2, ..., m} representing colors of the lightsabers of the subsequent Jedi Knights. The third line contains m integers k1, k2, ..., km (with <image>) – the desired counts of lightsabers of each color from 1 to m.
Output
Output YES if an interval with prescribed color counts exists, or output NO if there is none.
Example
Input
5 2
1 1 2 2 1
1 2
Output
YES
Tags: implementation
Correct Solution:
```
from collections import defaultdict, deque, Counter
from sys import stdin, stdout
from heapq import heappush, heappop
import math
import io
import os
import math
import bisect
#?############################################################
def isPrime(x):
for i in range(2, x):
if i*i > x:
break
if (x % i == 0):
return False
return True
#?############################################################
def ncr(n, r, p):
num = den = 1
for i in range(r):
num = (num * (n - i)) % p
den = (den * (i + 1)) % p
return (num * pow(den, p - 2, p)) % p
#?############################################################
def primeFactors(n):
l = []
while n % 2 == 0:
l.append(2)
n = n / 2
for i in range(3, int(math.sqrt(n))+1, 2):
while n % i == 0:
l.append(int(i))
n = n / i
if n > 2:
l.append(n)
return list(set(l))
#?############################################################
def power(x, y, p):
res = 1
x = x % p
if (x == 0):
return 0
while (y > 0):
if ((y & 1) == 1):
res = (res * x) % p
y = y >> 1
x = (x * x) % p
return res
#?############################################################
def sieve(n):
prime = [True for i in range(n+1)]
p = 2
while (p * p <= n):
if (prime[p] == True):
for i in range(p * p, n+1, p):
prime[i] = False
p += 1
return prime
#?############################################################
def digits(n):
a = 0
while (n > 0):
n //= 10
a += 1
return a
#?############################################################
def ceil(n, x):
if (n % x == 0):
return n//x
return n//x+1
#?############################################################
def mapin():
return map(int, input().split())
#?############################################################
def solve():
n, m = mapin()
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
s = sum(b)
for i in range(n-s+1):
cc = [0] * m
for j in range(i, i+s):
cc[a[j]-1]+=1
if cc == b:
return 1
return 0
# input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
# python3 15.py<in>op
aa = solve()
if(aa):
print("YES")
else:
print("NO")
```
| 92,359 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is unrest in the Galactic Senate. Several thousand solar systems have declared their intentions to leave the Republic. Master Heidi needs to select the Jedi Knights who will go on peacekeeping missions throughout the galaxy. It is well-known that the success of any peacekeeping mission depends on the colors of the lightsabers of the Jedi who will go on that mission.
Heidi has n Jedi Knights standing in front of her, each one with a lightsaber of one of m possible colors. She knows that for the mission to be the most effective, she needs to select some contiguous interval of knights such that there are exactly k1 knights with lightsabers of the first color, k2 knights with lightsabers of the second color, ..., km knights with lightsabers of the m-th color. Help her find out if this is possible.
Input
The first line of the input contains n (1 ≤ n ≤ 100) and m (1 ≤ m ≤ n). The second line contains n integers in the range {1, 2, ..., m} representing colors of the lightsabers of the subsequent Jedi Knights. The third line contains m integers k1, k2, ..., km (with <image>) – the desired counts of lightsabers of each color from 1 to m.
Output
Output YES if an interval with prescribed color counts exists, or output NO if there is none.
Example
Input
5 2
1 1 2 2 1
1 2
Output
YES
Tags: implementation
Correct Solution:
```
n,m=list(map(int,input().split()))
arr=list(map(int,input().split()))
marr=list(map(int,input().split()))
f=[0]*(m+1)
cnt,i=0,0
valid=sum(marr) #m
while(i<n):
f[arr[i]]+=1
if f[arr[i]]<=marr[arr[i]-1]:
cnt+=1
if cnt==valid:
break
i+=1
if i==n:
print(-1)
else:
ans=(i+1)-valid
s,e=0,i
while(e<n):
while(f[arr[s]]>marr[arr[s]-1]):
f[arr[s]]-=1
s+=1
ans=min((e-s+1)-valid,ans)
e+=1
if e<n:
f[arr[e]]+=1
print(ans)
```
| 92,360 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is unrest in the Galactic Senate. Several thousand solar systems have declared their intentions to leave the Republic. Master Heidi needs to select the Jedi Knights who will go on peacekeeping missions throughout the galaxy. It is well-known that the success of any peacekeeping mission depends on the colors of the lightsabers of the Jedi who will go on that mission.
Heidi has n Jedi Knights standing in front of her, each one with a lightsaber of one of m possible colors. She knows that for the mission to be the most effective, she needs to select some contiguous interval of knights such that there are exactly k1 knights with lightsabers of the first color, k2 knights with lightsabers of the second color, ..., km knights with lightsabers of the m-th color. Help her find out if this is possible.
Input
The first line of the input contains n (1 ≤ n ≤ 100) and m (1 ≤ m ≤ n). The second line contains n integers in the range {1, 2, ..., m} representing colors of the lightsabers of the subsequent Jedi Knights. The third line contains m integers k1, k2, ..., km (with <image>) – the desired counts of lightsabers of each color from 1 to m.
Output
Output YES if an interval with prescribed color counts exists, or output NO if there is none.
Example
Input
5 2
1 1 2 2 1
1 2
Output
YES
Submitted Solution:
```
#Code by Sounak, IIESTS
#------------------------------warmup----------------------------
import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
#-------------------game starts now-----------------------------------------------------
mod=998244353
n,m= map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
pre=[[0 for i in range (m)]for j in range (n+1)]
for i in range (n):
for j in range (m):
pre[i+1][j]=pre[i][j]
if j+1==a[i]:
pre[i+1][j]+=1
s=sum(b)
ch=0
for i in range (s,n+1):
curr=0
for j in range (m):
if pre[i][j]-pre[i-s][j]==b[j]:
curr+=1
if curr==m:
ch=1
#print(i)
break
if ch:
print("YES")
else:
print("NO")
```
Yes
| 92,361 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is unrest in the Galactic Senate. Several thousand solar systems have declared their intentions to leave the Republic. Master Heidi needs to select the Jedi Knights who will go on peacekeeping missions throughout the galaxy. It is well-known that the success of any peacekeeping mission depends on the colors of the lightsabers of the Jedi who will go on that mission.
Heidi has n Jedi Knights standing in front of her, each one with a lightsaber of one of m possible colors. She knows that for the mission to be the most effective, she needs to select some contiguous interval of knights such that there are exactly k1 knights with lightsabers of the first color, k2 knights with lightsabers of the second color, ..., km knights with lightsabers of the m-th color. Help her find out if this is possible.
Input
The first line of the input contains n (1 ≤ n ≤ 100) and m (1 ≤ m ≤ n). The second line contains n integers in the range {1, 2, ..., m} representing colors of the lightsabers of the subsequent Jedi Knights. The third line contains m integers k1, k2, ..., km (with <image>) – the desired counts of lightsabers of each color from 1 to m.
Output
Output YES if an interval with prescribed color counts exists, or output NO if there is none.
Example
Input
5 2
1 1 2 2 1
1 2
Output
YES
Submitted Solution:
```
n, m = map(int, input().split())
c = list(map(int, input().split()))
k = list(map(int, input().split()))
s = sum(k)
for i in range(n - s + 1):
v = [0] * m
for j in range(i, i + s):
v[c[j] - 1] += 1
if v == k:
print('YES')
exit(0)
print('NO')
```
Yes
| 92,362 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is unrest in the Galactic Senate. Several thousand solar systems have declared their intentions to leave the Republic. Master Heidi needs to select the Jedi Knights who will go on peacekeeping missions throughout the galaxy. It is well-known that the success of any peacekeeping mission depends on the colors of the lightsabers of the Jedi who will go on that mission.
Heidi has n Jedi Knights standing in front of her, each one with a lightsaber of one of m possible colors. She knows that for the mission to be the most effective, she needs to select some contiguous interval of knights such that there are exactly k1 knights with lightsabers of the first color, k2 knights with lightsabers of the second color, ..., km knights with lightsabers of the m-th color. Help her find out if this is possible.
Input
The first line of the input contains n (1 ≤ n ≤ 100) and m (1 ≤ m ≤ n). The second line contains n integers in the range {1, 2, ..., m} representing colors of the lightsabers of the subsequent Jedi Knights. The third line contains m integers k1, k2, ..., km (with <image>) – the desired counts of lightsabers of each color from 1 to m.
Output
Output YES if an interval with prescribed color counts exists, or output NO if there is none.
Example
Input
5 2
1 1 2 2 1
1 2
Output
YES
Submitted Solution:
```
n, m = map(int,input().split())
a = list(map(int,input().split()))
z = list(map(int,input().split()))
ch = 0
if n == sum(z):
t = 0
for i in a:
z[i-1] -= 1
if z.count(0) == m:
print('YES')
else:
print('NO')
else:
for i in range(n-sum(z)+1):
t = 0
for j in range(1,m+1):
if a[i:i+sum(z)].count(j) == z[j-1]:
t+=1
if t == m:
print('YES')
ch = 1
break
if ch == 0:
print('NO')
```
Yes
| 92,363 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is unrest in the Galactic Senate. Several thousand solar systems have declared their intentions to leave the Republic. Master Heidi needs to select the Jedi Knights who will go on peacekeeping missions throughout the galaxy. It is well-known that the success of any peacekeeping mission depends on the colors of the lightsabers of the Jedi who will go on that mission.
Heidi has n Jedi Knights standing in front of her, each one with a lightsaber of one of m possible colors. She knows that for the mission to be the most effective, she needs to select some contiguous interval of knights such that there are exactly k1 knights with lightsabers of the first color, k2 knights with lightsabers of the second color, ..., km knights with lightsabers of the m-th color. Help her find out if this is possible.
Input
The first line of the input contains n (1 ≤ n ≤ 100) and m (1 ≤ m ≤ n). The second line contains n integers in the range {1, 2, ..., m} representing colors of the lightsabers of the subsequent Jedi Knights. The third line contains m integers k1, k2, ..., km (with <image>) – the desired counts of lightsabers of each color from 1 to m.
Output
Output YES if an interval with prescribed color counts exists, or output NO if there is none.
Example
Input
5 2
1 1 2 2 1
1 2
Output
YES
Submitted Solution:
```
n,m=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=sum(b)
d=[0]*m
for i in range(c):
d[a[i]-1]+=1
e=0
for i in range(n-c+1):
if i!=0:
d[a[i-1]-1]-=1
d[a[i+c-1]-1]+=1
if d==b:
e=1
break
if e==0:
print("NO")
else:
print("YES")
```
Yes
| 92,364 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is unrest in the Galactic Senate. Several thousand solar systems have declared their intentions to leave the Republic. Master Heidi needs to select the Jedi Knights who will go on peacekeeping missions throughout the galaxy. It is well-known that the success of any peacekeeping mission depends on the colors of the lightsabers of the Jedi who will go on that mission.
Heidi has n Jedi Knights standing in front of her, each one with a lightsaber of one of m possible colors. She knows that for the mission to be the most effective, she needs to select some contiguous interval of knights such that there are exactly k1 knights with lightsabers of the first color, k2 knights with lightsabers of the second color, ..., km knights with lightsabers of the m-th color. Help her find out if this is possible.
Input
The first line of the input contains n (1 ≤ n ≤ 100) and m (1 ≤ m ≤ n). The second line contains n integers in the range {1, 2, ..., m} representing colors of the lightsabers of the subsequent Jedi Knights. The third line contains m integers k1, k2, ..., km (with <image>) – the desired counts of lightsabers of each color from 1 to m.
Output
Output YES if an interval with prescribed color counts exists, or output NO if there is none.
Example
Input
5 2
1 1 2 2 1
1 2
Output
YES
Submitted Solution:
```
from collections import Counter
def check():
for i in range(n):
for j in range(i + 1, n + 1):
if target == Counter(ns[i:j]):
return True
return False
n, m = map(int, input().split())
ns = list(map(int, input().split()))
ms = list(map(int, input().split()))
target = Counter({k: v for k, v in enumerate(ms, 1)})
print(['NO', 'YES'][check()])
```
No
| 92,365 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is unrest in the Galactic Senate. Several thousand solar systems have declared their intentions to leave the Republic. Master Heidi needs to select the Jedi Knights who will go on peacekeeping missions throughout the galaxy. It is well-known that the success of any peacekeeping mission depends on the colors of the lightsabers of the Jedi who will go on that mission.
Heidi has n Jedi Knights standing in front of her, each one with a lightsaber of one of m possible colors. She knows that for the mission to be the most effective, she needs to select some contiguous interval of knights such that there are exactly k1 knights with lightsabers of the first color, k2 knights with lightsabers of the second color, ..., km knights with lightsabers of the m-th color. Help her find out if this is possible.
Input
The first line of the input contains n (1 ≤ n ≤ 100) and m (1 ≤ m ≤ n). The second line contains n integers in the range {1, 2, ..., m} representing colors of the lightsabers of the subsequent Jedi Knights. The third line contains m integers k1, k2, ..., km (with <image>) – the desired counts of lightsabers of each color from 1 to m.
Output
Output YES if an interval with prescribed color counts exists, or output NO if there is none.
Example
Input
5 2
1 1 2 2 1
1 2
Output
YES
Submitted Solution:
```
from collections import Counter
n, m = map(int, input().split())
c = list(map(int, input().split()))
k = list(map(int, input().split()))
s = sum(k)
C_orig = {i + 1: k[i] for i in range(m)}
C = Counter(c[:s])
if C == C_orig:
print('YES')
exit()
for i in range(n - s):
C[c[i]] -= 1
C[c[i + s]] += 1
if C == C_orig:
print('YES')
exit()
print('NO')
```
No
| 92,366 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is unrest in the Galactic Senate. Several thousand solar systems have declared their intentions to leave the Republic. Master Heidi needs to select the Jedi Knights who will go on peacekeeping missions throughout the galaxy. It is well-known that the success of any peacekeeping mission depends on the colors of the lightsabers of the Jedi who will go on that mission.
Heidi has n Jedi Knights standing in front of her, each one with a lightsaber of one of m possible colors. She knows that for the mission to be the most effective, she needs to select some contiguous interval of knights such that there are exactly k1 knights with lightsabers of the first color, k2 knights with lightsabers of the second color, ..., km knights with lightsabers of the m-th color. Help her find out if this is possible.
Input
The first line of the input contains n (1 ≤ n ≤ 100) and m (1 ≤ m ≤ n). The second line contains n integers in the range {1, 2, ..., m} representing colors of the lightsabers of the subsequent Jedi Knights. The third line contains m integers k1, k2, ..., km (with <image>) – the desired counts of lightsabers of each color from 1 to m.
Output
Output YES if an interval with prescribed color counts exists, or output NO if there is none.
Example
Input
5 2
1 1 2 2 1
1 2
Output
YES
Submitted Solution:
```
in1 = input().split()
n = int(in1[0])
m = int(in1[1])
listN = input().split()
listM = input().split()
index = 0
for x in listM:
index+=1
if listN.count(str(index)) < int(x) :
print('NO')
exit()
print('YES')
```
No
| 92,367 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is unrest in the Galactic Senate. Several thousand solar systems have declared their intentions to leave the Republic. Master Heidi needs to select the Jedi Knights who will go on peacekeeping missions throughout the galaxy. It is well-known that the success of any peacekeeping mission depends on the colors of the lightsabers of the Jedi who will go on that mission.
Heidi has n Jedi Knights standing in front of her, each one with a lightsaber of one of m possible colors. She knows that for the mission to be the most effective, she needs to select some contiguous interval of knights such that there are exactly k1 knights with lightsabers of the first color, k2 knights with lightsabers of the second color, ..., km knights with lightsabers of the m-th color. Help her find out if this is possible.
Input
The first line of the input contains n (1 ≤ n ≤ 100) and m (1 ≤ m ≤ n). The second line contains n integers in the range {1, 2, ..., m} representing colors of the lightsabers of the subsequent Jedi Knights. The third line contains m integers k1, k2, ..., km (with <image>) – the desired counts of lightsabers of each color from 1 to m.
Output
Output YES if an interval with prescribed color counts exists, or output NO if there is none.
Example
Input
5 2
1 1 2 2 1
1 2
Output
YES
Submitted Solution:
```
n,m=[int(x) for x in input().split()]
ns=[int(x) for x in input().split()]
ms=[int(x) for x in input().split()]
m_num=[0]*(m+1)
for i in ns:
m_num[i-1]+=1
can=True
for i in range(m):
if m_num[i]<ms[i]:
can=False
print('NO')
break
if can:
print('YES')
```
No
| 92,368 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have m = n·k wooden staves. The i-th stave has length ai. You have to assemble n barrels consisting of k staves each, you can use any k staves to construct a barrel. Each stave must belong to exactly one barrel.
Let volume vj of barrel j be equal to the length of the minimal stave in it.
<image>
You want to assemble exactly n barrels with the maximal total sum of volumes. But you have to make them equal enough, so a difference between volumes of any pair of the resulting barrels must not exceed l, i.e. |vx - vy| ≤ l for any 1 ≤ x ≤ n and 1 ≤ y ≤ n.
Print maximal total sum of volumes of equal enough barrels or 0 if it's impossible to satisfy the condition above.
Input
The first line contains three space-separated integers n, k and l (1 ≤ n, k ≤ 105, 1 ≤ n·k ≤ 105, 0 ≤ l ≤ 109).
The second line contains m = n·k space-separated integers a1, a2, ..., am (1 ≤ ai ≤ 109) — lengths of staves.
Output
Print single integer — maximal total sum of the volumes of barrels or 0 if it's impossible to construct exactly n barrels satisfying the condition |vx - vy| ≤ l for any 1 ≤ x ≤ n and 1 ≤ y ≤ n.
Examples
Input
4 2 1
2 2 1 2 3 2 2 3
Output
7
Input
2 1 0
10 10
Output
20
Input
1 2 1
5 2
Output
2
Input
3 2 1
1 2 3 4 5 6
Output
0
Note
In the first example you can form the following barrels: [1, 2], [2, 2], [2, 3], [2, 3].
In the second example you can form the following barrels: [10], [10].
In the third example you can form the following barrels: [2, 5].
In the fourth example difference between volumes of barrels in any partition is at least 2 so it is impossible to make barrels equal enough.
Tags: greedy
Correct Solution:
```
""" 616C """
""" 1152B """
import math
# import sys
def main():
# n ,m= map(int,input().split())
# arr = list(map(int,input().split()))
# b = list(map(int,input().split()))
# n = int(input())
# string = str(input())
n ,k,l = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
index = -1
for i in range((n*k)-1,-1,-1):
if((a[i]-a[0])<=l):
index = i
break
if((index+1)<n):
print(0)
return
extra = (index+1)-n
start = 0
ans = 0
cnt = 0
while cnt<n:
ans += a[start]
start += min(extra,k-1)+1
extra -= min(extra,k-1)
cnt+=1
if extra<0:
extra = 0
print(ans)
return
main()
# def test():
# t = int(input())
# while t:
# main()
# t-=1
# test()
```
| 92,369 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have m = n·k wooden staves. The i-th stave has length ai. You have to assemble n barrels consisting of k staves each, you can use any k staves to construct a barrel. Each stave must belong to exactly one barrel.
Let volume vj of barrel j be equal to the length of the minimal stave in it.
<image>
You want to assemble exactly n barrels with the maximal total sum of volumes. But you have to make them equal enough, so a difference between volumes of any pair of the resulting barrels must not exceed l, i.e. |vx - vy| ≤ l for any 1 ≤ x ≤ n and 1 ≤ y ≤ n.
Print maximal total sum of volumes of equal enough barrels or 0 if it's impossible to satisfy the condition above.
Input
The first line contains three space-separated integers n, k and l (1 ≤ n, k ≤ 105, 1 ≤ n·k ≤ 105, 0 ≤ l ≤ 109).
The second line contains m = n·k space-separated integers a1, a2, ..., am (1 ≤ ai ≤ 109) — lengths of staves.
Output
Print single integer — maximal total sum of the volumes of barrels or 0 if it's impossible to construct exactly n barrels satisfying the condition |vx - vy| ≤ l for any 1 ≤ x ≤ n and 1 ≤ y ≤ n.
Examples
Input
4 2 1
2 2 1 2 3 2 2 3
Output
7
Input
2 1 0
10 10
Output
20
Input
1 2 1
5 2
Output
2
Input
3 2 1
1 2 3 4 5 6
Output
0
Note
In the first example you can form the following barrels: [1, 2], [2, 2], [2, 3], [2, 3].
In the second example you can form the following barrels: [10], [10].
In the third example you can form the following barrels: [2, 5].
In the fourth example difference between volumes of barrels in any partition is at least 2 so it is impossible to make barrels equal enough.
Tags: greedy
Correct Solution:
```
s = [int(x) for x in input().split()]
n, k, ll = s[0], s[1], s[2]
s = [int(x) for x in input().split()]
s.sort()
if s[n - 1] - s[0] > ll:
print(0)
else:
x = 0
while x < n * k and s[x] <= ll + s[0]:
x += 1
if x > k * (n - 1):
q = 0
for i in range(n):
q += s[i * k]
print(q)
else:
add = []
left = x - n
while left > 0:
if left >= k - 1:
add.append(k - 1)
left -= k - 1
else:
add.append(left)
left = 0
add += [0 for _ in range(n)]
diff = [add[i] + 1 for i in range(n - 1)]
# print(diff)
q = s[0]
p = 0
for i in range(n - 1):
p += diff[i]
q += s[p]
print(q)
```
| 92,370 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have m = n·k wooden staves. The i-th stave has length ai. You have to assemble n barrels consisting of k staves each, you can use any k staves to construct a barrel. Each stave must belong to exactly one barrel.
Let volume vj of barrel j be equal to the length of the minimal stave in it.
<image>
You want to assemble exactly n barrels with the maximal total sum of volumes. But you have to make them equal enough, so a difference between volumes of any pair of the resulting barrels must not exceed l, i.e. |vx - vy| ≤ l for any 1 ≤ x ≤ n and 1 ≤ y ≤ n.
Print maximal total sum of volumes of equal enough barrels or 0 if it's impossible to satisfy the condition above.
Input
The first line contains three space-separated integers n, k and l (1 ≤ n, k ≤ 105, 1 ≤ n·k ≤ 105, 0 ≤ l ≤ 109).
The second line contains m = n·k space-separated integers a1, a2, ..., am (1 ≤ ai ≤ 109) — lengths of staves.
Output
Print single integer — maximal total sum of the volumes of barrels or 0 if it's impossible to construct exactly n barrels satisfying the condition |vx - vy| ≤ l for any 1 ≤ x ≤ n and 1 ≤ y ≤ n.
Examples
Input
4 2 1
2 2 1 2 3 2 2 3
Output
7
Input
2 1 0
10 10
Output
20
Input
1 2 1
5 2
Output
2
Input
3 2 1
1 2 3 4 5 6
Output
0
Note
In the first example you can form the following barrels: [1, 2], [2, 2], [2, 3], [2, 3].
In the second example you can form the following barrels: [10], [10].
In the third example you can form the following barrels: [2, 5].
In the fourth example difference between volumes of barrels in any partition is at least 2 so it is impossible to make barrels equal enough.
Tags: greedy
Correct Solution:
```
n,k,L=map(int,input().split())
l=list(map(int,input().split()))
l=sorted(l)
s=0
v=n-1
p=0
ye=True
for i in range(len(l)-1,-1,-1) :
if abs(l[0]-l[i])>L :
p+=1
else :
if p>=k-1 and p>0 :
p-=k-1
s+=l[i]
else :
v=i
ye=False
break
if ye :
if p==0 :
print(s)
else :
print(0)
exit()
for i in range(0,v+1,k) :
s+=l[i]
print(s)
```
| 92,371 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have m = n·k wooden staves. The i-th stave has length ai. You have to assemble n barrels consisting of k staves each, you can use any k staves to construct a barrel. Each stave must belong to exactly one barrel.
Let volume vj of barrel j be equal to the length of the minimal stave in it.
<image>
You want to assemble exactly n barrels with the maximal total sum of volumes. But you have to make them equal enough, so a difference between volumes of any pair of the resulting barrels must not exceed l, i.e. |vx - vy| ≤ l for any 1 ≤ x ≤ n and 1 ≤ y ≤ n.
Print maximal total sum of volumes of equal enough barrels or 0 if it's impossible to satisfy the condition above.
Input
The first line contains three space-separated integers n, k and l (1 ≤ n, k ≤ 105, 1 ≤ n·k ≤ 105, 0 ≤ l ≤ 109).
The second line contains m = n·k space-separated integers a1, a2, ..., am (1 ≤ ai ≤ 109) — lengths of staves.
Output
Print single integer — maximal total sum of the volumes of barrels or 0 if it's impossible to construct exactly n barrels satisfying the condition |vx - vy| ≤ l for any 1 ≤ x ≤ n and 1 ≤ y ≤ n.
Examples
Input
4 2 1
2 2 1 2 3 2 2 3
Output
7
Input
2 1 0
10 10
Output
20
Input
1 2 1
5 2
Output
2
Input
3 2 1
1 2 3 4 5 6
Output
0
Note
In the first example you can form the following barrels: [1, 2], [2, 2], [2, 3], [2, 3].
In the second example you can form the following barrels: [10], [10].
In the third example you can form the following barrels: [2, 5].
In the fourth example difference between volumes of barrels in any partition is at least 2 so it is impossible to make barrels equal enough.
Tags: greedy
Correct Solution:
```
import bisect
import sys
input = sys.stdin.readline
n, k, l = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(a)
ans = [[] for i in range(n)]
max_min = a[0] + l
cnt = 0
for i in range(bisect.bisect_right(a, max_min)):
ans[cnt // k].append(a[i])
cnt += 1
nokori = 0
for i in range(n):
if not ans[i]:
nokori += 1
res = 0
for i in range(n)[::-1]:
for j, num in enumerate(ans[i][::-1]):
if nokori == 0:
break
if j == len(ans[i]) - 1:
continue
res += num
nokori -= 1
if nokori > 0:
print(0)
else:
for i in range(n):
if ans[i]:
res += ans[i][0]
print(res)
```
| 92,372 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have m = n·k wooden staves. The i-th stave has length ai. You have to assemble n barrels consisting of k staves each, you can use any k staves to construct a barrel. Each stave must belong to exactly one barrel.
Let volume vj of barrel j be equal to the length of the minimal stave in it.
<image>
You want to assemble exactly n barrels with the maximal total sum of volumes. But you have to make them equal enough, so a difference between volumes of any pair of the resulting barrels must not exceed l, i.e. |vx - vy| ≤ l for any 1 ≤ x ≤ n and 1 ≤ y ≤ n.
Print maximal total sum of volumes of equal enough barrels or 0 if it's impossible to satisfy the condition above.
Input
The first line contains three space-separated integers n, k and l (1 ≤ n, k ≤ 105, 1 ≤ n·k ≤ 105, 0 ≤ l ≤ 109).
The second line contains m = n·k space-separated integers a1, a2, ..., am (1 ≤ ai ≤ 109) — lengths of staves.
Output
Print single integer — maximal total sum of the volumes of barrels or 0 if it's impossible to construct exactly n barrels satisfying the condition |vx - vy| ≤ l for any 1 ≤ x ≤ n and 1 ≤ y ≤ n.
Examples
Input
4 2 1
2 2 1 2 3 2 2 3
Output
7
Input
2 1 0
10 10
Output
20
Input
1 2 1
5 2
Output
2
Input
3 2 1
1 2 3 4 5 6
Output
0
Note
In the first example you can form the following barrels: [1, 2], [2, 2], [2, 3], [2, 3].
In the second example you can form the following barrels: [10], [10].
In the third example you can form the following barrels: [2, 5].
In the fourth example difference between volumes of barrels in any partition is at least 2 so it is impossible to make barrels equal enough.
Tags: greedy
Correct Solution:
```
n, k, l = [int(i) for i in input().split()]
arr = sorted([int(i) for i in input().split()])
ma = n*k-1
for i in range(n*k):
if arr[0] + l < arr[i]:
ma = i - 1
break
#print(arr)
#print(ma)
if ma < n-1:
print(0)
exit()
ans = 0
for i in range(0, ma + 1, k):
ans += arr[i]
n-=1
arr[i] = 0
if (n == 0):
break
for i in range(ma, -1, -1):
if n == 0:
break
if arr[i] == 0:
continue
n -= 1
ans += arr[i]
print(ans)
```
| 92,373 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have m = n·k wooden staves. The i-th stave has length ai. You have to assemble n barrels consisting of k staves each, you can use any k staves to construct a barrel. Each stave must belong to exactly one barrel.
Let volume vj of barrel j be equal to the length of the minimal stave in it.
<image>
You want to assemble exactly n barrels with the maximal total sum of volumes. But you have to make them equal enough, so a difference between volumes of any pair of the resulting barrels must not exceed l, i.e. |vx - vy| ≤ l for any 1 ≤ x ≤ n and 1 ≤ y ≤ n.
Print maximal total sum of volumes of equal enough barrels or 0 if it's impossible to satisfy the condition above.
Input
The first line contains three space-separated integers n, k and l (1 ≤ n, k ≤ 105, 1 ≤ n·k ≤ 105, 0 ≤ l ≤ 109).
The second line contains m = n·k space-separated integers a1, a2, ..., am (1 ≤ ai ≤ 109) — lengths of staves.
Output
Print single integer — maximal total sum of the volumes of barrels or 0 if it's impossible to construct exactly n barrels satisfying the condition |vx - vy| ≤ l for any 1 ≤ x ≤ n and 1 ≤ y ≤ n.
Examples
Input
4 2 1
2 2 1 2 3 2 2 3
Output
7
Input
2 1 0
10 10
Output
20
Input
1 2 1
5 2
Output
2
Input
3 2 1
1 2 3 4 5 6
Output
0
Note
In the first example you can form the following barrels: [1, 2], [2, 2], [2, 3], [2, 3].
In the second example you can form the following barrels: [10], [10].
In the third example you can form the following barrels: [2, 5].
In the fourth example difference between volumes of barrels in any partition is at least 2 so it is impossible to make barrels equal enough.
Tags: greedy
Correct Solution:
```
def search(array, i, j, l):
if i > j or array[i] - array[0] > l:
return -1
mid = (i+j)//2
if array[mid] - array[0] > l:
return search(array, i, mid-1, l)
else:
return max(mid, search(array, mid+1, j, l))
if __name__ == '__main__':
n, k, l = input().split()
n = int(n)
k = int(k)
l = int(l)
a = input().split()
a = [int(x) for x in a]
a.sort()
ans = 0
if k == 1:
if a[n*k-1] - a[0] <= l:
i = 0
while i < n*k:
ans += a[i]
i += 1
else:
ans = 0
else:
ind = search(a,0, n*k-1, l)
if ind + 1 < n: ans = 0
else:
count = (n*k - ind - 1)//(k-1)
i = 0
while i < count:
ans += a[ind - i]
i+=1
i = 0
while i < n - count:
ans += a[i*k]
i += 1
print(ans)
```
| 92,374 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have m = n·k wooden staves. The i-th stave has length ai. You have to assemble n barrels consisting of k staves each, you can use any k staves to construct a barrel. Each stave must belong to exactly one barrel.
Let volume vj of barrel j be equal to the length of the minimal stave in it.
<image>
You want to assemble exactly n barrels with the maximal total sum of volumes. But you have to make them equal enough, so a difference between volumes of any pair of the resulting barrels must not exceed l, i.e. |vx - vy| ≤ l for any 1 ≤ x ≤ n and 1 ≤ y ≤ n.
Print maximal total sum of volumes of equal enough barrels or 0 if it's impossible to satisfy the condition above.
Input
The first line contains three space-separated integers n, k and l (1 ≤ n, k ≤ 105, 1 ≤ n·k ≤ 105, 0 ≤ l ≤ 109).
The second line contains m = n·k space-separated integers a1, a2, ..., am (1 ≤ ai ≤ 109) — lengths of staves.
Output
Print single integer — maximal total sum of the volumes of barrels or 0 if it's impossible to construct exactly n barrels satisfying the condition |vx - vy| ≤ l for any 1 ≤ x ≤ n and 1 ≤ y ≤ n.
Examples
Input
4 2 1
2 2 1 2 3 2 2 3
Output
7
Input
2 1 0
10 10
Output
20
Input
1 2 1
5 2
Output
2
Input
3 2 1
1 2 3 4 5 6
Output
0
Note
In the first example you can form the following barrels: [1, 2], [2, 2], [2, 3], [2, 3].
In the second example you can form the following barrels: [10], [10].
In the third example you can form the following barrels: [2, 5].
In the fourth example difference between volumes of barrels in any partition is at least 2 so it is impossible to make barrels equal enough.
Tags: greedy
Correct Solution:
```
n,k,l=map(int,input().split())
a=sorted(list(map(int,input().split())))
dontuse=0
ans=0
for i in range(n*k-1,-1,-1):
dontuse+=1
if a[i]-a[0]<=l and dontuse>=k:
ans+=a[i]
dontuse-=k
if dontuse>0:
print(0)
else:
print(ans)
```
| 92,375 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have m = n·k wooden staves. The i-th stave has length ai. You have to assemble n barrels consisting of k staves each, you can use any k staves to construct a barrel. Each stave must belong to exactly one barrel.
Let volume vj of barrel j be equal to the length of the minimal stave in it.
<image>
You want to assemble exactly n barrels with the maximal total sum of volumes. But you have to make them equal enough, so a difference between volumes of any pair of the resulting barrels must not exceed l, i.e. |vx - vy| ≤ l for any 1 ≤ x ≤ n and 1 ≤ y ≤ n.
Print maximal total sum of volumes of equal enough barrels or 0 if it's impossible to satisfy the condition above.
Input
The first line contains three space-separated integers n, k and l (1 ≤ n, k ≤ 105, 1 ≤ n·k ≤ 105, 0 ≤ l ≤ 109).
The second line contains m = n·k space-separated integers a1, a2, ..., am (1 ≤ ai ≤ 109) — lengths of staves.
Output
Print single integer — maximal total sum of the volumes of barrels or 0 if it's impossible to construct exactly n barrels satisfying the condition |vx - vy| ≤ l for any 1 ≤ x ≤ n and 1 ≤ y ≤ n.
Examples
Input
4 2 1
2 2 1 2 3 2 2 3
Output
7
Input
2 1 0
10 10
Output
20
Input
1 2 1
5 2
Output
2
Input
3 2 1
1 2 3 4 5 6
Output
0
Note
In the first example you can form the following barrels: [1, 2], [2, 2], [2, 3], [2, 3].
In the second example you can form the following barrels: [10], [10].
In the third example you can form the following barrels: [2, 5].
In the fourth example difference between volumes of barrels in any partition is at least 2 so it is impossible to make barrels equal enough.
Tags: greedy
Correct Solution:
```
n,k,l=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
x=0
while x<n*k-1 and a[x+1]-a[0]<=l:x+=1
if x+1<n:print(0);exit()
o=i=0
u=x-n+1
while i<=x:
o+=a[i]
u+=1
i=min(i+k,u)
print(o)
```
| 92,376 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have m = n·k wooden staves. The i-th stave has length ai. You have to assemble n barrels consisting of k staves each, you can use any k staves to construct a barrel. Each stave must belong to exactly one barrel.
Let volume vj of barrel j be equal to the length of the minimal stave in it.
<image>
You want to assemble exactly n barrels with the maximal total sum of volumes. But you have to make them equal enough, so a difference between volumes of any pair of the resulting barrels must not exceed l, i.e. |vx - vy| ≤ l for any 1 ≤ x ≤ n and 1 ≤ y ≤ n.
Print maximal total sum of volumes of equal enough barrels or 0 if it's impossible to satisfy the condition above.
Input
The first line contains three space-separated integers n, k and l (1 ≤ n, k ≤ 105, 1 ≤ n·k ≤ 105, 0 ≤ l ≤ 109).
The second line contains m = n·k space-separated integers a1, a2, ..., am (1 ≤ ai ≤ 109) — lengths of staves.
Output
Print single integer — maximal total sum of the volumes of barrels or 0 if it's impossible to construct exactly n barrels satisfying the condition |vx - vy| ≤ l for any 1 ≤ x ≤ n and 1 ≤ y ≤ n.
Examples
Input
4 2 1
2 2 1 2 3 2 2 3
Output
7
Input
2 1 0
10 10
Output
20
Input
1 2 1
5 2
Output
2
Input
3 2 1
1 2 3 4 5 6
Output
0
Note
In the first example you can form the following barrels: [1, 2], [2, 2], [2, 3], [2, 3].
In the second example you can form the following barrels: [10], [10].
In the third example you can form the following barrels: [2, 5].
In the fourth example difference between volumes of barrels in any partition is at least 2 so it is impossible to make barrels equal enough.
Submitted Solution:
```
n, k, l = list(map(int, input().split()))
arr = list(map(int, input().split()))
arr = sorted(arr)
if arr[n - 1] - arr[0] > l:
print(0)
else:
maxVol = arr[0] + l
index = 0
while index < n * k - 1 and arr[index + 1] <= maxVol: #index will be at most n * k - 1
index += 1
s = arr[0]
i = 0
remaining = n - 1
while remaining > 0 and i + k + remaining - 1 <= index: #jumps of k
i += k
remaining -= 1
s += arr[i]
if remaining > 0 and index - (remaining - 1) > 1 + i: #can now only make a jump of at most k - 1
i = (index - (remaining - 1))
s += arr[i]
remaining -= 1
while remaining > 0:
i += 1
s += arr[i]
remaining -= 1
print(s)
```
Yes
| 92,377 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have m = n·k wooden staves. The i-th stave has length ai. You have to assemble n barrels consisting of k staves each, you can use any k staves to construct a barrel. Each stave must belong to exactly one barrel.
Let volume vj of barrel j be equal to the length of the minimal stave in it.
<image>
You want to assemble exactly n barrels with the maximal total sum of volumes. But you have to make them equal enough, so a difference between volumes of any pair of the resulting barrels must not exceed l, i.e. |vx - vy| ≤ l for any 1 ≤ x ≤ n and 1 ≤ y ≤ n.
Print maximal total sum of volumes of equal enough barrels or 0 if it's impossible to satisfy the condition above.
Input
The first line contains three space-separated integers n, k and l (1 ≤ n, k ≤ 105, 1 ≤ n·k ≤ 105, 0 ≤ l ≤ 109).
The second line contains m = n·k space-separated integers a1, a2, ..., am (1 ≤ ai ≤ 109) — lengths of staves.
Output
Print single integer — maximal total sum of the volumes of barrels or 0 if it's impossible to construct exactly n barrels satisfying the condition |vx - vy| ≤ l for any 1 ≤ x ≤ n and 1 ≤ y ≤ n.
Examples
Input
4 2 1
2 2 1 2 3 2 2 3
Output
7
Input
2 1 0
10 10
Output
20
Input
1 2 1
5 2
Output
2
Input
3 2 1
1 2 3 4 5 6
Output
0
Note
In the first example you can form the following barrels: [1, 2], [2, 2], [2, 3], [2, 3].
In the second example you can form the following barrels: [10], [10].
In the third example you can form the following barrels: [2, 5].
In the fourth example difference between volumes of barrels in any partition is at least 2 so it is impossible to make barrels equal enough.
Submitted Solution:
```
def doit(n, k, l, a):
m = n * k
a.sort()
hen = 0
tai = m
while ((hen < m) and (a[hen] <= a[0] + l)):
hen += 1
if (hen < n):
return 0
for i in range(n):
tai -= k
if (hen > tai):
break
hen -= 1
a[hen], a[tai] = a[tai], a[hen]
temp = 0
for i in range(n):
temp += a[i * k]
return temp
n, k, l = input().split()
a = input().split()
for i in range(len(a)):
a[i] = int(a[i])
print(doit(int(n), int(k), int(l), a))
```
Yes
| 92,378 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have m = n·k wooden staves. The i-th stave has length ai. You have to assemble n barrels consisting of k staves each, you can use any k staves to construct a barrel. Each stave must belong to exactly one barrel.
Let volume vj of barrel j be equal to the length of the minimal stave in it.
<image>
You want to assemble exactly n barrels with the maximal total sum of volumes. But you have to make them equal enough, so a difference between volumes of any pair of the resulting barrels must not exceed l, i.e. |vx - vy| ≤ l for any 1 ≤ x ≤ n and 1 ≤ y ≤ n.
Print maximal total sum of volumes of equal enough barrels or 0 if it's impossible to satisfy the condition above.
Input
The first line contains three space-separated integers n, k and l (1 ≤ n, k ≤ 105, 1 ≤ n·k ≤ 105, 0 ≤ l ≤ 109).
The second line contains m = n·k space-separated integers a1, a2, ..., am (1 ≤ ai ≤ 109) — lengths of staves.
Output
Print single integer — maximal total sum of the volumes of barrels or 0 if it's impossible to construct exactly n barrels satisfying the condition |vx - vy| ≤ l for any 1 ≤ x ≤ n and 1 ≤ y ≤ n.
Examples
Input
4 2 1
2 2 1 2 3 2 2 3
Output
7
Input
2 1 0
10 10
Output
20
Input
1 2 1
5 2
Output
2
Input
3 2 1
1 2 3 4 5 6
Output
0
Note
In the first example you can form the following barrels: [1, 2], [2, 2], [2, 3], [2, 3].
In the second example you can form the following barrels: [10], [10].
In the third example you can form the following barrels: [2, 5].
In the fourth example difference between volumes of barrels in any partition is at least 2 so it is impossible to make barrels equal enough.
Submitted Solution:
```
def main():
n, k, l = map(int, input().split())
m = n * k
a = list(map(int, input().split()))
a.sort()
f = a[0]
i = 0
while (i < m and a[i] <= f + l):
i += 1
if (i != m):
i -= 1
else:
ans = 0
ind = 0
for i in range(n):
ans += a[ind]
ind += k
print(ans)
return
last = i
if (last + 1 < n):
print(0)
return
count = m - last - 1
ost = last + 1
ans = 0
i = last
while (i >= 0):
c = min(k - 1, count)
count -= c
i -= (k - c)
ans += a[i + 1]
print(ans)
main()
```
Yes
| 92,379 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have m = n·k wooden staves. The i-th stave has length ai. You have to assemble n barrels consisting of k staves each, you can use any k staves to construct a barrel. Each stave must belong to exactly one barrel.
Let volume vj of barrel j be equal to the length of the minimal stave in it.
<image>
You want to assemble exactly n barrels with the maximal total sum of volumes. But you have to make them equal enough, so a difference between volumes of any pair of the resulting barrels must not exceed l, i.e. |vx - vy| ≤ l for any 1 ≤ x ≤ n and 1 ≤ y ≤ n.
Print maximal total sum of volumes of equal enough barrels or 0 if it's impossible to satisfy the condition above.
Input
The first line contains three space-separated integers n, k and l (1 ≤ n, k ≤ 105, 1 ≤ n·k ≤ 105, 0 ≤ l ≤ 109).
The second line contains m = n·k space-separated integers a1, a2, ..., am (1 ≤ ai ≤ 109) — lengths of staves.
Output
Print single integer — maximal total sum of the volumes of barrels or 0 if it's impossible to construct exactly n barrels satisfying the condition |vx - vy| ≤ l for any 1 ≤ x ≤ n and 1 ≤ y ≤ n.
Examples
Input
4 2 1
2 2 1 2 3 2 2 3
Output
7
Input
2 1 0
10 10
Output
20
Input
1 2 1
5 2
Output
2
Input
3 2 1
1 2 3 4 5 6
Output
0
Note
In the first example you can form the following barrels: [1, 2], [2, 2], [2, 3], [2, 3].
In the second example you can form the following barrels: [10], [10].
In the third example you can form the following barrels: [2, 5].
In the fourth example difference between volumes of barrels in any partition is at least 2 so it is impossible to make barrels equal enough.
Submitted Solution:
```
(n, k, l) = [int(i) for i in input().split()]
lengths = input().split()
for i in range(n * k):
lengths[i] = int(lengths[i])
lengths.sort()
smallest = lengths[0]
biggest = smallest + l
stop = len(lengths)
for i in range(len(lengths)):
if lengths[i] > biggest:
stop = i
break
if stop < n:
print(0)
else:
ans = 0
pos = 0
todo = n
for i in range(n):
ans += lengths[pos]
pos += 1
for j in range(k - 1):
if (stop - pos) > n - i - 1:
pos += 1
print(ans)
```
Yes
| 92,380 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have m = n·k wooden staves. The i-th stave has length ai. You have to assemble n barrels consisting of k staves each, you can use any k staves to construct a barrel. Each stave must belong to exactly one barrel.
Let volume vj of barrel j be equal to the length of the minimal stave in it.
<image>
You want to assemble exactly n barrels with the maximal total sum of volumes. But you have to make them equal enough, so a difference between volumes of any pair of the resulting barrels must not exceed l, i.e. |vx - vy| ≤ l for any 1 ≤ x ≤ n and 1 ≤ y ≤ n.
Print maximal total sum of volumes of equal enough barrels or 0 if it's impossible to satisfy the condition above.
Input
The first line contains three space-separated integers n, k and l (1 ≤ n, k ≤ 105, 1 ≤ n·k ≤ 105, 0 ≤ l ≤ 109).
The second line contains m = n·k space-separated integers a1, a2, ..., am (1 ≤ ai ≤ 109) — lengths of staves.
Output
Print single integer — maximal total sum of the volumes of barrels or 0 if it's impossible to construct exactly n barrels satisfying the condition |vx - vy| ≤ l for any 1 ≤ x ≤ n and 1 ≤ y ≤ n.
Examples
Input
4 2 1
2 2 1 2 3 2 2 3
Output
7
Input
2 1 0
10 10
Output
20
Input
1 2 1
5 2
Output
2
Input
3 2 1
1 2 3 4 5 6
Output
0
Note
In the first example you can form the following barrels: [1, 2], [2, 2], [2, 3], [2, 3].
In the second example you can form the following barrels: [10], [10].
In the third example you can form the following barrels: [2, 5].
In the fourth example difference between volumes of barrels in any partition is at least 2 so it is impossible to make barrels equal enough.
Submitted Solution:
```
#-*- coding:utf-8 -*-
tmpstr = input().strip()
tmpvec = tmpstr.split(' ')
n = int(tmpvec[0])
k = int(tmpvec[1])
l = int(tmpvec[2])
tmpstr = input().strip()
tmpvec = tmpstr.split(' ')
vec_len = len(tmpvec)
data = map(int, tmpvec)
dlist = list(data)
dlist.sort()
index = 0
for i in range(n*k):
if dlist[i] > dlist[0] + l:
break
if(i != n * k -1):
i = i - 1
count = i + 1
tt = count
if i < n - 1:
print(0)
exit(0)
tail = i
start = 0
volume = 0
for i in range(n):
volume = volume + dlist[start]
if n + k <= count:
start = start + k
count = count - k
else:
diff = count - n
start = start + diff + 1
count = count - diff - 1
if n == 50000 and k ==2:
print(tt)
print(start)
print(volume)
```
No
| 92,381 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have m = n·k wooden staves. The i-th stave has length ai. You have to assemble n barrels consisting of k staves each, you can use any k staves to construct a barrel. Each stave must belong to exactly one barrel.
Let volume vj of barrel j be equal to the length of the minimal stave in it.
<image>
You want to assemble exactly n barrels with the maximal total sum of volumes. But you have to make them equal enough, so a difference between volumes of any pair of the resulting barrels must not exceed l, i.e. |vx - vy| ≤ l for any 1 ≤ x ≤ n and 1 ≤ y ≤ n.
Print maximal total sum of volumes of equal enough barrels or 0 if it's impossible to satisfy the condition above.
Input
The first line contains three space-separated integers n, k and l (1 ≤ n, k ≤ 105, 1 ≤ n·k ≤ 105, 0 ≤ l ≤ 109).
The second line contains m = n·k space-separated integers a1, a2, ..., am (1 ≤ ai ≤ 109) — lengths of staves.
Output
Print single integer — maximal total sum of the volumes of barrels or 0 if it's impossible to construct exactly n barrels satisfying the condition |vx - vy| ≤ l for any 1 ≤ x ≤ n and 1 ≤ y ≤ n.
Examples
Input
4 2 1
2 2 1 2 3 2 2 3
Output
7
Input
2 1 0
10 10
Output
20
Input
1 2 1
5 2
Output
2
Input
3 2 1
1 2 3 4 5 6
Output
0
Note
In the first example you can form the following barrels: [1, 2], [2, 2], [2, 3], [2, 3].
In the second example you can form the following barrels: [10], [10].
In the third example you can form the following barrels: [2, 5].
In the fourth example difference between volumes of barrels in any partition is at least 2 so it is impossible to make barrels equal enough.
Submitted Solution:
```
#-*- coding:utf-8 -*-
tmpstr = input().strip()
tmpvec = tmpstr.split(' ')
n = int(tmpvec[0])
k = int(tmpvec[1])
l = int(tmpvec[2])
tmpstr = input().strip()
tmpvec = tmpstr.split(' ')
vec_len = len(tmpvec)
data = map(int, tmpvec)
dlist = list(data)
dlist.sort()
index = 0
for i in range(n*k):
if dlist[i] > dlist[0] + l:
break
if(i != n * k -1):
i = i - 1
count = i + 1
if i < n - 1:
print(0)
exit(0)
tail = i
start = 0
volume = 0
for i in range(n):
volume = volume + dlist[start]
if n + k <= count:
start = start + k
count = count - k
else:
diff = count - n
start = start + diff + 1
count = count - diff - 1
print(volume)
```
No
| 92,382 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have m = n·k wooden staves. The i-th stave has length ai. You have to assemble n barrels consisting of k staves each, you can use any k staves to construct a barrel. Each stave must belong to exactly one barrel.
Let volume vj of barrel j be equal to the length of the minimal stave in it.
<image>
You want to assemble exactly n barrels with the maximal total sum of volumes. But you have to make them equal enough, so a difference between volumes of any pair of the resulting barrels must not exceed l, i.e. |vx - vy| ≤ l for any 1 ≤ x ≤ n and 1 ≤ y ≤ n.
Print maximal total sum of volumes of equal enough barrels or 0 if it's impossible to satisfy the condition above.
Input
The first line contains three space-separated integers n, k and l (1 ≤ n, k ≤ 105, 1 ≤ n·k ≤ 105, 0 ≤ l ≤ 109).
The second line contains m = n·k space-separated integers a1, a2, ..., am (1 ≤ ai ≤ 109) — lengths of staves.
Output
Print single integer — maximal total sum of the volumes of barrels or 0 if it's impossible to construct exactly n barrels satisfying the condition |vx - vy| ≤ l for any 1 ≤ x ≤ n and 1 ≤ y ≤ n.
Examples
Input
4 2 1
2 2 1 2 3 2 2 3
Output
7
Input
2 1 0
10 10
Output
20
Input
1 2 1
5 2
Output
2
Input
3 2 1
1 2 3 4 5 6
Output
0
Note
In the first example you can form the following barrels: [1, 2], [2, 2], [2, 3], [2, 3].
In the second example you can form the following barrels: [10], [10].
In the third example you can form the following barrels: [2, 5].
In the fourth example difference between volumes of barrels in any partition is at least 2 so it is impossible to make barrels equal enough.
Submitted Solution:
```
n, k, l = list(map(int, input().split()))
a = sorted(list(map(int, input().split(' '))))
# print(n, k, l, a)
if a[0] + l + 1 in a:
ok = a.index(a[0] + l + 1) - n
else:
ok = n*k - n
if ok < 0:
print(0)
else:
ans = 0
cur = 0
for i in range(n):
ans += a[cur]
use = min(k-1, ok)
ok -= use
cur += 1 + use
print(ans)
```
No
| 92,383 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have m = n·k wooden staves. The i-th stave has length ai. You have to assemble n barrels consisting of k staves each, you can use any k staves to construct a barrel. Each stave must belong to exactly one barrel.
Let volume vj of barrel j be equal to the length of the minimal stave in it.
<image>
You want to assemble exactly n barrels with the maximal total sum of volumes. But you have to make them equal enough, so a difference between volumes of any pair of the resulting barrels must not exceed l, i.e. |vx - vy| ≤ l for any 1 ≤ x ≤ n and 1 ≤ y ≤ n.
Print maximal total sum of volumes of equal enough barrels or 0 if it's impossible to satisfy the condition above.
Input
The first line contains three space-separated integers n, k and l (1 ≤ n, k ≤ 105, 1 ≤ n·k ≤ 105, 0 ≤ l ≤ 109).
The second line contains m = n·k space-separated integers a1, a2, ..., am (1 ≤ ai ≤ 109) — lengths of staves.
Output
Print single integer — maximal total sum of the volumes of barrels or 0 if it's impossible to construct exactly n barrels satisfying the condition |vx - vy| ≤ l for any 1 ≤ x ≤ n and 1 ≤ y ≤ n.
Examples
Input
4 2 1
2 2 1 2 3 2 2 3
Output
7
Input
2 1 0
10 10
Output
20
Input
1 2 1
5 2
Output
2
Input
3 2 1
1 2 3 4 5 6
Output
0
Note
In the first example you can form the following barrels: [1, 2], [2, 2], [2, 3], [2, 3].
In the second example you can form the following barrels: [10], [10].
In the third example you can form the following barrels: [2, 5].
In the fourth example difference between volumes of barrels in any partition is at least 2 so it is impossible to make barrels equal enough.
Submitted Solution:
```
n,k,l = map(int, input().split())
a=sorted(list(map(int, input().split())))
t1,t2=n-1,n*k
while t2-t1 > 1:
if a[(t1+t2)//2] <= a[0] + l:
t1=(t1+t2)//2
else:
t2=(t1+t2)//2
ans=0
for i in range(n):
if a[i*k] > a[t2+i-n]:
ans+=a[t2+i-n]
else:
ans+=a[i*k]
print(ans)
```
No
| 92,384 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi loves takoyaki - a ball-shaped snack.
With a takoyaki machine, he can make at most X pieces of takoyaki at a time, taking T minutes regardless of the number of pieces to make.
How long does it take to make N takoyaki?
Constraints
* 1 \leq N,X,T \leq 1000
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X T
Output
Print an integer representing the minimum number of minutes needed to make N pieces of takoyaki.
Examples
Input
20 12 6
Output
12
Input
1000 1 1000
Output
1000000
"Correct Solution:
```
n,x,t=map(int,input().split())
import math
print(math.ceil(n/x)*t)
```
| 92,385 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi loves takoyaki - a ball-shaped snack.
With a takoyaki machine, he can make at most X pieces of takoyaki at a time, taking T minutes regardless of the number of pieces to make.
How long does it take to make N takoyaki?
Constraints
* 1 \leq N,X,T \leq 1000
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X T
Output
Print an integer representing the minimum number of minutes needed to make N pieces of takoyaki.
Examples
Input
20 12 6
Output
12
Input
1000 1 1000
Output
1000000
"Correct Solution:
```
n,x,t = map(int,input().split())
print(-(n//-x)*t)
```
| 92,386 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi loves takoyaki - a ball-shaped snack.
With a takoyaki machine, he can make at most X pieces of takoyaki at a time, taking T minutes regardless of the number of pieces to make.
How long does it take to make N takoyaki?
Constraints
* 1 \leq N,X,T \leq 1000
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X T
Output
Print an integer representing the minimum number of minutes needed to make N pieces of takoyaki.
Examples
Input
20 12 6
Output
12
Input
1000 1 1000
Output
1000000
"Correct Solution:
```
(N,X,T) = map(int,input().split())
print((-((-N)//X)*T))
```
| 92,387 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi loves takoyaki - a ball-shaped snack.
With a takoyaki machine, he can make at most X pieces of takoyaki at a time, taking T minutes regardless of the number of pieces to make.
How long does it take to make N takoyaki?
Constraints
* 1 \leq N,X,T \leq 1000
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X T
Output
Print an integer representing the minimum number of minutes needed to make N pieces of takoyaki.
Examples
Input
20 12 6
Output
12
Input
1000 1 1000
Output
1000000
"Correct Solution:
```
N, X, T = [int(n) for n in input().split()]
print((N+X-1)//X*T)
```
| 92,388 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi loves takoyaki - a ball-shaped snack.
With a takoyaki machine, he can make at most X pieces of takoyaki at a time, taking T minutes regardless of the number of pieces to make.
How long does it take to make N takoyaki?
Constraints
* 1 \leq N,X,T \leq 1000
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X T
Output
Print an integer representing the minimum number of minutes needed to make N pieces of takoyaki.
Examples
Input
20 12 6
Output
12
Input
1000 1 1000
Output
1000000
"Correct Solution:
```
N, X, T = map(int, input().split())
ans = (N + X - 1)//X*T
print(ans)
```
| 92,389 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi loves takoyaki - a ball-shaped snack.
With a takoyaki machine, he can make at most X pieces of takoyaki at a time, taking T minutes regardless of the number of pieces to make.
How long does it take to make N takoyaki?
Constraints
* 1 \leq N,X,T \leq 1000
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X T
Output
Print an integer representing the minimum number of minutes needed to make N pieces of takoyaki.
Examples
Input
20 12 6
Output
12
Input
1000 1 1000
Output
1000000
"Correct Solution:
```
N,X,T=map(int,input().split())
print(-(-N//X*T))
```
| 92,390 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi loves takoyaki - a ball-shaped snack.
With a takoyaki machine, he can make at most X pieces of takoyaki at a time, taking T minutes regardless of the number of pieces to make.
How long does it take to make N takoyaki?
Constraints
* 1 \leq N,X,T \leq 1000
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X T
Output
Print an integer representing the minimum number of minutes needed to make N pieces of takoyaki.
Examples
Input
20 12 6
Output
12
Input
1000 1 1000
Output
1000000
"Correct Solution:
```
N,X,T=map(int,input().split())
import math
print(T*math.ceil(N/X))
```
| 92,391 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi loves takoyaki - a ball-shaped snack.
With a takoyaki machine, he can make at most X pieces of takoyaki at a time, taking T minutes regardless of the number of pieces to make.
How long does it take to make N takoyaki?
Constraints
* 1 \leq N,X,T \leq 1000
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X T
Output
Print an integer representing the minimum number of minutes needed to make N pieces of takoyaki.
Examples
Input
20 12 6
Output
12
Input
1000 1 1000
Output
1000000
"Correct Solution:
```
n,x,t=map(int,input().split())
print((n//x+((n%x)!=0))*t)
```
| 92,392 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi loves takoyaki - a ball-shaped snack.
With a takoyaki machine, he can make at most X pieces of takoyaki at a time, taking T minutes regardless of the number of pieces to make.
How long does it take to make N takoyaki?
Constraints
* 1 \leq N,X,T \leq 1000
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X T
Output
Print an integer representing the minimum number of minutes needed to make N pieces of takoyaki.
Examples
Input
20 12 6
Output
12
Input
1000 1 1000
Output
1000000
Submitted Solution:
```
n,x,t=map(int,input().split())
u=(n+x-1)//x
print(u*t)
```
Yes
| 92,393 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi loves takoyaki - a ball-shaped snack.
With a takoyaki machine, he can make at most X pieces of takoyaki at a time, taking T minutes regardless of the number of pieces to make.
How long does it take to make N takoyaki?
Constraints
* 1 \leq N,X,T \leq 1000
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X T
Output
Print an integer representing the minimum number of minutes needed to make N pieces of takoyaki.
Examples
Input
20 12 6
Output
12
Input
1000 1 1000
Output
1000000
Submitted Solution:
```
n,x,t=map(int,input().split())
print(t*(0--n//x))
```
Yes
| 92,394 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi loves takoyaki - a ball-shaped snack.
With a takoyaki machine, he can make at most X pieces of takoyaki at a time, taking T minutes regardless of the number of pieces to make.
How long does it take to make N takoyaki?
Constraints
* 1 \leq N,X,T \leq 1000
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X T
Output
Print an integer representing the minimum number of minutes needed to make N pieces of takoyaki.
Examples
Input
20 12 6
Output
12
Input
1000 1 1000
Output
1000000
Submitted Solution:
```
N,X,T = list(map(int, input().split()))
print(-(-N // X) * T)
```
Yes
| 92,395 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi loves takoyaki - a ball-shaped snack.
With a takoyaki machine, he can make at most X pieces of takoyaki at a time, taking T minutes regardless of the number of pieces to make.
How long does it take to make N takoyaki?
Constraints
* 1 \leq N,X,T \leq 1000
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X T
Output
Print an integer representing the minimum number of minutes needed to make N pieces of takoyaki.
Examples
Input
20 12 6
Output
12
Input
1000 1 1000
Output
1000000
Submitted Solution:
```
N,X,T=map(int,input().split())
print((N+(X-1))//X*T)
```
Yes
| 92,396 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi loves takoyaki - a ball-shaped snack.
With a takoyaki machine, he can make at most X pieces of takoyaki at a time, taking T minutes regardless of the number of pieces to make.
How long does it take to make N takoyaki?
Constraints
* 1 \leq N,X,T \leq 1000
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X T
Output
Print an integer representing the minimum number of minutes needed to make N pieces of takoyaki.
Examples
Input
20 12 6
Output
12
Input
1000 1 1000
Output
1000000
Submitted Solution:
```
import math
def main():
n, x, t = map(int, input().split())
print(t*(n // x + 1))
if __name__ == "__main__":
main()
```
No
| 92,397 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi loves takoyaki - a ball-shaped snack.
With a takoyaki machine, he can make at most X pieces of takoyaki at a time, taking T minutes regardless of the number of pieces to make.
How long does it take to make N takoyaki?
Constraints
* 1 \leq N,X,T \leq 1000
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X T
Output
Print an integer representing the minimum number of minutes needed to make N pieces of takoyaki.
Examples
Input
20 12 6
Output
12
Input
1000 1 1000
Output
1000000
Submitted Solution:
```
N,X,T=[int(i) fir i in input().split()]
a=divmod(N,X)
x=a[0]
if a[1]<X and a[1] != 0:
x += 1
print(x*T)
```
No
| 92,398 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi loves takoyaki - a ball-shaped snack.
With a takoyaki machine, he can make at most X pieces of takoyaki at a time, taking T minutes regardless of the number of pieces to make.
How long does it take to make N takoyaki?
Constraints
* 1 \leq N,X,T \leq 1000
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X T
Output
Print an integer representing the minimum number of minutes needed to make N pieces of takoyaki.
Examples
Input
20 12 6
Output
12
Input
1000 1 1000
Output
1000000
Submitted Solution:
```
N, X, T = input().split()
if N <= X:
print(T)
elif N % X == 0:
A = N / X * T
print(A)
else:
B = (N / X + 1) * T
print(B)
```
No
| 92,399 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.