text stringlengths 198 433k | conversation_id int64 0 109k |
|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
During the break, we decided to relax and play dominoes. Our box with Domino was empty, so we decided to borrow the teacher's dominoes.
The teacher responded instantly at our request. He put nm dominoes on the table as an n Γ 2m rectangle so that each of the n rows contained m dominoes arranged horizontally. Each half of each domino contained number (0 or 1).
We were taken aback, and the teacher smiled and said: "Consider some arrangement of dominoes in an n Γ 2m matrix. Let's count for each column of the matrix the sum of numbers in this column. Then among all such sums find the maximum one. Can you rearrange the dominoes in the matrix in such a way that the maximum sum will be minimum possible? Note that it is prohibited to change the orientation of the dominoes, they all need to stay horizontal, nevertheless dominoes are allowed to rotate by 180 degrees. As a reward I will give you all my dominoes".
We got even more taken aback. And while we are wondering what was going on, help us make an optimal matrix of dominoes.
Input
The first line contains integers n, m (1 β€ n, m β€ 103).
In the next lines there is a description of the teachers' matrix. Each of next n lines contains m dominoes. The description of one domino is two integers (0 or 1), written without a space β the digits on the left and right half of the domino.
Output
Print the resulting matrix of dominoes in the format: n lines, each of them contains m space-separated dominoes.
If there are multiple optimal solutions, print any of them.
Examples
Input
2 3
01 11 00
00 01 11
Output
11 11 10
00 00 01
Input
4 1
11
10
01
00
Output
11
10
01
00
Note
Consider the answer for the first sample. There, the maximum sum among all columns equals 1 (the number of columns is 6, and not 3). Obviously, this maximum can't be less than 1, then such matrix is optimal.
Note that the dominoes can be rotated by 180 degrees.
Tags: constructive algorithms, greedy
Correct Solution:
```
def find_matrix_col_sum(mat):
max_sum = -1
for cols in range(len(mat[0])):
s = 0
for i in range(2):
for rows in range(len(mat)):
s+=int(mat[rows][cols][i])
if s > max_sum:
max_sum = s
return max_sum
n,m=input().split()
n,m=int(n), int(m)
dominos_count = [0, 0, 0]
for i in range(n):
dominos = input().split()
for dominohaya in dominos:
if dominohaya == "11":
dominos_count[0] += 1
elif dominohaya == "01" or dominohaya == "10":
dominos_count[1] += 1
else:
dominos_count[2] += 1
dominios_list = [0]*n
total_sum = [0]*n
prev_sum_row = [0]*(2*m)
new_sum_row=[0]*(2*m)
for i in range(n):
new_row = [""]*(m)
for j in range(m):
if dominos_count[0] > 0:
new_sum_row[2*j]=prev_sum_row[2 * j] + 1
new_sum_row[2*j+1]=prev_sum_row[2 * j + 1] + 1
new_row[j]="11"
dominos_count[0] -= 1
elif dominos_count[1] > 0:
min_val = min(prev_sum_row)
if prev_sum_row[2 * j] == min_val:
new_row[j]="10"
dominos_count[1] -= 1
new_sum_row[2*j]=prev_sum_row[2 * j] + 1
new_sum_row[2*j+1]=prev_sum_row[2 * j + 1]
elif prev_sum_row[2 * j + 1] == min_val:
new_row[j]="01"
dominos_count[1] -= 1
new_sum_row[2*j]=prev_sum_row[2 * j]
new_sum_row[2*j+1]=prev_sum_row[2 * j + 1] + 1
else:
if dominos_count[2]>0:
new_row[j]="00"
dominos_count[2] -= 1
new_sum_row[2*j]=prev_sum_row[2 * j]
new_sum_row[2*j+1]=prev_sum_row[2 * j + 1]
else:
new_row[j]="01"
dominos_count[1] -= 1
new_sum_row[2*j]=prev_sum_row[2 * j] + 1
new_sum_row[2*j+1]=prev_sum_row[2 * j + 1] + 1
else:
new_row[j]="00"
dominos_count[2] -= 1
new_sum_row[2*j]=prev_sum_row[2 * j]
new_sum_row[2*j+1]=prev_sum_row[2 * j + 1]
total_sum[i] = new_sum_row
# dominios_list[i] = new_row
prev_sum_row = new_sum_row
s = " ".join(new_row)
print(s)
# for i in range(n):
# for j in range(m):
# print(dominios_list[i][j], end="")
# if j < m-1:
# print(" ", end="")
# print("")
#
```
| 12,000 |
Provide tags and a correct Python 3 solution for this coding contest problem.
During the break, we decided to relax and play dominoes. Our box with Domino was empty, so we decided to borrow the teacher's dominoes.
The teacher responded instantly at our request. He put nm dominoes on the table as an n Γ 2m rectangle so that each of the n rows contained m dominoes arranged horizontally. Each half of each domino contained number (0 or 1).
We were taken aback, and the teacher smiled and said: "Consider some arrangement of dominoes in an n Γ 2m matrix. Let's count for each column of the matrix the sum of numbers in this column. Then among all such sums find the maximum one. Can you rearrange the dominoes in the matrix in such a way that the maximum sum will be minimum possible? Note that it is prohibited to change the orientation of the dominoes, they all need to stay horizontal, nevertheless dominoes are allowed to rotate by 180 degrees. As a reward I will give you all my dominoes".
We got even more taken aback. And while we are wondering what was going on, help us make an optimal matrix of dominoes.
Input
The first line contains integers n, m (1 β€ n, m β€ 103).
In the next lines there is a description of the teachers' matrix. Each of next n lines contains m dominoes. The description of one domino is two integers (0 or 1), written without a space β the digits on the left and right half of the domino.
Output
Print the resulting matrix of dominoes in the format: n lines, each of them contains m space-separated dominoes.
If there are multiple optimal solutions, print any of them.
Examples
Input
2 3
01 11 00
00 01 11
Output
11 11 10
00 00 01
Input
4 1
11
10
01
00
Output
11
10
01
00
Note
Consider the answer for the first sample. There, the maximum sum among all columns equals 1 (the number of columns is 6, and not 3). Obviously, this maximum can't be less than 1, then such matrix is optimal.
Note that the dominoes can be rotated by 180 degrees.
Tags: constructive algorithms, greedy
Correct Solution:
```
n, m = map(int, input().split())
doubles, singles = 0, 0
for r in range(n):
for s in input().split():
if s == '11':
doubles += 1
elif s != '00':
singles += 1
lines = {
'zero': ' '.join(m * [ '00' ]),
'double': ' '.join(m * [ '11' ]),
'single_0': ' '.join(m * [ '01' ]),
'single_1': ' '.join(m * [ '10' ])
}
zeros = n * m - doubles - singles
while doubles >= m:
print(lines['double'])
doubles -= m
while singles >= 2 * m:
print(lines['single_0'])
print(lines['single_1'])
singles -= 2 * m
while zeros >= m:
print(lines['zero'])
zeros -= m
x = doubles + singles + zeros
tail = [ m * [ '00' ] for r in range(x // m) ]
height = len(tail)
r, c = 0, 0
while singles + doubles > 0:
if tail[r][c] == '00':
if doubles > 0:
tail[r][c] = '11'
doubles -= 1
else:
tail[r][c] = '01'
singles -= 1
if singles > 0 and r + 1 < height:
tail[r + 1][c] = '10'
singles -= 1
c += 1
if c == m:
c = 0
r += 1
for row in tail:
print(' '.join(row))
```
| 12,001 |
Provide tags and a correct Python 3 solution for this coding contest problem.
During the break, we decided to relax and play dominoes. Our box with Domino was empty, so we decided to borrow the teacher's dominoes.
The teacher responded instantly at our request. He put nm dominoes on the table as an n Γ 2m rectangle so that each of the n rows contained m dominoes arranged horizontally. Each half of each domino contained number (0 or 1).
We were taken aback, and the teacher smiled and said: "Consider some arrangement of dominoes in an n Γ 2m matrix. Let's count for each column of the matrix the sum of numbers in this column. Then among all such sums find the maximum one. Can you rearrange the dominoes in the matrix in such a way that the maximum sum will be minimum possible? Note that it is prohibited to change the orientation of the dominoes, they all need to stay horizontal, nevertheless dominoes are allowed to rotate by 180 degrees. As a reward I will give you all my dominoes".
We got even more taken aback. And while we are wondering what was going on, help us make an optimal matrix of dominoes.
Input
The first line contains integers n, m (1 β€ n, m β€ 103).
In the next lines there is a description of the teachers' matrix. Each of next n lines contains m dominoes. The description of one domino is two integers (0 or 1), written without a space β the digits on the left and right half of the domino.
Output
Print the resulting matrix of dominoes in the format: n lines, each of them contains m space-separated dominoes.
If there are multiple optimal solutions, print any of them.
Examples
Input
2 3
01 11 00
00 01 11
Output
11 11 10
00 00 01
Input
4 1
11
10
01
00
Output
11
10
01
00
Note
Consider the answer for the first sample. There, the maximum sum among all columns equals 1 (the number of columns is 6, and not 3). Obviously, this maximum can't be less than 1, then such matrix is optimal.
Note that the dominoes can be rotated by 180 degrees.
Tags: constructive algorithms, greedy
Correct Solution:
```
n, m = map(int, input().split())
cnt1 = 0
cnt2 = 0
for i in range(n):
for x in input().split():
if x == "11": cnt2 += 1
elif x == "01": cnt1 += 1
elif x == "10": cnt1 += 1
cnt0 = n*m - cnt1 - cnt2
mat = [ [-1]*(m) for i in range(n) ]
col = [0]*(2*m)
strB = [ "00", "01", "10", "11" ]
i = j = 0
while cnt2 > 0:
cnt2 -= 1
mat[i][j] = 3
col[2*j] += 1
col[2*j+1] += 1
j += 1
if j == m:
i += 1
j = 0
i = n-1
j = 0
while cnt0 > 0:
if mat[i][j] == -1:
cnt0 -= 1
mat[i][j] = 0
j += 1
if j == m:
i -= 1
j = 0
for i in range(n):
for j in range(0,m):
if mat[i][j] == -1:
if col[2*j] > col[2*j+1]:
mat[i][j] = 1
col[2*j+1] += 1
else:
mat[i][j] = 2
col[2*j] += 1
for i in range(n):
print(" ".join(strB[x] for x in mat[i]))
```
| 12,002 |
Provide tags and a correct Python 3 solution for this coding contest problem.
During the break, we decided to relax and play dominoes. Our box with Domino was empty, so we decided to borrow the teacher's dominoes.
The teacher responded instantly at our request. He put nm dominoes on the table as an n Γ 2m rectangle so that each of the n rows contained m dominoes arranged horizontally. Each half of each domino contained number (0 or 1).
We were taken aback, and the teacher smiled and said: "Consider some arrangement of dominoes in an n Γ 2m matrix. Let's count for each column of the matrix the sum of numbers in this column. Then among all such sums find the maximum one. Can you rearrange the dominoes in the matrix in such a way that the maximum sum will be minimum possible? Note that it is prohibited to change the orientation of the dominoes, they all need to stay horizontal, nevertheless dominoes are allowed to rotate by 180 degrees. As a reward I will give you all my dominoes".
We got even more taken aback. And while we are wondering what was going on, help us make an optimal matrix of dominoes.
Input
The first line contains integers n, m (1 β€ n, m β€ 103).
In the next lines there is a description of the teachers' matrix. Each of next n lines contains m dominoes. The description of one domino is two integers (0 or 1), written without a space β the digits on the left and right half of the domino.
Output
Print the resulting matrix of dominoes in the format: n lines, each of them contains m space-separated dominoes.
If there are multiple optimal solutions, print any of them.
Examples
Input
2 3
01 11 00
00 01 11
Output
11 11 10
00 00 01
Input
4 1
11
10
01
00
Output
11
10
01
00
Note
Consider the answer for the first sample. There, the maximum sum among all columns equals 1 (the number of columns is 6, and not 3). Obviously, this maximum can't be less than 1, then such matrix is optimal.
Note that the dominoes can be rotated by 180 degrees.
Tags: constructive algorithms, greedy
Correct Solution:
```
line = input().split()
n = int(line[0])
m = int(line[1])
one = 0
double = 0
switch = -1
switchm = -1
dom = [["00" for i in range(m)] for j in range(n)]
for i in range(n):
line = input().split()
for j in range(m):
num = int(line[j][0])+int(line[j][1])
if num == 1:
one+=1
elif num == 2:
double+=1
for i in range(n):
for j in range(m):
if double>0:
dom[i][j]="11"
double-=1;
elif one>0:
if switch==-1:
switch=i+1
switchm=j
dom[i][j]=str(i%2)+str((i+1)%2)
one-=1
if switch!=-1:
break
for i in [k+switch for k in range(n-switch)]:
for j in range(m):
if one==0:
break
else:
dom[i][(j+switchm)%m]=str(i%2)+str((i+1)%2)
one-=1
for i in range(n):
print(" ".join(dom[i]))
```
| 12,003 |
Provide tags and a correct Python 3 solution for this coding contest problem.
During the break, we decided to relax and play dominoes. Our box with Domino was empty, so we decided to borrow the teacher's dominoes.
The teacher responded instantly at our request. He put nm dominoes on the table as an n Γ 2m rectangle so that each of the n rows contained m dominoes arranged horizontally. Each half of each domino contained number (0 or 1).
We were taken aback, and the teacher smiled and said: "Consider some arrangement of dominoes in an n Γ 2m matrix. Let's count for each column of the matrix the sum of numbers in this column. Then among all such sums find the maximum one. Can you rearrange the dominoes in the matrix in such a way that the maximum sum will be minimum possible? Note that it is prohibited to change the orientation of the dominoes, they all need to stay horizontal, nevertheless dominoes are allowed to rotate by 180 degrees. As a reward I will give you all my dominoes".
We got even more taken aback. And while we are wondering what was going on, help us make an optimal matrix of dominoes.
Input
The first line contains integers n, m (1 β€ n, m β€ 103).
In the next lines there is a description of the teachers' matrix. Each of next n lines contains m dominoes. The description of one domino is two integers (0 or 1), written without a space β the digits on the left and right half of the domino.
Output
Print the resulting matrix of dominoes in the format: n lines, each of them contains m space-separated dominoes.
If there are multiple optimal solutions, print any of them.
Examples
Input
2 3
01 11 00
00 01 11
Output
11 11 10
00 00 01
Input
4 1
11
10
01
00
Output
11
10
01
00
Note
Consider the answer for the first sample. There, the maximum sum among all columns equals 1 (the number of columns is 6, and not 3). Obviously, this maximum can't be less than 1, then such matrix is optimal.
Note that the dominoes can be rotated by 180 degrees.
Tags: constructive algorithms, greedy
Correct Solution:
```
n, m = map(int, input().split())
k, d = n * m, 2 * m
c = {'11': 0, '01': 0, '10': 0}
for i in range(n):
t = input()
for i in ('11', '01', '10'): c[i] += t.count(i)
a, b = c['11'], c['10'] + c['01']
t = ['11'] * a + (b // 2) * ['10', '01'] + ['10'] * (b & 1) + ['00'] * (k - a - b)
for i in range(0, k, d):
print(' '.join(t[i: i + m]))
print(' '.join(t[i + d - 1: i + m - 1: -1]))
```
| 12,004 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
During the break, we decided to relax and play dominoes. Our box with Domino was empty, so we decided to borrow the teacher's dominoes.
The teacher responded instantly at our request. He put nm dominoes on the table as an n Γ 2m rectangle so that each of the n rows contained m dominoes arranged horizontally. Each half of each domino contained number (0 or 1).
We were taken aback, and the teacher smiled and said: "Consider some arrangement of dominoes in an n Γ 2m matrix. Let's count for each column of the matrix the sum of numbers in this column. Then among all such sums find the maximum one. Can you rearrange the dominoes in the matrix in such a way that the maximum sum will be minimum possible? Note that it is prohibited to change the orientation of the dominoes, they all need to stay horizontal, nevertheless dominoes are allowed to rotate by 180 degrees. As a reward I will give you all my dominoes".
We got even more taken aback. And while we are wondering what was going on, help us make an optimal matrix of dominoes.
Input
The first line contains integers n, m (1 β€ n, m β€ 103).
In the next lines there is a description of the teachers' matrix. Each of next n lines contains m dominoes. The description of one domino is two integers (0 or 1), written without a space β the digits on the left and right half of the domino.
Output
Print the resulting matrix of dominoes in the format: n lines, each of them contains m space-separated dominoes.
If there are multiple optimal solutions, print any of them.
Examples
Input
2 3
01 11 00
00 01 11
Output
11 11 10
00 00 01
Input
4 1
11
10
01
00
Output
11
10
01
00
Note
Consider the answer for the first sample. There, the maximum sum among all columns equals 1 (the number of columns is 6, and not 3). Obviously, this maximum can't be less than 1, then such matrix is optimal.
Note that the dominoes can be rotated by 180 degrees.
Submitted Solution:
```
n, m = map(int, input().split())
k, d = n * m, 2 * m
c = {'11': 0, '01': 0, '10': 0}
for i in range(n):
t = input()
for i in ('11', '01', '10'): c[i] += t.count(i)
a, b = c['11'], c['10'] + c['01']
t = '11 ' * a + '10 01 ' * (b // 2) + '10 ' * (b & 1) + '00 ' * (k - a - b)
k *= 3; d *= 3; m *= 3
for i in range(0, k, d):
print(t[i: i + m])
print(t[i + m: i + d])
if n & 1: print(t[k - m: m])
```
No
| 12,005 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
During the break, we decided to relax and play dominoes. Our box with Domino was empty, so we decided to borrow the teacher's dominoes.
The teacher responded instantly at our request. He put nm dominoes on the table as an n Γ 2m rectangle so that each of the n rows contained m dominoes arranged horizontally. Each half of each domino contained number (0 or 1).
We were taken aback, and the teacher smiled and said: "Consider some arrangement of dominoes in an n Γ 2m matrix. Let's count for each column of the matrix the sum of numbers in this column. Then among all such sums find the maximum one. Can you rearrange the dominoes in the matrix in such a way that the maximum sum will be minimum possible? Note that it is prohibited to change the orientation of the dominoes, they all need to stay horizontal, nevertheless dominoes are allowed to rotate by 180 degrees. As a reward I will give you all my dominoes".
We got even more taken aback. And while we are wondering what was going on, help us make an optimal matrix of dominoes.
Input
The first line contains integers n, m (1 β€ n, m β€ 103).
In the next lines there is a description of the teachers' matrix. Each of next n lines contains m dominoes. The description of one domino is two integers (0 or 1), written without a space β the digits on the left and right half of the domino.
Output
Print the resulting matrix of dominoes in the format: n lines, each of them contains m space-separated dominoes.
If there are multiple optimal solutions, print any of them.
Examples
Input
2 3
01 11 00
00 01 11
Output
11 11 10
00 00 01
Input
4 1
11
10
01
00
Output
11
10
01
00
Note
Consider the answer for the first sample. There, the maximum sum among all columns equals 1 (the number of columns is 6, and not 3). Obviously, this maximum can't be less than 1, then such matrix is optimal.
Note that the dominoes can be rotated by 180 degrees.
Submitted Solution:
```
a,b=map(int,input().split())
c=list()
cn=list()
x00=0
x01=0
x11=0
for i in range(a):
c.append(list(input().split()))
x11+=c[-1].count('11')
x01+=c[-1].count('01')+c[-1].count('10')
d=x11//b
for i in range(d):
print((b-1)*'11 '+'11')
d=x11%b
e=x01//2
f=(d+e)//b
for i in range(f):
print((d//f)*'11 '+(e//f-1)*'01 '+'01')
print((d//f)*'00 '+(e//f-1)*'10 '+'10')
for i in range(a-d-2*f):
print((b-1)*'00 '+'00')
```
No
| 12,006 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
During the break, we decided to relax and play dominoes. Our box with Domino was empty, so we decided to borrow the teacher's dominoes.
The teacher responded instantly at our request. He put nm dominoes on the table as an n Γ 2m rectangle so that each of the n rows contained m dominoes arranged horizontally. Each half of each domino contained number (0 or 1).
We were taken aback, and the teacher smiled and said: "Consider some arrangement of dominoes in an n Γ 2m matrix. Let's count for each column of the matrix the sum of numbers in this column. Then among all such sums find the maximum one. Can you rearrange the dominoes in the matrix in such a way that the maximum sum will be minimum possible? Note that it is prohibited to change the orientation of the dominoes, they all need to stay horizontal, nevertheless dominoes are allowed to rotate by 180 degrees. As a reward I will give you all my dominoes".
We got even more taken aback. And while we are wondering what was going on, help us make an optimal matrix of dominoes.
Input
The first line contains integers n, m (1 β€ n, m β€ 103).
In the next lines there is a description of the teachers' matrix. Each of next n lines contains m dominoes. The description of one domino is two integers (0 or 1), written without a space β the digits on the left and right half of the domino.
Output
Print the resulting matrix of dominoes in the format: n lines, each of them contains m space-separated dominoes.
If there are multiple optimal solutions, print any of them.
Examples
Input
2 3
01 11 00
00 01 11
Output
11 11 10
00 00 01
Input
4 1
11
10
01
00
Output
11
10
01
00
Note
Consider the answer for the first sample. There, the maximum sum among all columns equals 1 (the number of columns is 6, and not 3). Obviously, this maximum can't be less than 1, then such matrix is optimal.
Note that the dominoes can be rotated by 180 degrees.
Submitted Solution:
```
n, m = map(int, input().split())
doubles, singles = 0, 0
for r in range(n):
for s in input().split():
if s == '11':
doubles += 1
elif s != '00':
singles += 1
lines = {
'zero': ' '.join(m * [ '00' ]),
'double': ' '.join(m * [ '11' ]),
'single_0': ' '.join(m * [ '01' ]),
'single_1': ' '.join(m * [ '10' ])
}
zeros = n * m - doubles - singles
while doubles >= m:
print(lines['double'])
doubles -= m
while singles >= 2 * m:
print(lines['single_0'])
print(lines['single_1'])
singles -= 2 * m
while zeros >= m:
print(lines['zero'])
zeros -= m
tail = [ m * [ '00' ] for r in range((doubles + singles + zeros) // m) ]
if len(tail) >= 1:
for c in range(0, m, 2):
if doubles == 0:
break
tail[0][c] = '11'
doubles -= 1
if len(tail) >= 2 and singles >= 2:
tail[0][c + 1] = '01'
tail[1][c + 1] = '10'
singles -= 2
if len(tail) == 3:
for c in range(1, m, 2):
if doubles == 0:
break
tail[2][c] = '11'
doubles -= 1
for r in range(len(tail)):
if singles == 0:
break
s = '01' if r % 2 == 0 else '10'
for c in range(m):
if singles == 0:
break
if tail[r][c] == '00':
tail[r][c] = s
singles -= 1
for row in tail:
print(' '.join(row))
```
No
| 12,007 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
During the break, we decided to relax and play dominoes. Our box with Domino was empty, so we decided to borrow the teacher's dominoes.
The teacher responded instantly at our request. He put nm dominoes on the table as an n Γ 2m rectangle so that each of the n rows contained m dominoes arranged horizontally. Each half of each domino contained number (0 or 1).
We were taken aback, and the teacher smiled and said: "Consider some arrangement of dominoes in an n Γ 2m matrix. Let's count for each column of the matrix the sum of numbers in this column. Then among all such sums find the maximum one. Can you rearrange the dominoes in the matrix in such a way that the maximum sum will be minimum possible? Note that it is prohibited to change the orientation of the dominoes, they all need to stay horizontal, nevertheless dominoes are allowed to rotate by 180 degrees. As a reward I will give you all my dominoes".
We got even more taken aback. And while we are wondering what was going on, help us make an optimal matrix of dominoes.
Input
The first line contains integers n, m (1 β€ n, m β€ 103).
In the next lines there is a description of the teachers' matrix. Each of next n lines contains m dominoes. The description of one domino is two integers (0 or 1), written without a space β the digits on the left and right half of the domino.
Output
Print the resulting matrix of dominoes in the format: n lines, each of them contains m space-separated dominoes.
If there are multiple optimal solutions, print any of them.
Examples
Input
2 3
01 11 00
00 01 11
Output
11 11 10
00 00 01
Input
4 1
11
10
01
00
Output
11
10
01
00
Note
Consider the answer for the first sample. There, the maximum sum among all columns equals 1 (the number of columns is 6, and not 3). Obviously, this maximum can't be less than 1, then such matrix is optimal.
Note that the dominoes can be rotated by 180 degrees.
Submitted Solution:
```
n, m = map(int, input().split())
doubles, singles = 0, 0
for r in range(n):
for s in input().split():
if s == '11':
doubles += 1
elif s != '00':
singles += 1
lines = {
'zero': ' '.join(m * [ '00' ]),
'double': ' '.join(m * [ '11' ]),
'single_0': ' '.join(m * [ '01' ]),
'single_1': ' '.join(m * [ '10' ])
}
zeros = n * m - doubles - singles
print(zeros, singles, doubles)
while doubles >= m:
print(lines['double'])
doubles -= m
while singles >= 2 * m:
print(lines['single_0'])
print(lines['single_1'])
singles -= 2 * m
while zeros >= m:
print(lines['zero'])
zeros -= m
tail = [ m * [ '00' ] for r in range((doubles + singles + zeros) // m) ]
if len(tail) >= 1:
for c in range(0, m, 2):
if doubles == 0:
break
tail[0][c] = '11'
doubles -= 1
if len(tail) >= 2 and singles >= 2:
tail[0][c + 1] = '01'
tail[1][c + 1] = '10'
singles -= 2
if len(tail) == 3:
for c in range(1, m, 2):
if doubles == 0:
break
tail[2][c] = '11'
doubles -= 1
for r in range(len(tail)):
if singles == 0:
break
s = '01' if r % 2 == 0 else '10'
for c in range(m):
if singles == 0:
break
if tail[r][c] == '00':
tail[r][c] = s
singles -= 1
for row in tail:
print(' '.join(row))
```
No
| 12,008 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You've got array a[1], a[2], ..., a[n], consisting of n integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the same.
More formally, you need to find the number of such pairs of indices i, j (2 β€ i β€ j β€ n - 1), that <image>.
Input
The first line contains integer n (1 β€ n β€ 5Β·105), showing how many numbers are in the array. The second line contains n integers a[1], a[2], ..., a[n] (|a[i]| β€ 109) β the elements of array a.
Output
Print a single integer β the number of ways to split the array into three parts with the same sum.
Examples
Input
5
1 2 3 0 3
Output
2
Input
4
0 1 -1 0
Output
1
Input
2
4 1
Output
0
Tags: binary search, brute force, data structures, dp, two pointers
Correct Solution:
```
n=int(input())
c=list(map(int,input().split()))
pre=[0 for _ in range(n)]
pre[0]=c[0]
for i in range(1,n):
pre[i]=c[i]
pre[i]+=pre[i-1]
#print(pre)
if pre[-1]%3!=0:
print(0)
exit(0)
u,v=0,0
a=pre[-1]//3
for i in range(n):
if pre[i]==2*a and i!=n-1:
v+=u
if pre[i]==a:
u+=1
print(v)
```
| 12,009 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You've got array a[1], a[2], ..., a[n], consisting of n integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the same.
More formally, you need to find the number of such pairs of indices i, j (2 β€ i β€ j β€ n - 1), that <image>.
Input
The first line contains integer n (1 β€ n β€ 5Β·105), showing how many numbers are in the array. The second line contains n integers a[1], a[2], ..., a[n] (|a[i]| β€ 109) β the elements of array a.
Output
Print a single integer β the number of ways to split the array into three parts with the same sum.
Examples
Input
5
1 2 3 0 3
Output
2
Input
4
0 1 -1 0
Output
1
Input
2
4 1
Output
0
Tags: binary search, brute force, data structures, dp, two pointers
Correct Solution:
```
from collections import deque, Counter, OrderedDict
from heapq import nsmallest, nlargest
from math import ceil,floor,log,log2,sqrt,gcd,factorial,pow,pi
def binNumber(n,size=4):
return bin(n)[2:].zfill(size)
def iar():
return list(map(int,input().split()))
def ini():
return int(input())
def isp():
return map(int,input().split())
def sti():
return str(input())
def par(a):
print(' '.join(list(map(str,a))))
def tdl(outerListSize,innerListSize,defaultValue = 0):
return [[defaultValue]*innerListSize for i in range(outerListSize)]
def sts(s):
s = list(s)
s.sort()
return ''.join(s)
class pair:
def __init__(self,f,s):
self.fi = f
self.se = s
def __lt__(self,other):
return (self.fi,self.se) < (other.fi,other.se)
# ========= /\ /| |====/|
# | / \ | | / |
# | /____\ | | / |
# | / \ | | / |
# ========= / \ ===== |/====|
# code
if __name__ == "__main__":
n = ini()
a = iar()
s = sum(a)
if s%3 != 0:
print(0)
quit()
s = s//3
ans,cnt = 0,0
x = 0
for i in range(n-1):
x += a[i]
if x == 2*s:
ans += cnt
if x == s:
cnt += 1
print(ans)
```
| 12,010 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You've got array a[1], a[2], ..., a[n], consisting of n integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the same.
More formally, you need to find the number of such pairs of indices i, j (2 β€ i β€ j β€ n - 1), that <image>.
Input
The first line contains integer n (1 β€ n β€ 5Β·105), showing how many numbers are in the array. The second line contains n integers a[1], a[2], ..., a[n] (|a[i]| β€ 109) β the elements of array a.
Output
Print a single integer β the number of ways to split the array into three parts with the same sum.
Examples
Input
5
1 2 3 0 3
Output
2
Input
4
0 1 -1 0
Output
1
Input
2
4 1
Output
0
Tags: binary search, brute force, data structures, dp, two pointers
Correct Solution:
```
elements = int(input())
arr = list(map(int,input().split()))
arr_sum, answer, count, temp_sum = sum(arr), 0, 0, 0
if arr_sum % 3 == 0:
arr_sum = arr_sum / 3
for i in range(elements - 1):
temp_sum = temp_sum + arr[i]
if temp_sum == 2 * arr_sum: answer = answer + count
if temp_sum == arr_sum: count = count + 1
print(answer)
```
| 12,011 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You've got array a[1], a[2], ..., a[n], consisting of n integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the same.
More formally, you need to find the number of such pairs of indices i, j (2 β€ i β€ j β€ n - 1), that <image>.
Input
The first line contains integer n (1 β€ n β€ 5Β·105), showing how many numbers are in the array. The second line contains n integers a[1], a[2], ..., a[n] (|a[i]| β€ 109) β the elements of array a.
Output
Print a single integer β the number of ways to split the array into three parts with the same sum.
Examples
Input
5
1 2 3 0 3
Output
2
Input
4
0 1 -1 0
Output
1
Input
2
4 1
Output
0
Tags: binary search, brute force, data structures, dp, two pointers
Correct Solution:
```
n = int(input())
*arr , = map(int , input().split())
prefix_arr = [0 for i in range(n)]
prefix_arr[0] = arr[0]
for i in range(1 ,n):
prefix_arr[i] = arr[i] + prefix_arr[i-1]
ans = fac = 0
# print(*prefix_arr)
for i in range(n-1):
if prefix_arr[i]*3 == prefix_arr[n-1]*2:
ans += fac
# print('a')
if prefix_arr[i]*3 == prefix_arr[n-1]:
# print('f')
fac += 1
print(ans)
```
| 12,012 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You've got array a[1], a[2], ..., a[n], consisting of n integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the same.
More formally, you need to find the number of such pairs of indices i, j (2 β€ i β€ j β€ n - 1), that <image>.
Input
The first line contains integer n (1 β€ n β€ 5Β·105), showing how many numbers are in the array. The second line contains n integers a[1], a[2], ..., a[n] (|a[i]| β€ 109) β the elements of array a.
Output
Print a single integer β the number of ways to split the array into three parts with the same sum.
Examples
Input
5
1 2 3 0 3
Output
2
Input
4
0 1 -1 0
Output
1
Input
2
4 1
Output
0
Tags: binary search, brute force, data structures, dp, two pointers
Correct Solution:
```
n = int(input())
a = [int(x) for x in input().split()]
s = sum(a)
if s % 3 != 0:
print(0)
else:
b = [a[0]]
s = s//3
for i in range(1,n):
b.append(b[i-1]+a[i])
if s==0:
m = b.count(0)
print((m-1) *(m-2) //2 if m>2 else 0)
else:
t = 0
c = [0]
for i in range(n-1,-1,-1):
if b[i] == s*2:
t+=1
elif b[i] == s:
c.append(t+c[-1])
t = 0
print(sum(c))
```
| 12,013 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You've got array a[1], a[2], ..., a[n], consisting of n integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the same.
More formally, you need to find the number of such pairs of indices i, j (2 β€ i β€ j β€ n - 1), that <image>.
Input
The first line contains integer n (1 β€ n β€ 5Β·105), showing how many numbers are in the array. The second line contains n integers a[1], a[2], ..., a[n] (|a[i]| β€ 109) β the elements of array a.
Output
Print a single integer β the number of ways to split the array into three parts with the same sum.
Examples
Input
5
1 2 3 0 3
Output
2
Input
4
0 1 -1 0
Output
1
Input
2
4 1
Output
0
Tags: binary search, brute force, data structures, dp, two pointers
Correct Solution:
```
n = int(input())
a = list(map(int, input().split()))
s = sum(a)
m = 0
c = 0
ans = 0
if s % 3 == 0:
s //= 3
for i in range(n-1):
m += a[i]
if m == s * 2:
ans += c
if m == s:
c += 1
print(ans)
```
| 12,014 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You've got array a[1], a[2], ..., a[n], consisting of n integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the same.
More formally, you need to find the number of such pairs of indices i, j (2 β€ i β€ j β€ n - 1), that <image>.
Input
The first line contains integer n (1 β€ n β€ 5Β·105), showing how many numbers are in the array. The second line contains n integers a[1], a[2], ..., a[n] (|a[i]| β€ 109) β the elements of array a.
Output
Print a single integer β the number of ways to split the array into three parts with the same sum.
Examples
Input
5
1 2 3 0 3
Output
2
Input
4
0 1 -1 0
Output
1
Input
2
4 1
Output
0
Tags: binary search, brute force, data structures, dp, two pointers
Correct Solution:
```
n = int(input())
a = list(map(int, input().split()))
ret, s = 0, sum(a)
if s % 3 == 0:
p1 = s // 3
p2 = s - p1
s = c = 0
for i in range(n - 1):
s += a[i]
if s == p2:
ret += c
if s == p1:
c += 1
print(ret)
```
| 12,015 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You've got array a[1], a[2], ..., a[n], consisting of n integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the same.
More formally, you need to find the number of such pairs of indices i, j (2 β€ i β€ j β€ n - 1), that <image>.
Input
The first line contains integer n (1 β€ n β€ 5Β·105), showing how many numbers are in the array. The second line contains n integers a[1], a[2], ..., a[n] (|a[i]| β€ 109) β the elements of array a.
Output
Print a single integer β the number of ways to split the array into three parts with the same sum.
Examples
Input
5
1 2 3 0 3
Output
2
Input
4
0 1 -1 0
Output
1
Input
2
4 1
Output
0
Tags: binary search, brute force, data structures, dp, two pointers
Correct Solution:
```
def countways(a, n):
cnt = [0 for i in range(n)]
s = 0
s = sum(a)
if (s % 3 != 0):
return 0
s //= 3
ss = 0
for i in range(n - 1, -1, -1):
ss += a[i]
if (ss == s):
cnt[i] = 1
for i in range(n - 2, -1, -1):
cnt[i] += cnt[i + 1]
ans = 0
ss = 0
for i in range(0, n - 2):
ss += a[i]
if (ss == s):
ans += cnt[i + 2]
return ans
n=int(input())
a=list(map(int,input().split()))
print(countways(a,n))
```
| 12,016 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You've got array a[1], a[2], ..., a[n], consisting of n integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the same.
More formally, you need to find the number of such pairs of indices i, j (2 β€ i β€ j β€ n - 1), that <image>.
Input
The first line contains integer n (1 β€ n β€ 5Β·105), showing how many numbers are in the array. The second line contains n integers a[1], a[2], ..., a[n] (|a[i]| β€ 109) β the elements of array a.
Output
Print a single integer β the number of ways to split the array into three parts with the same sum.
Examples
Input
5
1 2 3 0 3
Output
2
Input
4
0 1 -1 0
Output
1
Input
2
4 1
Output
0
Submitted Solution:
```
from bisect import bisect_left
def bini(a,x):
i=bisect_left(a,x)
return i;
a=int(input())
z=list(map(int,input().split()))
if(sum(z)%3!=0):
print(0)
else:
t=sum(z)//3
total=0
count=0
save=[]
save1=[]
ans=[]
for i in range(len(z)):
total=total+z[i]
if(total==t and i!=len(z)-1):
save.append(i)
if(total==2*t and i!=0 and i!=len(z)-1):
save1.append(i)
for i in range(len(save1)):
ans.append(bini(save,save1[i]))
print(sum(ans))
```
Yes
| 12,017 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You've got array a[1], a[2], ..., a[n], consisting of n integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the same.
More formally, you need to find the number of such pairs of indices i, j (2 β€ i β€ j β€ n - 1), that <image>.
Input
The first line contains integer n (1 β€ n β€ 5Β·105), showing how many numbers are in the array. The second line contains n integers a[1], a[2], ..., a[n] (|a[i]| β€ 109) β the elements of array a.
Output
Print a single integer β the number of ways to split the array into three parts with the same sum.
Examples
Input
5
1 2 3 0 3
Output
2
Input
4
0 1 -1 0
Output
1
Input
2
4 1
Output
0
Submitted Solution:
```
n=int(input())
a=[int(x) for x in input().split()]
s=sum(a)
if s%3!=0:
print(0)
else:
s1=s/3;s2=2*s1
tick1=tick2=num=0
for i in range(n-1):
tick2+=a[i]
if tick2==s2:
num+=tick1
if tick2==s1:
tick1+=1
print(num)
```
Yes
| 12,018 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You've got array a[1], a[2], ..., a[n], consisting of n integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the same.
More formally, you need to find the number of such pairs of indices i, j (2 β€ i β€ j β€ n - 1), that <image>.
Input
The first line contains integer n (1 β€ n β€ 5Β·105), showing how many numbers are in the array. The second line contains n integers a[1], a[2], ..., a[n] (|a[i]| β€ 109) β the elements of array a.
Output
Print a single integer β the number of ways to split the array into three parts with the same sum.
Examples
Input
5
1 2 3 0 3
Output
2
Input
4
0 1 -1 0
Output
1
Input
2
4 1
Output
0
Submitted Solution:
```
n = int(input())
x = input().split()
a = list(int(x[i]) for i in range(len(x)))
way = 0
suma = sum(a[i] for i in range(len(a)))
if (suma % 3 > 0) or (len(a) < 3):
print(0)
else:
sign = 1
target = suma // 3
if target == 0:
segment = 0
sumseg = 0
for i in range(len(a)):
sumseg += a[i]
if sumseg == 0:
segment += 1
way = (segment - 1) * (segment - 2) // 2
else:
sumseg = 0
list0 = []
dict0 = {}
dict1 = {}
i = 1
while i < len(a) - 1:
if a[i] == 0:
i0 = i - 1
while a[i] == 0:
i += 1
dict0[i0] = dict1[i] = i - i0
else:
i += 1
i = 0
while i < len(a) - 2:
sumseg += a[i]
if sumseg == target:
list0.insert(0, i)
if i in dict0.keys():
i += dict0[i]
continue
i += 1
sumseg = 0
list1 = []
i = len(a) - 1
while i > 1:
sumseg += a[i]
if sumseg == target:
list1.insert(0, i)
if i in dict1.keys():
i -= dict1[i]
continue
i -= 1
flag = 0
sumlist1 = 0
sumlist0 = 0
for i in range(len(list1)):
sumlist1 += 1 if list1[i] not in dict1.keys() else dict1[list1[i]]
for i in range(len(list0)):
sumlist0 += 1 if list0[i] not in dict0.keys() else dict0[list0[i]]
minusadd = 0
for i in range(len(list0)):
if list0[i] < list1[0]:
break
else:
for j in range(len(list1)):
if list0[i] < list1[j]:
for k in range(j):
minusadd += (1 if list1[j] not in dict1.keys() else dict1[list1[j]]) * (1 if list0[i] not in dict0.keys() else dict0[list0[i]])
break
way = sumlist1 * sumlist0 - minusadd
print(way)
```
Yes
| 12,019 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You've got array a[1], a[2], ..., a[n], consisting of n integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the same.
More formally, you need to find the number of such pairs of indices i, j (2 β€ i β€ j β€ n - 1), that <image>.
Input
The first line contains integer n (1 β€ n β€ 5Β·105), showing how many numbers are in the array. The second line contains n integers a[1], a[2], ..., a[n] (|a[i]| β€ 109) β the elements of array a.
Output
Print a single integer β the number of ways to split the array into three parts with the same sum.
Examples
Input
5
1 2 3 0 3
Output
2
Input
4
0 1 -1 0
Output
1
Input
2
4 1
Output
0
Submitted Solution:
```
n = int(input())
li = list(map(int, input().split()))
if(sum(li)%3 != 0):
print(0)
quit()
t = sum(li)//3
for i in range(1, n):
li[i] += li[i-1]
cnt = [0]*n
for i in range(n-2, -1, -1):
cnt[i] = cnt[i+1]
if li[i] == 2*t:
cnt[i] += 1
ans = 0
for i in range(0, n-1):
if li[i] != t:
continue
ans += cnt[i+1]
print(ans)
```
Yes
| 12,020 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You've got array a[1], a[2], ..., a[n], consisting of n integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the same.
More formally, you need to find the number of such pairs of indices i, j (2 β€ i β€ j β€ n - 1), that <image>.
Input
The first line contains integer n (1 β€ n β€ 5Β·105), showing how many numbers are in the array. The second line contains n integers a[1], a[2], ..., a[n] (|a[i]| β€ 109) β the elements of array a.
Output
Print a single integer β the number of ways to split the array into three parts with the same sum.
Examples
Input
5
1 2 3 0 3
Output
2
Input
4
0 1 -1 0
Output
1
Input
2
4 1
Output
0
Submitted Solution:
```
n=int(input())
num=input()
list=[int(x) for x in num.split()]
tol=sum(list)
s=0
t=0
w=0
if tol%3!=0:
print(0)
else:
t3=int(tol/3)
for i in range(n):
s+=list[i]
if s==t3:
t=0
for j in range(i+1,n-1):
t+=list[j]
if t==t3:
w+=0
print(w)
```
No
| 12,021 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You've got array a[1], a[2], ..., a[n], consisting of n integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the same.
More formally, you need to find the number of such pairs of indices i, j (2 β€ i β€ j β€ n - 1), that <image>.
Input
The first line contains integer n (1 β€ n β€ 5Β·105), showing how many numbers are in the array. The second line contains n integers a[1], a[2], ..., a[n] (|a[i]| β€ 109) β the elements of array a.
Output
Print a single integer β the number of ways to split the array into three parts with the same sum.
Examples
Input
5
1 2 3 0 3
Output
2
Input
4
0 1 -1 0
Output
1
Input
2
4 1
Output
0
Submitted Solution:
```
n, a = int(input()), list(map(int, input().split()))
sums, s = [[0, 0]] + [0] * n, sum(a)
for i in range(n):
sums[i + 1] = [sums[i][0] + a[i], sums[i][1] + int(i and (sums[i][0] + a[i]) * 3 == s * 2)]
print(0 if s % 3 else sum(sums[-1][1] - sums[i][1] for i in range(2, n) if sums[i][0] * 3 == s))
```
No
| 12,022 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You've got array a[1], a[2], ..., a[n], consisting of n integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the same.
More formally, you need to find the number of such pairs of indices i, j (2 β€ i β€ j β€ n - 1), that <image>.
Input
The first line contains integer n (1 β€ n β€ 5Β·105), showing how many numbers are in the array. The second line contains n integers a[1], a[2], ..., a[n] (|a[i]| β€ 109) β the elements of array a.
Output
Print a single integer β the number of ways to split the array into three parts with the same sum.
Examples
Input
5
1 2 3 0 3
Output
2
Input
4
0 1 -1 0
Output
1
Input
2
4 1
Output
0
Submitted Solution:
```
n=int(input())
ch=str(input())
LLL=ch.split()
L=list()
L1=list()
total=0
for c in LLL:
L.append(int(c))
total+=int(c)
L1.append(total)
if (total%3!=0):
print(0)
elif (total!=0):
c1=0
c2=0
res=0
for i in range(0,n-1):
if L1[i]==total//3:
c1+=1
if (L1[i]==(total//3)*2) and (i!=0) and (i!=n-1):
res+=c1
print(res)
else:
print(1)
```
No
| 12,023 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You've got array a[1], a[2], ..., a[n], consisting of n integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the same.
More formally, you need to find the number of such pairs of indices i, j (2 β€ i β€ j β€ n - 1), that <image>.
Input
The first line contains integer n (1 β€ n β€ 5Β·105), showing how many numbers are in the array. The second line contains n integers a[1], a[2], ..., a[n] (|a[i]| β€ 109) β the elements of array a.
Output
Print a single integer β the number of ways to split the array into three parts with the same sum.
Examples
Input
5
1 2 3 0 3
Output
2
Input
4
0 1 -1 0
Output
1
Input
2
4 1
Output
0
Submitted Solution:
```
# -*- coding: utf-8 -*-
"""
Created on Fri Nov 20 17:44:41 2020
@author: 17831
"""
n = int(input())
a = [int(x) for x in input().split()]
b = int(sum(a)/3)
def factorial(num):
if num == 0 or num == 1:
return 1
else:
return (num*factorial(num-1))
if b != int(b):
print(0)
elif b == 0:
q = 0
num = 0
for i in range(n):
q+=a[i]
if q == b or q == 2*b:
num+=1
else:
pass
print(num)
print(int(factorial(num-1)/(factorial(num-3)*2)))
else:
p = 0
first = 0
second = 0
third = 0
for i in range(n):
p+=a[i]
if p == b:
first+=1
elif p == 2*b:
second+=1
elif p == 3*b:
third+=1
else:
pass
print(first*second*third)
```
No
| 12,024 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodorβs parents and sometimes from anonymous benefactors, in which case it is hard to determine to which one of them the package has been sent. A photographic rifle is obviously for Sharic who loves hunting and fish is for Matroskin, but for whom was a new video game console meant? Every one of the three friends claimed that the present is for him and nearly quarreled. Uncle Fyodor had an idea how to solve the problem justly: they should suppose that the console was sent to all three of them and play it in turns. Everybody got relieved but then yet another burning problem popped up β who will play first? This time Matroskin came up with a brilliant solution, suggesting the most fair way to find it out: play rock-paper-scissors together. The rules of the game are very simple. On the count of three every player shows a combination with his hand (or paw). The combination corresponds to one of three things: a rock, scissors or paper. Some of the gestures win over some other ones according to well-known rules: the rock breaks the scissors, the scissors cut the paper, and the paper gets wrapped over the stone. Usually there are two players. Yet there are three friends, thatβs why they decided to choose the winner like that: If someone shows the gesture that wins over the other two players, then that player wins. Otherwise, another game round is required. Write a program that will determine the winner by the gestures they have shown.
Input
The first input line contains the name of the gesture that Uncle Fyodor showed, the second line shows which gesture Matroskin showed and the third line shows Sharicβs gesture.
Output
Print "F" (without quotes) if Uncle Fyodor wins. Print "M" if Matroskin wins and "S" if Sharic wins. If it is impossible to find the winner, print "?".
Examples
Input
rock
rock
rock
Output
?
Input
paper
rock
rock
Output
F
Input
scissors
rock
rock
Output
?
Input
scissors
paper
rock
Output
?
Tags: implementation, schedules
Correct Solution:
```
import sys
a, b, c = input().strip(), input().strip(), input().strip()
def beats(x, y):
if x == 'rock' and y == 'scissors':
return True
if x == 'scissors' and y == 'paper':
return True
if x == 'paper' and y == 'rock':
return True
return False
if beats(a, b) and beats(a, c):
print('F')
elif beats(b, a) and beats(b, c):
print('M')
elif beats(c, a) and beats(c, b):
print('S')
else:
print('?')
```
| 12,025 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodorβs parents and sometimes from anonymous benefactors, in which case it is hard to determine to which one of them the package has been sent. A photographic rifle is obviously for Sharic who loves hunting and fish is for Matroskin, but for whom was a new video game console meant? Every one of the three friends claimed that the present is for him and nearly quarreled. Uncle Fyodor had an idea how to solve the problem justly: they should suppose that the console was sent to all three of them and play it in turns. Everybody got relieved but then yet another burning problem popped up β who will play first? This time Matroskin came up with a brilliant solution, suggesting the most fair way to find it out: play rock-paper-scissors together. The rules of the game are very simple. On the count of three every player shows a combination with his hand (or paw). The combination corresponds to one of three things: a rock, scissors or paper. Some of the gestures win over some other ones according to well-known rules: the rock breaks the scissors, the scissors cut the paper, and the paper gets wrapped over the stone. Usually there are two players. Yet there are three friends, thatβs why they decided to choose the winner like that: If someone shows the gesture that wins over the other two players, then that player wins. Otherwise, another game round is required. Write a program that will determine the winner by the gestures they have shown.
Input
The first input line contains the name of the gesture that Uncle Fyodor showed, the second line shows which gesture Matroskin showed and the third line shows Sharicβs gesture.
Output
Print "F" (without quotes) if Uncle Fyodor wins. Print "M" if Matroskin wins and "S" if Sharic wins. If it is impossible to find the winner, print "?".
Examples
Input
rock
rock
rock
Output
?
Input
paper
rock
rock
Output
F
Input
scissors
rock
rock
Output
?
Input
scissors
paper
rock
Output
?
Tags: implementation, schedules
Correct Solution:
```
F=input()
M=input()
S=input()
Beater={"rock":"paper","paper":"scissors","scissors":"rock"}
if(F==M and S==Beater[F]):
print("S")
elif(F==S and M==Beater[F]):
print("M")
elif(S==M and F==Beater[S]):
print("F")
else:
print("?")
```
| 12,026 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodorβs parents and sometimes from anonymous benefactors, in which case it is hard to determine to which one of them the package has been sent. A photographic rifle is obviously for Sharic who loves hunting and fish is for Matroskin, but for whom was a new video game console meant? Every one of the three friends claimed that the present is for him and nearly quarreled. Uncle Fyodor had an idea how to solve the problem justly: they should suppose that the console was sent to all three of them and play it in turns. Everybody got relieved but then yet another burning problem popped up β who will play first? This time Matroskin came up with a brilliant solution, suggesting the most fair way to find it out: play rock-paper-scissors together. The rules of the game are very simple. On the count of three every player shows a combination with his hand (or paw). The combination corresponds to one of three things: a rock, scissors or paper. Some of the gestures win over some other ones according to well-known rules: the rock breaks the scissors, the scissors cut the paper, and the paper gets wrapped over the stone. Usually there are two players. Yet there are three friends, thatβs why they decided to choose the winner like that: If someone shows the gesture that wins over the other two players, then that player wins. Otherwise, another game round is required. Write a program that will determine the winner by the gestures they have shown.
Input
The first input line contains the name of the gesture that Uncle Fyodor showed, the second line shows which gesture Matroskin showed and the third line shows Sharicβs gesture.
Output
Print "F" (without quotes) if Uncle Fyodor wins. Print "M" if Matroskin wins and "S" if Sharic wins. If it is impossible to find the winner, print "?".
Examples
Input
rock
rock
rock
Output
?
Input
paper
rock
rock
Output
F
Input
scissors
rock
rock
Output
?
Input
scissors
paper
rock
Output
?
Tags: implementation, schedules
Correct Solution:
```
a=input()
b=input()
c=input()
if (a==b and b==c) or (a!=b and b!=c and a!=c):
print('?')
elif (a=='rock' and b=='scissors' and b==c) or (a=='paper' and b=='rock' and b==c) or (a=='scissors' and b=='paper' and b==c):
print('F')
elif (b=='rock' and a=='scissors' and a==c) or (b=='paper' and a=='rock' and a==c) or (b=='scissors' and a=='paper' and a==c):
print('M')
elif (a=='rock' and ((b=='rock' and c=='scissors') or (c=='rock' and b=='scissors'))) or (b=='rock' and ((a=='rock' and c=='scissors') or (c=='rock' and a=='scissors'))) or (c=='rock' and ((b=='rock' and a=='scissors') or (a=='rock' and b=='scissors'))):
print('?')
elif (a=='paper' and ((b=='paper' and c=='rock') or (c=='paper' and b=='rock'))) or (b=='paper' and ((a=='rock' and c=='paper') or (c=='rock' and a=='paper'))) or (c=='paper' and ((b=='rock' and a=='paper') or (a=='rock' and b=='paper'))):
print('?')
elif (a=='scissors' and ((b=='paper' and c=='scissors') or (c=='paper' and b=='scissors'))) or (b=='scissors' and ((a=='scissors' and c=='paper') or (c=='scissors' and a=='paper'))) or (c=='scissors' and ((b=='scissors' and a=='paper') or (a=='scissors' and b=='paper'))):
print('?')
else:
print('S')
```
| 12,027 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodorβs parents and sometimes from anonymous benefactors, in which case it is hard to determine to which one of them the package has been sent. A photographic rifle is obviously for Sharic who loves hunting and fish is for Matroskin, but for whom was a new video game console meant? Every one of the three friends claimed that the present is for him and nearly quarreled. Uncle Fyodor had an idea how to solve the problem justly: they should suppose that the console was sent to all three of them and play it in turns. Everybody got relieved but then yet another burning problem popped up β who will play first? This time Matroskin came up with a brilliant solution, suggesting the most fair way to find it out: play rock-paper-scissors together. The rules of the game are very simple. On the count of three every player shows a combination with his hand (or paw). The combination corresponds to one of three things: a rock, scissors or paper. Some of the gestures win over some other ones according to well-known rules: the rock breaks the scissors, the scissors cut the paper, and the paper gets wrapped over the stone. Usually there are two players. Yet there are three friends, thatβs why they decided to choose the winner like that: If someone shows the gesture that wins over the other two players, then that player wins. Otherwise, another game round is required. Write a program that will determine the winner by the gestures they have shown.
Input
The first input line contains the name of the gesture that Uncle Fyodor showed, the second line shows which gesture Matroskin showed and the third line shows Sharicβs gesture.
Output
Print "F" (without quotes) if Uncle Fyodor wins. Print "M" if Matroskin wins and "S" if Sharic wins. If it is impossible to find the winner, print "?".
Examples
Input
rock
rock
rock
Output
?
Input
paper
rock
rock
Output
F
Input
scissors
rock
rock
Output
?
Input
scissors
paper
rock
Output
?
Tags: implementation, schedules
Correct Solution:
```
F=str(input())
M=str(input())
W=str(input())
if F=="rock" and M=="scissors" and W=="scissors":
print("F")
elif F=="rock" and M=="paper" and W=="rock":
print("M")
elif F=="rock" and M=="rock" and W=="paper":
print("S")
elif F=="paper" and M=="rock" and W=="rock":
print("F")
elif F=="scissors" and M=="paper" and W=="paper":
print("F")
elif F=="scissors" and M=="scissors" and W=="rock":
print("S")
elif F=="paper" and M=="scissors" and W=="paper":
print("M")
elif F=="scissors" and M=="rock" and W=="scissors":
print("M")
elif F=="paper" and M=="paper" and W=="scissors":
print("S")
else:
print("?")
```
| 12,028 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodorβs parents and sometimes from anonymous benefactors, in which case it is hard to determine to which one of them the package has been sent. A photographic rifle is obviously for Sharic who loves hunting and fish is for Matroskin, but for whom was a new video game console meant? Every one of the three friends claimed that the present is for him and nearly quarreled. Uncle Fyodor had an idea how to solve the problem justly: they should suppose that the console was sent to all three of them and play it in turns. Everybody got relieved but then yet another burning problem popped up β who will play first? This time Matroskin came up with a brilliant solution, suggesting the most fair way to find it out: play rock-paper-scissors together. The rules of the game are very simple. On the count of three every player shows a combination with his hand (or paw). The combination corresponds to one of three things: a rock, scissors or paper. Some of the gestures win over some other ones according to well-known rules: the rock breaks the scissors, the scissors cut the paper, and the paper gets wrapped over the stone. Usually there are two players. Yet there are three friends, thatβs why they decided to choose the winner like that: If someone shows the gesture that wins over the other two players, then that player wins. Otherwise, another game round is required. Write a program that will determine the winner by the gestures they have shown.
Input
The first input line contains the name of the gesture that Uncle Fyodor showed, the second line shows which gesture Matroskin showed and the third line shows Sharicβs gesture.
Output
Print "F" (without quotes) if Uncle Fyodor wins. Print "M" if Matroskin wins and "S" if Sharic wins. If it is impossible to find the winner, print "?".
Examples
Input
rock
rock
rock
Output
?
Input
paper
rock
rock
Output
F
Input
scissors
rock
rock
Output
?
Input
scissors
paper
rock
Output
?
Tags: implementation, schedules
Correct Solution:
```
F = input()
M = input()
S = input()
ans = ["F", "M","S"]
#print(set([F,M,S]))
if len(set([F,M,S]))!=2:
print("?")
else:
if [F,M,S].count("rock")==2:
if "paper" in [F,M,S]:print(ans[[F,M,S].index("paper")])
else:print("?")
elif [F,M,S].count("paper")==2:
if "scissors" in [F,M,S]:print(ans[[F,M,S].index("scissors")])
else:print("?")
else:
if "rock" in [F,M,S]:
print(ans[[F,M,S].index("rock")])
else:
print("?")
```
| 12,029 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodorβs parents and sometimes from anonymous benefactors, in which case it is hard to determine to which one of them the package has been sent. A photographic rifle is obviously for Sharic who loves hunting and fish is for Matroskin, but for whom was a new video game console meant? Every one of the three friends claimed that the present is for him and nearly quarreled. Uncle Fyodor had an idea how to solve the problem justly: they should suppose that the console was sent to all three of them and play it in turns. Everybody got relieved but then yet another burning problem popped up β who will play first? This time Matroskin came up with a brilliant solution, suggesting the most fair way to find it out: play rock-paper-scissors together. The rules of the game are very simple. On the count of three every player shows a combination with his hand (or paw). The combination corresponds to one of three things: a rock, scissors or paper. Some of the gestures win over some other ones according to well-known rules: the rock breaks the scissors, the scissors cut the paper, and the paper gets wrapped over the stone. Usually there are two players. Yet there are three friends, thatβs why they decided to choose the winner like that: If someone shows the gesture that wins over the other two players, then that player wins. Otherwise, another game round is required. Write a program that will determine the winner by the gestures they have shown.
Input
The first input line contains the name of the gesture that Uncle Fyodor showed, the second line shows which gesture Matroskin showed and the third line shows Sharicβs gesture.
Output
Print "F" (without quotes) if Uncle Fyodor wins. Print "M" if Matroskin wins and "S" if Sharic wins. If it is impossible to find the winner, print "?".
Examples
Input
rock
rock
rock
Output
?
Input
paper
rock
rock
Output
F
Input
scissors
rock
rock
Output
?
Input
scissors
paper
rock
Output
?
Tags: implementation, schedules
Correct Solution:
```
f = ""
m = ""
s = ""
paper = "paper"
rock = "rock"
scissors = "scissors"
def compare(f, s, m):
if f == s and s == m:
return "?"
# F wins
if f == paper:
if s == rock and m == rock:
return "F"
if f == rock:
if s == scissors and m == scissors:
return "F"
if f == scissors:
if s == paper and m == paper:
return "F"
# M wins
if m == paper:
if s == rock and f == rock:
return "M"
if m == rock:
if s == scissors and f == scissors:
return "M"
if m == scissors:
if s == paper and f == paper:
return "M"
# S wins
if s == paper:
if m == rock and f == rock:
return "S"
if s == rock:
if m == scissors and f == scissors:
return "S"
if s == scissors:
if m == paper and f == paper:
return "S"
# Nobody wins
return "?"
def main(inputs):
f = inputs[0]
m = inputs[1]
s = inputs[2]
print(compare(f, s, m))
import sys
inputs = sys.stdin.read().split()
main(inputs)
```
| 12,030 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodorβs parents and sometimes from anonymous benefactors, in which case it is hard to determine to which one of them the package has been sent. A photographic rifle is obviously for Sharic who loves hunting and fish is for Matroskin, but for whom was a new video game console meant? Every one of the three friends claimed that the present is for him and nearly quarreled. Uncle Fyodor had an idea how to solve the problem justly: they should suppose that the console was sent to all three of them and play it in turns. Everybody got relieved but then yet another burning problem popped up β who will play first? This time Matroskin came up with a brilliant solution, suggesting the most fair way to find it out: play rock-paper-scissors together. The rules of the game are very simple. On the count of three every player shows a combination with his hand (or paw). The combination corresponds to one of three things: a rock, scissors or paper. Some of the gestures win over some other ones according to well-known rules: the rock breaks the scissors, the scissors cut the paper, and the paper gets wrapped over the stone. Usually there are two players. Yet there are three friends, thatβs why they decided to choose the winner like that: If someone shows the gesture that wins over the other two players, then that player wins. Otherwise, another game round is required. Write a program that will determine the winner by the gestures they have shown.
Input
The first input line contains the name of the gesture that Uncle Fyodor showed, the second line shows which gesture Matroskin showed and the third line shows Sharicβs gesture.
Output
Print "F" (without quotes) if Uncle Fyodor wins. Print "M" if Matroskin wins and "S" if Sharic wins. If it is impossible to find the winner, print "?".
Examples
Input
rock
rock
rock
Output
?
Input
paper
rock
rock
Output
F
Input
scissors
rock
rock
Output
?
Input
scissors
paper
rock
Output
?
Tags: implementation, schedules
Correct Solution:
```
f = input()
m = input()
s = input()
t = [f, m, s]
if t.count('rock') == 3 or t.count('paper') == 3 or t.count('scissors') == 3:
print('?')
exit()
if t.count('rock') == 1 and t.count('paper') == 1 and t.count('scissors') == 1:
print('?')
exit()
if t.count('rock') == 2:
if t.count('paper') == 1:
d = t.index('paper')
if d == 0:
print('F')
exit()
if d == 1:
print('M')
exit()
if d == 2:
print('S')
exit()
if t.count('scissors'):
print('?')
exit()
if t.count('paper') == 2:
if t.count('scissors') == 1:
d = t.index('scissors')
if d == 0:
print('F')
exit()
if d == 1:
print('M')
exit()
if d == 2:
print('S')
exit()
if t.count('rock'):
print('?')
exit()
if t.count('scissors') == 2:
if t.count('rock') == 1:
d = t.index('rock')
if d == 0:
print('F')
exit()
if d == 1:
print('M')
exit()
if d == 2:
print('S')
exit()
if t.count('paper'):
print('?')
exit()
```
| 12,031 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodorβs parents and sometimes from anonymous benefactors, in which case it is hard to determine to which one of them the package has been sent. A photographic rifle is obviously for Sharic who loves hunting and fish is for Matroskin, but for whom was a new video game console meant? Every one of the three friends claimed that the present is for him and nearly quarreled. Uncle Fyodor had an idea how to solve the problem justly: they should suppose that the console was sent to all three of them and play it in turns. Everybody got relieved but then yet another burning problem popped up β who will play first? This time Matroskin came up with a brilliant solution, suggesting the most fair way to find it out: play rock-paper-scissors together. The rules of the game are very simple. On the count of three every player shows a combination with his hand (or paw). The combination corresponds to one of three things: a rock, scissors or paper. Some of the gestures win over some other ones according to well-known rules: the rock breaks the scissors, the scissors cut the paper, and the paper gets wrapped over the stone. Usually there are two players. Yet there are three friends, thatβs why they decided to choose the winner like that: If someone shows the gesture that wins over the other two players, then that player wins. Otherwise, another game round is required. Write a program that will determine the winner by the gestures they have shown.
Input
The first input line contains the name of the gesture that Uncle Fyodor showed, the second line shows which gesture Matroskin showed and the third line shows Sharicβs gesture.
Output
Print "F" (without quotes) if Uncle Fyodor wins. Print "M" if Matroskin wins and "S" if Sharic wins. If it is impossible to find the winner, print "?".
Examples
Input
rock
rock
rock
Output
?
Input
paper
rock
rock
Output
F
Input
scissors
rock
rock
Output
?
Input
scissors
paper
rock
Output
?
Tags: implementation, schedules
Correct Solution:
```
def winner(f,s):
if f == "r":
if s == "r":
return 0
elif s == "s":
return 1
return -1
elif f == "s":
if s == "s":
return 0
elif s == "p":
return 1
return -1
else:
if s == "p":
return 0
elif s == "r":
return 1
return -1
f = input()[0]
m = input()[0]
s = input()[0]
###rpsr
if (f != m and f != s and m != s) or (f == m and m == s):
print("?")
elif (winner(f,m) == 0 and winner(f,s) == 1) or (winner(f,s) == 0 and winner(f,m) == 1) or (winner(s,m) == 0 and winner(s,f) == 1):
print("?")
else:
print("F" *winner(f,m) + "M" * winner(m,f )+ "S" * winner(s,m))
```
| 12,032 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodorβs parents and sometimes from anonymous benefactors, in which case it is hard to determine to which one of them the package has been sent. A photographic rifle is obviously for Sharic who loves hunting and fish is for Matroskin, but for whom was a new video game console meant? Every one of the three friends claimed that the present is for him and nearly quarreled. Uncle Fyodor had an idea how to solve the problem justly: they should suppose that the console was sent to all three of them and play it in turns. Everybody got relieved but then yet another burning problem popped up β who will play first? This time Matroskin came up with a brilliant solution, suggesting the most fair way to find it out: play rock-paper-scissors together. The rules of the game are very simple. On the count of three every player shows a combination with his hand (or paw). The combination corresponds to one of three things: a rock, scissors or paper. Some of the gestures win over some other ones according to well-known rules: the rock breaks the scissors, the scissors cut the paper, and the paper gets wrapped over the stone. Usually there are two players. Yet there are three friends, thatβs why they decided to choose the winner like that: If someone shows the gesture that wins over the other two players, then that player wins. Otherwise, another game round is required. Write a program that will determine the winner by the gestures they have shown.
Input
The first input line contains the name of the gesture that Uncle Fyodor showed, the second line shows which gesture Matroskin showed and the third line shows Sharicβs gesture.
Output
Print "F" (without quotes) if Uncle Fyodor wins. Print "M" if Matroskin wins and "S" if Sharic wins. If it is impossible to find the winner, print "?".
Examples
Input
rock
rock
rock
Output
?
Input
paper
rock
rock
Output
F
Input
scissors
rock
rock
Output
?
Input
scissors
paper
rock
Output
?
Submitted Solution:
```
F=input()
M=input()
S=input()
d=dict()
d['rock']='paper'
d['paper']='scissors'
d['scissors']='rock'
if(F==M):
if(d[F]==S):
print('S')
else:
print('?')
elif(M==S):
if(d[M]==F):
print('F')
else:
print('?')
elif(F==S):
if(d[F]==M):
print('M')
else:
print('?')
else:
print('?')
```
Yes
| 12,033 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodorβs parents and sometimes from anonymous benefactors, in which case it is hard to determine to which one of them the package has been sent. A photographic rifle is obviously for Sharic who loves hunting and fish is for Matroskin, but for whom was a new video game console meant? Every one of the three friends claimed that the present is for him and nearly quarreled. Uncle Fyodor had an idea how to solve the problem justly: they should suppose that the console was sent to all three of them and play it in turns. Everybody got relieved but then yet another burning problem popped up β who will play first? This time Matroskin came up with a brilliant solution, suggesting the most fair way to find it out: play rock-paper-scissors together. The rules of the game are very simple. On the count of three every player shows a combination with his hand (or paw). The combination corresponds to one of three things: a rock, scissors or paper. Some of the gestures win over some other ones according to well-known rules: the rock breaks the scissors, the scissors cut the paper, and the paper gets wrapped over the stone. Usually there are two players. Yet there are three friends, thatβs why they decided to choose the winner like that: If someone shows the gesture that wins over the other two players, then that player wins. Otherwise, another game round is required. Write a program that will determine the winner by the gestures they have shown.
Input
The first input line contains the name of the gesture that Uncle Fyodor showed, the second line shows which gesture Matroskin showed and the third line shows Sharicβs gesture.
Output
Print "F" (without quotes) if Uncle Fyodor wins. Print "M" if Matroskin wins and "S" if Sharic wins. If it is impossible to find the winner, print "?".
Examples
Input
rock
rock
rock
Output
?
Input
paper
rock
rock
Output
F
Input
scissors
rock
rock
Output
?
Input
scissors
paper
rock
Output
?
Submitted Solution:
```
manos = [input(),input(),input()]
indice_ganador = None
jugadores = ['F','M','S']
#manos = ['rock','paper','scissors']
reglas = ['paper','rock','scissors','paper']
for i in range(3):
for j in range(4):
if manos[i] == reglas[j]:
if reglas[j+1] == manos[(i+1)%3] and reglas[j+1] == manos[(i+2)%3]:
indice_ganador = i
break
if indice_ganador != None:
print(jugadores[indice_ganador])
else:
print('?')
```
Yes
| 12,034 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodorβs parents and sometimes from anonymous benefactors, in which case it is hard to determine to which one of them the package has been sent. A photographic rifle is obviously for Sharic who loves hunting and fish is for Matroskin, but for whom was a new video game console meant? Every one of the three friends claimed that the present is for him and nearly quarreled. Uncle Fyodor had an idea how to solve the problem justly: they should suppose that the console was sent to all three of them and play it in turns. Everybody got relieved but then yet another burning problem popped up β who will play first? This time Matroskin came up with a brilliant solution, suggesting the most fair way to find it out: play rock-paper-scissors together. The rules of the game are very simple. On the count of three every player shows a combination with his hand (or paw). The combination corresponds to one of three things: a rock, scissors or paper. Some of the gestures win over some other ones according to well-known rules: the rock breaks the scissors, the scissors cut the paper, and the paper gets wrapped over the stone. Usually there are two players. Yet there are three friends, thatβs why they decided to choose the winner like that: If someone shows the gesture that wins over the other two players, then that player wins. Otherwise, another game round is required. Write a program that will determine the winner by the gestures they have shown.
Input
The first input line contains the name of the gesture that Uncle Fyodor showed, the second line shows which gesture Matroskin showed and the third line shows Sharicβs gesture.
Output
Print "F" (without quotes) if Uncle Fyodor wins. Print "M" if Matroskin wins and "S" if Sharic wins. If it is impossible to find the winner, print "?".
Examples
Input
rock
rock
rock
Output
?
Input
paper
rock
rock
Output
F
Input
scissors
rock
rock
Output
?
Input
scissors
paper
rock
Output
?
Submitted Solution:
```
f=input()
m=input()
s=input()
if (f=='rock' and m==s=='scissors') or (f=='paper' and m==s=='rock') or (f=='scissors' and m==s=='paper'):
print('F')
elif (m=='rock' and f==s=='scissors') or (m=='paper' and f==s=='rock') or (m=='scissors' and f==s=='paper'):
print('M')
elif (s=='rock' and f==m=='scissors') or (s=='paper' and f==m=='rock') or (s=='scissors' and f==m=='paper'):
print('S')
else:
print('?')
```
Yes
| 12,035 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodorβs parents and sometimes from anonymous benefactors, in which case it is hard to determine to which one of them the package has been sent. A photographic rifle is obviously for Sharic who loves hunting and fish is for Matroskin, but for whom was a new video game console meant? Every one of the three friends claimed that the present is for him and nearly quarreled. Uncle Fyodor had an idea how to solve the problem justly: they should suppose that the console was sent to all three of them and play it in turns. Everybody got relieved but then yet another burning problem popped up β who will play first? This time Matroskin came up with a brilliant solution, suggesting the most fair way to find it out: play rock-paper-scissors together. The rules of the game are very simple. On the count of three every player shows a combination with his hand (or paw). The combination corresponds to one of three things: a rock, scissors or paper. Some of the gestures win over some other ones according to well-known rules: the rock breaks the scissors, the scissors cut the paper, and the paper gets wrapped over the stone. Usually there are two players. Yet there are three friends, thatβs why they decided to choose the winner like that: If someone shows the gesture that wins over the other two players, then that player wins. Otherwise, another game round is required. Write a program that will determine the winner by the gestures they have shown.
Input
The first input line contains the name of the gesture that Uncle Fyodor showed, the second line shows which gesture Matroskin showed and the third line shows Sharicβs gesture.
Output
Print "F" (without quotes) if Uncle Fyodor wins. Print "M" if Matroskin wins and "S" if Sharic wins. If it is impossible to find the winner, print "?".
Examples
Input
rock
rock
rock
Output
?
Input
paper
rock
rock
Output
F
Input
scissors
rock
rock
Output
?
Input
scissors
paper
rock
Output
?
Submitted Solution:
```
n1=input()
n2=input()
n3=input()
if n1==n2==n3:
print('?')
elif n1!=n2 and n2!=n3 and n1!=n3:
print('?')
elif n1=='scissors' and n2=='paper' and n2==n3 or n1=='rock' and n2=='scissors' and n2==n3 or n1=='paper' and n2=='rock' and n2==n3:
print('F')
elif n2=='scissors' and n3=='paper' and n1==n3 or n2=='rock' and n1=='scissors' and n1==n3 or n2=='paper' and n1=='rock' and n1==n3:
print('M')
elif n3=='scissors' and n2=='paper' and n2==n1 or n3=='rock' and n2=='scissors' and n2==n1 or n3=='paper' and n2=='rock' and n2==n1:
print('S')
else:
print('?')
```
Yes
| 12,036 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodorβs parents and sometimes from anonymous benefactors, in which case it is hard to determine to which one of them the package has been sent. A photographic rifle is obviously for Sharic who loves hunting and fish is for Matroskin, but for whom was a new video game console meant? Every one of the three friends claimed that the present is for him and nearly quarreled. Uncle Fyodor had an idea how to solve the problem justly: they should suppose that the console was sent to all three of them and play it in turns. Everybody got relieved but then yet another burning problem popped up β who will play first? This time Matroskin came up with a brilliant solution, suggesting the most fair way to find it out: play rock-paper-scissors together. The rules of the game are very simple. On the count of three every player shows a combination with his hand (or paw). The combination corresponds to one of three things: a rock, scissors or paper. Some of the gestures win over some other ones according to well-known rules: the rock breaks the scissors, the scissors cut the paper, and the paper gets wrapped over the stone. Usually there are two players. Yet there are three friends, thatβs why they decided to choose the winner like that: If someone shows the gesture that wins over the other two players, then that player wins. Otherwise, another game round is required. Write a program that will determine the winner by the gestures they have shown.
Input
The first input line contains the name of the gesture that Uncle Fyodor showed, the second line shows which gesture Matroskin showed and the third line shows Sharicβs gesture.
Output
Print "F" (without quotes) if Uncle Fyodor wins. Print "M" if Matroskin wins and "S" if Sharic wins. If it is impossible to find the winner, print "?".
Examples
Input
rock
rock
rock
Output
?
Input
paper
rock
rock
Output
F
Input
scissors
rock
rock
Output
?
Input
scissors
paper
rock
Output
?
Submitted Solution:
```
# ΠΠ°ΠΌΠ΅Π½Ρ Π½Π°Π·ΡΠ²Π°Π΅ΡΡΡ Β«rockΒ», Π±ΡΠΌΠ°Π³Π° Π½Π°Π·ΡΠ²Π°Π΅ΡΡΡ Β«paperΒ», Π° Π½ΠΎΠΆΠ½ΠΈΡΡ β Β«scissorsΒ».
n=input()
m=input()
k=input()
if n==m==k or n!=m!=k or (n=='scissors' and k==m=='rock') or (k=='scissors' and n==m=='rock') or (m=='scissors' and n==k=='rock') or (n=='rock' and m==k=='paper') or (m=='rock' and n==k=='paper') or (k=='rock' and n==m=='paper'):
print('?')
exit()
if k=='paper' and m==n=='rock':print('S');exit()
if k=='rock' and m==n=='scissors':print('S');exit()
if k=='scissors' and m==n=='paper':print('S');exit()
if n=='paper' and m==k=='rock':print('F');exit()
if n=='rock' and m==k=='scissors':print('F');exit()
if n=='scissors' and m==k=='paper':print('F');exit()
if m=='paper' and k==n=='rock':print('M');exit()
if m=='rock' and k==n=='scissors':print('M');exit()
if m=='scissors' and k==n=='paper':print('M');exit()
```
No
| 12,037 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodorβs parents and sometimes from anonymous benefactors, in which case it is hard to determine to which one of them the package has been sent. A photographic rifle is obviously for Sharic who loves hunting and fish is for Matroskin, but for whom was a new video game console meant? Every one of the three friends claimed that the present is for him and nearly quarreled. Uncle Fyodor had an idea how to solve the problem justly: they should suppose that the console was sent to all three of them and play it in turns. Everybody got relieved but then yet another burning problem popped up β who will play first? This time Matroskin came up with a brilliant solution, suggesting the most fair way to find it out: play rock-paper-scissors together. The rules of the game are very simple. On the count of three every player shows a combination with his hand (or paw). The combination corresponds to one of three things: a rock, scissors or paper. Some of the gestures win over some other ones according to well-known rules: the rock breaks the scissors, the scissors cut the paper, and the paper gets wrapped over the stone. Usually there are two players. Yet there are three friends, thatβs why they decided to choose the winner like that: If someone shows the gesture that wins over the other two players, then that player wins. Otherwise, another game round is required. Write a program that will determine the winner by the gestures they have shown.
Input
The first input line contains the name of the gesture that Uncle Fyodor showed, the second line shows which gesture Matroskin showed and the third line shows Sharicβs gesture.
Output
Print "F" (without quotes) if Uncle Fyodor wins. Print "M" if Matroskin wins and "S" if Sharic wins. If it is impossible to find the winner, print "?".
Examples
Input
rock
rock
rock
Output
?
Input
paper
rock
rock
Output
F
Input
scissors
rock
rock
Output
?
Input
scissors
paper
rock
Output
?
Submitted Solution:
```
#rock pair scissor
f = input();
m = input();
s = input();
if f=='rock' and m=='scissor' and s=='scissor':
print('F')
elif m=='rock' and f=='scissor' and s=='scissor':
print('M')
elif s=='rock' and f=='scissor' and m=='scissor':
print('S')
elif f=='scissor' and m=='paper' and s=='paper':
print('F')
elif m=='scissor' and f=='paper' and s=='paper':
print('M')
elif s=='scissor' and f=='paper' and m=='paper':
print('S')
elif f=='paper' and m=='rock' and s=='rock':
print('F')
elif m=='paper' and f=='rock' and s=='rock':
print('M')
elif s=='paper' and f=='rock' and m=='rock':
print('S')
else:
print('?')
```
No
| 12,038 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodorβs parents and sometimes from anonymous benefactors, in which case it is hard to determine to which one of them the package has been sent. A photographic rifle is obviously for Sharic who loves hunting and fish is for Matroskin, but for whom was a new video game console meant? Every one of the three friends claimed that the present is for him and nearly quarreled. Uncle Fyodor had an idea how to solve the problem justly: they should suppose that the console was sent to all three of them and play it in turns. Everybody got relieved but then yet another burning problem popped up β who will play first? This time Matroskin came up with a brilliant solution, suggesting the most fair way to find it out: play rock-paper-scissors together. The rules of the game are very simple. On the count of three every player shows a combination with his hand (or paw). The combination corresponds to one of three things: a rock, scissors or paper. Some of the gestures win over some other ones according to well-known rules: the rock breaks the scissors, the scissors cut the paper, and the paper gets wrapped over the stone. Usually there are two players. Yet there are three friends, thatβs why they decided to choose the winner like that: If someone shows the gesture that wins over the other two players, then that player wins. Otherwise, another game round is required. Write a program that will determine the winner by the gestures they have shown.
Input
The first input line contains the name of the gesture that Uncle Fyodor showed, the second line shows which gesture Matroskin showed and the third line shows Sharicβs gesture.
Output
Print "F" (without quotes) if Uncle Fyodor wins. Print "M" if Matroskin wins and "S" if Sharic wins. If it is impossible to find the winner, print "?".
Examples
Input
rock
rock
rock
Output
?
Input
paper
rock
rock
Output
F
Input
scissors
rock
rock
Output
?
Input
scissors
paper
rock
Output
?
Submitted Solution:
```
a=['l']*3
a[0],a[1],a[2]=input(),input(),input()
c=['F','M','S']
b=['scissors','paper','rock']
for i, j,k in [0,1,2],[0,2,1],[1,2,0],[1,0,2],[2,0,1],[2,1,0]:
if a[i]==a[j]:
if b.index(a[i])-b.index(a[k]) in [1,-2]:
break
else:
print('?')
```
No
| 12,039 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodorβs parents and sometimes from anonymous benefactors, in which case it is hard to determine to which one of them the package has been sent. A photographic rifle is obviously for Sharic who loves hunting and fish is for Matroskin, but for whom was a new video game console meant? Every one of the three friends claimed that the present is for him and nearly quarreled. Uncle Fyodor had an idea how to solve the problem justly: they should suppose that the console was sent to all three of them and play it in turns. Everybody got relieved but then yet another burning problem popped up β who will play first? This time Matroskin came up with a brilliant solution, suggesting the most fair way to find it out: play rock-paper-scissors together. The rules of the game are very simple. On the count of three every player shows a combination with his hand (or paw). The combination corresponds to one of three things: a rock, scissors or paper. Some of the gestures win over some other ones according to well-known rules: the rock breaks the scissors, the scissors cut the paper, and the paper gets wrapped over the stone. Usually there are two players. Yet there are three friends, thatβs why they decided to choose the winner like that: If someone shows the gesture that wins over the other two players, then that player wins. Otherwise, another game round is required. Write a program that will determine the winner by the gestures they have shown.
Input
The first input line contains the name of the gesture that Uncle Fyodor showed, the second line shows which gesture Matroskin showed and the third line shows Sharicβs gesture.
Output
Print "F" (without quotes) if Uncle Fyodor wins. Print "M" if Matroskin wins and "S" if Sharic wins. If it is impossible to find the winner, print "?".
Examples
Input
rock
rock
rock
Output
?
Input
paper
rock
rock
Output
F
Input
scissors
rock
rock
Output
?
Input
scissors
paper
rock
Output
?
Submitted Solution:
```
F=input ()
M=input ()
S=input ()
if F=='rock' and M=='scissors':
fw='rock'
if S=='rock':
print("?")
elif S=='scissors':
print("F")
elif S=='paper':
print('S')
elif F=='scissors' and M=='paper':
fw='scissors'
if S=='paper':
print("F")
elif S=='scissors':
print("?")
elif S=='rock':
print('S')
elif F=='paper' and M=='scissors':
fw='scissors'
if S=='paper':
print("M")
elif S=='scissors':
print("?")
elif S=='rock':
print('S')
elif F=='paper' and M=='rock':
fw='paper'
if S=='paper':
print("?")
elif S=='scissors':
print("S")
elif S=='rock':
print('F')
elif M=='paper' and F=='rock':
fw='paper'
if S=='paper':
print("?")
elif S=='scissors':
print("S")
elif S=='rock':
print('M')
elif M=='rock' and F=='scissors':
fw='rock'
if S=='rock':
print("?")
elif S=='scissors':
print("M")
elif S=='paper':
print('S')
elif M=='rock' and F=='rock':
print("?")
elif M=='paper' and F=='paper':
print("?")
elif M=='scissors' and F=='scissors':
print("?")
```
No
| 12,040 |
Provide tags and a correct Python 3 solution for this coding contest problem.
All cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with its position xi β a coordinate on the Ox axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in).
Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city.
For each city calculate two values ββmini and maxi, where mini is the minimum cost of sending a letter from the i-th city to some other city, and maxi is the the maximum cost of sending a letter from the i-th city to some other city
Input
The first line of the input contains integer n (2 β€ n β€ 105) β the number of cities in Lineland. The second line contains the sequence of n distinct integers x1, x2, ..., xn ( - 109 β€ xi β€ 109), where xi is the x-coordinate of the i-th city. All the xi's are distinct and follow in ascending order.
Output
Print n lines, the i-th line must contain two integers mini, maxi, separated by a space, where mini is the minimum cost of sending a letter from the i-th city, and maxi is the maximum cost of sending a letter from the i-th city.
Examples
Input
4
-5 -2 2 7
Output
3 12
3 9
4 7
5 12
Input
2
-1 1
Output
2 2
2 2
Tags: greedy, implementation
Correct Solution:
```
n=int(input());x=list(map(int,input().split()))
for i in range(n):t=x[i];print(min(abs(t-x[i-1]),abs(x[i-n+1]-t)),max(t-x[0],x[n-1]-t))
```
| 12,041 |
Provide tags and a correct Python 3 solution for this coding contest problem.
All cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with its position xi β a coordinate on the Ox axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in).
Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city.
For each city calculate two values ββmini and maxi, where mini is the minimum cost of sending a letter from the i-th city to some other city, and maxi is the the maximum cost of sending a letter from the i-th city to some other city
Input
The first line of the input contains integer n (2 β€ n β€ 105) β the number of cities in Lineland. The second line contains the sequence of n distinct integers x1, x2, ..., xn ( - 109 β€ xi β€ 109), where xi is the x-coordinate of the i-th city. All the xi's are distinct and follow in ascending order.
Output
Print n lines, the i-th line must contain two integers mini, maxi, separated by a space, where mini is the minimum cost of sending a letter from the i-th city, and maxi is the maximum cost of sending a letter from the i-th city.
Examples
Input
4
-5 -2 2 7
Output
3 12
3 9
4 7
5 12
Input
2
-1 1
Output
2 2
2 2
Tags: greedy, implementation
Correct Solution:
```
n= int(input())
dis = list(map(int, input().split(" ")))
result = [0]*n
for i in range(n):
if i == 0:
minimum = abs(dis[0]-dis[1])
maximam = abs(dis[i] - dis[n-1])
elif i == n -1:
minimum = abs(dis[i]-dis[i-1])
maximam= abs(dis[i] - dis[0])
else:
maximam = max(abs(dis[i] - dis[n-1]),abs(dis[i]-dis[0]))
minimum = min(abs(dis[i]- dis[i+1]), abs(dis[i]-dis[i-1]))
result[i] = str(minimum)+' ' +str(maximam)+'\n'
print(''.join(result),end = '')
```
| 12,042 |
Provide tags and a correct Python 3 solution for this coding contest problem.
All cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with its position xi β a coordinate on the Ox axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in).
Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city.
For each city calculate two values ββmini and maxi, where mini is the minimum cost of sending a letter from the i-th city to some other city, and maxi is the the maximum cost of sending a letter from the i-th city to some other city
Input
The first line of the input contains integer n (2 β€ n β€ 105) β the number of cities in Lineland. The second line contains the sequence of n distinct integers x1, x2, ..., xn ( - 109 β€ xi β€ 109), where xi is the x-coordinate of the i-th city. All the xi's are distinct and follow in ascending order.
Output
Print n lines, the i-th line must contain two integers mini, maxi, separated by a space, where mini is the minimum cost of sending a letter from the i-th city, and maxi is the maximum cost of sending a letter from the i-th city.
Examples
Input
4
-5 -2 2 7
Output
3 12
3 9
4 7
5 12
Input
2
-1 1
Output
2 2
2 2
Tags: greedy, implementation
Correct Solution:
```
n = input()
locations = list(map(int, input().split()))
for idx, loc in enumerate(locations):
if idx == 0:
minimum = locations[1] - loc
maximum = locations[-1] - loc
elif idx == len(locations) - 1 :
minimum = loc - locations[-2]
maximum = loc - locations[0]
else:
minimum = min(abs(loc - locations[idx + 1]), abs(loc - locations[idx - 1]))
maximum = max(abs(loc - locations[-1]), abs(loc - locations[0]))
print(minimum, maximum)
```
| 12,043 |
Provide tags and a correct Python 3 solution for this coding contest problem.
All cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with its position xi β a coordinate on the Ox axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in).
Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city.
For each city calculate two values ββmini and maxi, where mini is the minimum cost of sending a letter from the i-th city to some other city, and maxi is the the maximum cost of sending a letter from the i-th city to some other city
Input
The first line of the input contains integer n (2 β€ n β€ 105) β the number of cities in Lineland. The second line contains the sequence of n distinct integers x1, x2, ..., xn ( - 109 β€ xi β€ 109), where xi is the x-coordinate of the i-th city. All the xi's are distinct and follow in ascending order.
Output
Print n lines, the i-th line must contain two integers mini, maxi, separated by a space, where mini is the minimum cost of sending a letter from the i-th city, and maxi is the maximum cost of sending a letter from the i-th city.
Examples
Input
4
-5 -2 2 7
Output
3 12
3 9
4 7
5 12
Input
2
-1 1
Output
2 2
2 2
Tags: greedy, implementation
Correct Solution:
```
n = int(input())
lista = [int(x) for x in input().split()]
ult = n -1
for x in range(n):
if(x == 0):
min = lista[1] - lista[0]
max = lista[ult] - lista[0]
elif(x == ult):
min = lista[ult] - lista[ult - 1]
max = lista[ult] - lista[0]
else:
min = lista[x] - lista[x -1]
if (lista[x + 1] - lista[x] < min):
min = lista[x + 1] - lista[x]
max = lista[ult] - lista[x]
if (lista[x] - lista[0] > max):
max = lista[x] - lista[0]
print(min, " ", max)
```
| 12,044 |
Provide tags and a correct Python 3 solution for this coding contest problem.
All cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with its position xi β a coordinate on the Ox axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in).
Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city.
For each city calculate two values ββmini and maxi, where mini is the minimum cost of sending a letter from the i-th city to some other city, and maxi is the the maximum cost of sending a letter from the i-th city to some other city
Input
The first line of the input contains integer n (2 β€ n β€ 105) β the number of cities in Lineland. The second line contains the sequence of n distinct integers x1, x2, ..., xn ( - 109 β€ xi β€ 109), where xi is the x-coordinate of the i-th city. All the xi's are distinct and follow in ascending order.
Output
Print n lines, the i-th line must contain two integers mini, maxi, separated by a space, where mini is the minimum cost of sending a letter from the i-th city, and maxi is the maximum cost of sending a letter from the i-th city.
Examples
Input
4
-5 -2 2 7
Output
3 12
3 9
4 7
5 12
Input
2
-1 1
Output
2 2
2 2
Tags: greedy, implementation
Correct Solution:
```
x = int(input())
coord = list(map(int, input().split()))
for i in range(x):
max, min = 0,0
if(i == 0):
min = abs(coord[i] - coord[i+1])
max = abs(coord[i] - coord[x-1])
elif( i == x-1):
min = abs(coord[i] - coord[i-1])
max = abs(coord[i] - coord[0])
else:
min = abs(coord[i] - coord[i-1])
if(abs(coord[i] - coord[i+1] )< min):
min = abs(coord[i] - coord[i+1])
max = abs(coord[i] - coord[0])
if(abs(coord[i] - coord[x-1]) > max):
max = abs(coord[i] - coord[x-1])
print (min, "", max)
```
| 12,045 |
Provide tags and a correct Python 3 solution for this coding contest problem.
All cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with its position xi β a coordinate on the Ox axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in).
Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city.
For each city calculate two values ββmini and maxi, where mini is the minimum cost of sending a letter from the i-th city to some other city, and maxi is the the maximum cost of sending a letter from the i-th city to some other city
Input
The first line of the input contains integer n (2 β€ n β€ 105) β the number of cities in Lineland. The second line contains the sequence of n distinct integers x1, x2, ..., xn ( - 109 β€ xi β€ 109), where xi is the x-coordinate of the i-th city. All the xi's are distinct and follow in ascending order.
Output
Print n lines, the i-th line must contain two integers mini, maxi, separated by a space, where mini is the minimum cost of sending a letter from the i-th city, and maxi is the maximum cost of sending a letter from the i-th city.
Examples
Input
4
-5 -2 2 7
Output
3 12
3 9
4 7
5 12
Input
2
-1 1
Output
2 2
2 2
Tags: greedy, implementation
Correct Solution:
```
n = int(input())
cities = list(map(int, input().split()))
ans = []
for i in range(n):
if i == 0:
maxi = abs(cities[-1] - cities[0])
mini = abs(cities[1] - cities[0])
elif i == n-1:
maxi = abs(cities[-1] - cities[0])
mini = abs(cities[-1] - cities[-2])
else:
min1 = abs(cities[i] - cities[i-1])
min2 = abs(cities[i] - cities[i+1])
if min1 < min2:
mini = min1
else:
mini = min2
max1 = abs(cities[i] - cities[0])
max2 = abs(cities[i] - cities[-1])
if max1 > max2:
maxi = max1
else:
maxi = max2
ans.append(mini)
ans.append(maxi)
for i in range(0, 2*n, 2):
print(str(ans[i]) + ' ' + str(ans[i+1]))
```
| 12,046 |
Provide tags and a correct Python 3 solution for this coding contest problem.
All cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with its position xi β a coordinate on the Ox axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in).
Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city.
For each city calculate two values ββmini and maxi, where mini is the minimum cost of sending a letter from the i-th city to some other city, and maxi is the the maximum cost of sending a letter from the i-th city to some other city
Input
The first line of the input contains integer n (2 β€ n β€ 105) β the number of cities in Lineland. The second line contains the sequence of n distinct integers x1, x2, ..., xn ( - 109 β€ xi β€ 109), where xi is the x-coordinate of the i-th city. All the xi's are distinct and follow in ascending order.
Output
Print n lines, the i-th line must contain two integers mini, maxi, separated by a space, where mini is the minimum cost of sending a letter from the i-th city, and maxi is the maximum cost of sending a letter from the i-th city.
Examples
Input
4
-5 -2 2 7
Output
3 12
3 9
4 7
5 12
Input
2
-1 1
Output
2 2
2 2
Tags: greedy, implementation
Correct Solution:
```
n = int(input())
x = list(map(int, input().split()))
mincost = []
maxcost = []
mincost.append(x[1] - x[0])
maxcost.append(x[n - 1] - x[0])
for i in range(1, n - 1):
mincost.append(min(x[i] - x[i - 1], x[i + 1] - x[i]))
maxcost.append(max(x[i] - x[0], x[n - 1] - x[i]))
mincost.append(x[n - 1] - x[n - 2])
maxcost.append(x[n - 1] - x[0])
for i in range(0, n):
print (mincost[i], maxcost[i])
```
| 12,047 |
Provide tags and a correct Python 3 solution for this coding contest problem.
All cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with its position xi β a coordinate on the Ox axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in).
Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city.
For each city calculate two values ββmini and maxi, where mini is the minimum cost of sending a letter from the i-th city to some other city, and maxi is the the maximum cost of sending a letter from the i-th city to some other city
Input
The first line of the input contains integer n (2 β€ n β€ 105) β the number of cities in Lineland. The second line contains the sequence of n distinct integers x1, x2, ..., xn ( - 109 β€ xi β€ 109), where xi is the x-coordinate of the i-th city. All the xi's are distinct and follow in ascending order.
Output
Print n lines, the i-th line must contain two integers mini, maxi, separated by a space, where mini is the minimum cost of sending a letter from the i-th city, and maxi is the maximum cost of sending a letter from the i-th city.
Examples
Input
4
-5 -2 2 7
Output
3 12
3 9
4 7
5 12
Input
2
-1 1
Output
2 2
2 2
Tags: greedy, implementation
Correct Solution:
```
n = int(input())
c = list(map(int,input().split()))
for i in range(n):
c_max = max(abs(c[-1]-c[i]),abs(c[i]-c[0]))
c_min = 10**15
if (i != 0):
c_min = min(abs(c[i]-c[i-1]),c_min)
if (i != (n-1)):
c_min = min(abs(c[i+1]-c[i]),c_min)
print("%d %d"%(c_min,c_max))
```
| 12,048 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
All cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with its position xi β a coordinate on the Ox axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in).
Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city.
For each city calculate two values ββmini and maxi, where mini is the minimum cost of sending a letter from the i-th city to some other city, and maxi is the the maximum cost of sending a letter from the i-th city to some other city
Input
The first line of the input contains integer n (2 β€ n β€ 105) β the number of cities in Lineland. The second line contains the sequence of n distinct integers x1, x2, ..., xn ( - 109 β€ xi β€ 109), where xi is the x-coordinate of the i-th city. All the xi's are distinct and follow in ascending order.
Output
Print n lines, the i-th line must contain two integers mini, maxi, separated by a space, where mini is the minimum cost of sending a letter from the i-th city, and maxi is the maximum cost of sending a letter from the i-th city.
Examples
Input
4
-5 -2 2 7
Output
3 12
3 9
4 7
5 12
Input
2
-1 1
Output
2 2
2 2
Submitted Solution:
```
def mail(n, lst):
b = list()
for i in range(n):
if i == 0:
b.append([lst[1] - lst[0], lst[n - 1] - lst[0]])
elif i == n - 1:
b.append([lst[n - 1] - lst[n - 2], lst[n - 1] - lst[0]])
else:
b.append([min(lst[i + 1] - lst[i], lst[i] - lst[i - 1]), max(lst[i] - lst[0], lst[n - 1] - lst[i])])
return b
m = int(input())
a = [int(j) for j in input().split()]
for elem in mail(m, a):
print(*elem)
```
Yes
| 12,049 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
All cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with its position xi β a coordinate on the Ox axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in).
Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city.
For each city calculate two values ββmini and maxi, where mini is the minimum cost of sending a letter from the i-th city to some other city, and maxi is the the maximum cost of sending a letter from the i-th city to some other city
Input
The first line of the input contains integer n (2 β€ n β€ 105) β the number of cities in Lineland. The second line contains the sequence of n distinct integers x1, x2, ..., xn ( - 109 β€ xi β€ 109), where xi is the x-coordinate of the i-th city. All the xi's are distinct and follow in ascending order.
Output
Print n lines, the i-th line must contain two integers mini, maxi, separated by a space, where mini is the minimum cost of sending a letter from the i-th city, and maxi is the maximum cost of sending a letter from the i-th city.
Examples
Input
4
-5 -2 2 7
Output
3 12
3 9
4 7
5 12
Input
2
-1 1
Output
2 2
2 2
Submitted Solution:
```
n = int(input())
x = [int(i) for i in input().split()]
print(str(abs(x[0]-x[1]))+' '+str(abs(x[0]-x[n-1])))
for i in range(1, n-1):
mini = min(abs(x[i]-x[i-1]), abs(x[i]-x[i+1]))
maxi = max(abs(x[i]-x[0]), abs(x[i]-x[n-1]))
print(str(mini)+' '+str(maxi))
print(str(abs(x[n-1]-x[n-2]))+' '+str(abs(x[n-1]-x[0])))
```
Yes
| 12,050 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
All cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with its position xi β a coordinate on the Ox axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in).
Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city.
For each city calculate two values ββmini and maxi, where mini is the minimum cost of sending a letter from the i-th city to some other city, and maxi is the the maximum cost of sending a letter from the i-th city to some other city
Input
The first line of the input contains integer n (2 β€ n β€ 105) β the number of cities in Lineland. The second line contains the sequence of n distinct integers x1, x2, ..., xn ( - 109 β€ xi β€ 109), where xi is the x-coordinate of the i-th city. All the xi's are distinct and follow in ascending order.
Output
Print n lines, the i-th line must contain two integers mini, maxi, separated by a space, where mini is the minimum cost of sending a letter from the i-th city, and maxi is the maximum cost of sending a letter from the i-th city.
Examples
Input
4
-5 -2 2 7
Output
3 12
3 9
4 7
5 12
Input
2
-1 1
Output
2 2
2 2
Submitted Solution:
```
n=int(input())
list1=list(map(int,input().strip().split(' ')))
print(list1[1]-list1[0],list1[-1]-list1[0])
for i in range(1,n-1):
print(min(list1[i+1]-list1[i],list1[i]-list1[i-1]),max(list1[i]-list1[0],list1[-1]-list1[i]))
print(list1[-1]-list1[-2],list1[-1]-list1[0])
```
Yes
| 12,051 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
All cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with its position xi β a coordinate on the Ox axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in).
Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city.
For each city calculate two values ββmini and maxi, where mini is the minimum cost of sending a letter from the i-th city to some other city, and maxi is the the maximum cost of sending a letter from the i-th city to some other city
Input
The first line of the input contains integer n (2 β€ n β€ 105) β the number of cities in Lineland. The second line contains the sequence of n distinct integers x1, x2, ..., xn ( - 109 β€ xi β€ 109), where xi is the x-coordinate of the i-th city. All the xi's are distinct and follow in ascending order.
Output
Print n lines, the i-th line must contain two integers mini, maxi, separated by a space, where mini is the minimum cost of sending a letter from the i-th city, and maxi is the maximum cost of sending a letter from the i-th city.
Examples
Input
4
-5 -2 2 7
Output
3 12
3 9
4 7
5 12
Input
2
-1 1
Output
2 2
2 2
Submitted Solution:
```
n= int(input())
mas = list(map(int,input().split(" ")))
for i in range(len(mas)):
if i==0:
print(abs(mas[i]-mas[i+1]), abs(mas[i]-mas[-1]))
elif i==len(mas)-1:
print(abs(mas[i]-mas[i-1]), abs(mas[i]-mas[0]))
else:
print(min(abs(mas[i]-mas[i+1]),abs(mas[i]-mas[i-1]))
, max(abs(mas[i]-mas[-1]),abs(mas[i]-mas[0])))
```
Yes
| 12,052 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
All cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with its position xi β a coordinate on the Ox axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in).
Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city.
For each city calculate two values ββmini and maxi, where mini is the minimum cost of sending a letter from the i-th city to some other city, and maxi is the the maximum cost of sending a letter from the i-th city to some other city
Input
The first line of the input contains integer n (2 β€ n β€ 105) β the number of cities in Lineland. The second line contains the sequence of n distinct integers x1, x2, ..., xn ( - 109 β€ xi β€ 109), where xi is the x-coordinate of the i-th city. All the xi's are distinct and follow in ascending order.
Output
Print n lines, the i-th line must contain two integers mini, maxi, separated by a space, where mini is the minimum cost of sending a letter from the i-th city, and maxi is the maximum cost of sending a letter from the i-th city.
Examples
Input
4
-5 -2 2 7
Output
3 12
3 9
4 7
5 12
Input
2
-1 1
Output
2 2
2 2
Submitted Solution:
```
import math
def distance(a, b):
return int(math.fabs(a - b))
n = int(input())
line = [int(i) for i in input().split()]
for i in range(len(line)):
if(i == 0):
print(distance(line[i], line[i+1]), distance(line[i], line[-1]))
elif(i == n - 1):
print(distance(line[i], line[i-1]), distance(line[i], line[0]))
else:
previousElement = line[i-1]
current = line[i]
nextElement = line[i+1]
minimum = distance(previousElement, line[i])
if(distance(current, nextElement) < minimum):
minimum = line[i+1]
maximum = distance(current, line[0])
if(distance(current, line[-1]) > maximum):
maximum = distance(current, line[-1])
print(minimum, maximum)
```
No
| 12,053 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
All cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with its position xi β a coordinate on the Ox axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in).
Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city.
For each city calculate two values ββmini and maxi, where mini is the minimum cost of sending a letter from the i-th city to some other city, and maxi is the the maximum cost of sending a letter from the i-th city to some other city
Input
The first line of the input contains integer n (2 β€ n β€ 105) β the number of cities in Lineland. The second line contains the sequence of n distinct integers x1, x2, ..., xn ( - 109 β€ xi β€ 109), where xi is the x-coordinate of the i-th city. All the xi's are distinct and follow in ascending order.
Output
Print n lines, the i-th line must contain two integers mini, maxi, separated by a space, where mini is the minimum cost of sending a letter from the i-th city, and maxi is the maximum cost of sending a letter from the i-th city.
Examples
Input
4
-5 -2 2 7
Output
3 12
3 9
4 7
5 12
Input
2
-1 1
Output
2 2
2 2
Submitted Solution:
```
n=int(input())
list1=list(map(int,input().split(" ")))
for i in range(0,n):
maxi=10**-9-1
mini=10**9+1
for j in range(0,n):
if i!=j:
maxi=max(maxi,abs(list1[i]-list1[j]))
mini=min(mini,abs(list1[i]-list1[j]))
print(mini,maxi)
```
No
| 12,054 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
All cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with its position xi β a coordinate on the Ox axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in).
Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city.
For each city calculate two values ββmini and maxi, where mini is the minimum cost of sending a letter from the i-th city to some other city, and maxi is the the maximum cost of sending a letter from the i-th city to some other city
Input
The first line of the input contains integer n (2 β€ n β€ 105) β the number of cities in Lineland. The second line contains the sequence of n distinct integers x1, x2, ..., xn ( - 109 β€ xi β€ 109), where xi is the x-coordinate of the i-th city. All the xi's are distinct and follow in ascending order.
Output
Print n lines, the i-th line must contain two integers mini, maxi, separated by a space, where mini is the minimum cost of sending a letter from the i-th city, and maxi is the maximum cost of sending a letter from the i-th city.
Examples
Input
4
-5 -2 2 7
Output
3 12
3 9
4 7
5 12
Input
2
-1 1
Output
2 2
2 2
Submitted Solution:
```
#!/usr/bin/env python
import os
import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from io import BytesIO, IOBase
from itertools import (
accumulate, combinations, combinations_with_replacement, groupby,
permutations, product)
from math import (
acos, asin, atan, ceil, cos, degrees, factorial, hypot, log2, pi, radians,
sin, sqrt, tan)
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits
def inp():
return(int(input()))
def inlist():
return(list(map(int, input().split())))
def instr():
s = input()
return(list(s[:len(s)]))
def invr():
return(map(int, input().split()))
def main():
n = inp()
a = inlist()
print(abs(a[1]-a[0]), abs(a[n-1]-a[0]))
for i in range(1, n-1):
mini = min(a[i] - a[i-1], a[i+1] - a[i])
maxi = max(a[i] - a[0], a[n-1], a[i])
print(abs(mini), abs(maxi))
print(abs(a[n-1]-a[n-2]), abs(a[n-1]-a[0]))
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
def input(): return sys.stdin.readline().rstrip("\r\n")
# endregion
if __name__ == "__main__":
main()
```
No
| 12,055 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
All cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with its position xi β a coordinate on the Ox axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in).
Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city.
For each city calculate two values ββmini and maxi, where mini is the minimum cost of sending a letter from the i-th city to some other city, and maxi is the the maximum cost of sending a letter from the i-th city to some other city
Input
The first line of the input contains integer n (2 β€ n β€ 105) β the number of cities in Lineland. The second line contains the sequence of n distinct integers x1, x2, ..., xn ( - 109 β€ xi β€ 109), where xi is the x-coordinate of the i-th city. All the xi's are distinct and follow in ascending order.
Output
Print n lines, the i-th line must contain two integers mini, maxi, separated by a space, where mini is the minimum cost of sending a letter from the i-th city, and maxi is the maximum cost of sending a letter from the i-th city.
Examples
Input
4
-5 -2 2 7
Output
3 12
3 9
4 7
5 12
Input
2
-1 1
Output
2 2
2 2
Submitted Solution:
```
n = int(input())
cordinates = [*map(int, input().split())]
def diff(a, b):
return abs(a - b)
if n == 2:
dif = diff(cordinates[0], cordinates[1])
print(dif, dif)
else:
for i in range(n):
nexti = i+1
backi = i-1
if backi >= 0 and nexti < n:
d1 = diff(cordinates[backi], cordinates[i])
d2 = diff(cordinates[i], cordinates[nexti])
minv = min(d1, d2)
elif backi < 0:
minv = diff(cordinates[i], cordinates[nexti])
else:
minv = diff(cordinates[i], cordinates[backi])
md1 = diff(cordinates[0], cordinates[i])
md2 = diff(cordinates[n-1], cordinates[i])
maxv = max(md1,md2)
print(minv, maxv)
```
No
| 12,056 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of i-th of them is 2wi pounds. In each step, Duff can lift some of the remaining weights and throw them away. She does this until there's no more weight left. Malek asked her to minimize the number of steps.
<image>
Duff is a competitive programming fan. That's why in each step, she can only lift and throw away a sequence of weights 2a1, ..., 2ak if and only if there exists a non-negative integer x such that 2a1 + 2a2 + ... + 2ak = 2x, i. e. the sum of those numbers is a power of two.
Duff is a competitive programming fan, but not a programmer. That's why she asked for your help. Help her minimize the number of steps.
Input
The first line of input contains integer n (1 β€ n β€ 106), the number of weights.
The second line contains n integers w1, ..., wn separated by spaces (0 β€ wi β€ 106 for each 1 β€ i β€ n), the powers of two forming the weights values.
Output
Print the minimum number of steps in a single line.
Examples
Input
5
1 1 2 3 3
Output
2
Input
4
0 1 2 3
Output
4
Note
In the first sample case: One optimal way would be to throw away the first three in the first step and the rest in the second step. Also, it's not possible to do it in one step because their sum is not a power of two.
In the second sample case: The only optimal way is to throw away one weight in each step. It's not possible to do it in less than 4 steps because there's no subset of weights with more than one weight and sum equal to a power of two.
Tags: greedy
Correct Solution:
```
n=int(input())
l=list(map(int,input().split()))
cnt=[0]*(10**6+100)
for i in l:
cnt[i]+=1
s=0
ans=0
for i in cnt:
s+=i
ans+=s%2
s//=2
print(ans)
```
| 12,057 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of i-th of them is 2wi pounds. In each step, Duff can lift some of the remaining weights and throw them away. She does this until there's no more weight left. Malek asked her to minimize the number of steps.
<image>
Duff is a competitive programming fan. That's why in each step, she can only lift and throw away a sequence of weights 2a1, ..., 2ak if and only if there exists a non-negative integer x such that 2a1 + 2a2 + ... + 2ak = 2x, i. e. the sum of those numbers is a power of two.
Duff is a competitive programming fan, but not a programmer. That's why she asked for your help. Help her minimize the number of steps.
Input
The first line of input contains integer n (1 β€ n β€ 106), the number of weights.
The second line contains n integers w1, ..., wn separated by spaces (0 β€ wi β€ 106 for each 1 β€ i β€ n), the powers of two forming the weights values.
Output
Print the minimum number of steps in a single line.
Examples
Input
5
1 1 2 3 3
Output
2
Input
4
0 1 2 3
Output
4
Note
In the first sample case: One optimal way would be to throw away the first three in the first step and the rest in the second step. Also, it's not possible to do it in one step because their sum is not a power of two.
In the second sample case: The only optimal way is to throw away one weight in each step. It's not possible to do it in less than 4 steps because there's no subset of weights with more than one weight and sum equal to a power of two.
Tags: greedy
Correct Solution:
```
n = int(input())
l = [0] * (10**6+100)
for i in map(int,input().split()):
l[i] += 1
cur = ans = 0
for i in l:
cur += i
if cur%2:
ans += 1
cur //=2
print (ans)
# Made By Mostafa_Khaled
```
| 12,058 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of i-th of them is 2wi pounds. In each step, Duff can lift some of the remaining weights and throw them away. She does this until there's no more weight left. Malek asked her to minimize the number of steps.
<image>
Duff is a competitive programming fan. That's why in each step, she can only lift and throw away a sequence of weights 2a1, ..., 2ak if and only if there exists a non-negative integer x such that 2a1 + 2a2 + ... + 2ak = 2x, i. e. the sum of those numbers is a power of two.
Duff is a competitive programming fan, but not a programmer. That's why she asked for your help. Help her minimize the number of steps.
Input
The first line of input contains integer n (1 β€ n β€ 106), the number of weights.
The second line contains n integers w1, ..., wn separated by spaces (0 β€ wi β€ 106 for each 1 β€ i β€ n), the powers of two forming the weights values.
Output
Print the minimum number of steps in a single line.
Examples
Input
5
1 1 2 3 3
Output
2
Input
4
0 1 2 3
Output
4
Note
In the first sample case: One optimal way would be to throw away the first three in the first step and the rest in the second step. Also, it's not possible to do it in one step because their sum is not a power of two.
In the second sample case: The only optimal way is to throw away one weight in each step. It's not possible to do it in less than 4 steps because there's no subset of weights with more than one weight and sum equal to a power of two.
Tags: greedy
Correct Solution:
```
n = int(input())
lis = sorted(map(int,input().split()))
ans=c=0
c=1
#print(lis)
for i in range(1,n):
if lis[i]==lis[i-1]:
c+=1
else:
# print(c,lis[i],'c')
while lis[i]!=lis[i-1] and c>0:
if c%2:
ans+=1
c = c//2
lis[i-1]+=1
# print(ans)
c+=1
#print(c,ans)
while c>0:
if c%2:
ans+=1
c = c//2
print(ans)
```
| 12,059 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of i-th of them is 2wi pounds. In each step, Duff can lift some of the remaining weights and throw them away. She does this until there's no more weight left. Malek asked her to minimize the number of steps.
<image>
Duff is a competitive programming fan. That's why in each step, she can only lift and throw away a sequence of weights 2a1, ..., 2ak if and only if there exists a non-negative integer x such that 2a1 + 2a2 + ... + 2ak = 2x, i. e. the sum of those numbers is a power of two.
Duff is a competitive programming fan, but not a programmer. That's why she asked for your help. Help her minimize the number of steps.
Input
The first line of input contains integer n (1 β€ n β€ 106), the number of weights.
The second line contains n integers w1, ..., wn separated by spaces (0 β€ wi β€ 106 for each 1 β€ i β€ n), the powers of two forming the weights values.
Output
Print the minimum number of steps in a single line.
Examples
Input
5
1 1 2 3 3
Output
2
Input
4
0 1 2 3
Output
4
Note
In the first sample case: One optimal way would be to throw away the first three in the first step and the rest in the second step. Also, it's not possible to do it in one step because their sum is not a power of two.
In the second sample case: The only optimal way is to throw away one weight in each step. It's not possible to do it in less than 4 steps because there's no subset of weights with more than one weight and sum equal to a power of two.
Tags: greedy
Correct Solution:
```
N = int(1e6) + 20
n = int(input())
m = [0] * N
k = 1e6 + 1
for x in map(int, input().split()):
m[x] += 1
k = min(k, x)
result = 0
while k < N - 1:
v = m[k]
m[k + 1] += v >> 1
result += v & 0x1
k += 1
print(result + m[-1])
```
| 12,060 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of i-th of them is 2wi pounds. In each step, Duff can lift some of the remaining weights and throw them away. She does this until there's no more weight left. Malek asked her to minimize the number of steps.
<image>
Duff is a competitive programming fan. That's why in each step, she can only lift and throw away a sequence of weights 2a1, ..., 2ak if and only if there exists a non-negative integer x such that 2a1 + 2a2 + ... + 2ak = 2x, i. e. the sum of those numbers is a power of two.
Duff is a competitive programming fan, but not a programmer. That's why she asked for your help. Help her minimize the number of steps.
Input
The first line of input contains integer n (1 β€ n β€ 106), the number of weights.
The second line contains n integers w1, ..., wn separated by spaces (0 β€ wi β€ 106 for each 1 β€ i β€ n), the powers of two forming the weights values.
Output
Print the minimum number of steps in a single line.
Examples
Input
5
1 1 2 3 3
Output
2
Input
4
0 1 2 3
Output
4
Note
In the first sample case: One optimal way would be to throw away the first three in the first step and the rest in the second step. Also, it's not possible to do it in one step because their sum is not a power of two.
In the second sample case: The only optimal way is to throw away one weight in each step. It's not possible to do it in less than 4 steps because there's no subset of weights with more than one weight and sum equal to a power of two.
Tags: greedy
Correct Solution:
```
#!/usr/bin/env python
# -*- coding: utf-8 -*-
n = int(input())
weights = list(map(int,input().split()))
counter = [0] * (10** 6 + 21)
for weight in weights:
counter[weight] += 1
ans = 0
for i in range(10**6 + 21):
weight, count = (i, counter[i])
if count > 0 and count // 2 > 0:
counter[weight+1] += count//2
count -= (count//2)*2
ans += count
print(ans)
```
| 12,061 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of i-th of them is 2wi pounds. In each step, Duff can lift some of the remaining weights and throw them away. She does this until there's no more weight left. Malek asked her to minimize the number of steps.
<image>
Duff is a competitive programming fan. That's why in each step, she can only lift and throw away a sequence of weights 2a1, ..., 2ak if and only if there exists a non-negative integer x such that 2a1 + 2a2 + ... + 2ak = 2x, i. e. the sum of those numbers is a power of two.
Duff is a competitive programming fan, but not a programmer. That's why she asked for your help. Help her minimize the number of steps.
Input
The first line of input contains integer n (1 β€ n β€ 106), the number of weights.
The second line contains n integers w1, ..., wn separated by spaces (0 β€ wi β€ 106 for each 1 β€ i β€ n), the powers of two forming the weights values.
Output
Print the minimum number of steps in a single line.
Examples
Input
5
1 1 2 3 3
Output
2
Input
4
0 1 2 3
Output
4
Note
In the first sample case: One optimal way would be to throw away the first three in the first step and the rest in the second step. Also, it's not possible to do it in one step because their sum is not a power of two.
In the second sample case: The only optimal way is to throw away one weight in each step. It's not possible to do it in less than 4 steps because there's no subset of weights with more than one weight and sum equal to a power of two.
Tags: greedy
Correct Solution:
```
n = int(input())
a = [0 for i in range(10**6+1)]
for x in input().split():
a[int(x)] += 1
c = 0
prev = 0
for el in a:
prev += el
if prev%2 == 1:
c+=1
prev //= 2
while prev>0:
c += prev%2
prev //= 2
print(c)
```
| 12,062 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of i-th of them is 2wi pounds. In each step, Duff can lift some of the remaining weights and throw them away. She does this until there's no more weight left. Malek asked her to minimize the number of steps.
<image>
Duff is a competitive programming fan. That's why in each step, she can only lift and throw away a sequence of weights 2a1, ..., 2ak if and only if there exists a non-negative integer x such that 2a1 + 2a2 + ... + 2ak = 2x, i. e. the sum of those numbers is a power of two.
Duff is a competitive programming fan, but not a programmer. That's why she asked for your help. Help her minimize the number of steps.
Input
The first line of input contains integer n (1 β€ n β€ 106), the number of weights.
The second line contains n integers w1, ..., wn separated by spaces (0 β€ wi β€ 106 for each 1 β€ i β€ n), the powers of two forming the weights values.
Output
Print the minimum number of steps in a single line.
Examples
Input
5
1 1 2 3 3
Output
2
Input
4
0 1 2 3
Output
4
Note
In the first sample case: One optimal way would be to throw away the first three in the first step and the rest in the second step. Also, it's not possible to do it in one step because their sum is not a power of two.
In the second sample case: The only optimal way is to throw away one weight in each step. It's not possible to do it in less than 4 steps because there's no subset of weights with more than one weight and sum equal to a power of two.
Tags: greedy
Correct Solution:
```
from collections import *
import sys
import math
from functools import reduce
def factors(n):
return set(reduce(list.__add__,([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))
def li():return [int(i) for i in input().rstrip('\n').split(' ')]
def st():return input().rstrip('\n')
def val():return int(input())
def stli():return [int(i) for i in input().rstrip('\n')]
def persquare(x):
return 1 if x**0.5 == int(x**0.5) else 0
n = val()
l = sorted(li())
currlist = [0 for i in range(10**6 + 22)]
for i in l:
currlist[i] += 1
tot = 0
# print(currlist[:10])
for i in range(10**6 + 21):
while currlist[i]>1:
temp = 2**int(math.log2(currlist[i]))
currlist[i] -= temp
currlist[i + 1] += temp//2
# print(currlist[:10])
print(sum(currlist))
```
| 12,063 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of i-th of them is 2wi pounds. In each step, Duff can lift some of the remaining weights and throw them away. She does this until there's no more weight left. Malek asked her to minimize the number of steps.
<image>
Duff is a competitive programming fan. That's why in each step, she can only lift and throw away a sequence of weights 2a1, ..., 2ak if and only if there exists a non-negative integer x such that 2a1 + 2a2 + ... + 2ak = 2x, i. e. the sum of those numbers is a power of two.
Duff is a competitive programming fan, but not a programmer. That's why she asked for your help. Help her minimize the number of steps.
Input
The first line of input contains integer n (1 β€ n β€ 106), the number of weights.
The second line contains n integers w1, ..., wn separated by spaces (0 β€ wi β€ 106 for each 1 β€ i β€ n), the powers of two forming the weights values.
Output
Print the minimum number of steps in a single line.
Examples
Input
5
1 1 2 3 3
Output
2
Input
4
0 1 2 3
Output
4
Note
In the first sample case: One optimal way would be to throw away the first three in the first step and the rest in the second step. Also, it's not possible to do it in one step because their sum is not a power of two.
In the second sample case: The only optimal way is to throw away one weight in each step. It's not possible to do it in less than 4 steps because there's no subset of weights with more than one weight and sum equal to a power of two.
Tags: greedy
Correct Solution:
```
def main():
input()
l = [0] * 1000001
for w in map(int, input().split()):
l[w] += 1
t = rest = 0
for x in l:
t += x
if t & 1:
rest += 1
t >>= 1
print(bin(t).count('1') + rest)
if __name__ == '__main__':
main()
```
| 12,064 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of i-th of them is 2wi pounds. In each step, Duff can lift some of the remaining weights and throw them away. She does this until there's no more weight left. Malek asked her to minimize the number of steps.
<image>
Duff is a competitive programming fan. That's why in each step, she can only lift and throw away a sequence of weights 2a1, ..., 2ak if and only if there exists a non-negative integer x such that 2a1 + 2a2 + ... + 2ak = 2x, i. e. the sum of those numbers is a power of two.
Duff is a competitive programming fan, but not a programmer. That's why she asked for your help. Help her minimize the number of steps.
Input
The first line of input contains integer n (1 β€ n β€ 106), the number of weights.
The second line contains n integers w1, ..., wn separated by spaces (0 β€ wi β€ 106 for each 1 β€ i β€ n), the powers of two forming the weights values.
Output
Print the minimum number of steps in a single line.
Examples
Input
5
1 1 2 3 3
Output
2
Input
4
0 1 2 3
Output
4
Note
In the first sample case: One optimal way would be to throw away the first three in the first step and the rest in the second step. Also, it's not possible to do it in one step because their sum is not a power of two.
In the second sample case: The only optimal way is to throw away one weight in each step. It's not possible to do it in less than 4 steps because there's no subset of weights with more than one weight and sum equal to a power of two.
Submitted Solution:
```
def main():
n = int(input())
w = list(map(int, input().split()))
bits = [0] * (10 ** 6 + 100)
for e in w:
bits[e] += 1
cur, res = 0, 0
for e in bits:
cur += e
if cur % 2:
res += 1
cur //= 2
print(res)
if __name__ == '__main__':
main()
```
Yes
| 12,065 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of i-th of them is 2wi pounds. In each step, Duff can lift some of the remaining weights and throw them away. She does this until there's no more weight left. Malek asked her to minimize the number of steps.
<image>
Duff is a competitive programming fan. That's why in each step, she can only lift and throw away a sequence of weights 2a1, ..., 2ak if and only if there exists a non-negative integer x such that 2a1 + 2a2 + ... + 2ak = 2x, i. e. the sum of those numbers is a power of two.
Duff is a competitive programming fan, but not a programmer. That's why she asked for your help. Help her minimize the number of steps.
Input
The first line of input contains integer n (1 β€ n β€ 106), the number of weights.
The second line contains n integers w1, ..., wn separated by spaces (0 β€ wi β€ 106 for each 1 β€ i β€ n), the powers of two forming the weights values.
Output
Print the minimum number of steps in a single line.
Examples
Input
5
1 1 2 3 3
Output
2
Input
4
0 1 2 3
Output
4
Note
In the first sample case: One optimal way would be to throw away the first three in the first step and the rest in the second step. Also, it's not possible to do it in one step because their sum is not a power of two.
In the second sample case: The only optimal way is to throw away one weight in each step. It's not possible to do it in less than 4 steps because there's no subset of weights with more than one weight and sum equal to a power of two.
Submitted Solution:
```
def inc(a,w):
n=len(a)
i=w
while(i<n and a[i]==1):
a[i]=0
i+=1
if(i<n):
a[i]=1
else:
a.append(1)
n=int(input())
x=input().split(' ')
w=[int(y) for y in x]
a=[0]*1000024
for t in w:
inc(a,t)
print(sum(a))
```
Yes
| 12,066 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of i-th of them is 2wi pounds. In each step, Duff can lift some of the remaining weights and throw them away. She does this until there's no more weight left. Malek asked her to minimize the number of steps.
<image>
Duff is a competitive programming fan. That's why in each step, she can only lift and throw away a sequence of weights 2a1, ..., 2ak if and only if there exists a non-negative integer x such that 2a1 + 2a2 + ... + 2ak = 2x, i. e. the sum of those numbers is a power of two.
Duff is a competitive programming fan, but not a programmer. That's why she asked for your help. Help her minimize the number of steps.
Input
The first line of input contains integer n (1 β€ n β€ 106), the number of weights.
The second line contains n integers w1, ..., wn separated by spaces (0 β€ wi β€ 106 for each 1 β€ i β€ n), the powers of two forming the weights values.
Output
Print the minimum number of steps in a single line.
Examples
Input
5
1 1 2 3 3
Output
2
Input
4
0 1 2 3
Output
4
Note
In the first sample case: One optimal way would be to throw away the first three in the first step and the rest in the second step. Also, it's not possible to do it in one step because their sum is not a power of two.
In the second sample case: The only optimal way is to throw away one weight in each step. It's not possible to do it in less than 4 steps because there's no subset of weights with more than one weight and sum equal to a power of two.
Submitted Solution:
```
n = int(input())
l = list(map(int,input().split()))
bit = [0]*(10**6+101)
for i in l:
bit[i] = bit[i]+1
#print(bit[0],bit[1],bit[2],bit[3])
ans = 0
s = 0
for i in bit:
s = s+i
ans = ans+(s%2)
s = s//2
print(ans)
```
Yes
| 12,067 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of i-th of them is 2wi pounds. In each step, Duff can lift some of the remaining weights and throw them away. She does this until there's no more weight left. Malek asked her to minimize the number of steps.
<image>
Duff is a competitive programming fan. That's why in each step, she can only lift and throw away a sequence of weights 2a1, ..., 2ak if and only if there exists a non-negative integer x such that 2a1 + 2a2 + ... + 2ak = 2x, i. e. the sum of those numbers is a power of two.
Duff is a competitive programming fan, but not a programmer. That's why she asked for your help. Help her minimize the number of steps.
Input
The first line of input contains integer n (1 β€ n β€ 106), the number of weights.
The second line contains n integers w1, ..., wn separated by spaces (0 β€ wi β€ 106 for each 1 β€ i β€ n), the powers of two forming the weights values.
Output
Print the minimum number of steps in a single line.
Examples
Input
5
1 1 2 3 3
Output
2
Input
4
0 1 2 3
Output
4
Note
In the first sample case: One optimal way would be to throw away the first three in the first step and the rest in the second step. Also, it's not possible to do it in one step because their sum is not a power of two.
In the second sample case: The only optimal way is to throw away one weight in each step. It's not possible to do it in less than 4 steps because there's no subset of weights with more than one weight and sum equal to a power of two.
Submitted Solution:
```
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from collections import Counter
n = int(input())
weights = sorted(list(map(int,input().split())))
counter = Counter(weights)
minus_counter = Counter()
ans = 0
for weight, count in sorted(counter.items()):
count -= max(0, minus_counter[2**weight])
if count > 0 and count // 2 > 0:
minus_counter[2**weight*(count//2)*2] += 1
count -= (count//2)*2
ans += 1
ans += count
print(ans)
```
No
| 12,068 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of i-th of them is 2wi pounds. In each step, Duff can lift some of the remaining weights and throw them away. She does this until there's no more weight left. Malek asked her to minimize the number of steps.
<image>
Duff is a competitive programming fan. That's why in each step, she can only lift and throw away a sequence of weights 2a1, ..., 2ak if and only if there exists a non-negative integer x such that 2a1 + 2a2 + ... + 2ak = 2x, i. e. the sum of those numbers is a power of two.
Duff is a competitive programming fan, but not a programmer. That's why she asked for your help. Help her minimize the number of steps.
Input
The first line of input contains integer n (1 β€ n β€ 106), the number of weights.
The second line contains n integers w1, ..., wn separated by spaces (0 β€ wi β€ 106 for each 1 β€ i β€ n), the powers of two forming the weights values.
Output
Print the minimum number of steps in a single line.
Examples
Input
5
1 1 2 3 3
Output
2
Input
4
0 1 2 3
Output
4
Note
In the first sample case: One optimal way would be to throw away the first three in the first step and the rest in the second step. Also, it's not possible to do it in one step because their sum is not a power of two.
In the second sample case: The only optimal way is to throw away one weight in each step. It's not possible to do it in less than 4 steps because there's no subset of weights with more than one weight and sum equal to a power of two.
Submitted Solution:
```
n=4
inputList = '0 1 2 3'
list = [int(x) for x in inputList.split()]
#n = int(input())
#list = [int(x) for x in input().split()]
length = n
previousLength = 0
while length != previousLength:
previousLength = length
for i in range(len(list)-1,0,-1):
if list[i] == list[i-1]:
list[i-1] += list[i]
del list[i]
length = len(list)
print(length)
```
No
| 12,069 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of i-th of them is 2wi pounds. In each step, Duff can lift some of the remaining weights and throw them away. She does this until there's no more weight left. Malek asked her to minimize the number of steps.
<image>
Duff is a competitive programming fan. That's why in each step, she can only lift and throw away a sequence of weights 2a1, ..., 2ak if and only if there exists a non-negative integer x such that 2a1 + 2a2 + ... + 2ak = 2x, i. e. the sum of those numbers is a power of two.
Duff is a competitive programming fan, but not a programmer. That's why she asked for your help. Help her minimize the number of steps.
Input
The first line of input contains integer n (1 β€ n β€ 106), the number of weights.
The second line contains n integers w1, ..., wn separated by spaces (0 β€ wi β€ 106 for each 1 β€ i β€ n), the powers of two forming the weights values.
Output
Print the minimum number of steps in a single line.
Examples
Input
5
1 1 2 3 3
Output
2
Input
4
0 1 2 3
Output
4
Note
In the first sample case: One optimal way would be to throw away the first three in the first step and the rest in the second step. Also, it's not possible to do it in one step because their sum is not a power of two.
In the second sample case: The only optimal way is to throw away one weight in each step. It's not possible to do it in less than 4 steps because there's no subset of weights with more than one weight and sum equal to a power of two.
Submitted Solution:
```
from collections import *
import sys
import math
from functools import reduce
def factors(n):
return set(reduce(list.__add__,([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))
def li():return [int(i) for i in input().rstrip('\n').split(' ')]
def st():return input().rstrip('\n')
def val():return int(input())
def stli():return [int(i) for i in input().rstrip('\n')]
def persquare(x):
return 1 if x**0.5 == int(x**0.5) else 0
n = val()
l = sorted(li())
currlist = [0 for i in range(10**6 + 10)]
for i in l:
currlist[i] += 1
tot = 0
for i in range(10**6 + 10):
while currlist[i]>1:
temp = 2**int(math.log2(currlist[i]))
currlist[i] -= temp
currlist[temp//2] += 1
print(sum(currlist))
```
No
| 12,070 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of i-th of them is 2wi pounds. In each step, Duff can lift some of the remaining weights and throw them away. She does this until there's no more weight left. Malek asked her to minimize the number of steps.
<image>
Duff is a competitive programming fan. That's why in each step, she can only lift and throw away a sequence of weights 2a1, ..., 2ak if and only if there exists a non-negative integer x such that 2a1 + 2a2 + ... + 2ak = 2x, i. e. the sum of those numbers is a power of two.
Duff is a competitive programming fan, but not a programmer. That's why she asked for your help. Help her minimize the number of steps.
Input
The first line of input contains integer n (1 β€ n β€ 106), the number of weights.
The second line contains n integers w1, ..., wn separated by spaces (0 β€ wi β€ 106 for each 1 β€ i β€ n), the powers of two forming the weights values.
Output
Print the minimum number of steps in a single line.
Examples
Input
5
1 1 2 3 3
Output
2
Input
4
0 1 2 3
Output
4
Note
In the first sample case: One optimal way would be to throw away the first three in the first step and the rest in the second step. Also, it's not possible to do it in one step because their sum is not a power of two.
In the second sample case: The only optimal way is to throw away one weight in each step. It's not possible to do it in less than 4 steps because there's no subset of weights with more than one weight and sum equal to a power of two.
Submitted Solution:
```
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from collections import Counter
n = int(input())
weights = sorted(list(map(int,input().split())))
counter = [0] * 10** 7
for weight, count in Counter(weights).items():
counter[weight] = count
ans = 0
for i in range(10**7):
weight, count = (i, counter[i])
if count > 0 and count // 2 > 0:
counter[weight+(count//2)] += 1
count -= (count//2)*2
ans += count
print(ans)
```
No
| 12,071 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Once upon a time in the thicket of the mushroom forest lived mushroom gnomes. They were famous among their neighbors for their magic mushrooms. Their magic nature made it possible that between every two neighboring mushrooms every minute grew another mushroom with the weight equal to the sum of weights of two neighboring ones.
The mushroom gnomes loved it when everything was in order, that's why they always planted the mushrooms in one line in the order of their weights' increasing. Well... The gnomes planted the mushrooms and went to eat. After x minutes they returned and saw that new mushrooms had grown up, so that the increasing order had been violated. The gnomes replanted all the mushrooms in the correct order, that is, they sorted the mushrooms in the order of the weights' increasing. And went to eat again (those gnomes were quite big eaters). What total weights modulo p will the mushrooms have in another y minutes?
Input
The first line contains four integers n, x, y, p (1 β€ n β€ 106, 0 β€ x, y β€ 1018, x + y > 0, 2 β€ p β€ 109) which represent the number of mushrooms, the number of minutes after the first replanting, the number of minutes after the second replanting and the module. The next line contains n integers ai which represent the mushrooms' weight in the non-decreasing order (0 β€ ai β€ 109).
Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d).
Output
The answer should contain a single number which is the total weights of the mushrooms modulo p in the end after x + y minutes.
Examples
Input
2 1 0 657276545
1 2
Output
6
Input
2 1 1 888450282
1 2
Output
14
Input
4 5 0 10000
1 2 3 4
Output
1825
Tags: math, matrices
Correct Solution:
```
#!/usr/bin/pypy3
from sys import stdin, stdout
input, print = stdin.readline, stdout.write
p = 0
def readints():
return list(map(int, input().split()))
def writeln(x):
print(str(x) + '\n')
def mod(x):
return (x % p + p) % p
def matmul(a, b):
n = len(a)
c = [[0 for x in range(n)] for y in range(n)]
for i in range(n):
for j in range(n):
for k in range(n):
c[i][j] = (c[i][j] + a[i][k] * b[k][j]) % p
return c
def matpow(b, p):
n = len(b)
res = [[0 if x != y else 1 for x in range(n)] for y in range(n)]
while p:
if p & 1:
res = matmul(res, b)
b = matmul(b, b)
p >>= 1
return res
def main():
global p
n, x, y, p = readints()
a = [each % p for each in sorted(readints())]
if n == 1:
writeln(a[0])
return
"""
[a sum] * [[1 -1], = [a sum]
[0 3]]
[sc mv] * [[0 1],
[1, 1]] = [mv mv+sc]
"""
b = matpow([
[1, -1],
[0, 3]], x)
sum0 = matmul([
[a[0] + a[-1], sum(a)],
[0, 0]], b)[0][1]
b = matpow([
[0, 1],
[1, 1]], x)
maxa = matmul(
[[a[-2], a[-1]],
[0, 0]], b)[0][1]
b = matpow([
[1, -1],
[0, 3]], y)
sum1 = matmul([
[a[0] + maxa, sum0],
[0, 0]], b)[0][1]
writeln(mod(sum1))
if __name__ == '__main__':
main()
```
| 12,072 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Once upon a time in the thicket of the mushroom forest lived mushroom gnomes. They were famous among their neighbors for their magic mushrooms. Their magic nature made it possible that between every two neighboring mushrooms every minute grew another mushroom with the weight equal to the sum of weights of two neighboring ones.
The mushroom gnomes loved it when everything was in order, that's why they always planted the mushrooms in one line in the order of their weights' increasing. Well... The gnomes planted the mushrooms and went to eat. After x minutes they returned and saw that new mushrooms had grown up, so that the increasing order had been violated. The gnomes replanted all the mushrooms in the correct order, that is, they sorted the mushrooms in the order of the weights' increasing. And went to eat again (those gnomes were quite big eaters). What total weights modulo p will the mushrooms have in another y minutes?
Input
The first line contains four integers n, x, y, p (1 β€ n β€ 106, 0 β€ x, y β€ 1018, x + y > 0, 2 β€ p β€ 109) which represent the number of mushrooms, the number of minutes after the first replanting, the number of minutes after the second replanting and the module. The next line contains n integers ai which represent the mushrooms' weight in the non-decreasing order (0 β€ ai β€ 109).
Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d).
Output
The answer should contain a single number which is the total weights of the mushrooms modulo p in the end after x + y minutes.
Examples
Input
2 1 0 657276545
1 2
Output
6
Input
2 1 1 888450282
1 2
Output
14
Input
4 5 0 10000
1 2 3 4
Output
1825
Tags: math, matrices
Correct Solution:
```
#!/usr/bin/pypy3
from sys import stdin, stdout
input, print = stdin.readline, stdout.write
p = 0
def readints():
return list(map(int, input().split()))
def writeln(x):
print(str(x) + '\n')
def mod(x):
return (x % p + p) % p
def matmul(a, b):
n = len(a)
c = [[0 for x in range(n)] for y in range(n)]
for i in range(n):
for j in range(n):
for k in range(n):
c[i][j] = (c[i][j] + a[i][k] * b[k][j]) % p
return c
def matpow(b, p):
n = len(b)
res = [[0 if x != y else 1 for x in range(n)] for y in range(n)]
while p:
if p & 1:
res = matmul(res, b)
b = matmul(b, b)
p >>= 1
return res
n, x, y, p = readints()
a = [each % p for each in sorted(readints())]
if n == 1:
writeln(a[0])
exit(0)
"""
[a sum] * [[1 -1], = [a sum]
[0 3]]
[sc mv] * [[0 1],
[1, 1]] = [mv mv+sc]
"""
b = matpow([
[1, -1],
[0, 3]], x)
sum0 = matmul([
[a[0] + a[-1], sum(a)],
[0, 0]], b)[0][1]
b = matpow([
[0, 1],
[1, 1]], x)
maxa = matmul(
[[a[-2], a[-1]],
[0, 0]], b)[0][1]
b = matpow([
[1, -1],
[0, 3]], y)
sum1 = matmul([
[a[0] + maxa, sum0],
[0, 0]], b)[0][1]
writeln(mod(sum1))
```
| 12,073 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Once upon a time in the thicket of the mushroom forest lived mushroom gnomes. They were famous among their neighbors for their magic mushrooms. Their magic nature made it possible that between every two neighboring mushrooms every minute grew another mushroom with the weight equal to the sum of weights of two neighboring ones.
The mushroom gnomes loved it when everything was in order, that's why they always planted the mushrooms in one line in the order of their weights' increasing. Well... The gnomes planted the mushrooms and went to eat. After x minutes they returned and saw that new mushrooms had grown up, so that the increasing order had been violated. The gnomes replanted all the mushrooms in the correct order, that is, they sorted the mushrooms in the order of the weights' increasing. And went to eat again (those gnomes were quite big eaters). What total weights modulo p will the mushrooms have in another y minutes?
Input
The first line contains four integers n, x, y, p (1 β€ n β€ 106, 0 β€ x, y β€ 1018, x + y > 0, 2 β€ p β€ 109) which represent the number of mushrooms, the number of minutes after the first replanting, the number of minutes after the second replanting and the module. The next line contains n integers ai which represent the mushrooms' weight in the non-decreasing order (0 β€ ai β€ 109).
Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d).
Output
The answer should contain a single number which is the total weights of the mushrooms modulo p in the end after x + y minutes.
Examples
Input
2 1 0 657276545
1 2
Output
6
Input
2 1 1 888450282
1 2
Output
14
Input
4 5 0 10000
1 2 3 4
Output
1825
Submitted Solution:
```
import sys
I = lambda: int(input())
RL = readline = lambda: sys.stdin.readline().strip('\n')
RM = readmap = lambda x = int: map(x,readline().split(' '))
#E
n,x,y,p = RM()
a = [*RM()]
s = temps = sum(a)
ends = a[0] + a[-1]
for i in range(x):
temps = (3*temps - ends)%p
ends = a[0] + a[-2] + x*a[-1]
for i in range(y):
temps = (3*temps - ends)%p
print(temps)
```
No
| 12,074 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Once upon a time in the thicket of the mushroom forest lived mushroom gnomes. They were famous among their neighbors for their magic mushrooms. Their magic nature made it possible that between every two neighboring mushrooms every minute grew another mushroom with the weight equal to the sum of weights of two neighboring ones.
The mushroom gnomes loved it when everything was in order, that's why they always planted the mushrooms in one line in the order of their weights' increasing. Well... The gnomes planted the mushrooms and went to eat. After x minutes they returned and saw that new mushrooms had grown up, so that the increasing order had been violated. The gnomes replanted all the mushrooms in the correct order, that is, they sorted the mushrooms in the order of the weights' increasing. And went to eat again (those gnomes were quite big eaters). What total weights modulo p will the mushrooms have in another y minutes?
Input
The first line contains four integers n, x, y, p (1 β€ n β€ 106, 0 β€ x, y β€ 1018, x + y > 0, 2 β€ p β€ 109) which represent the number of mushrooms, the number of minutes after the first replanting, the number of minutes after the second replanting and the module. The next line contains n integers ai which represent the mushrooms' weight in the non-decreasing order (0 β€ ai β€ 109).
Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d).
Output
The answer should contain a single number which is the total weights of the mushrooms modulo p in the end after x + y minutes.
Examples
Input
2 1 0 657276545
1 2
Output
6
Input
2 1 1 888450282
1 2
Output
14
Input
4 5 0 10000
1 2 3 4
Output
1825
Submitted Solution:
```
import sys
I = lambda: int(input())
RL = readline = lambda: sys.stdin.readline().strip('\n')
RM = readmap = lambda x = int: map(x,readline().split(' '))
#E
'''
solution:
sum grows exponentially if the sum of array at 0th min is s and the sum of
start and end is e then sum in the next minute is s + (2*s - e)
after x days and rearragning them the start is same but the end is
different if x>0 and is equal to a[-2] + x*a[-1]
or same if x==0 i.e the end is a[-1]
'''
n,x,y,p = RM()
a = [*RM()]
s = temps = sum(a)
ends = a[0] + a[-1]
for i in range(x):
temps = (3*temps - ends)%p
ends = a[0] + ((a[-2] + x*a[-1]) if x>0 else a[-1])
for i in range(y):
temps = (3*temps - ends)%p
print(temps)
'''
4 0 8 78731972
1 52 76 81
'''
```
No
| 12,075 |
Provide tags and a correct Python 3 solution for this coding contest problem.
IT City company developing computer games invented a new way to reward its employees. After a new game release users start buying it actively, and the company tracks the number of sales with precision to each transaction. Every time when the next number of sales is divisible by all numbers from 2 to 10 every developer of this game gets a small bonus.
A game designer Petya knows that the company is just about to release a new game that was partly developed by him. On the basis of his experience he predicts that n people will buy the game during the first month. Now Petya wants to determine how many times he will get the bonus. Help him to know it.
Input
The only line of the input contains one integer n (1 β€ n β€ 1018) β the prediction on the number of people who will buy the game.
Output
Output one integer showing how many numbers from 1 to n are divisible by all numbers from 2 to 10.
Examples
Input
3000
Output
1
Tags: math, number theory
Correct Solution:
```
import sys
import math
# sys.stdin = open('input.txt')
# sys.stdout = open('output.txt', 'w')
def main():
n = int(input())
a = n // 2
b = n // 3
c = n // 5
d = n // 7
ab = n // 6
ac = n // 10
ad = n // 14
bc = n // 15
bd = n // 21
cd = n // 35
abc = n // 30
abd = n // 42
acd = n // 70
bcd = n // 105
abcd = n // 210
v = a + b + c + d - ab - ac - ad - bc - bd - cd + abc + abd + acd + bcd - abcd
print(n - v)
main()
```
| 12,076 |
Provide tags and a correct Python 3 solution for this coding contest problem.
IT City company developing computer games invented a new way to reward its employees. After a new game release users start buying it actively, and the company tracks the number of sales with precision to each transaction. Every time when the next number of sales is divisible by all numbers from 2 to 10 every developer of this game gets a small bonus.
A game designer Petya knows that the company is just about to release a new game that was partly developed by him. On the basis of his experience he predicts that n people will buy the game during the first month. Now Petya wants to determine how many times he will get the bonus. Help him to know it.
Input
The only line of the input contains one integer n (1 β€ n β€ 1018) β the prediction on the number of people who will buy the game.
Output
Output one integer showing how many numbers from 1 to n are divisible by all numbers from 2 to 10.
Examples
Input
3000
Output
1
Tags: math, number theory
Correct Solution:
```
n = int(input())
s = 0
for i in range(16):
d = 1
for j, k in ((1, 2), (2, 3), (4, 5), (8, 7)):
if i & j: d *= -k
if d > 0: s += n // d
else: s -= n // -d
print(s)
```
| 12,077 |
Provide tags and a correct Python 3 solution for this coding contest problem.
IT City company developing computer games invented a new way to reward its employees. After a new game release users start buying it actively, and the company tracks the number of sales with precision to each transaction. Every time when the next number of sales is divisible by all numbers from 2 to 10 every developer of this game gets a small bonus.
A game designer Petya knows that the company is just about to release a new game that was partly developed by him. On the basis of his experience he predicts that n people will buy the game during the first month. Now Petya wants to determine how many times he will get the bonus. Help him to know it.
Input
The only line of the input contains one integer n (1 β€ n β€ 1018) β the prediction on the number of people who will buy the game.
Output
Output one integer showing how many numbers from 1 to n are divisible by all numbers from 2 to 10.
Examples
Input
3000
Output
1
Tags: math, number theory
Correct Solution:
```
from sys import stdin,stdout
from math import gcd, ceil, sqrt,factorial as f
ii1 = lambda: int(stdin.readline().strip())
is1 = lambda: stdin.readline().strip()
iia = lambda: list(map(int, stdin.readline().strip().split()))
isa = lambda: stdin.readline().strip().split()
mod = 1000000007
n = ii1()
div = 8 * 5 * 9 * 7
print(n//div)
```
| 12,078 |
Provide tags and a correct Python 3 solution for this coding contest problem.
IT City company developing computer games invented a new way to reward its employees. After a new game release users start buying it actively, and the company tracks the number of sales with precision to each transaction. Every time when the next number of sales is divisible by all numbers from 2 to 10 every developer of this game gets a small bonus.
A game designer Petya knows that the company is just about to release a new game that was partly developed by him. On the basis of his experience he predicts that n people will buy the game during the first month. Now Petya wants to determine how many times he will get the bonus. Help him to know it.
Input
The only line of the input contains one integer n (1 β€ n β€ 1018) β the prediction on the number of people who will buy the game.
Output
Output one integer showing how many numbers from 1 to n are divisible by all numbers from 2 to 10.
Examples
Input
3000
Output
1
Tags: math, number theory
Correct Solution:
```
n = int(input())
a=(n//2+n//3+n//5+n//7-n//6-n//10-n//14-n//15-n//21-n//35+n//30+n//42+n//70+n//105-n//210)
print(n-a)
```
| 12,079 |
Provide tags and a correct Python 3 solution for this coding contest problem.
IT City company developing computer games invented a new way to reward its employees. After a new game release users start buying it actively, and the company tracks the number of sales with precision to each transaction. Every time when the next number of sales is divisible by all numbers from 2 to 10 every developer of this game gets a small bonus.
A game designer Petya knows that the company is just about to release a new game that was partly developed by him. On the basis of his experience he predicts that n people will buy the game during the first month. Now Petya wants to determine how many times he will get the bonus. Help him to know it.
Input
The only line of the input contains one integer n (1 β€ n β€ 1018) β the prediction on the number of people who will buy the game.
Output
Output one integer showing how many numbers from 1 to n are divisible by all numbers from 2 to 10.
Examples
Input
3000
Output
1
Tags: math, number theory
Correct Solution:
```
n = int(input())
f = lambda x: n // x
a1 = f(2) + f(3) + f(5) + f(7)
a2 = f(6) + f(10) + f(14) + f(15) + f(21) + f(35)
a3 = f(30) + f(42) + f(70) + f(105)
a4 = f(210)
ans = n - (a1 - a2 + a3 - a4)
print(ans)
```
| 12,080 |
Provide tags and a correct Python 3 solution for this coding contest problem.
IT City company developing computer games invented a new way to reward its employees. After a new game release users start buying it actively, and the company tracks the number of sales with precision to each transaction. Every time when the next number of sales is divisible by all numbers from 2 to 10 every developer of this game gets a small bonus.
A game designer Petya knows that the company is just about to release a new game that was partly developed by him. On the basis of his experience he predicts that n people will buy the game during the first month. Now Petya wants to determine how many times he will get the bonus. Help him to know it.
Input
The only line of the input contains one integer n (1 β€ n β€ 1018) β the prediction on the number of people who will buy the game.
Output
Output one integer showing how many numbers from 1 to n are divisible by all numbers from 2 to 10.
Examples
Input
3000
Output
1
Tags: math, number theory
Correct Solution:
```
n=int(input())
a=1
for i in {8,9,5,7}:
a*=i
#print(a)
print(n//a)
```
| 12,081 |
Provide tags and a correct Python 3 solution for this coding contest problem.
IT City company developing computer games invented a new way to reward its employees. After a new game release users start buying it actively, and the company tracks the number of sales with precision to each transaction. Every time when the next number of sales is divisible by all numbers from 2 to 10 every developer of this game gets a small bonus.
A game designer Petya knows that the company is just about to release a new game that was partly developed by him. On the basis of his experience he predicts that n people will buy the game during the first month. Now Petya wants to determine how many times he will get the bonus. Help him to know it.
Input
The only line of the input contains one integer n (1 β€ n β€ 1018) β the prediction on the number of people who will buy the game.
Output
Output one integer showing how many numbers from 1 to n are divisible by all numbers from 2 to 10.
Examples
Input
3000
Output
1
Tags: math, number theory
Correct Solution:
```
x = int(input())
#x, y = map(int, input().split())
y = x//210*48
for i in range(1, x%210 + 1):
if i%2 and i%3 and i%5 and i%7:
y+=1
print(y)
```
| 12,082 |
Provide tags and a correct Python 3 solution for this coding contest problem.
IT City company developing computer games invented a new way to reward its employees. After a new game release users start buying it actively, and the company tracks the number of sales with precision to each transaction. Every time when the next number of sales is divisible by all numbers from 2 to 10 every developer of this game gets a small bonus.
A game designer Petya knows that the company is just about to release a new game that was partly developed by him. On the basis of his experience he predicts that n people will buy the game during the first month. Now Petya wants to determine how many times he will get the bonus. Help him to know it.
Input
The only line of the input contains one integer n (1 β€ n β€ 1018) β the prediction on the number of people who will buy the game.
Output
Output one integer showing how many numbers from 1 to n are divisible by all numbers from 2 to 10.
Examples
Input
3000
Output
1
Tags: math, number theory
Correct Solution:
```
n = int(input())
print(n//(2*3*5*2*7*2*3))
```
| 12,083 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
IT City company developing computer games invented a new way to reward its employees. After a new game release users start buying it actively, and the company tracks the number of sales with precision to each transaction. Every time when the next number of sales is divisible by all numbers from 2 to 10 every developer of this game gets a small bonus.
A game designer Petya knows that the company is just about to release a new game that was partly developed by him. On the basis of his experience he predicts that n people will buy the game during the first month. Now Petya wants to determine how many times he will get the bonus. Help him to know it.
Input
The only line of the input contains one integer n (1 β€ n β€ 1018) β the prediction on the number of people who will buy the game.
Output
Output one integer showing how many numbers from 1 to n are divisible by all numbers from 2 to 10.
Examples
Input
3000
Output
1
Submitted Solution:
```
import bisect
from itertools import accumulate
import os
import sys
import math
from decimal import *
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
def input():
return sys.stdin.readline().rstrip("\r\n")
def isPrime(n):
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i = i + 6
return True
def SieveOfEratosthenes(n):
prime = []
primes = [True for i in range(n + 1)]
p = 2
while p * p <= n:
if primes[p] == True:
prime.append(p)
for i in range(p * p, n + 1, p):
primes[i] = False
p += 1
return prime
def primefactors(n):
fac = []
while n % 2 == 0:
fac.append(2)
n = n // 2
for i in range(3, int(math.sqrt(n)) + 2):
while n % i == 0:
fac.append(i)
n = n // i
if n > 1:
fac.append(n)
return sorted(fac)
def factors(n):
fac = set()
fac.add(1)
fac.add(n)
for i in range(2, int(math.sqrt(n)) + 1):
if n % i == 0:
fac.add(i)
fac.add(n // i)
return list(fac)
def modInverse(a, m):
m0 = m
y = 0
x = 1
if m == 1:
return 0
while a > 1:
q = a // m
t = m
m = a % m
a = t
t = y
y = x - q * y
x = t
if x < 0:
x = x + m0
return x
# ------------------------------------------------------code
n=int(input())
print(n-n//2-n//3-n//5-n//7+n//6+n//15+n//35+n//10+n//14+n//21-n//105-n//70-n//30-n//42+n//210)
```
Yes
| 12,084 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
IT City company developing computer games invented a new way to reward its employees. After a new game release users start buying it actively, and the company tracks the number of sales with precision to each transaction. Every time when the next number of sales is divisible by all numbers from 2 to 10 every developer of this game gets a small bonus.
A game designer Petya knows that the company is just about to release a new game that was partly developed by him. On the basis of his experience he predicts that n people will buy the game during the first month. Now Petya wants to determine how many times he will get the bonus. Help him to know it.
Input
The only line of the input contains one integer n (1 β€ n β€ 1018) β the prediction on the number of people who will buy the game.
Output
Output one integer showing how many numbers from 1 to n are divisible by all numbers from 2 to 10.
Examples
Input
3000
Output
1
Submitted Solution:
```
print(int(input())//(2 ** 3 * 5 * 7 * 9))
```
Yes
| 12,085 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
IT City company developing computer games invented a new way to reward its employees. After a new game release users start buying it actively, and the company tracks the number of sales with precision to each transaction. Every time when the next number of sales is divisible by all numbers from 2 to 10 every developer of this game gets a small bonus.
A game designer Petya knows that the company is just about to release a new game that was partly developed by him. On the basis of his experience he predicts that n people will buy the game during the first month. Now Petya wants to determine how many times he will get the bonus. Help him to know it.
Input
The only line of the input contains one integer n (1 β€ n β€ 1018) β the prediction on the number of people who will buy the game.
Output
Output one integer showing how many numbers from 1 to n are divisible by all numbers from 2 to 10.
Examples
Input
3000
Output
1
Submitted Solution:
```
n = int(input())
print(n // 2520)
# 1537625614765
```
Yes
| 12,086 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
IT City company developing computer games invented a new way to reward its employees. After a new game release users start buying it actively, and the company tracks the number of sales with precision to each transaction. Every time when the next number of sales is divisible by all numbers from 2 to 10 every developer of this game gets a small bonus.
A game designer Petya knows that the company is just about to release a new game that was partly developed by him. On the basis of his experience he predicts that n people will buy the game during the first month. Now Petya wants to determine how many times he will get the bonus. Help him to know it.
Input
The only line of the input contains one integer n (1 β€ n β€ 1018) β the prediction on the number of people who will buy the game.
Output
Output one integer showing how many numbers from 1 to n are divisible by all numbers from 2 to 10.
Examples
Input
3000
Output
1
Submitted Solution:
```
n = int(input());
m = int(n/2520);
print(m);
```
Yes
| 12,087 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
IT City company developing computer games invented a new way to reward its employees. After a new game release users start buying it actively, and the company tracks the number of sales with precision to each transaction. Every time when the next number of sales is divisible by all numbers from 2 to 10 every developer of this game gets a small bonus.
A game designer Petya knows that the company is just about to release a new game that was partly developed by him. On the basis of his experience he predicts that n people will buy the game during the first month. Now Petya wants to determine how many times he will get the bonus. Help him to know it.
Input
The only line of the input contains one integer n (1 β€ n β€ 1018) β the prediction on the number of people who will buy the game.
Output
Output one integer showing how many numbers from 1 to n are divisible by all numbers from 2 to 10.
Examples
Input
3000
Output
1
Submitted Solution:
```
D = (2 * 2 * 2) * (3 * 3) * 5 * 7
n = int(input())
print(int(n / D+1))
```
No
| 12,088 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
IT City company developing computer games invented a new way to reward its employees. After a new game release users start buying it actively, and the company tracks the number of sales with precision to each transaction. Every time when the next number of sales is divisible by all numbers from 2 to 10 every developer of this game gets a small bonus.
A game designer Petya knows that the company is just about to release a new game that was partly developed by him. On the basis of his experience he predicts that n people will buy the game during the first month. Now Petya wants to determine how many times he will get the bonus. Help him to know it.
Input
The only line of the input contains one integer n (1 β€ n β€ 1018) β the prediction on the number of people who will buy the game.
Output
Output one integer showing how many numbers from 1 to n are divisible by all numbers from 2 to 10.
Examples
Input
3000
Output
1
Submitted Solution:
```
n=int(input())
c=0
for i in range(1,n):
k=2
while k < 11 and (i%k)==0:
k+=1
if k==11:
c+=1
print(c)
```
No
| 12,089 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
IT City company developing computer games invented a new way to reward its employees. After a new game release users start buying it actively, and the company tracks the number of sales with precision to each transaction. Every time when the next number of sales is divisible by all numbers from 2 to 10 every developer of this game gets a small bonus.
A game designer Petya knows that the company is just about to release a new game that was partly developed by him. On the basis of his experience he predicts that n people will buy the game during the first month. Now Petya wants to determine how many times he will get the bonus. Help him to know it.
Input
The only line of the input contains one integer n (1 β€ n β€ 1018) β the prediction on the number of people who will buy the game.
Output
Output one integer showing how many numbers from 1 to n are divisible by all numbers from 2 to 10.
Examples
Input
3000
Output
1
Submitted Solution:
```
def problem3_3(month, day, year):
months = ("January","February","March","April","May","June",
"July","August","September","Octobor","November","December")
print(str(months[month-1]) + " " + str(day) + ", " + str(year))
```
No
| 12,090 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
IT City company developing computer games invented a new way to reward its employees. After a new game release users start buying it actively, and the company tracks the number of sales with precision to each transaction. Every time when the next number of sales is divisible by all numbers from 2 to 10 every developer of this game gets a small bonus.
A game designer Petya knows that the company is just about to release a new game that was partly developed by him. On the basis of his experience he predicts that n people will buy the game during the first month. Now Petya wants to determine how many times he will get the bonus. Help him to know it.
Input
The only line of the input contains one integer n (1 β€ n β€ 1018) β the prediction on the number of people who will buy the game.
Output
Output one integer showing how many numbers from 1 to n are divisible by all numbers from 2 to 10.
Examples
Input
3000
Output
1
Submitted Solution:
```
n = int(input())
a = []
k = int(n / 3000)
while n % 3000 != 0:
if n % 3 == 0:
if n % 4 == 0:
if n % 5 == 0:
if n % 6 == 0:
if n % 7 == 0:
if n % 8 == 0:
if n % 9 == 0:
a.append(n)
n -= 1
if len(a) > 0:
print(k+1)
else:
print(k)
```
No
| 12,091 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive.
The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest.
Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests.
Input
The first line of the input contains two integers n and m (2 β€ n β€ 100 000, 1 β€ m β€ 10 000, n β₯ 2m) β the number of participants of the qualifying contest and the number of regions in Berland.
Next n lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to 10 characters and consisting of large and small English letters), region number (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800, inclusive).
It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the m regions. The surnames that only differ in letter cases, should be considered distinct.
Output
Print m lines. On the i-th line print the team of the i-th region β the surnames of the two team members in an arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region.
Examples
Input
5 2
Ivanov 1 763
Andreev 2 800
Petrov 1 595
Sidorov 1 790
Semenov 2 503
Output
Sidorov Ivanov
Andreev Semenov
Input
5 2
Ivanov 1 800
Andreev 2 763
Petrov 1 800
Sidorov 1 800
Semenov 2 503
Output
?
Andreev Semenov
Note
In the first sample region teams are uniquely determined.
In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely.
Tags: constructive algorithms, sortings
Correct Solution:
```
tokens = []
tokens_next = 0
#file = open('in', 'r')
import sys
file = sys.stdin
def next_str():
global tokens, tokens_next
while tokens_next >= tokens.__len__() :
tokens = file.readline().split()
tokens_next = 0
tokens_next += 1
return tokens[tokens_next - 1]
def nextInt():
return int(next_str())
n = nextInt();
m = nextInt();
regions = [[] for i in range(n)]
for _ in range(n):
name, round, score = next_str(), nextInt(), nextInt();
regions[round].append((score, name))
for r in regions:
r.sort(reverse=True)
if len(r) < 2:
continue
if len(r) > 2 and r[1][0] == r[2][0]:
print('?')
else :
print(r[0][1], r[1][1])
```
| 12,092 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive.
The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest.
Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests.
Input
The first line of the input contains two integers n and m (2 β€ n β€ 100 000, 1 β€ m β€ 10 000, n β₯ 2m) β the number of participants of the qualifying contest and the number of regions in Berland.
Next n lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to 10 characters and consisting of large and small English letters), region number (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800, inclusive).
It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the m regions. The surnames that only differ in letter cases, should be considered distinct.
Output
Print m lines. On the i-th line print the team of the i-th region β the surnames of the two team members in an arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region.
Examples
Input
5 2
Ivanov 1 763
Andreev 2 800
Petrov 1 595
Sidorov 1 790
Semenov 2 503
Output
Sidorov Ivanov
Andreev Semenov
Input
5 2
Ivanov 1 800
Andreev 2 763
Petrov 1 800
Sidorov 1 800
Semenov 2 503
Output
?
Andreev Semenov
Note
In the first sample region teams are uniquely determined.
In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely.
Tags: constructive algorithms, sortings
Correct Solution:
```
namelist=[['','',''] for i in range(100005)]
scorelist=[[-1,-1,-1] for i in range(100005)]
def enroll(recod):
name=recod[0]
region=int(recod[1])
score=int(recod[2])
for i in range(3):
if score>scorelist[region][i]:
t=name
name=namelist[region][i]
namelist[region][i]=t
t=score
score=scorelist[region][i]
scorelist[region][i]=t
ll=input().split()
n=int(ll[0])
m=int(ll[1])
for i in range(n):
enroll(input().split())
for i in range(1,m+1):
if scorelist[i][1]!=scorelist[i][2]:
print("%s %s" % (namelist[i][0],namelist[i][1]))
else:
print("?")
```
| 12,093 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive.
The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest.
Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests.
Input
The first line of the input contains two integers n and m (2 β€ n β€ 100 000, 1 β€ m β€ 10 000, n β₯ 2m) β the number of participants of the qualifying contest and the number of regions in Berland.
Next n lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to 10 characters and consisting of large and small English letters), region number (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800, inclusive).
It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the m regions. The surnames that only differ in letter cases, should be considered distinct.
Output
Print m lines. On the i-th line print the team of the i-th region β the surnames of the two team members in an arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region.
Examples
Input
5 2
Ivanov 1 763
Andreev 2 800
Petrov 1 595
Sidorov 1 790
Semenov 2 503
Output
Sidorov Ivanov
Andreev Semenov
Input
5 2
Ivanov 1 800
Andreev 2 763
Petrov 1 800
Sidorov 1 800
Semenov 2 503
Output
?
Andreev Semenov
Note
In the first sample region teams are uniquely determined.
In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely.
Tags: constructive algorithms, sortings
Correct Solution:
```
import operator
class Participant:
def __init__(self,name,point):
self.name=name
self.point=point
n,m=map(int,input().split())
des=[None]*m
for i in range(m):
des[i]=[]
for i in range(n):
name,region,point=input().split()
des[int(region)-1].append(Participant(name,int(point)))
results=['?']*m
for i in range(m):
cur_region=des[i]
is_ok=False
if len(cur_region)==2:
is_ok=True
else:
cur_region.sort(key=operator.attrgetter('point'))
if cur_region[-2].point!=cur_region[-3].point:
is_ok=True
if is_ok:
results[i]=' '.join([cur_region[-1].name,cur_region[-2].name])
print('\n'.join(results))
```
| 12,094 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive.
The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest.
Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests.
Input
The first line of the input contains two integers n and m (2 β€ n β€ 100 000, 1 β€ m β€ 10 000, n β₯ 2m) β the number of participants of the qualifying contest and the number of regions in Berland.
Next n lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to 10 characters and consisting of large and small English letters), region number (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800, inclusive).
It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the m regions. The surnames that only differ in letter cases, should be considered distinct.
Output
Print m lines. On the i-th line print the team of the i-th region β the surnames of the two team members in an arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region.
Examples
Input
5 2
Ivanov 1 763
Andreev 2 800
Petrov 1 595
Sidorov 1 790
Semenov 2 503
Output
Sidorov Ivanov
Andreev Semenov
Input
5 2
Ivanov 1 800
Andreev 2 763
Petrov 1 800
Sidorov 1 800
Semenov 2 503
Output
?
Andreev Semenov
Note
In the first sample region teams are uniquely determined.
In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely.
Tags: constructive algorithms, sortings
Correct Solution:
```
def contest(n, m, P):
D = [[(-1, None), (-1, None), (-1, None)] for _ in range(m)]
for n, r, p in P:
D_i = D[r-1]
d = (p, n)
if d > D_i[0]:
D_i[2] = D_i[1]
D_i[1] = D_i[0]
D_i[0] = d
elif d > D_i[1]:
D_i[2] = D_i[1]
D_i[1] = d
elif d > D_i[2]:
D_i[2] = d
for i in range(m):
D_i = D[i]
if D_i[1][0] == D_i[2][0]:
yield '?'
else:
yield f'{D_i[0][1]} {D_i[1][1]}'
def readp():
n, sr, sp = input().split()
return n, int(sr), int(sp)
def main():
n, m = readinti()
P = [readp() for _ in range(n)]
print('\n'.join(contest(n, m, P)))
##########
import sys
def readint():
return int(input())
def readinti():
return map(int, input().split())
def readintt():
return tuple(readinti())
def readintl():
return list(readinti())
def readinttl(k):
return [readintt() for _ in range(k)]
def readintll(k):
return [readintl() for _ in range(k)]
def log(*args, **kwargs):
print(*args, **kwargs, file=sys.stderr)
if __name__ == '__main__':
main()
```
| 12,095 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive.
The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest.
Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests.
Input
The first line of the input contains two integers n and m (2 β€ n β€ 100 000, 1 β€ m β€ 10 000, n β₯ 2m) β the number of participants of the qualifying contest and the number of regions in Berland.
Next n lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to 10 characters and consisting of large and small English letters), region number (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800, inclusive).
It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the m regions. The surnames that only differ in letter cases, should be considered distinct.
Output
Print m lines. On the i-th line print the team of the i-th region β the surnames of the two team members in an arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region.
Examples
Input
5 2
Ivanov 1 763
Andreev 2 800
Petrov 1 595
Sidorov 1 790
Semenov 2 503
Output
Sidorov Ivanov
Andreev Semenov
Input
5 2
Ivanov 1 800
Andreev 2 763
Petrov 1 800
Sidorov 1 800
Semenov 2 503
Output
?
Andreev Semenov
Note
In the first sample region teams are uniquely determined.
In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely.
Tags: constructive algorithms, sortings
Correct Solution:
```
import sys
n, m = [int(x) for x in input().split()]
A = [[] for i in range(m)]
for line in sys.stdin:
name, region, result = line.split()
region, result = int(region) - 1, int(result)
A[region].append((result, name))
for a in A:
a.sort()
if len(a) > 2 and a[-2][0] == a[-3][0]:
sys.stdout.write('?\n')
else:
sys.stdout.write(a[-2][1] + ' ' + a[-1][1] + '\n')
```
| 12,096 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive.
The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest.
Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests.
Input
The first line of the input contains two integers n and m (2 β€ n β€ 100 000, 1 β€ m β€ 10 000, n β₯ 2m) β the number of participants of the qualifying contest and the number of regions in Berland.
Next n lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to 10 characters and consisting of large and small English letters), region number (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800, inclusive).
It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the m regions. The surnames that only differ in letter cases, should be considered distinct.
Output
Print m lines. On the i-th line print the team of the i-th region β the surnames of the two team members in an arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region.
Examples
Input
5 2
Ivanov 1 763
Andreev 2 800
Petrov 1 595
Sidorov 1 790
Semenov 2 503
Output
Sidorov Ivanov
Andreev Semenov
Input
5 2
Ivanov 1 800
Andreev 2 763
Petrov 1 800
Sidorov 1 800
Semenov 2 503
Output
?
Andreev Semenov
Note
In the first sample region teams are uniquely determined.
In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely.
Tags: constructive algorithms, sortings
Correct Solution:
```
n,m = map(int,input().split())
l = [[]for i in range(m)]
for i in range(n):
j = input().split()
j[1]=int(j[1])-1
j[2]=int(j[2])
l[j[1]].append((j[2],j[0]))
for i in range(m):
l[i].sort(reverse=1)
if len(l[i])>2 and l[i][1][0]==l[i][2][0]:
print('?')
else:
print(l[i][0][1],l[i][1][1])
```
| 12,097 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive.
The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest.
Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests.
Input
The first line of the input contains two integers n and m (2 β€ n β€ 100 000, 1 β€ m β€ 10 000, n β₯ 2m) β the number of participants of the qualifying contest and the number of regions in Berland.
Next n lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to 10 characters and consisting of large and small English letters), region number (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800, inclusive).
It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the m regions. The surnames that only differ in letter cases, should be considered distinct.
Output
Print m lines. On the i-th line print the team of the i-th region β the surnames of the two team members in an arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region.
Examples
Input
5 2
Ivanov 1 763
Andreev 2 800
Petrov 1 595
Sidorov 1 790
Semenov 2 503
Output
Sidorov Ivanov
Andreev Semenov
Input
5 2
Ivanov 1 800
Andreev 2 763
Petrov 1 800
Sidorov 1 800
Semenov 2 503
Output
?
Andreev Semenov
Note
In the first sample region teams are uniquely determined.
In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely.
Tags: constructive algorithms, sortings
Correct Solution:
```
n, m = map(int, input().split(' '))
c = {}
for i in range(n):
line = input().split()
line[1], line[2] = int(line[1]), int(line[2])
if line[1] not in c:
c[line[1]] = []
c[line[1]].append((line[2], line[0]))
for i in range(1, m+1):
c[i].sort(reverse = True)
if len(c[i]) > 2 and c[i][1][0] == c[i][2][0]:
print('?')
else:
print(c[i][0][1], c[i][1][1])
```
| 12,098 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive.
The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest.
Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests.
Input
The first line of the input contains two integers n and m (2 β€ n β€ 100 000, 1 β€ m β€ 10 000, n β₯ 2m) β the number of participants of the qualifying contest and the number of regions in Berland.
Next n lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to 10 characters and consisting of large and small English letters), region number (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800, inclusive).
It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the m regions. The surnames that only differ in letter cases, should be considered distinct.
Output
Print m lines. On the i-th line print the team of the i-th region β the surnames of the two team members in an arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region.
Examples
Input
5 2
Ivanov 1 763
Andreev 2 800
Petrov 1 595
Sidorov 1 790
Semenov 2 503
Output
Sidorov Ivanov
Andreev Semenov
Input
5 2
Ivanov 1 800
Andreev 2 763
Petrov 1 800
Sidorov 1 800
Semenov 2 503
Output
?
Andreev Semenov
Note
In the first sample region teams are uniquely determined.
In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely.
Tags: constructive algorithms, sortings
Correct Solution:
```
#!/usr/bin/python3
class StdIO:
def read_int(self):
return int(self.read_string())
def read_ints(self, sep=None):
return [int(i) for i in self.read_strings(sep)]
def read_float(self):
return float(self.read_string())
def read_floats(self, sep=None):
return [float(i) for i in self.read_strings(sep)]
def read_string(self):
return input()
def read_strings(self, sep=None):
return self.read_string().split(sep)
io = StdIO()
def main():
n, m = io.read_ints()
ppl = [list() for i in range(m)]
for i in range(n):
name, reg, score = io.read_strings()
reg = int(reg)
score = int(score)
reg -= 1
ppl[reg].append((score, name))
for reg in range(m):
ppl[reg].sort(reverse=True)
team = ppl[reg]
sca = team[0][0]
scb = team[1][0]
scc = team[2][0] if len(team) > 2 else None
if scc is None or (sca > scc and scb > scc):
print(team[0][1], team[1][1])
else:
print('?')
if __name__ == '__main__':
main()
```
| 12,099 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.