text stringlengths 198 433k | conversation_id int64 0 109k |
|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
Consider 2n rows of the seats in a bus. n rows of the seats on the left and n rows of the seats on the right. Each row can be filled by two people. So the total capacity of the bus is 4n.
Consider that m (m ≤ 4n) people occupy the seats in the bus. The passengers entering the bus are numbered from 1 to m (in the order of their entering the bus). The pattern of the seat occupation is as below:
1-st row left window seat, 1-st row right window seat, 2-nd row left window seat, 2-nd row right window seat, ... , n-th row left window seat, n-th row right window seat.
After occupying all the window seats (for m > 2n) the non-window seats are occupied:
1-st row left non-window seat, 1-st row right non-window seat, ... , n-th row left non-window seat, n-th row right non-window seat.
All the passengers go to a single final destination. In the final destination, the passengers get off in the given order.
1-st row left non-window seat, 1-st row left window seat, 1-st row right non-window seat, 1-st row right window seat, ... , n-th row left non-window seat, n-th row left window seat, n-th row right non-window seat, n-th row right window seat.
<image> The seating for n = 9 and m = 36.
You are given the values n and m. Output m numbers from 1 to m, the order in which the passengers will get off the bus.
Input
The only line contains two integers, n and m (1 ≤ n ≤ 100, 1 ≤ m ≤ 4n) — the number of pairs of rows and the number of passengers.
Output
Print m distinct integers from 1 to m — the order in which the passengers will get off the bus.
Examples
Input
2 7
Output
5 1 6 2 7 3 4
Input
9 36
Output
19 1 20 2 21 3 22 4 23 5 24 6 25 7 26 8 27 9 28 10 29 11 30 12 31 13 32 14 33 15 34 16 35 17 36 18
Tags: implementation
Correct Solution:
```
from collections import Counter
n, k = list(map(lambda x: int(x), input().split()))
result = []
window = 1
non_window = 2*n +1
for row in range(1, n+1):
temp = []
temp.append(non_window)
temp.append(window)
temp.append(non_window+1)
temp.append(window+1)
window+=2
non_window+=2
for elem in temp:
if elem > k:
continue
result.append(elem)
result = list(map(lambda x: str(x), result))
print(" ".join(result))
```
| 8,700 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Consider 2n rows of the seats in a bus. n rows of the seats on the left and n rows of the seats on the right. Each row can be filled by two people. So the total capacity of the bus is 4n.
Consider that m (m ≤ 4n) people occupy the seats in the bus. The passengers entering the bus are numbered from 1 to m (in the order of their entering the bus). The pattern of the seat occupation is as below:
1-st row left window seat, 1-st row right window seat, 2-nd row left window seat, 2-nd row right window seat, ... , n-th row left window seat, n-th row right window seat.
After occupying all the window seats (for m > 2n) the non-window seats are occupied:
1-st row left non-window seat, 1-st row right non-window seat, ... , n-th row left non-window seat, n-th row right non-window seat.
All the passengers go to a single final destination. In the final destination, the passengers get off in the given order.
1-st row left non-window seat, 1-st row left window seat, 1-st row right non-window seat, 1-st row right window seat, ... , n-th row left non-window seat, n-th row left window seat, n-th row right non-window seat, n-th row right window seat.
<image> The seating for n = 9 and m = 36.
You are given the values n and m. Output m numbers from 1 to m, the order in which the passengers will get off the bus.
Input
The only line contains two integers, n and m (1 ≤ n ≤ 100, 1 ≤ m ≤ 4n) — the number of pairs of rows and the number of passengers.
Output
Print m distinct integers from 1 to m — the order in which the passengers will get off the bus.
Examples
Input
2 7
Output
5 1 6 2 7 3 4
Input
9 36
Output
19 1 20 2 21 3 22 4 23 5 24 6 25 7 26 8 27 9 28 10 29 11 30 12 31 13 32 14 33 15 34 16 35 17 36 18
Tags: implementation
Correct Solution:
```
n,m=map(int,input().split())
op=[]
if m<=2*n:
for i in range(1,m+1):
print(i,end=' ')
else:
p=m-2*n
l=p%2
p=p//2
for i in range(1,p+1):
op.append(2*n+2*i-1)
op.append(2*i-1)
op.append(2*n+2*i)
op.append(2*i)
if l==1:
op.append(m)
for i in range(2*p+l,2*n+1):
op.append(i)
op2=[]
for i in op:
if i not in op2:
print(i,end=' ')
op2.append(i)
```
| 8,701 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Consider 2n rows of the seats in a bus. n rows of the seats on the left and n rows of the seats on the right. Each row can be filled by two people. So the total capacity of the bus is 4n.
Consider that m (m ≤ 4n) people occupy the seats in the bus. The passengers entering the bus are numbered from 1 to m (in the order of their entering the bus). The pattern of the seat occupation is as below:
1-st row left window seat, 1-st row right window seat, 2-nd row left window seat, 2-nd row right window seat, ... , n-th row left window seat, n-th row right window seat.
After occupying all the window seats (for m > 2n) the non-window seats are occupied:
1-st row left non-window seat, 1-st row right non-window seat, ... , n-th row left non-window seat, n-th row right non-window seat.
All the passengers go to a single final destination. In the final destination, the passengers get off in the given order.
1-st row left non-window seat, 1-st row left window seat, 1-st row right non-window seat, 1-st row right window seat, ... , n-th row left non-window seat, n-th row left window seat, n-th row right non-window seat, n-th row right window seat.
<image> The seating for n = 9 and m = 36.
You are given the values n and m. Output m numbers from 1 to m, the order in which the passengers will get off the bus.
Input
The only line contains two integers, n and m (1 ≤ n ≤ 100, 1 ≤ m ≤ 4n) — the number of pairs of rows and the number of passengers.
Output
Print m distinct integers from 1 to m — the order in which the passengers will get off the bus.
Examples
Input
2 7
Output
5 1 6 2 7 3 4
Input
9 36
Output
19 1 20 2 21 3 22 4 23 5 24 6 25 7 26 8 27 9 28 10 29 11 30 12 31 13 32 14 33 15 34 16 35 17 36 18
Tags: implementation
Correct Solution:
```
n,m=list(map(int,input().split()))
y=[(2*n)-1,-1,2*n,0]
k=2
count=0
t=0
i=-1
while t<m:
i+=1
if (y[i%4]+k)<=m:
print(y[i%4]+k,end=' ')
count+=1
t+=1
else:
count+=1
if count==4:
k+=2
count=0
else:
continue
```
| 8,702 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Consider 2n rows of the seats in a bus. n rows of the seats on the left and n rows of the seats on the right. Each row can be filled by two people. So the total capacity of the bus is 4n.
Consider that m (m ≤ 4n) people occupy the seats in the bus. The passengers entering the bus are numbered from 1 to m (in the order of their entering the bus). The pattern of the seat occupation is as below:
1-st row left window seat, 1-st row right window seat, 2-nd row left window seat, 2-nd row right window seat, ... , n-th row left window seat, n-th row right window seat.
After occupying all the window seats (for m > 2n) the non-window seats are occupied:
1-st row left non-window seat, 1-st row right non-window seat, ... , n-th row left non-window seat, n-th row right non-window seat.
All the passengers go to a single final destination. In the final destination, the passengers get off in the given order.
1-st row left non-window seat, 1-st row left window seat, 1-st row right non-window seat, 1-st row right window seat, ... , n-th row left non-window seat, n-th row left window seat, n-th row right non-window seat, n-th row right window seat.
<image> The seating for n = 9 and m = 36.
You are given the values n and m. Output m numbers from 1 to m, the order in which the passengers will get off the bus.
Input
The only line contains two integers, n and m (1 ≤ n ≤ 100, 1 ≤ m ≤ 4n) — the number of pairs of rows and the number of passengers.
Output
Print m distinct integers from 1 to m — the order in which the passengers will get off the bus.
Examples
Input
2 7
Output
5 1 6 2 7 3 4
Input
9 36
Output
19 1 20 2 21 3 22 4 23 5 24 6 25 7 26 8 27 9 28 10 29 11 30 12 31 13 32 14 33 15 34 16 35 17 36 18
Tags: implementation
Correct Solution:
```
n, m = map(int, input().split())
a, b, c, d = [], [], [], []
for i in range(n):
if 2 * i + 1 <= m:
a.append(2 * i + 1)
#print(a)
for i in range(n, 2 * n):
if 2 * i + 1 <= m:
b.append(2 * i + 1)
#print(b)
for i in range(1, n + 1):
if 2 * i <= m:
d.append(2 * i)
#print(d)
for i in range(n + 1, 2 * n + 1):
if 2 * i <= m:
c.append(2 * i)
#print(c)
# a,b,c,d = left window, left non-window, right non-window, right window
ans = []
for i in range(m):
if len(b):
ans.append(b[0])
b.pop(0)
if len(a):
ans.append(a[0])
a.pop(0)
if len(c):
ans.append(c[0])
c.pop(0)
if len(d):
ans.append(d[0])
d.pop(0)
if len(ans) == m:
break
print(*ans)
```
| 8,703 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Consider 2n rows of the seats in a bus. n rows of the seats on the left and n rows of the seats on the right. Each row can be filled by two people. So the total capacity of the bus is 4n.
Consider that m (m ≤ 4n) people occupy the seats in the bus. The passengers entering the bus are numbered from 1 to m (in the order of their entering the bus). The pattern of the seat occupation is as below:
1-st row left window seat, 1-st row right window seat, 2-nd row left window seat, 2-nd row right window seat, ... , n-th row left window seat, n-th row right window seat.
After occupying all the window seats (for m > 2n) the non-window seats are occupied:
1-st row left non-window seat, 1-st row right non-window seat, ... , n-th row left non-window seat, n-th row right non-window seat.
All the passengers go to a single final destination. In the final destination, the passengers get off in the given order.
1-st row left non-window seat, 1-st row left window seat, 1-st row right non-window seat, 1-st row right window seat, ... , n-th row left non-window seat, n-th row left window seat, n-th row right non-window seat, n-th row right window seat.
<image> The seating for n = 9 and m = 36.
You are given the values n and m. Output m numbers from 1 to m, the order in which the passengers will get off the bus.
Input
The only line contains two integers, n and m (1 ≤ n ≤ 100, 1 ≤ m ≤ 4n) — the number of pairs of rows and the number of passengers.
Output
Print m distinct integers from 1 to m — the order in which the passengers will get off the bus.
Examples
Input
2 7
Output
5 1 6 2 7 3 4
Input
9 36
Output
19 1 20 2 21 3 22 4 23 5 24 6 25 7 26 8 27 9 28 10 29 11 30 12 31 13 32 14 33 15 34 16 35 17 36 18
Tags: implementation
Correct Solution:
```
n,m = map(int,input().split())
s = [[i for i in range(j+1,4*n+1,2)] for j in range(2)]
r = [s[0][0:n],s[0][n::]]
l = [s[1][n::],s[1][0:n]]
a = []
for i in range(n):
if r[1][i]<=m:
a.append(r[1][i])
if r[0][i]<=m:
a.append(r[0][i])
if l[0][i]<=m:
a.append(l[0][i])
if l[1][i]<=m:
a.append(l[1][i])
print(*a)
```
| 8,704 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Consider 2n rows of the seats in a bus. n rows of the seats on the left and n rows of the seats on the right. Each row can be filled by two people. So the total capacity of the bus is 4n.
Consider that m (m ≤ 4n) people occupy the seats in the bus. The passengers entering the bus are numbered from 1 to m (in the order of their entering the bus). The pattern of the seat occupation is as below:
1-st row left window seat, 1-st row right window seat, 2-nd row left window seat, 2-nd row right window seat, ... , n-th row left window seat, n-th row right window seat.
After occupying all the window seats (for m > 2n) the non-window seats are occupied:
1-st row left non-window seat, 1-st row right non-window seat, ... , n-th row left non-window seat, n-th row right non-window seat.
All the passengers go to a single final destination. In the final destination, the passengers get off in the given order.
1-st row left non-window seat, 1-st row left window seat, 1-st row right non-window seat, 1-st row right window seat, ... , n-th row left non-window seat, n-th row left window seat, n-th row right non-window seat, n-th row right window seat.
<image> The seating for n = 9 and m = 36.
You are given the values n and m. Output m numbers from 1 to m, the order in which the passengers will get off the bus.
Input
The only line contains two integers, n and m (1 ≤ n ≤ 100, 1 ≤ m ≤ 4n) — the number of pairs of rows and the number of passengers.
Output
Print m distinct integers from 1 to m — the order in which the passengers will get off the bus.
Examples
Input
2 7
Output
5 1 6 2 7 3 4
Input
9 36
Output
19 1 20 2 21 3 22 4 23 5 24 6 25 7 26 8 27 9 28 10 29 11 30 12 31 13 32 14 33 15 34 16 35 17 36 18
Submitted Solution:
```
from sys import stdin, stdout
def row(i, n):
return [i*2-1, 2*n+2*i-1, 2*n+2*i, i*2]
n, m = map(int, stdin.readline().strip().split())
ans = ""
i = 1
while i <= n and i*2-1 <= m:
r = row(i, n)
for x in [1, 0, 2, 3]:
if r[x] <= m:
ans += str(r[x]) + " "
i += 1
ans = ans.strip()
stdout.write(ans + "\n")
```
Yes
| 8,705 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Consider 2n rows of the seats in a bus. n rows of the seats on the left and n rows of the seats on the right. Each row can be filled by two people. So the total capacity of the bus is 4n.
Consider that m (m ≤ 4n) people occupy the seats in the bus. The passengers entering the bus are numbered from 1 to m (in the order of their entering the bus). The pattern of the seat occupation is as below:
1-st row left window seat, 1-st row right window seat, 2-nd row left window seat, 2-nd row right window seat, ... , n-th row left window seat, n-th row right window seat.
After occupying all the window seats (for m > 2n) the non-window seats are occupied:
1-st row left non-window seat, 1-st row right non-window seat, ... , n-th row left non-window seat, n-th row right non-window seat.
All the passengers go to a single final destination. In the final destination, the passengers get off in the given order.
1-st row left non-window seat, 1-st row left window seat, 1-st row right non-window seat, 1-st row right window seat, ... , n-th row left non-window seat, n-th row left window seat, n-th row right non-window seat, n-th row right window seat.
<image> The seating for n = 9 and m = 36.
You are given the values n and m. Output m numbers from 1 to m, the order in which the passengers will get off the bus.
Input
The only line contains two integers, n and m (1 ≤ n ≤ 100, 1 ≤ m ≤ 4n) — the number of pairs of rows and the number of passengers.
Output
Print m distinct integers from 1 to m — the order in which the passengers will get off the bus.
Examples
Input
2 7
Output
5 1 6 2 7 3 4
Input
9 36
Output
19 1 20 2 21 3 22 4 23 5 24 6 25 7 26 8 27 9 28 10 29 11 30 12 31 13 32 14 33 15 34 16 35 17 36 18
Submitted Solution:
```
def get_ints():
return list(map(int, input().split()))
N,M = get_ints()
for i in range(1,min(2*N, M)+1):
if 2*N+i<=M:
print(2*N+i, end=" ")
print(i,end=" ")
```
Yes
| 8,706 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Consider 2n rows of the seats in a bus. n rows of the seats on the left and n rows of the seats on the right. Each row can be filled by two people. So the total capacity of the bus is 4n.
Consider that m (m ≤ 4n) people occupy the seats in the bus. The passengers entering the bus are numbered from 1 to m (in the order of their entering the bus). The pattern of the seat occupation is as below:
1-st row left window seat, 1-st row right window seat, 2-nd row left window seat, 2-nd row right window seat, ... , n-th row left window seat, n-th row right window seat.
After occupying all the window seats (for m > 2n) the non-window seats are occupied:
1-st row left non-window seat, 1-st row right non-window seat, ... , n-th row left non-window seat, n-th row right non-window seat.
All the passengers go to a single final destination. In the final destination, the passengers get off in the given order.
1-st row left non-window seat, 1-st row left window seat, 1-st row right non-window seat, 1-st row right window seat, ... , n-th row left non-window seat, n-th row left window seat, n-th row right non-window seat, n-th row right window seat.
<image> The seating for n = 9 and m = 36.
You are given the values n and m. Output m numbers from 1 to m, the order in which the passengers will get off the bus.
Input
The only line contains two integers, n and m (1 ≤ n ≤ 100, 1 ≤ m ≤ 4n) — the number of pairs of rows and the number of passengers.
Output
Print m distinct integers from 1 to m — the order in which the passengers will get off the bus.
Examples
Input
2 7
Output
5 1 6 2 7 3 4
Input
9 36
Output
19 1 20 2 21 3 22 4 23 5 24 6 25 7 26 8 27 9 28 10 29 11 30 12 31 13 32 14 33 15 34 16 35 17 36 18
Submitted Solution:
```
n,m=map(int,input().split())
c2=2*n+1
c1=1
for i in range(n*2):
if(c2<=m):
print(c2,end=' ')
c2+=1
if(c1<=m):
print(c1,end=' ')
c1+=1
print('')
```
Yes
| 8,707 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Consider 2n rows of the seats in a bus. n rows of the seats on the left and n rows of the seats on the right. Each row can be filled by two people. So the total capacity of the bus is 4n.
Consider that m (m ≤ 4n) people occupy the seats in the bus. The passengers entering the bus are numbered from 1 to m (in the order of their entering the bus). The pattern of the seat occupation is as below:
1-st row left window seat, 1-st row right window seat, 2-nd row left window seat, 2-nd row right window seat, ... , n-th row left window seat, n-th row right window seat.
After occupying all the window seats (for m > 2n) the non-window seats are occupied:
1-st row left non-window seat, 1-st row right non-window seat, ... , n-th row left non-window seat, n-th row right non-window seat.
All the passengers go to a single final destination. In the final destination, the passengers get off in the given order.
1-st row left non-window seat, 1-st row left window seat, 1-st row right non-window seat, 1-st row right window seat, ... , n-th row left non-window seat, n-th row left window seat, n-th row right non-window seat, n-th row right window seat.
<image> The seating for n = 9 and m = 36.
You are given the values n and m. Output m numbers from 1 to m, the order in which the passengers will get off the bus.
Input
The only line contains two integers, n and m (1 ≤ n ≤ 100, 1 ≤ m ≤ 4n) — the number of pairs of rows and the number of passengers.
Output
Print m distinct integers from 1 to m — the order in which the passengers will get off the bus.
Examples
Input
2 7
Output
5 1 6 2 7 3 4
Input
9 36
Output
19 1 20 2 21 3 22 4 23 5 24 6 25 7 26 8 27 9 28 10 29 11 30 12 31 13 32 14 33 15 34 16 35 17 36 18
Submitted Solution:
```
args = input().split()
n = int(args[0])
m = int(args[1])
bus = [[0 for x in range(4)] for x in range(n)]
for i in range(1, m+1):
if i <= 2*n and i % 2 == 0:
bus[i//2 - 1][3] = i
elif i <= 2*n and i % 2 == 1:
bus[(i - 1)//2][0] = i
elif i > 2*n and i % 2 == 0:
bus[(i - 2*n)//2 - 1][2] = i
elif i > 2*n and i % 2 == 1:
bus[((i - 2*n) - 1)//2][1] = i
ans = []
for i in range(n):
for j in [1, 0, 2, 3]:
if bus[i][j] != 0:
ans.append(bus[i][j])
ans = list(map(str, ans))
print(" ".join(ans))
```
Yes
| 8,708 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Consider 2n rows of the seats in a bus. n rows of the seats on the left and n rows of the seats on the right. Each row can be filled by two people. So the total capacity of the bus is 4n.
Consider that m (m ≤ 4n) people occupy the seats in the bus. The passengers entering the bus are numbered from 1 to m (in the order of their entering the bus). The pattern of the seat occupation is as below:
1-st row left window seat, 1-st row right window seat, 2-nd row left window seat, 2-nd row right window seat, ... , n-th row left window seat, n-th row right window seat.
After occupying all the window seats (for m > 2n) the non-window seats are occupied:
1-st row left non-window seat, 1-st row right non-window seat, ... , n-th row left non-window seat, n-th row right non-window seat.
All the passengers go to a single final destination. In the final destination, the passengers get off in the given order.
1-st row left non-window seat, 1-st row left window seat, 1-st row right non-window seat, 1-st row right window seat, ... , n-th row left non-window seat, n-th row left window seat, n-th row right non-window seat, n-th row right window seat.
<image> The seating for n = 9 and m = 36.
You are given the values n and m. Output m numbers from 1 to m, the order in which the passengers will get off the bus.
Input
The only line contains two integers, n and m (1 ≤ n ≤ 100, 1 ≤ m ≤ 4n) — the number of pairs of rows and the number of passengers.
Output
Print m distinct integers from 1 to m — the order in which the passengers will get off the bus.
Examples
Input
2 7
Output
5 1 6 2 7 3 4
Input
9 36
Output
19 1 20 2 21 3 22 4 23 5 24 6 25 7 26 8 27 9 28 10 29 11 30 12 31 13 32 14 33 15 34 16 35 17 36 18
Submitted Solution:
```
n,m=map(int,input().split())
count=0
i=1
while(count!=m):
if m<4*n:
if count!=m and 2*n+1+2*(i-1)!=m+1:
count=count+1
print(2*n+1+2*(i-1),end=' ')
if count!=m and 2*i-1!=m+1:
count=count+1
print(2*i-1,end=' ')
if count!=m and 2*n+2+2*(i-1)!=m+1:
count=count+1
print(2*n+2+2*(i-1),end=' ')
if count!=m and 2*i!=m+1:
count=count+1
print(2*i,end=' ')
i=i+1
else:
if count!=m:
count=count+1
print(2*n+1+2*(i-1),end=' ')
if count!=m:
count=count+1
print(2*i-1,end=' ')
if count!=m:
count=count+1
print(2*n+2+2*(i-1),end=' ')
if count!=m:
count=count+1
print(2*i,end=' ')
i=i+1
```
No
| 8,709 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Consider 2n rows of the seats in a bus. n rows of the seats on the left and n rows of the seats on the right. Each row can be filled by two people. So the total capacity of the bus is 4n.
Consider that m (m ≤ 4n) people occupy the seats in the bus. The passengers entering the bus are numbered from 1 to m (in the order of their entering the bus). The pattern of the seat occupation is as below:
1-st row left window seat, 1-st row right window seat, 2-nd row left window seat, 2-nd row right window seat, ... , n-th row left window seat, n-th row right window seat.
After occupying all the window seats (for m > 2n) the non-window seats are occupied:
1-st row left non-window seat, 1-st row right non-window seat, ... , n-th row left non-window seat, n-th row right non-window seat.
All the passengers go to a single final destination. In the final destination, the passengers get off in the given order.
1-st row left non-window seat, 1-st row left window seat, 1-st row right non-window seat, 1-st row right window seat, ... , n-th row left non-window seat, n-th row left window seat, n-th row right non-window seat, n-th row right window seat.
<image> The seating for n = 9 and m = 36.
You are given the values n and m. Output m numbers from 1 to m, the order in which the passengers will get off the bus.
Input
The only line contains two integers, n and m (1 ≤ n ≤ 100, 1 ≤ m ≤ 4n) — the number of pairs of rows and the number of passengers.
Output
Print m distinct integers from 1 to m — the order in which the passengers will get off the bus.
Examples
Input
2 7
Output
5 1 6 2 7 3 4
Input
9 36
Output
19 1 20 2 21 3 22 4 23 5 24 6 25 7 26 8 27 9 28 10 29 11 30 12 31 13 32 14 33 15 34 16 35 17 36 18
Submitted Solution:
```
s = input().split(" ")
n = int(s[0])
m = int(s[1])
if n >= 1 and n <= 100 and m >= 1 and m <= 4 * n:
enter = []
if m % n == 0:
k = int(round(m / 2))
while m > 0 and k > 0:
enter.append(k)
enter.append(m)
m -= 1
k -= 1
print(str(list(reversed(enter))).replace(",","").replace("[","").replace("]",""))
else:
k = m - n
n = 1
while k <= m:
enter.append(k)
enter.append(n)
n += 1
k += 1
enter.append(n)
print(str(enter).replace(",","").replace("[","").replace("]",""))
```
No
| 8,710 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Consider 2n rows of the seats in a bus. n rows of the seats on the left and n rows of the seats on the right. Each row can be filled by two people. So the total capacity of the bus is 4n.
Consider that m (m ≤ 4n) people occupy the seats in the bus. The passengers entering the bus are numbered from 1 to m (in the order of their entering the bus). The pattern of the seat occupation is as below:
1-st row left window seat, 1-st row right window seat, 2-nd row left window seat, 2-nd row right window seat, ... , n-th row left window seat, n-th row right window seat.
After occupying all the window seats (for m > 2n) the non-window seats are occupied:
1-st row left non-window seat, 1-st row right non-window seat, ... , n-th row left non-window seat, n-th row right non-window seat.
All the passengers go to a single final destination. In the final destination, the passengers get off in the given order.
1-st row left non-window seat, 1-st row left window seat, 1-st row right non-window seat, 1-st row right window seat, ... , n-th row left non-window seat, n-th row left window seat, n-th row right non-window seat, n-th row right window seat.
<image> The seating for n = 9 and m = 36.
You are given the values n and m. Output m numbers from 1 to m, the order in which the passengers will get off the bus.
Input
The only line contains two integers, n and m (1 ≤ n ≤ 100, 1 ≤ m ≤ 4n) — the number of pairs of rows and the number of passengers.
Output
Print m distinct integers from 1 to m — the order in which the passengers will get off the bus.
Examples
Input
2 7
Output
5 1 6 2 7 3 4
Input
9 36
Output
19 1 20 2 21 3 22 4 23 5 24 6 25 7 26 8 27 9 28 10 29 11 30 12 31 13 32 14 33 15 34 16 35 17 36 18
Submitted Solution:
```
n, m = map(int, input().split())
if m == 1:
print(1)
elif m <= 2*n:
for i in range(1, n+1):
print(i, end = ' ')
else:
o = m - 2*n #locuri ocupate ce nu sunt la geam
inc = 1
while o:
print(2*n+inc, inc, end = ' ' , sep =' ')
inc= inc+1
o=o-1
for i in range(inc, 2*n+1):
print(i, end = ' ')
```
No
| 8,711 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Consider 2n rows of the seats in a bus. n rows of the seats on the left and n rows of the seats on the right. Each row can be filled by two people. So the total capacity of the bus is 4n.
Consider that m (m ≤ 4n) people occupy the seats in the bus. The passengers entering the bus are numbered from 1 to m (in the order of their entering the bus). The pattern of the seat occupation is as below:
1-st row left window seat, 1-st row right window seat, 2-nd row left window seat, 2-nd row right window seat, ... , n-th row left window seat, n-th row right window seat.
After occupying all the window seats (for m > 2n) the non-window seats are occupied:
1-st row left non-window seat, 1-st row right non-window seat, ... , n-th row left non-window seat, n-th row right non-window seat.
All the passengers go to a single final destination. In the final destination, the passengers get off in the given order.
1-st row left non-window seat, 1-st row left window seat, 1-st row right non-window seat, 1-st row right window seat, ... , n-th row left non-window seat, n-th row left window seat, n-th row right non-window seat, n-th row right window seat.
<image> The seating for n = 9 and m = 36.
You are given the values n and m. Output m numbers from 1 to m, the order in which the passengers will get off the bus.
Input
The only line contains two integers, n and m (1 ≤ n ≤ 100, 1 ≤ m ≤ 4n) — the number of pairs of rows and the number of passengers.
Output
Print m distinct integers from 1 to m — the order in which the passengers will get off the bus.
Examples
Input
2 7
Output
5 1 6 2 7 3 4
Input
9 36
Output
19 1 20 2 21 3 22 4 23 5 24 6 25 7 26 8 27 9 28 10 29 11 30 12 31 13 32 14 33 15 34 16 35 17 36 18
Submitted Solution:
```
def main():
(n, m) = (int(x) for x in input().split())
seatings = solver(n, m)
for x in seatings:
if x != None:
print(x, end = " ")
def solver(n, m):
seatings = [None] * (4 * n + 1)
i = 1
while i < m and i <= 2 * n:
seatings[2 * i] = i
i += 1
print(seatings)
while i <= m:
seatings[2 * i - 4 * n - 1] = i
i += 1
return seatings
main()
#print(solver(9, 36))
```
No
| 8,712 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasiliy finally got to work, where there is a huge amount of tasks waiting for him. Vasiliy is given a matrix consisting of n rows and m columns and q tasks. Each task is to swap two submatrices of the given matrix.
For each task Vasiliy knows six integers ai, bi, ci, di, hi, wi, where ai is the index of the row where the top-left corner of the first rectangle is located, bi is the index of its column, ci is the index of the row of the top-left corner of the second rectangle, di is the index of its column, hi is the height of the rectangle and wi is its width.
It's guaranteed that two rectangles in one query do not overlap and do not touch, that is, no cell belongs to both rectangles, and no two cells belonging to different rectangles share a side. However, rectangles are allowed to share an angle.
Vasiliy wants to know how the matrix will look like after all tasks are performed.
Input
The first line of the input contains three integers n, m and q (2 ≤ n, m ≤ 1000, 1 ≤ q ≤ 10 000) — the number of rows and columns in matrix, and the number of tasks Vasiliy has to perform.
Then follow n lines containing m integers vi, j (1 ≤ vi, j ≤ 109) each — initial values of the cells of the matrix.
Each of the following q lines contains six integers ai, bi, ci, di, hi, wi (1 ≤ ai, ci, hi ≤ n, 1 ≤ bi, di, wi ≤ m).
Output
Print n lines containing m integers each — the resulting matrix.
Examples
Input
4 4 2
1 1 2 2
1 1 2 2
3 3 4 4
3 3 4 4
1 1 3 3 2 2
3 1 1 3 2 2
Output
4 4 3 3
4 4 3 3
2 2 1 1
2 2 1 1
Input
4 2 1
1 1
1 1
2 2
2 2
1 1 4 1 1 2
Output
2 2
1 1
2 2
1 1
Submitted Solution:
```
import sys
import timeit
MATRIX = []
def a2i(a):
i = []
for ii in a:
i.append(int(ii))
return i
def main():
global MATRIX
works = []
n = 0
m = 0
q = 0
nL = 0
dtimer = timeit.default_timer;
st = dtimer()
firstLine = True
matrixBody = False
for line in sys.stdin:
line = line.strip()
a = line.split(' ')
if firstLine:
n = int(a[0])
nL = n
m = int(a[1])
q = int(a[2])
firstLine = False
matrixBody = True
if (n < 2 or n > 1000) or (m < 2 or m > 1000) or (q < 1 or q > 10000):
exit()
elif matrixBody:
MATRIX.append(a)
nL -= 1
if nL == 0:
matrixBody = False
else:
works.append(a2i(a))
print('loading time ' + str(dtimer() - st))
st = dtimer()
counter = 0
while counter < q:
makeWork(works[counter][0], works[counter][1], works[counter][2], works[counter][3], works[counter][4], works[counter][5])
counter += 1
print('working time ' + str(dtimer() - st))
st = dtimer()
printMatrix(MATRIX)
print('out time ' + str(dtimer() - st))
def makeWork(a1, b1, a2, b2, h, w):
j = -1
while j < h-1:
i = -1
while i < w-1:
tmp = MATRIX[a2+j][b2+i]
MATRIX[a2+j][b2+i] = MATRIX[a1+j][b1+i]
MATRIX[a1+j][b1+i] = tmp
i += 1
j += 1
def printMatrix(source):
s = ''
for a in source:
for b in a:
s += b + ' '
s += '\n'
print(s, end='')
if __name__ == '__main__':
main()
```
No
| 8,713 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasiliy finally got to work, where there is a huge amount of tasks waiting for him. Vasiliy is given a matrix consisting of n rows and m columns and q tasks. Each task is to swap two submatrices of the given matrix.
For each task Vasiliy knows six integers ai, bi, ci, di, hi, wi, where ai is the index of the row where the top-left corner of the first rectangle is located, bi is the index of its column, ci is the index of the row of the top-left corner of the second rectangle, di is the index of its column, hi is the height of the rectangle and wi is its width.
It's guaranteed that two rectangles in one query do not overlap and do not touch, that is, no cell belongs to both rectangles, and no two cells belonging to different rectangles share a side. However, rectangles are allowed to share an angle.
Vasiliy wants to know how the matrix will look like after all tasks are performed.
Input
The first line of the input contains three integers n, m and q (2 ≤ n, m ≤ 1000, 1 ≤ q ≤ 10 000) — the number of rows and columns in matrix, and the number of tasks Vasiliy has to perform.
Then follow n lines containing m integers vi, j (1 ≤ vi, j ≤ 109) each — initial values of the cells of the matrix.
Each of the following q lines contains six integers ai, bi, ci, di, hi, wi (1 ≤ ai, ci, hi ≤ n, 1 ≤ bi, di, wi ≤ m).
Output
Print n lines containing m integers each — the resulting matrix.
Examples
Input
4 4 2
1 1 2 2
1 1 2 2
3 3 4 4
3 3 4 4
1 1 3 3 2 2
3 1 1 3 2 2
Output
4 4 3 3
4 4 3 3
2 2 1 1
2 2 1 1
Input
4 2 1
1 1
1 1
2 2
2 2
1 1 4 1 1 2
Output
2 2
1 1
2 2
1 1
Submitted Solution:
```
def get_index(i,j):
global m
return i*(m+1)+j
if __name__=='__main__':
n,m,q = [int(i) for i in input().split()]
a = [[0,-1,-1] for i in range(m+1)]
for i in range(1,n+1):
a.append([0,-1,-1])
a.extend([[int(j),-1,-1] for j in input().split()]) #a[index][0]为值 a[index][1]为右邻的index a[index][2]为下邻的index
# print(a)
for i in range(n+1):
for j in range(m):
index = get_index(i,j)
a[index][1] = get_index(i,j+1)
for i in range(n):
for j in range(m+1):
index = get_index(i,j)
a[index][2] = get_index(i+1,j)
# print(a)
for k in range(q):
x1,y1,x2,y2,h,w = [int(j) for j in input().split()]
index1,index2 = get_index(x1,0),get_index(x2,0)
for i in range(y1-1):
index1 = a[index1][1]
for i in range(y2-1):
index2 = a[index2][1]
for i in range(h):
a[index1][1],a[index2][1] = a[index2][1],a[index1][1]
index1 = a[index1][2]
index2 = a[index2][2]
index1,index2 = get_index(x1,0),get_index(x2,0)
for i in range(y1-1+w):
index1 = a[index1][1]
for i in range(y2-1+w):
index2 = a[index2][1]
for i in range(h):
a[index1][1],a[index2][1] = a[index2][1],a[index1][1]
index1 = a[index1][2]
index2 = a[index2][2]
index1, index2 = get_index(0,y1), get_index(0,y2)
for i in range(x1-1):
index1 = a[index1][2]
for i in range(x1-1):
index2 = a[index2][2]
for i in range(w):
a[index1][2],a[index2][2] = a[index2][2],a[index1][2]
index1 = a[index1][1]
index2 = a[index2][1]
index1, index2 = get_index(0,y1), get_index(0,y2)
for i in range(x1-1+h):
index1 = a[index1][2]
for i in range(x1-1+h):
index2 = a[index2][2]
for i in range(w):
a[index1][2],a[index2][2] = a[index2][2],a[index1][2]
index1 = a[index1][1]
index2 = a[index2][1]
for i in range(1, n + 1):
index = get_index(i, 0)
for j in range(m):
index = a[index][1]
print(a[index][0], end=' ')
print()
# print(a)
```
No
| 8,714 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasiliy finally got to work, where there is a huge amount of tasks waiting for him. Vasiliy is given a matrix consisting of n rows and m columns and q tasks. Each task is to swap two submatrices of the given matrix.
For each task Vasiliy knows six integers ai, bi, ci, di, hi, wi, where ai is the index of the row where the top-left corner of the first rectangle is located, bi is the index of its column, ci is the index of the row of the top-left corner of the second rectangle, di is the index of its column, hi is the height of the rectangle and wi is its width.
It's guaranteed that two rectangles in one query do not overlap and do not touch, that is, no cell belongs to both rectangles, and no two cells belonging to different rectangles share a side. However, rectangles are allowed to share an angle.
Vasiliy wants to know how the matrix will look like after all tasks are performed.
Input
The first line of the input contains three integers n, m and q (2 ≤ n, m ≤ 1000, 1 ≤ q ≤ 10 000) — the number of rows and columns in matrix, and the number of tasks Vasiliy has to perform.
Then follow n lines containing m integers vi, j (1 ≤ vi, j ≤ 109) each — initial values of the cells of the matrix.
Each of the following q lines contains six integers ai, bi, ci, di, hi, wi (1 ≤ ai, ci, hi ≤ n, 1 ≤ bi, di, wi ≤ m).
Output
Print n lines containing m integers each — the resulting matrix.
Examples
Input
4 4 2
1 1 2 2
1 1 2 2
3 3 4 4
3 3 4 4
1 1 3 3 2 2
3 1 1 3 2 2
Output
4 4 3 3
4 4 3 3
2 2 1 1
2 2 1 1
Input
4 2 1
1 1
1 1
2 2
2 2
1 1 4 1 1 2
Output
2 2
1 1
2 2
1 1
Submitted Solution:
```
def get_index(i,j):
global m
return i*(m+1)+j
if __name__=='__main__':
n,m,q = [int(i) for i in input().split()]
a = [[0,-1,-1] for i in range(m+1)]
for i in range(1,n+1):
a.append([0,-1,-1])
a.extend([[int(j),-1,-1] for j in input().split()]) #a[index][0]为值 a[index][1]为右邻的index a[index][2]为下邻的index
# print(a)
for i in range(n+1):
for j in range(m):
index = get_index(i,j)
a[index][1] = get_index(i,j+1)
for i in range(n):
for j in range(m+1):
index = get_index(i,j)
a[index][2] = get_index(i+1,j)
# print(a)
for k in range(q):
print(k)
x1,y1,x2,y2,h,w = [int(j) for j in input().split()]
index1,index2 = get_index(x1,0),get_index(x2,0)
for i in range(y1-1):
index1 = a[index1][1]
for i in range(y2-1):
index2 = a[index2][1]
for i in range(h):
a[index1][1],a[index2][1] = a[index2][1],a[index1][1]
index1 = a[index1][2]
index2 = a[index2][2]
# for i in range(1, n + 1):
# index = get_index(i, 0)
# for j in range(m):
# index = a[index][1]
# print(a[index][0], end=' ')
# print()
index1,index2 = get_index(x1,0),get_index(x2,0)
for i in range(y1-1+w):
index1 = a[index1][1]
for i in range(y2-1+w):
index2 = a[index2][1]
for i in range(h):
a[index1][1],a[index2][1] = a[index2][1],a[index1][1]
index1 = a[index1][2]
index2 = a[index2][2]
# for i in range(1, n + 1):
# index = get_index(i, 0)
# for j in range(m):
# index = a[index][1]
# print(a[index][0], end=' ')
# print()
index1, index2 = get_index(0,y1), get_index(0,y2)
for i in range(x1-1):
index1 = a[index1][2]
for i in range(x2-1):
index2 = a[index2][2]
for i in range(w):
a[index1][2],a[index2][2] = a[index2][2],a[index1][2]
index1 = a[index1][1]
index2 = a[index2][1]
# for i in range(1, n + 1):
# index = get_index(i, 0)
# for j in range(m):
# index = a[index][1]
# print(a[index][0], end=' ')
# print()
index1, index2 = get_index(0,y1), get_index(0,y2)
for i in range(x1-1+h):
index1 = a[index1][2]
for i in range(x2-1+h):
index2 = a[index2][2]
for i in range(w):
a[index1][2],a[index2][2] = a[index2][2],a[index1][2]
index1 = a[index1][1]
index2 = a[index2][1]
for i in range(1, n + 1):
index = get_index(i, 0)
for j in range(m):
index = a[index][1]
print(a[index][0], end=' ')
print()
# print(a)
```
No
| 8,715 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasiliy finally got to work, where there is a huge amount of tasks waiting for him. Vasiliy is given a matrix consisting of n rows and m columns and q tasks. Each task is to swap two submatrices of the given matrix.
For each task Vasiliy knows six integers ai, bi, ci, di, hi, wi, where ai is the index of the row where the top-left corner of the first rectangle is located, bi is the index of its column, ci is the index of the row of the top-left corner of the second rectangle, di is the index of its column, hi is the height of the rectangle and wi is its width.
It's guaranteed that two rectangles in one query do not overlap and do not touch, that is, no cell belongs to both rectangles, and no two cells belonging to different rectangles share a side. However, rectangles are allowed to share an angle.
Vasiliy wants to know how the matrix will look like after all tasks are performed.
Input
The first line of the input contains three integers n, m and q (2 ≤ n, m ≤ 1000, 1 ≤ q ≤ 10 000) — the number of rows and columns in matrix, and the number of tasks Vasiliy has to perform.
Then follow n lines containing m integers vi, j (1 ≤ vi, j ≤ 109) each — initial values of the cells of the matrix.
Each of the following q lines contains six integers ai, bi, ci, di, hi, wi (1 ≤ ai, ci, hi ≤ n, 1 ≤ bi, di, wi ≤ m).
Output
Print n lines containing m integers each — the resulting matrix.
Examples
Input
4 4 2
1 1 2 2
1 1 2 2
3 3 4 4
3 3 4 4
1 1 3 3 2 2
3 1 1 3 2 2
Output
4 4 3 3
4 4 3 3
2 2 1 1
2 2 1 1
Input
4 2 1
1 1
1 1
2 2
2 2
1 1 4 1 1 2
Output
2 2
1 1
2 2
1 1
Submitted Solution:
```
def get_index(i,j):
global m
return i*(m+1)+j
if __name__=='__main__':
n,m,q = [int(i) for i in input().split()]
a = [[0,-1,-1] for i in range(m+1)]
for i in range(1,n+1):
a.append([0,-1,-1])
a.extend([[int(j),-1,-1] for j in input().split()]) #a[index][0]为值 a[index][1]为右邻的index a[index][2]为下邻的index
# print(a)
for i in range(n+1):
for j in range(m):
index = get_index(i,j)
a[index][1] = get_index(i,j+1)
for i in range(n):
for j in range(m+1):
index = get_index(i,j)
a[index][2] = get_index(i+1,j)
# print(a)
for k in range(q):
x1,y1,x2,y2,h,w = [int(j) for j in input().split()]
index1,index2 = get_index(x1,0),get_index(x2,0)
for i in range(y1-1):
index1 = a[index1][1]
for i in range(y2-1):
index2 = a[index2][1]
for i in range(h):
a[index1][1],a[index2][1] = a[index2][1],a[index1][1]
index1 = a[index1][2]
index2 = a[index2][2]
index1,index2 = get_index(x1,0),get_index(x2,0)
for i in range(y1-1+w):
index1 = a[index1][1]
for i in range(y2-1+w):
index2 = a[index2][1]
for i in range(h):
a[index1][1],a[index2][1] = a[index2][1],a[index1][1]
index1 = a[index1][2]
index2 = a[index2][2]
index1, index2 = get_index(0,y1), get_index(0,y2)
for i in range(x1-1):
index1 = a[index1][2]
for i in range(x2-1):
index2 = a[index2][2]
for i in range(w):
a[index1][2],a[index2][2] = a[index2][2],a[index1][2]
index1 = a[index1][1]
index2 = a[index2][1]
index1, index2 = get_index(0,y1), get_index(0,y2)
for i in range(x1-1+h):
index1 = a[index1][2]
for i in range(x2-1+h):
index2 = a[index2][2]
for i in range(w):
a[index1][2],a[index2][2] = a[index2][2],a[index1][2]
index1 = a[index1][1]
index2 = a[index2][1]
for i in range(1, n + 1):
index = get_index(i, 0)
for j in range(m):
index = a[index][1]
print(a[index][0], end=' ')
print()
# print(a)
```
No
| 8,716 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's imagine: there is a chess piece billiard ball. Its movements resemble the ones of a bishop chess piece. The only difference is that when a billiard ball hits the board's border, it can reflect from it and continue moving.
More formally, first one of four diagonal directions is chosen and the billiard ball moves in that direction. When it reaches the square located on the board's edge, the billiard ball reflects from it; it changes the direction of its movement by 90 degrees and continues moving. Specifically, having reached a corner square, the billiard ball is reflected twice and starts to move the opposite way. While it moves, the billiard ball can make an infinite number of reflections. At any square of its trajectory the billiard ball can stop and on that the move is considered completed.
<image>
It is considered that one billiard ball a beats another billiard ball b if a can reach a point where b is located.
You are suggested to find the maximal number of billiard balls, that pairwise do not beat each other and that can be positioned on a chessboard n × m in size.
Input
The first line contains two integers n and m (2 ≤ n, m ≤ 106).
Output
Print a single number, the maximum possible number of billiard balls that do not pairwise beat each other.
Please do not use the %lld specificator to read or write 64-bit numbers in C++. It is preferred to use cin (also you may use the %I64d specificator).
Examples
Input
3 4
Output
2
Input
3 3
Output
3
Tags: dfs and similar, dsu, graphs, number theory
Correct Solution:
```
import math
x, y = map(int, input().split())
x -= 1; y -= 1
print(math.gcd(x, y)+1)
```
| 8,717 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's imagine: there is a chess piece billiard ball. Its movements resemble the ones of a bishop chess piece. The only difference is that when a billiard ball hits the board's border, it can reflect from it and continue moving.
More formally, first one of four diagonal directions is chosen and the billiard ball moves in that direction. When it reaches the square located on the board's edge, the billiard ball reflects from it; it changes the direction of its movement by 90 degrees and continues moving. Specifically, having reached a corner square, the billiard ball is reflected twice and starts to move the opposite way. While it moves, the billiard ball can make an infinite number of reflections. At any square of its trajectory the billiard ball can stop and on that the move is considered completed.
<image>
It is considered that one billiard ball a beats another billiard ball b if a can reach a point where b is located.
You are suggested to find the maximal number of billiard balls, that pairwise do not beat each other and that can be positioned on a chessboard n × m in size.
Input
The first line contains two integers n and m (2 ≤ n, m ≤ 106).
Output
Print a single number, the maximum possible number of billiard balls that do not pairwise beat each other.
Please do not use the %lld specificator to read or write 64-bit numbers in C++. It is preferred to use cin (also you may use the %I64d specificator).
Examples
Input
3 4
Output
2
Input
3 3
Output
3
Tags: dfs and similar, dsu, graphs, number theory
Correct Solution:
```
n, m = map(int, input().split())
while 1 == 1:
if n == m:
print(n)
break
if n > m:
n, m = m, n
m -= (n - 1)
```
| 8,718 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's imagine: there is a chess piece billiard ball. Its movements resemble the ones of a bishop chess piece. The only difference is that when a billiard ball hits the board's border, it can reflect from it and continue moving.
More formally, first one of four diagonal directions is chosen and the billiard ball moves in that direction. When it reaches the square located on the board's edge, the billiard ball reflects from it; it changes the direction of its movement by 90 degrees and continues moving. Specifically, having reached a corner square, the billiard ball is reflected twice and starts to move the opposite way. While it moves, the billiard ball can make an infinite number of reflections. At any square of its trajectory the billiard ball can stop and on that the move is considered completed.
<image>
It is considered that one billiard ball a beats another billiard ball b if a can reach a point where b is located.
You are suggested to find the maximal number of billiard balls, that pairwise do not beat each other and that can be positioned on a chessboard n × m in size.
Input
The first line contains two integers n and m (2 ≤ n, m ≤ 106).
Output
Print a single number, the maximum possible number of billiard balls that do not pairwise beat each other.
Please do not use the %lld specificator to read or write 64-bit numbers in C++. It is preferred to use cin (also you may use the %I64d specificator).
Examples
Input
3 4
Output
2
Input
3 3
Output
3
Tags: dfs and similar, dsu, graphs, number theory
Correct Solution:
```
import math
n,m=map(int,input().split())
print(math.gcd(n-1,m-1)+1)
```
| 8,719 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's imagine: there is a chess piece billiard ball. Its movements resemble the ones of a bishop chess piece. The only difference is that when a billiard ball hits the board's border, it can reflect from it and continue moving.
More formally, first one of four diagonal directions is chosen and the billiard ball moves in that direction. When it reaches the square located on the board's edge, the billiard ball reflects from it; it changes the direction of its movement by 90 degrees and continues moving. Specifically, having reached a corner square, the billiard ball is reflected twice and starts to move the opposite way. While it moves, the billiard ball can make an infinite number of reflections. At any square of its trajectory the billiard ball can stop and on that the move is considered completed.
<image>
It is considered that one billiard ball a beats another billiard ball b if a can reach a point where b is located.
You are suggested to find the maximal number of billiard balls, that pairwise do not beat each other and that can be positioned on a chessboard n × m in size.
Input
The first line contains two integers n and m (2 ≤ n, m ≤ 106).
Output
Print a single number, the maximum possible number of billiard balls that do not pairwise beat each other.
Please do not use the %lld specificator to read or write 64-bit numbers in C++. It is preferred to use cin (also you may use the %I64d specificator).
Examples
Input
3 4
Output
2
Input
3 3
Output
3
Tags: dfs and similar, dsu, graphs, number theory
Correct Solution:
```
n, m = map(int, input().split())
while True:
if n == m:
print(n)
break
if n > m:
n, m = m, n
m -= (n - 1)
```
| 8,720 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's imagine: there is a chess piece billiard ball. Its movements resemble the ones of a bishop chess piece. The only difference is that when a billiard ball hits the board's border, it can reflect from it and continue moving.
More formally, first one of four diagonal directions is chosen and the billiard ball moves in that direction. When it reaches the square located on the board's edge, the billiard ball reflects from it; it changes the direction of its movement by 90 degrees and continues moving. Specifically, having reached a corner square, the billiard ball is reflected twice and starts to move the opposite way. While it moves, the billiard ball can make an infinite number of reflections. At any square of its trajectory the billiard ball can stop and on that the move is considered completed.
<image>
It is considered that one billiard ball a beats another billiard ball b if a can reach a point where b is located.
You are suggested to find the maximal number of billiard balls, that pairwise do not beat each other and that can be positioned on a chessboard n × m in size.
Input
The first line contains two integers n and m (2 ≤ n, m ≤ 106).
Output
Print a single number, the maximum possible number of billiard balls that do not pairwise beat each other.
Please do not use the %lld specificator to read or write 64-bit numbers in C++. It is preferred to use cin (also you may use the %I64d specificator).
Examples
Input
3 4
Output
2
Input
3 3
Output
3
Tags: dfs and similar, dsu, graphs, number theory
Correct Solution:
```
from math import *
n,m=sorted(list(map(int,input().split())))
print(1+gcd(n-1,m-n))
```
| 8,721 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's imagine: there is a chess piece billiard ball. Its movements resemble the ones of a bishop chess piece. The only difference is that when a billiard ball hits the board's border, it can reflect from it and continue moving.
More formally, first one of four diagonal directions is chosen and the billiard ball moves in that direction. When it reaches the square located on the board's edge, the billiard ball reflects from it; it changes the direction of its movement by 90 degrees and continues moving. Specifically, having reached a corner square, the billiard ball is reflected twice and starts to move the opposite way. While it moves, the billiard ball can make an infinite number of reflections. At any square of its trajectory the billiard ball can stop and on that the move is considered completed.
<image>
It is considered that one billiard ball a beats another billiard ball b if a can reach a point where b is located.
You are suggested to find the maximal number of billiard balls, that pairwise do not beat each other and that can be positioned on a chessboard n × m in size.
Input
The first line contains two integers n and m (2 ≤ n, m ≤ 106).
Output
Print a single number, the maximum possible number of billiard balls that do not pairwise beat each other.
Please do not use the %lld specificator to read or write 64-bit numbers in C++. It is preferred to use cin (also you may use the %I64d specificator).
Examples
Input
3 4
Output
2
Input
3 3
Output
3
Submitted Solution:
```
import sys
n, m = map(int, sys.stdin.readline().split())
def solve(n, m):
if n == m:
print(n)
return
if n > m:
n,m = m,n
if (m - 1) % (n - 1) == 0:
print(n)
return
print(gcd(2*(n-1), 2*(m-1)))
def gcd(a,b):
if b < a:
a,b = b,a
while b % a != 0:
a,b = b % a, a
return a
solve(n,m)
```
No
| 8,722 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's imagine: there is a chess piece billiard ball. Its movements resemble the ones of a bishop chess piece. The only difference is that when a billiard ball hits the board's border, it can reflect from it and continue moving.
More formally, first one of four diagonal directions is chosen and the billiard ball moves in that direction. When it reaches the square located on the board's edge, the billiard ball reflects from it; it changes the direction of its movement by 90 degrees and continues moving. Specifically, having reached a corner square, the billiard ball is reflected twice and starts to move the opposite way. While it moves, the billiard ball can make an infinite number of reflections. At any square of its trajectory the billiard ball can stop and on that the move is considered completed.
<image>
It is considered that one billiard ball a beats another billiard ball b if a can reach a point where b is located.
You are suggested to find the maximal number of billiard balls, that pairwise do not beat each other and that can be positioned on a chessboard n × m in size.
Input
The first line contains two integers n and m (2 ≤ n, m ≤ 106).
Output
Print a single number, the maximum possible number of billiard balls that do not pairwise beat each other.
Please do not use the %lld specificator to read or write 64-bit numbers in C++. It is preferred to use cin (also you may use the %I64d specificator).
Examples
Input
3 4
Output
2
Input
3 3
Output
3
Submitted Solution:
```
def solve(n, m):
if n == m:
print(n)
return
if n > m:
n,m = m,n
if (m - 1) % (n - 1) == 0:
print(n)
return
print(gcd(2*(n-1), 2*(m-1)))
def gcd(a,b):
if b < a:
a,b = b,a
while b % a != 0:
a,b = b % a, a
return a
```
No
| 8,723 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's imagine: there is a chess piece billiard ball. Its movements resemble the ones of a bishop chess piece. The only difference is that when a billiard ball hits the board's border, it can reflect from it and continue moving.
More formally, first one of four diagonal directions is chosen and the billiard ball moves in that direction. When it reaches the square located on the board's edge, the billiard ball reflects from it; it changes the direction of its movement by 90 degrees and continues moving. Specifically, having reached a corner square, the billiard ball is reflected twice and starts to move the opposite way. While it moves, the billiard ball can make an infinite number of reflections. At any square of its trajectory the billiard ball can stop and on that the move is considered completed.
<image>
It is considered that one billiard ball a beats another billiard ball b if a can reach a point where b is located.
You are suggested to find the maximal number of billiard balls, that pairwise do not beat each other and that can be positioned on a chessboard n × m in size.
Input
The first line contains two integers n and m (2 ≤ n, m ≤ 106).
Output
Print a single number, the maximum possible number of billiard balls that do not pairwise beat each other.
Please do not use the %lld specificator to read or write 64-bit numbers in C++. It is preferred to use cin (also you may use the %I64d specificator).
Examples
Input
3 4
Output
2
Input
3 3
Output
3
Submitted Solution:
```
def solve(n, m):
if n == m:
return n
if n > m:
n,m = m,n
if (m - 1) % (n - 1) == 0:
return n
return gcd(2*(n-1), 2*(m-1))
def gcd(a,b):
if b < a:
a,b = b,a
while b % a != 0:
a,b = b % a, a
return a
```
No
| 8,724 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's imagine: there is a chess piece billiard ball. Its movements resemble the ones of a bishop chess piece. The only difference is that when a billiard ball hits the board's border, it can reflect from it and continue moving.
More formally, first one of four diagonal directions is chosen and the billiard ball moves in that direction. When it reaches the square located on the board's edge, the billiard ball reflects from it; it changes the direction of its movement by 90 degrees and continues moving. Specifically, having reached a corner square, the billiard ball is reflected twice and starts to move the opposite way. While it moves, the billiard ball can make an infinite number of reflections. At any square of its trajectory the billiard ball can stop and on that the move is considered completed.
<image>
It is considered that one billiard ball a beats another billiard ball b if a can reach a point where b is located.
You are suggested to find the maximal number of billiard balls, that pairwise do not beat each other and that can be positioned on a chessboard n × m in size.
Input
The first line contains two integers n and m (2 ≤ n, m ≤ 106).
Output
Print a single number, the maximum possible number of billiard balls that do not pairwise beat each other.
Please do not use the %lld specificator to read or write 64-bit numbers in C++. It is preferred to use cin (also you may use the %I64d specificator).
Examples
Input
3 4
Output
2
Input
3 3
Output
3
Submitted Solution:
```
n,m=sorted(list(map(int,input().split())))
if n%(n-1)==m%(n-1):
print(n)
else:
print(2)
```
No
| 8,725 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems.
For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round.
<image>
Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to 1 / 4, and the problem's maximum point value is equal to 1500.
If the problem's maximum point value is equal to x, then for each whole minute passed from the beginning of the contest to the moment of the participant's correct submission, the participant loses x / 250 points. For example, if the problem's maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with 2000·(1 - 40 / 250) = 1680 points for this problem.
There are n participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It's also possible that this participant made no submissions to this problem.
With two seconds until the end of the round, all participants' submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing.
Unfortunately, Vasya is a cheater. He has registered 109 + 7 new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn't solved.
Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn't want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts.
Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya's assumptions are correct), or report that Vasya can't achieve his goal.
Input
The first line contains a single integer n (2 ≤ n ≤ 120) — the number of round participants, including Vasya and Petya.
Each of the next n lines contains five integers ai, 1, ai, 2..., ai, 5 ( - 1 ≤ ai, j ≤ 119) — the number of minutes passed between the beginning of the round and the submission of problem j by participant i, or -1 if participant i hasn't solved problem j.
It is guaranteed that each participant has made at least one successful submission.
Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order.
Output
Output a single integer — the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can't achieve his goal.
Examples
Input
2
5 15 40 70 115
50 45 40 30 15
Output
2
Input
3
55 80 10 -1 -1
15 -1 79 60 -1
42 -1 13 -1 -1
Output
3
Input
5
119 119 119 119 119
0 0 0 0 -1
20 65 12 73 77
78 112 22 23 11
1 78 60 111 62
Output
27
Input
4
-1 20 40 77 119
30 10 73 50 107
21 29 -1 64 98
117 65 -1 -1 -1
Output
-1
Note
In the first example, Vasya's optimal strategy is to submit the solutions to the last three problems from two new accounts. In this case the first two problems will have the maximum point value of 1000, while the last three problems will have the maximum point value of 500. Vasya's score will be equal to 980 + 940 + 420 + 360 + 270 = 2970 points, while Petya will score just 800 + 820 + 420 + 440 + 470 = 2950 points.
In the second example, Vasya has to make a single unsuccessful submission to any problem from two new accounts, and a single successful submission to the first problem from the third new account. In this case, the maximum point values of the problems will be equal to 500, 1500, 1000, 1500, 3000. Vasya will score 2370 points, while Petya will score just 2294 points.
In the third example, Vasya can achieve his goal by submitting the solutions to the first four problems from 27 new accounts. The maximum point values of the problems will be equal to 500, 500, 500, 500, 2000. Thanks to the high cost of the fifth problem, Vasya will manage to beat Petya who solved the first four problems very quickly, but couldn't solve the fifth one.
Tags: brute force, greedy
Correct Solution:
```
n=int(input())
a=[list(map(int,input().split())) for i in range(n)]
solved=[0]*5
score=[0]*5
for i in range(n):
for j in range(5):
solved[j]+=int(a[i][j]>-1)
for k in range(31*n+1):
for i in range(5):
tot=n+k
cur=solved[i]
cur+=k*(a[0][i]>-1 and a[1][i]>-1 and a[0][i]>a[1][i])
score[i]=500
while score[i]<3000 and 2*cur<=tot:
cur*=2;
score[i]+=500
res=[0,0]
for j in range(2):
for i in range(5):
res[j]+=(a[j][i]>-1)*score[i]/250*(250-a[j][i])
if res[0]>res[1]:
print(k)
break
else:
print("-1")
```
| 8,726 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems.
For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round.
<image>
Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to 1 / 4, and the problem's maximum point value is equal to 1500.
If the problem's maximum point value is equal to x, then for each whole minute passed from the beginning of the contest to the moment of the participant's correct submission, the participant loses x / 250 points. For example, if the problem's maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with 2000·(1 - 40 / 250) = 1680 points for this problem.
There are n participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It's also possible that this participant made no submissions to this problem.
With two seconds until the end of the round, all participants' submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing.
Unfortunately, Vasya is a cheater. He has registered 109 + 7 new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn't solved.
Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn't want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts.
Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya's assumptions are correct), or report that Vasya can't achieve his goal.
Input
The first line contains a single integer n (2 ≤ n ≤ 120) — the number of round participants, including Vasya and Petya.
Each of the next n lines contains five integers ai, 1, ai, 2..., ai, 5 ( - 1 ≤ ai, j ≤ 119) — the number of minutes passed between the beginning of the round and the submission of problem j by participant i, or -1 if participant i hasn't solved problem j.
It is guaranteed that each participant has made at least one successful submission.
Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order.
Output
Output a single integer — the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can't achieve his goal.
Examples
Input
2
5 15 40 70 115
50 45 40 30 15
Output
2
Input
3
55 80 10 -1 -1
15 -1 79 60 -1
42 -1 13 -1 -1
Output
3
Input
5
119 119 119 119 119
0 0 0 0 -1
20 65 12 73 77
78 112 22 23 11
1 78 60 111 62
Output
27
Input
4
-1 20 40 77 119
30 10 73 50 107
21 29 -1 64 98
117 65 -1 -1 -1
Output
-1
Note
In the first example, Vasya's optimal strategy is to submit the solutions to the last three problems from two new accounts. In this case the first two problems will have the maximum point value of 1000, while the last three problems will have the maximum point value of 500. Vasya's score will be equal to 980 + 940 + 420 + 360 + 270 = 2970 points, while Petya will score just 800 + 820 + 420 + 440 + 470 = 2950 points.
In the second example, Vasya has to make a single unsuccessful submission to any problem from two new accounts, and a single successful submission to the first problem from the third new account. In this case, the maximum point values of the problems will be equal to 500, 1500, 1000, 1500, 3000. Vasya will score 2370 points, while Petya will score just 2294 points.
In the third example, Vasya can achieve his goal by submitting the solutions to the first four problems from 27 new accounts. The maximum point values of the problems will be equal to 500, 500, 500, 500, 2000. Thanks to the high cost of the fifth problem, Vasya will manage to beat Petya who solved the first four problems very quickly, but couldn't solve the fifth one.
Tags: brute force, greedy
Correct Solution:
```
n = int(input())
t = [0] * n
for i in range(n):
t[i] = list(map(int, input().split()))
value = [0] * 5
solve = [0] * 5
for i in range(5):
solved = 0
for j in range(n):
if t[j][i] != -1:
solved += 1
else:
t[j][i] = 250
if (solved * 2 > n):
value[i] = 500
elif (solved * 4 > n):
value[i] = 1000
elif (solved * 8 > n):
value[i] = 1500
elif (solved * 16 > n):
value[i] = 2000
elif (solved * 32 > n):
value[i] = 2500
else:
value[i] = 3000
solve[i] = solved
vasya = 0
for i in range(5):
vasya += value[i] - value[i] // 250 * t[0][i]
petya = 0
for i in range(5):
petya += value[i] - value[i] // 250 * t[1][i]
pot = [[0] * 20000 for i in range(5)]
for problem in range(5):
if t[0][problem] < t[1][problem]:
cur_ac = 0
while 1:
if solve[problem] * 32 <= n + cur_ac:
win = 3000 - 3000 // 250 * t[0][problem] - (3000 - 3000 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 16 <= n + cur_ac:
win = 2500 - 2500 // 250 * t[0][problem] - (2500 - 2500 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 8 <= n + cur_ac:
win = 2000 - 2000 // 250 * t[0][problem] - (2000 - 2000 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 4 <= n + cur_ac:
win = 1500 - 1500 // 250 * t[0][problem] - (1500 - 1500 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 2 <= n + cur_ac:
win = 1000 - 1000 // 250 * t[0][problem] - (1000 - 1000 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
else:
win = 500 - 500 // 250 * t[0][problem] - (500 - 500 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
cur_ac += 1
if cur_ac == 20000:
break
elif t[0][problem] != 250:
cur_ac = 0
while 1:
if solve[problem] * 32 + cur_ac <= n + cur_ac:
win = 3000 - 3000 // 250 * t[0][problem] - (3000 - 3000 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 16 + cur_ac <= n + cur_ac:
win = 2500 - 2500 // 250 * t[0][problem] - (2500 - 2500 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 8 + cur_ac <= n + cur_ac:
win = 2000 - 2000 // 250 * t[0][problem] - (2000 - 2000 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 4 + cur_ac <= n + cur_ac:
win = 1500 - 1500 // 250 * t[0][problem] - (1500 - 1500 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 2 + cur_ac <= n + cur_ac:
win = 1000 - 1000 // 250 * t[0][problem] - (1000 - 1000 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
else:
win = 500 - 500 // 250 * t[0][problem] - (500 - 500 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
cur_ac += 1
if cur_ac == 20000:
break
else:
cur_ac = 0
while 1:
if solve[problem] * 32 <= n + cur_ac:
win = -(3000 - 3000 // 250 * t[1][problem]) -(
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 16 <= n + cur_ac:
win = -(2500 - 2500 // 250 * t[1][problem]) - (
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 8 <= n + cur_ac:
win = -(2000 - 2000 // 250 * t[1][problem]) - (
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 4 <= n + cur_ac:
win = -(1500 - 1500 // 250 * t[1][problem]) - (
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 2 <= n + cur_ac:
win = -(1000 - 1000 // 250 * t[1][problem]) - (
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
else:
win = -(500 - 500 // 250 * t[1][problem]) - (
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
cur_ac += 1
if cur_ac == 20000:
break
res = -1
maxi = 0
for i in range(5):
maxi = max(maxi, len(pot[i]))
for i in range(maxi):
tmp = 0
for pr in range(5):
if len(pot[pr]) <= i:
tmp += pot[pr][-1]
else:
tmp += pot[pr][i]
if tmp > petya - vasya:
res = i
break
print(res)
```
| 8,727 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems.
For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round.
<image>
Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to 1 / 4, and the problem's maximum point value is equal to 1500.
If the problem's maximum point value is equal to x, then for each whole minute passed from the beginning of the contest to the moment of the participant's correct submission, the participant loses x / 250 points. For example, if the problem's maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with 2000·(1 - 40 / 250) = 1680 points for this problem.
There are n participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It's also possible that this participant made no submissions to this problem.
With two seconds until the end of the round, all participants' submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing.
Unfortunately, Vasya is a cheater. He has registered 109 + 7 new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn't solved.
Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn't want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts.
Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya's assumptions are correct), or report that Vasya can't achieve his goal.
Input
The first line contains a single integer n (2 ≤ n ≤ 120) — the number of round participants, including Vasya and Petya.
Each of the next n lines contains five integers ai, 1, ai, 2..., ai, 5 ( - 1 ≤ ai, j ≤ 119) — the number of minutes passed between the beginning of the round and the submission of problem j by participant i, or -1 if participant i hasn't solved problem j.
It is guaranteed that each participant has made at least one successful submission.
Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order.
Output
Output a single integer — the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can't achieve his goal.
Examples
Input
2
5 15 40 70 115
50 45 40 30 15
Output
2
Input
3
55 80 10 -1 -1
15 -1 79 60 -1
42 -1 13 -1 -1
Output
3
Input
5
119 119 119 119 119
0 0 0 0 -1
20 65 12 73 77
78 112 22 23 11
1 78 60 111 62
Output
27
Input
4
-1 20 40 77 119
30 10 73 50 107
21 29 -1 64 98
117 65 -1 -1 -1
Output
-1
Note
In the first example, Vasya's optimal strategy is to submit the solutions to the last three problems from two new accounts. In this case the first two problems will have the maximum point value of 1000, while the last three problems will have the maximum point value of 500. Vasya's score will be equal to 980 + 940 + 420 + 360 + 270 = 2970 points, while Petya will score just 800 + 820 + 420 + 440 + 470 = 2950 points.
In the second example, Vasya has to make a single unsuccessful submission to any problem from two new accounts, and a single successful submission to the first problem from the third new account. In this case, the maximum point values of the problems will be equal to 500, 1500, 1000, 1500, 3000. Vasya will score 2370 points, while Petya will score just 2294 points.
In the third example, Vasya can achieve his goal by submitting the solutions to the first four problems from 27 new accounts. The maximum point values of the problems will be equal to 500, 500, 500, 500, 2000. Thanks to the high cost of the fifth problem, Vasya will manage to beat Petya who solved the first four problems very quickly, but couldn't solve the fifth one.
Tags: brute force, greedy
Correct Solution:
```
def get_value(parters, solved):
if solved * 32 <= parters:
return 3000
if solved * 16 <= parters:
return 2500
if solved * 8 <= parters:
return 2000
if solved * 4 <= parters:
return 1500
if solved * 2 <= parters:
return 1000
return 500
def points(value, time):
return value - value // 500 * time
n = int(input())
t = [0] * n
for i in range(n):
t[i] = list(map(int, input().split()))
value = [0] * 5
solve = [0] * 5
for i in range(5):
solved = 0
for j in range(n):
if t[j][i] != -1:
solved += 1
else:
t[j][i] = 250
value[i] = get_value(n, solved)
solve[i] = solved
vasya = 0
for i in range(5):
vasya += points(value[i], t[0][i])
petya = 0
for i in range(5):
petya += points(value[i], t[1][i])
pot = [[0] * 20000 for i in range(5)]
for problem in range(5):
for cur_ac in range(20000):
new_value = 0
if t[0][problem] < t[1][problem]:
new_value = get_value(n + cur_ac, solve[problem])
elif t[0][problem] != 250:
new_value = get_value(n + cur_ac, solve[problem] + cur_ac)
else:
new_value = get_value(n + cur_ac, solve[problem])
win = points(new_value, t[0][problem]) - points(new_value, t[1][problem]) - points(value[problem], t[0][problem]) + points(value[problem], t[1][problem])
pot[problem][cur_ac] = win
res = -1
for i in range(20000):
tmp = 0
for pr in range(5):
if len(pot[pr]) <= i:
tmp += pot[pr][-1]
else:
tmp += pot[pr][i]
if tmp > petya - vasya:
res = i
break
print(res)
```
| 8,728 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems.
For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round.
<image>
Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to 1 / 4, and the problem's maximum point value is equal to 1500.
If the problem's maximum point value is equal to x, then for each whole minute passed from the beginning of the contest to the moment of the participant's correct submission, the participant loses x / 250 points. For example, if the problem's maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with 2000·(1 - 40 / 250) = 1680 points for this problem.
There are n participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It's also possible that this participant made no submissions to this problem.
With two seconds until the end of the round, all participants' submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing.
Unfortunately, Vasya is a cheater. He has registered 109 + 7 new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn't solved.
Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn't want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts.
Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya's assumptions are correct), or report that Vasya can't achieve his goal.
Input
The first line contains a single integer n (2 ≤ n ≤ 120) — the number of round participants, including Vasya and Petya.
Each of the next n lines contains five integers ai, 1, ai, 2..., ai, 5 ( - 1 ≤ ai, j ≤ 119) — the number of minutes passed between the beginning of the round and the submission of problem j by participant i, or -1 if participant i hasn't solved problem j.
It is guaranteed that each participant has made at least one successful submission.
Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order.
Output
Output a single integer — the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can't achieve his goal.
Examples
Input
2
5 15 40 70 115
50 45 40 30 15
Output
2
Input
3
55 80 10 -1 -1
15 -1 79 60 -1
42 -1 13 -1 -1
Output
3
Input
5
119 119 119 119 119
0 0 0 0 -1
20 65 12 73 77
78 112 22 23 11
1 78 60 111 62
Output
27
Input
4
-1 20 40 77 119
30 10 73 50 107
21 29 -1 64 98
117 65 -1 -1 -1
Output
-1
Note
In the first example, Vasya's optimal strategy is to submit the solutions to the last three problems from two new accounts. In this case the first two problems will have the maximum point value of 1000, while the last three problems will have the maximum point value of 500. Vasya's score will be equal to 980 + 940 + 420 + 360 + 270 = 2970 points, while Petya will score just 800 + 820 + 420 + 440 + 470 = 2950 points.
In the second example, Vasya has to make a single unsuccessful submission to any problem from two new accounts, and a single successful submission to the first problem from the third new account. In this case, the maximum point values of the problems will be equal to 500, 1500, 1000, 1500, 3000. Vasya will score 2370 points, while Petya will score just 2294 points.
In the third example, Vasya can achieve his goal by submitting the solutions to the first four problems from 27 new accounts. The maximum point values of the problems will be equal to 500, 500, 500, 500, 2000. Thanks to the high cost of the fifth problem, Vasya will manage to beat Petya who solved the first four problems very quickly, but couldn't solve the fifth one.
Tags: brute force, greedy
Correct Solution:
```
from sys import stdin, stdout
fractionBoundaries = [1/2,1/4,1/8,1/16,1/32,0]
scoreList = [500,1000,1500,2000,2500,3000]
def assessScores(n,Vsol,Psol,solvers):
vScore=0
pScore=0
for i in range(5):
for j in range(6):
if solvers[i]/n>fractionBoundaries[j]:
qnScore=scoreList[j]
break
if Vsol[i]>=0:
vScore+=qnScore-(qnScore*Vsol[i]//250)
if Psol[i]>=0:
pScore+=qnScore-(qnScore*Psol[i]//250)
return vScore>pScore
def main():
n = int(stdin.readline().rstrip())
Vsol = [int(x) for x in stdin.readline().rstrip().split()]
Psol = [int(x) for x in stdin.readline().rstrip().split()]
solvers = [0]*5
for _ in range(n-2):
a = [int(x) for x in stdin.readline().rstrip().split()]
for i in range(5):
if a[i]>=0:
solvers[i]+=1
for i in range(5):
if Vsol[i]>=0:
solvers[i]+=1
if Psol[i]>=0:
solvers[i]+=1
newSolvers=0
vWins=[]
pWins=[]
for i in range(5):
if (Vsol[i]<Psol[i] and Vsol[i]>=0) or (Vsol[i]>=0 and Psol[i]<0):
vWins.append(i)
elif (Psol[i]<Vsol[i] and Psol[i]>=0 and Vsol[i]>=0):
pWins.append(i)
if len(vWins)==0:
print(-1)
else:
while not assessScores(n+newSolvers,Vsol,Psol,solvers) and newSolvers<=100000007:
solversNeeded=9999999999999
for i in range(5):
if i in vWins:
currentRatio = solvers[i]/(newSolvers+n)
for j in range(6):
if solvers[i]/(newSolvers+n)>fractionBoundaries[j]:
nextBoundary = fractionBoundaries[j]
break
if nextBoundary!=0:
if solvers[i]%nextBoundary==0:
solversNeeded = min([solvers[i]//nextBoundary - (newSolvers+n),solversNeeded])
else:
solversNeeded = min([solvers[i]//nextBoundary - (newSolvers+n)+1,solversNeeded])
elif i in pWins and Vsol[i]>0:
currentRatio = solvers[i]/(newSolvers+n)
for j in range(6):
if solvers[i]/(newSolvers+n)>fractionBoundaries[j]:
if j>0:
nextBoundary = fractionBoundaries[j-1]
solversNeeded = min([(nextBoundary*(newSolvers+n)-solvers[i])//(1-nextBoundary)+1,solversNeeded])
break
newSolvers+=solversNeeded
for x in pWins:
solvers[x]+=solversNeeded
if newSolvers>1000000007:
print(-1)
else:
print(int(newSolvers))
main()
```
| 8,729 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems.
For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round.
<image>
Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to 1 / 4, and the problem's maximum point value is equal to 1500.
If the problem's maximum point value is equal to x, then for each whole minute passed from the beginning of the contest to the moment of the participant's correct submission, the participant loses x / 250 points. For example, if the problem's maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with 2000·(1 - 40 / 250) = 1680 points for this problem.
There are n participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It's also possible that this participant made no submissions to this problem.
With two seconds until the end of the round, all participants' submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing.
Unfortunately, Vasya is a cheater. He has registered 109 + 7 new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn't solved.
Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn't want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts.
Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya's assumptions are correct), or report that Vasya can't achieve his goal.
Input
The first line contains a single integer n (2 ≤ n ≤ 120) — the number of round participants, including Vasya and Petya.
Each of the next n lines contains five integers ai, 1, ai, 2..., ai, 5 ( - 1 ≤ ai, j ≤ 119) — the number of minutes passed between the beginning of the round and the submission of problem j by participant i, or -1 if participant i hasn't solved problem j.
It is guaranteed that each participant has made at least one successful submission.
Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order.
Output
Output a single integer — the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can't achieve his goal.
Examples
Input
2
5 15 40 70 115
50 45 40 30 15
Output
2
Input
3
55 80 10 -1 -1
15 -1 79 60 -1
42 -1 13 -1 -1
Output
3
Input
5
119 119 119 119 119
0 0 0 0 -1
20 65 12 73 77
78 112 22 23 11
1 78 60 111 62
Output
27
Input
4
-1 20 40 77 119
30 10 73 50 107
21 29 -1 64 98
117 65 -1 -1 -1
Output
-1
Note
In the first example, Vasya's optimal strategy is to submit the solutions to the last three problems from two new accounts. In this case the first two problems will have the maximum point value of 1000, while the last three problems will have the maximum point value of 500. Vasya's score will be equal to 980 + 940 + 420 + 360 + 270 = 2970 points, while Petya will score just 800 + 820 + 420 + 440 + 470 = 2950 points.
In the second example, Vasya has to make a single unsuccessful submission to any problem from two new accounts, and a single successful submission to the first problem from the third new account. In this case, the maximum point values of the problems will be equal to 500, 1500, 1000, 1500, 3000. Vasya will score 2370 points, while Petya will score just 2294 points.
In the third example, Vasya can achieve his goal by submitting the solutions to the first four problems from 27 new accounts. The maximum point values of the problems will be equal to 500, 500, 500, 500, 2000. Thanks to the high cost of the fifth problem, Vasya will manage to beat Petya who solved the first four problems very quickly, but couldn't solve the fifth one.
Tags: brute force, greedy
Correct Solution:
```
import sys
inf = 10**9 + 7
def solve():
n = int(sys.stdin.readline())
v = [int(vi) for vi in sys.stdin.readline().split()] # Vesya
p = [int(pi) for pi in sys.stdin.readline().split()] # Petya
cnt = [0]*5
for i in range(5):
if v[i] != -1:
cnt[i] += 1
if p[i] != -1:
cnt[i] += 1
for i in range(n - 2):
a = [int(ai) for ai in sys.stdin.readline().split()]
for j in range(5):
if a[j] != -1:
cnt[j] += 1
for i in range(4000):
if check(n, v, p, cnt, i):
print(i)
return
print(-1)
def check(n, v, p, cnt, m):
tot = n + m
solved = cnt[:]
dif = 0
for i in range(5):
if p[i] != -1 and v[i] > p[i]:
solved[i] += m
for i in range(5):
if solved[i]*2 > tot:
max_score = 500
elif solved[i]*4 > tot:
max_score = 1000
elif solved[i]*8 > tot:
max_score = 1500
elif solved[i]*16 > tot:
max_score = 2000
elif solved[i]*32 > tot:
max_score = 2500
else:
max_score = 3000
if v[i] == p[i] == -1:
pass
elif v[i] == -1:
dif -= max_score * (250 - p[i]) // 250
elif p[i] == -1:
dif += max_score * (250 - v[i]) // 250
else:
dif += max_score * (p[i] - v[i]) // 250
return dif > 0
if __name__ == '__main__':
solve()
```
| 8,730 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems.
For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round.
<image>
Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to 1 / 4, and the problem's maximum point value is equal to 1500.
If the problem's maximum point value is equal to x, then for each whole minute passed from the beginning of the contest to the moment of the participant's correct submission, the participant loses x / 250 points. For example, if the problem's maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with 2000·(1 - 40 / 250) = 1680 points for this problem.
There are n participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It's also possible that this participant made no submissions to this problem.
With two seconds until the end of the round, all participants' submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing.
Unfortunately, Vasya is a cheater. He has registered 109 + 7 new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn't solved.
Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn't want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts.
Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya's assumptions are correct), or report that Vasya can't achieve his goal.
Input
The first line contains a single integer n (2 ≤ n ≤ 120) — the number of round participants, including Vasya and Petya.
Each of the next n lines contains five integers ai, 1, ai, 2..., ai, 5 ( - 1 ≤ ai, j ≤ 119) — the number of minutes passed between the beginning of the round and the submission of problem j by participant i, or -1 if participant i hasn't solved problem j.
It is guaranteed that each participant has made at least one successful submission.
Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order.
Output
Output a single integer — the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can't achieve his goal.
Examples
Input
2
5 15 40 70 115
50 45 40 30 15
Output
2
Input
3
55 80 10 -1 -1
15 -1 79 60 -1
42 -1 13 -1 -1
Output
3
Input
5
119 119 119 119 119
0 0 0 0 -1
20 65 12 73 77
78 112 22 23 11
1 78 60 111 62
Output
27
Input
4
-1 20 40 77 119
30 10 73 50 107
21 29 -1 64 98
117 65 -1 -1 -1
Output
-1
Note
In the first example, Vasya's optimal strategy is to submit the solutions to the last three problems from two new accounts. In this case the first two problems will have the maximum point value of 1000, while the last three problems will have the maximum point value of 500. Vasya's score will be equal to 980 + 940 + 420 + 360 + 270 = 2970 points, while Petya will score just 800 + 820 + 420 + 440 + 470 = 2950 points.
In the second example, Vasya has to make a single unsuccessful submission to any problem from two new accounts, and a single successful submission to the first problem from the third new account. In this case, the maximum point values of the problems will be equal to 500, 1500, 1000, 1500, 3000. Vasya will score 2370 points, while Petya will score just 2294 points.
In the third example, Vasya can achieve his goal by submitting the solutions to the first four problems from 27 new accounts. The maximum point values of the problems will be equal to 500, 500, 500, 500, 2000. Thanks to the high cost of the fifth problem, Vasya will manage to beat Petya who solved the first four problems very quickly, but couldn't solve the fifth one.
Tags: brute force, greedy
Correct Solution:
```
import sys
inf = 10**9 + 7
def solve():
n = int(sys.stdin.readline())
v = [int(vi) for vi in sys.stdin.readline().split()] # Vesya
p = [int(pi) for pi in sys.stdin.readline().split()] # Petya
cnt = [0]*5
for i in range(5):
if v[i] != -1:
cnt[i] += 1
if p[i] != -1:
cnt[i] += 1
for i in range(n - 2):
a = [int(ai) for ai in sys.stdin.readline().split()]
for j in range(5):
if a[j] != -1:
cnt[j] += 1
for i in range(10**5):
if check(n, v, p, cnt, i):
print(i)
return
print(-1)
def check(n, v, p, cnt, m):
tot = n + m
solved = cnt[:]
dif = 0
for i in range(5):
if p[i] != -1 and v[i] > p[i]:
solved[i] += m
for i in range(5):
if solved[i]*2 > tot:
max_score = 500
elif solved[i]*4 > tot:
max_score = 1000
elif solved[i]*8 > tot:
max_score = 1500
elif solved[i]*16 > tot:
max_score = 2000
elif solved[i]*32 > tot:
max_score = 2500
else:
max_score = 3000
if v[i] == p[i] == -1:
pass
elif v[i] == -1:
dif -= max_score * (250 - p[i]) // 250
elif p[i] == -1:
dif += max_score * (250 - v[i]) // 250
else:
dif += max_score * (p[i] - v[i]) // 250
return dif > 0
if __name__ == '__main__':
solve()
```
| 8,731 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems.
For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round.
<image>
Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to 1 / 4, and the problem's maximum point value is equal to 1500.
If the problem's maximum point value is equal to x, then for each whole minute passed from the beginning of the contest to the moment of the participant's correct submission, the participant loses x / 250 points. For example, if the problem's maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with 2000·(1 - 40 / 250) = 1680 points for this problem.
There are n participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It's also possible that this participant made no submissions to this problem.
With two seconds until the end of the round, all participants' submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing.
Unfortunately, Vasya is a cheater. He has registered 109 + 7 new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn't solved.
Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn't want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts.
Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya's assumptions are correct), or report that Vasya can't achieve his goal.
Input
The first line contains a single integer n (2 ≤ n ≤ 120) — the number of round participants, including Vasya and Petya.
Each of the next n lines contains five integers ai, 1, ai, 2..., ai, 5 ( - 1 ≤ ai, j ≤ 119) — the number of minutes passed between the beginning of the round and the submission of problem j by participant i, or -1 if participant i hasn't solved problem j.
It is guaranteed that each participant has made at least one successful submission.
Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order.
Output
Output a single integer — the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can't achieve his goal.
Examples
Input
2
5 15 40 70 115
50 45 40 30 15
Output
2
Input
3
55 80 10 -1 -1
15 -1 79 60 -1
42 -1 13 -1 -1
Output
3
Input
5
119 119 119 119 119
0 0 0 0 -1
20 65 12 73 77
78 112 22 23 11
1 78 60 111 62
Output
27
Input
4
-1 20 40 77 119
30 10 73 50 107
21 29 -1 64 98
117 65 -1 -1 -1
Output
-1
Note
In the first example, Vasya's optimal strategy is to submit the solutions to the last three problems from two new accounts. In this case the first two problems will have the maximum point value of 1000, while the last three problems will have the maximum point value of 500. Vasya's score will be equal to 980 + 940 + 420 + 360 + 270 = 2970 points, while Petya will score just 800 + 820 + 420 + 440 + 470 = 2950 points.
In the second example, Vasya has to make a single unsuccessful submission to any problem from two new accounts, and a single successful submission to the first problem from the third new account. In this case, the maximum point values of the problems will be equal to 500, 1500, 1000, 1500, 3000. Vasya will score 2370 points, while Petya will score just 2294 points.
In the third example, Vasya can achieve his goal by submitting the solutions to the first four problems from 27 new accounts. The maximum point values of the problems will be equal to 500, 500, 500, 500, 2000. Thanks to the high cost of the fifth problem, Vasya will manage to beat Petya who solved the first four problems very quickly, but couldn't solve the fifth one.
Tags: brute force, greedy
Correct Solution:
```
import sys
inf = 10**9 + 7
def solve():
def check(mid):
tot = n + mid
dif = 0
solved = cnt[:]
for i in range(5):
if v[i] != -1 and p[i] != -1 and p[i] < v[i]:
solved[i] += mid
for i in range(5):
if solved[i]*2 > tot:
max_score = 500
elif solved[i]*4 > tot:
max_score = 1000
elif solved[i]*8 > tot:
max_score = 1500
elif solved[i]*16 > tot:
max_score = 2000
elif solved[i]*32 > tot:
max_score = 2500
else:
max_score = 3000
if v[i] == p[i]:
pass
elif v[i] == -1:
dif += max_score * (250 - p[i]) // 250
elif p[i] == -1:
dif += -max_score * (250 - v[i]) // 250
else:
dif += max_score * (-p[i] + v[i]) // 250
# print(mid, dif)
return dif < 0
n = int(sys.stdin.readline())
cnt = [0]*5
v = [int(i) for i in sys.stdin.readline().split()]
for i in range(5):
if v[i] != -1:
cnt[i] += 1
p = [int(i) for i in sys.stdin.readline().split()]
for i in range(5):
if p[i] != -1:
cnt[i] += 1
for i in range(n - 2):
a = [int(ai) for ai in sys.stdin.readline().split()]
for j in range(5):
if a[j] != -1:
cnt[j] += 1
for i in range(6000):
if check(i):
print(i)
return
print(-1)
if __name__ == '__main__':
solve()
```
| 8,732 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems.
For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round.
<image>
Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to 1 / 4, and the problem's maximum point value is equal to 1500.
If the problem's maximum point value is equal to x, then for each whole minute passed from the beginning of the contest to the moment of the participant's correct submission, the participant loses x / 250 points. For example, if the problem's maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with 2000·(1 - 40 / 250) = 1680 points for this problem.
There are n participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It's also possible that this participant made no submissions to this problem.
With two seconds until the end of the round, all participants' submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing.
Unfortunately, Vasya is a cheater. He has registered 109 + 7 new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn't solved.
Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn't want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts.
Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya's assumptions are correct), or report that Vasya can't achieve his goal.
Input
The first line contains a single integer n (2 ≤ n ≤ 120) — the number of round participants, including Vasya and Petya.
Each of the next n lines contains five integers ai, 1, ai, 2..., ai, 5 ( - 1 ≤ ai, j ≤ 119) — the number of minutes passed between the beginning of the round and the submission of problem j by participant i, or -1 if participant i hasn't solved problem j.
It is guaranteed that each participant has made at least one successful submission.
Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order.
Output
Output a single integer — the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can't achieve his goal.
Examples
Input
2
5 15 40 70 115
50 45 40 30 15
Output
2
Input
3
55 80 10 -1 -1
15 -1 79 60 -1
42 -1 13 -1 -1
Output
3
Input
5
119 119 119 119 119
0 0 0 0 -1
20 65 12 73 77
78 112 22 23 11
1 78 60 111 62
Output
27
Input
4
-1 20 40 77 119
30 10 73 50 107
21 29 -1 64 98
117 65 -1 -1 -1
Output
-1
Note
In the first example, Vasya's optimal strategy is to submit the solutions to the last three problems from two new accounts. In this case the first two problems will have the maximum point value of 1000, while the last three problems will have the maximum point value of 500. Vasya's score will be equal to 980 + 940 + 420 + 360 + 270 = 2970 points, while Petya will score just 800 + 820 + 420 + 440 + 470 = 2950 points.
In the second example, Vasya has to make a single unsuccessful submission to any problem from two new accounts, and a single successful submission to the first problem from the third new account. In this case, the maximum point values of the problems will be equal to 500, 1500, 1000, 1500, 3000. Vasya will score 2370 points, while Petya will score just 2294 points.
In the third example, Vasya can achieve his goal by submitting the solutions to the first four problems from 27 new accounts. The maximum point values of the problems will be equal to 500, 500, 500, 500, 2000. Thanks to the high cost of the fifth problem, Vasya will manage to beat Petya who solved the first four problems very quickly, but couldn't solve the fifth one.
Tags: brute force, greedy
Correct Solution:
```
n=int(input())
a=[list(map(int,input().split())) for i in range(n)]
solved=[0 for i in range(5)]
score=[0 for i in range(5)]
for i in range(n):
for j in range(5):
solved[j]+=int(a[i][j]>-1)
for k in range(31*n+1):
for i in range(5):
tot=n+k
cur=solved[i]
if a[0][i]>-1 and a[1][i]>-1 and a[0][i]>a[1][i]:
cur+=k
score[i]=500
while score[i]<3000 and 2*cur<=tot:
cur*=2;
score[i]+=500
res=[0,0]
for j in range(2):
for i in range(5):
if a[j][i]>-1:
res[j]+=score[i]/250*(250-a[j][i])
if res[0]>res[1]:
print(k)
exit()
print("-1")
```
| 8,733 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems.
For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round.
<image>
Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to 1 / 4, and the problem's maximum point value is equal to 1500.
If the problem's maximum point value is equal to x, then for each whole minute passed from the beginning of the contest to the moment of the participant's correct submission, the participant loses x / 250 points. For example, if the problem's maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with 2000·(1 - 40 / 250) = 1680 points for this problem.
There are n participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It's also possible that this participant made no submissions to this problem.
With two seconds until the end of the round, all participants' submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing.
Unfortunately, Vasya is a cheater. He has registered 109 + 7 new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn't solved.
Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn't want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts.
Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya's assumptions are correct), or report that Vasya can't achieve his goal.
Input
The first line contains a single integer n (2 ≤ n ≤ 120) — the number of round participants, including Vasya and Petya.
Each of the next n lines contains five integers ai, 1, ai, 2..., ai, 5 ( - 1 ≤ ai, j ≤ 119) — the number of minutes passed between the beginning of the round and the submission of problem j by participant i, or -1 if participant i hasn't solved problem j.
It is guaranteed that each participant has made at least one successful submission.
Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order.
Output
Output a single integer — the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can't achieve his goal.
Examples
Input
2
5 15 40 70 115
50 45 40 30 15
Output
2
Input
3
55 80 10 -1 -1
15 -1 79 60 -1
42 -1 13 -1 -1
Output
3
Input
5
119 119 119 119 119
0 0 0 0 -1
20 65 12 73 77
78 112 22 23 11
1 78 60 111 62
Output
27
Input
4
-1 20 40 77 119
30 10 73 50 107
21 29 -1 64 98
117 65 -1 -1 -1
Output
-1
Note
In the first example, Vasya's optimal strategy is to submit the solutions to the last three problems from two new accounts. In this case the first two problems will have the maximum point value of 1000, while the last three problems will have the maximum point value of 500. Vasya's score will be equal to 980 + 940 + 420 + 360 + 270 = 2970 points, while Petya will score just 800 + 820 + 420 + 440 + 470 = 2950 points.
In the second example, Vasya has to make a single unsuccessful submission to any problem from two new accounts, and a single successful submission to the first problem from the third new account. In this case, the maximum point values of the problems will be equal to 500, 1500, 1000, 1500, 3000. Vasya will score 2370 points, while Petya will score just 2294 points.
In the third example, Vasya can achieve his goal by submitting the solutions to the first four problems from 27 new accounts. The maximum point values of the problems will be equal to 500, 500, 500, 500, 2000. Thanks to the high cost of the fifth problem, Vasya will manage to beat Petya who solved the first four problems very quickly, but couldn't solve the fifth one.
Submitted Solution:
```
def f(v, x, n):
if v<0:
return 0
elif x<<1>n:
return int( 500*(1-v/250))
elif x<<2>n:
return int(1000*(1-v/250))
elif x<<3>n:
return int(1500*(1-v/250))
elif x<<4>n:
return int(2000*(1-v/250))
elif x<<5>n:
return int(2500*(1-v/250))
else:
return int(3000*(1-v/250))
n=int(input())
a=[list(map(int, input().split())) for _ in range(n)]
c=[sum(_[i]>=0 for _ in a) for i in range(5)]
ans=-1
for i in range(10000):
p, q=0, 0
for j in range(5):
x, y=c[j], n
if a[0][j]>a[1][j] and a[1][j]>=0:
x+=i
p+=f(a[0][j], x, n+i)
q+=f(a[1][j], x, n+i)
if p>q:
ans=i
break
print(ans)
# Made By Mostafa_Khaled
```
Yes
| 8,734 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems.
For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round.
<image>
Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to 1 / 4, and the problem's maximum point value is equal to 1500.
If the problem's maximum point value is equal to x, then for each whole minute passed from the beginning of the contest to the moment of the participant's correct submission, the participant loses x / 250 points. For example, if the problem's maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with 2000·(1 - 40 / 250) = 1680 points for this problem.
There are n participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It's also possible that this participant made no submissions to this problem.
With two seconds until the end of the round, all participants' submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing.
Unfortunately, Vasya is a cheater. He has registered 109 + 7 new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn't solved.
Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn't want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts.
Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya's assumptions are correct), or report that Vasya can't achieve his goal.
Input
The first line contains a single integer n (2 ≤ n ≤ 120) — the number of round participants, including Vasya and Petya.
Each of the next n lines contains five integers ai, 1, ai, 2..., ai, 5 ( - 1 ≤ ai, j ≤ 119) — the number of minutes passed between the beginning of the round and the submission of problem j by participant i, or -1 if participant i hasn't solved problem j.
It is guaranteed that each participant has made at least one successful submission.
Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order.
Output
Output a single integer — the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can't achieve his goal.
Examples
Input
2
5 15 40 70 115
50 45 40 30 15
Output
2
Input
3
55 80 10 -1 -1
15 -1 79 60 -1
42 -1 13 -1 -1
Output
3
Input
5
119 119 119 119 119
0 0 0 0 -1
20 65 12 73 77
78 112 22 23 11
1 78 60 111 62
Output
27
Input
4
-1 20 40 77 119
30 10 73 50 107
21 29 -1 64 98
117 65 -1 -1 -1
Output
-1
Note
In the first example, Vasya's optimal strategy is to submit the solutions to the last three problems from two new accounts. In this case the first two problems will have the maximum point value of 1000, while the last three problems will have the maximum point value of 500. Vasya's score will be equal to 980 + 940 + 420 + 360 + 270 = 2970 points, while Petya will score just 800 + 820 + 420 + 440 + 470 = 2950 points.
In the second example, Vasya has to make a single unsuccessful submission to any problem from two new accounts, and a single successful submission to the first problem from the third new account. In this case, the maximum point values of the problems will be equal to 500, 1500, 1000, 1500, 3000. Vasya will score 2370 points, while Petya will score just 2294 points.
In the third example, Vasya can achieve his goal by submitting the solutions to the first four problems from 27 new accounts. The maximum point values of the problems will be equal to 500, 500, 500, 500, 2000. Thanks to the high cost of the fifth problem, Vasya will manage to beat Petya who solved the first four problems very quickly, but couldn't solve the fifth one.
Submitted Solution:
```
n = int(input())
t = [0] * n
for i in range(n):
t[i] = list(map(int, input().split()))
value = [0] * 5
solve = [0] * 5
for i in range(5):
solved = 0
for j in range(n):
if t[j][i] != -1:
solved += 1
else:
t[j][i] = 250
if (solved * 2 > n):
value[i] = 500
elif (solved * 4 > n):
value[i] = 1000
elif (solved * 8 > n):
value[i] = 1500
elif (solved * 16 > n):
value[i] = 2000
elif (solved * 32 > n):
value[i] = 2500
else:
value[i] = 3000
solve[i] = solved
vasya = 0
for i in range(5):
vasya += value[i] - value[i] // 250 * t[0][i]
petya = 0
for i in range(5):
petya += value[i] - value[i] // 250 * t[1][i]
pot = [[0] * 20000 for i in range(5)]
for problem in range(5):
if t[0][problem] < t[1][problem]:
cur_ac = 0
while 1:
if solve[problem] * 32 <= n + cur_ac:
win = 3000 - 3000 // 250 * t[0][problem] - (3000 - 3000 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 16 <= n + cur_ac:
win = 2500 - 2500 // 250 * t[0][problem] - (2500 - 2500 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 8 <= n + cur_ac:
win = 2000 - 2000 // 250 * t[0][problem] - (2000 - 2000 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 4 <= n + cur_ac:
win = 1500 - 1500 // 250 * t[0][problem] - (1500 - 1500 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 2 <= n + cur_ac:
win = 1000 - 1000 // 250 * t[0][problem] - (1000 - 1000 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
else:
win = 500 - 500 // 250 * t[0][problem] - (500 - 500 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
cur_ac += 1
if cur_ac == 20000:
break
elif t[0][problem] != 250:
cur_ac = 0
while 1:
if solve[problem] * 32 + cur_ac <= n + cur_ac:
win = 3000 - 3000 // 250 * t[0][problem] - (3000 - 3000 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 16 + cur_ac <= n + cur_ac:
win = 2500 - 2500 // 250 * t[0][problem] - (2500 - 2500 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 8 + cur_ac <= n + cur_ac:
win = 2000 - 2000 // 250 * t[0][problem] - (2000 - 2000 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 4 + cur_ac <= n + cur_ac:
win = 1500 - 1500 // 250 * t[0][problem] - (1500 - 1500 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 2 + cur_ac <= n + cur_ac:
win = 1000 - 1000 // 250 * t[0][problem] - (1000 - 1000 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
else:
win = 500 - 500 // 250 * t[0][problem] - (500 - 500 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
cur_ac += 1
if cur_ac == 20000:
break
else:
cur_ac = 0
while 1:
if solve[problem] * 32 <= n + cur_ac:
win = -(3000 - 3000 // 250 * t[1][problem]) -(
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
break
elif solve[problem] * 16 <= n + cur_ac:
win = -(2500 - 2500 // 250 * t[1][problem]) - (
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 8 <= n + cur_ac:
win = -(2000 - 2000 // 250 * t[1][problem]) - (
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 4 <= n + cur_ac:
win = -(1500 - 1500 // 250 * t[1][problem]) - (
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 2 <= n + cur_ac:
win = -(1000 - 1000 // 250 * t[1][problem]) - (
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
else:
win = -(500 - 500 // 250 * t[1][problem]) - (
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
cur_ac += 1
if cur_ac == 20000:
break
res = -1
maxi = 0
for i in range(5):
maxi = max(maxi, len(pot[i]))
for i in range(maxi):
tmp = 0
for pr in range(5):
if len(pot[pr]) <= i:
tmp += pot[pr][-1]
else:
tmp += pot[pr][i]
if tmp > petya - vasya:
res = i
break
if n == 98:
print(solve)
print(res)
```
No
| 8,735 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems.
For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round.
<image>
Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to 1 / 4, and the problem's maximum point value is equal to 1500.
If the problem's maximum point value is equal to x, then for each whole minute passed from the beginning of the contest to the moment of the participant's correct submission, the participant loses x / 250 points. For example, if the problem's maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with 2000·(1 - 40 / 250) = 1680 points for this problem.
There are n participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It's also possible that this participant made no submissions to this problem.
With two seconds until the end of the round, all participants' submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing.
Unfortunately, Vasya is a cheater. He has registered 109 + 7 new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn't solved.
Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn't want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts.
Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya's assumptions are correct), or report that Vasya can't achieve his goal.
Input
The first line contains a single integer n (2 ≤ n ≤ 120) — the number of round participants, including Vasya and Petya.
Each of the next n lines contains five integers ai, 1, ai, 2..., ai, 5 ( - 1 ≤ ai, j ≤ 119) — the number of minutes passed between the beginning of the round and the submission of problem j by participant i, or -1 if participant i hasn't solved problem j.
It is guaranteed that each participant has made at least one successful submission.
Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order.
Output
Output a single integer — the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can't achieve his goal.
Examples
Input
2
5 15 40 70 115
50 45 40 30 15
Output
2
Input
3
55 80 10 -1 -1
15 -1 79 60 -1
42 -1 13 -1 -1
Output
3
Input
5
119 119 119 119 119
0 0 0 0 -1
20 65 12 73 77
78 112 22 23 11
1 78 60 111 62
Output
27
Input
4
-1 20 40 77 119
30 10 73 50 107
21 29 -1 64 98
117 65 -1 -1 -1
Output
-1
Note
In the first example, Vasya's optimal strategy is to submit the solutions to the last three problems from two new accounts. In this case the first two problems will have the maximum point value of 1000, while the last three problems will have the maximum point value of 500. Vasya's score will be equal to 980 + 940 + 420 + 360 + 270 = 2970 points, while Petya will score just 800 + 820 + 420 + 440 + 470 = 2950 points.
In the second example, Vasya has to make a single unsuccessful submission to any problem from two new accounts, and a single successful submission to the first problem from the third new account. In this case, the maximum point values of the problems will be equal to 500, 1500, 1000, 1500, 3000. Vasya will score 2370 points, while Petya will score just 2294 points.
In the third example, Vasya can achieve his goal by submitting the solutions to the first four problems from 27 new accounts. The maximum point values of the problems will be equal to 500, 500, 500, 500, 2000. Thanks to the high cost of the fifth problem, Vasya will manage to beat Petya who solved the first four problems very quickly, but couldn't solve the fifth one.
Submitted Solution:
```
n = int(input())
Mines =[[int(x) for x in input().split(' ')] for y in range(n)]
diff =[]
for i in range(n):
diff.append(abs( Mines[i][0] - Mines[i][1] ))
print(diff.index(max(diff))+1)
```
No
| 8,736 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems.
For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round.
<image>
Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to 1 / 4, and the problem's maximum point value is equal to 1500.
If the problem's maximum point value is equal to x, then for each whole minute passed from the beginning of the contest to the moment of the participant's correct submission, the participant loses x / 250 points. For example, if the problem's maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with 2000·(1 - 40 / 250) = 1680 points for this problem.
There are n participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It's also possible that this participant made no submissions to this problem.
With two seconds until the end of the round, all participants' submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing.
Unfortunately, Vasya is a cheater. He has registered 109 + 7 new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn't solved.
Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn't want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts.
Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya's assumptions are correct), or report that Vasya can't achieve his goal.
Input
The first line contains a single integer n (2 ≤ n ≤ 120) — the number of round participants, including Vasya and Petya.
Each of the next n lines contains five integers ai, 1, ai, 2..., ai, 5 ( - 1 ≤ ai, j ≤ 119) — the number of minutes passed between the beginning of the round and the submission of problem j by participant i, or -1 if participant i hasn't solved problem j.
It is guaranteed that each participant has made at least one successful submission.
Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order.
Output
Output a single integer — the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can't achieve his goal.
Examples
Input
2
5 15 40 70 115
50 45 40 30 15
Output
2
Input
3
55 80 10 -1 -1
15 -1 79 60 -1
42 -1 13 -1 -1
Output
3
Input
5
119 119 119 119 119
0 0 0 0 -1
20 65 12 73 77
78 112 22 23 11
1 78 60 111 62
Output
27
Input
4
-1 20 40 77 119
30 10 73 50 107
21 29 -1 64 98
117 65 -1 -1 -1
Output
-1
Note
In the first example, Vasya's optimal strategy is to submit the solutions to the last three problems from two new accounts. In this case the first two problems will have the maximum point value of 1000, while the last three problems will have the maximum point value of 500. Vasya's score will be equal to 980 + 940 + 420 + 360 + 270 = 2970 points, while Petya will score just 800 + 820 + 420 + 440 + 470 = 2950 points.
In the second example, Vasya has to make a single unsuccessful submission to any problem from two new accounts, and a single successful submission to the first problem from the third new account. In this case, the maximum point values of the problems will be equal to 500, 1500, 1000, 1500, 3000. Vasya will score 2370 points, while Petya will score just 2294 points.
In the third example, Vasya can achieve his goal by submitting the solutions to the first four problems from 27 new accounts. The maximum point values of the problems will be equal to 500, 500, 500, 500, 2000. Thanks to the high cost of the fifth problem, Vasya will manage to beat Petya who solved the first four problems very quickly, but couldn't solve the fifth one.
Submitted Solution:
```
n = int(input())
t = [0] * n
for i in range(n):
t[i] = list(map(int, input().split()))
value = [0] * 5
solve = [0] * 5
for i in range(5):
solved = 0
for j in range(n):
if t[j][i] != -1:
solved += 1
else:
t[j][i] = 250
if (solved * 2 > n):
value[i] = 500
elif (solved * 4 > n):
value[i] = 1000
elif (solved * 8 > n):
value[i] = 1500
elif (solved * 16 > n):
value[i] = 2000
elif (solved * 32 > n):
value[i] = 2500
else:
value[i] = 3000
solve[i] = solved
vasya = 0
for i in range(5):
vasya += value[i] - value[i] // 250 * t[0][i]
petya = 0
for i in range(5):
petya += value[i] - value[i] // 250 * t[1][i]
pot = [[0] * 20000 for i in range(5)]
for problem in range(5):
if t[0][problem] < t[1][problem]:
cur_ac = 0
while 1:
if solve[problem] * 32 <= n + cur_ac:
win = 3000 - 3000 // 250 * t[0][problem] - (3000 - 3000 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 16 <= n + cur_ac:
win = 2500 - 2500 // 250 * t[0][problem] - (2500 - 2500 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 8 <= n + cur_ac:
win = 2000 - 2000 // 250 * t[0][problem] - (2000 - 2000 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 4 <= n + cur_ac:
win = 1500 - 1500 // 250 * t[0][problem] - (1500 - 1500 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 2 <= n + cur_ac:
win = 1000 - 1000 // 250 * t[0][problem] - (1000 - 1000 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
else:
win = 500 - 500 // 250 * t[0][problem] - (500 - 500 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
cur_ac += 1
if cur_ac == 20000:
break
elif t[0][problem] != 250:
cur_ac = 0
while 1:
if solve[problem] * 32 + cur_ac <= n + cur_ac:
win = 3000 - 3000 // 250 * t[0][problem] - (3000 - 3000 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 16 + cur_ac <= n + cur_ac:
win = 2500 - 2500 // 250 * t[0][problem] - (2500 - 2500 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 8 + cur_ac <= n + cur_ac:
win = 2000 - 2000 // 250 * t[0][problem] - (2000 - 2000 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 4 + cur_ac <= n + cur_ac:
win = 1500 - 1500 // 250 * t[0][problem] - (1500 - 1500 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 2 + cur_ac <= n + cur_ac:
win = 1000 - 1000 // 250 * t[0][problem] - (1000 - 1000 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
else:
win = 500 - 500 // 250 * t[0][problem] - (500 - 500 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
cur_ac += 1
if cur_ac == 20000:
break
else:
cur_ac = 0
while 1:
if solve[problem] * 32 <= n + cur_ac:
win = -(3000 - 3000 // 250 * t[1][problem]) -(
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
break
elif solve[problem] * 16 <= n + cur_ac:
win = -(2500 - 2500 // 250 * t[1][problem]) - (
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 8 <= n + cur_ac:
win = -(2000 - 2000 // 250 * t[1][problem]) - (
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 4 <= n + cur_ac:
win = -(1500 - 1500 // 250 * t[1][problem]) - (
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 2 <= n + cur_ac:
win = -(1000 - 1000 // 250 * t[1][problem]) - (
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
else:
win = -(500 - 500 // 250 * t[1][problem]) - (
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
cur_ac += 1
if cur_ac == 20000:
break
res = -1
maxi = 0
for i in range(5):
maxi = max(maxi, len(pot[i]))
for i in range(maxi):
tmp = 0
for pr in range(5):
if len(pot[pr]) <= i:
tmp += pot[pr][-1]
else:
tmp += pot[pr][i]
if n == 97 and i == 3007:
print(tmp)
if tmp > petya - vasya:
res = i
break
if (n == 97):
print(vasya, petya, solve)
print(res)
```
No
| 8,737 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems.
For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round.
<image>
Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to 1 / 4, and the problem's maximum point value is equal to 1500.
If the problem's maximum point value is equal to x, then for each whole minute passed from the beginning of the contest to the moment of the participant's correct submission, the participant loses x / 250 points. For example, if the problem's maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with 2000·(1 - 40 / 250) = 1680 points for this problem.
There are n participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It's also possible that this participant made no submissions to this problem.
With two seconds until the end of the round, all participants' submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing.
Unfortunately, Vasya is a cheater. He has registered 109 + 7 new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn't solved.
Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn't want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts.
Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya's assumptions are correct), or report that Vasya can't achieve his goal.
Input
The first line contains a single integer n (2 ≤ n ≤ 120) — the number of round participants, including Vasya and Petya.
Each of the next n lines contains five integers ai, 1, ai, 2..., ai, 5 ( - 1 ≤ ai, j ≤ 119) — the number of minutes passed between the beginning of the round and the submission of problem j by participant i, or -1 if participant i hasn't solved problem j.
It is guaranteed that each participant has made at least one successful submission.
Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order.
Output
Output a single integer — the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can't achieve his goal.
Examples
Input
2
5 15 40 70 115
50 45 40 30 15
Output
2
Input
3
55 80 10 -1 -1
15 -1 79 60 -1
42 -1 13 -1 -1
Output
3
Input
5
119 119 119 119 119
0 0 0 0 -1
20 65 12 73 77
78 112 22 23 11
1 78 60 111 62
Output
27
Input
4
-1 20 40 77 119
30 10 73 50 107
21 29 -1 64 98
117 65 -1 -1 -1
Output
-1
Note
In the first example, Vasya's optimal strategy is to submit the solutions to the last three problems from two new accounts. In this case the first two problems will have the maximum point value of 1000, while the last three problems will have the maximum point value of 500. Vasya's score will be equal to 980 + 940 + 420 + 360 + 270 = 2970 points, while Petya will score just 800 + 820 + 420 + 440 + 470 = 2950 points.
In the second example, Vasya has to make a single unsuccessful submission to any problem from two new accounts, and a single successful submission to the first problem from the third new account. In this case, the maximum point values of the problems will be equal to 500, 1500, 1000, 1500, 3000. Vasya will score 2370 points, while Petya will score just 2294 points.
In the third example, Vasya can achieve his goal by submitting the solutions to the first four problems from 27 new accounts. The maximum point values of the problems will be equal to 500, 500, 500, 500, 2000. Thanks to the high cost of the fifth problem, Vasya will manage to beat Petya who solved the first four problems very quickly, but couldn't solve the fifth one.
Submitted Solution:
```
n = int(input())
t = [0] * n
for i in range(n):
t[i] = list(map(int, input().split()))
value = [0] * 5
solve = [0] * 5
for i in range(5):
solved = 0
for j in range(n):
if t[j][i] != -1:
solved += 1
else:
t[j][i] = 250
if (solved * 2 > n):
value[i] = 500
elif (solved * 4 > n):
value[i] = 1000
elif (solved * 8 > n):
value[i] = 1500
elif (solved * 16 > n):
value[i] = 2000
elif (solved * 32 > n):
value[i] = 2500
else:
value[i] = 3000
solve[i] = solved
vasya = 0
for i in range(5):
vasya += value[i] - value[i] // 250 * t[0][i]
petya = 0
for i in range(5):
petya += value[i] - value[i] // 250 * t[1][i]
pot = [[0] * 200000 for i in range(5)]
for problem in range(5):
if t[0][problem] < t[1][problem]:
cur_ac = 0
while 1:
if solve[problem] * 32 <= n + cur_ac:
win = 3000 - 3000 // 250 * t[0][problem] - (3000 - 3000 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
break
elif solve[problem] * 16 <= n + cur_ac:
win = 2500 - 2500 // 250 * t[0][problem] - (2500 - 2500 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 8 <= n + cur_ac:
win = 2000 - 2000 // 250 * t[0][problem] - (2000 - 2000 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 4 <= n + cur_ac:
win = 1500 - 1500 // 250 * t[0][problem] - (1500 - 1500 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 2 <= n + cur_ac:
win = 1000 - 1000 // 250 * t[0][problem] - (1000 - 1000 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
else:
win = 500 - 500 // 250 * t[0][problem] - (500 - 500 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
cur_ac += 1
elif t[0][problem] != 250:
cur_ac = 0
while 1:
if solve[problem] * 32 + cur_ac <= n + cur_ac:
win = 3000 - 3000 // 250 * t[0][problem] - (3000 - 3000 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 16 + cur_ac <= n + cur_ac:
win = 2500 - 2500 // 250 * t[0][problem] - (2500 - 2500 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 8 + cur_ac <= n + cur_ac:
win = 2000 - 2000 // 250 * t[0][problem] - (2000 - 2000 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 4 + cur_ac <= n + cur_ac:
win = 1500 - 1500 // 250 * t[0][problem] - (1500 - 1500 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 2 + cur_ac <= n + cur_ac:
win = 1000 - 1000 // 250 * t[0][problem] - (1000 - 1000 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
else:
win = 500 - 500 // 250 * t[0][problem] - (500 - 500 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
break
cur_ac += 1
else:
cur_ac = 0
while 1:
if solve[problem] * 32 <= n + cur_ac:
win = -(3000 - 3000 // 250 * t[1][problem]) -(
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
break
elif solve[problem] * 16 <= n + cur_ac:
win = -(2500 - 2500 // 250 * t[1][problem]) - (
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 8 <= n + cur_ac:
win = -(2000 - 2000 // 250 * t[1][problem]) - (
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 4 <= n + cur_ac:
win = -(1500 - 1500 // 250 * t[1][problem]) - (
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 2 <= n + cur_ac:
win = -(1000 - 1000 // 250 * t[1][problem]) - (
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
else:
win = -(500 - 500 // 250 * t[1][problem]) - (
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
cur_ac += 1
res = -1
maxi = 0
for i in range(5):
maxi = max(maxi, len(pot[i]))
for i in range(maxi):
tmp = 0
for pr in range(5):
if len(pot[pr]) <= i:
tmp += pot[pr][-1]
else:
tmp += pot[pr][i]
if tmp > petya - vasya:
res = i
break
print(res)
```
No
| 8,738 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mike has a string s consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome.
A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codeforces", "reality", "ab" are not.
Input
The first and single line contains string s (1 ≤ |s| ≤ 15).
Output
Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise.
Examples
Input
abccaa
Output
YES
Input
abbcca
Output
NO
Input
abcda
Output
YES
Tags: brute force, constructive algorithms, strings
Correct Solution:
```
s = input()
cnt = 0
for i in range(len(s)):
if (s[i] != s[len(s) - i - 1]): cnt += 1
print("YES" if (cnt == 2) or (cnt == 0 and len(s) % 2 == 1) else "NO")
```
| 8,739 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mike has a string s consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome.
A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codeforces", "reality", "ab" are not.
Input
The first and single line contains string s (1 ≤ |s| ≤ 15).
Output
Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise.
Examples
Input
abccaa
Output
YES
Input
abbcca
Output
NO
Input
abcda
Output
YES
Tags: brute force, constructive algorithms, strings
Correct Solution:
```
s=input()
n=len(s)
c=0
for i in range(n//2):
if(s[i]!=s[n-i-1]):
c=c+1
if(c==1):
print("YES")
elif(n%2==1 and c==0):
print("YES")
else:
print("NO")
```
| 8,740 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mike has a string s consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome.
A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codeforces", "reality", "ab" are not.
Input
The first and single line contains string s (1 ≤ |s| ≤ 15).
Output
Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise.
Examples
Input
abccaa
Output
YES
Input
abbcca
Output
NO
Input
abcda
Output
YES
Tags: brute force, constructive algorithms, strings
Correct Solution:
```
x = list(input())
g = len(x)
p = g//2
w = 0
if g%2==0:
q = x[:p]+x[:p][::-1]
elif x[::-1]==x and g%2!=0:
print("YES")
quit()
else:
q = x[:p+1]+x[:p][::-1]
for i in range(p,g):
if x[i]!=q[i-g]:
w+=1
if w == 1:
print("YES")
else:
print("NO")
```
| 8,741 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mike has a string s consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome.
A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codeforces", "reality", "ab" are not.
Input
The first and single line contains string s (1 ≤ |s| ≤ 15).
Output
Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise.
Examples
Input
abccaa
Output
YES
Input
abbcca
Output
NO
Input
abcda
Output
YES
Tags: brute force, constructive algorithms, strings
Correct Solution:
```
def main():
s = input()
n = len(s)
l = 0
r = n-1
cnt = 0
while(l<=r):
if(s[l]!=s[r]):
cnt+=1
l+=1
r-=1
if(cnt>1):
print("NO")
return
if(cnt==1 or n%2==1):
print("YES")
else:
print("NO")
main()
```
| 8,742 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mike has a string s consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome.
A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codeforces", "reality", "ab" are not.
Input
The first and single line contains string s (1 ≤ |s| ≤ 15).
Output
Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise.
Examples
Input
abccaa
Output
YES
Input
abbcca
Output
NO
Input
abcda
Output
YES
Tags: brute force, constructive algorithms, strings
Correct Solution:
```
s=input()
count=0
i=0
j=len(s)-1
while i<j:
if s[i]!=s[j]:
count+=1
i=i+1
j=j-1
if count==1:
print('YES')
elif count==0:
if len(s)%2==0:
print('NO')
else:
print("YES")
else:
print('NO')
```
| 8,743 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mike has a string s consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome.
A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codeforces", "reality", "ab" are not.
Input
The first and single line contains string s (1 ≤ |s| ≤ 15).
Output
Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise.
Examples
Input
abccaa
Output
YES
Input
abbcca
Output
NO
Input
abcda
Output
YES
Tags: brute force, constructive algorithms, strings
Correct Solution:
```
s=input()
if len(s)%2==0:
t=s[:len(s)//2]
y=s[len(s)//2:]
y=y[::-1]
c=0
for i in range(len(s)//2):
if t[i]!=y[i]:
c=c+1
if c!=1:
print("NO")
else:
print("YES")
else:
t = s[:len(s) // 2]
y = s[len(s) // 2+1:]
y = y[::-1]
c = 0
for i in range(len(s) // 2):
if t[i] != y[i]:
c = c + 1
if c > 1:
print("NO")
else:
print("YES")
```
| 8,744 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mike has a string s consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome.
A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codeforces", "reality", "ab" are not.
Input
The first and single line contains string s (1 ≤ |s| ≤ 15).
Output
Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise.
Examples
Input
abccaa
Output
YES
Input
abbcca
Output
NO
Input
abcda
Output
YES
Tags: brute force, constructive algorithms, strings
Correct Solution:
```
s = input()
c = 0
if (s[::-1] == s and len(s)&1 == 1):
print("YES")
exit()
for i in range(len(s)//2):
if s[i] != s[-i-1]:
c+=1
print("NO YES".split()[c==1])
```
| 8,745 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mike has a string s consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome.
A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codeforces", "reality", "ab" are not.
Input
The first and single line contains string s (1 ≤ |s| ≤ 15).
Output
Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise.
Examples
Input
abccaa
Output
YES
Input
abbcca
Output
NO
Input
abcda
Output
YES
Tags: brute force, constructive algorithms, strings
Correct Solution:
```
n=input()
t=0
for i in range(len(n)//2):
if(n[i]!=n[len(n)-i-1]):
t+=1
if(t==1 or (t==0 and len(n)%2==1)):
print("YES")
else:
print("NO")
```
| 8,746 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mike has a string s consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome.
A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codeforces", "reality", "ab" are not.
Input
The first and single line contains string s (1 ≤ |s| ≤ 15).
Output
Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise.
Examples
Input
abccaa
Output
YES
Input
abbcca
Output
NO
Input
abcda
Output
YES
Submitted Solution:
```
li= input()
b = len(li)//2
count = 0
for i in range(b):
if li[i] != li[-(i+1)]:
count += 1
if count == 1: print('YES')
elif count ==0 and len(li) & 1: print('YES')
else: print("NO")
```
Yes
| 8,747 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mike has a string s consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome.
A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codeforces", "reality", "ab" are not.
Input
The first and single line contains string s (1 ≤ |s| ≤ 15).
Output
Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise.
Examples
Input
abccaa
Output
YES
Input
abbcca
Output
NO
Input
abcda
Output
YES
Submitted Solution:
```
s=input()
if len(s)==1:
print('YES')
else:
l=list(s)
l.reverse()
t=''.join(l)
l=[0]*len(s)
for i in range(len(s)):
if s[i]!=t[i]:
l[i]=1
r=''.join([str(i) for i in l])
if r.count('1')==2 or r.count('1')==0 and len(s)%2==1:
print('YES')
else:
print('NO')
```
Yes
| 8,748 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mike has a string s consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome.
A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codeforces", "reality", "ab" are not.
Input
The first and single line contains string s (1 ≤ |s| ≤ 15).
Output
Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise.
Examples
Input
abccaa
Output
YES
Input
abbcca
Output
NO
Input
abcda
Output
YES
Submitted Solution:
```
from math import ceil
n = input()
ln = ceil(len(n)/2)
f = 0
if n != n[::-1] :
for i in range(0,ln):
if n[i] != n[-(i+1)]:
if f == 0:
f = 1
else:
print('NO')
f = 0
break
elif len(n)%2==1: print('YES')
else: print('NO')
if f==1: print('YES')
```
Yes
| 8,749 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mike has a string s consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome.
A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codeforces", "reality", "ab" are not.
Input
The first and single line contains string s (1 ≤ |s| ≤ 15).
Output
Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise.
Examples
Input
abccaa
Output
YES
Input
abbcca
Output
NO
Input
abcda
Output
YES
Submitted Solution:
```
s=input()
i=0
j=len(s)-1
b=0
t=0
if len(s)==1:
print('YES')
exit()
s1=s[0]
if len(s)%2:
if s[:j//2]==s[j//2+1:][::-1]:
print('YES')
exit()
while i<j:
if s[i]!=s[j]:
b+=1
if b>1:
print('NO')
exit()
i+=1
j-=1
print('YES') if b==1 else print('NO')
```
Yes
| 8,750 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mike has a string s consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome.
A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codeforces", "reality", "ab" are not.
Input
The first and single line contains string s (1 ≤ |s| ≤ 15).
Output
Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise.
Examples
Input
abccaa
Output
YES
Input
abbcca
Output
NO
Input
abcda
Output
YES
Submitted Solution:
```
s=input()
p=0
for i in range(len(s)//2):
if (s[i]!=s[-i-1]):
p+=1
if p>1 or p==0:
print("NO")
else :
print("YES")
```
No
| 8,751 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mike has a string s consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome.
A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codeforces", "reality", "ab" are not.
Input
The first and single line contains string s (1 ≤ |s| ≤ 15).
Output
Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise.
Examples
Input
abccaa
Output
YES
Input
abbcca
Output
NO
Input
abcda
Output
YES
Submitted Solution:
```
s=input()
r=0
while(r<2 and len(s)>3):
if(s[0]!=s[-1]):
r+=1
s=s.replace(s[0],'',1)
s=s[::-1]
s=s.replace(s[0],'',1)
s=s[::-1]
if(len(s)==2 and s[0]!=s[-1]):
r+=1
print(['YES','NO'][r==2])
```
No
| 8,752 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mike has a string s consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome.
A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codeforces", "reality", "ab" are not.
Input
The first and single line contains string s (1 ≤ |s| ≤ 15).
Output
Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise.
Examples
Input
abccaa
Output
YES
Input
abbcca
Output
NO
Input
abcda
Output
YES
Submitted Solution:
```
string = input()
counter = 0
for i in range(len(string) // 2):
l = i
r = len(string) - i - 1
counter += string[l] != string[r]
print("YES" if counter == 1 else "NO")
```
No
| 8,753 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mike has a string s consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome.
A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codeforces", "reality", "ab" are not.
Input
The first and single line contains string s (1 ≤ |s| ≤ 15).
Output
Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise.
Examples
Input
abccaa
Output
YES
Input
abbcca
Output
NO
Input
abcda
Output
YES
Submitted Solution:
```
s = input()
length = len(s)
if length % 2 == 0:
count = 0
for i in range(length//2):
if s[i] != s[length - i -1]:
count += 1
if count == 1:
print("YES")
else:
print("NO")
else:
count = 0
for i in range((length - 1)//2):
if s[i] != s[length - i - 1]:
count += 1
if count == 1:
print("YES")
else:
print("NO")
```
No
| 8,754 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Yet another round on DecoForces is coming! Grandpa Maks wanted to participate in it but someone has stolen his precious sofa! And how can one perform well with such a major loss?
Fortunately, the thief had left a note for Grandpa Maks. This note got Maks to the sofa storehouse. Still he had no idea which sofa belongs to him as they all looked the same!
The storehouse is represented as matrix n × m. Every sofa takes two neighbouring by some side cells. No cell is covered by more than one sofa. There can be empty cells.
Sofa A is standing to the left of sofa B if there exist two such cells a and b that xa < xb, a is covered by A and b is covered by B. Sofa A is standing to the top of sofa B if there exist two such cells a and b that ya < yb, a is covered by A and b is covered by B. Right and bottom conditions are declared the same way.
Note that in all conditions A ≠ B. Also some sofa A can be both to the top of another sofa B and to the bottom of it. The same is for left and right conditions.
The note also stated that there are cntl sofas to the left of Grandpa Maks's sofa, cntr — to the right, cntt — to the top and cntb — to the bottom.
Grandpa Maks asks you to help him to identify his sofa. It is guaranteed that there is no more than one sofa of given conditions.
Output the number of Grandpa Maks's sofa. If there is no such sofa that all the conditions are met for it then output -1.
Input
The first line contains one integer number d (1 ≤ d ≤ 105) — the number of sofas in the storehouse.
The second line contains two integer numbers n, m (1 ≤ n, m ≤ 105) — the size of the storehouse.
Next d lines contains four integer numbers x1, y1, x2, y2 (1 ≤ x1, x2 ≤ n, 1 ≤ y1, y2 ≤ m) — coordinates of the i-th sofa. It is guaranteed that cells (x1, y1) and (x2, y2) have common side, (x1, y1) ≠ (x2, y2) and no cell is covered by more than one sofa.
The last line contains four integer numbers cntl, cntr, cntt, cntb (0 ≤ cntl, cntr, cntt, cntb ≤ d - 1).
Output
Print the number of the sofa for which all the conditions are met. Sofas are numbered 1 through d as given in input. If there is no such sofa then print -1.
Examples
Input
2
3 2
3 1 3 2
1 2 2 2
1 0 0 1
Output
1
Input
3
10 10
1 2 1 1
5 5 6 5
6 4 5 4
2 1 2 0
Output
2
Input
2
2 2
2 1 1 1
1 2 2 2
1 0 0 0
Output
-1
Note
Let's consider the second example.
* The first sofa has 0 to its left, 2 sofas to its right ((1, 1) is to the left of both (5, 5) and (5, 4)), 0 to its top and 2 to its bottom (both 2nd and 3rd sofas are below).
* The second sofa has cntl = 2, cntr = 1, cntt = 2 and cntb = 0.
* The third sofa has cntl = 2, cntr = 1, cntt = 1 and cntb = 1.
So the second one corresponds to the given conditions.
In the third example
* The first sofa has cntl = 1, cntr = 1, cntt = 0 and cntb = 1.
* The second sofa has cntl = 1, cntr = 1, cntt = 1 and cntb = 0.
And there is no sofa with the set (1, 0, 0, 0) so the answer is -1.
Tags: brute force, implementation
Correct Solution:
```
from sys import stdin, stdout
k = int(stdin.readline())
n, m = map(int, stdin.readline().split())
left, right, down, up = [], [], [], []
coordinates = []
for i in range(k):
x1, y1, x2, y2 = map(int, stdin.readline().split())
if x1 == x2:
if y1 < y2:
coordinates.append((x1, y1, x2, y2, i))
else:
coordinates.append((x2, y2, x1, y1, i))
else:
if x1 < x2:
coordinates.append((x1, y1, x2, y2, i))
else:
coordinates.append((x2, y2, x1, y1, i))
left.append(coordinates[-1])
right.append(coordinates[-1])
up.append(coordinates[-1])
down.append(coordinates[-1])
left.sort(key = lambda x: (x[0], x[2]))
down.sort(key = lambda x: (x[1], x[3]))
challengers = [[], [], [], []]
cntl, cntr, cntd, cntu = map(int, stdin.readline().split())
label = 1
if cntl or not cntl:
for i in range(cntl, -1, -1):
if (left[i][0], left[i][2]) == (left[cntl][0], left[cntl][2]):
challengers[0].append(left[i][-1])
else:
break
for i in range(cntl + 1, k):
if (left[i][0], left[i][2]) == (left[cntl][0], left[cntl][2]) and left[i][2] > left[i][0]:
label = 0
if (left[i][0], left[i][2]) == (left[cntl][0], left[cntl][2]):
challengers[0].append(left[i][-1])
else:
break
if cntr or not cntr:
for i in range(k - 1 - cntr, k):
if (left[i][0], left[i][2]) == (left[k - 1 - cntr][0], left[k - 1 - cntr][2]):
challengers[1].append(left[i][-1])
else:
break
for i in range(k - 2 - cntr, -1, -1):
if (left[i][0], left[i][2]) == (left[k - 1 - cntr][0], left[k - 1 - cntr][2]) and left[i][2] > left[i][0]:
label = 0
if (left[i][0], left[i][2]) == (left[k - 1 - cntr][0], left[k - 1 - cntr][2]):
challengers[1].append(left[i][-1])
else:
break
#!!!!!!!!!!!
if cntd or not cntd:
for i in range(cntd, -1, -1):
if (down[i][1], down[i][3]) == (down[cntd][1], down[cntd][3]):
challengers[2].append(down[i][-1])
else:
break
for i in range(cntd + 1, k):
if (down[i][1], down[i][3]) == (down[cntd][1], down[cntd][3]) and down[i][3] > down[i][1]:
label = 0
if (down[i][1], down[i][3]) == (down[cntd][1], down[cntd][3]):
challengers[2].append(down[i][-1])
else:
break
if cntu or not cntu:
for i in range(k - 1 - cntu, k):
if (down[i][1], down[i][3]) == (down[k - 1 - cntu][1], down[k - 1 - cntu][3]):
challengers[3].append(down[i][-1])
else:
break
for i in range(k - 2 - cntu, -1, -1):
if (down[i][1], down[i][3]) == (down[k - 1 - cntu][1], down[k - 1 - cntu][3]) and down[i][3] > down[i][1]:
label = 0
if (down[i][1], down[i][3]) == (down[k - 1 - cntu][1], down[k - 1 - cntu][3]):
challengers[3].append(down[i][-1])
else:
break
ans = set(challengers[0]) & set(challengers[1]) & set(challengers[2]) & set(challengers[3])
if not len(ans) or not label:
stdout.write('-1')
else:
stdout.write(str(list(ans)[0] + 1))
```
| 8,755 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Yet another round on DecoForces is coming! Grandpa Maks wanted to participate in it but someone has stolen his precious sofa! And how can one perform well with such a major loss?
Fortunately, the thief had left a note for Grandpa Maks. This note got Maks to the sofa storehouse. Still he had no idea which sofa belongs to him as they all looked the same!
The storehouse is represented as matrix n × m. Every sofa takes two neighbouring by some side cells. No cell is covered by more than one sofa. There can be empty cells.
Sofa A is standing to the left of sofa B if there exist two such cells a and b that xa < xb, a is covered by A and b is covered by B. Sofa A is standing to the top of sofa B if there exist two such cells a and b that ya < yb, a is covered by A and b is covered by B. Right and bottom conditions are declared the same way.
Note that in all conditions A ≠ B. Also some sofa A can be both to the top of another sofa B and to the bottom of it. The same is for left and right conditions.
The note also stated that there are cntl sofas to the left of Grandpa Maks's sofa, cntr — to the right, cntt — to the top and cntb — to the bottom.
Grandpa Maks asks you to help him to identify his sofa. It is guaranteed that there is no more than one sofa of given conditions.
Output the number of Grandpa Maks's sofa. If there is no such sofa that all the conditions are met for it then output -1.
Input
The first line contains one integer number d (1 ≤ d ≤ 105) — the number of sofas in the storehouse.
The second line contains two integer numbers n, m (1 ≤ n, m ≤ 105) — the size of the storehouse.
Next d lines contains four integer numbers x1, y1, x2, y2 (1 ≤ x1, x2 ≤ n, 1 ≤ y1, y2 ≤ m) — coordinates of the i-th sofa. It is guaranteed that cells (x1, y1) and (x2, y2) have common side, (x1, y1) ≠ (x2, y2) and no cell is covered by more than one sofa.
The last line contains four integer numbers cntl, cntr, cntt, cntb (0 ≤ cntl, cntr, cntt, cntb ≤ d - 1).
Output
Print the number of the sofa for which all the conditions are met. Sofas are numbered 1 through d as given in input. If there is no such sofa then print -1.
Examples
Input
2
3 2
3 1 3 2
1 2 2 2
1 0 0 1
Output
1
Input
3
10 10
1 2 1 1
5 5 6 5
6 4 5 4
2 1 2 0
Output
2
Input
2
2 2
2 1 1 1
1 2 2 2
1 0 0 0
Output
-1
Note
Let's consider the second example.
* The first sofa has 0 to its left, 2 sofas to its right ((1, 1) is to the left of both (5, 5) and (5, 4)), 0 to its top and 2 to its bottom (both 2nd and 3rd sofas are below).
* The second sofa has cntl = 2, cntr = 1, cntt = 2 and cntb = 0.
* The third sofa has cntl = 2, cntr = 1, cntt = 1 and cntb = 1.
So the second one corresponds to the given conditions.
In the third example
* The first sofa has cntl = 1, cntr = 1, cntt = 0 and cntb = 1.
* The second sofa has cntl = 1, cntr = 1, cntt = 1 and cntb = 0.
And there is no sofa with the set (1, 0, 0, 0) so the answer is -1.
Tags: brute force, implementation
Correct Solution:
```
from sys import stdin, stdout
k = int(stdin.readline())
n, m = map(int, stdin.readline().split())
left, right, down, up = [], [], [], []
coordinates = []
for i in range(k):
x1, y1, x2, y2 = map(int, stdin.readline().split())
if x1 == x2:
if y1 < y2:
coordinates.append((x1, y1, x2, y2, i))
else:
coordinates.append((x2, y2, x1, y1, i))
else:
if x1 < x2:
coordinates.append((x1, y1, x2, y2, i))
else:
coordinates.append((x2, y2, x1, y1, i))
left.append(coordinates[-1])
right.append(coordinates[-1])
up.append(coordinates[-1])
down.append(coordinates[-1])
left.sort(key = lambda x: (x[0], x[2]))
down.sort(key = lambda x: (x[1], x[3]))
challengers = [[], [], [], []]
cntl, cntr, cntd, cntu = map(int, stdin.readline().split())
label = 1
if cntl or not cntl:
for i in range(cntl, -1, -1):
if (left[i][0], left[i][2]) == (left[cntl][0], left[cntl][2]):
challengers[0].append(left[i][-1])
else:
break
for i in range(cntl + 1, k):
if (left[i][0], left[i][2]) == (left[cntl][0], left[cntl][2]) and left[i][2] > left[i][0]:
label = 0
if (left[i][0], left[i][2]) == (left[cntl][0], left[cntl][2]):
challengers[0].append(left[i][-1])
else:
break
if cntr or not cntr:
for i in range(k - 1 - cntr, k):
if (left[i][0], left[i][2]) == (left[k - 1 - cntr][0], left[k - 1 - cntr][2]):
challengers[1].append(left[i][-1])
else:
break
for i in range(k - 2 - cntr, -1, -1):
if (left[i][0], left[i][2]) == (left[k - 1 - cntr][0], left[k - 1 - cntr][2]) and left[i][2] > left[i][0]:
label = 0
if (left[i][0], left[i][2]) == (left[k - 1 - cntr][0], left[k - 1 - cntr][2]):
challengers[1].append(left[i][-1])
else:
break
#!!!!!!!!!!!
if cntd or not cntd:
for i in range(cntd, -1, -1):
if (down[i][1], down[i][3]) == (down[cntd][1], down[cntd][3]):
challengers[2].append(down[i][-1])
else:
break
for i in range(cntd + 1, k):
if (down[i][1], down[i][3]) == (down[cntd][1], down[cntd][3]) and down[i][3] > down[i][1]:
label = 0
if (down[i][1], down[i][3]) == (down[cntd][1], down[cntd][3]):
challengers[2].append(down[i][-1])
else:
break
if cntu or not cntu:
for i in range(k - 1 - cntu, k):
if (down[i][1], down[i][3]) == (down[k - 1 - cntu][1], down[k - 1 - cntu][3]):
challengers[3].append(down[i][-1])
else:
break
for i in range(k - 2 - cntu, -1, -1):
if (down[i][1], down[i][3]) == (down[k - 1 - cntu][1], down[k - 1 - cntu][3]) and down[i][3] > down[i][1]:
label = 0
if (down[i][1], down[i][3]) == (down[k - 1 - cntu][1], down[k - 1 - cntu][3]):
challengers[3].append(down[i][-1])
else:
break
ans = set(challengers[0]) & set(challengers[1]) & set(challengers[2]) & set(challengers[3])
if not len(ans) or not label:
stdout.write('-1')
else:
stdout.write(str(list(ans)[0] + 1))
# Made By Mostafa_Khaled
```
| 8,756 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Yet another round on DecoForces is coming! Grandpa Maks wanted to participate in it but someone has stolen his precious sofa! And how can one perform well with such a major loss?
Fortunately, the thief had left a note for Grandpa Maks. This note got Maks to the sofa storehouse. Still he had no idea which sofa belongs to him as they all looked the same!
The storehouse is represented as matrix n × m. Every sofa takes two neighbouring by some side cells. No cell is covered by more than one sofa. There can be empty cells.
Sofa A is standing to the left of sofa B if there exist two such cells a and b that xa < xb, a is covered by A and b is covered by B. Sofa A is standing to the top of sofa B if there exist two such cells a and b that ya < yb, a is covered by A and b is covered by B. Right and bottom conditions are declared the same way.
Note that in all conditions A ≠ B. Also some sofa A can be both to the top of another sofa B and to the bottom of it. The same is for left and right conditions.
The note also stated that there are cntl sofas to the left of Grandpa Maks's sofa, cntr — to the right, cntt — to the top and cntb — to the bottom.
Grandpa Maks asks you to help him to identify his sofa. It is guaranteed that there is no more than one sofa of given conditions.
Output the number of Grandpa Maks's sofa. If there is no such sofa that all the conditions are met for it then output -1.
Input
The first line contains one integer number d (1 ≤ d ≤ 105) — the number of sofas in the storehouse.
The second line contains two integer numbers n, m (1 ≤ n, m ≤ 105) — the size of the storehouse.
Next d lines contains four integer numbers x1, y1, x2, y2 (1 ≤ x1, x2 ≤ n, 1 ≤ y1, y2 ≤ m) — coordinates of the i-th sofa. It is guaranteed that cells (x1, y1) and (x2, y2) have common side, (x1, y1) ≠ (x2, y2) and no cell is covered by more than one sofa.
The last line contains four integer numbers cntl, cntr, cntt, cntb (0 ≤ cntl, cntr, cntt, cntb ≤ d - 1).
Output
Print the number of the sofa for which all the conditions are met. Sofas are numbered 1 through d as given in input. If there is no such sofa then print -1.
Examples
Input
2
3 2
3 1 3 2
1 2 2 2
1 0 0 1
Output
1
Input
3
10 10
1 2 1 1
5 5 6 5
6 4 5 4
2 1 2 0
Output
2
Input
2
2 2
2 1 1 1
1 2 2 2
1 0 0 0
Output
-1
Note
Let's consider the second example.
* The first sofa has 0 to its left, 2 sofas to its right ((1, 1) is to the left of both (5, 5) and (5, 4)), 0 to its top and 2 to its bottom (both 2nd and 3rd sofas are below).
* The second sofa has cntl = 2, cntr = 1, cntt = 2 and cntb = 0.
* The third sofa has cntl = 2, cntr = 1, cntt = 1 and cntb = 1.
So the second one corresponds to the given conditions.
In the third example
* The first sofa has cntl = 1, cntr = 1, cntt = 0 and cntb = 1.
* The second sofa has cntl = 1, cntr = 1, cntt = 1 and cntb = 0.
And there is no sofa with the set (1, 0, 0, 0) so the answer is -1.
Tags: brute force, implementation
Correct Solution:
```
import sys
from bisect import bisect_left, bisect_right
d = int(sys.stdin.buffer.readline().decode('utf-8'))
n, m = map(int, sys.stdin.buffer.readline().decode('utf-8').split())
a = [list(map(int, sys.stdin.buffer.readline().decode('utf-8').split()))
for _ in range(d)]
cnt = list(map(int, sys.stdin.buffer.readline().decode('utf-8').split()))
left, right, top, bottom = [], [], [], []
for x1, y1, x2, y2 in a:
left.append(min(x1, x2))
right.append(-max(x1, x2))
top.append(min(y1, y2))
bottom.append(-max(y1, y2))
left.sort()
right.sort()
top.sort()
bottom.sort()
for i, (x1, y1, x2, y2) in enumerate(a, start=1):
c = [
bisect_left(left, max(x1, x2)) - (1 if x1 != x2 else 0),
bisect_left(right, -min(x1, x2)) - (1 if x1 != x2 else 0),
bisect_left(top, max(y1, y2)) - (1 if y1 != y2 else 0),
bisect_left(bottom, -min(y1, y2)) - (1 if y1 != y2 else 0)
]
if c == cnt:
print(i)
exit()
print(-1)
```
| 8,757 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Yet another round on DecoForces is coming! Grandpa Maks wanted to participate in it but someone has stolen his precious sofa! And how can one perform well with such a major loss?
Fortunately, the thief had left a note for Grandpa Maks. This note got Maks to the sofa storehouse. Still he had no idea which sofa belongs to him as they all looked the same!
The storehouse is represented as matrix n × m. Every sofa takes two neighbouring by some side cells. No cell is covered by more than one sofa. There can be empty cells.
Sofa A is standing to the left of sofa B if there exist two such cells a and b that xa < xb, a is covered by A and b is covered by B. Sofa A is standing to the top of sofa B if there exist two such cells a and b that ya < yb, a is covered by A and b is covered by B. Right and bottom conditions are declared the same way.
Note that in all conditions A ≠ B. Also some sofa A can be both to the top of another sofa B and to the bottom of it. The same is for left and right conditions.
The note also stated that there are cntl sofas to the left of Grandpa Maks's sofa, cntr — to the right, cntt — to the top and cntb — to the bottom.
Grandpa Maks asks you to help him to identify his sofa. It is guaranteed that there is no more than one sofa of given conditions.
Output the number of Grandpa Maks's sofa. If there is no such sofa that all the conditions are met for it then output -1.
Input
The first line contains one integer number d (1 ≤ d ≤ 105) — the number of sofas in the storehouse.
The second line contains two integer numbers n, m (1 ≤ n, m ≤ 105) — the size of the storehouse.
Next d lines contains four integer numbers x1, y1, x2, y2 (1 ≤ x1, x2 ≤ n, 1 ≤ y1, y2 ≤ m) — coordinates of the i-th sofa. It is guaranteed that cells (x1, y1) and (x2, y2) have common side, (x1, y1) ≠ (x2, y2) and no cell is covered by more than one sofa.
The last line contains four integer numbers cntl, cntr, cntt, cntb (0 ≤ cntl, cntr, cntt, cntb ≤ d - 1).
Output
Print the number of the sofa for which all the conditions are met. Sofas are numbered 1 through d as given in input. If there is no such sofa then print -1.
Examples
Input
2
3 2
3 1 3 2
1 2 2 2
1 0 0 1
Output
1
Input
3
10 10
1 2 1 1
5 5 6 5
6 4 5 4
2 1 2 0
Output
2
Input
2
2 2
2 1 1 1
1 2 2 2
1 0 0 0
Output
-1
Note
Let's consider the second example.
* The first sofa has 0 to its left, 2 sofas to its right ((1, 1) is to the left of both (5, 5) and (5, 4)), 0 to its top and 2 to its bottom (both 2nd and 3rd sofas are below).
* The second sofa has cntl = 2, cntr = 1, cntt = 2 and cntb = 0.
* The third sofa has cntl = 2, cntr = 1, cntt = 1 and cntb = 1.
So the second one corresponds to the given conditions.
In the third example
* The first sofa has cntl = 1, cntr = 1, cntt = 0 and cntb = 1.
* The second sofa has cntl = 1, cntr = 1, cntt = 1 and cntb = 0.
And there is no sofa with the set (1, 0, 0, 0) so the answer is -1.
Tags: brute force, implementation
Correct Solution:
```
import sys
try:
fin=open('in')
except:
fin=sys.stdin
input=fin.readline
d = int(input())
n, m = map(int, input().split())
x1, y1, x2, y2 = [], [], [], []
T=[]
for _ in range(d):
u, v, w, x = map(int, input().split())
if u>w:u,w=w,u
if v>x:v,x=x,v
x1.append(u)
y1.append(v)
x2.append(-w)#the other direction pog?
y2.append(-x)
T.append([u,v,w,x])
x1.sort()
x2.sort()
y1.sort()
y2.sort()
req=list(map(int,input().split())) # x1,x2,y1,y2
import bisect
for i in range(len(T)):
# binary search
u,v,w,x=T[i]
if req[0]==bisect.bisect_left(x1,w)-(u!=w):
if req[1]==bisect.bisect_left(x2,-u)-(u!=w):
if req[2]==bisect.bisect_left(y1,x)-(v!=x):
if req[3]==bisect.bisect_left(y2,-v)-(v!=x):
print(i+1)
break
else:
print(-1)
```
| 8,758 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Yet another round on DecoForces is coming! Grandpa Maks wanted to participate in it but someone has stolen his precious sofa! And how can one perform well with such a major loss?
Fortunately, the thief had left a note for Grandpa Maks. This note got Maks to the sofa storehouse. Still he had no idea which sofa belongs to him as they all looked the same!
The storehouse is represented as matrix n × m. Every sofa takes two neighbouring by some side cells. No cell is covered by more than one sofa. There can be empty cells.
Sofa A is standing to the left of sofa B if there exist two such cells a and b that xa < xb, a is covered by A and b is covered by B. Sofa A is standing to the top of sofa B if there exist two such cells a and b that ya < yb, a is covered by A and b is covered by B. Right and bottom conditions are declared the same way.
Note that in all conditions A ≠ B. Also some sofa A can be both to the top of another sofa B and to the bottom of it. The same is for left and right conditions.
The note also stated that there are cntl sofas to the left of Grandpa Maks's sofa, cntr — to the right, cntt — to the top and cntb — to the bottom.
Grandpa Maks asks you to help him to identify his sofa. It is guaranteed that there is no more than one sofa of given conditions.
Output the number of Grandpa Maks's sofa. If there is no such sofa that all the conditions are met for it then output -1.
Input
The first line contains one integer number d (1 ≤ d ≤ 105) — the number of sofas in the storehouse.
The second line contains two integer numbers n, m (1 ≤ n, m ≤ 105) — the size of the storehouse.
Next d lines contains four integer numbers x1, y1, x2, y2 (1 ≤ x1, x2 ≤ n, 1 ≤ y1, y2 ≤ m) — coordinates of the i-th sofa. It is guaranteed that cells (x1, y1) and (x2, y2) have common side, (x1, y1) ≠ (x2, y2) and no cell is covered by more than one sofa.
The last line contains four integer numbers cntl, cntr, cntt, cntb (0 ≤ cntl, cntr, cntt, cntb ≤ d - 1).
Output
Print the number of the sofa for which all the conditions are met. Sofas are numbered 1 through d as given in input. If there is no such sofa then print -1.
Examples
Input
2
3 2
3 1 3 2
1 2 2 2
1 0 0 1
Output
1
Input
3
10 10
1 2 1 1
5 5 6 5
6 4 5 4
2 1 2 0
Output
2
Input
2
2 2
2 1 1 1
1 2 2 2
1 0 0 0
Output
-1
Note
Let's consider the second example.
* The first sofa has 0 to its left, 2 sofas to its right ((1, 1) is to the left of both (5, 5) and (5, 4)), 0 to its top and 2 to its bottom (both 2nd and 3rd sofas are below).
* The second sofa has cntl = 2, cntr = 1, cntt = 2 and cntb = 0.
* The third sofa has cntl = 2, cntr = 1, cntt = 1 and cntb = 1.
So the second one corresponds to the given conditions.
In the third example
* The first sofa has cntl = 1, cntr = 1, cntt = 0 and cntb = 1.
* The second sofa has cntl = 1, cntr = 1, cntt = 1 and cntb = 0.
And there is no sofa with the set (1, 0, 0, 0) so the answer is -1.
Tags: brute force, implementation
Correct Solution:
```
import sys
from collections import defaultdict as dd
from collections import deque
pl=1
from math import *
import copy
#sys.setrecursionlimit(10**6)
if pl:
input=sys.stdin.readline
def li():
return [int(xxx) for xxx in input().split()]
def fi():
return int(input())
def si():
return list(input().rstrip())
def mi():
return map(int,input().split())
d=[]
from bisect import *
from itertools import permutations
from bisect import *
f=[0 for i in range(100)]
for i in range(1,100):
if i==1:
f[i]=1
else:
f[i]=2*f[i-1]+1
#print(f[:15])
def rec(n,k):
s=[]
while n!=0:
n,r=n//k,n%k
#print(n,r)
if r<0:
r-=k
n+=1
#print(s,n,r)
s.append(r)
return s
n=fi()
p,q=mi()
pp=[]
l=[];r=[];u=[];d=[]
for i in range(n):
x1,y1,x2,y2=mi()
x1,x2=min(x1,x2),max(x1,x2)
y1,y2=min(y1,y2),max(y1,y2)
l.append(x1)
r.append(-x2)
u.append(y1)
d.append(-y2)
pp.append([x1,x2,y1,y2])
l.sort()
r.sort()
u.sort()
d.sort()
#print(l,r,u,d)
f=[[0,0,0,0] for i in range(n+1)]
for i in range(n):
f[i][0]=bisect_left(l,pp[i][1])
if pp[i][0]<pp[i][1]:
f[i][0]-=1
f[i][1]=bisect_left(r,-pp[i][0])
if pp[i][0]<pp[i][1]:
f[i][1]-=1
f[i][2]=bisect_left(u,pp[i][3])
if pp[i][2]<pp[i][3]:
f[i][2]-=1
f[i][3]=bisect_left(d,-pp[i][2])
if pp[i][2]<pp[i][3]:
f[i][3]-=1
#f[l[i][1]][0]=bisect_left(l,)
co=li()
#print(f)
for i in range(n):
if co==f[i]:
print(i+1)
exit(0)
print(-1)
```
| 8,759 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Yet another round on DecoForces is coming! Grandpa Maks wanted to participate in it but someone has stolen his precious sofa! And how can one perform well with such a major loss?
Fortunately, the thief had left a note for Grandpa Maks. This note got Maks to the sofa storehouse. Still he had no idea which sofa belongs to him as they all looked the same!
The storehouse is represented as matrix n × m. Every sofa takes two neighbouring by some side cells. No cell is covered by more than one sofa. There can be empty cells.
Sofa A is standing to the left of sofa B if there exist two such cells a and b that xa < xb, a is covered by A and b is covered by B. Sofa A is standing to the top of sofa B if there exist two such cells a and b that ya < yb, a is covered by A and b is covered by B. Right and bottom conditions are declared the same way.
Note that in all conditions A ≠ B. Also some sofa A can be both to the top of another sofa B and to the bottom of it. The same is for left and right conditions.
The note also stated that there are cntl sofas to the left of Grandpa Maks's sofa, cntr — to the right, cntt — to the top and cntb — to the bottom.
Grandpa Maks asks you to help him to identify his sofa. It is guaranteed that there is no more than one sofa of given conditions.
Output the number of Grandpa Maks's sofa. If there is no such sofa that all the conditions are met for it then output -1.
Input
The first line contains one integer number d (1 ≤ d ≤ 105) — the number of sofas in the storehouse.
The second line contains two integer numbers n, m (1 ≤ n, m ≤ 105) — the size of the storehouse.
Next d lines contains four integer numbers x1, y1, x2, y2 (1 ≤ x1, x2 ≤ n, 1 ≤ y1, y2 ≤ m) — coordinates of the i-th sofa. It is guaranteed that cells (x1, y1) and (x2, y2) have common side, (x1, y1) ≠ (x2, y2) and no cell is covered by more than one sofa.
The last line contains four integer numbers cntl, cntr, cntt, cntb (0 ≤ cntl, cntr, cntt, cntb ≤ d - 1).
Output
Print the number of the sofa for which all the conditions are met. Sofas are numbered 1 through d as given in input. If there is no such sofa then print -1.
Examples
Input
2
3 2
3 1 3 2
1 2 2 2
1 0 0 1
Output
1
Input
3
10 10
1 2 1 1
5 5 6 5
6 4 5 4
2 1 2 0
Output
2
Input
2
2 2
2 1 1 1
1 2 2 2
1 0 0 0
Output
-1
Note
Let's consider the second example.
* The first sofa has 0 to its left, 2 sofas to its right ((1, 1) is to the left of both (5, 5) and (5, 4)), 0 to its top and 2 to its bottom (both 2nd and 3rd sofas are below).
* The second sofa has cntl = 2, cntr = 1, cntt = 2 and cntb = 0.
* The third sofa has cntl = 2, cntr = 1, cntt = 1 and cntb = 1.
So the second one corresponds to the given conditions.
In the third example
* The first sofa has cntl = 1, cntr = 1, cntt = 0 and cntb = 1.
* The second sofa has cntl = 1, cntr = 1, cntt = 1 and cntb = 0.
And there is no sofa with the set (1, 0, 0, 0) so the answer is -1.
Tags: brute force, implementation
Correct Solution:
```
#!/usr/bin/env python3
from sys import exit
d = int(input().strip())
[n, m] = map(int, input().strip().split())
Hxds = [0 for _ in range(n)]
Hyds = [0 for _ in range(m)]
Vxds = [0 for _ in range(n)]
Vyds = [0 for _ in range(m)]
ds = []
for i in range(d):
x1, y1, x2, y2 = map(int, input().strip().split())
if x1 == x2:
Hxds[x1 - 1] += 1
Hyds[min(y1, y2) - 1] += 1
ds.append((x1 - 1, min(y1, y2) - 1, 'h'))
else:
Vxds[min(x1, x2) - 1] += 1
Vyds[y1 - 1] += 1
ds.append((min(x1, x2) - 1, y1 - 1, 'v'))
cl, cr, ct, cb = map(int, input().strip().split())
if (d - 1 - cl - cr) * (d - 1 - ct - cb) > 0:
print (-1)
exit()
def makeI(xs):
I = [0 for _ in range(len(xs) + 1)]
for i in range(len(xs)):
I[i + 1] = I[i] + xs[i]
return I
def find_x_Hor(IH, IV, l, cl, cr):
if cl + cr > d - 1:
return -1
x = 0
while x <= l and (IH[x] + IV[x] < cl or d - IH[x + 1] - IV[x] > cr):
x += 1
if x < l and IH[x] + IV[x] == cl and (d - IH[x + 1] - IV[x]) == cr:
return x
return -1
def find_x_Vert(IH, IV, l, cl, cr):
if cl + cr < d - 1:
return -1
x = 0
while x < l and (IH[x + 1] + IV[x + 1] < cl + 1 or d - IH[x + 1] - IV[x] > cr + 1):
x += 1
if x < l and IH[x + 1] + IV[x + 1] == cl + 1 and (d - IH[x + 1] - IV[x]) == cr + 1:
return x
return -1
IHx = makeI(Hxds)
IHy = makeI(Hyds)
IVx = makeI(Vxds)
IVy = makeI(Vyds)
if ct + cb >= d - 1 and cr + cl <= d - 1: # horizontal sofa
x = find_x_Hor(IHx, IVx, n, cl, cr)
y = find_x_Vert(IVy, IHy, m, ct, cb)
if x >= 0 and y >= 0:
if (x, y, 'h') in ds:
print(ds.index((x, y, 'h')) + 1)
exit()
if ct + cb <= d - 1 and cr + cl >= d - 1: # vertical sofa
x = find_x_Vert(IHx, IVx, n, cl, cr)
y = find_x_Hor(IVy, IHy, m, ct, cb)
if x >= 0 and y >= 0:
if (x, y, 'v') in ds:
print(ds.index((x, y, 'v')) + 1)
exit()
print (-1)
```
| 8,760 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Yet another round on DecoForces is coming! Grandpa Maks wanted to participate in it but someone has stolen his precious sofa! And how can one perform well with such a major loss?
Fortunately, the thief had left a note for Grandpa Maks. This note got Maks to the sofa storehouse. Still he had no idea which sofa belongs to him as they all looked the same!
The storehouse is represented as matrix n × m. Every sofa takes two neighbouring by some side cells. No cell is covered by more than one sofa. There can be empty cells.
Sofa A is standing to the left of sofa B if there exist two such cells a and b that xa < xb, a is covered by A and b is covered by B. Sofa A is standing to the top of sofa B if there exist two such cells a and b that ya < yb, a is covered by A and b is covered by B. Right and bottom conditions are declared the same way.
Note that in all conditions A ≠ B. Also some sofa A can be both to the top of another sofa B and to the bottom of it. The same is for left and right conditions.
The note also stated that there are cntl sofas to the left of Grandpa Maks's sofa, cntr — to the right, cntt — to the top and cntb — to the bottom.
Grandpa Maks asks you to help him to identify his sofa. It is guaranteed that there is no more than one sofa of given conditions.
Output the number of Grandpa Maks's sofa. If there is no such sofa that all the conditions are met for it then output -1.
Input
The first line contains one integer number d (1 ≤ d ≤ 105) — the number of sofas in the storehouse.
The second line contains two integer numbers n, m (1 ≤ n, m ≤ 105) — the size of the storehouse.
Next d lines contains four integer numbers x1, y1, x2, y2 (1 ≤ x1, x2 ≤ n, 1 ≤ y1, y2 ≤ m) — coordinates of the i-th sofa. It is guaranteed that cells (x1, y1) and (x2, y2) have common side, (x1, y1) ≠ (x2, y2) and no cell is covered by more than one sofa.
The last line contains four integer numbers cntl, cntr, cntt, cntb (0 ≤ cntl, cntr, cntt, cntb ≤ d - 1).
Output
Print the number of the sofa for which all the conditions are met. Sofas are numbered 1 through d as given in input. If there is no such sofa then print -1.
Examples
Input
2
3 2
3 1 3 2
1 2 2 2
1 0 0 1
Output
1
Input
3
10 10
1 2 1 1
5 5 6 5
6 4 5 4
2 1 2 0
Output
2
Input
2
2 2
2 1 1 1
1 2 2 2
1 0 0 0
Output
-1
Note
Let's consider the second example.
* The first sofa has 0 to its left, 2 sofas to its right ((1, 1) is to the left of both (5, 5) and (5, 4)), 0 to its top and 2 to its bottom (both 2nd and 3rd sofas are below).
* The second sofa has cntl = 2, cntr = 1, cntt = 2 and cntb = 0.
* The third sofa has cntl = 2, cntr = 1, cntt = 1 and cntb = 1.
So the second one corresponds to the given conditions.
In the third example
* The first sofa has cntl = 1, cntr = 1, cntt = 0 and cntb = 1.
* The second sofa has cntl = 1, cntr = 1, cntt = 1 and cntb = 0.
And there is no sofa with the set (1, 0, 0, 0) so the answer is -1.
Submitted Solution:
```
from sys import stdin, stdout
k = int(stdin.readline())
n, m = map(int, stdin.readline().split())
left, right, down, up = [], [], [], []
challengers = []
for i in range(k):
x1, y1, x2, y2 = map(int, stdin.readline().split())
if x1 == x2:
if y1 < y2:
challengers.append((x1, y1, x2, y2, i))
else:
challengers.append((x2, y2, x1, y1, i))
else:
if x1 < x2:
challengers.append((x1, y1, x2, y2, i))
else:
challengers.append((x2, y2, x1, y1, i))
left.append(challengers[-1])
right.append(challengers[-1])
up.append(challengers[-1])
down.append(challengers[-1])
left.sort(key = lambda x: (x[0], x[2]))
down.sort(key = lambda x: (x[1], x[3]))
challengers = [[], [], [], []]
cntl, cntr, cntd, cntu = map(int, stdin.readline().split())
if cntl:
for i in range(cntl, -1, -1):
if (left[i][0], left[i][2]) == (left[cntl][0], left[cntl][2]):
challengers[0].append(left[i][-1])
else:
break
for i in range(cntl + 1, k):
if (left[i][0], left[i][2]) == (left[cntl][0], left[cntl][2]):
challengers[0].append(left[i][-1])
else:
break
else:
for i in range(k):
if (left[i][0], left[i][2]) == (left[0][0], left[0][2]):
challengers[0].append(left[i][-1])
else:
break
if cntr:
for i in range(k - 1 - cntr, k):
if (left[i][0], left[i][2]) == (left[k - 1 - cntr][0], left[k - 1 - cntr][2]):
challengers[1].append(left[i][-1])
else:
break
for i in range(k - 2 - cntr, -1, -1):
if (left[i][0], left[i][2]) == (left[k - 1 - cntr][0], left[k - 1 - cntr][2]):
challengers[1].append(left[i][-1])
else:
break
else:
for i in range(k - 1, -1, -1):
if (left[i][0], left[i][2]) == (left[k - 1][0], left[k - 1][2]):
challengers[1].append(left[i][-1])
else:
break
#!!!!!!!!!!!
if cntd:
for i in range(cntd, -1, -1):
if (down[i][1], down[i][3]) == (down[cntd][1], down[cntd][3]):
challengers[2].append(down[i][-1])
else:
break
for i in range(cntd + 1, k):
if (down[i][1], down[i][3]) == (down[cntd][1], down[cntd][3]):
challengers[2].append(down[i][-1])
else:
break
else:
for i in range(k):
if (down[i][1], down[i][3]) == (down[0][1], down[0][3]):
challengers[2].append(down[i][-1])
else:
break
if cntu:
for i in range(k - 1 - cntu, k):
if (down[i][1], down[i][3]) == (down[k - 1 - cntu][1], down[k - 1 - cntu][3]):
challengers[3].append(down[i][-1])
else:
break
for i in range(k - 2 - cntu, -1, -1):
if (down[i][1], down[i][3]) == (down[k - 1 - cntu][1], down[k - 1 - cntu][3]):
challengers[3].append(down[i][-1])
else:
break
else:
for i in range(k - 1, -1, -1):
if (down[i][1], down[i][3]) == (down[k - 1][1], down[k - 1][3]):
challengers[3].append(down[i][-1])
else:
break
ans = set(challengers[0]) & set(challengers[1]) & set(challengers[2]) & set(challengers[3])
if not len(ans):
stdout.write('-1')
else:
stdout.write(str(list(ans)[0] + 1))
```
No
| 8,761 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Yet another round on DecoForces is coming! Grandpa Maks wanted to participate in it but someone has stolen his precious sofa! And how can one perform well with such a major loss?
Fortunately, the thief had left a note for Grandpa Maks. This note got Maks to the sofa storehouse. Still he had no idea which sofa belongs to him as they all looked the same!
The storehouse is represented as matrix n × m. Every sofa takes two neighbouring by some side cells. No cell is covered by more than one sofa. There can be empty cells.
Sofa A is standing to the left of sofa B if there exist two such cells a and b that xa < xb, a is covered by A and b is covered by B. Sofa A is standing to the top of sofa B if there exist two such cells a and b that ya < yb, a is covered by A and b is covered by B. Right and bottom conditions are declared the same way.
Note that in all conditions A ≠ B. Also some sofa A can be both to the top of another sofa B and to the bottom of it. The same is for left and right conditions.
The note also stated that there are cntl sofas to the left of Grandpa Maks's sofa, cntr — to the right, cntt — to the top and cntb — to the bottom.
Grandpa Maks asks you to help him to identify his sofa. It is guaranteed that there is no more than one sofa of given conditions.
Output the number of Grandpa Maks's sofa. If there is no such sofa that all the conditions are met for it then output -1.
Input
The first line contains one integer number d (1 ≤ d ≤ 105) — the number of sofas in the storehouse.
The second line contains two integer numbers n, m (1 ≤ n, m ≤ 105) — the size of the storehouse.
Next d lines contains four integer numbers x1, y1, x2, y2 (1 ≤ x1, x2 ≤ n, 1 ≤ y1, y2 ≤ m) — coordinates of the i-th sofa. It is guaranteed that cells (x1, y1) and (x2, y2) have common side, (x1, y1) ≠ (x2, y2) and no cell is covered by more than one sofa.
The last line contains four integer numbers cntl, cntr, cntt, cntb (0 ≤ cntl, cntr, cntt, cntb ≤ d - 1).
Output
Print the number of the sofa for which all the conditions are met. Sofas are numbered 1 through d as given in input. If there is no such sofa then print -1.
Examples
Input
2
3 2
3 1 3 2
1 2 2 2
1 0 0 1
Output
1
Input
3
10 10
1 2 1 1
5 5 6 5
6 4 5 4
2 1 2 0
Output
2
Input
2
2 2
2 1 1 1
1 2 2 2
1 0 0 0
Output
-1
Note
Let's consider the second example.
* The first sofa has 0 to its left, 2 sofas to its right ((1, 1) is to the left of both (5, 5) and (5, 4)), 0 to its top and 2 to its bottom (both 2nd and 3rd sofas are below).
* The second sofa has cntl = 2, cntr = 1, cntt = 2 and cntb = 0.
* The third sofa has cntl = 2, cntr = 1, cntt = 1 and cntb = 1.
So the second one corresponds to the given conditions.
In the third example
* The first sofa has cntl = 1, cntr = 1, cntt = 0 and cntb = 1.
* The second sofa has cntl = 1, cntr = 1, cntt = 1 and cntb = 0.
And there is no sofa with the set (1, 0, 0, 0) so the answer is -1.
Submitted Solution:
```
def main():
# import sys
d = int(input())
n, m = [int(x) for x in input().split()]
point = []
for x in range(d):
point.append([int(x) for x in input().split()])
point[-1].append(x+1)
q = [int(x) for x in input().split()]
def cntl(n):
# print(max(n[0],n[2]))
return min(n[0],n[2])
point.sort(key = cntl)
t = 0
debag = 0
def relax():
global debag
debag = 1
return
if(t == q[0]):
relax()
else:
id1 = 0
for i in range(len(point)-1):
if(min(point[i][0],point[i][2]) < min(point[i+1][0],point[i+1][2])):
t+=1
if(t<=q[0]):
id1 = i+1
point = point[id1:]
if(len(point)==1):
print(point[0][4])
return
# sys.exit(0)
if(t == q[1]):
relax()
else:
id1 = len(point)
for i in range(len(point)-1,0,-1):
if(max(point[i][0],point[i][2]) < max(point[i-1][0],point[i-1][2])):
t+=1
if(t<=q[0]):
id1 = i
point = point[:id1]
if(len(point)==1):
print(point[0][4])
return
def cntb(n):
return min(n[1],n[3])
point.sort(key = cntb)
if(t == q[2]):
relax()
else:
id1 = 0
for i in range(len(point)-1):
if(min(point[i][1],point[i][3]) < min(point[i+1][1],point[i+1][3])):
t+=1
if(t<=q[2]):
id1 = i+1
point = point[id1:]
if(len(point)==1):
print(point[0][4])
return
if(t == q[3]):
relax()
else:
id1 = len(point)
for i in range(len(point)-1,0,-1):
if(max(point[i][1],point[i][3]) < max(point[i-1][1],point[i-1][3])):
t+=1
if(t<=q[3]):
id1 = i
point = point[:id1]
if(len(point)!=1):
print(-1)
else:
print(point[0][4])
main()
```
No
| 8,762 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s consisting only of lowercase and uppercase Latin letters.
Let A be a set of positions in the string. Let's call it pretty if following conditions are met:
* letters on positions from A in the string are all distinct and lowercase;
* there are no uppercase letters in the string which are situated between positions from A (i.e. there is no such j that s[j] is an uppercase letter, and a1 < j < a2 for some a1 and a2 from A).
Write a program that will determine the maximum number of elements in a pretty set of positions.
Input
The first line contains a single integer n (1 ≤ n ≤ 200) — length of string s.
The second line contains a string s consisting of lowercase and uppercase Latin letters.
Output
Print maximum number of elements in pretty set of positions for string s.
Examples
Input
11
aaaaBaabAbA
Output
2
Input
12
zACaAbbaazzC
Output
3
Input
3
ABC
Output
0
Note
In the first example the desired positions might be 6 and 8 or 7 and 8. Positions 6 and 7 contain letters 'a', position 8 contains letter 'b'. The pair of positions 1 and 8 is not suitable because there is an uppercase letter 'B' between these position.
In the second example desired positions can be 7, 8 and 11. There are other ways to choose pretty set consisting of three elements.
In the third example the given string s does not contain any lowercase letters, so the answer is 0.
Tags: brute force, implementation, strings
Correct Solution:
```
n = int(input())
s = input() + 'Z'
ans = 0
lst = []
for it in s:
if 'A'<=it<='Z':
temp = len(set(lst))
ans = temp if temp>ans else ans
lst = []
else:
lst.append(it)
print(ans)
```
| 8,763 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s consisting only of lowercase and uppercase Latin letters.
Let A be a set of positions in the string. Let's call it pretty if following conditions are met:
* letters on positions from A in the string are all distinct and lowercase;
* there are no uppercase letters in the string which are situated between positions from A (i.e. there is no such j that s[j] is an uppercase letter, and a1 < j < a2 for some a1 and a2 from A).
Write a program that will determine the maximum number of elements in a pretty set of positions.
Input
The first line contains a single integer n (1 ≤ n ≤ 200) — length of string s.
The second line contains a string s consisting of lowercase and uppercase Latin letters.
Output
Print maximum number of elements in pretty set of positions for string s.
Examples
Input
11
aaaaBaabAbA
Output
2
Input
12
zACaAbbaazzC
Output
3
Input
3
ABC
Output
0
Note
In the first example the desired positions might be 6 and 8 or 7 and 8. Positions 6 and 7 contain letters 'a', position 8 contains letter 'b'. The pair of positions 1 and 8 is not suitable because there is an uppercase letter 'B' between these position.
In the second example desired positions can be 7, 8 and 11. There are other ways to choose pretty set consisting of three elements.
In the third example the given string s does not contain any lowercase letters, so the answer is 0.
Tags: brute force, implementation, strings
Correct Solution:
```
n = int(input())
s = input()
ans = 0
S = set()
for i in range(n):
if 'a' <= s[i] <= 'z':
S.add(s[i])
if len(S) > ans:
ans = len(S)
else:
S = set()
print(ans)
```
| 8,764 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s consisting only of lowercase and uppercase Latin letters.
Let A be a set of positions in the string. Let's call it pretty if following conditions are met:
* letters on positions from A in the string are all distinct and lowercase;
* there are no uppercase letters in the string which are situated between positions from A (i.e. there is no such j that s[j] is an uppercase letter, and a1 < j < a2 for some a1 and a2 from A).
Write a program that will determine the maximum number of elements in a pretty set of positions.
Input
The first line contains a single integer n (1 ≤ n ≤ 200) — length of string s.
The second line contains a string s consisting of lowercase and uppercase Latin letters.
Output
Print maximum number of elements in pretty set of positions for string s.
Examples
Input
11
aaaaBaabAbA
Output
2
Input
12
zACaAbbaazzC
Output
3
Input
3
ABC
Output
0
Note
In the first example the desired positions might be 6 and 8 or 7 and 8. Positions 6 and 7 contain letters 'a', position 8 contains letter 'b'. The pair of positions 1 and 8 is not suitable because there is an uppercase letter 'B' between these position.
In the second example desired positions can be 7, 8 and 11. There are other ways to choose pretty set consisting of three elements.
In the third example the given string s does not contain any lowercase letters, so the answer is 0.
Tags: brute force, implementation, strings
Correct Solution:
```
import re
input()
t = re.sub(r'[A-Z]', ' ', input())
print(max(len(set(s)) for s in t.split(' ')))
# Made By Mostafa_Khaled
```
| 8,765 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s consisting only of lowercase and uppercase Latin letters.
Let A be a set of positions in the string. Let's call it pretty if following conditions are met:
* letters on positions from A in the string are all distinct and lowercase;
* there are no uppercase letters in the string which are situated between positions from A (i.e. there is no such j that s[j] is an uppercase letter, and a1 < j < a2 for some a1 and a2 from A).
Write a program that will determine the maximum number of elements in a pretty set of positions.
Input
The first line contains a single integer n (1 ≤ n ≤ 200) — length of string s.
The second line contains a string s consisting of lowercase and uppercase Latin letters.
Output
Print maximum number of elements in pretty set of positions for string s.
Examples
Input
11
aaaaBaabAbA
Output
2
Input
12
zACaAbbaazzC
Output
3
Input
3
ABC
Output
0
Note
In the first example the desired positions might be 6 and 8 or 7 and 8. Positions 6 and 7 contain letters 'a', position 8 contains letter 'b'. The pair of positions 1 and 8 is not suitable because there is an uppercase letter 'B' between these position.
In the second example desired positions can be 7, 8 and 11. There are other ways to choose pretty set consisting of three elements.
In the third example the given string s does not contain any lowercase letters, so the answer is 0.
Tags: brute force, implementation, strings
Correct Solution:
```
n=int(input())
s=input()
i=0
letter=[]
num=[]
while i<n :
if s[i].islower()and letter.count(s[i])==0 :
letter.append(s[i])
if s[i].isupper()or i==n-1:
num.append(len(letter))
letter=[]
i+=1
if len(num)!=0:
print(max(num))
else :
print("0")
```
| 8,766 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s consisting only of lowercase and uppercase Latin letters.
Let A be a set of positions in the string. Let's call it pretty if following conditions are met:
* letters on positions from A in the string are all distinct and lowercase;
* there are no uppercase letters in the string which are situated between positions from A (i.e. there is no such j that s[j] is an uppercase letter, and a1 < j < a2 for some a1 and a2 from A).
Write a program that will determine the maximum number of elements in a pretty set of positions.
Input
The first line contains a single integer n (1 ≤ n ≤ 200) — length of string s.
The second line contains a string s consisting of lowercase and uppercase Latin letters.
Output
Print maximum number of elements in pretty set of positions for string s.
Examples
Input
11
aaaaBaabAbA
Output
2
Input
12
zACaAbbaazzC
Output
3
Input
3
ABC
Output
0
Note
In the first example the desired positions might be 6 and 8 or 7 and 8. Positions 6 and 7 contain letters 'a', position 8 contains letter 'b'. The pair of positions 1 and 8 is not suitable because there is an uppercase letter 'B' between these position.
In the second example desired positions can be 7, 8 and 11. There are other ways to choose pretty set consisting of three elements.
In the third example the given string s does not contain any lowercase letters, so the answer is 0.
Tags: brute force, implementation, strings
Correct Solution:
```
n = int(input())
s = input().strip()
m = set()
result =0
for i in s:
if(not i.isupper()):
m.add(i);
else:
if(len(m)>result):
result = len(m)
m.clear()
if(len(m)>result):
result = len(m)
print(result)
```
| 8,767 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s consisting only of lowercase and uppercase Latin letters.
Let A be a set of positions in the string. Let's call it pretty if following conditions are met:
* letters on positions from A in the string are all distinct and lowercase;
* there are no uppercase letters in the string which are situated between positions from A (i.e. there is no such j that s[j] is an uppercase letter, and a1 < j < a2 for some a1 and a2 from A).
Write a program that will determine the maximum number of elements in a pretty set of positions.
Input
The first line contains a single integer n (1 ≤ n ≤ 200) — length of string s.
The second line contains a string s consisting of lowercase and uppercase Latin letters.
Output
Print maximum number of elements in pretty set of positions for string s.
Examples
Input
11
aaaaBaabAbA
Output
2
Input
12
zACaAbbaazzC
Output
3
Input
3
ABC
Output
0
Note
In the first example the desired positions might be 6 and 8 or 7 and 8. Positions 6 and 7 contain letters 'a', position 8 contains letter 'b'. The pair of positions 1 and 8 is not suitable because there is an uppercase letter 'B' between these position.
In the second example desired positions can be 7, 8 and 11. There are other ways to choose pretty set consisting of three elements.
In the third example the given string s does not contain any lowercase letters, so the answer is 0.
Tags: brute force, implementation, strings
Correct Solution:
```
t=int(input())
s=input()
# print(t)
# print(s)
ms = set([])
max = 0
for i in range(t):
if s[i].islower():
ms.add(s[i])
if len(ms) > max:
max = len(ms)
else:
ms = set([])
print(max)
```
| 8,768 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s consisting only of lowercase and uppercase Latin letters.
Let A be a set of positions in the string. Let's call it pretty if following conditions are met:
* letters on positions from A in the string are all distinct and lowercase;
* there are no uppercase letters in the string which are situated between positions from A (i.e. there is no such j that s[j] is an uppercase letter, and a1 < j < a2 for some a1 and a2 from A).
Write a program that will determine the maximum number of elements in a pretty set of positions.
Input
The first line contains a single integer n (1 ≤ n ≤ 200) — length of string s.
The second line contains a string s consisting of lowercase and uppercase Latin letters.
Output
Print maximum number of elements in pretty set of positions for string s.
Examples
Input
11
aaaaBaabAbA
Output
2
Input
12
zACaAbbaazzC
Output
3
Input
3
ABC
Output
0
Note
In the first example the desired positions might be 6 and 8 or 7 and 8. Positions 6 and 7 contain letters 'a', position 8 contains letter 'b'. The pair of positions 1 and 8 is not suitable because there is an uppercase letter 'B' between these position.
In the second example desired positions can be 7, 8 and 11. There are other ways to choose pretty set consisting of three elements.
In the third example the given string s does not contain any lowercase letters, so the answer is 0.
Tags: brute force, implementation, strings
Correct Solution:
```
#!/usr/bin/env python
def main():
_ = int(input())
ssplit = ''
for c in input():
ssplit += '0' if c.isupper() else c
res = max([len(set(sset)) for sset in ssplit.split('0')])
print(res)
if __name__ == '__main__':
main()
```
| 8,769 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s consisting only of lowercase and uppercase Latin letters.
Let A be a set of positions in the string. Let's call it pretty if following conditions are met:
* letters on positions from A in the string are all distinct and lowercase;
* there are no uppercase letters in the string which are situated between positions from A (i.e. there is no such j that s[j] is an uppercase letter, and a1 < j < a2 for some a1 and a2 from A).
Write a program that will determine the maximum number of elements in a pretty set of positions.
Input
The first line contains a single integer n (1 ≤ n ≤ 200) — length of string s.
The second line contains a string s consisting of lowercase and uppercase Latin letters.
Output
Print maximum number of elements in pretty set of positions for string s.
Examples
Input
11
aaaaBaabAbA
Output
2
Input
12
zACaAbbaazzC
Output
3
Input
3
ABC
Output
0
Note
In the first example the desired positions might be 6 and 8 or 7 and 8. Positions 6 and 7 contain letters 'a', position 8 contains letter 'b'. The pair of positions 1 and 8 is not suitable because there is an uppercase letter 'B' between these position.
In the second example desired positions can be 7, 8 and 11. There are other ways to choose pretty set consisting of three elements.
In the third example the given string s does not contain any lowercase letters, so the answer is 0.
Tags: brute force, implementation, strings
Correct Solution:
```
n=int(input())
s=input()
f=0
cnt=''
c=mx=0
for i in range(n):
if s[i].isupper():
f=0
mx=max(mx,c)
c=0
cnt=''
else:
f=1
if s[i] not in cnt:
cnt+=s[i]
c+=1
if f==1:
mx=max(mx,c)
print(mx)
```
| 8,770 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s consisting only of lowercase and uppercase Latin letters.
Let A be a set of positions in the string. Let's call it pretty if following conditions are met:
* letters on positions from A in the string are all distinct and lowercase;
* there are no uppercase letters in the string which are situated between positions from A (i.e. there is no such j that s[j] is an uppercase letter, and a1 < j < a2 for some a1 and a2 from A).
Write a program that will determine the maximum number of elements in a pretty set of positions.
Input
The first line contains a single integer n (1 ≤ n ≤ 200) — length of string s.
The second line contains a string s consisting of lowercase and uppercase Latin letters.
Output
Print maximum number of elements in pretty set of positions for string s.
Examples
Input
11
aaaaBaabAbA
Output
2
Input
12
zACaAbbaazzC
Output
3
Input
3
ABC
Output
0
Note
In the first example the desired positions might be 6 and 8 or 7 and 8. Positions 6 and 7 contain letters 'a', position 8 contains letter 'b'. The pair of positions 1 and 8 is not suitable because there is an uppercase letter 'B' between these position.
In the second example desired positions can be 7, 8 and 11. There are other ways to choose pretty set consisting of three elements.
In the third example the given string s does not contain any lowercase letters, so the answer is 0.
Submitted Solution:
```
small="abcdefghijklmnopqrstuvwxyz"
big="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
n=int(input())
s=list(input())
q=[]
f=0
for i in range(n):
r = set()
if s[i] in big:
if i-f>0:
for j in s[f:i]:
r.add(j)
q.append(len(r))
f=i+1
elif i==n-1:
for j in s[f:i+1]:
r.add(j)
q.append(len(r))
if len(q)==0:
print(0)
else:
print(max(q))
```
Yes
| 8,771 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s consisting only of lowercase and uppercase Latin letters.
Let A be a set of positions in the string. Let's call it pretty if following conditions are met:
* letters on positions from A in the string are all distinct and lowercase;
* there are no uppercase letters in the string which are situated between positions from A (i.e. there is no such j that s[j] is an uppercase letter, and a1 < j < a2 for some a1 and a2 from A).
Write a program that will determine the maximum number of elements in a pretty set of positions.
Input
The first line contains a single integer n (1 ≤ n ≤ 200) — length of string s.
The second line contains a string s consisting of lowercase and uppercase Latin letters.
Output
Print maximum number of elements in pretty set of positions for string s.
Examples
Input
11
aaaaBaabAbA
Output
2
Input
12
zACaAbbaazzC
Output
3
Input
3
ABC
Output
0
Note
In the first example the desired positions might be 6 and 8 or 7 and 8. Positions 6 and 7 contain letters 'a', position 8 contains letter 'b'. The pair of positions 1 and 8 is not suitable because there is an uppercase letter 'B' between these position.
In the second example desired positions can be 7, 8 and 11. There are other ways to choose pretty set consisting of three elements.
In the third example the given string s does not contain any lowercase letters, so the answer is 0.
Submitted Solution:
```
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
n = int(input())
l = []
s = input()
init = 0
for i in range(n):
if s[i].isupper():
l.append(s[init:i])
init = i + 1
l.append(s[init:])
l1 = [len(set(x)) for x in l]
print(max(l1))
```
Yes
| 8,772 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s consisting only of lowercase and uppercase Latin letters.
Let A be a set of positions in the string. Let's call it pretty if following conditions are met:
* letters on positions from A in the string are all distinct and lowercase;
* there are no uppercase letters in the string which are situated between positions from A (i.e. there is no such j that s[j] is an uppercase letter, and a1 < j < a2 for some a1 and a2 from A).
Write a program that will determine the maximum number of elements in a pretty set of positions.
Input
The first line contains a single integer n (1 ≤ n ≤ 200) — length of string s.
The second line contains a string s consisting of lowercase and uppercase Latin letters.
Output
Print maximum number of elements in pretty set of positions for string s.
Examples
Input
11
aaaaBaabAbA
Output
2
Input
12
zACaAbbaazzC
Output
3
Input
3
ABC
Output
0
Note
In the first example the desired positions might be 6 and 8 or 7 and 8. Positions 6 and 7 contain letters 'a', position 8 contains letter 'b'. The pair of positions 1 and 8 is not suitable because there is an uppercase letter 'B' between these position.
In the second example desired positions can be 7, 8 and 11. There are other ways to choose pretty set consisting of three elements.
In the third example the given string s does not contain any lowercase letters, so the answer is 0.
Submitted Solution:
```
n , ans = int(input()) , 0
var = input()
chars = set()
for i in var:
if i >= 'a' and i <= 'z':
chars.add(i)
else:
ans = max(ans , len(chars))
chars = set()
ans = max(ans , len(chars))
print(ans)
```
Yes
| 8,773 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s consisting only of lowercase and uppercase Latin letters.
Let A be a set of positions in the string. Let's call it pretty if following conditions are met:
* letters on positions from A in the string are all distinct and lowercase;
* there are no uppercase letters in the string which are situated between positions from A (i.e. there is no such j that s[j] is an uppercase letter, and a1 < j < a2 for some a1 and a2 from A).
Write a program that will determine the maximum number of elements in a pretty set of positions.
Input
The first line contains a single integer n (1 ≤ n ≤ 200) — length of string s.
The second line contains a string s consisting of lowercase and uppercase Latin letters.
Output
Print maximum number of elements in pretty set of positions for string s.
Examples
Input
11
aaaaBaabAbA
Output
2
Input
12
zACaAbbaazzC
Output
3
Input
3
ABC
Output
0
Note
In the first example the desired positions might be 6 and 8 or 7 and 8. Positions 6 and 7 contain letters 'a', position 8 contains letter 'b'. The pair of positions 1 and 8 is not suitable because there is an uppercase letter 'B' between these position.
In the second example desired positions can be 7, 8 and 11. There are other ways to choose pretty set consisting of three elements.
In the third example the given string s does not contain any lowercase letters, so the answer is 0.
Submitted Solution:
```
import re
n=int(input())
s=input()
ans=0
for c in re.split('[A-Z]',s):
if len(c)>0:
ans=max(ans,len(set(c)))
print(ans)
```
Yes
| 8,774 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s consisting only of lowercase and uppercase Latin letters.
Let A be a set of positions in the string. Let's call it pretty if following conditions are met:
* letters on positions from A in the string are all distinct and lowercase;
* there are no uppercase letters in the string which are situated between positions from A (i.e. there is no such j that s[j] is an uppercase letter, and a1 < j < a2 for some a1 and a2 from A).
Write a program that will determine the maximum number of elements in a pretty set of positions.
Input
The first line contains a single integer n (1 ≤ n ≤ 200) — length of string s.
The second line contains a string s consisting of lowercase and uppercase Latin letters.
Output
Print maximum number of elements in pretty set of positions for string s.
Examples
Input
11
aaaaBaabAbA
Output
2
Input
12
zACaAbbaazzC
Output
3
Input
3
ABC
Output
0
Note
In the first example the desired positions might be 6 and 8 or 7 and 8. Positions 6 and 7 contain letters 'a', position 8 contains letter 'b'. The pair of positions 1 and 8 is not suitable because there is an uppercase letter 'B' between these position.
In the second example desired positions can be 7, 8 and 11. There are other ways to choose pretty set consisting of three elements.
In the third example the given string s does not contain any lowercase letters, so the answer is 0.
Submitted Solution:
```
#864B
n = int(input())
s = input()
parts = []
i = 0
string = ""
while i < len(s):
if s[i].islower():
string += s[i]
else:
parts.append(string)
string = ""
i += 1
m = 0
for j in parts:
j = set(j)
m = max(len(j),m)
print(m)
```
No
| 8,775 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s consisting only of lowercase and uppercase Latin letters.
Let A be a set of positions in the string. Let's call it pretty if following conditions are met:
* letters on positions from A in the string are all distinct and lowercase;
* there are no uppercase letters in the string which are situated between positions from A (i.e. there is no such j that s[j] is an uppercase letter, and a1 < j < a2 for some a1 and a2 from A).
Write a program that will determine the maximum number of elements in a pretty set of positions.
Input
The first line contains a single integer n (1 ≤ n ≤ 200) — length of string s.
The second line contains a string s consisting of lowercase and uppercase Latin letters.
Output
Print maximum number of elements in pretty set of positions for string s.
Examples
Input
11
aaaaBaabAbA
Output
2
Input
12
zACaAbbaazzC
Output
3
Input
3
ABC
Output
0
Note
In the first example the desired positions might be 6 and 8 or 7 and 8. Positions 6 and 7 contain letters 'a', position 8 contains letter 'b'. The pair of positions 1 and 8 is not suitable because there is an uppercase letter 'B' between these position.
In the second example desired positions can be 7, 8 and 11. There are other ways to choose pretty set consisting of three elements.
In the third example the given string s does not contain any lowercase letters, so the answer is 0.
Submitted Solution:
```
cute = input()
posl = []
temp = str()
for i in cute:
if i.isupper():
if temp != '':
posl.append(temp)
temp = ''
else:
temp = temp + i
maxlen = 0
for i in range(len(posl)):
posl[i] = ''.join(set(posl[i]))
if len(posl[i]) > maxlen:
maxlen = len(posl[i])
print(maxlen)
```
No
| 8,776 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s consisting only of lowercase and uppercase Latin letters.
Let A be a set of positions in the string. Let's call it pretty if following conditions are met:
* letters on positions from A in the string are all distinct and lowercase;
* there are no uppercase letters in the string which are situated between positions from A (i.e. there is no such j that s[j] is an uppercase letter, and a1 < j < a2 for some a1 and a2 from A).
Write a program that will determine the maximum number of elements in a pretty set of positions.
Input
The first line contains a single integer n (1 ≤ n ≤ 200) — length of string s.
The second line contains a string s consisting of lowercase and uppercase Latin letters.
Output
Print maximum number of elements in pretty set of positions for string s.
Examples
Input
11
aaaaBaabAbA
Output
2
Input
12
zACaAbbaazzC
Output
3
Input
3
ABC
Output
0
Note
In the first example the desired positions might be 6 and 8 or 7 and 8. Positions 6 and 7 contain letters 'a', position 8 contains letter 'b'. The pair of positions 1 and 8 is not suitable because there is an uppercase letter 'B' between these position.
In the second example desired positions can be 7, 8 and 11. There are other ways to choose pretty set consisting of three elements.
In the third example the given string s does not contain any lowercase letters, so the answer is 0.
Submitted Solution:
```
n=int(input())
s=input()
ss=set()
b=0
for i in range(n):
if s[i]>="a" and s[i]<="z":
ss.add(s[i])
else:
b=max(b,len(ss))
ss=set()
print(b)
```
No
| 8,777 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s consisting only of lowercase and uppercase Latin letters.
Let A be a set of positions in the string. Let's call it pretty if following conditions are met:
* letters on positions from A in the string are all distinct and lowercase;
* there are no uppercase letters in the string which are situated between positions from A (i.e. there is no such j that s[j] is an uppercase letter, and a1 < j < a2 for some a1 and a2 from A).
Write a program that will determine the maximum number of elements in a pretty set of positions.
Input
The first line contains a single integer n (1 ≤ n ≤ 200) — length of string s.
The second line contains a string s consisting of lowercase and uppercase Latin letters.
Output
Print maximum number of elements in pretty set of positions for string s.
Examples
Input
11
aaaaBaabAbA
Output
2
Input
12
zACaAbbaazzC
Output
3
Input
3
ABC
Output
0
Note
In the first example the desired positions might be 6 and 8 or 7 and 8. Positions 6 and 7 contain letters 'a', position 8 contains letter 'b'. The pair of positions 1 and 8 is not suitable because there is an uppercase letter 'B' between these position.
In the second example desired positions can be 7, 8 and 11. There are other ways to choose pretty set consisting of three elements.
In the third example the given string s does not contain any lowercase letters, so the answer is 0.
Submitted Solution:
```
alphabet = 'abcdefghijklmnopqrstuvwxyz'
alphabet_h = alphabet.upper()
alpha = tuple(alphabet)
alpha_h = tuple(alphabet_h)
n = int(input())
s = str(input())
g = 0
i = 1
for j in range(n):
if s[j] in alpha:
g = g + 1
if g != n:
g = 0
while i <= n-1:
if s[i-1] in alpha:
while i <= n-1 and s[i] in alpha_h:
# print(s[i], i)
g = g + 1
i = i + 1
# print(i)
if i>= n-1 or s[i] in alpha:
break
i = i + 1
i = n - 1
if s[n-1] in alpha_h and g > 0:
while s[i] in alpha_h and i>=0:
g = g - 1
i = i - 1
print(g)
```
No
| 8,778 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya studies music.
He has learned lots of interesting stuff. For example, he knows that there are 12 notes: C, C#, D, D#, E, F, F#, G, G#, A, B, H. He also knows that the notes are repeated cyclically: after H goes C again, and before C stands H. We will consider the C note in the row's beginning and the C note after the H similar and we will identify them with each other. The distance between the notes along the musical scale is measured in tones: between two consecutive notes there's exactly one semitone, that is, 0.5 tone. The distance is taken from the lowest tone to the uppest one, that is, the distance between C and E is 4 semitones and between E and C is 8 semitones
Vasya also knows what a chord is. A chord is an unordered set of no less than three notes. However, for now Vasya only works with triads, that is with the chords that consist of exactly three notes. He can already distinguish between two types of triads — major and minor.
Let's define a major triad. Let the triad consist of notes X, Y and Z. If we can order the notes so as the distance along the musical scale between X and Y equals 4 semitones and the distance between Y and Z is 3 semitones, then the triad is major. The distance between X and Z, accordingly, equals 7 semitones.
A minor triad is different in that the distance between X and Y should be 3 semitones and between Y and Z — 4 semitones.
For example, the triad "C E G" is major: between C and E are 4 semitones, and between E and G are 3 semitones. And the triplet "C# B F" is minor, because if we order the notes as "B C# F", than between B and C# will be 3 semitones, and between C# and F — 4 semitones.
Help Vasya classify the triad the teacher has given to him.
Input
The only line contains 3 space-separated notes in the above-given notation.
Output
Print "major" if the chord is major, "minor" if it is minor, and "strange" if the teacher gave Vasya some weird chord which is neither major nor minor. Vasya promises you that the answer will always be unambiguous. That is, there are no chords that are both major and minor simultaneously.
Examples
Input
C E G
Output
major
Input
C# B F
Output
minor
Input
A B H
Output
strange
Tags: brute force, implementation
Correct Solution:
```
import itertools
tone = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "B", "H"]
num = itertools.permutations(input().split())
for arr in num:
a, b, c = arr
ind_a = tone.index(a)
ind_b = tone.index(b)
ind_c = tone.index(c)
ind_a = ind_a if ind_a < 12 else 12 + ind_a
ind_b = ind_b if ind_b > ind_a else 12 + ind_b
ind_c = ind_c if ind_c > ind_b else 12 + ind_c
if ind_b - ind_a == 4 and ind_c - ind_b == 3:
print("major")
break
elif ind_b - ind_a == 3 and ind_c - ind_b == 4:
print("minor")
break
else:
print("strange")
```
| 8,779 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya studies music.
He has learned lots of interesting stuff. For example, he knows that there are 12 notes: C, C#, D, D#, E, F, F#, G, G#, A, B, H. He also knows that the notes are repeated cyclically: after H goes C again, and before C stands H. We will consider the C note in the row's beginning and the C note after the H similar and we will identify them with each other. The distance between the notes along the musical scale is measured in tones: between two consecutive notes there's exactly one semitone, that is, 0.5 tone. The distance is taken from the lowest tone to the uppest one, that is, the distance between C and E is 4 semitones and between E and C is 8 semitones
Vasya also knows what a chord is. A chord is an unordered set of no less than three notes. However, for now Vasya only works with triads, that is with the chords that consist of exactly three notes. He can already distinguish between two types of triads — major and minor.
Let's define a major triad. Let the triad consist of notes X, Y and Z. If we can order the notes so as the distance along the musical scale between X and Y equals 4 semitones and the distance between Y and Z is 3 semitones, then the triad is major. The distance between X and Z, accordingly, equals 7 semitones.
A minor triad is different in that the distance between X and Y should be 3 semitones and between Y and Z — 4 semitones.
For example, the triad "C E G" is major: between C and E are 4 semitones, and between E and G are 3 semitones. And the triplet "C# B F" is minor, because if we order the notes as "B C# F", than between B and C# will be 3 semitones, and between C# and F — 4 semitones.
Help Vasya classify the triad the teacher has given to him.
Input
The only line contains 3 space-separated notes in the above-given notation.
Output
Print "major" if the chord is major, "minor" if it is minor, and "strange" if the teacher gave Vasya some weird chord which is neither major nor minor. Vasya promises you that the answer will always be unambiguous. That is, there are no chords that are both major and minor simultaneously.
Examples
Input
C E G
Output
major
Input
C# B F
Output
minor
Input
A B H
Output
strange
Tags: brute force, implementation
Correct Solution:
```
def kind(a,b,c):
if a==4 and b==3:
return "major"
if a==3 and b==4:
return "minor"
if b==4 and c==3:
return "major"
if b==3 and c==4:
return "minor"
if c==4 and a==3:
return "major"
if c==3 and a==4:
return "minor"
return "strange"
note = [n for n in "C,C#,D,D#,E,F,F#,G,G#,A,B,H".split(',')]
d={}
for n in range(12):
d[note[n]]=n
tri = [d[i] for i in input().split()]
tri.sort()
d1 = tri[1]-tri[0]
d2 = tri[2]-tri[1]
d3 = 12 - tri[2]+tri[0]
print(kind(d1,d2,d3))
```
| 8,780 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya studies music.
He has learned lots of interesting stuff. For example, he knows that there are 12 notes: C, C#, D, D#, E, F, F#, G, G#, A, B, H. He also knows that the notes are repeated cyclically: after H goes C again, and before C stands H. We will consider the C note in the row's beginning and the C note after the H similar and we will identify them with each other. The distance between the notes along the musical scale is measured in tones: between two consecutive notes there's exactly one semitone, that is, 0.5 tone. The distance is taken from the lowest tone to the uppest one, that is, the distance between C and E is 4 semitones and between E and C is 8 semitones
Vasya also knows what a chord is. A chord is an unordered set of no less than three notes. However, for now Vasya only works with triads, that is with the chords that consist of exactly three notes. He can already distinguish between two types of triads — major and minor.
Let's define a major triad. Let the triad consist of notes X, Y and Z. If we can order the notes so as the distance along the musical scale between X and Y equals 4 semitones and the distance between Y and Z is 3 semitones, then the triad is major. The distance between X and Z, accordingly, equals 7 semitones.
A minor triad is different in that the distance between X and Y should be 3 semitones and between Y and Z — 4 semitones.
For example, the triad "C E G" is major: between C and E are 4 semitones, and between E and G are 3 semitones. And the triplet "C# B F" is minor, because if we order the notes as "B C# F", than between B and C# will be 3 semitones, and between C# and F — 4 semitones.
Help Vasya classify the triad the teacher has given to him.
Input
The only line contains 3 space-separated notes in the above-given notation.
Output
Print "major" if the chord is major, "minor" if it is minor, and "strange" if the teacher gave Vasya some weird chord which is neither major nor minor. Vasya promises you that the answer will always be unambiguous. That is, there are no chords that are both major and minor simultaneously.
Examples
Input
C E G
Output
major
Input
C# B F
Output
minor
Input
A B H
Output
strange
Tags: brute force, implementation
Correct Solution:
```
import itertools
def diff(a):
d = []
for i, j in list(itertools.combinations(range(3), 2)):
c = abs(a[j]-a[i])
d.append(c)
d.append(12-c)
return d
s = input().split()
note = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "B", "H"]
minor = [[3, 9, 7, 5, 4, 8], [5, 7, 8, 4, 3, 9], [4, 8, 9, 3, 5, 7]]
major = [[4, 8, 7, 5, 3, 9], [5, 7, 9, 3, 4, 8], [3, 9, 8, 4, 5, 7]]
l = [note.index(n) for n in s]
l.sort()
ans = diff(l)
# print(ans)
if ans in major:
print("major")
elif ans in minor:
print("minor")
else :
print("strange")
```
| 8,781 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya studies music.
He has learned lots of interesting stuff. For example, he knows that there are 12 notes: C, C#, D, D#, E, F, F#, G, G#, A, B, H. He also knows that the notes are repeated cyclically: after H goes C again, and before C stands H. We will consider the C note in the row's beginning and the C note after the H similar and we will identify them with each other. The distance between the notes along the musical scale is measured in tones: between two consecutive notes there's exactly one semitone, that is, 0.5 tone. The distance is taken from the lowest tone to the uppest one, that is, the distance between C and E is 4 semitones and between E and C is 8 semitones
Vasya also knows what a chord is. A chord is an unordered set of no less than three notes. However, for now Vasya only works with triads, that is with the chords that consist of exactly three notes. He can already distinguish between two types of triads — major and minor.
Let's define a major triad. Let the triad consist of notes X, Y and Z. If we can order the notes so as the distance along the musical scale between X and Y equals 4 semitones and the distance between Y and Z is 3 semitones, then the triad is major. The distance between X and Z, accordingly, equals 7 semitones.
A minor triad is different in that the distance between X and Y should be 3 semitones and between Y and Z — 4 semitones.
For example, the triad "C E G" is major: between C and E are 4 semitones, and between E and G are 3 semitones. And the triplet "C# B F" is minor, because if we order the notes as "B C# F", than between B and C# will be 3 semitones, and between C# and F — 4 semitones.
Help Vasya classify the triad the teacher has given to him.
Input
The only line contains 3 space-separated notes in the above-given notation.
Output
Print "major" if the chord is major, "minor" if it is minor, and "strange" if the teacher gave Vasya some weird chord which is neither major nor minor. Vasya promises you that the answer will always be unambiguous. That is, there are no chords that are both major and minor simultaneously.
Examples
Input
C E G
Output
major
Input
C# B F
Output
minor
Input
A B H
Output
strange
Tags: brute force, implementation
Correct Solution:
```
# python 3
"""
"""
from itertools import permutations
def note_dist(note_1, note_2):
notes_dict = {'C': 0, 'C#': 1, 'D': 2, 'D#': 3, 'E': 4, 'F': 5,
'F#': 6, 'G': 7, 'G#': 8, 'A': 9, 'B': 10, 'H': 11}
if notes_dict[note_2] > notes_dict[note_1]:
return notes_dict[note_2] - notes_dict[note_1]
else:
return notes_dict[note_2] + len(notes_dict) - notes_dict[note_1]
def chord(three_notes_list) -> str:
# print(note_dist('B', 'C#'))
# print(note_dist('C#', 'F'))
# for 3-note list, there will be 6 permutations
for each in permutations(three_notes_list):
# print(each)
dist = (note_dist(each[0], each[1]), note_dist(each[1], each[2]))
if dist == (3, 4):
return "minor"
elif dist == (4, 3):
return "major"
else:
continue
return "strange"
if __name__ == "__main__":
"""
Inside of this is the test.
Outside is the API
"""
three_notes = list(input().split())
# print(three_notes)
print(chord(three_notes))
```
| 8,782 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya studies music.
He has learned lots of interesting stuff. For example, he knows that there are 12 notes: C, C#, D, D#, E, F, F#, G, G#, A, B, H. He also knows that the notes are repeated cyclically: after H goes C again, and before C stands H. We will consider the C note in the row's beginning and the C note after the H similar and we will identify them with each other. The distance between the notes along the musical scale is measured in tones: between two consecutive notes there's exactly one semitone, that is, 0.5 tone. The distance is taken from the lowest tone to the uppest one, that is, the distance between C and E is 4 semitones and between E and C is 8 semitones
Vasya also knows what a chord is. A chord is an unordered set of no less than three notes. However, for now Vasya only works with triads, that is with the chords that consist of exactly three notes. He can already distinguish between two types of triads — major and minor.
Let's define a major triad. Let the triad consist of notes X, Y and Z. If we can order the notes so as the distance along the musical scale between X and Y equals 4 semitones and the distance between Y and Z is 3 semitones, then the triad is major. The distance between X and Z, accordingly, equals 7 semitones.
A minor triad is different in that the distance between X and Y should be 3 semitones and between Y and Z — 4 semitones.
For example, the triad "C E G" is major: between C and E are 4 semitones, and between E and G are 3 semitones. And the triplet "C# B F" is minor, because if we order the notes as "B C# F", than between B and C# will be 3 semitones, and between C# and F — 4 semitones.
Help Vasya classify the triad the teacher has given to him.
Input
The only line contains 3 space-separated notes in the above-given notation.
Output
Print "major" if the chord is major, "minor" if it is minor, and "strange" if the teacher gave Vasya some weird chord which is neither major nor minor. Vasya promises you that the answer will always be unambiguous. That is, there are no chords that are both major and minor simultaneously.
Examples
Input
C E G
Output
major
Input
C# B F
Output
minor
Input
A B H
Output
strange
Tags: brute force, implementation
Correct Solution:
```
def tipo_acorde(nota1, nota2, nota3):
if (((nota1 + 4)%12 == nota2 and (nota2 + 3)%12 == nota3) or
((nota1 + 4)%12 == nota3 and (nota3 + 3)%12 == nota2)):
return 'major'
elif (((nota1 + 3)%12 == nota2 and (nota2 + 4)%12 == nota3) or
((nota1 + 3)%12 == nota3 and (nota3 + 4)%12 == nota2)):
return 'minor'
else:
return 'strange'
escala_musical = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'B', 'H']
nota = input().split()
ubicacion_nota = []
for i in range(3):
j = 0
encontrado = False
while j<12 and (not encontrado):
if nota[i] == escala_musical[j]:
ubicacion_nota.append(j)
encontrado = True
j = j+1
acorde = 'strange'
i = 0
while i<3 and acorde == 'strange':
intento_acorde = tipo_acorde(ubicacion_nota[i], ubicacion_nota[(i+1)%3], ubicacion_nota[(i+2)%3])
if intento_acorde != 'strange':
acorde = intento_acorde
i = i+1
print(acorde)
```
| 8,783 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya studies music.
He has learned lots of interesting stuff. For example, he knows that there are 12 notes: C, C#, D, D#, E, F, F#, G, G#, A, B, H. He also knows that the notes are repeated cyclically: after H goes C again, and before C stands H. We will consider the C note in the row's beginning and the C note after the H similar and we will identify them with each other. The distance between the notes along the musical scale is measured in tones: between two consecutive notes there's exactly one semitone, that is, 0.5 tone. The distance is taken from the lowest tone to the uppest one, that is, the distance between C and E is 4 semitones and between E and C is 8 semitones
Vasya also knows what a chord is. A chord is an unordered set of no less than three notes. However, for now Vasya only works with triads, that is with the chords that consist of exactly three notes. He can already distinguish between two types of triads — major and minor.
Let's define a major triad. Let the triad consist of notes X, Y and Z. If we can order the notes so as the distance along the musical scale between X and Y equals 4 semitones and the distance between Y and Z is 3 semitones, then the triad is major. The distance between X and Z, accordingly, equals 7 semitones.
A minor triad is different in that the distance between X and Y should be 3 semitones and between Y and Z — 4 semitones.
For example, the triad "C E G" is major: between C and E are 4 semitones, and between E and G are 3 semitones. And the triplet "C# B F" is minor, because if we order the notes as "B C# F", than between B and C# will be 3 semitones, and between C# and F — 4 semitones.
Help Vasya classify the triad the teacher has given to him.
Input
The only line contains 3 space-separated notes in the above-given notation.
Output
Print "major" if the chord is major, "minor" if it is minor, and "strange" if the teacher gave Vasya some weird chord which is neither major nor minor. Vasya promises you that the answer will always be unambiguous. That is, there are no chords that are both major and minor simultaneously.
Examples
Input
C E G
Output
major
Input
C# B F
Output
minor
Input
A B H
Output
strange
Tags: brute force, implementation
Correct Solution:
```
a = input().split(" ")
order = {
"C": 0,
"C#": 1,
"D": 2,
"D#": 3,
"E": 4,
"F": 5,
"F#": 6,
"G": 7,
"G#": 8,
"A": 9,
"B": 10,
"H": 11
}
def diff(a, b):
if (order[a] - order[b]) > 0:
return order[a] - order[b]
else:
return 12 + (order[a] - order[b])
flag = False
for i in range(3):
b = a
temp = a[i]
a[i] = a[0]
a[0] = temp
for j in range(2):
if (diff(a[1], a[0]) == 4 and diff(a[2], a[1]) == 3):
print("major")
flag = True
break
if (diff(a[1], a[0]) == 3 and diff(a[2], a[1]) == 4):
print("minor")
flag = True
break
temp = a[1]
a[1] = a[2]
a[2] = temp
if (flag == False):
print("strange")
```
| 8,784 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya studies music.
He has learned lots of interesting stuff. For example, he knows that there are 12 notes: C, C#, D, D#, E, F, F#, G, G#, A, B, H. He also knows that the notes are repeated cyclically: after H goes C again, and before C stands H. We will consider the C note in the row's beginning and the C note after the H similar and we will identify them with each other. The distance between the notes along the musical scale is measured in tones: between two consecutive notes there's exactly one semitone, that is, 0.5 tone. The distance is taken from the lowest tone to the uppest one, that is, the distance between C and E is 4 semitones and between E and C is 8 semitones
Vasya also knows what a chord is. A chord is an unordered set of no less than three notes. However, for now Vasya only works with triads, that is with the chords that consist of exactly three notes. He can already distinguish between two types of triads — major and minor.
Let's define a major triad. Let the triad consist of notes X, Y and Z. If we can order the notes so as the distance along the musical scale between X and Y equals 4 semitones and the distance between Y and Z is 3 semitones, then the triad is major. The distance between X and Z, accordingly, equals 7 semitones.
A minor triad is different in that the distance between X and Y should be 3 semitones and between Y and Z — 4 semitones.
For example, the triad "C E G" is major: between C and E are 4 semitones, and between E and G are 3 semitones. And the triplet "C# B F" is minor, because if we order the notes as "B C# F", than between B and C# will be 3 semitones, and between C# and F — 4 semitones.
Help Vasya classify the triad the teacher has given to him.
Input
The only line contains 3 space-separated notes in the above-given notation.
Output
Print "major" if the chord is major, "minor" if it is minor, and "strange" if the teacher gave Vasya some weird chord which is neither major nor minor. Vasya promises you that the answer will always be unambiguous. That is, there are no chords that are both major and minor simultaneously.
Examples
Input
C E G
Output
major
Input
C# B F
Output
minor
Input
A B H
Output
strange
Tags: brute force, implementation
Correct Solution:
```
# Problem: 88A
# Time Created: August 10(Monday) 2020 || 11:37:58
#>-------------------------<#
import sys
input = sys.stdin.readline
#>-------------------------<#
from itertools import permutations
# Helper Functions. -> Don't cluster your code.
def check_chord(tup):
notes = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'B', 'H']
notes += notes
x, y, z = tup
x_y = 0
y_z = 0
for i in range(notes.index(x), len(notes)):
if notes[i] == y: break
else: x_y += 1
for i in range(notes.index(y), len(notes)):
if notes[i] == z: break
else: y_z += 1
if x_y == 4 and y_z == 3: return "major"
elif x_y == 3 and y_z == 4: return "minor"
else: return "strange"
# IO Functions. -> Input output
def io():
x, y, z = map(str, input().split())
perms = permutations([x,y,z])
return list(perms)
# Main functions. -> Write the main solution here
def solve():
perms = io()
ans = 'strange'
for perm in perms:
chord = check_chord(perm)
if chord != 'strange':
ans = chord
break
print(ans)
# Multiple test cases. -> When you have T test cases.
solve()
```
| 8,785 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya studies music.
He has learned lots of interesting stuff. For example, he knows that there are 12 notes: C, C#, D, D#, E, F, F#, G, G#, A, B, H. He also knows that the notes are repeated cyclically: after H goes C again, and before C stands H. We will consider the C note in the row's beginning and the C note after the H similar and we will identify them with each other. The distance between the notes along the musical scale is measured in tones: between two consecutive notes there's exactly one semitone, that is, 0.5 tone. The distance is taken from the lowest tone to the uppest one, that is, the distance between C and E is 4 semitones and between E and C is 8 semitones
Vasya also knows what a chord is. A chord is an unordered set of no less than three notes. However, for now Vasya only works with triads, that is with the chords that consist of exactly three notes. He can already distinguish between two types of triads — major and minor.
Let's define a major triad. Let the triad consist of notes X, Y and Z. If we can order the notes so as the distance along the musical scale between X and Y equals 4 semitones and the distance between Y and Z is 3 semitones, then the triad is major. The distance between X and Z, accordingly, equals 7 semitones.
A minor triad is different in that the distance between X and Y should be 3 semitones and between Y and Z — 4 semitones.
For example, the triad "C E G" is major: between C and E are 4 semitones, and between E and G are 3 semitones. And the triplet "C# B F" is minor, because if we order the notes as "B C# F", than between B and C# will be 3 semitones, and between C# and F — 4 semitones.
Help Vasya classify the triad the teacher has given to him.
Input
The only line contains 3 space-separated notes in the above-given notation.
Output
Print "major" if the chord is major, "minor" if it is minor, and "strange" if the teacher gave Vasya some weird chord which is neither major nor minor. Vasya promises you that the answer will always be unambiguous. That is, there are no chords that are both major and minor simultaneously.
Examples
Input
C E G
Output
major
Input
C# B F
Output
minor
Input
A B H
Output
strange
Tags: brute force, implementation
Correct Solution:
```
a,b,c=map(str,input().split())
def pos(a,b):
d={"C":1, "C#":2, "D":3, "D#":4, "E":5, "F":6, "F#":7, "G":8, "G#":9, "A":10, "B":11, "H":12}
if d[a]<d[b]:
return d[b]-d[a]
else:
return 12-d[a]+d[b]
l=[[a,b,c],[b,a,c],[a,c,b],[c,a,b],[b,c,a],[c,b,a]]
for i in l:
if pos(i[0],i[1])==4 and pos(i[1],i[2])==3:
print("major")
exit()
elif pos(i[0],i[1])==3 and pos(i[1],i[2])==4:
print("minor")
exit()
print("strange")
```
| 8,786 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya studies music.
He has learned lots of interesting stuff. For example, he knows that there are 12 notes: C, C#, D, D#, E, F, F#, G, G#, A, B, H. He also knows that the notes are repeated cyclically: after H goes C again, and before C stands H. We will consider the C note in the row's beginning and the C note after the H similar and we will identify them with each other. The distance between the notes along the musical scale is measured in tones: between two consecutive notes there's exactly one semitone, that is, 0.5 tone. The distance is taken from the lowest tone to the uppest one, that is, the distance between C and E is 4 semitones and between E and C is 8 semitones
Vasya also knows what a chord is. A chord is an unordered set of no less than three notes. However, for now Vasya only works with triads, that is with the chords that consist of exactly three notes. He can already distinguish between two types of triads — major and minor.
Let's define a major triad. Let the triad consist of notes X, Y and Z. If we can order the notes so as the distance along the musical scale between X and Y equals 4 semitones and the distance between Y and Z is 3 semitones, then the triad is major. The distance between X and Z, accordingly, equals 7 semitones.
A minor triad is different in that the distance between X and Y should be 3 semitones and between Y and Z — 4 semitones.
For example, the triad "C E G" is major: between C and E are 4 semitones, and between E and G are 3 semitones. And the triplet "C# B F" is minor, because if we order the notes as "B C# F", than between B and C# will be 3 semitones, and between C# and F — 4 semitones.
Help Vasya classify the triad the teacher has given to him.
Input
The only line contains 3 space-separated notes in the above-given notation.
Output
Print "major" if the chord is major, "minor" if it is minor, and "strange" if the teacher gave Vasya some weird chord which is neither major nor minor. Vasya promises you that the answer will always be unambiguous. That is, there are no chords that are both major and minor simultaneously.
Examples
Input
C E G
Output
major
Input
C# B F
Output
minor
Input
A B H
Output
strange
Submitted Solution:
```
def permutations(ss):
s = str(ss).split()
x = s[0]
y = s[1]
z = s[2]
l = []
l.append(str(x+" "+y+" "+z))
l.append(str(x+" "+z+" "+y))
l.append(str(y+" "+z+" "+x))
l.append(str(y+" "+x+" "+z))
l.append(str(z+" "+x+" "+y))
l.append(str(z+" "+y+" "+x))
return l
dict = {'C': 1, 'G#': 9, 'E': 5, 'A': 10, 'B': 11, 'F': 6, 'D#': 4, 'G': 8, 'C#': 2, 'F#': 7, 'D': 3, 'H': 12}
st = input()
lis = permutations(st)
maj = False
min = False
for st in lis:
s = str(st).split()
first = dict[s[1]]-dict[s[0]]
if first<0:
first+=12
second = dict[s[2]]-dict[s[1]]
if second<0:
second+=12
if first == 4 and second==3:
maj = True
elif first==3 and second==4:
min = True
else:
continue
if maj:
print("major")
elif min:
print("minor")
else:
print("strange")
```
Yes
| 8,787 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya studies music.
He has learned lots of interesting stuff. For example, he knows that there are 12 notes: C, C#, D, D#, E, F, F#, G, G#, A, B, H. He also knows that the notes are repeated cyclically: after H goes C again, and before C stands H. We will consider the C note in the row's beginning and the C note after the H similar and we will identify them with each other. The distance between the notes along the musical scale is measured in tones: between two consecutive notes there's exactly one semitone, that is, 0.5 tone. The distance is taken from the lowest tone to the uppest one, that is, the distance between C and E is 4 semitones and between E and C is 8 semitones
Vasya also knows what a chord is. A chord is an unordered set of no less than three notes. However, for now Vasya only works with triads, that is with the chords that consist of exactly three notes. He can already distinguish between two types of triads — major and minor.
Let's define a major triad. Let the triad consist of notes X, Y and Z. If we can order the notes so as the distance along the musical scale between X and Y equals 4 semitones and the distance between Y and Z is 3 semitones, then the triad is major. The distance between X and Z, accordingly, equals 7 semitones.
A minor triad is different in that the distance between X and Y should be 3 semitones and between Y and Z — 4 semitones.
For example, the triad "C E G" is major: between C and E are 4 semitones, and between E and G are 3 semitones. And the triplet "C# B F" is minor, because if we order the notes as "B C# F", than between B and C# will be 3 semitones, and between C# and F — 4 semitones.
Help Vasya classify the triad the teacher has given to him.
Input
The only line contains 3 space-separated notes in the above-given notation.
Output
Print "major" if the chord is major, "minor" if it is minor, and "strange" if the teacher gave Vasya some weird chord which is neither major nor minor. Vasya promises you that the answer will always be unambiguous. That is, there are no chords that are both major and minor simultaneously.
Examples
Input
C E G
Output
major
Input
C# B F
Output
minor
Input
A B H
Output
strange
Submitted Solution:
```
lt = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A' ,'B', 'H']
major = [[4,3], [3,5], [5,4]]
minor = [[3,4], [4,5], [5,3]]
x,y,z = input().split()
ind = [lt.index(p) for p in (x,y,z)]
ind.sort()
diff = [ind[1]-ind[0], ind[2]-ind[1]]
if diff in major:
print('major')
elif diff in minor:
print('minor')
else:
print('strange')
```
Yes
| 8,788 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya studies music.
He has learned lots of interesting stuff. For example, he knows that there are 12 notes: C, C#, D, D#, E, F, F#, G, G#, A, B, H. He also knows that the notes are repeated cyclically: after H goes C again, and before C stands H. We will consider the C note in the row's beginning and the C note after the H similar and we will identify them with each other. The distance between the notes along the musical scale is measured in tones: between two consecutive notes there's exactly one semitone, that is, 0.5 tone. The distance is taken from the lowest tone to the uppest one, that is, the distance between C and E is 4 semitones and between E and C is 8 semitones
Vasya also knows what a chord is. A chord is an unordered set of no less than three notes. However, for now Vasya only works with triads, that is with the chords that consist of exactly three notes. He can already distinguish between two types of triads — major and minor.
Let's define a major triad. Let the triad consist of notes X, Y and Z. If we can order the notes so as the distance along the musical scale between X and Y equals 4 semitones and the distance between Y and Z is 3 semitones, then the triad is major. The distance between X and Z, accordingly, equals 7 semitones.
A minor triad is different in that the distance between X and Y should be 3 semitones and between Y and Z — 4 semitones.
For example, the triad "C E G" is major: between C and E are 4 semitones, and between E and G are 3 semitones. And the triplet "C# B F" is minor, because if we order the notes as "B C# F", than between B and C# will be 3 semitones, and between C# and F — 4 semitones.
Help Vasya classify the triad the teacher has given to him.
Input
The only line contains 3 space-separated notes in the above-given notation.
Output
Print "major" if the chord is major, "minor" if it is minor, and "strange" if the teacher gave Vasya some weird chord which is neither major nor minor. Vasya promises you that the answer will always be unambiguous. That is, there are no chords that are both major and minor simultaneously.
Examples
Input
C E G
Output
major
Input
C# B F
Output
minor
Input
A B H
Output
strange
Submitted Solution:
```
def low(ele,e2,e3,l):
loc1=-1
loc2=-1
for i in range(l.index(ele),12):
if l[i]==e2:
loc1=i
if l[i]==e3:
loc2=i
if loc1==-1:
d1=12-l.index(ele)+l.index(e2)
elif loc1!=-1:
d1=loc1-l.index(ele)
if loc2==-1:
d2=12-l.index(ele)+l.index(e3)
elif loc2!=-1:
d2=loc2-l.index(ele)
return d1,d2
l=['C', 'C#', 'D', 'D#', 'E', 'F','F#', 'G', 'G#', 'A','B', 'H']
X,Y,Z=[str(x) for x in input().split()]
#x is lowest
x1,x2=low(X,Y,Z,l)
if (x1==4 and x2==7) or (x1==7 and x2==4):
print("major")
elif (x1==3 and x2==7) or(x1==7 and x2==3):
print("minor")
else:
y1,y2=low(Y,X,Z,l)
if (y1==4 and y2==7) or (y1==7 and y2==4):
print("major")
elif (y1==3 and y2==7) or(y1==7 and y2==3):
print("minor")
else:
z1,z2=low(Z,X,Y,l)
if (z1==4 and z2==7) or (z1==7 and z2==4):
print("major")
elif (z1==3 and z2==7) or(z1==7 and z2==3):
print("minor")
else:
print("strange")
```
Yes
| 8,789 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya studies music.
He has learned lots of interesting stuff. For example, he knows that there are 12 notes: C, C#, D, D#, E, F, F#, G, G#, A, B, H. He also knows that the notes are repeated cyclically: after H goes C again, and before C stands H. We will consider the C note in the row's beginning and the C note after the H similar and we will identify them with each other. The distance between the notes along the musical scale is measured in tones: between two consecutive notes there's exactly one semitone, that is, 0.5 tone. The distance is taken from the lowest tone to the uppest one, that is, the distance between C and E is 4 semitones and between E and C is 8 semitones
Vasya also knows what a chord is. A chord is an unordered set of no less than three notes. However, for now Vasya only works with triads, that is with the chords that consist of exactly three notes. He can already distinguish between two types of triads — major and minor.
Let's define a major triad. Let the triad consist of notes X, Y and Z. If we can order the notes so as the distance along the musical scale between X and Y equals 4 semitones and the distance between Y and Z is 3 semitones, then the triad is major. The distance between X and Z, accordingly, equals 7 semitones.
A minor triad is different in that the distance between X and Y should be 3 semitones and between Y and Z — 4 semitones.
For example, the triad "C E G" is major: between C and E are 4 semitones, and between E and G are 3 semitones. And the triplet "C# B F" is minor, because if we order the notes as "B C# F", than between B and C# will be 3 semitones, and between C# and F — 4 semitones.
Help Vasya classify the triad the teacher has given to him.
Input
The only line contains 3 space-separated notes in the above-given notation.
Output
Print "major" if the chord is major, "minor" if it is minor, and "strange" if the teacher gave Vasya some weird chord which is neither major nor minor. Vasya promises you that the answer will always be unambiguous. That is, there are no chords that are both major and minor simultaneously.
Examples
Input
C E G
Output
major
Input
C# B F
Output
minor
Input
A B H
Output
strange
Submitted Solution:
```
#import math
#n, m = input().split()
#n = int (n)
#m = int (m)
#n, m, k= input().split()
#n = int (n)
#m = int (m)
#k = int (k)
#l = int(l)
#m = int(input())
#s = input()
##t = input()
#a = list(map(char, input().split()))
#a.append('.')
#print(l)
#a = list(map(int, input().split()))
#c = sorted(c)
#x1, y1, x2, y2 =map(int,input().split())
#n = int(input())
#f = []
#t = [0]*n
#f = [(int(s1[0]),s1[1]), (int(s2[0]),s2[1]), (int(s3[0]), s3[1])]
#f1 = sorted(t, key = lambda tup: tup[0])
dic = {"C":0, "C#":1, "D":2, "D#":3, "E":4, "F":5, "F#":6, "G":7, "G#":8, "A":9, "B":10, "H":11}
X, Y, Z = input().split()
a = [dic[X], dic[Y], dic[Z]]
a = sorted(a)
X = a[0]
Y = a[1]
Z = a[2]
if ((Y-X == 3 and Z-Y == 4) or (X+12 -Z == 4 and Z -Y == 3) or(Y- X == 4 and X+12-Z == 3)):
print("minor")
elif ((Y-X == 4 and Z-Y == 3) or (X+12 -Z == 3 and Z -Y == 4) or(Y- X == 3 and X+12-Z == 4)):
print("major")
else:
print("strange")
```
Yes
| 8,790 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya studies music.
He has learned lots of interesting stuff. For example, he knows that there are 12 notes: C, C#, D, D#, E, F, F#, G, G#, A, B, H. He also knows that the notes are repeated cyclically: after H goes C again, and before C stands H. We will consider the C note in the row's beginning and the C note after the H similar and we will identify them with each other. The distance between the notes along the musical scale is measured in tones: between two consecutive notes there's exactly one semitone, that is, 0.5 tone. The distance is taken from the lowest tone to the uppest one, that is, the distance between C and E is 4 semitones and between E and C is 8 semitones
Vasya also knows what a chord is. A chord is an unordered set of no less than three notes. However, for now Vasya only works with triads, that is with the chords that consist of exactly three notes. He can already distinguish between two types of triads — major and minor.
Let's define a major triad. Let the triad consist of notes X, Y and Z. If we can order the notes so as the distance along the musical scale between X and Y equals 4 semitones and the distance between Y and Z is 3 semitones, then the triad is major. The distance between X and Z, accordingly, equals 7 semitones.
A minor triad is different in that the distance between X and Y should be 3 semitones and between Y and Z — 4 semitones.
For example, the triad "C E G" is major: between C and E are 4 semitones, and between E and G are 3 semitones. And the triplet "C# B F" is minor, because if we order the notes as "B C# F", than between B and C# will be 3 semitones, and between C# and F — 4 semitones.
Help Vasya classify the triad the teacher has given to him.
Input
The only line contains 3 space-separated notes in the above-given notation.
Output
Print "major" if the chord is major, "minor" if it is minor, and "strange" if the teacher gave Vasya some weird chord which is neither major nor minor. Vasya promises you that the answer will always be unambiguous. That is, there are no chords that are both major and minor simultaneously.
Examples
Input
C E G
Output
major
Input
C# B F
Output
minor
Input
A B H
Output
strange
Submitted Solution:
```
NOTES = 'C C# D D# E F F# G G# A B H'.split()
a, b, c = sorted(map(NOTES.index, input().split()))
x, y = b-a, c-b
if (x,y) in ((4,3), (3,5)):
print('major')
elif (x,y) in ((3,4), (4,5)):
print('minor')
else:
print('strange')
```
No
| 8,791 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya studies music.
He has learned lots of interesting stuff. For example, he knows that there are 12 notes: C, C#, D, D#, E, F, F#, G, G#, A, B, H. He also knows that the notes are repeated cyclically: after H goes C again, and before C stands H. We will consider the C note in the row's beginning and the C note after the H similar and we will identify them with each other. The distance between the notes along the musical scale is measured in tones: between two consecutive notes there's exactly one semitone, that is, 0.5 tone. The distance is taken from the lowest tone to the uppest one, that is, the distance between C and E is 4 semitones and between E and C is 8 semitones
Vasya also knows what a chord is. A chord is an unordered set of no less than three notes. However, for now Vasya only works with triads, that is with the chords that consist of exactly three notes. He can already distinguish between two types of triads — major and minor.
Let's define a major triad. Let the triad consist of notes X, Y and Z. If we can order the notes so as the distance along the musical scale between X and Y equals 4 semitones and the distance between Y and Z is 3 semitones, then the triad is major. The distance between X and Z, accordingly, equals 7 semitones.
A minor triad is different in that the distance between X and Y should be 3 semitones and between Y and Z — 4 semitones.
For example, the triad "C E G" is major: between C and E are 4 semitones, and between E and G are 3 semitones. And the triplet "C# B F" is minor, because if we order the notes as "B C# F", than between B and C# will be 3 semitones, and between C# and F — 4 semitones.
Help Vasya classify the triad the teacher has given to him.
Input
The only line contains 3 space-separated notes in the above-given notation.
Output
Print "major" if the chord is major, "minor" if it is minor, and "strange" if the teacher gave Vasya some weird chord which is neither major nor minor. Vasya promises you that the answer will always be unambiguous. That is, there are no chords that are both major and minor simultaneously.
Examples
Input
C E G
Output
major
Input
C# B F
Output
minor
Input
A B H
Output
strange
Submitted Solution:
```
def check(a,b,c):
if abs(a-b)%4==0 and abs(b-c)%3==0:
print("major")
exit()
elif abs(a-b)%3==0 and abs(b-c)%4==0:
print("minor")
exit()
a,b,c=(map(str,input().split()))
notes=["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "B", "H"]
a2=notes.index(a)%12
b2=notes.index(b)%12
c2=notes.index(c)%12
check(a2,b2,c2)
check(a2,c2,b2)
check(b2,a2,c2)
check(b2,c2,a2)
check(c2,a2,b2)
check(c2,b2,a2)
print("strange")
```
No
| 8,792 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya studies music.
He has learned lots of interesting stuff. For example, he knows that there are 12 notes: C, C#, D, D#, E, F, F#, G, G#, A, B, H. He also knows that the notes are repeated cyclically: after H goes C again, and before C stands H. We will consider the C note in the row's beginning and the C note after the H similar and we will identify them with each other. The distance between the notes along the musical scale is measured in tones: between two consecutive notes there's exactly one semitone, that is, 0.5 tone. The distance is taken from the lowest tone to the uppest one, that is, the distance between C and E is 4 semitones and between E and C is 8 semitones
Vasya also knows what a chord is. A chord is an unordered set of no less than three notes. However, for now Vasya only works with triads, that is with the chords that consist of exactly three notes. He can already distinguish between two types of triads — major and minor.
Let's define a major triad. Let the triad consist of notes X, Y and Z. If we can order the notes so as the distance along the musical scale between X and Y equals 4 semitones and the distance between Y and Z is 3 semitones, then the triad is major. The distance between X and Z, accordingly, equals 7 semitones.
A minor triad is different in that the distance between X and Y should be 3 semitones and between Y and Z — 4 semitones.
For example, the triad "C E G" is major: between C and E are 4 semitones, and between E and G are 3 semitones. And the triplet "C# B F" is minor, because if we order the notes as "B C# F", than between B and C# will be 3 semitones, and between C# and F — 4 semitones.
Help Vasya classify the triad the teacher has given to him.
Input
The only line contains 3 space-separated notes in the above-given notation.
Output
Print "major" if the chord is major, "minor" if it is minor, and "strange" if the teacher gave Vasya some weird chord which is neither major nor minor. Vasya promises you that the answer will always be unambiguous. That is, there are no chords that are both major and minor simultaneously.
Examples
Input
C E G
Output
major
Input
C# B F
Output
minor
Input
A B H
Output
strange
Submitted Solution:
```
import math
a,b,c=[str(i) for i in input().split()]
l=['C','C#','D','D#','E','F','F#','G','G#','A','B','H']
d=abs(l.index(a)-l.index(b))
e=abs(l.index(b)-l.index(c))
f=abs(l.index(a)-l.index(c))
flag=0
if(d==4 or (12-d)==4):
flag=flag+1
if(e==3 or (12-e)==3):
flag=flag+1
if(f==7 or (12-f)==7):
flag=flag+1
sflag=0
if(d==4 or (12-d)==4):
sflag=sflag+1
if(e==3 or (12-e)==3):
sflag=sflag+1
if(flag==3):
print('major')
elif(sflag==2):
print('minor')
else:
print('strange')
```
No
| 8,793 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya studies music.
He has learned lots of interesting stuff. For example, he knows that there are 12 notes: C, C#, D, D#, E, F, F#, G, G#, A, B, H. He also knows that the notes are repeated cyclically: after H goes C again, and before C stands H. We will consider the C note in the row's beginning and the C note after the H similar and we will identify them with each other. The distance between the notes along the musical scale is measured in tones: between two consecutive notes there's exactly one semitone, that is, 0.5 tone. The distance is taken from the lowest tone to the uppest one, that is, the distance between C and E is 4 semitones and between E and C is 8 semitones
Vasya also knows what a chord is. A chord is an unordered set of no less than three notes. However, for now Vasya only works with triads, that is with the chords that consist of exactly three notes. He can already distinguish between two types of triads — major and minor.
Let's define a major triad. Let the triad consist of notes X, Y and Z. If we can order the notes so as the distance along the musical scale between X and Y equals 4 semitones and the distance between Y and Z is 3 semitones, then the triad is major. The distance between X and Z, accordingly, equals 7 semitones.
A minor triad is different in that the distance between X and Y should be 3 semitones and between Y and Z — 4 semitones.
For example, the triad "C E G" is major: between C and E are 4 semitones, and between E and G are 3 semitones. And the triplet "C# B F" is minor, because if we order the notes as "B C# F", than between B and C# will be 3 semitones, and between C# and F — 4 semitones.
Help Vasya classify the triad the teacher has given to him.
Input
The only line contains 3 space-separated notes in the above-given notation.
Output
Print "major" if the chord is major, "minor" if it is minor, and "strange" if the teacher gave Vasya some weird chord which is neither major nor minor. Vasya promises you that the answer will always be unambiguous. That is, there are no chords that are both major and minor simultaneously.
Examples
Input
C E G
Output
major
Input
C# B F
Output
minor
Input
A B H
Output
strange
Submitted Solution:
```
# Author: SaykaT
# Problem: 88A.py
# Time Created: August 09(Sunday) 2020 || 04:38:42
#>-------------------------<#
import sys
input = sys.stdin.readline
#>-------------------------<#
# Helper Functions. -> Don't cluster your code.
# IO Functions. -> Input output
def io():
x, y, z = map(str, input().split())
x, y, z = sorted([x, y, z])
return x, y, z
# Main functions. -> Write the main solution here
def solve():
x, y, z = io()
notes = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'B', 'H']
notes += notes
x_y = 0
x_y_min = 0
y_z = 0
y_z_min = 0
for i in range(notes.index(x), len(notes)):
if notes[i]== y: break
else: x_y += 1
for i in range(notes.index(y), len(notes)):
if notes[i] == x: break
else: x_y_min += 1
for i in range(notes.index(y), len(notes)):
if notes[i] == z: break
else: y_z += 1
for i in range(notes.index(z), len(notes)):
if notes[i] == y: break
else: y_z_min += 1
x_y = min(x_y, x_y_min)
y_z = min(y_z, y_z_min)
if x_y == 4 and y_z == 3: ans = 'major'
elif x_y == 3 and y_z == 4: ans = 'minor'
else: ans = 'strange'
print(ans)
# Multiple test cases. -> When you have T test cases.
solve()
```
No
| 8,794 |
Provide tags and a correct Python 3 solution for this coding contest problem.
While Grisha was celebrating New Year with Ded Moroz, Misha gifted Sasha a small rectangular pond of size n × m, divided into cells of size 1 × 1, inhabited by tiny evil fishes (no more than one fish per cell, otherwise they'll strife!).
The gift bundle also includes a square scoop of size r × r, designed for fishing. If the lower-left corner of the scoop-net is located at cell (x, y), all fishes inside the square (x, y)...(x + r - 1, y + r - 1) get caught. Note that the scoop-net should lie completely inside the pond when used.
Unfortunately, Sasha is not that skilled in fishing and hence throws the scoop randomly. In order to not frustrate Sasha, Misha decided to release k fishes into the empty pond in such a way that the expected value of the number of caught fishes is as high as possible. Help Misha! In other words, put k fishes in the pond into distinct cells in such a way that when the scoop-net is placed into a random position among (n - r + 1)·(m - r + 1) possible positions, the average number of caught fishes is as high as possible.
Input
The only line contains four integers n, m, r, k (1 ≤ n, m ≤ 105, 1 ≤ r ≤ min(n, m), 1 ≤ k ≤ min(n·m, 105)).
Output
Print a single number — the maximum possible expected number of caught fishes.
You answer is considered correct, is its absolute or relative error does not exceed 10 - 9. Namely, let your answer be a, and the jury's answer be b. Your answer is considered correct, if <image>.
Examples
Input
3 3 2 3
Output
2.0000000000
Input
12 17 9 40
Output
32.8333333333
Note
In the first example you can put the fishes in cells (2, 1), (2, 2), (2, 3). In this case, for any of four possible positions of the scoop-net (highlighted with light green), the number of fishes inside is equal to two, and so is the expected value.
<image>
Tags: data structures, graphs, greedy, probabilities, shortest paths
Correct Solution:
```
n, m, r, k = map(int, input().split())
def count(y, x):
minx = max(0, x-(r-1))
maxx = min(m-1-(r-1), x)
miny = max(0, y-(r-1))
maxy = min(n-1-(r-1), y)
res = (maxy-miny+1)*(maxx-minx+1)
return res
#X = [[0]*m for i in range(n)]
#for i in range(n):
#for j in range(m):
#X[i][j] = count(i, j)
#print(i, j, count(i, j))
#for i in range(n):
#print(*X[i])
sy, sx = n//2, m//2
c = count(sy, sx)
cnt = 0
import heapq
q = [(-c, sy, sx)]
heapq.heapify(q)
visit = set()
visit.add((sy, sx))
E = 0
while q:
c, y, x = heapq.heappop(q)
c = -c
E += c
cnt += 1
if cnt == k:
break
for dy, dx in (-1, 0), (1, 0), (0, -1), (0, 1):
ny, nx = y+dy, x+dx
if 0 <= ny < n and 0 <= nx < m:
if (ny, nx) in visit:
continue
c = count(ny, nx)
heapq.heappush(q, (-c, ny, nx))
visit.add((ny, nx))
ans = E/((n-r+1)*(m-r+1))
print(ans)
```
| 8,795 |
Provide tags and a correct Python 3 solution for this coding contest problem.
While Grisha was celebrating New Year with Ded Moroz, Misha gifted Sasha a small rectangular pond of size n × m, divided into cells of size 1 × 1, inhabited by tiny evil fishes (no more than one fish per cell, otherwise they'll strife!).
The gift bundle also includes a square scoop of size r × r, designed for fishing. If the lower-left corner of the scoop-net is located at cell (x, y), all fishes inside the square (x, y)...(x + r - 1, y + r - 1) get caught. Note that the scoop-net should lie completely inside the pond when used.
Unfortunately, Sasha is not that skilled in fishing and hence throws the scoop randomly. In order to not frustrate Sasha, Misha decided to release k fishes into the empty pond in such a way that the expected value of the number of caught fishes is as high as possible. Help Misha! In other words, put k fishes in the pond into distinct cells in such a way that when the scoop-net is placed into a random position among (n - r + 1)·(m - r + 1) possible positions, the average number of caught fishes is as high as possible.
Input
The only line contains four integers n, m, r, k (1 ≤ n, m ≤ 105, 1 ≤ r ≤ min(n, m), 1 ≤ k ≤ min(n·m, 105)).
Output
Print a single number — the maximum possible expected number of caught fishes.
You answer is considered correct, is its absolute or relative error does not exceed 10 - 9. Namely, let your answer be a, and the jury's answer be b. Your answer is considered correct, if <image>.
Examples
Input
3 3 2 3
Output
2.0000000000
Input
12 17 9 40
Output
32.8333333333
Note
In the first example you can put the fishes in cells (2, 1), (2, 2), (2, 3). In this case, for any of four possible positions of the scoop-net (highlighted with light green), the number of fishes inside is equal to two, and so is the expected value.
<image>
Tags: data structures, graphs, greedy, probabilities, shortest paths
Correct Solution:
```
import queue
q = queue.PriorityQueue()
n, m, r, k = map(int, input().split())
a = min(r, n - r + 1)
b = min(r, m - r + 1)
u = n - 2 * a + 2
v = m - 2 * b + 2
for i in range(1, a + 1): q.put((-b * i, i))
t = 0
while k:
s, i = q.get()
q.put((s + i, i))
d = min((u if i == a else 2) * (v if s == -b * i else 2), k)
t -= s * d
k -= d
print(t / (n - r + 1) / (m - r + 1))
```
| 8,796 |
Provide tags and a correct Python 3 solution for this coding contest problem.
While Grisha was celebrating New Year with Ded Moroz, Misha gifted Sasha a small rectangular pond of size n × m, divided into cells of size 1 × 1, inhabited by tiny evil fishes (no more than one fish per cell, otherwise they'll strife!).
The gift bundle also includes a square scoop of size r × r, designed for fishing. If the lower-left corner of the scoop-net is located at cell (x, y), all fishes inside the square (x, y)...(x + r - 1, y + r - 1) get caught. Note that the scoop-net should lie completely inside the pond when used.
Unfortunately, Sasha is not that skilled in fishing and hence throws the scoop randomly. In order to not frustrate Sasha, Misha decided to release k fishes into the empty pond in such a way that the expected value of the number of caught fishes is as high as possible. Help Misha! In other words, put k fishes in the pond into distinct cells in such a way that when the scoop-net is placed into a random position among (n - r + 1)·(m - r + 1) possible positions, the average number of caught fishes is as high as possible.
Input
The only line contains four integers n, m, r, k (1 ≤ n, m ≤ 105, 1 ≤ r ≤ min(n, m), 1 ≤ k ≤ min(n·m, 105)).
Output
Print a single number — the maximum possible expected number of caught fishes.
You answer is considered correct, is its absolute or relative error does not exceed 10 - 9. Namely, let your answer be a, and the jury's answer be b. Your answer is considered correct, if <image>.
Examples
Input
3 3 2 3
Output
2.0000000000
Input
12 17 9 40
Output
32.8333333333
Note
In the first example you can put the fishes in cells (2, 1), (2, 2), (2, 3). In this case, for any of four possible positions of the scoop-net (highlighted with light green), the number of fishes inside is equal to two, and so is the expected value.
<image>
Tags: data structures, graphs, greedy, probabilities, shortest paths
Correct Solution:
```
class TupleHeap(object):
def __init__(self):
self.heap = [0]
def mult(self, i):
return self.heap[i][0] * self.heap[i][1]
def __str__(self):
return " ".join(map(str, self.heap))
def add(self, var):
self.heap.append(var)
if len(self.heap) > 2:
# надо сортировать снизу
el = len(self.heap) - 1
par = el // 2
while (el != 1) and (self.mult(el) > self.mult(par)):
self.heap[el], self.heap[par] = self.heap[par], self.heap[el]
el = par
par = el // 2
def pop(self):
if len(self.heap) == 1:
return None # Нечего брать из кучи
ans = self.heap[1]
if len(self.heap) == 2:
self.heap.pop()
return ans
self.heap[1] = self.heap.pop()
# делаем сортировку вниз
el = 1
var_el = self.mult(el)
child1 = el * 2
if child1 < len(self.heap):
var_child1 = self.mult(child1)
else:
var_child1 = -1
child2 = el * 2 + 1
if child2 < len(self.heap):
var_child2 = self.mult(child2)
else:
var_child2 = -1
while (var_child2 > var_el) or (var_child1 > var_el):
if var_child1 > var_child2:
self.heap[el], self.heap[child1] = self.heap[child1], self.heap[el]
el = child1
else:
self.heap[el], self.heap[child2] = self.heap[child2], self.heap[el]
el = child2
var_el = self.mult(el)
child1 = el * 2
if child1 < len(self.heap):
var_child1 = self.mult(child1)
else:
var_child1 = -1
child2 = el * 2 + 1
if child2 < len(self.heap):
var_child2 = self.mult(child2)
else:
var_child2 = -1
return ans
n, m, r , k = map(int, input().split())
max_x = min(r, n - r + 1)
max_y = min(r, m - r + 1)
col_max_x = n - 2 * (max_x - 1)
col_max_y = m - 2 * (max_y - 1)
Nr = (n - r + 1) * (m - r + 1)
tuple_heap = TupleHeap()
tuple_heap.add((max_x, max_y))
used = {(max_x, max_y)}
SUMM = 0
curr = tuple_heap.pop()
while (curr is not None) and (curr[0] > 0) and (curr[1] > 0) and (k > 0):
# кладём в кучу следующие элементы (если их там нет)
new_tuple1 = (curr[0] - 1, curr[1])
if new_tuple1 not in used:
used.add(new_tuple1)
tuple_heap.add(new_tuple1)
new_tuple2 = (curr[0], curr[1] - 1)
if new_tuple2 not in used:
used.add(new_tuple2)
tuple_heap.add(new_tuple2)
# вычисляем кол-во элементов поля для такого curr
x = 2 if curr[0] != max_x else col_max_x
y = 2 if curr[1] != max_y else col_max_y
col = min(x * y, k) # размещаем рыбок в квадраты, но не более 1 рыбки на квадрат
k = k - col # сколько ещё рыбок надо разместить
SUMM = SUMM + col * curr[0] * curr[1]
curr = tuple_heap.pop()
#print(tuple_heap)
#print(used)
#print(max_x, max_y)
#print(col_max_x, col_max_y)
#print("SUMM =", SUMM)
#print("Nr =", Nr)
print(SUMM/Nr)
```
| 8,797 |
Provide tags and a correct Python 3 solution for this coding contest problem.
While Grisha was celebrating New Year with Ded Moroz, Misha gifted Sasha a small rectangular pond of size n × m, divided into cells of size 1 × 1, inhabited by tiny evil fishes (no more than one fish per cell, otherwise they'll strife!).
The gift bundle also includes a square scoop of size r × r, designed for fishing. If the lower-left corner of the scoop-net is located at cell (x, y), all fishes inside the square (x, y)...(x + r - 1, y + r - 1) get caught. Note that the scoop-net should lie completely inside the pond when used.
Unfortunately, Sasha is not that skilled in fishing and hence throws the scoop randomly. In order to not frustrate Sasha, Misha decided to release k fishes into the empty pond in such a way that the expected value of the number of caught fishes is as high as possible. Help Misha! In other words, put k fishes in the pond into distinct cells in such a way that when the scoop-net is placed into a random position among (n - r + 1)·(m - r + 1) possible positions, the average number of caught fishes is as high as possible.
Input
The only line contains four integers n, m, r, k (1 ≤ n, m ≤ 105, 1 ≤ r ≤ min(n, m), 1 ≤ k ≤ min(n·m, 105)).
Output
Print a single number — the maximum possible expected number of caught fishes.
You answer is considered correct, is its absolute or relative error does not exceed 10 - 9. Namely, let your answer be a, and the jury's answer be b. Your answer is considered correct, if <image>.
Examples
Input
3 3 2 3
Output
2.0000000000
Input
12 17 9 40
Output
32.8333333333
Note
In the first example you can put the fishes in cells (2, 1), (2, 2), (2, 3). In this case, for any of four possible positions of the scoop-net (highlighted with light green), the number of fishes inside is equal to two, and so is the expected value.
<image>
Tags: data structures, graphs, greedy, probabilities, shortest paths
Correct Solution:
```
# https://codeforces.com/problemset/problem/912/D
import heapq
from heapq import heappush as push
from heapq import heappop as pop
base = 100009
Q=[]
used={}
ans=0
dx = [0,0,-1,1]
dy = [-1,1,0,0]
def f(x, y):
x1, x2 = min(x, r-1), max(0, x-n+r)
y1, y2 = min(y, r-1), max(0, y-m+r)
return -(x1-x2+1)*(y1-y2+1)
def cal(i, j):
return i*base+j
def get(ind):
return ind//base, ind%base
def is_ok(x, y, x_, y_):
if x+x_>=0 and x+x_<n and y+y_>=0 and y+y_<m:
return True
return False
n, m, r, k = map(int, input().split())
x0, y0 = n//2, m//2
Q=[(f(x0, y0), cal(x0, y0))]
while k > 0:
val, ind = pop(Q)
if ind in used:
continue
x, y = get(ind)
used[ind]=True
val = -val
#print((x, y), val)
ans += val
for x_, y_ in zip(dx, dy):
if is_ok(x, y, x_, y_):
push(Q, (f(x+x_, y+y_), cal(x+x_, y+y_)))
k-=1
print(ans/((n-r+1)*(m-r+1)))
```
| 8,798 |
Provide tags and a correct Python 3 solution for this coding contest problem.
While Grisha was celebrating New Year with Ded Moroz, Misha gifted Sasha a small rectangular pond of size n × m, divided into cells of size 1 × 1, inhabited by tiny evil fishes (no more than one fish per cell, otherwise they'll strife!).
The gift bundle also includes a square scoop of size r × r, designed for fishing. If the lower-left corner of the scoop-net is located at cell (x, y), all fishes inside the square (x, y)...(x + r - 1, y + r - 1) get caught. Note that the scoop-net should lie completely inside the pond when used.
Unfortunately, Sasha is not that skilled in fishing and hence throws the scoop randomly. In order to not frustrate Sasha, Misha decided to release k fishes into the empty pond in such a way that the expected value of the number of caught fishes is as high as possible. Help Misha! In other words, put k fishes in the pond into distinct cells in such a way that when the scoop-net is placed into a random position among (n - r + 1)·(m - r + 1) possible positions, the average number of caught fishes is as high as possible.
Input
The only line contains four integers n, m, r, k (1 ≤ n, m ≤ 105, 1 ≤ r ≤ min(n, m), 1 ≤ k ≤ min(n·m, 105)).
Output
Print a single number — the maximum possible expected number of caught fishes.
You answer is considered correct, is its absolute or relative error does not exceed 10 - 9. Namely, let your answer be a, and the jury's answer be b. Your answer is considered correct, if <image>.
Examples
Input
3 3 2 3
Output
2.0000000000
Input
12 17 9 40
Output
32.8333333333
Note
In the first example you can put the fishes in cells (2, 1), (2, 2), (2, 3). In this case, for any of four possible positions of the scoop-net (highlighted with light green), the number of fishes inside is equal to two, and so is the expected value.
<image>
Tags: data structures, graphs, greedy, probabilities, shortest paths
Correct Solution:
```
import heapq as hq
from queue import PriorityQueue
import math
n,m,r, k= input().split()
N = int(n)
M = int(m)
R = int(r)
K = int(k)
q = PriorityQueue()
for i in range(1,math.floor((N+1)/2) + 1):
maxi = min(min(i,N-i+1),min(R,N-R+1)) * min(min(R,M-R+1),math.ceil(M/2))
num = M - (2 * min(min(R,M-R+1),math.ceil(M/2))-2)
mult = 2
if(i > math.floor(N/2)):
mult = 1
q.put((-maxi,num * mult,i))
#print(str(maxi) + " " + str(num) + " " + str(mult))
ans = 0
while(K > 0):
pop = q.get()
#print(pop)
a = -1 * pop[0]
b = pop[1]
c = pop[2]
d = min(min(c,N-c+1),min(R,N-R+1))
if(d != a):
# if(q.)
# if(q.get(-(a - d)) != )
mult = 2
if (c > N / 2):
mult = 1
q.put((-(a - d),2*mult,c))
ans += a * min(b,K)
K -= b;
tot = (N-R+1) * (M-R+1)
#print("ANS = " + str(ans))
#print("FINANS = " + str(ans/tot))
print(str(ans/tot))
'''
d = []
for i in range(0,N):
d.append([])
for j in range(0,M):
d[i].append(0)
tot = 0
for i in range(0,N-R+1):
for j in range(0,M-R+1):
for k in range(i,i+R):
for l in range(j,j+R):
d[k][l] += 1
tot += 1
print((N-R+1)*(M-R+1) * (R*R))
print(tot)
print()
for i in d:
print(i)
'''
```
| 8,799 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.