message stringlengths 2 65.1k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 0 108k | cluster float64 14 14 | __index_level_0__ int64 0 217k |
|---|---|---|---|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n parliamentarians in Berland. They are numbered with integers from 1 to n. It happened that all parliamentarians with odd indices are Democrats and all parliamentarians with even indices are Republicans.
New parliament assembly hall is a rectangle consisting of a Γ b chairs β a rows of b chairs each. Two chairs are considered neighbouring if they share as side. For example, chair number 5 in row number 2 is neighbouring to chairs number 4 and 6 in this row and chairs with number 5 in rows 1 and 3. Thus, chairs have four neighbours in general, except for the chairs on the border of the hall
We know that if two parliamentarians from one political party (that is two Democrats or two Republicans) seat nearby they spent all time discussing internal party issues.
Write the program that given the number of parliamentarians and the sizes of the hall determine if there is a way to find a seat for any parliamentarian, such that no two members of the same party share neighbouring seats.
Input
The first line of the input contains three integers n, a and b (1 β€ n β€ 10 000, 1 β€ a, b β€ 100) β the number of parliamentarians, the number of rows in the assembly hall and the number of seats in each row, respectively.
Output
If there is no way to assigns seats to parliamentarians in a proper way print -1.
Otherwise print the solution in a lines, each containing b integers. The j-th integer of the i-th line should be equal to the index of parliamentarian occupying this seat, or 0 if this seat should remain empty. If there are multiple possible solution, you may print any of them.
Examples
Input
3 2 2
Output
0 3
1 2
Input
8 4 3
Output
7 8 3
0 1 4
6 0 5
0 2 0
Input
10 2 2
Output
-1
Note
In the first sample there are many other possible solutions. For example,
3 2
0 1
and
2 1
3 0
The following assignment
3 2
1 0
is incorrect, because parliamentarians 1 and 3 are both from Democrats party but will occupy neighbouring seats. | instruction | 0 | 12,938 | 14 | 25,876 |
Tags: *special, constructive algorithms
Correct Solution:
```
members, row, column = [int(a) for a in input().split(' ')]
if members <= row * column:
current_row = []
current_members_in_current_row = 0
flip = 1
for row_number in range(row):
while current_members_in_current_row != column:
current_row.append(str(members))
current_members_in_current_row += 1
if members != 0:
members -= 1
print(' '.join(current_row[::flip]))
current_row = []
current_members_in_current_row = 0
flip *= -1
else:
print(-1)
``` | output | 1 | 12,938 | 14 | 25,877 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n parliamentarians in Berland. They are numbered with integers from 1 to n. It happened that all parliamentarians with odd indices are Democrats and all parliamentarians with even indices are Republicans.
New parliament assembly hall is a rectangle consisting of a Γ b chairs β a rows of b chairs each. Two chairs are considered neighbouring if they share as side. For example, chair number 5 in row number 2 is neighbouring to chairs number 4 and 6 in this row and chairs with number 5 in rows 1 and 3. Thus, chairs have four neighbours in general, except for the chairs on the border of the hall
We know that if two parliamentarians from one political party (that is two Democrats or two Republicans) seat nearby they spent all time discussing internal party issues.
Write the program that given the number of parliamentarians and the sizes of the hall determine if there is a way to find a seat for any parliamentarian, such that no two members of the same party share neighbouring seats.
Input
The first line of the input contains three integers n, a and b (1 β€ n β€ 10 000, 1 β€ a, b β€ 100) β the number of parliamentarians, the number of rows in the assembly hall and the number of seats in each row, respectively.
Output
If there is no way to assigns seats to parliamentarians in a proper way print -1.
Otherwise print the solution in a lines, each containing b integers. The j-th integer of the i-th line should be equal to the index of parliamentarian occupying this seat, or 0 if this seat should remain empty. If there are multiple possible solution, you may print any of them.
Examples
Input
3 2 2
Output
0 3
1 2
Input
8 4 3
Output
7 8 3
0 1 4
6 0 5
0 2 0
Input
10 2 2
Output
-1
Note
In the first sample there are many other possible solutions. For example,
3 2
0 1
and
2 1
3 0
The following assignment
3 2
1 0
is incorrect, because parliamentarians 1 and 3 are both from Democrats party but will occupy neighbouring seats.
Submitted Solution:
```
n,b,a = map(int, input().split())
mem = list(x for x in range(n))
if len(mem) > a * b:
print("-1")
else:
tmp_list = list(0 for _ in range(a*b))
for i in range(len(mem)):
tmp_list[i] = mem[i] + 1
index = 0
output = ""
for row in range(b):
if a % 2 == 0 and (row + 1) % 2 == 0:
tmp = tmp_list[index:index + a]
tmp = tmp[::-1]
output += " ".join(str(x) for x in tmp)
index += a
else:
tmp = tmp_list[index:index + a]
output += " ".join(str(x) for x in tmp)
index += a
output += '\n'
print(output)
``` | instruction | 0 | 12,939 | 14 | 25,878 |
Yes | output | 1 | 12,939 | 14 | 25,879 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n parliamentarians in Berland. They are numbered with integers from 1 to n. It happened that all parliamentarians with odd indices are Democrats and all parliamentarians with even indices are Republicans.
New parliament assembly hall is a rectangle consisting of a Γ b chairs β a rows of b chairs each. Two chairs are considered neighbouring if they share as side. For example, chair number 5 in row number 2 is neighbouring to chairs number 4 and 6 in this row and chairs with number 5 in rows 1 and 3. Thus, chairs have four neighbours in general, except for the chairs on the border of the hall
We know that if two parliamentarians from one political party (that is two Democrats or two Republicans) seat nearby they spent all time discussing internal party issues.
Write the program that given the number of parliamentarians and the sizes of the hall determine if there is a way to find a seat for any parliamentarian, such that no two members of the same party share neighbouring seats.
Input
The first line of the input contains three integers n, a and b (1 β€ n β€ 10 000, 1 β€ a, b β€ 100) β the number of parliamentarians, the number of rows in the assembly hall and the number of seats in each row, respectively.
Output
If there is no way to assigns seats to parliamentarians in a proper way print -1.
Otherwise print the solution in a lines, each containing b integers. The j-th integer of the i-th line should be equal to the index of parliamentarian occupying this seat, or 0 if this seat should remain empty. If there are multiple possible solution, you may print any of them.
Examples
Input
3 2 2
Output
0 3
1 2
Input
8 4 3
Output
7 8 3
0 1 4
6 0 5
0 2 0
Input
10 2 2
Output
-1
Note
In the first sample there are many other possible solutions. For example,
3 2
0 1
and
2 1
3 0
The following assignment
3 2
1 0
is incorrect, because parliamentarians 1 and 3 are both from Democrats party but will occupy neighbouring seats.
Submitted Solution:
```
n,a,b = map(int,input().split())
if n > a*b:
print('-1')
exit(0)
# if n == a*b:
# if n%2 == 1:
# print('-1')
# exit(0)
mat = [[0 for i in range(b)]for i in range(a)]
x,y = 2,1
for j in range(a):
if j%2:
for i in range(0,b,2):
if x > n:
break
mat[j][i] = x
x += 2
if x > n:
break
else:
for i in range(1,b,2):
if x > n:
break
mat[j][i] = x
x += 2
if x > n:
break
for j in range(a):
if j%2:
for i in range(1,b,2):
if y > n:
break
mat[j][i] = y
y += 2
if y > n:
break
else:
for i in range(0,b,2):
if y > n:
break
mat[j][i] = y
y += 2
if y > n:
break
for i in range(a):
for j in range(b):
print(mat[i][j],end=' ')
print()
``` | instruction | 0 | 12,940 | 14 | 25,880 |
Yes | output | 1 | 12,940 | 14 | 25,881 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n parliamentarians in Berland. They are numbered with integers from 1 to n. It happened that all parliamentarians with odd indices are Democrats and all parliamentarians with even indices are Republicans.
New parliament assembly hall is a rectangle consisting of a Γ b chairs β a rows of b chairs each. Two chairs are considered neighbouring if they share as side. For example, chair number 5 in row number 2 is neighbouring to chairs number 4 and 6 in this row and chairs with number 5 in rows 1 and 3. Thus, chairs have four neighbours in general, except for the chairs on the border of the hall
We know that if two parliamentarians from one political party (that is two Democrats or two Republicans) seat nearby they spent all time discussing internal party issues.
Write the program that given the number of parliamentarians and the sizes of the hall determine if there is a way to find a seat for any parliamentarian, such that no two members of the same party share neighbouring seats.
Input
The first line of the input contains three integers n, a and b (1 β€ n β€ 10 000, 1 β€ a, b β€ 100) β the number of parliamentarians, the number of rows in the assembly hall and the number of seats in each row, respectively.
Output
If there is no way to assigns seats to parliamentarians in a proper way print -1.
Otherwise print the solution in a lines, each containing b integers. The j-th integer of the i-th line should be equal to the index of parliamentarian occupying this seat, or 0 if this seat should remain empty. If there are multiple possible solution, you may print any of them.
Examples
Input
3 2 2
Output
0 3
1 2
Input
8 4 3
Output
7 8 3
0 1 4
6 0 5
0 2 0
Input
10 2 2
Output
-1
Note
In the first sample there are many other possible solutions. For example,
3 2
0 1
and
2 1
3 0
The following assignment
3 2
1 0
is incorrect, because parliamentarians 1 and 3 are both from Democrats party but will occupy neighbouring seats.
Submitted Solution:
```
from sys import maxsize as m
from itertools import product as P
class Solution:
def bazinga(self,N,p):
pass
if __name__=='__main__':
n,a,b = map(int,input().split(' '))
D = [str(i) for i in range(1,n+1,2)] #odd
R = [str(i) for i in range(2,n+1,2)] #even
M = [[0 for i in range(b)] for i in range(a)]
#print(R,D,M)
for p in P([i for i in range(a)],[i for i in range(b)]):
x,y=p[0],p[1]
if (x+y)%2!=0:
if R!=[]: M[x][y]=R.pop(-1)
else: M[x][y]= '0'
else:
if D!=[]: M[x][y]=D.pop(-1)
else: M[x][y]= '0'
if (len(D)>0 or len(R)>0) and n!=1:
print(-1)
else:
for i in range(len(M)):
print(' '.join(M[i]))
``` | instruction | 0 | 12,941 | 14 | 25,882 |
Yes | output | 1 | 12,941 | 14 | 25,883 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n parliamentarians in Berland. They are numbered with integers from 1 to n. It happened that all parliamentarians with odd indices are Democrats and all parliamentarians with even indices are Republicans.
New parliament assembly hall is a rectangle consisting of a Γ b chairs β a rows of b chairs each. Two chairs are considered neighbouring if they share as side. For example, chair number 5 in row number 2 is neighbouring to chairs number 4 and 6 in this row and chairs with number 5 in rows 1 and 3. Thus, chairs have four neighbours in general, except for the chairs on the border of the hall
We know that if two parliamentarians from one political party (that is two Democrats or two Republicans) seat nearby they spent all time discussing internal party issues.
Write the program that given the number of parliamentarians and the sizes of the hall determine if there is a way to find a seat for any parliamentarian, such that no two members of the same party share neighbouring seats.
Input
The first line of the input contains three integers n, a and b (1 β€ n β€ 10 000, 1 β€ a, b β€ 100) β the number of parliamentarians, the number of rows in the assembly hall and the number of seats in each row, respectively.
Output
If there is no way to assigns seats to parliamentarians in a proper way print -1.
Otherwise print the solution in a lines, each containing b integers. The j-th integer of the i-th line should be equal to the index of parliamentarian occupying this seat, or 0 if this seat should remain empty. If there are multiple possible solution, you may print any of them.
Examples
Input
3 2 2
Output
0 3
1 2
Input
8 4 3
Output
7 8 3
0 1 4
6 0 5
0 2 0
Input
10 2 2
Output
-1
Note
In the first sample there are many other possible solutions. For example,
3 2
0 1
and
2 1
3 0
The following assignment
3 2
1 0
is incorrect, because parliamentarians 1 and 3 are both from Democrats party but will occupy neighbouring seats.
Submitted Solution:
```
n, a, b = map(int, input().split())
ans = [[0] * b for _ in range(a)]
if n > a * b:
print(-1)
else:
for i in range(n):
ans[i // b][i % b] = i + 1
for i in range(a):
if b % 2 == 0 and i % 2 == 1:
ans[i] = ans[i][1:] + [ans[i][0]]
print(*ans[i])
``` | instruction | 0 | 12,942 | 14 | 25,884 |
Yes | output | 1 | 12,942 | 14 | 25,885 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n parliamentarians in Berland. They are numbered with integers from 1 to n. It happened that all parliamentarians with odd indices are Democrats and all parliamentarians with even indices are Republicans.
New parliament assembly hall is a rectangle consisting of a Γ b chairs β a rows of b chairs each. Two chairs are considered neighbouring if they share as side. For example, chair number 5 in row number 2 is neighbouring to chairs number 4 and 6 in this row and chairs with number 5 in rows 1 and 3. Thus, chairs have four neighbours in general, except for the chairs on the border of the hall
We know that if two parliamentarians from one political party (that is two Democrats or two Republicans) seat nearby they spent all time discussing internal party issues.
Write the program that given the number of parliamentarians and the sizes of the hall determine if there is a way to find a seat for any parliamentarian, such that no two members of the same party share neighbouring seats.
Input
The first line of the input contains three integers n, a and b (1 β€ n β€ 10 000, 1 β€ a, b β€ 100) β the number of parliamentarians, the number of rows in the assembly hall and the number of seats in each row, respectively.
Output
If there is no way to assigns seats to parliamentarians in a proper way print -1.
Otherwise print the solution in a lines, each containing b integers. The j-th integer of the i-th line should be equal to the index of parliamentarian occupying this seat, or 0 if this seat should remain empty. If there are multiple possible solution, you may print any of them.
Examples
Input
3 2 2
Output
0 3
1 2
Input
8 4 3
Output
7 8 3
0 1 4
6 0 5
0 2 0
Input
10 2 2
Output
-1
Note
In the first sample there are many other possible solutions. For example,
3 2
0 1
and
2 1
3 0
The following assignment
3 2
1 0
is incorrect, because parliamentarians 1 and 3 are both from Democrats party but will occupy neighbouring seats.
Submitted Solution:
```
n, a, b = map(int, input().split())
if n > a*b:
print(-1)
exit()
dd = 1
cur = 1
for j in range(a):
s = " ".join([str(i) if i <= n else "0" for i in range(cur, cur + b)])[::dd]
print(s)
cur += b
dd *= 1 if b%2 == 1 else -1
``` | instruction | 0 | 12,943 | 14 | 25,886 |
No | output | 1 | 12,943 | 14 | 25,887 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n parliamentarians in Berland. They are numbered with integers from 1 to n. It happened that all parliamentarians with odd indices are Democrats and all parliamentarians with even indices are Republicans.
New parliament assembly hall is a rectangle consisting of a Γ b chairs β a rows of b chairs each. Two chairs are considered neighbouring if they share as side. For example, chair number 5 in row number 2 is neighbouring to chairs number 4 and 6 in this row and chairs with number 5 in rows 1 and 3. Thus, chairs have four neighbours in general, except for the chairs on the border of the hall
We know that if two parliamentarians from one political party (that is two Democrats or two Republicans) seat nearby they spent all time discussing internal party issues.
Write the program that given the number of parliamentarians and the sizes of the hall determine if there is a way to find a seat for any parliamentarian, such that no two members of the same party share neighbouring seats.
Input
The first line of the input contains three integers n, a and b (1 β€ n β€ 10 000, 1 β€ a, b β€ 100) β the number of parliamentarians, the number of rows in the assembly hall and the number of seats in each row, respectively.
Output
If there is no way to assigns seats to parliamentarians in a proper way print -1.
Otherwise print the solution in a lines, each containing b integers. The j-th integer of the i-th line should be equal to the index of parliamentarian occupying this seat, or 0 if this seat should remain empty. If there are multiple possible solution, you may print any of them.
Examples
Input
3 2 2
Output
0 3
1 2
Input
8 4 3
Output
7 8 3
0 1 4
6 0 5
0 2 0
Input
10 2 2
Output
-1
Note
In the first sample there are many other possible solutions. For example,
3 2
0 1
and
2 1
3 0
The following assignment
3 2
1 0
is incorrect, because parliamentarians 1 and 3 are both from Democrats party but will occupy neighbouring seats.
Submitted Solution:
```
n=input()
llist=[]
llist=n.split()
kol=int(llist[0])
a=int(llist[1])
b=int(llist[2])
if a*b<kol:
print(-1)
else:
for i in range(a):
if i//2==0:
for j in range(b):
if i*b+j+1<=kol:
print(i*b+j+1, end = ' ')
else:
print('0', end=' ')
print(' ')
else:
for j in range(b):
j=b-j
if i*b+j+1<=kol:
print(i*b+j+1, end = ' ')
else:
print('0', end=' ')
print(' ')
``` | instruction | 0 | 12,944 | 14 | 25,888 |
No | output | 1 | 12,944 | 14 | 25,889 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n parliamentarians in Berland. They are numbered with integers from 1 to n. It happened that all parliamentarians with odd indices are Democrats and all parliamentarians with even indices are Republicans.
New parliament assembly hall is a rectangle consisting of a Γ b chairs β a rows of b chairs each. Two chairs are considered neighbouring if they share as side. For example, chair number 5 in row number 2 is neighbouring to chairs number 4 and 6 in this row and chairs with number 5 in rows 1 and 3. Thus, chairs have four neighbours in general, except for the chairs on the border of the hall
We know that if two parliamentarians from one political party (that is two Democrats or two Republicans) seat nearby they spent all time discussing internal party issues.
Write the program that given the number of parliamentarians and the sizes of the hall determine if there is a way to find a seat for any parliamentarian, such that no two members of the same party share neighbouring seats.
Input
The first line of the input contains three integers n, a and b (1 β€ n β€ 10 000, 1 β€ a, b β€ 100) β the number of parliamentarians, the number of rows in the assembly hall and the number of seats in each row, respectively.
Output
If there is no way to assigns seats to parliamentarians in a proper way print -1.
Otherwise print the solution in a lines, each containing b integers. The j-th integer of the i-th line should be equal to the index of parliamentarian occupying this seat, or 0 if this seat should remain empty. If there are multiple possible solution, you may print any of them.
Examples
Input
3 2 2
Output
0 3
1 2
Input
8 4 3
Output
7 8 3
0 1 4
6 0 5
0 2 0
Input
10 2 2
Output
-1
Note
In the first sample there are many other possible solutions. For example,
3 2
0 1
and
2 1
3 0
The following assignment
3 2
1 0
is incorrect, because parliamentarians 1 and 3 are both from Democrats party but will occupy neighbouring seats.
Submitted Solution:
```
n, r, c = map(int, input().split())
g = [[0 for _ in range(c)] for _ in range(r)]
ret = 0
for i in range(r):
for j in range(c):
if ret >= n:
continue
elif i > 0 and g[i-1][j] % 2 == (ret + 1) % 2:
continue
elif j > 0 and g[i][j-1] % 2 == (ret + 1) % 2:
continue
ret += 1
g[i][j] = ret
if ret < n:
print(-1)
else:
for l in g:
print(" ".join(map(str, l)))
``` | instruction | 0 | 12,945 | 14 | 25,890 |
No | output | 1 | 12,945 | 14 | 25,891 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n parliamentarians in Berland. They are numbered with integers from 1 to n. It happened that all parliamentarians with odd indices are Democrats and all parliamentarians with even indices are Republicans.
New parliament assembly hall is a rectangle consisting of a Γ b chairs β a rows of b chairs each. Two chairs are considered neighbouring if they share as side. For example, chair number 5 in row number 2 is neighbouring to chairs number 4 and 6 in this row and chairs with number 5 in rows 1 and 3. Thus, chairs have four neighbours in general, except for the chairs on the border of the hall
We know that if two parliamentarians from one political party (that is two Democrats or two Republicans) seat nearby they spent all time discussing internal party issues.
Write the program that given the number of parliamentarians and the sizes of the hall determine if there is a way to find a seat for any parliamentarian, such that no two members of the same party share neighbouring seats.
Input
The first line of the input contains three integers n, a and b (1 β€ n β€ 10 000, 1 β€ a, b β€ 100) β the number of parliamentarians, the number of rows in the assembly hall and the number of seats in each row, respectively.
Output
If there is no way to assigns seats to parliamentarians in a proper way print -1.
Otherwise print the solution in a lines, each containing b integers. The j-th integer of the i-th line should be equal to the index of parliamentarian occupying this seat, or 0 if this seat should remain empty. If there are multiple possible solution, you may print any of them.
Examples
Input
3 2 2
Output
0 3
1 2
Input
8 4 3
Output
7 8 3
0 1 4
6 0 5
0 2 0
Input
10 2 2
Output
-1
Note
In the first sample there are many other possible solutions. For example,
3 2
0 1
and
2 1
3 0
The following assignment
3 2
1 0
is incorrect, because parliamentarians 1 and 3 are both from Democrats party but will occupy neighbouring seats.
Submitted Solution:
```
import sys
EPS = sys.float_info.epsilon
LENGTH = 10
matrix = [[] for i in range(LENGTH)]
arr = [0] * 1001
n, a, b = map(int, input().split())
arr = [[0] * b for i in range(a)]
c1 = 3
c2 = 2
arr[0][0] = 1
for j in range(1, b):
arr[0][j] = j + 1
if j % 2 == 0 and c1 <= n:
arr[0][j] = c1
c1 += 2
elif j % 2 == 1 and c2 <= n:
arr[0][j] = c2
c2 += 2
for i in range(1, a):
for j in range(b):
val = arr[i - 1][j]
if val % 2 == 0 and c1 <= n:
arr[i][j] = c1
c1 += 2
elif val % 2 == 1 and c2 <= n:
arr[i][j] = c2
c2 += 2
if c1 > n and c2 > n:
for i in range(a):
for j in range(b):
print(arr[i][j], end=' ')
print()
else:
arr = [[0] * b for i in range(a)]
c1 = 1
c2 = 4
arr[0][0] = 2
for j in range(1, b):
arr[0][j] = j + 1
if j % 2 == 1 and c1 <= n:
arr[0][j] = c1
c1 += 2
elif j % 2 == 0 and c2 <= n:
arr[0][j] = c2
c2 += 2
for i in range(1, a):
for j in range(b):
val = arr[i - 1][j]
if val % 2 == 0 and c1 <= n:
arr[i][j] = c1
c1 += 2
elif val % 2 == 1 and c2 <= n:
arr[i][j] = c2
c2 += 2
if c1 > n and c2 > n:
for i in range(a):
for j in range(b):
print(arr[i][j], end=' ')
print()
else:
print(-1)
``` | instruction | 0 | 12,946 | 14 | 25,892 |
No | output | 1 | 12,946 | 14 | 25,893 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are quite a lot of ways to have fun with inflatable balloons. For example, you can fill them with water and see what happens.
Grigory and Andrew have the same opinion. So, once upon a time, they went to the shop and bought n packets with inflatable balloons, where i-th of them has exactly a_i balloons inside.
They want to divide the balloons among themselves. In addition, there are several conditions to hold:
* Do not rip the packets (both Grigory and Andrew should get unbroken packets);
* Distribute all packets (every packet should be given to someone);
* Give both Grigory and Andrew at least one packet;
* To provide more fun, the total number of balloons in Grigory's packets should not be equal to the total number of balloons in Andrew's packets.
Help them to divide the balloons or determine that it's impossible under these conditions.
Input
The first line of input contains a single integer n (1 β€ n β€ 10) β the number of packets with balloons.
The second line contains n integers: a_1, a_2, β¦, a_n (1 β€ a_i β€ 1000) β the number of balloons inside the corresponding packet.
Output
If it's impossible to divide the balloons satisfying the conditions above, print -1.
Otherwise, print an integer k β the number of packets to give to Grigory followed by k distinct integers from 1 to n β the indices of those. The order of packets doesn't matter.
If there are multiple ways to divide balloons, output any of them.
Examples
Input
3
1 2 1
Output
2
1 2
Input
2
5 5
Output
-1
Input
1
10
Output
-1
Note
In the first test Grigory gets 3 balloons in total while Andrey gets 1.
In the second test there's only one way to divide the packets which leads to equal numbers of balloons.
In the third test one of the boys won't get a packet at all. | instruction | 0 | 13,092 | 14 | 26,184 |
Tags: constructive algorithms, implementation
Correct Solution:
```
n = int(input())
a = list(map(int, input().split()))
if (n == 1) or (n == 2 and a[0] == a[1]):
print(-1)
else:
print(1)
print(a.index(min(a)) + 1)
``` | output | 1 | 13,092 | 14 | 26,185 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are quite a lot of ways to have fun with inflatable balloons. For example, you can fill them with water and see what happens.
Grigory and Andrew have the same opinion. So, once upon a time, they went to the shop and bought n packets with inflatable balloons, where i-th of them has exactly a_i balloons inside.
They want to divide the balloons among themselves. In addition, there are several conditions to hold:
* Do not rip the packets (both Grigory and Andrew should get unbroken packets);
* Distribute all packets (every packet should be given to someone);
* Give both Grigory and Andrew at least one packet;
* To provide more fun, the total number of balloons in Grigory's packets should not be equal to the total number of balloons in Andrew's packets.
Help them to divide the balloons or determine that it's impossible under these conditions.
Input
The first line of input contains a single integer n (1 β€ n β€ 10) β the number of packets with balloons.
The second line contains n integers: a_1, a_2, β¦, a_n (1 β€ a_i β€ 1000) β the number of balloons inside the corresponding packet.
Output
If it's impossible to divide the balloons satisfying the conditions above, print -1.
Otherwise, print an integer k β the number of packets to give to Grigory followed by k distinct integers from 1 to n β the indices of those. The order of packets doesn't matter.
If there are multiple ways to divide balloons, output any of them.
Examples
Input
3
1 2 1
Output
2
1 2
Input
2
5 5
Output
-1
Input
1
10
Output
-1
Note
In the first test Grigory gets 3 balloons in total while Andrey gets 1.
In the second test there's only one way to divide the packets which leads to equal numbers of balloons.
In the third test one of the boys won't get a packet at all. | instruction | 0 | 13,093 | 14 | 26,186 |
Tags: constructive algorithms, implementation
Correct Solution:
```
def read():
return int(input())
def rl():
return list(map(int, input().split()))
n = read()
a = rl()
if n == 1:
print("-1")
elif n == 2:
if a[0] == a[1]:
print("-1")
else:
print(1)
print(1)
else:
if a[0] == sum(a[1:]):
print(2)
print(1, 2)
else:
print(1)
print(1)
``` | output | 1 | 13,093 | 14 | 26,187 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are quite a lot of ways to have fun with inflatable balloons. For example, you can fill them with water and see what happens.
Grigory and Andrew have the same opinion. So, once upon a time, they went to the shop and bought n packets with inflatable balloons, where i-th of them has exactly a_i balloons inside.
They want to divide the balloons among themselves. In addition, there are several conditions to hold:
* Do not rip the packets (both Grigory and Andrew should get unbroken packets);
* Distribute all packets (every packet should be given to someone);
* Give both Grigory and Andrew at least one packet;
* To provide more fun, the total number of balloons in Grigory's packets should not be equal to the total number of balloons in Andrew's packets.
Help them to divide the balloons or determine that it's impossible under these conditions.
Input
The first line of input contains a single integer n (1 β€ n β€ 10) β the number of packets with balloons.
The second line contains n integers: a_1, a_2, β¦, a_n (1 β€ a_i β€ 1000) β the number of balloons inside the corresponding packet.
Output
If it's impossible to divide the balloons satisfying the conditions above, print -1.
Otherwise, print an integer k β the number of packets to give to Grigory followed by k distinct integers from 1 to n β the indices of those. The order of packets doesn't matter.
If there are multiple ways to divide balloons, output any of them.
Examples
Input
3
1 2 1
Output
2
1 2
Input
2
5 5
Output
-1
Input
1
10
Output
-1
Note
In the first test Grigory gets 3 balloons in total while Andrey gets 1.
In the second test there's only one way to divide the packets which leads to equal numbers of balloons.
In the third test one of the boys won't get a packet at all. | instruction | 0 | 13,094 | 14 | 26,188 |
Tags: constructive algorithms, implementation
Correct Solution:
```
n=int(input())
arr=[int(s) for s in input().split()]
min_=min(arr)
max_=max(arr)
for i in range(0,n):
if arr[i]==min_:
a=i
if n==1 or (n==2 and min_==max_):
print(-1)
else:
print(1)
print(a+1)
``` | output | 1 | 13,094 | 14 | 26,189 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are quite a lot of ways to have fun with inflatable balloons. For example, you can fill them with water and see what happens.
Grigory and Andrew have the same opinion. So, once upon a time, they went to the shop and bought n packets with inflatable balloons, where i-th of them has exactly a_i balloons inside.
They want to divide the balloons among themselves. In addition, there are several conditions to hold:
* Do not rip the packets (both Grigory and Andrew should get unbroken packets);
* Distribute all packets (every packet should be given to someone);
* Give both Grigory and Andrew at least one packet;
* To provide more fun, the total number of balloons in Grigory's packets should not be equal to the total number of balloons in Andrew's packets.
Help them to divide the balloons or determine that it's impossible under these conditions.
Input
The first line of input contains a single integer n (1 β€ n β€ 10) β the number of packets with balloons.
The second line contains n integers: a_1, a_2, β¦, a_n (1 β€ a_i β€ 1000) β the number of balloons inside the corresponding packet.
Output
If it's impossible to divide the balloons satisfying the conditions above, print -1.
Otherwise, print an integer k β the number of packets to give to Grigory followed by k distinct integers from 1 to n β the indices of those. The order of packets doesn't matter.
If there are multiple ways to divide balloons, output any of them.
Examples
Input
3
1 2 1
Output
2
1 2
Input
2
5 5
Output
-1
Input
1
10
Output
-1
Note
In the first test Grigory gets 3 balloons in total while Andrey gets 1.
In the second test there's only one way to divide the packets which leads to equal numbers of balloons.
In the third test one of the boys won't get a packet at all. | instruction | 0 | 13,095 | 14 | 26,190 |
Tags: constructive algorithms, implementation
Correct Solution:
```
n = int(input())
a = list(map(int, input().split()))
if n == 1:
print(-1)
else:
if a[0] == sum(a[1:]):
if n == 2:
print(-1)
else:
print(2)
print(1, 2)
else:
print(1)
print(1)
``` | output | 1 | 13,095 | 14 | 26,191 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are quite a lot of ways to have fun with inflatable balloons. For example, you can fill them with water and see what happens.
Grigory and Andrew have the same opinion. So, once upon a time, they went to the shop and bought n packets with inflatable balloons, where i-th of them has exactly a_i balloons inside.
They want to divide the balloons among themselves. In addition, there are several conditions to hold:
* Do not rip the packets (both Grigory and Andrew should get unbroken packets);
* Distribute all packets (every packet should be given to someone);
* Give both Grigory and Andrew at least one packet;
* To provide more fun, the total number of balloons in Grigory's packets should not be equal to the total number of balloons in Andrew's packets.
Help them to divide the balloons or determine that it's impossible under these conditions.
Input
The first line of input contains a single integer n (1 β€ n β€ 10) β the number of packets with balloons.
The second line contains n integers: a_1, a_2, β¦, a_n (1 β€ a_i β€ 1000) β the number of balloons inside the corresponding packet.
Output
If it's impossible to divide the balloons satisfying the conditions above, print -1.
Otherwise, print an integer k β the number of packets to give to Grigory followed by k distinct integers from 1 to n β the indices of those. The order of packets doesn't matter.
If there are multiple ways to divide balloons, output any of them.
Examples
Input
3
1 2 1
Output
2
1 2
Input
2
5 5
Output
-1
Input
1
10
Output
-1
Note
In the first test Grigory gets 3 balloons in total while Andrey gets 1.
In the second test there's only one way to divide the packets which leads to equal numbers of balloons.
In the third test one of the boys won't get a packet at all. | instruction | 0 | 13,096 | 14 | 26,192 |
Tags: constructive algorithms, implementation
Correct Solution:
```
#code
n,l = int(input()),list(map(int,input().split()))
l1 = sorted(l)
if len(l1)<2:
print(-1)
elif len(l1)==2:
if l1[-1]==l1[0]:
print(-1)
else:
print(1,1,sep='\n')
else:
print(1,l.index(l1[0])+1,sep='\n')
``` | output | 1 | 13,096 | 14 | 26,193 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are quite a lot of ways to have fun with inflatable balloons. For example, you can fill them with water and see what happens.
Grigory and Andrew have the same opinion. So, once upon a time, they went to the shop and bought n packets with inflatable balloons, where i-th of them has exactly a_i balloons inside.
They want to divide the balloons among themselves. In addition, there are several conditions to hold:
* Do not rip the packets (both Grigory and Andrew should get unbroken packets);
* Distribute all packets (every packet should be given to someone);
* Give both Grigory and Andrew at least one packet;
* To provide more fun, the total number of balloons in Grigory's packets should not be equal to the total number of balloons in Andrew's packets.
Help them to divide the balloons or determine that it's impossible under these conditions.
Input
The first line of input contains a single integer n (1 β€ n β€ 10) β the number of packets with balloons.
The second line contains n integers: a_1, a_2, β¦, a_n (1 β€ a_i β€ 1000) β the number of balloons inside the corresponding packet.
Output
If it's impossible to divide the balloons satisfying the conditions above, print -1.
Otherwise, print an integer k β the number of packets to give to Grigory followed by k distinct integers from 1 to n β the indices of those. The order of packets doesn't matter.
If there are multiple ways to divide balloons, output any of them.
Examples
Input
3
1 2 1
Output
2
1 2
Input
2
5 5
Output
-1
Input
1
10
Output
-1
Note
In the first test Grigory gets 3 balloons in total while Andrey gets 1.
In the second test there's only one way to divide the packets which leads to equal numbers of balloons.
In the third test one of the boys won't get a packet at all. | instruction | 0 | 13,097 | 14 | 26,194 |
Tags: constructive algorithms, implementation
Correct Solution:
```
sum=0;flag=0
m=[0]*2005
n=int(input())
a=list(map(int,input().split()))
for i in range(n):
sum+=a[i]
m[a[i]]=i+1
a.sort(reverse=True)
if n>1:
for i in range(n):
if a[i]<sum/2:
print(1)
print(m[a[i]])
flag=1
break
if flag!=1:
print(-1)
``` | output | 1 | 13,097 | 14 | 26,195 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are quite a lot of ways to have fun with inflatable balloons. For example, you can fill them with water and see what happens.
Grigory and Andrew have the same opinion. So, once upon a time, they went to the shop and bought n packets with inflatable balloons, where i-th of them has exactly a_i balloons inside.
They want to divide the balloons among themselves. In addition, there are several conditions to hold:
* Do not rip the packets (both Grigory and Andrew should get unbroken packets);
* Distribute all packets (every packet should be given to someone);
* Give both Grigory and Andrew at least one packet;
* To provide more fun, the total number of balloons in Grigory's packets should not be equal to the total number of balloons in Andrew's packets.
Help them to divide the balloons or determine that it's impossible under these conditions.
Input
The first line of input contains a single integer n (1 β€ n β€ 10) β the number of packets with balloons.
The second line contains n integers: a_1, a_2, β¦, a_n (1 β€ a_i β€ 1000) β the number of balloons inside the corresponding packet.
Output
If it's impossible to divide the balloons satisfying the conditions above, print -1.
Otherwise, print an integer k β the number of packets to give to Grigory followed by k distinct integers from 1 to n β the indices of those. The order of packets doesn't matter.
If there are multiple ways to divide balloons, output any of them.
Examples
Input
3
1 2 1
Output
2
1 2
Input
2
5 5
Output
-1
Input
1
10
Output
-1
Note
In the first test Grigory gets 3 balloons in total while Andrey gets 1.
In the second test there's only one way to divide the packets which leads to equal numbers of balloons.
In the third test one of the boys won't get a packet at all. | instruction | 0 | 13,098 | 14 | 26,196 |
Tags: constructive algorithms, implementation
Correct Solution:
```
n = int(input())
arr = list(map(int, input().split()))
if n == 1:
k = -1
elif n == 2 and arr[0] == arr[1]:
k = -1
else:
k = 1
ans = [1]
if arr[0] == sum(arr[1:]):
ans.append(2)
k = 2
print(k)
if k != -1:
print(*ans)
``` | output | 1 | 13,098 | 14 | 26,197 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are quite a lot of ways to have fun with inflatable balloons. For example, you can fill them with water and see what happens.
Grigory and Andrew have the same opinion. So, once upon a time, they went to the shop and bought n packets with inflatable balloons, where i-th of them has exactly a_i balloons inside.
They want to divide the balloons among themselves. In addition, there are several conditions to hold:
* Do not rip the packets (both Grigory and Andrew should get unbroken packets);
* Distribute all packets (every packet should be given to someone);
* Give both Grigory and Andrew at least one packet;
* To provide more fun, the total number of balloons in Grigory's packets should not be equal to the total number of balloons in Andrew's packets.
Help them to divide the balloons or determine that it's impossible under these conditions.
Input
The first line of input contains a single integer n (1 β€ n β€ 10) β the number of packets with balloons.
The second line contains n integers: a_1, a_2, β¦, a_n (1 β€ a_i β€ 1000) β the number of balloons inside the corresponding packet.
Output
If it's impossible to divide the balloons satisfying the conditions above, print -1.
Otherwise, print an integer k β the number of packets to give to Grigory followed by k distinct integers from 1 to n β the indices of those. The order of packets doesn't matter.
If there are multiple ways to divide balloons, output any of them.
Examples
Input
3
1 2 1
Output
2
1 2
Input
2
5 5
Output
-1
Input
1
10
Output
-1
Note
In the first test Grigory gets 3 balloons in total while Andrey gets 1.
In the second test there's only one way to divide the packets which leads to equal numbers of balloons.
In the third test one of the boys won't get a packet at all. | instruction | 0 | 13,099 | 14 | 26,198 |
Tags: constructive algorithms, implementation
Correct Solution:
```
n = int(input())
a = list(map(int, input().split()))
s = 0
for x in a:
s += x
if n == 1:
print(-1)
exit()
for i in range(n):
if 2 * a[i] != s:
print(1)
print(i + 1)
break
else:
print(-1)
``` | output | 1 | 13,099 | 14 | 26,199 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are quite a lot of ways to have fun with inflatable balloons. For example, you can fill them with water and see what happens.
Grigory and Andrew have the same opinion. So, once upon a time, they went to the shop and bought n packets with inflatable balloons, where i-th of them has exactly a_i balloons inside.
They want to divide the balloons among themselves. In addition, there are several conditions to hold:
* Do not rip the packets (both Grigory and Andrew should get unbroken packets);
* Distribute all packets (every packet should be given to someone);
* Give both Grigory and Andrew at least one packet;
* To provide more fun, the total number of balloons in Grigory's packets should not be equal to the total number of balloons in Andrew's packets.
Help them to divide the balloons or determine that it's impossible under these conditions.
Input
The first line of input contains a single integer n (1 β€ n β€ 10) β the number of packets with balloons.
The second line contains n integers: a_1, a_2, β¦, a_n (1 β€ a_i β€ 1000) β the number of balloons inside the corresponding packet.
Output
If it's impossible to divide the balloons satisfying the conditions above, print -1.
Otherwise, print an integer k β the number of packets to give to Grigory followed by k distinct integers from 1 to n β the indices of those. The order of packets doesn't matter.
If there are multiple ways to divide balloons, output any of them.
Examples
Input
3
1 2 1
Output
2
1 2
Input
2
5 5
Output
-1
Input
1
10
Output
-1
Note
In the first test Grigory gets 3 balloons in total while Andrey gets 1.
In the second test there's only one way to divide the packets which leads to equal numbers of balloons.
In the third test one of the boys won't get a packet at all.
Submitted Solution:
```
n=int(input())
x = list(map(int, input().split(" ")))
if n==1 or x.count(min(x))==2==len(x):
print(-1)
else:
print(1,x.index(min(x))+1,sep="\n")
``` | instruction | 0 | 13,100 | 14 | 26,200 |
Yes | output | 1 | 13,100 | 14 | 26,201 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are quite a lot of ways to have fun with inflatable balloons. For example, you can fill them with water and see what happens.
Grigory and Andrew have the same opinion. So, once upon a time, they went to the shop and bought n packets with inflatable balloons, where i-th of them has exactly a_i balloons inside.
They want to divide the balloons among themselves. In addition, there are several conditions to hold:
* Do not rip the packets (both Grigory and Andrew should get unbroken packets);
* Distribute all packets (every packet should be given to someone);
* Give both Grigory and Andrew at least one packet;
* To provide more fun, the total number of balloons in Grigory's packets should not be equal to the total number of balloons in Andrew's packets.
Help them to divide the balloons or determine that it's impossible under these conditions.
Input
The first line of input contains a single integer n (1 β€ n β€ 10) β the number of packets with balloons.
The second line contains n integers: a_1, a_2, β¦, a_n (1 β€ a_i β€ 1000) β the number of balloons inside the corresponding packet.
Output
If it's impossible to divide the balloons satisfying the conditions above, print -1.
Otherwise, print an integer k β the number of packets to give to Grigory followed by k distinct integers from 1 to n β the indices of those. The order of packets doesn't matter.
If there are multiple ways to divide balloons, output any of them.
Examples
Input
3
1 2 1
Output
2
1 2
Input
2
5 5
Output
-1
Input
1
10
Output
-1
Note
In the first test Grigory gets 3 balloons in total while Andrey gets 1.
In the second test there's only one way to divide the packets which leads to equal numbers of balloons.
In the third test one of the boys won't get a packet at all.
Submitted Solution:
```
n = int(input())
a = list(map(int, input().split()))
if n == 1:
print (-1)
elif n == 2 and a[0] == a[1]:
print (-1)
else:
m = min(a)
id = a.index(m) + 1
print (1)
print (id)
``` | instruction | 0 | 13,101 | 14 | 26,202 |
Yes | output | 1 | 13,101 | 14 | 26,203 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are quite a lot of ways to have fun with inflatable balloons. For example, you can fill them with water and see what happens.
Grigory and Andrew have the same opinion. So, once upon a time, they went to the shop and bought n packets with inflatable balloons, where i-th of them has exactly a_i balloons inside.
They want to divide the balloons among themselves. In addition, there are several conditions to hold:
* Do not rip the packets (both Grigory and Andrew should get unbroken packets);
* Distribute all packets (every packet should be given to someone);
* Give both Grigory and Andrew at least one packet;
* To provide more fun, the total number of balloons in Grigory's packets should not be equal to the total number of balloons in Andrew's packets.
Help them to divide the balloons or determine that it's impossible under these conditions.
Input
The first line of input contains a single integer n (1 β€ n β€ 10) β the number of packets with balloons.
The second line contains n integers: a_1, a_2, β¦, a_n (1 β€ a_i β€ 1000) β the number of balloons inside the corresponding packet.
Output
If it's impossible to divide the balloons satisfying the conditions above, print -1.
Otherwise, print an integer k β the number of packets to give to Grigory followed by k distinct integers from 1 to n β the indices of those. The order of packets doesn't matter.
If there are multiple ways to divide balloons, output any of them.
Examples
Input
3
1 2 1
Output
2
1 2
Input
2
5 5
Output
-1
Input
1
10
Output
-1
Note
In the first test Grigory gets 3 balloons in total while Andrey gets 1.
In the second test there's only one way to divide the packets which leads to equal numbers of balloons.
In the third test one of the boys won't get a packet at all.
Submitted Solution:
```
n=int(input())
arr=list(map(int,input().strip().split(' ')))
m=min(arr)
ind=arr.index(m)
if(n==1):
print(-1)
elif(n==2 and arr[0]==arr[1]):
print(-1)
else:
print(1)
print(ind+1)
``` | instruction | 0 | 13,102 | 14 | 26,204 |
Yes | output | 1 | 13,102 | 14 | 26,205 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are quite a lot of ways to have fun with inflatable balloons. For example, you can fill them with water and see what happens.
Grigory and Andrew have the same opinion. So, once upon a time, they went to the shop and bought n packets with inflatable balloons, where i-th of them has exactly a_i balloons inside.
They want to divide the balloons among themselves. In addition, there are several conditions to hold:
* Do not rip the packets (both Grigory and Andrew should get unbroken packets);
* Distribute all packets (every packet should be given to someone);
* Give both Grigory and Andrew at least one packet;
* To provide more fun, the total number of balloons in Grigory's packets should not be equal to the total number of balloons in Andrew's packets.
Help them to divide the balloons or determine that it's impossible under these conditions.
Input
The first line of input contains a single integer n (1 β€ n β€ 10) β the number of packets with balloons.
The second line contains n integers: a_1, a_2, β¦, a_n (1 β€ a_i β€ 1000) β the number of balloons inside the corresponding packet.
Output
If it's impossible to divide the balloons satisfying the conditions above, print -1.
Otherwise, print an integer k β the number of packets to give to Grigory followed by k distinct integers from 1 to n β the indices of those. The order of packets doesn't matter.
If there are multiple ways to divide balloons, output any of them.
Examples
Input
3
1 2 1
Output
2
1 2
Input
2
5 5
Output
-1
Input
1
10
Output
-1
Note
In the first test Grigory gets 3 balloons in total while Andrey gets 1.
In the second test there's only one way to divide the packets which leads to equal numbers of balloons.
In the third test one of the boys won't get a packet at all.
Submitted Solution:
```
n=int(input())
a=list(map(int,input().split()))
if n==1 or n==2 and a[0]==a[1]:
print(-1)
else:
print(1)
print(a.index(min(a))+1)
``` | instruction | 0 | 13,103 | 14 | 26,206 |
Yes | output | 1 | 13,103 | 14 | 26,207 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are quite a lot of ways to have fun with inflatable balloons. For example, you can fill them with water and see what happens.
Grigory and Andrew have the same opinion. So, once upon a time, they went to the shop and bought n packets with inflatable balloons, where i-th of them has exactly a_i balloons inside.
They want to divide the balloons among themselves. In addition, there are several conditions to hold:
* Do not rip the packets (both Grigory and Andrew should get unbroken packets);
* Distribute all packets (every packet should be given to someone);
* Give both Grigory and Andrew at least one packet;
* To provide more fun, the total number of balloons in Grigory's packets should not be equal to the total number of balloons in Andrew's packets.
Help them to divide the balloons or determine that it's impossible under these conditions.
Input
The first line of input contains a single integer n (1 β€ n β€ 10) β the number of packets with balloons.
The second line contains n integers: a_1, a_2, β¦, a_n (1 β€ a_i β€ 1000) β the number of balloons inside the corresponding packet.
Output
If it's impossible to divide the balloons satisfying the conditions above, print -1.
Otherwise, print an integer k β the number of packets to give to Grigory followed by k distinct integers from 1 to n β the indices of those. The order of packets doesn't matter.
If there are multiple ways to divide balloons, output any of them.
Examples
Input
3
1 2 1
Output
2
1 2
Input
2
5 5
Output
-1
Input
1
10
Output
-1
Note
In the first test Grigory gets 3 balloons in total while Andrey gets 1.
In the second test there's only one way to divide the packets which leads to equal numbers of balloons.
In the third test one of the boys won't get a packet at all.
Submitted Solution:
```
n = int(input())
a = list(map(int, input().split()))
a.sort()
if (a[0] == sum(a[:1]) or len(a) <= 1):
print(-1)
else:
print(a[0])
print(*a[1:])
``` | instruction | 0 | 13,104 | 14 | 26,208 |
No | output | 1 | 13,104 | 14 | 26,209 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are quite a lot of ways to have fun with inflatable balloons. For example, you can fill them with water and see what happens.
Grigory and Andrew have the same opinion. So, once upon a time, they went to the shop and bought n packets with inflatable balloons, where i-th of them has exactly a_i balloons inside.
They want to divide the balloons among themselves. In addition, there are several conditions to hold:
* Do not rip the packets (both Grigory and Andrew should get unbroken packets);
* Distribute all packets (every packet should be given to someone);
* Give both Grigory and Andrew at least one packet;
* To provide more fun, the total number of balloons in Grigory's packets should not be equal to the total number of balloons in Andrew's packets.
Help them to divide the balloons or determine that it's impossible under these conditions.
Input
The first line of input contains a single integer n (1 β€ n β€ 10) β the number of packets with balloons.
The second line contains n integers: a_1, a_2, β¦, a_n (1 β€ a_i β€ 1000) β the number of balloons inside the corresponding packet.
Output
If it's impossible to divide the balloons satisfying the conditions above, print -1.
Otherwise, print an integer k β the number of packets to give to Grigory followed by k distinct integers from 1 to n β the indices of those. The order of packets doesn't matter.
If there are multiple ways to divide balloons, output any of them.
Examples
Input
3
1 2 1
Output
2
1 2
Input
2
5 5
Output
-1
Input
1
10
Output
-1
Note
In the first test Grigory gets 3 balloons in total while Andrey gets 1.
In the second test there's only one way to divide the packets which leads to equal numbers of balloons.
In the third test one of the boys won't get a packet at all.
Submitted Solution:
```
a=int(input());b=sorted(map(int,input().split()));print(*[[-1],["1\n1"]][a>1 and b[0]!=sum(b)-b[0]])
``` | instruction | 0 | 13,105 | 14 | 26,210 |
No | output | 1 | 13,105 | 14 | 26,211 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are quite a lot of ways to have fun with inflatable balloons. For example, you can fill them with water and see what happens.
Grigory and Andrew have the same opinion. So, once upon a time, they went to the shop and bought n packets with inflatable balloons, where i-th of them has exactly a_i balloons inside.
They want to divide the balloons among themselves. In addition, there are several conditions to hold:
* Do not rip the packets (both Grigory and Andrew should get unbroken packets);
* Distribute all packets (every packet should be given to someone);
* Give both Grigory and Andrew at least one packet;
* To provide more fun, the total number of balloons in Grigory's packets should not be equal to the total number of balloons in Andrew's packets.
Help them to divide the balloons or determine that it's impossible under these conditions.
Input
The first line of input contains a single integer n (1 β€ n β€ 10) β the number of packets with balloons.
The second line contains n integers: a_1, a_2, β¦, a_n (1 β€ a_i β€ 1000) β the number of balloons inside the corresponding packet.
Output
If it's impossible to divide the balloons satisfying the conditions above, print -1.
Otherwise, print an integer k β the number of packets to give to Grigory followed by k distinct integers from 1 to n β the indices of those. The order of packets doesn't matter.
If there are multiple ways to divide balloons, output any of them.
Examples
Input
3
1 2 1
Output
2
1 2
Input
2
5 5
Output
-1
Input
1
10
Output
-1
Note
In the first test Grigory gets 3 balloons in total while Andrey gets 1.
In the second test there's only one way to divide the packets which leads to equal numbers of balloons.
In the third test one of the boys won't get a packet at all.
Submitted Solution:
```
n = int(input())
A = list(map(int, input().split()))
if n == 1:
print(-1)
elif len(A) == 2:
if A[0] != A[1]:
print(1)
print(A[0])
else:
print(-1)
else:
if sum(A) - A[n - 1] != A[:n-1]:
print(1)
print(A[n - 1])
else:
print(2)
print(A[n-1], A[n-2])
``` | instruction | 0 | 13,106 | 14 | 26,212 |
No | output | 1 | 13,106 | 14 | 26,213 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are quite a lot of ways to have fun with inflatable balloons. For example, you can fill them with water and see what happens.
Grigory and Andrew have the same opinion. So, once upon a time, they went to the shop and bought n packets with inflatable balloons, where i-th of them has exactly a_i balloons inside.
They want to divide the balloons among themselves. In addition, there are several conditions to hold:
* Do not rip the packets (both Grigory and Andrew should get unbroken packets);
* Distribute all packets (every packet should be given to someone);
* Give both Grigory and Andrew at least one packet;
* To provide more fun, the total number of balloons in Grigory's packets should not be equal to the total number of balloons in Andrew's packets.
Help them to divide the balloons or determine that it's impossible under these conditions.
Input
The first line of input contains a single integer n (1 β€ n β€ 10) β the number of packets with balloons.
The second line contains n integers: a_1, a_2, β¦, a_n (1 β€ a_i β€ 1000) β the number of balloons inside the corresponding packet.
Output
If it's impossible to divide the balloons satisfying the conditions above, print -1.
Otherwise, print an integer k β the number of packets to give to Grigory followed by k distinct integers from 1 to n β the indices of those. The order of packets doesn't matter.
If there are multiple ways to divide balloons, output any of them.
Examples
Input
3
1 2 1
Output
2
1 2
Input
2
5 5
Output
-1
Input
1
10
Output
-1
Note
In the first test Grigory gets 3 balloons in total while Andrey gets 1.
In the second test there's only one way to divide the packets which leads to equal numbers of balloons.
In the third test one of the boys won't get a packet at all.
Submitted Solution:
```
n = int(input())
ar = input().split()
mi = ar.index(min(ar))
print("-1" if n == 2 and ar[0] == ar[1] else "1 " + str(mi))
``` | instruction | 0 | 13,107 | 14 | 26,214 |
No | output | 1 | 13,107 | 14 | 26,215 |
Provide tags and a correct Python 3 solution for this coding contest problem.
During one of the space missions, humans have found an evidence of previous life at one of the planets. They were lucky enough to find a book with birth and death years of each individual that had been living at this planet. What's interesting is that these years are in the range (1, 10^9)! Therefore, the planet was named Longlifer.
In order to learn more about Longlifer's previous population, scientists need to determine the year with maximum number of individuals that were alive, as well as the number of alive individuals in that year. Your task is to help scientists solve this problem!
Input
The first line contains an integer n (1 β€ n β€ 10^5) β the number of people.
Each of the following n lines contain two integers b and d (1 β€ b < d β€ 10^9) representing birth and death year (respectively) of each individual.
Output
Print two integer numbers separated by blank character, y β the year with a maximum number of people alive and k β the number of people alive in year y.
In the case of multiple possible solutions, print the solution with minimum year.
Examples
Input
3
1 5
2 4
5 6
Output
2 2
Input
4
3 4
4 5
4 6
8 10
Output
4 2
Note
You can assume that an individual living from b to d has been born at the beginning of b and died at the beginning of d, and therefore living for d - b years. | instruction | 0 | 13,484 | 14 | 26,968 |
Tags: data structures, sortings
Correct Solution:
```
years = {}
for k in range(int(input())):
b, d = map(int, input().split())
if b in years:
years[b] += 1
else:
years[b] = 1
if d in years:
years[d] -= 1
else:
years[d] = -1
keys = sorted(years.keys())
maxLivingYear = 0
maxLivingCount = 0
currentCount = 0
for year in keys:
currentCount += years[year]
if currentCount > maxLivingCount:
maxLivingYear = year
maxLivingCount = currentCount
print(maxLivingYear, maxLivingCount)
``` | output | 1 | 13,484 | 14 | 26,969 |
Provide tags and a correct Python 3 solution for this coding contest problem.
During one of the space missions, humans have found an evidence of previous life at one of the planets. They were lucky enough to find a book with birth and death years of each individual that had been living at this planet. What's interesting is that these years are in the range (1, 10^9)! Therefore, the planet was named Longlifer.
In order to learn more about Longlifer's previous population, scientists need to determine the year with maximum number of individuals that were alive, as well as the number of alive individuals in that year. Your task is to help scientists solve this problem!
Input
The first line contains an integer n (1 β€ n β€ 10^5) β the number of people.
Each of the following n lines contain two integers b and d (1 β€ b < d β€ 10^9) representing birth and death year (respectively) of each individual.
Output
Print two integer numbers separated by blank character, y β the year with a maximum number of people alive and k β the number of people alive in year y.
In the case of multiple possible solutions, print the solution with minimum year.
Examples
Input
3
1 5
2 4
5 6
Output
2 2
Input
4
3 4
4 5
4 6
8 10
Output
4 2
Note
You can assume that an individual living from b to d has been born at the beginning of b and died at the beginning of d, and therefore living for d - b years. | instruction | 0 | 13,489 | 14 | 26,978 |
Tags: data structures, sortings
Correct Solution:
```
import sys
from collections import defaultdict
def load_sys():
return sys.stdin.readlines()
def load_local():
with open('input.txt','r') as f:
input=f.readlines()
return input
def years(arr):
events=[[x[0],'b'] for x in arr]+[[x[1],'d'] for x in arr]
events.sort(key=lambda x:x[0])
ctr=defaultdict(int)
for y,event in events:
if event=='b':
ctr[y]+=1
else:
ctr[y]-=1
prev=0
mx=float('-inf')
ans=0
for y in ctr:
prev+=ctr[y]
ctr[y]=prev
if ctr[y]>mx:
ans=y
mx=ctr[y]
return str(ans)+' '+str(mx)
#input=load_local()
input=load_sys()
N=int(input[0])
arr=[]
#test_cases=[]
for i in range(1,len(input)):
person=input[i].split()
person=[int(x) for x in person]
arr.append(person)
print(years(arr))
``` | output | 1 | 13,489 | 14 | 26,979 |
Provide tags and a correct Python 3 solution for this coding contest problem.
During the break the schoolchildren, boys and girls, formed a queue of n people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward each second.
Let's describe the process more precisely. Let's say that the positions in the queue are sequentially numbered by integers from 1 to n, at that the person in the position number 1 is served first. Then, if at time x a boy stands on the i-th position and a girl stands on the (i + 1)-th position, then at time x + 1 the i-th position will have a girl and the (i + 1)-th position will have a boy. The time is given in seconds.
You've got the initial position of the children, at the initial moment of time. Determine the way the queue is going to look after t seconds.
Input
The first line contains two integers n and t (1 β€ n, t β€ 50), which represent the number of children in the queue and the time after which the queue will transform into the arrangement you need to find.
The next line contains string s, which represents the schoolchildren's initial arrangement. If the i-th position in the queue contains a boy, then the i-th character of string s equals "B", otherwise the i-th character equals "G".
Output
Print string a, which describes the arrangement after t seconds. If the i-th position has a boy after the needed time, then the i-th character a must equal "B", otherwise it must equal "G".
Examples
Input
5 1
BGGBG
Output
GBGGB
Input
5 2
BGGBG
Output
GGBGB
Input
4 1
GGGB
Output
GGGB | instruction | 0 | 13,567 | 14 | 27,134 |
Tags: constructive algorithms, graph matchings, implementation, shortest paths
Correct Solution:
```
n,t = map(int,input().split())
seq = input().rstrip().lstrip()
main = [i for i in seq]
def find_boys(s):
d = []
for i in range(len(s)) :
if s[i] == "B":
d.append(i)
return d
for i in range(t):
li = find_boys(main)
for j in li:
if j != len(main) -1 and main[j+1] == "G":
main[j] , main[j+1] = main[j+1] , main[j]
print("".join(main))
``` | output | 1 | 13,567 | 14 | 27,135 |
Provide tags and a correct Python 3 solution for this coding contest problem.
During the break the schoolchildren, boys and girls, formed a queue of n people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward each second.
Let's describe the process more precisely. Let's say that the positions in the queue are sequentially numbered by integers from 1 to n, at that the person in the position number 1 is served first. Then, if at time x a boy stands on the i-th position and a girl stands on the (i + 1)-th position, then at time x + 1 the i-th position will have a girl and the (i + 1)-th position will have a boy. The time is given in seconds.
You've got the initial position of the children, at the initial moment of time. Determine the way the queue is going to look after t seconds.
Input
The first line contains two integers n and t (1 β€ n, t β€ 50), which represent the number of children in the queue and the time after which the queue will transform into the arrangement you need to find.
The next line contains string s, which represents the schoolchildren's initial arrangement. If the i-th position in the queue contains a boy, then the i-th character of string s equals "B", otherwise the i-th character equals "G".
Output
Print string a, which describes the arrangement after t seconds. If the i-th position has a boy after the needed time, then the i-th character a must equal "B", otherwise it must equal "G".
Examples
Input
5 1
BGGBG
Output
GBGGB
Input
5 2
BGGBG
Output
GGBGB
Input
4 1
GGGB
Output
GGGB | instruction | 0 | 13,568 | 14 | 27,136 |
Tags: constructive algorithms, graph matchings, implementation, shortest paths
Correct Solution:
```
n,p=map(int,input().split())
queue=input()
queue=list(queue)
i=0
for t in range(p):
while i<n-1:
if queue[i]=="B" and queue[i+1]=="G":
queue[i]="G"
queue[i+1]="B"
i+=2
else:
i+=1
i=0
print("".join(queue))
``` | output | 1 | 13,568 | 14 | 27,137 |
Provide tags and a correct Python 3 solution for this coding contest problem.
During the break the schoolchildren, boys and girls, formed a queue of n people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward each second.
Let's describe the process more precisely. Let's say that the positions in the queue are sequentially numbered by integers from 1 to n, at that the person in the position number 1 is served first. Then, if at time x a boy stands on the i-th position and a girl stands on the (i + 1)-th position, then at time x + 1 the i-th position will have a girl and the (i + 1)-th position will have a boy. The time is given in seconds.
You've got the initial position of the children, at the initial moment of time. Determine the way the queue is going to look after t seconds.
Input
The first line contains two integers n and t (1 β€ n, t β€ 50), which represent the number of children in the queue and the time after which the queue will transform into the arrangement you need to find.
The next line contains string s, which represents the schoolchildren's initial arrangement. If the i-th position in the queue contains a boy, then the i-th character of string s equals "B", otherwise the i-th character equals "G".
Output
Print string a, which describes the arrangement after t seconds. If the i-th position has a boy after the needed time, then the i-th character a must equal "B", otherwise it must equal "G".
Examples
Input
5 1
BGGBG
Output
GBGGB
Input
5 2
BGGBG
Output
GGBGB
Input
4 1
GGGB
Output
GGGB | instruction | 0 | 13,569 | 14 | 27,138 |
Tags: constructive algorithms, graph matchings, implementation, shortest paths
Correct Solution:
```
n,t = map(int,input().split(" "))
q = input()
klist = list(i for i in q)
for _ in range(t):
i = 0
while i < n-1:
if klist[i] == "B" and klist [i+1] == "G":
klist[i],klist[i+1] = klist[i+1],klist[i]
i += 1
i += 1
print("".join(klist))
``` | output | 1 | 13,569 | 14 | 27,139 |
Provide tags and a correct Python 3 solution for this coding contest problem.
During the break the schoolchildren, boys and girls, formed a queue of n people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward each second.
Let's describe the process more precisely. Let's say that the positions in the queue are sequentially numbered by integers from 1 to n, at that the person in the position number 1 is served first. Then, if at time x a boy stands on the i-th position and a girl stands on the (i + 1)-th position, then at time x + 1 the i-th position will have a girl and the (i + 1)-th position will have a boy. The time is given in seconds.
You've got the initial position of the children, at the initial moment of time. Determine the way the queue is going to look after t seconds.
Input
The first line contains two integers n and t (1 β€ n, t β€ 50), which represent the number of children in the queue and the time after which the queue will transform into the arrangement you need to find.
The next line contains string s, which represents the schoolchildren's initial arrangement. If the i-th position in the queue contains a boy, then the i-th character of string s equals "B", otherwise the i-th character equals "G".
Output
Print string a, which describes the arrangement after t seconds. If the i-th position has a boy after the needed time, then the i-th character a must equal "B", otherwise it must equal "G".
Examples
Input
5 1
BGGBG
Output
GBGGB
Input
5 2
BGGBG
Output
GGBGB
Input
4 1
GGGB
Output
GGGB | instruction | 0 | 13,570 | 14 | 27,140 |
Tags: constructive algorithms, graph matchings, implementation, shortest paths
Correct Solution:
```
import sys
u = sys.stdin.read().split("\n")
t = int(u[0].split()[1])
s = u[1]
newS = ""
for i in range(t):
if newS != "":
s = newS
newS = ""
switched = 0
for j in range(len(s)):
if s[j] == 'G':
if switched == 1:
newS += 'B'
switched = 0
else:
newS += s[j]
else:
if(j+1 == len(s)):
newS += s[j]
else:
if s[j+1] == 'G':
newS += 'G'
switched = 1
else:
newS += s[j]
print(newS)
``` | output | 1 | 13,570 | 14 | 27,141 |
Provide tags and a correct Python 3 solution for this coding contest problem.
During the break the schoolchildren, boys and girls, formed a queue of n people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward each second.
Let's describe the process more precisely. Let's say that the positions in the queue are sequentially numbered by integers from 1 to n, at that the person in the position number 1 is served first. Then, if at time x a boy stands on the i-th position and a girl stands on the (i + 1)-th position, then at time x + 1 the i-th position will have a girl and the (i + 1)-th position will have a boy. The time is given in seconds.
You've got the initial position of the children, at the initial moment of time. Determine the way the queue is going to look after t seconds.
Input
The first line contains two integers n and t (1 β€ n, t β€ 50), which represent the number of children in the queue and the time after which the queue will transform into the arrangement you need to find.
The next line contains string s, which represents the schoolchildren's initial arrangement. If the i-th position in the queue contains a boy, then the i-th character of string s equals "B", otherwise the i-th character equals "G".
Output
Print string a, which describes the arrangement after t seconds. If the i-th position has a boy after the needed time, then the i-th character a must equal "B", otherwise it must equal "G".
Examples
Input
5 1
BGGBG
Output
GBGGB
Input
5 2
BGGBG
Output
GGBGB
Input
4 1
GGGB
Output
GGGB | instruction | 0 | 13,571 | 14 | 27,142 |
Tags: constructive algorithms, graph matchings, implementation, shortest paths
Correct Solution:
```
from sys import stdin,stdout
from collections import Counter
def ai(): return list(map(int, stdin.readline().split()))
def ei(): return map(int, stdin.readline().split())
def ip(): return int(stdin.readline().strip())
def op(ans): return stdout.write(str(ans) + '\n')
from math import ceil
n,t = ei()
s = [i for i in input()]
for i in range(t):
x = set()
for j in range(n-1):
if s[j] == 'B' and s[j+1] == 'G' and j not in x and j+1 not in x:
s[j],s[j+1] = s[j+1],s[j]
x.add(j);x.add(j+1)
print("".join(s))
``` | output | 1 | 13,571 | 14 | 27,143 |
Provide tags and a correct Python 3 solution for this coding contest problem.
During the break the schoolchildren, boys and girls, formed a queue of n people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward each second.
Let's describe the process more precisely. Let's say that the positions in the queue are sequentially numbered by integers from 1 to n, at that the person in the position number 1 is served first. Then, if at time x a boy stands on the i-th position and a girl stands on the (i + 1)-th position, then at time x + 1 the i-th position will have a girl and the (i + 1)-th position will have a boy. The time is given in seconds.
You've got the initial position of the children, at the initial moment of time. Determine the way the queue is going to look after t seconds.
Input
The first line contains two integers n and t (1 β€ n, t β€ 50), which represent the number of children in the queue and the time after which the queue will transform into the arrangement you need to find.
The next line contains string s, which represents the schoolchildren's initial arrangement. If the i-th position in the queue contains a boy, then the i-th character of string s equals "B", otherwise the i-th character equals "G".
Output
Print string a, which describes the arrangement after t seconds. If the i-th position has a boy after the needed time, then the i-th character a must equal "B", otherwise it must equal "G".
Examples
Input
5 1
BGGBG
Output
GBGGB
Input
5 2
BGGBG
Output
GGBGB
Input
4 1
GGGB
Output
GGGB | instruction | 0 | 13,572 | 14 | 27,144 |
Tags: constructive algorithms, graph matchings, implementation, shortest paths
Correct Solution:
```
n,k = map(int,input().split())
q = input()
for i in range(k):
q = q.replace('BG','GB')
print(q)
``` | output | 1 | 13,572 | 14 | 27,145 |
Provide tags and a correct Python 3 solution for this coding contest problem.
During the break the schoolchildren, boys and girls, formed a queue of n people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward each second.
Let's describe the process more precisely. Let's say that the positions in the queue are sequentially numbered by integers from 1 to n, at that the person in the position number 1 is served first. Then, if at time x a boy stands on the i-th position and a girl stands on the (i + 1)-th position, then at time x + 1 the i-th position will have a girl and the (i + 1)-th position will have a boy. The time is given in seconds.
You've got the initial position of the children, at the initial moment of time. Determine the way the queue is going to look after t seconds.
Input
The first line contains two integers n and t (1 β€ n, t β€ 50), which represent the number of children in the queue and the time after which the queue will transform into the arrangement you need to find.
The next line contains string s, which represents the schoolchildren's initial arrangement. If the i-th position in the queue contains a boy, then the i-th character of string s equals "B", otherwise the i-th character equals "G".
Output
Print string a, which describes the arrangement after t seconds. If the i-th position has a boy after the needed time, then the i-th character a must equal "B", otherwise it must equal "G".
Examples
Input
5 1
BGGBG
Output
GBGGB
Input
5 2
BGGBG
Output
GGBGB
Input
4 1
GGGB
Output
GGGB | instruction | 0 | 13,573 | 14 | 27,146 |
Tags: constructive algorithms, graph matchings, implementation, shortest paths
Correct Solution:
```
b, c = map(int, input().split())
# a = []
# x = ['B']
y = []
# g = ""
e = input()
def swap(s, i, j):
lst = list(s)
# print("length of lst ", len(lst))
if i > len(lst)-1:
return
elif i < len(lst)-1:
lst[i], lst[j] = lst[j], lst[i]
elif i == len(lst)-1:
lst = list(s)
aa = ''.join(lst)
# return ''.join(lst)
return aa
# def callit(e):
# for n in range(0,len(y)):
# e = swap(e,int(y[n]),int(y[n])+1)
# return e
#
# p = int(0)
# if len(e) > 0:
# for j in e :
# if j == 'B':
# print(e.index(j)+p)
# p = e.index(j)
# print("VALUE OF p",p)
# e = e[e.index(j):]
for j in range(0,len(e)):
if e[j] == 'B':
y.append(j)
# print(y)
# for n in range(0, len(y)):
# e = swap(e, int(y[n]), int(y[n]) + 1)
# print(e)
count = 0
while (count <c):
for n in range(0, len(y)):
e = swap(e, int(y[n]), int(y[n]) + 1)
e = e
y.clear()
Y=[]
for j in range(0, len(e)):
if e[j] == 'B':
y.append(j)
# print(y)
count = count + 1
print(e)
``` | output | 1 | 13,573 | 14 | 27,147 |
Provide tags and a correct Python 3 solution for this coding contest problem.
During the break the schoolchildren, boys and girls, formed a queue of n people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward each second.
Let's describe the process more precisely. Let's say that the positions in the queue are sequentially numbered by integers from 1 to n, at that the person in the position number 1 is served first. Then, if at time x a boy stands on the i-th position and a girl stands on the (i + 1)-th position, then at time x + 1 the i-th position will have a girl and the (i + 1)-th position will have a boy. The time is given in seconds.
You've got the initial position of the children, at the initial moment of time. Determine the way the queue is going to look after t seconds.
Input
The first line contains two integers n and t (1 β€ n, t β€ 50), which represent the number of children in the queue and the time after which the queue will transform into the arrangement you need to find.
The next line contains string s, which represents the schoolchildren's initial arrangement. If the i-th position in the queue contains a boy, then the i-th character of string s equals "B", otherwise the i-th character equals "G".
Output
Print string a, which describes the arrangement after t seconds. If the i-th position has a boy after the needed time, then the i-th character a must equal "B", otherwise it must equal "G".
Examples
Input
5 1
BGGBG
Output
GBGGB
Input
5 2
BGGBG
Output
GGBGB
Input
4 1
GGGB
Output
GGGB | instruction | 0 | 13,574 | 14 | 27,148 |
Tags: constructive algorithms, graph matchings, implementation, shortest paths
Correct Solution:
```
seconds = [int(i) for i in input().split()][1]
queue = [i for i in input()]
for i in range(seconds):
pointer = 0
while pointer < len(queue):
try:
if queue[pointer] == 'B' and queue[pointer + 1] == 'G':
queue[pointer] = 'G'
queue[pointer + 1] = 'B'
pointer += 1
except:
pass
pointer += 1
print(''.join(queue))
``` | output | 1 | 13,574 | 14 | 27,149 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
During the break the schoolchildren, boys and girls, formed a queue of n people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward each second.
Let's describe the process more precisely. Let's say that the positions in the queue are sequentially numbered by integers from 1 to n, at that the person in the position number 1 is served first. Then, if at time x a boy stands on the i-th position and a girl stands on the (i + 1)-th position, then at time x + 1 the i-th position will have a girl and the (i + 1)-th position will have a boy. The time is given in seconds.
You've got the initial position of the children, at the initial moment of time. Determine the way the queue is going to look after t seconds.
Input
The first line contains two integers n and t (1 β€ n, t β€ 50), which represent the number of children in the queue and the time after which the queue will transform into the arrangement you need to find.
The next line contains string s, which represents the schoolchildren's initial arrangement. If the i-th position in the queue contains a boy, then the i-th character of string s equals "B", otherwise the i-th character equals "G".
Output
Print string a, which describes the arrangement after t seconds. If the i-th position has a boy after the needed time, then the i-th character a must equal "B", otherwise it must equal "G".
Examples
Input
5 1
BGGBG
Output
GBGGB
Input
5 2
BGGBG
Output
GGBGB
Input
4 1
GGGB
Output
GGGB
Submitted Solution:
```
# cook your dish here
n, t = tuple(map(int,input().split()))
s1=input()
s=[]
for tn in s1:
s.append(tn)
for lgc in range(t):
i=0
while(i<n-1):
if(s[i]=='B' and s[i+1]=='G' ):
s[i]='G'
s[i+1]='B'
i+=1
i+=1
for i in s:
print(i,end='')
``` | instruction | 0 | 13,575 | 14 | 27,150 |
Yes | output | 1 | 13,575 | 14 | 27,151 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
During the break the schoolchildren, boys and girls, formed a queue of n people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward each second.
Let's describe the process more precisely. Let's say that the positions in the queue are sequentially numbered by integers from 1 to n, at that the person in the position number 1 is served first. Then, if at time x a boy stands on the i-th position and a girl stands on the (i + 1)-th position, then at time x + 1 the i-th position will have a girl and the (i + 1)-th position will have a boy. The time is given in seconds.
You've got the initial position of the children, at the initial moment of time. Determine the way the queue is going to look after t seconds.
Input
The first line contains two integers n and t (1 β€ n, t β€ 50), which represent the number of children in the queue and the time after which the queue will transform into the arrangement you need to find.
The next line contains string s, which represents the schoolchildren's initial arrangement. If the i-th position in the queue contains a boy, then the i-th character of string s equals "B", otherwise the i-th character equals "G".
Output
Print string a, which describes the arrangement after t seconds. If the i-th position has a boy after the needed time, then the i-th character a must equal "B", otherwise it must equal "G".
Examples
Input
5 1
BGGBG
Output
GBGGB
Input
5 2
BGGBG
Output
GGBGB
Input
4 1
GGGB
Output
GGGB
Submitted Solution:
```
n,t = map(int,input().split())
li = str(input())
l=list(li)
for n in range(t):
i=1
while(i<len(l)):
if(l[i]=='G' and l[i-1]=='B'):
l[i-1]='G'
l[i]='B'
i=i+1
i=i+1
print("".join(l))
``` | instruction | 0 | 13,576 | 14 | 27,152 |
Yes | output | 1 | 13,576 | 14 | 27,153 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
During the break the schoolchildren, boys and girls, formed a queue of n people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward each second.
Let's describe the process more precisely. Let's say that the positions in the queue are sequentially numbered by integers from 1 to n, at that the person in the position number 1 is served first. Then, if at time x a boy stands on the i-th position and a girl stands on the (i + 1)-th position, then at time x + 1 the i-th position will have a girl and the (i + 1)-th position will have a boy. The time is given in seconds.
You've got the initial position of the children, at the initial moment of time. Determine the way the queue is going to look after t seconds.
Input
The first line contains two integers n and t (1 β€ n, t β€ 50), which represent the number of children in the queue and the time after which the queue will transform into the arrangement you need to find.
The next line contains string s, which represents the schoolchildren's initial arrangement. If the i-th position in the queue contains a boy, then the i-th character of string s equals "B", otherwise the i-th character equals "G".
Output
Print string a, which describes the arrangement after t seconds. If the i-th position has a boy after the needed time, then the i-th character a must equal "B", otherwise it must equal "G".
Examples
Input
5 1
BGGBG
Output
GBGGB
Input
5 2
BGGBG
Output
GGBGB
Input
4 1
GGGB
Output
GGGB
Submitted Solution:
```
n,b=map(int,input().split())
a=input()
for i in range(b):
a=a.replace("BG","GB")
print(a)
``` | instruction | 0 | 13,577 | 14 | 27,154 |
Yes | output | 1 | 13,577 | 14 | 27,155 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
During the break the schoolchildren, boys and girls, formed a queue of n people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward each second.
Let's describe the process more precisely. Let's say that the positions in the queue are sequentially numbered by integers from 1 to n, at that the person in the position number 1 is served first. Then, if at time x a boy stands on the i-th position and a girl stands on the (i + 1)-th position, then at time x + 1 the i-th position will have a girl and the (i + 1)-th position will have a boy. The time is given in seconds.
You've got the initial position of the children, at the initial moment of time. Determine the way the queue is going to look after t seconds.
Input
The first line contains two integers n and t (1 β€ n, t β€ 50), which represent the number of children in the queue and the time after which the queue will transform into the arrangement you need to find.
The next line contains string s, which represents the schoolchildren's initial arrangement. If the i-th position in the queue contains a boy, then the i-th character of string s equals "B", otherwise the i-th character equals "G".
Output
Print string a, which describes the arrangement after t seconds. If the i-th position has a boy after the needed time, then the i-th character a must equal "B", otherwise it must equal "G".
Examples
Input
5 1
BGGBG
Output
GBGGB
Input
5 2
BGGBG
Output
GGBGB
Input
4 1
GGGB
Output
GGGB
Submitted Solution:
```
N=[int(x) for x in input().split()]
queue=input()
a=[]
b=[]
for i in range(0,N[0]):
a.append(queue[i])
b.append(queue[i])
for i in range(0,N[1]):
for j in range(0,N[0]-1):
if a[j]=='B' and a[j+1]=='G':
b[j]='G'
b[j+1]='B'
for j in range(0,N[0]):
a[j]=b[j]
print(''.join(a))
``` | instruction | 0 | 13,578 | 14 | 27,156 |
Yes | output | 1 | 13,578 | 14 | 27,157 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
During the break the schoolchildren, boys and girls, formed a queue of n people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward each second.
Let's describe the process more precisely. Let's say that the positions in the queue are sequentially numbered by integers from 1 to n, at that the person in the position number 1 is served first. Then, if at time x a boy stands on the i-th position and a girl stands on the (i + 1)-th position, then at time x + 1 the i-th position will have a girl and the (i + 1)-th position will have a boy. The time is given in seconds.
You've got the initial position of the children, at the initial moment of time. Determine the way the queue is going to look after t seconds.
Input
The first line contains two integers n and t (1 β€ n, t β€ 50), which represent the number of children in the queue and the time after which the queue will transform into the arrangement you need to find.
The next line contains string s, which represents the schoolchildren's initial arrangement. If the i-th position in the queue contains a boy, then the i-th character of string s equals "B", otherwise the i-th character equals "G".
Output
Print string a, which describes the arrangement after t seconds. If the i-th position has a boy after the needed time, then the i-th character a must equal "B", otherwise it must equal "G".
Examples
Input
5 1
BGGBG
Output
GBGGB
Input
5 2
BGGBG
Output
GGBGB
Input
4 1
GGGB
Output
GGGB
Submitted Solution:
```
array = list(map(int, input().split(' ')))
queue = input()
n = array[0]
t = array[1]
item = 0
i = 0
while item != t:
pos = queue.find('B', i, n)
i = pos+2
queue = [i for i in queue]
if pos == n-1:
queue = ''.join(queue)
break
elif queue[pos+1] == 'G' and pos >= 0:
queue[pos],queue[pos+1] = queue[pos+1],queue[pos]
if i >= n:
i = 0
item += 1
queue = ''.join(queue)
print(queue)
``` | instruction | 0 | 13,579 | 14 | 27,158 |
No | output | 1 | 13,579 | 14 | 27,159 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
During the break the schoolchildren, boys and girls, formed a queue of n people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward each second.
Let's describe the process more precisely. Let's say that the positions in the queue are sequentially numbered by integers from 1 to n, at that the person in the position number 1 is served first. Then, if at time x a boy stands on the i-th position and a girl stands on the (i + 1)-th position, then at time x + 1 the i-th position will have a girl and the (i + 1)-th position will have a boy. The time is given in seconds.
You've got the initial position of the children, at the initial moment of time. Determine the way the queue is going to look after t seconds.
Input
The first line contains two integers n and t (1 β€ n, t β€ 50), which represent the number of children in the queue and the time after which the queue will transform into the arrangement you need to find.
The next line contains string s, which represents the schoolchildren's initial arrangement. If the i-th position in the queue contains a boy, then the i-th character of string s equals "B", otherwise the i-th character equals "G".
Output
Print string a, which describes the arrangement after t seconds. If the i-th position has a boy after the needed time, then the i-th character a must equal "B", otherwise it must equal "G".
Examples
Input
5 1
BGGBG
Output
GBGGB
Input
5 2
BGGBG
Output
GGBGB
Input
4 1
GGGB
Output
GGGB
Submitted Solution:
```
x=list(map(int,input().split()))
s=list(input())
print(s)
for i in range(x[1]):
for j in range(len(s)-1):
if s[j]=='B' and s[j+1]=='G':
s[j]='G'
s[j+1]='B'
print(*s)
``` | instruction | 0 | 13,580 | 14 | 27,160 |
No | output | 1 | 13,580 | 14 | 27,161 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
During the break the schoolchildren, boys and girls, formed a queue of n people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward each second.
Let's describe the process more precisely. Let's say that the positions in the queue are sequentially numbered by integers from 1 to n, at that the person in the position number 1 is served first. Then, if at time x a boy stands on the i-th position and a girl stands on the (i + 1)-th position, then at time x + 1 the i-th position will have a girl and the (i + 1)-th position will have a boy. The time is given in seconds.
You've got the initial position of the children, at the initial moment of time. Determine the way the queue is going to look after t seconds.
Input
The first line contains two integers n and t (1 β€ n, t β€ 50), which represent the number of children in the queue and the time after which the queue will transform into the arrangement you need to find.
The next line contains string s, which represents the schoolchildren's initial arrangement. If the i-th position in the queue contains a boy, then the i-th character of string s equals "B", otherwise the i-th character equals "G".
Output
Print string a, which describes the arrangement after t seconds. If the i-th position has a boy after the needed time, then the i-th character a must equal "B", otherwise it must equal "G".
Examples
Input
5 1
BGGBG
Output
GBGGB
Input
5 2
BGGBG
Output
GGBGB
Input
4 1
GGGB
Output
GGGB
Submitted Solution:
```
size,time = map(int,input().split(" "))
string = input()
length = len(string)
my_list = [a for a in string]
while time > 0:
i = 0
while i < size-1:
if my_list[i] == "B" and my_list[i+1] == "G":
my_list[i+1] = "B"
my_list[i] = "G"
i = i + 2
else:
i = i + 1
time-=1
print(my_list)
``` | instruction | 0 | 13,581 | 14 | 27,162 |
No | output | 1 | 13,581 | 14 | 27,163 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
During the break the schoolchildren, boys and girls, formed a queue of n people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward each second.
Let's describe the process more precisely. Let's say that the positions in the queue are sequentially numbered by integers from 1 to n, at that the person in the position number 1 is served first. Then, if at time x a boy stands on the i-th position and a girl stands on the (i + 1)-th position, then at time x + 1 the i-th position will have a girl and the (i + 1)-th position will have a boy. The time is given in seconds.
You've got the initial position of the children, at the initial moment of time. Determine the way the queue is going to look after t seconds.
Input
The first line contains two integers n and t (1 β€ n, t β€ 50), which represent the number of children in the queue and the time after which the queue will transform into the arrangement you need to find.
The next line contains string s, which represents the schoolchildren's initial arrangement. If the i-th position in the queue contains a boy, then the i-th character of string s equals "B", otherwise the i-th character equals "G".
Output
Print string a, which describes the arrangement after t seconds. If the i-th position has a boy after the needed time, then the i-th character a must equal "B", otherwise it must equal "G".
Examples
Input
5 1
BGGBG
Output
GBGGB
Input
5 2
BGGBG
Output
GGBGB
Input
4 1
GGGB
Output
GGGB
Submitted Solution:
```
lis = list(map(int, input().split()))
st = list(input())
for j in range(lis[1]):
for i in range(lis[0] -1):
if st[i] == 'B' and st[i+1] == 'G':
st[i], st[i+1] = st[i+1], st[i]
stc = ("".join(st))
print(stc)
``` | instruction | 0 | 13,582 | 14 | 27,164 |
No | output | 1 | 13,582 | 14 | 27,165 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Spongebob is already tired trying to reason his weird actions and calculations, so he simply asked you to find all pairs of n and m, such that there are exactly x distinct squares in the table consisting of n rows and m columns. For example, in a 3 Γ 5 table there are 15 squares with side one, 8 squares with side two and 3 squares with side three. The total number of distinct squares in a 3 Γ 5 table is 15 + 8 + 3 = 26.
Input
The first line of the input contains a single integer x (1 β€ x β€ 1018) β the number of squares inside the tables Spongebob is interested in.
Output
First print a single integer k β the number of tables with exactly x distinct squares inside.
Then print k pairs of integers describing the tables. Print the pairs in the order of increasing n, and in case of equality β in the order of increasing m.
Examples
Input
26
Output
6
1 26
2 9
3 5
5 3
9 2
26 1
Input
2
Output
2
1 2
2 1
Input
8
Output
4
1 8
2 3
3 2
8 1
Note
In a 1 Γ 2 table there are 2 1 Γ 1 squares. So, 2 distinct squares in total.
<image>
In a 2 Γ 3 table there are 6 1 Γ 1 squares and 2 2 Γ 2 squares. That is equal to 8 squares in total.
<image> | instruction | 0 | 13,705 | 14 | 27,410 |
Tags: brute force, math
Correct Solution:
```
p, q = int(input()), 1
t, n = [], 1
while p > n * q:
if p % q == 0: t.append((p // q, n))
n += 1
q += n
p += (n * n - n) // 2
t += [(m, n) for n, m in t]
if p == n * q: t.append((n, n))
print(len(t))
for n, m in sorted(t): print(n, m)
``` | output | 1 | 13,705 | 14 | 27,411 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n pearls in a row. Let's enumerate them with integers from 1 to n from the left to the right. The pearl number i has the type ai.
Let's call a sequence of consecutive pearls a segment. Let's call a segment good if it contains two pearls of the same type.
Split the row of the pearls to the maximal number of good segments. Note that each pearl should appear in exactly one segment of the partition.
As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
Input
The first line contains integer n (1 β€ n β€ 3Β·105) β the number of pearls in a row.
The second line contains n integers ai (1 β€ ai β€ 109) β the type of the i-th pearl.
Output
On the first line print integer k β the maximal number of segments in a partition of the row.
Each of the next k lines should contain two integers lj, rj (1 β€ lj β€ rj β€ n) β the number of the leftmost and the rightmost pearls in the j-th segment.
Note you should print the correct partition of the row of the pearls, so each pearl should be in exactly one segment and all segments should contain two pearls of the same type.
If there are several optimal solutions print any of them. You can print the segments in any order.
If there are no correct partitions of the row print the number "-1".
Examples
Input
5
1 2 3 4 1
Output
1
1 5
Input
5
1 2 3 4 5
Output
-1
Input
7
1 2 1 3 1 2 1
Output
2
1 3
4 7 | instruction | 0 | 13,722 | 14 | 27,444 |
Tags: greedy
Correct Solution:
```
#### IMPORTANT LIBRARY ####
############################
### DO NOT USE import random --> 250ms to load the library
############################
### In case of extra libraries: https://github.com/cheran-senthil/PyRival
######################
####### IMPORT #######
######################
from functools import cmp_to_key
from collections import deque, Counter
from heapq import heappush, heappop
from math import log, ceil
######################
#### STANDARD I/O ####
######################
import sys
import os
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")
if sys.version_info[0] < 3:
sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
def print(*args, **kwargs):
sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
at_start = True
for x in args:
if not at_start:
file.write(sep)
file.write(str(x))
at_start = False
file.write(kwargs.pop("end", "\n"))
if kwargs.pop("flush", False):
file.flush()
def inp():
return sys.stdin.readline().rstrip("\r\n") # for fast input
def ii():
return int(inp())
def si():
return str(inp())
def li(lag = 0):
l = list(map(int, inp().split()))
if lag != 0:
for i in range(len(l)):
l[i] += lag
return l
def mi(lag = 0):
matrix = list()
for i in range(n):
matrix.append(li(lag))
return matrix
def lsi(): #string list
return list(map(str, inp().split()))
def print_list(lista, space = " "):
print(space.join(map(str, lista)))
######################
### BISECT METHODS ###
######################
def bisect_left(a, x):
"""i tale che a[i] >= x e a[i-1] < x"""
left = 0
right = len(a)
while left < right:
mid = (left+right)//2
if a[mid] < x:
left = mid+1
else:
right = mid
return left
def bisect_right(a, x):
"""i tale che a[i] > x e a[i-1] <= x"""
left = 0
right = len(a)
while left < right:
mid = (left+right)//2
if a[mid] > x:
right = mid
else:
left = mid+1
return left
def bisect_elements(a, x):
"""elementi pari a x nell'Γ‘rray sortato"""
return bisect_right(a, x) - bisect_left(a, x)
######################
### MOD OPERATION ####
######################
MOD = 10**9 + 7
maxN = 5
FACT = [0] * maxN
INV_FACT = [0] * maxN
def add(x, y):
return (x+y) % MOD
def multiply(x, y):
return (x*y) % MOD
def power(x, y):
if y == 0:
return 1
elif y % 2:
return multiply(x, power(x, y-1))
else:
a = power(x, y//2)
return multiply(a, a)
def inverse(x):
return power(x, MOD-2)
def divide(x, y):
return multiply(x, inverse(y))
def allFactorials():
FACT[0] = 1
for i in range(1, maxN):
FACT[i] = multiply(i, FACT[i-1])
def inverseFactorials():
n = len(INV_FACT)
INV_FACT[n-1] = inverse(FACT[n-1])
for i in range(n-2, -1, -1):
INV_FACT[i] = multiply(INV_FACT[i+1], i+1)
def coeffBinom(n, k):
if n < k:
return 0
return multiply(FACT[n], multiply(INV_FACT[k], INV_FACT[n-k]))
######################
#### GRAPH ALGOS #####
######################
# ZERO BASED GRAPH
def create_graph(n, m, undirected = 1, unweighted = 1):
graph = [[] for i in range(n)]
if unweighted:
for i in range(m):
[x, y] = li(lag = -1)
graph[x].append(y)
if undirected:
graph[y].append(x)
else:
for i in range(m):
[x, y, w] = li(lag = -1)
w += 1
graph[x].append([y,w])
if undirected:
graph[y].append([x,w])
return graph
def create_tree(n, unweighted = 1):
children = [[] for i in range(n)]
if unweighted:
for i in range(n-1):
[x, y] = li(lag = -1)
children[x].append(y)
children[y].append(x)
else:
for i in range(n-1):
[x, y, w] = li(lag = -1)
w += 1
children[x].append([y, w])
children[y].append([x, w])
return children
def dist(tree, n, A, B = -1):
s = [[A, 0]]
massimo, massimo_nodo = 0, 0
distanza = -1
v = [-1] * n
while s:
el, dis = s.pop()
if dis > massimo:
massimo = dis
massimo_nodo = el
if el == B:
distanza = dis
for child in tree[el]:
if v[child] == -1:
v[child] = 1
s.append([child, dis+1])
return massimo, massimo_nodo, distanza
def diameter(tree):
_, foglia, _ = dist(tree, n, 0)
diam, _, _ = dist(tree, n, foglia)
return diam
def dfs(graph, n, A):
v = [-1] * n
s = [[A, 0]]
v[A] = 0
while s:
el, dis = s.pop()
for child in graph[el]:
if v[child] == -1:
v[child] = dis + 1
s.append([child, dis + 1])
return v #visited: -1 if not visited, otherwise v[B] is the distance in terms of edges
def bfs(graph, n, A):
v = [-1] * n
s = deque()
s.append([A, 0])
v[A] = 0
while s:
el, dis = s.popleft()
for child in graph[el]:
if v[child] == -1:
v[child] = dis + 1
s.append([child, dis + 1])
return v #visited: -1 if not visited, otherwise v[B] is the distance in terms of edges
#FROM A GIVEN ROOT, RECOVER THE STRUCTURE
def parents_children_root_unrooted_tree(tree, n, root = 0):
q = deque()
visited = [0] * n
parent = [-1] * n
children = [[] for i in range(n)]
q.append(root)
while q:
all_done = 1
visited[q[0]] = 1
for child in tree[q[0]]:
if not visited[child]:
all_done = 0
q.appendleft(child)
if all_done:
for child in tree[q[0]]:
if parent[child] == -1:
parent[q[0]] = child
children[child].append(q[0])
q.popleft()
return parent, children
# CALCULATING LONGEST PATH FOR ALL THE NODES
def all_longest_path_passing_from_node(parent, children, n):
q = deque()
visited = [len(children[i]) for i in range(n)]
downwards = [[0,0] for i in range(n)]
upward = [1] * n
longest_path = [1] * n
for i in range(n):
if not visited[i]:
q.append(i)
downwards[i] = [1,0]
while q:
node = q.popleft()
if parent[node] != -1:
visited[parent[node]] -= 1
if not visited[parent[node]]:
q.append(parent[node])
else:
root = node
for child in children[node]:
downwards[node] = sorted([downwards[node][0], downwards[node][1], downwards[child][0] + 1], reverse = True)[0:2]
s = [node]
while s:
node = s.pop()
if parent[node] != -1:
if downwards[parent[node]][0] == downwards[node][0] + 1:
upward[node] = 1 + max(upward[parent[node]], downwards[parent[node]][1])
else:
upward[node] = 1 + max(upward[parent[node]], downwards[parent[node]][0])
longest_path[node] = downwards[node][0] + downwards[node][1] + upward[node] - min([downwards[node][0], downwards[node][1], upward[node]]) - 1
for child in children[node]:
s.append(child)
return longest_path
### TBD SUCCESSOR GRAPH 7.5
### TBD TREE QUERIES 10.2 da 2 a 4
### TBD ADVANCED TREE 10.3
### TBD GRAPHS AND MATRICES 11.3.3 e 11.4.3 e 11.5.3 (ON GAMES)
######################
## END OF LIBRARIES ##
######################
n = ii()
a = li()
seen = set()
start = 0
end = 0
res = list()
while end < n:
if a[end] in seen:
res.append([start+1,end+1])
start = end+1
seen = set()
else:
seen.add(a[end])
end += 1
if len(res) == 0:
print(-1)
else:
if start < n:
x,y = res.pop()
res.append([x,n])
print(len(res))
for i in range(len(res)):
print_list(res[i])
``` | output | 1 | 13,722 | 14 | 27,445 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n pearls in a row. Let's enumerate them with integers from 1 to n from the left to the right. The pearl number i has the type ai.
Let's call a sequence of consecutive pearls a segment. Let's call a segment good if it contains two pearls of the same type.
Split the row of the pearls to the maximal number of good segments. Note that each pearl should appear in exactly one segment of the partition.
As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
Input
The first line contains integer n (1 β€ n β€ 3Β·105) β the number of pearls in a row.
The second line contains n integers ai (1 β€ ai β€ 109) β the type of the i-th pearl.
Output
On the first line print integer k β the maximal number of segments in a partition of the row.
Each of the next k lines should contain two integers lj, rj (1 β€ lj β€ rj β€ n) β the number of the leftmost and the rightmost pearls in the j-th segment.
Note you should print the correct partition of the row of the pearls, so each pearl should be in exactly one segment and all segments should contain two pearls of the same type.
If there are several optimal solutions print any of them. You can print the segments in any order.
If there are no correct partitions of the row print the number "-1".
Examples
Input
5
1 2 3 4 1
Output
1
1 5
Input
5
1 2 3 4 5
Output
-1
Input
7
1 2 1 3 1 2 1
Output
2
1 3
4 7 | instruction | 0 | 13,723 | 14 | 27,446 |
Tags: greedy
Correct Solution:
```
length = int(input())
gems = input().split()
result = []
s = 0
dist = set()
pend_e = 0
pend_s = 0
for i in range(0, length):
cur = gems[i]
if cur not in dist:
dist.add(cur)
else:
if pend_e != 0:
result.append([pend_s, pend_e])
pend_e = i + 1
pend_s = s + 1
s = i + 1
dist.clear()
if s != 0 and pend_e != length + 1:
result.append([pend_s, length])
if len(result) == 0:
print(-1)
else:
print(len(result))
for r in result:
print(r[0], r[1])
``` | output | 1 | 13,723 | 14 | 27,447 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n pearls in a row. Let's enumerate them with integers from 1 to n from the left to the right. The pearl number i has the type ai.
Let's call a sequence of consecutive pearls a segment. Let's call a segment good if it contains two pearls of the same type.
Split the row of the pearls to the maximal number of good segments. Note that each pearl should appear in exactly one segment of the partition.
As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
Input
The first line contains integer n (1 β€ n β€ 3Β·105) β the number of pearls in a row.
The second line contains n integers ai (1 β€ ai β€ 109) β the type of the i-th pearl.
Output
On the first line print integer k β the maximal number of segments in a partition of the row.
Each of the next k lines should contain two integers lj, rj (1 β€ lj β€ rj β€ n) β the number of the leftmost and the rightmost pearls in the j-th segment.
Note you should print the correct partition of the row of the pearls, so each pearl should be in exactly one segment and all segments should contain two pearls of the same type.
If there are several optimal solutions print any of them. You can print the segments in any order.
If there are no correct partitions of the row print the number "-1".
Examples
Input
5
1 2 3 4 1
Output
1
1 5
Input
5
1 2 3 4 5
Output
-1
Input
7
1 2 1 3 1 2 1
Output
2
1 3
4 7 | instruction | 0 | 13,724 | 14 | 27,448 |
Tags: greedy
Correct Solution:
```
n = int(input())
li = list(map(int,input().split()))
s=set()
ans=[]
l=0
r=-1
for i in range(n):
if li[i] in s:
ans.append([l+1,i+1])
s = set()
l = i+1
r=1
else:
s.add(li[i])
if r==-1:
print(-1)
else:
print(len(ans))
ans[len(ans)-1][1]=n
for i in ans:
print(*i)
``` | output | 1 | 13,724 | 14 | 27,449 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n pearls in a row. Let's enumerate them with integers from 1 to n from the left to the right. The pearl number i has the type ai.
Let's call a sequence of consecutive pearls a segment. Let's call a segment good if it contains two pearls of the same type.
Split the row of the pearls to the maximal number of good segments. Note that each pearl should appear in exactly one segment of the partition.
As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
Input
The first line contains integer n (1 β€ n β€ 3Β·105) β the number of pearls in a row.
The second line contains n integers ai (1 β€ ai β€ 109) β the type of the i-th pearl.
Output
On the first line print integer k β the maximal number of segments in a partition of the row.
Each of the next k lines should contain two integers lj, rj (1 β€ lj β€ rj β€ n) β the number of the leftmost and the rightmost pearls in the j-th segment.
Note you should print the correct partition of the row of the pearls, so each pearl should be in exactly one segment and all segments should contain two pearls of the same type.
If there are several optimal solutions print any of them. You can print the segments in any order.
If there are no correct partitions of the row print the number "-1".
Examples
Input
5
1 2 3 4 1
Output
1
1 5
Input
5
1 2 3 4 5
Output
-1
Input
7
1 2 1 3 1 2 1
Output
2
1 3
4 7 | instruction | 0 | 13,725 | 14 | 27,450 |
Tags: greedy
Correct Solution:
```
n = int(input())
lis=[*map(int,input().split())]
ans=[]
k=0;s = set()
for i in range(n):
if lis[i] in s:
ans.append([k+1,i+1])
k=i+1
s = set()
else:
s.add(lis[i])
c=len(ans)
if c==0:
print('-1')
else:
print(c)
ans[-1][1]=n
for i in ans:
print(*i)
``` | output | 1 | 13,725 | 14 | 27,451 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n pearls in a row. Let's enumerate them with integers from 1 to n from the left to the right. The pearl number i has the type ai.
Let's call a sequence of consecutive pearls a segment. Let's call a segment good if it contains two pearls of the same type.
Split the row of the pearls to the maximal number of good segments. Note that each pearl should appear in exactly one segment of the partition.
As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
Input
The first line contains integer n (1 β€ n β€ 3Β·105) β the number of pearls in a row.
The second line contains n integers ai (1 β€ ai β€ 109) β the type of the i-th pearl.
Output
On the first line print integer k β the maximal number of segments in a partition of the row.
Each of the next k lines should contain two integers lj, rj (1 β€ lj β€ rj β€ n) β the number of the leftmost and the rightmost pearls in the j-th segment.
Note you should print the correct partition of the row of the pearls, so each pearl should be in exactly one segment and all segments should contain two pearls of the same type.
If there are several optimal solutions print any of them. You can print the segments in any order.
If there are no correct partitions of the row print the number "-1".
Examples
Input
5
1 2 3 4 1
Output
1
1 5
Input
5
1 2 3 4 5
Output
-1
Input
7
1 2 1 3 1 2 1
Output
2
1 3
4 7 | instruction | 0 | 13,726 | 14 | 27,452 |
Tags: greedy
Correct Solution:
```
n = int(input())
a = list(map(int, input().split()))
z = []; p = set()
k1 = 1
for i in range(n):
if a[i] in p:
z.append((k1, i+1))
k1 = i+2
p = set()
else:
p.add(a[i])
if len(z) > 0:
z[len(z)-1] = (z[len(z)-1][0], n)
print(len(z))
for k in z:
print(k[0], k[1])
else:
print(-1)
``` | output | 1 | 13,726 | 14 | 27,453 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n pearls in a row. Let's enumerate them with integers from 1 to n from the left to the right. The pearl number i has the type ai.
Let's call a sequence of consecutive pearls a segment. Let's call a segment good if it contains two pearls of the same type.
Split the row of the pearls to the maximal number of good segments. Note that each pearl should appear in exactly one segment of the partition.
As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
Input
The first line contains integer n (1 β€ n β€ 3Β·105) β the number of pearls in a row.
The second line contains n integers ai (1 β€ ai β€ 109) β the type of the i-th pearl.
Output
On the first line print integer k β the maximal number of segments in a partition of the row.
Each of the next k lines should contain two integers lj, rj (1 β€ lj β€ rj β€ n) β the number of the leftmost and the rightmost pearls in the j-th segment.
Note you should print the correct partition of the row of the pearls, so each pearl should be in exactly one segment and all segments should contain two pearls of the same type.
If there are several optimal solutions print any of them. You can print the segments in any order.
If there are no correct partitions of the row print the number "-1".
Examples
Input
5
1 2 3 4 1
Output
1
1 5
Input
5
1 2 3 4 5
Output
-1
Input
7
1 2 1 3 1 2 1
Output
2
1 3
4 7 | instruction | 0 | 13,727 | 14 | 27,454 |
Tags: greedy
Correct Solution:
```
def main():
n, res = int(input()), []
s, i, fmt = set(), 1, "{:n} {:n}".format
for j, a in enumerate(input().split(), 1):
if a in s:
s = set()
res.append(fmt(i, j))
i = j + 1
else:
s.add(a)
if res:
print(len(res))
res[-1] = res[-1].split()[0] + ' ' + str(n)
print('\n'.join(res))
else:
print(-1)
if __name__ == '__main__':
main()
``` | output | 1 | 13,727 | 14 | 27,455 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.