message stringlengths 2 16.2k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 575 109k | cluster float64 16 16 | __index_level_0__ int64 1.15k 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has an integer sequence A of length N.
He will make three cuts in A and divide it into four (non-empty) contiguous subsequences B, C, D and E. The positions of the cuts can be freely chosen.
Let P,Q,R,S be the sums of the elements in B,C,D,E, respectively. Snuke is happier when the absolute difference of the maximum and the minimum among P,Q,R,S is smaller. Find the minimum possible absolute difference of the maximum and the minimum among P,Q,R,S.
Constraints
* 4 \leq N \leq 2 \times 10^5
* 1 \leq A_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
Output
Find the minimum possible absolute difference of the maximum and the minimum among P,Q,R,S.
Examples
Input
5
3 2 4 1 2
Output
2
Input
10
10 71 84 33 6 47 23 25 52 64
Output
36
Input
7
1 2 3 1000000000 4 5 6
Output
999999994
Submitted Solution:
```
import sys
import itertools
import bisect
readInt = lambda : [int(i) for i in input().split()];
n = readInt()[0]
A = readInt()
B = list(itertools.accumulate(A))
cand = 2 * pow(10, 14)
for i in range(2, len(A)-1):
z = B[i-1]
s = z // 2
j = bisect.bisect_right(B, s)
c0 = abs(2 * B[j-1] - z)
c1 = abs(2 * B[j] - z)
j0 = j-1 if c0 < c1 else j
z = B[i-1]
s = z + (B[-1] - z) // 2
j = bisect.bisect_right(B, s)
c0 = abs(2 * B[j-1] - z)
c1 = abs(2 * B[j] - z)
j1 = j-1 if c0 < c1 else j
c = [B[j0], B[i-1] - B[j0], B[j1] - B[i-1], B[-1] - B[j1]]
cand = min(cand, max(c) - min(c))
ans = cand
print(ans)
``` | instruction | 0 | 47,780 | 16 | 95,560 |
No | output | 1 | 47,780 | 16 | 95,561 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has an integer sequence A of length N.
He will make three cuts in A and divide it into four (non-empty) contiguous subsequences B, C, D and E. The positions of the cuts can be freely chosen.
Let P,Q,R,S be the sums of the elements in B,C,D,E, respectively. Snuke is happier when the absolute difference of the maximum and the minimum among P,Q,R,S is smaller. Find the minimum possible absolute difference of the maximum and the minimum among P,Q,R,S.
Constraints
* 4 \leq N \leq 2 \times 10^5
* 1 \leq A_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
Output
Find the minimum possible absolute difference of the maximum and the minimum among P,Q,R,S.
Examples
Input
5
3 2 4 1 2
Output
2
Input
10
10 71 84 33 6 47 23 25 52 64
Output
36
Input
7
1 2 3 1000000000 4 5 6
Output
999999994
Submitted Solution:
```
# -*- coding: utf-8 -*-
from bisect import bisect, bisect_left
from itertools import accumulate, product
N = int(input())
A = list(map(int, input().split()))
S = list(accumulate(A))
T = sum(A)
ans = 10**16
for j in range(1, N-1):
PQ = S[j]
RS = T - S[j]
#print("PQ RS", PQ, RS)
i1 = bisect(S, PQ/2) - 1
i2 = bisect_left(S, PQ/2)
k1 = bisect(S, RS/2 + PQ) - 1
k2 = bisect_left(S, RS/2 + PQ)
for i, k in product([i1, i2], [k1, k2]):
#print(i, j, k)
if i < 0 or i==j or j == k or k == N-1:
continue
PQRS = [S[i], S[j] - S[i], S[k] - S[j], T - S[k]]
#print(PQRS)
ans = min(ans, abs(max(PQRS) - min(PQRS)))
print(ans)
``` | instruction | 0 | 47,781 | 16 | 95,562 |
No | output | 1 | 47,781 | 16 | 95,563 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has an integer sequence A of length N.
He will make three cuts in A and divide it into four (non-empty) contiguous subsequences B, C, D and E. The positions of the cuts can be freely chosen.
Let P,Q,R,S be the sums of the elements in B,C,D,E, respectively. Snuke is happier when the absolute difference of the maximum and the minimum among P,Q,R,S is smaller. Find the minimum possible absolute difference of the maximum and the minimum among P,Q,R,S.
Constraints
* 4 \leq N \leq 2 \times 10^5
* 1 \leq A_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
Output
Find the minimum possible absolute difference of the maximum and the minimum among P,Q,R,S.
Examples
Input
5
3 2 4 1 2
Output
2
Input
10
10 71 84 33 6 47 23 25 52 64
Output
36
Input
7
1 2 3 1000000000 4 5 6
Output
999999994
Submitted Solution:
```
def bsearch(mn, mx, func):
#func(i)=False を満たす最大のi
idx = (mx + mn)//2
while mx-mn>1:
if func(idx):
idx, mx = (idx + mn)//2, idx
continue
idx, mn = (idx + mx)//2, idx
return idx
N, = map(int, input().split())
A = list(map(int, input().split()))
X = [0]*(N+2)
Y = [0]*(N+2)
for i in range(N):
X[i+1] = X[i] + A[i]
for i in range(N, 0, -1):
Y[i] = Y[i+1] + A[i-1]
R = 10**18
for i in range(2, N-1):
# X0, X1, X2 .. Xi
# Xj Xj+1 (1<= j <= i-1)
idx1 = bsearch(1, i-1, lambda j:X[i]//2 < X[j])
idx2 = bsearch(i+1, N, lambda j:(X[N]-X[i])//2 < (X[j]-X[i]))
# print(X[idx1], X[i]-X[idx1], X[idx2]-X[i], X[N]-X[idx2])
cand = []
if idx1+1 <= i-1:
if abs(2*X[idx1]-X[i]) > abs(2*X[idx1+1]-X[i]):
idx1+=1
if idx2+1 <= i-1:
if abs(2*X[idx2]-X[i]-X[N]) > abs(2*X[idx2+1]-X[i]-X[N]):
idx2+=1
mx = max([X[idx1], X[i]-X[idx1], X[idx2]-X[i], X[N]-X[idx2]])
mn = min([X[idx1], X[i]-X[idx1], X[idx2]-X[i], X[N]-X[idx2]])
# print(idx1, i, idx2)
# print(mx-mn)
R = min(R, mx-mn)
print(R)
``` | instruction | 0 | 47,782 | 16 | 95,564 |
No | output | 1 | 47,782 | 16 | 95,565 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has an integer sequence A of length N.
He will make three cuts in A and divide it into four (non-empty) contiguous subsequences B, C, D and E. The positions of the cuts can be freely chosen.
Let P,Q,R,S be the sums of the elements in B,C,D,E, respectively. Snuke is happier when the absolute difference of the maximum and the minimum among P,Q,R,S is smaller. Find the minimum possible absolute difference of the maximum and the minimum among P,Q,R,S.
Constraints
* 4 \leq N \leq 2 \times 10^5
* 1 \leq A_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
Output
Find the minimum possible absolute difference of the maximum and the minimum among P,Q,R,S.
Examples
Input
5
3 2 4 1 2
Output
2
Input
10
10 71 84 33 6 47 23 25 52 64
Output
36
Input
7
1 2 3 1000000000 4 5 6
Output
999999994
Submitted Solution:
```
from bisect import bisect
n = int(input())
a = [int(x) for x in input().split()]
r = 0
s = []
for i in a:
r += i
s.append(r)
def bs(x,y):
b = bisect(x, y)
if abs(x[b-1] - y) < abs(x[b] - y):
b = b-1
return b
m = 10**20
for i in range(2, n-1):
k = bs(s, s[i] / 2)
l = bs(s, (s[n] + s[i]) / 2)
s4 = [s[k],s[i]-s[k],s[l]-s[i],s[n]-s[l]]
m = min(m, max(s4) - min(s4))
print(m)
``` | instruction | 0 | 47,783 | 16 | 95,566 |
No | output | 1 | 47,783 | 16 | 95,567 |
Provide a correct Python 3 solution for this coding contest problem.
We will call a non-negative integer increasing if, for any two adjacent digits in its decimal representation, the digit to the right is greater than or equal to the digit to the left. For example, 1558, 11, 3 and 0 are all increasing; 10 and 20170312 are not.
Snuke has an integer N. Find the minimum number of increasing integers that can represent N as their sum.
Constraints
* 1 \leq N \leq 10^{500000}
Input
The input is given from Standard Input in the following format:
N
Output
Print the minimum number of increasing integers that can represent N as their sum.
Examples
Input
80
Output
2
Input
123456789
Output
1
Input
20170312
Output
4
Input
7204647845201772120166980358816078279571541735614841625060678056933503
Output
31 | instruction | 0 | 47,816 | 16 | 95,632 |
"Correct Solution:
```
n=list(input())
n.reverse()
lb,ub=0,len(n)
def check(x):
g=0
for i in n:
x-=(x+g-int(i))%10
if x<0:
break
g=(x+g)//10
return x>=0
while ub-lb>1:
mid=(lb+ub)//2
if check(9*mid):
ub=mid
else:
lb=mid
print(ub)
``` | output | 1 | 47,816 | 16 | 95,633 |
Provide a correct Python 3 solution for this coding contest problem.
We have a square grid with H rows and W columns. Snuke wants to write 0 or 1 in each of the squares. Here, all of the following conditions have to be satisfied:
* For every row, the smaller of the following is A: the number of 0s contained in the row, and the number of 1s contained in the row. (If these two numbers are equal, “the smaller” should be read as “either”.)
* For every column, the smaller of the following is B: the number of 0s contained in the column, and the number of 1s contained in the column.
Determine if these conditions can be satisfied by writing 0 or 1 in each of the squares. If the answer is yes, show one way to fill the squares so that the conditions are satisfied.
Constraints
* 1 \leq H,W \leq 1000
* 0 \leq A
* 2 \times A \leq W
* 0 \leq B
* 2 \times B \leq H
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
H W A B
Output
If the conditions cannot be satisfied by writing 0 or 1 in each of the squares, print -1.
If the conditions can be satisfied, print one way to fill the squares so that the conditions are satisfied, in the following format:
s_{11}s_{12}\cdots s_{1W}
s_{21}s_{22}\cdots s_{2W}
\vdots
s_{H1}s_{H2}\cdots s_{HW}
Here s_{ij} is the digit written in the square at the i-th row from the top and the j-th column from the left in the grid.
If multiple solutions exist, printing any of them will be accepted.
Examples
Input
3 3 1 1
Output
100
010
001
Input
1 5 2 0
Output
01010 | instruction | 0 | 48,574 | 16 | 97,148 |
"Correct Solution:
```
H, W, A, B = [int(x) for x in input().split()]
M = [[0] * W for _ in range(H)]
for h in range(H):
if h < B:
print('1' * A + '0' * (W - A))
else:
print('0' * A + '1' * (W - A))
``` | output | 1 | 48,574 | 16 | 97,149 |
Provide a correct Python 3 solution for this coding contest problem.
We have a square grid with H rows and W columns. Snuke wants to write 0 or 1 in each of the squares. Here, all of the following conditions have to be satisfied:
* For every row, the smaller of the following is A: the number of 0s contained in the row, and the number of 1s contained in the row. (If these two numbers are equal, “the smaller” should be read as “either”.)
* For every column, the smaller of the following is B: the number of 0s contained in the column, and the number of 1s contained in the column.
Determine if these conditions can be satisfied by writing 0 or 1 in each of the squares. If the answer is yes, show one way to fill the squares so that the conditions are satisfied.
Constraints
* 1 \leq H,W \leq 1000
* 0 \leq A
* 2 \times A \leq W
* 0 \leq B
* 2 \times B \leq H
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
H W A B
Output
If the conditions cannot be satisfied by writing 0 or 1 in each of the squares, print -1.
If the conditions can be satisfied, print one way to fill the squares so that the conditions are satisfied, in the following format:
s_{11}s_{12}\cdots s_{1W}
s_{21}s_{22}\cdots s_{2W}
\vdots
s_{H1}s_{H2}\cdots s_{HW}
Here s_{ij} is the digit written in the square at the i-th row from the top and the j-th column from the left in the grid.
If multiple solutions exist, printing any of them will be accepted.
Examples
Input
3 3 1 1
Output
100
010
001
Input
1 5 2 0
Output
01010 | instruction | 0 | 48,575 | 16 | 97,150 |
"Correct Solution:
```
h,w,a,b=map(int,input().split())
for i in range(h):
print("".join(map(str,[((i<b)+(j<a))%2 for j in range(w)])))
``` | output | 1 | 48,575 | 16 | 97,151 |
Provide a correct Python 3 solution for this coding contest problem.
We have a square grid with H rows and W columns. Snuke wants to write 0 or 1 in each of the squares. Here, all of the following conditions have to be satisfied:
* For every row, the smaller of the following is A: the number of 0s contained in the row, and the number of 1s contained in the row. (If these two numbers are equal, “the smaller” should be read as “either”.)
* For every column, the smaller of the following is B: the number of 0s contained in the column, and the number of 1s contained in the column.
Determine if these conditions can be satisfied by writing 0 or 1 in each of the squares. If the answer is yes, show one way to fill the squares so that the conditions are satisfied.
Constraints
* 1 \leq H,W \leq 1000
* 0 \leq A
* 2 \times A \leq W
* 0 \leq B
* 2 \times B \leq H
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
H W A B
Output
If the conditions cannot be satisfied by writing 0 or 1 in each of the squares, print -1.
If the conditions can be satisfied, print one way to fill the squares so that the conditions are satisfied, in the following format:
s_{11}s_{12}\cdots s_{1W}
s_{21}s_{22}\cdots s_{2W}
\vdots
s_{H1}s_{H2}\cdots s_{HW}
Here s_{ij} is the digit written in the square at the i-th row from the top and the j-th column from the left in the grid.
If multiple solutions exist, printing any of them will be accepted.
Examples
Input
3 3 1 1
Output
100
010
001
Input
1 5 2 0
Output
01010 | instruction | 0 | 48,576 | 16 | 97,152 |
"Correct Solution:
```
h,w,a,b=map(int,input().split())
x=''
y=''
for i in range(a):
x+='1'
y+='0'
for i in range(w-a):
x+='0'
y+='1'
for i in range(b):
print(x)
for i in range(h-b):
print(y)
``` | output | 1 | 48,576 | 16 | 97,153 |
Provide a correct Python 3 solution for this coding contest problem.
We have a square grid with H rows and W columns. Snuke wants to write 0 or 1 in each of the squares. Here, all of the following conditions have to be satisfied:
* For every row, the smaller of the following is A: the number of 0s contained in the row, and the number of 1s contained in the row. (If these two numbers are equal, “the smaller” should be read as “either”.)
* For every column, the smaller of the following is B: the number of 0s contained in the column, and the number of 1s contained in the column.
Determine if these conditions can be satisfied by writing 0 or 1 in each of the squares. If the answer is yes, show one way to fill the squares so that the conditions are satisfied.
Constraints
* 1 \leq H,W \leq 1000
* 0 \leq A
* 2 \times A \leq W
* 0 \leq B
* 2 \times B \leq H
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
H W A B
Output
If the conditions cannot be satisfied by writing 0 or 1 in each of the squares, print -1.
If the conditions can be satisfied, print one way to fill the squares so that the conditions are satisfied, in the following format:
s_{11}s_{12}\cdots s_{1W}
s_{21}s_{22}\cdots s_{2W}
\vdots
s_{H1}s_{H2}\cdots s_{HW}
Here s_{ij} is the digit written in the square at the i-th row from the top and the j-th column from the left in the grid.
If multiple solutions exist, printing any of them will be accepted.
Examples
Input
3 3 1 1
Output
100
010
001
Input
1 5 2 0
Output
01010 | instruction | 0 | 48,577 | 16 | 97,154 |
"Correct Solution:
```
H,W,A,B = map(int,input().split())
s1 = '0'*A + '1'*(W-A)
s2 = '1'*A + '0'*(W-A)
for i in range(B):
print(s1)
for i in range(H-B):
print(s2)
``` | output | 1 | 48,577 | 16 | 97,155 |
Provide a correct Python 3 solution for this coding contest problem.
We have a square grid with H rows and W columns. Snuke wants to write 0 or 1 in each of the squares. Here, all of the following conditions have to be satisfied:
* For every row, the smaller of the following is A: the number of 0s contained in the row, and the number of 1s contained in the row. (If these two numbers are equal, “the smaller” should be read as “either”.)
* For every column, the smaller of the following is B: the number of 0s contained in the column, and the number of 1s contained in the column.
Determine if these conditions can be satisfied by writing 0 or 1 in each of the squares. If the answer is yes, show one way to fill the squares so that the conditions are satisfied.
Constraints
* 1 \leq H,W \leq 1000
* 0 \leq A
* 2 \times A \leq W
* 0 \leq B
* 2 \times B \leq H
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
H W A B
Output
If the conditions cannot be satisfied by writing 0 or 1 in each of the squares, print -1.
If the conditions can be satisfied, print one way to fill the squares so that the conditions are satisfied, in the following format:
s_{11}s_{12}\cdots s_{1W}
s_{21}s_{22}\cdots s_{2W}
\vdots
s_{H1}s_{H2}\cdots s_{HW}
Here s_{ij} is the digit written in the square at the i-th row from the top and the j-th column from the left in the grid.
If multiple solutions exist, printing any of them will be accepted.
Examples
Input
3 3 1 1
Output
100
010
001
Input
1 5 2 0
Output
01010 | instruction | 0 | 48,578 | 16 | 97,156 |
"Correct Solution:
```
H,W,A,B=map(int,input().split())
print(*['0'*A+'1'*(W-A) if i<B else '1'*A+'0'*(W-A) for i in range(H)],sep='\n')
``` | output | 1 | 48,578 | 16 | 97,157 |
Provide a correct Python 3 solution for this coding contest problem.
We have a square grid with H rows and W columns. Snuke wants to write 0 or 1 in each of the squares. Here, all of the following conditions have to be satisfied:
* For every row, the smaller of the following is A: the number of 0s contained in the row, and the number of 1s contained in the row. (If these two numbers are equal, “the smaller” should be read as “either”.)
* For every column, the smaller of the following is B: the number of 0s contained in the column, and the number of 1s contained in the column.
Determine if these conditions can be satisfied by writing 0 or 1 in each of the squares. If the answer is yes, show one way to fill the squares so that the conditions are satisfied.
Constraints
* 1 \leq H,W \leq 1000
* 0 \leq A
* 2 \times A \leq W
* 0 \leq B
* 2 \times B \leq H
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
H W A B
Output
If the conditions cannot be satisfied by writing 0 or 1 in each of the squares, print -1.
If the conditions can be satisfied, print one way to fill the squares so that the conditions are satisfied, in the following format:
s_{11}s_{12}\cdots s_{1W}
s_{21}s_{22}\cdots s_{2W}
\vdots
s_{H1}s_{H2}\cdots s_{HW}
Here s_{ij} is the digit written in the square at the i-th row from the top and the j-th column from the left in the grid.
If multiple solutions exist, printing any of them will be accepted.
Examples
Input
3 3 1 1
Output
100
010
001
Input
1 5 2 0
Output
01010 | instruction | 0 | 48,579 | 16 | 97,158 |
"Correct Solution:
```
H, W, A, B = map(int, input().split())
a = "0" * A + "1" * (W-A)
b = "1" * A + "0" * (W-A)
for i in range(B):
print(a)
for i in range(H-B):
print(b)
``` | output | 1 | 48,579 | 16 | 97,159 |
Provide a correct Python 3 solution for this coding contest problem.
We have a square grid with H rows and W columns. Snuke wants to write 0 or 1 in each of the squares. Here, all of the following conditions have to be satisfied:
* For every row, the smaller of the following is A: the number of 0s contained in the row, and the number of 1s contained in the row. (If these two numbers are equal, “the smaller” should be read as “either”.)
* For every column, the smaller of the following is B: the number of 0s contained in the column, and the number of 1s contained in the column.
Determine if these conditions can be satisfied by writing 0 or 1 in each of the squares. If the answer is yes, show one way to fill the squares so that the conditions are satisfied.
Constraints
* 1 \leq H,W \leq 1000
* 0 \leq A
* 2 \times A \leq W
* 0 \leq B
* 2 \times B \leq H
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
H W A B
Output
If the conditions cannot be satisfied by writing 0 or 1 in each of the squares, print -1.
If the conditions can be satisfied, print one way to fill the squares so that the conditions are satisfied, in the following format:
s_{11}s_{12}\cdots s_{1W}
s_{21}s_{22}\cdots s_{2W}
\vdots
s_{H1}s_{H2}\cdots s_{HW}
Here s_{ij} is the digit written in the square at the i-th row from the top and the j-th column from the left in the grid.
If multiple solutions exist, printing any of them will be accepted.
Examples
Input
3 3 1 1
Output
100
010
001
Input
1 5 2 0
Output
01010 | instruction | 0 | 48,580 | 16 | 97,160 |
"Correct Solution:
```
h,w,a,b = map(int,input().split())
if b > h//2 or a > w//2:
print("No")
exit(0)
for _ in range(h-b):
print("0"*(w-a) + "1"*a)
for _ in range(b):
print("1"*(w-a) + "0"*a)
``` | output | 1 | 48,580 | 16 | 97,161 |
Provide a correct Python 3 solution for this coding contest problem.
We have a square grid with H rows and W columns. Snuke wants to write 0 or 1 in each of the squares. Here, all of the following conditions have to be satisfied:
* For every row, the smaller of the following is A: the number of 0s contained in the row, and the number of 1s contained in the row. (If these two numbers are equal, “the smaller” should be read as “either”.)
* For every column, the smaller of the following is B: the number of 0s contained in the column, and the number of 1s contained in the column.
Determine if these conditions can be satisfied by writing 0 or 1 in each of the squares. If the answer is yes, show one way to fill the squares so that the conditions are satisfied.
Constraints
* 1 \leq H,W \leq 1000
* 0 \leq A
* 2 \times A \leq W
* 0 \leq B
* 2 \times B \leq H
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
H W A B
Output
If the conditions cannot be satisfied by writing 0 or 1 in each of the squares, print -1.
If the conditions can be satisfied, print one way to fill the squares so that the conditions are satisfied, in the following format:
s_{11}s_{12}\cdots s_{1W}
s_{21}s_{22}\cdots s_{2W}
\vdots
s_{H1}s_{H2}\cdots s_{HW}
Here s_{ij} is the digit written in the square at the i-th row from the top and the j-th column from the left in the grid.
If multiple solutions exist, printing any of them will be accepted.
Examples
Input
3 3 1 1
Output
100
010
001
Input
1 5 2 0
Output
01010 | instruction | 0 | 48,581 | 16 | 97,162 |
"Correct Solution:
```
h,w,a,b = map(int,input().split())
a1="0"*a + "1"*(w-a)
a2="1"*a + "0"*(w-a)
for i in range(h):
if i<b:print(a1)
else:print(a2)
``` | output | 1 | 48,581 | 16 | 97,163 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have a square grid with H rows and W columns. Snuke wants to write 0 or 1 in each of the squares. Here, all of the following conditions have to be satisfied:
* For every row, the smaller of the following is A: the number of 0s contained in the row, and the number of 1s contained in the row. (If these two numbers are equal, “the smaller” should be read as “either”.)
* For every column, the smaller of the following is B: the number of 0s contained in the column, and the number of 1s contained in the column.
Determine if these conditions can be satisfied by writing 0 or 1 in each of the squares. If the answer is yes, show one way to fill the squares so that the conditions are satisfied.
Constraints
* 1 \leq H,W \leq 1000
* 0 \leq A
* 2 \times A \leq W
* 0 \leq B
* 2 \times B \leq H
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
H W A B
Output
If the conditions cannot be satisfied by writing 0 or 1 in each of the squares, print -1.
If the conditions can be satisfied, print one way to fill the squares so that the conditions are satisfied, in the following format:
s_{11}s_{12}\cdots s_{1W}
s_{21}s_{22}\cdots s_{2W}
\vdots
s_{H1}s_{H2}\cdots s_{HW}
Here s_{ij} is the digit written in the square at the i-th row from the top and the j-th column from the left in the grid.
If multiple solutions exist, printing any of them will be accepted.
Examples
Input
3 3 1 1
Output
100
010
001
Input
1 5 2 0
Output
01010
Submitted Solution:
```
H, W, A, B = map(int, input().split())
print("\n".join(["1" * A + "0" * (W - A)] * B + ["0" * A + "1" * (W - A)] * (H - B)))
``` | instruction | 0 | 48,582 | 16 | 97,164 |
Yes | output | 1 | 48,582 | 16 | 97,165 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have a square grid with H rows and W columns. Snuke wants to write 0 or 1 in each of the squares. Here, all of the following conditions have to be satisfied:
* For every row, the smaller of the following is A: the number of 0s contained in the row, and the number of 1s contained in the row. (If these two numbers are equal, “the smaller” should be read as “either”.)
* For every column, the smaller of the following is B: the number of 0s contained in the column, and the number of 1s contained in the column.
Determine if these conditions can be satisfied by writing 0 or 1 in each of the squares. If the answer is yes, show one way to fill the squares so that the conditions are satisfied.
Constraints
* 1 \leq H,W \leq 1000
* 0 \leq A
* 2 \times A \leq W
* 0 \leq B
* 2 \times B \leq H
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
H W A B
Output
If the conditions cannot be satisfied by writing 0 or 1 in each of the squares, print -1.
If the conditions can be satisfied, print one way to fill the squares so that the conditions are satisfied, in the following format:
s_{11}s_{12}\cdots s_{1W}
s_{21}s_{22}\cdots s_{2W}
\vdots
s_{H1}s_{H2}\cdots s_{HW}
Here s_{ij} is the digit written in the square at the i-th row from the top and the j-th column from the left in the grid.
If multiple solutions exist, printing any of them will be accepted.
Examples
Input
3 3 1 1
Output
100
010
001
Input
1 5 2 0
Output
01010
Submitted Solution:
```
h,w,a,b=map(int,input().split())
if a>w//2or b>h//2:print('No')
else:
for i in range(h):t=i<b;print(('0'*(w-a)+'1'*a)*(1-t)+('1'*(w-a)+'0'*a)*t)
``` | instruction | 0 | 48,583 | 16 | 97,166 |
Yes | output | 1 | 48,583 | 16 | 97,167 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have a square grid with H rows and W columns. Snuke wants to write 0 or 1 in each of the squares. Here, all of the following conditions have to be satisfied:
* For every row, the smaller of the following is A: the number of 0s contained in the row, and the number of 1s contained in the row. (If these two numbers are equal, “the smaller” should be read as “either”.)
* For every column, the smaller of the following is B: the number of 0s contained in the column, and the number of 1s contained in the column.
Determine if these conditions can be satisfied by writing 0 or 1 in each of the squares. If the answer is yes, show one way to fill the squares so that the conditions are satisfied.
Constraints
* 1 \leq H,W \leq 1000
* 0 \leq A
* 2 \times A \leq W
* 0 \leq B
* 2 \times B \leq H
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
H W A B
Output
If the conditions cannot be satisfied by writing 0 or 1 in each of the squares, print -1.
If the conditions can be satisfied, print one way to fill the squares so that the conditions are satisfied, in the following format:
s_{11}s_{12}\cdots s_{1W}
s_{21}s_{22}\cdots s_{2W}
\vdots
s_{H1}s_{H2}\cdots s_{HW}
Here s_{ij} is the digit written in the square at the i-th row from the top and the j-th column from the left in the grid.
If multiple solutions exist, printing any of them will be accepted.
Examples
Input
3 3 1 1
Output
100
010
001
Input
1 5 2 0
Output
01010
Submitted Solution:
```
h,w,a,b=map(int,input().split());print("\n".join(["1"*a+"0"*(w-a)]*b+["0"*a+"1"*(w-a)]*(h-b)))
``` | instruction | 0 | 48,584 | 16 | 97,168 |
Yes | output | 1 | 48,584 | 16 | 97,169 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have a square grid with H rows and W columns. Snuke wants to write 0 or 1 in each of the squares. Here, all of the following conditions have to be satisfied:
* For every row, the smaller of the following is A: the number of 0s contained in the row, and the number of 1s contained in the row. (If these two numbers are equal, “the smaller” should be read as “either”.)
* For every column, the smaller of the following is B: the number of 0s contained in the column, and the number of 1s contained in the column.
Determine if these conditions can be satisfied by writing 0 or 1 in each of the squares. If the answer is yes, show one way to fill the squares so that the conditions are satisfied.
Constraints
* 1 \leq H,W \leq 1000
* 0 \leq A
* 2 \times A \leq W
* 0 \leq B
* 2 \times B \leq H
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
H W A B
Output
If the conditions cannot be satisfied by writing 0 or 1 in each of the squares, print -1.
If the conditions can be satisfied, print one way to fill the squares so that the conditions are satisfied, in the following format:
s_{11}s_{12}\cdots s_{1W}
s_{21}s_{22}\cdots s_{2W}
\vdots
s_{H1}s_{H2}\cdots s_{HW}
Here s_{ij} is the digit written in the square at the i-th row from the top and the j-th column from the left in the grid.
If multiple solutions exist, printing any of them will be accepted.
Examples
Input
3 3 1 1
Output
100
010
001
Input
1 5 2 0
Output
01010
Submitted Solution:
```
H,W,A,B = map(int,input().split())
for i in range(H):
if i < B:
print("0"*A + "1"*(W-A))
else:
print("1"*A + "0"*(W-A))
``` | instruction | 0 | 48,585 | 16 | 97,170 |
Yes | output | 1 | 48,585 | 16 | 97,171 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have a square grid with H rows and W columns. Snuke wants to write 0 or 1 in each of the squares. Here, all of the following conditions have to be satisfied:
* For every row, the smaller of the following is A: the number of 0s contained in the row, and the number of 1s contained in the row. (If these two numbers are equal, “the smaller” should be read as “either”.)
* For every column, the smaller of the following is B: the number of 0s contained in the column, and the number of 1s contained in the column.
Determine if these conditions can be satisfied by writing 0 or 1 in each of the squares. If the answer is yes, show one way to fill the squares so that the conditions are satisfied.
Constraints
* 1 \leq H,W \leq 1000
* 0 \leq A
* 2 \times A \leq W
* 0 \leq B
* 2 \times B \leq H
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
H W A B
Output
If the conditions cannot be satisfied by writing 0 or 1 in each of the squares, print -1.
If the conditions can be satisfied, print one way to fill the squares so that the conditions are satisfied, in the following format:
s_{11}s_{12}\cdots s_{1W}
s_{21}s_{22}\cdots s_{2W}
\vdots
s_{H1}s_{H2}\cdots s_{HW}
Here s_{ij} is the digit written in the square at the i-th row from the top and the j-th column from the left in the grid.
If multiple solutions exist, printing any of them will be accepted.
Examples
Input
3 3 1 1
Output
100
010
001
Input
1 5 2 0
Output
01010
Submitted Solution:
```
h, w, a, b = map(int, input().split())
for i in range(h):
if i < a: print("0"*a+"1"*(w-a))
else: print("1"*a+"0"*(h-a))
``` | instruction | 0 | 48,586 | 16 | 97,172 |
No | output | 1 | 48,586 | 16 | 97,173 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have a square grid with H rows and W columns. Snuke wants to write 0 or 1 in each of the squares. Here, all of the following conditions have to be satisfied:
* For every row, the smaller of the following is A: the number of 0s contained in the row, and the number of 1s contained in the row. (If these two numbers are equal, “the smaller” should be read as “either”.)
* For every column, the smaller of the following is B: the number of 0s contained in the column, and the number of 1s contained in the column.
Determine if these conditions can be satisfied by writing 0 or 1 in each of the squares. If the answer is yes, show one way to fill the squares so that the conditions are satisfied.
Constraints
* 1 \leq H,W \leq 1000
* 0 \leq A
* 2 \times A \leq W
* 0 \leq B
* 2 \times B \leq H
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
H W A B
Output
If the conditions cannot be satisfied by writing 0 or 1 in each of the squares, print -1.
If the conditions can be satisfied, print one way to fill the squares so that the conditions are satisfied, in the following format:
s_{11}s_{12}\cdots s_{1W}
s_{21}s_{22}\cdots s_{2W}
\vdots
s_{H1}s_{H2}\cdots s_{HW}
Here s_{ij} is the digit written in the square at the i-th row from the top and the j-th column from the left in the grid.
If multiple solutions exist, printing any of them will be accepted.
Examples
Input
3 3 1 1
Output
100
010
001
Input
1 5 2 0
Output
01010
Submitted Solution:
```
H,W,A,B = [int(x) for x in input().split()]
field = [[1 for i in range(W)]for j in range(H)]
for i in range(H):
for j in range(A):
field[i][j]=0
#print(field)
ones = H*W-A*H
zeros = H*W -ones
#s = (H*W-A*H)//B
#s = min(ones,zeros)//W
#print(s)
for i in range(1,H):
for j in range(W):
# field[i][j] = pre[(j+1)%W]
field[i][j] = field[i-1][(j+1)%W]
#print(field)
#print(field)
f2 = [list(x) for x in zip(*field)]
#print(f2)
for i in range(W):
# print(f2[i])
# print(f2[i].count(0))
if min(f2[i].count(0),f2[i].count(1))!=B:
print("No")
exit()
for i in range(H):
for j in range(W):
print(field[i][j],end = "")
print("")
``` | instruction | 0 | 48,587 | 16 | 97,174 |
No | output | 1 | 48,587 | 16 | 97,175 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have a square grid with H rows and W columns. Snuke wants to write 0 or 1 in each of the squares. Here, all of the following conditions have to be satisfied:
* For every row, the smaller of the following is A: the number of 0s contained in the row, and the number of 1s contained in the row. (If these two numbers are equal, “the smaller” should be read as “either”.)
* For every column, the smaller of the following is B: the number of 0s contained in the column, and the number of 1s contained in the column.
Determine if these conditions can be satisfied by writing 0 or 1 in each of the squares. If the answer is yes, show one way to fill the squares so that the conditions are satisfied.
Constraints
* 1 \leq H,W \leq 1000
* 0 \leq A
* 2 \times A \leq W
* 0 \leq B
* 2 \times B \leq H
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
H W A B
Output
If the conditions cannot be satisfied by writing 0 or 1 in each of the squares, print -1.
If the conditions can be satisfied, print one way to fill the squares so that the conditions are satisfied, in the following format:
s_{11}s_{12}\cdots s_{1W}
s_{21}s_{22}\cdots s_{2W}
\vdots
s_{H1}s_{H2}\cdots s_{HW}
Here s_{ij} is the digit written in the square at the i-th row from the top and the j-th column from the left in the grid.
If multiple solutions exist, printing any of them will be accepted.
Examples
Input
3 3 1 1
Output
100
010
001
Input
1 5 2 0
Output
01010
Submitted Solution:
```
h,w,a,b=map(int,input().split())
if(w%h!=0 or h%w!=0):
print("No")
elif(w*a/h==b or w*a/h==w-b):
print("Yes")
else:
print("No")
``` | instruction | 0 | 48,588 | 16 | 97,176 |
No | output | 1 | 48,588 | 16 | 97,177 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have a square grid with H rows and W columns. Snuke wants to write 0 or 1 in each of the squares. Here, all of the following conditions have to be satisfied:
* For every row, the smaller of the following is A: the number of 0s contained in the row, and the number of 1s contained in the row. (If these two numbers are equal, “the smaller” should be read as “either”.)
* For every column, the smaller of the following is B: the number of 0s contained in the column, and the number of 1s contained in the column.
Determine if these conditions can be satisfied by writing 0 or 1 in each of the squares. If the answer is yes, show one way to fill the squares so that the conditions are satisfied.
Constraints
* 1 \leq H,W \leq 1000
* 0 \leq A
* 2 \times A \leq W
* 0 \leq B
* 2 \times B \leq H
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
H W A B
Output
If the conditions cannot be satisfied by writing 0 or 1 in each of the squares, print -1.
If the conditions can be satisfied, print one way to fill the squares so that the conditions are satisfied, in the following format:
s_{11}s_{12}\cdots s_{1W}
s_{21}s_{22}\cdots s_{2W}
\vdots
s_{H1}s_{H2}\cdots s_{HW}
Here s_{ij} is the digit written in the square at the i-th row from the top and the j-th column from the left in the grid.
If multiple solutions exist, printing any of them will be accepted.
Examples
Input
3 3 1 1
Output
100
010
001
Input
1 5 2 0
Output
01010
Submitted Solution:
```
LL = [int(i) for i in input().split()]
H = LL[0]
W = LL[1]
A = LL[2]
B = LL[3]
Math = [[0 for a in range(W)] for b in range(H)]
for i in range(A):
for j in range(B):
Math[i][j] = 1
for i in range(W - A):
for j in range(H - B):
Math[H - i][W -j] = 1
for i in range(H):
print(*Math)
``` | instruction | 0 | 48,589 | 16 | 97,178 |
No | output | 1 | 48,589 | 16 | 97,179 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has an integer sequence A of length N.
He will freely choose an integer b. Here, he will get sad if A_i and b+i are far from each other. More specifically, the sadness of Snuke is calculated as follows:
* abs(A_1 - (b+1)) + abs(A_2 - (b+2)) + ... + abs(A_N - (b+N))
Here, abs(x) is a function that returns the absolute value of x.
Find the minimum possible sadness of Snuke.
Constraints
* 1 \leq N \leq 2 \times 10^5
* 1 \leq A_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
Output
Print the minimum possible sadness of Snuke.
Examples
Input
5
2 2 3 5 5
Output
2
Input
9
1 2 3 4 5 6 7 8 9
Output
0
Input
6
6 5 4 3 2 1
Output
18
Input
7
1 1 1 1 2 3 4
Output
6 | instruction | 0 | 49,477 | 16 | 98,954 |
"Correct Solution:
```
n = int(input())
a = list(map(int,input().split()))
b = sorted([x-i-1 for x,i in zip(a,range(n))])
print(sum([abs(x-b[n//2]) for x in b]))
``` | output | 1 | 49,477 | 16 | 98,955 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has an integer sequence A of length N.
He will freely choose an integer b. Here, he will get sad if A_i and b+i are far from each other. More specifically, the sadness of Snuke is calculated as follows:
* abs(A_1 - (b+1)) + abs(A_2 - (b+2)) + ... + abs(A_N - (b+N))
Here, abs(x) is a function that returns the absolute value of x.
Find the minimum possible sadness of Snuke.
Constraints
* 1 \leq N \leq 2 \times 10^5
* 1 \leq A_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
Output
Print the minimum possible sadness of Snuke.
Examples
Input
5
2 2 3 5 5
Output
2
Input
9
1 2 3 4 5 6 7 8 9
Output
0
Input
6
6 5 4 3 2 1
Output
18
Input
7
1 1 1 1 2 3 4
Output
6 | instruction | 0 | 49,478 | 16 | 98,956 |
"Correct Solution:
```
N = int(input())
A = list(map(int,input().split()))
x = []
X = 0
for i in range(N):
x.append(A[i]-i)
x.sort()
b = x[N//2]
for i in range(N):
X+= abs(A[i]-i-b)
print(X)
``` | output | 1 | 49,478 | 16 | 98,957 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has an integer sequence A of length N.
He will freely choose an integer b. Here, he will get sad if A_i and b+i are far from each other. More specifically, the sadness of Snuke is calculated as follows:
* abs(A_1 - (b+1)) + abs(A_2 - (b+2)) + ... + abs(A_N - (b+N))
Here, abs(x) is a function that returns the absolute value of x.
Find the minimum possible sadness of Snuke.
Constraints
* 1 \leq N \leq 2 \times 10^5
* 1 \leq A_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
Output
Print the minimum possible sadness of Snuke.
Examples
Input
5
2 2 3 5 5
Output
2
Input
9
1 2 3 4 5 6 7 8 9
Output
0
Input
6
6 5 4 3 2 1
Output
18
Input
7
1 1 1 1 2 3 4
Output
6 | instruction | 0 | 49,479 | 16 | 98,958 |
"Correct Solution:
```
n = int(input())
a = list(map(int, input().split()))
b = [a[i] - i+1 for i in range(n)]
b = list(sorted(b))
d = b[n//2]
b = [abs(b[i]-d) for i in range(n)]
print(sum(b))
``` | output | 1 | 49,479 | 16 | 98,959 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has an integer sequence A of length N.
He will freely choose an integer b. Here, he will get sad if A_i and b+i are far from each other. More specifically, the sadness of Snuke is calculated as follows:
* abs(A_1 - (b+1)) + abs(A_2 - (b+2)) + ... + abs(A_N - (b+N))
Here, abs(x) is a function that returns the absolute value of x.
Find the minimum possible sadness of Snuke.
Constraints
* 1 \leq N \leq 2 \times 10^5
* 1 \leq A_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
Output
Print the minimum possible sadness of Snuke.
Examples
Input
5
2 2 3 5 5
Output
2
Input
9
1 2 3 4 5 6 7 8 9
Output
0
Input
6
6 5 4 3 2 1
Output
18
Input
7
1 1 1 1 2 3 4
Output
6 | instruction | 0 | 49,480 | 16 | 98,960 |
"Correct Solution:
```
n = int(input())
a = sorted(int(ai) - i - 1 for i, ai in enumerate(input().split()))
b = a[int(n // 2)]
print(sum(abs(i - b) for i in a))
``` | output | 1 | 49,480 | 16 | 98,961 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has an integer sequence A of length N.
He will freely choose an integer b. Here, he will get sad if A_i and b+i are far from each other. More specifically, the sadness of Snuke is calculated as follows:
* abs(A_1 - (b+1)) + abs(A_2 - (b+2)) + ... + abs(A_N - (b+N))
Here, abs(x) is a function that returns the absolute value of x.
Find the minimum possible sadness of Snuke.
Constraints
* 1 \leq N \leq 2 \times 10^5
* 1 \leq A_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
Output
Print the minimum possible sadness of Snuke.
Examples
Input
5
2 2 3 5 5
Output
2
Input
9
1 2 3 4 5 6 7 8 9
Output
0
Input
6
6 5 4 3 2 1
Output
18
Input
7
1 1 1 1 2 3 4
Output
6 | instruction | 0 | 49,481 | 16 | 98,962 |
"Correct Solution:
```
n=int(input())
a=[int(i) for i in input().split()]
for i in range(n):
a[i]-=(i+1)
a.sort()
s=0
for i in range(n):
s+=abs(a[i]-a[int(n/2)])
print(s)
``` | output | 1 | 49,481 | 16 | 98,963 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has an integer sequence A of length N.
He will freely choose an integer b. Here, he will get sad if A_i and b+i are far from each other. More specifically, the sadness of Snuke is calculated as follows:
* abs(A_1 - (b+1)) + abs(A_2 - (b+2)) + ... + abs(A_N - (b+N))
Here, abs(x) is a function that returns the absolute value of x.
Find the minimum possible sadness of Snuke.
Constraints
* 1 \leq N \leq 2 \times 10^5
* 1 \leq A_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
Output
Print the minimum possible sadness of Snuke.
Examples
Input
5
2 2 3 5 5
Output
2
Input
9
1 2 3 4 5 6 7 8 9
Output
0
Input
6
6 5 4 3 2 1
Output
18
Input
7
1 1 1 1 2 3 4
Output
6 | instruction | 0 | 49,482 | 16 | 98,964 |
"Correct Solution:
```
n = int(input())
a = list(map(int, input().split()))
a = [a[i] - i for i in range(n)]
b = sorted(a)[n // 2]
print(sum(abs(ai - b) for ai in a))
``` | output | 1 | 49,482 | 16 | 98,965 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has an integer sequence A of length N.
He will freely choose an integer b. Here, he will get sad if A_i and b+i are far from each other. More specifically, the sadness of Snuke is calculated as follows:
* abs(A_1 - (b+1)) + abs(A_2 - (b+2)) + ... + abs(A_N - (b+N))
Here, abs(x) is a function that returns the absolute value of x.
Find the minimum possible sadness of Snuke.
Constraints
* 1 \leq N \leq 2 \times 10^5
* 1 \leq A_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
Output
Print the minimum possible sadness of Snuke.
Examples
Input
5
2 2 3 5 5
Output
2
Input
9
1 2 3 4 5 6 7 8 9
Output
0
Input
6
6 5 4 3 2 1
Output
18
Input
7
1 1 1 1 2 3 4
Output
6 | instruction | 0 | 49,483 | 16 | 98,966 |
"Correct Solution:
```
n = int(input())
t = [int(n) - i for i, n in enumerate(input().split())]
t.sort()
b = t[len(t) // 2]
print(sum([abs(n - b) for n in t]))
``` | output | 1 | 49,483 | 16 | 98,967 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has an integer sequence A of length N.
He will freely choose an integer b. Here, he will get sad if A_i and b+i are far from each other. More specifically, the sadness of Snuke is calculated as follows:
* abs(A_1 - (b+1)) + abs(A_2 - (b+2)) + ... + abs(A_N - (b+N))
Here, abs(x) is a function that returns the absolute value of x.
Find the minimum possible sadness of Snuke.
Constraints
* 1 \leq N \leq 2 \times 10^5
* 1 \leq A_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
Output
Print the minimum possible sadness of Snuke.
Examples
Input
5
2 2 3 5 5
Output
2
Input
9
1 2 3 4 5 6 7 8 9
Output
0
Input
6
6 5 4 3 2 1
Output
18
Input
7
1 1 1 1 2 3 4
Output
6 | instruction | 0 | 49,484 | 16 | 98,968 |
"Correct Solution:
```
n=int(input())
lst=list(map(int,input().split()))
for i in range(n):
lst[i] = lst[i] - 1 - i
lst.sort()
b=lst[n//2]
print(sum([abs(b - lst[j]) for j in range(n)]))
``` | output | 1 | 49,484 | 16 | 98,969 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has an integer sequence A of length N.
He will freely choose an integer b. Here, he will get sad if A_i and b+i are far from each other. More specifically, the sadness of Snuke is calculated as follows:
* abs(A_1 - (b+1)) + abs(A_2 - (b+2)) + ... + abs(A_N - (b+N))
Here, abs(x) is a function that returns the absolute value of x.
Find the minimum possible sadness of Snuke.
Constraints
* 1 \leq N \leq 2 \times 10^5
* 1 \leq A_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
Output
Print the minimum possible sadness of Snuke.
Examples
Input
5
2 2 3 5 5
Output
2
Input
9
1 2 3 4 5 6 7 8 9
Output
0
Input
6
6 5 4 3 2 1
Output
18
Input
7
1 1 1 1 2 3 4
Output
6
Submitted Solution:
```
N=int(input())
A=list(map(int,input().split()))
for i in range(N):
A[i]-=i
A.sort()
m=A[N//2]
s=0
for i in range(N):
s+=abs(A[i]-m)
print(s)
``` | instruction | 0 | 49,485 | 16 | 98,970 |
Yes | output | 1 | 49,485 | 16 | 98,971 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has an integer sequence A of length N.
He will freely choose an integer b. Here, he will get sad if A_i and b+i are far from each other. More specifically, the sadness of Snuke is calculated as follows:
* abs(A_1 - (b+1)) + abs(A_2 - (b+2)) + ... + abs(A_N - (b+N))
Here, abs(x) is a function that returns the absolute value of x.
Find the minimum possible sadness of Snuke.
Constraints
* 1 \leq N \leq 2 \times 10^5
* 1 \leq A_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
Output
Print the minimum possible sadness of Snuke.
Examples
Input
5
2 2 3 5 5
Output
2
Input
9
1 2 3 4 5 6 7 8 9
Output
0
Input
6
6 5 4 3 2 1
Output
18
Input
7
1 1 1 1 2 3 4
Output
6
Submitted Solution:
```
n = int(input())
l = list(map(int,input().split()))
l = list(l[i]-i for i in range(n))
import statistics as st
m = int(st.median(l))
print(sum(abs(m-i) for i in l))
``` | instruction | 0 | 49,486 | 16 | 98,972 |
Yes | output | 1 | 49,486 | 16 | 98,973 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has an integer sequence A of length N.
He will freely choose an integer b. Here, he will get sad if A_i and b+i are far from each other. More specifically, the sadness of Snuke is calculated as follows:
* abs(A_1 - (b+1)) + abs(A_2 - (b+2)) + ... + abs(A_N - (b+N))
Here, abs(x) is a function that returns the absolute value of x.
Find the minimum possible sadness of Snuke.
Constraints
* 1 \leq N \leq 2 \times 10^5
* 1 \leq A_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
Output
Print the minimum possible sadness of Snuke.
Examples
Input
5
2 2 3 5 5
Output
2
Input
9
1 2 3 4 5 6 7 8 9
Output
0
Input
6
6 5 4 3 2 1
Output
18
Input
7
1 1 1 1 2 3 4
Output
6
Submitted Solution:
```
n = int(input())
a = list(map(int, input().split()))
a = [a[i] - (i+1) for i in range(len(a))]
b = sorted(a)[int(n/2)]
print(sum([abs(i-b) for i in a]))
``` | instruction | 0 | 49,487 | 16 | 98,974 |
Yes | output | 1 | 49,487 | 16 | 98,975 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has an integer sequence A of length N.
He will freely choose an integer b. Here, he will get sad if A_i and b+i are far from each other. More specifically, the sadness of Snuke is calculated as follows:
* abs(A_1 - (b+1)) + abs(A_2 - (b+2)) + ... + abs(A_N - (b+N))
Here, abs(x) is a function that returns the absolute value of x.
Find the minimum possible sadness of Snuke.
Constraints
* 1 \leq N \leq 2 \times 10^5
* 1 \leq A_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
Output
Print the minimum possible sadness of Snuke.
Examples
Input
5
2 2 3 5 5
Output
2
Input
9
1 2 3 4 5 6 7 8 9
Output
0
Input
6
6 5 4 3 2 1
Output
18
Input
7
1 1 1 1 2 3 4
Output
6
Submitted Solution:
```
N = int(input())
A = list(map(int, input().split()))
A = [A[i] - i for i in range(N)]
A.sort()
b = A[N // 2]
c = 0
for i in range(N):
c += abs(A[i] - b)
print(c)
``` | instruction | 0 | 49,488 | 16 | 98,976 |
Yes | output | 1 | 49,488 | 16 | 98,977 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has an integer sequence A of length N.
He will freely choose an integer b. Here, he will get sad if A_i and b+i are far from each other. More specifically, the sadness of Snuke is calculated as follows:
* abs(A_1 - (b+1)) + abs(A_2 - (b+2)) + ... + abs(A_N - (b+N))
Here, abs(x) is a function that returns the absolute value of x.
Find the minimum possible sadness of Snuke.
Constraints
* 1 \leq N \leq 2 \times 10^5
* 1 \leq A_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
Output
Print the minimum possible sadness of Snuke.
Examples
Input
5
2 2 3 5 5
Output
2
Input
9
1 2 3 4 5 6 7 8 9
Output
0
Input
6
6 5 4 3 2 1
Output
18
Input
7
1 1 1 1 2 3 4
Output
6
Submitted Solution:
```
n = int(input().strip())
a = list(map(int, input().split()))
b = int(sum(a) / n) - ((n + 1) / 2)
ans = 0
for i in range(1, (n + 1), 1):
ans += abs(a[i - 1] - (b + i))
print(int(ans))
``` | instruction | 0 | 49,489 | 16 | 98,978 |
No | output | 1 | 49,489 | 16 | 98,979 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has an integer sequence A of length N.
He will freely choose an integer b. Here, he will get sad if A_i and b+i are far from each other. More specifically, the sadness of Snuke is calculated as follows:
* abs(A_1 - (b+1)) + abs(A_2 - (b+2)) + ... + abs(A_N - (b+N))
Here, abs(x) is a function that returns the absolute value of x.
Find the minimum possible sadness of Snuke.
Constraints
* 1 \leq N \leq 2 \times 10^5
* 1 \leq A_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
Output
Print the minimum possible sadness of Snuke.
Examples
Input
5
2 2 3 5 5
Output
2
Input
9
1 2 3 4 5 6 7 8 9
Output
0
Input
6
6 5 4 3 2 1
Output
18
Input
7
1 1 1 1 2 3 4
Output
6
Submitted Solution:
```
# ai-iの数が一番多いやつをbにすればいけそう(いちばん余剰分を殺せるので) 複数あったら全部試せ
n = int(input())
arr = list(map(int, input().split()))
d = {}
for i in range(n):
t = arr[i] - (i + 1)
if t in d:
d[t] += 1
else:
d[t] = 1
d = sorted(d.items(), key=lambda x: x[1], reverse=True)
max_v = d[0][1]
ans = 10 ** 10
for k, v in d:
if v != max_v:
break
tmp = 0
for i in range(n):
tmp += abs(arr[i] - (k + i + 1))
ans = min(ans, tmp)
print(ans)
``` | instruction | 0 | 49,490 | 16 | 98,980 |
No | output | 1 | 49,490 | 16 | 98,981 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has an integer sequence A of length N.
He will freely choose an integer b. Here, he will get sad if A_i and b+i are far from each other. More specifically, the sadness of Snuke is calculated as follows:
* abs(A_1 - (b+1)) + abs(A_2 - (b+2)) + ... + abs(A_N - (b+N))
Here, abs(x) is a function that returns the absolute value of x.
Find the minimum possible sadness of Snuke.
Constraints
* 1 \leq N \leq 2 \times 10^5
* 1 \leq A_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
Output
Print the minimum possible sadness of Snuke.
Examples
Input
5
2 2 3 5 5
Output
2
Input
9
1 2 3 4 5 6 7 8 9
Output
0
Input
6
6 5 4 3 2 1
Output
18
Input
7
1 1 1 1 2 3 4
Output
6
Submitted Solution:
```
#!/usr/bin/env python3
import sys
def solve(N: int, A: "List[int]"):
for i in range(N):
A[i] -= i + 1
s = sum(A)
x = s // N
ret = [0, 0, 0]
for a in A:
ret[0] += abs(a - (x - 1))
ret[1] += abs(a - (x))
ret[2] += abs(a - (x + 1))
ret = min(ret)
print(ret)
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
A = [ int(next(tokens)) for _ in range(N) ] # type: "List[int]"
solve(N, A)
if __name__ == '__main__':
main()
``` | instruction | 0 | 49,491 | 16 | 98,982 |
No | output | 1 | 49,491 | 16 | 98,983 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has an integer sequence A of length N.
He will freely choose an integer b. Here, he will get sad if A_i and b+i are far from each other. More specifically, the sadness of Snuke is calculated as follows:
* abs(A_1 - (b+1)) + abs(A_2 - (b+2)) + ... + abs(A_N - (b+N))
Here, abs(x) is a function that returns the absolute value of x.
Find the minimum possible sadness of Snuke.
Constraints
* 1 \leq N \leq 2 \times 10^5
* 1 \leq A_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
Output
Print the minimum possible sadness of Snuke.
Examples
Input
5
2 2 3 5 5
Output
2
Input
9
1 2 3 4 5 6 7 8 9
Output
0
Input
6
6 5 4 3 2 1
Output
18
Input
7
1 1 1 1 2 3 4
Output
6
Submitted Solution:
```
n = int(input())
a = list(map(int, input().split()))
c = []
for i in range(n):
c.append(a[i] - (i + 1))
ave = sum(c)//n
ans = 10**14*n
for b in range(ave-100, ave+100):
t = 0
for i in range(n):
t += abs(c[i]-b)
ans = min(ans, t)
print(ans)
``` | instruction | 0 | 49,492 | 16 | 98,984 |
No | output | 1 | 49,492 | 16 | 98,985 |
Provide a correct Python 3 solution for this coding contest problem.
We have a board with an H \times W grid. Each square in the grid is painted in black or white. The square at the i-th row from the top and j-th column from the left is black if the j-th character in S_i is `#`, and white if that character is `.`.
Snuke can perform the following operation on the grid any number of times:
* Select a row or column in the grid, and invert the color of all the squares in that row or column (that is, black squares become white and vice versa).
Then, Snuke draws a rectangle along grid lines. Here, all the squares contained in the rectangle must be painted in black.
Find the maximum possible area of Snuke's rectangle when the operation is performed optimally.
Constraints
* 2 \leq H \leq 2000
* 2 \leq W \leq 2000
* |S_i| = W
* S_i consists of `#` and `.`.
Input
Input is given from Standard Input in the following format:
H W
S_1
S_2
:
S_H
Output
Print the maximum possible area of Snuke's rectangle.
Examples
Input
3 3
..#
##.
.#.
Output
6
Input
3 3
..#
.
.#.
Output
6
Input
4 4
....
....
....
....
Output
16
Input
10 8
...#.#
...#.#
..###.#.
.##.#.#
.#..#.#.
..##.#.#
.#.#..
...#.#..
.#.##
..###
Output
27 | instruction | 0 | 49,493 | 16 | 98,986 |
"Correct Solution:
```
H, W = map(int, input().split())
S = [input() for _ in range(H)]
ans = max(H, W)
f = [1] * W
for i in range(1, H):
f = [(f[j]+1) if (S[i-1][j:j+2] + S[i][j:j+2]).count('#') in [0,2,4] else 1 for j in range(W-1)] + [0]
stk = []
for j, v in enumerate(f):
while len(stk) > 0 and f[stk[-1]] >= v:
ans = max(ans, f[stk.pop()] * (j - (stk[-1] if len(stk) > 0 else -1)))
stk.append(j)
print(ans)
``` | output | 1 | 49,493 | 16 | 98,987 |
Provide a correct Python 3 solution for this coding contest problem.
We have a board with an H \times W grid. Each square in the grid is painted in black or white. The square at the i-th row from the top and j-th column from the left is black if the j-th character in S_i is `#`, and white if that character is `.`.
Snuke can perform the following operation on the grid any number of times:
* Select a row or column in the grid, and invert the color of all the squares in that row or column (that is, black squares become white and vice versa).
Then, Snuke draws a rectangle along grid lines. Here, all the squares contained in the rectangle must be painted in black.
Find the maximum possible area of Snuke's rectangle when the operation is performed optimally.
Constraints
* 2 \leq H \leq 2000
* 2 \leq W \leq 2000
* |S_i| = W
* S_i consists of `#` and `.`.
Input
Input is given from Standard Input in the following format:
H W
S_1
S_2
:
S_H
Output
Print the maximum possible area of Snuke's rectangle.
Examples
Input
3 3
..#
##.
.#.
Output
6
Input
3 3
..#
.
.#.
Output
6
Input
4 4
....
....
....
....
Output
16
Input
10 8
...#.#
...#.#
..###.#.
.##.#.#
.#..#.#.
..##.#.#
.#.#..
...#.#..
.#.##
..###
Output
27 | instruction | 0 | 49,494 | 16 | 98,988 |
"Correct Solution:
```
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
"""
・2x2内の偶奇が不変量。これが偶数なら、そこは単色でとれる
・単色でとれる領域を調べる -> 色変更なしに大きい長方形をとる問題になる
・ベースラインを固定すると、ヒストグラムの長方形の問題(アリ本)
"""
H,W = map(int,readline().split())
grid = read().replace(b'\r',b'').replace(b'\n',b'')
H,W
# 左上に集める
cnt = [0]*(H*W)
for x in range(H*W):
if grid[x]==ord('#'):
# その場
cnt[x]^=1
# 左
if x%W:
cnt[x-1]^=1
# 上
if x>=W:
cnt[x-W]^=1
if x%W and x>=W:
cnt[x-W-1]^=1
max_area = 0
height = [1]*(W-1)
for i in range(H-1):
for j in range(W-1):
if cnt[W*i+j]:
height[j]=1
else:
height[j]+=1
# 最大長方形の変種。
stack=[]
for j,h in enumerate(height+[0]):
while stack:
prev_h = height[stack[-1]]
if prev_h < h:
break
stack.pop()
left_end = -1 if not stack else stack[-1]
area = (j-left_end)*prev_h
if max_area < area:
max_area = area
stack.append(j)
# 幅1の長方形は2x2を素材としない
if max_area < max(W,H):
max_area = max(W,H)
print(max_area)
``` | output | 1 | 49,494 | 16 | 98,989 |
Provide a correct Python 3 solution for this coding contest problem.
We have a board with an H \times W grid. Each square in the grid is painted in black or white. The square at the i-th row from the top and j-th column from the left is black if the j-th character in S_i is `#`, and white if that character is `.`.
Snuke can perform the following operation on the grid any number of times:
* Select a row or column in the grid, and invert the color of all the squares in that row or column (that is, black squares become white and vice versa).
Then, Snuke draws a rectangle along grid lines. Here, all the squares contained in the rectangle must be painted in black.
Find the maximum possible area of Snuke's rectangle when the operation is performed optimally.
Constraints
* 2 \leq H \leq 2000
* 2 \leq W \leq 2000
* |S_i| = W
* S_i consists of `#` and `.`.
Input
Input is given from Standard Input in the following format:
H W
S_1
S_2
:
S_H
Output
Print the maximum possible area of Snuke's rectangle.
Examples
Input
3 3
..#
##.
.#.
Output
6
Input
3 3
..#
.
.#.
Output
6
Input
4 4
....
....
....
....
Output
16
Input
10 8
...#.#
...#.#
..###.#.
.##.#.#
.#..#.#.
..##.#.#
.#.#..
...#.#..
.#.##
..###
Output
27 | instruction | 0 | 49,495 | 16 | 98,990 |
"Correct Solution:
```
from collections import deque
H,W=map(int,input().split())
S=[input() for i in range(H)]
table=[[0]*(W-1) for i in range(H-1)]
for i in range(W-1):
for j in range(H-1):
table[j][i]=(int(S[j][i]=='#')+int(S[j+1][i]=='#')+int(S[j][i+1]=='#')+int(S[j+1][i+1]=='#') +1 )%2
def get_rec(L):
a = len(L)
arr = L + [0]
stack = deque()
ans = -1
for i in range(a + 1):
#print(stack)
if len(stack)==0:
stack.append((arr[i], i))
elif stack[-1][0] < arr[i]:
stack.append((arr[i], i))
elif stack[-1][0] > arr[i]:
while len(stack) != 0 and stack[-1][0] >= arr[i]:
x, y = stack.pop()
ans = max((x+1) * (i - y+1), ans)
# print(x,y,x*(i-y))
stack.append((arr[i], y))
#print(ans)
return ans
dp=[[0]*(W-1) for i in range(H-1)]
for i in range(W-1):
for j in range(H-1):
if j==0:
dp[0][i]=table[0][i]
continue
if table[j][i]==1:
dp[j][i]=dp[j-1][i]+1
ans=max(H,W)
for j in range(H-1):
ans=max(ans,get_rec(dp[j]))
print(ans)
``` | output | 1 | 49,495 | 16 | 98,991 |
Provide a correct Python 3 solution for this coding contest problem.
We have a board with an H \times W grid. Each square in the grid is painted in black or white. The square at the i-th row from the top and j-th column from the left is black if the j-th character in S_i is `#`, and white if that character is `.`.
Snuke can perform the following operation on the grid any number of times:
* Select a row or column in the grid, and invert the color of all the squares in that row or column (that is, black squares become white and vice versa).
Then, Snuke draws a rectangle along grid lines. Here, all the squares contained in the rectangle must be painted in black.
Find the maximum possible area of Snuke's rectangle when the operation is performed optimally.
Constraints
* 2 \leq H \leq 2000
* 2 \leq W \leq 2000
* |S_i| = W
* S_i consists of `#` and `.`.
Input
Input is given from Standard Input in the following format:
H W
S_1
S_2
:
S_H
Output
Print the maximum possible area of Snuke's rectangle.
Examples
Input
3 3
..#
##.
.#.
Output
6
Input
3 3
..#
.
.#.
Output
6
Input
4 4
....
....
....
....
Output
16
Input
10 8
...#.#
...#.#
..###.#.
.##.#.#
.#..#.#.
..##.#.#
.#.#..
...#.#..
.#.##
..###
Output
27 | instruction | 0 | 49,496 | 16 | 98,992 |
"Correct Solution:
```
def inpl(): return [int(i) for i in input().split()]
H, W = inpl()
ans = max(H, W)
S = [input() for _ in range(H)]
T = [[0]*(W-1)]
for i in range(H-1):
t = []
for j in range(W-1):
r = S[i][j:j+2] + S[i+1][j:j+2]
t.append(r.count('.')%2)
ts = [T[-1][i] + 1 if not k else 0 for i, k in enumerate(t) ]
T.append(ts)
for iT in T[1:]:
stack = []
for i, l in enumerate(iT+[0]):
dw = -1
while stack and stack[-1][1] >= l:
dw, dh = stack.pop()
ans = max(ans, (dh+1)*(i-dw+1))
if dw != -1:
stack.append((dw,l))
continue
stack.append((i, l))
print(ans)
``` | output | 1 | 49,496 | 16 | 98,993 |
Provide a correct Python 3 solution for this coding contest problem.
We have a board with an H \times W grid. Each square in the grid is painted in black or white. The square at the i-th row from the top and j-th column from the left is black if the j-th character in S_i is `#`, and white if that character is `.`.
Snuke can perform the following operation on the grid any number of times:
* Select a row or column in the grid, and invert the color of all the squares in that row or column (that is, black squares become white and vice versa).
Then, Snuke draws a rectangle along grid lines. Here, all the squares contained in the rectangle must be painted in black.
Find the maximum possible area of Snuke's rectangle when the operation is performed optimally.
Constraints
* 2 \leq H \leq 2000
* 2 \leq W \leq 2000
* |S_i| = W
* S_i consists of `#` and `.`.
Input
Input is given from Standard Input in the following format:
H W
S_1
S_2
:
S_H
Output
Print the maximum possible area of Snuke's rectangle.
Examples
Input
3 3
..#
##.
.#.
Output
6
Input
3 3
..#
.
.#.
Output
6
Input
4 4
....
....
....
....
Output
16
Input
10 8
...#.#
...#.#
..###.#.
.##.#.#
.#..#.#.
..##.#.#
.#.#..
...#.#..
.#.##
..###
Output
27 | instruction | 0 | 49,497 | 16 | 98,994 |
"Correct Solution:
```
H,W=map(int,input().split())
ans=max(H, W)
S=[input() for i in range(H)]
T = [[0]*(W-1)]
for i in range(H-1):
t,ts=[],[]
for j in range(W-1):
r=S[i][j:j+2]+S[i+1][j:j+2]
t.append(r.count('.')%2)
if t[j]==0:
ts.append(T[-1][j]+1)
else:
ts.append(0)
T.append(ts)
for L in T[1:]:
stack=[]
for i,l in enumerate(L+[0]):
w=-1
while stack and stack[-1][1]>=l:
w,h=stack.pop()
ans = max(ans, (h+1)*(i-w+1))
if w!=-1:
stack.append((w,l))
continue
stack.append((i,l))
print(ans)
``` | output | 1 | 49,497 | 16 | 98,995 |
Provide a correct Python 3 solution for this coding contest problem.
We have a board with an H \times W grid. Each square in the grid is painted in black or white. The square at the i-th row from the top and j-th column from the left is black if the j-th character in S_i is `#`, and white if that character is `.`.
Snuke can perform the following operation on the grid any number of times:
* Select a row or column in the grid, and invert the color of all the squares in that row or column (that is, black squares become white and vice versa).
Then, Snuke draws a rectangle along grid lines. Here, all the squares contained in the rectangle must be painted in black.
Find the maximum possible area of Snuke's rectangle when the operation is performed optimally.
Constraints
* 2 \leq H \leq 2000
* 2 \leq W \leq 2000
* |S_i| = W
* S_i consists of `#` and `.`.
Input
Input is given from Standard Input in the following format:
H W
S_1
S_2
:
S_H
Output
Print the maximum possible area of Snuke's rectangle.
Examples
Input
3 3
..#
##.
.#.
Output
6
Input
3 3
..#
.
.#.
Output
6
Input
4 4
....
....
....
....
Output
16
Input
10 8
...#.#
...#.#
..###.#.
.##.#.#
.#..#.#.
..##.#.#
.#.#..
...#.#..
.#.##
..###
Output
27 | instruction | 0 | 49,498 | 16 | 98,996 |
"Correct Solution:
```
import sys
input=sys.stdin.readline
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def main():
h, w = MI()
s = [[c == "#" for c in input()[:-1]] for _ in range(h)]
#if w == 2:
# s = [list(sc) for sc in zip(*s)]
# h, w = w, h
# p2D(s)
t = [[-1] * (w - 1) for _ in range(h - 1)]
for i in range(h - 1):
si = s[i]
si1 = s[i + 1]
t[i] = [1 - (sum(si[j:j + 2]) + sum(si1[j:j + 2])) % 2 for j in range(w - 1)]
# p2D(t)
# print()
ti=t[0]
for i in range(1, h - 1):
ti1=ti
ti=t[i]
for j in range(w - 1):
if ti[j]: ti[j] = ti1[j] + 1
# p2D(t)
ans = 0
for i in range(h - 1):
jtol = [0] * (w - 1)
jtor = [0] * (w - 1)
ti=t[i]
# 高さ、位置の順
stack = [[-1, 0]]
for j in range(w - 1):
tij=ti[j]
while stack[-1][0] >= tij: stack.pop()
jtol[j] = stack[-1][1]
stack.append([tij, j + 1])
stack = [[-1, w - 1]]
for j in range(w - 2, -1, -1):
tij=ti[j]
while stack[-1][0] >= tij: stack.pop()
jtor[j] = stack[-1][1]
stack.append([tij, j])
for j in range(w - 1):
tmp = (jtor[j] - jtol[j] + 1) * (ti[j] + 1)
if tmp > ans: ans = tmp
print(max(ans,h,w))
main()
``` | output | 1 | 49,498 | 16 | 98,997 |
Provide a correct Python 3 solution for this coding contest problem.
We have a board with an H \times W grid. Each square in the grid is painted in black or white. The square at the i-th row from the top and j-th column from the left is black if the j-th character in S_i is `#`, and white if that character is `.`.
Snuke can perform the following operation on the grid any number of times:
* Select a row or column in the grid, and invert the color of all the squares in that row or column (that is, black squares become white and vice versa).
Then, Snuke draws a rectangle along grid lines. Here, all the squares contained in the rectangle must be painted in black.
Find the maximum possible area of Snuke's rectangle when the operation is performed optimally.
Constraints
* 2 \leq H \leq 2000
* 2 \leq W \leq 2000
* |S_i| = W
* S_i consists of `#` and `.`.
Input
Input is given from Standard Input in the following format:
H W
S_1
S_2
:
S_H
Output
Print the maximum possible area of Snuke's rectangle.
Examples
Input
3 3
..#
##.
.#.
Output
6
Input
3 3
..#
.
.#.
Output
6
Input
4 4
....
....
....
....
Output
16
Input
10 8
...#.#
...#.#
..###.#.
.##.#.#
.#..#.#.
..##.#.#
.#.#..
...#.#..
.#.##
..###
Output
27 | instruction | 0 | 49,499 | 16 | 98,998 |
"Correct Solution:
```
import sys
input = sys.stdin.readline
from collections import deque
h,w = map(int,input().split())
s = []
for i in range(h):
q = input().rstrip()
s.append(q)
chk = [[0]*(w-1) for i in range(h-1)]
for i in range(w-1):
for j in range(h-1):
chk[j][i] = 1-int((s[j][i]=='#')^(s[j+1][i]=='#')^(s[j][i+1]=='#')^(s[j+1][i+1]=='#'))
def f(a):
a += [0]
stack = deque()
ans = -1
for i in range(w):
if stack == deque():
stack.append((a[i], i))
elif stack[-1][0] < a[i]:
stack.append((a[i], i))
elif stack[-1][0] > a[i]:
while stack and stack[-1][0] >= a[i]:
x, y = stack.pop()
ans = max((x+1)*(i-y+1), ans)
stack.append((a[i], y))
return ans
dp = [[0]*(w-1) for i in range(h-1)]
for i in range(w-1):
dp[0][i] = chk[0][i]
for i in range(1,h-1):
for j in range(w-1):
if chk[i][j]:
dp[i][j] = dp[i-1][j]+1
ans=max(h,w)
for i in range(h-1):
ans=max(ans,f(dp[i]))
print(ans)
``` | output | 1 | 49,499 | 16 | 98,999 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have a board with an H \times W grid. Each square in the grid is painted in black or white. The square at the i-th row from the top and j-th column from the left is black if the j-th character in S_i is `#`, and white if that character is `.`.
Snuke can perform the following operation on the grid any number of times:
* Select a row or column in the grid, and invert the color of all the squares in that row or column (that is, black squares become white and vice versa).
Then, Snuke draws a rectangle along grid lines. Here, all the squares contained in the rectangle must be painted in black.
Find the maximum possible area of Snuke's rectangle when the operation is performed optimally.
Constraints
* 2 \leq H \leq 2000
* 2 \leq W \leq 2000
* |S_i| = W
* S_i consists of `#` and `.`.
Input
Input is given from Standard Input in the following format:
H W
S_1
S_2
:
S_H
Output
Print the maximum possible area of Snuke's rectangle.
Examples
Input
3 3
..#
##.
.#.
Output
6
Input
3 3
..#
.
.#.
Output
6
Input
4 4
....
....
....
....
Output
16
Input
10 8
...#.#
...#.#
..###.#.
.##.#.#
.#..#.#.
..##.#.#
.#.#..
...#.#..
.#.##
..###
Output
27
Submitted Solution:
```
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def main():
h, w = MI()
s = [[c == "#" for c in input()[:-1]] for _ in range(h)]
if w == 2:
s = [list(sc) for sc in zip(*s)]
h, w = w, h
# p2D(s)
t = [[-1] * (w - 1) for _ in range(h - 1)]
for i in range(h - 1):
si = s[i]
si1 = s[i + 1]
t[i] = [1 - (sum(si[j:j + 2]) + sum(si1[j:j + 2])) % 2 for j in range(w - 1)]
# p2D(t)
# print()
ti=t[0]
for i in range(1, h - 1):
ti1=ti
ti=t[i]
for j in range(w - 1):
if ti[j]: ti[j] = ti1[j] + 1
# p2D(t)
ans = 0
for i in range(h - 1):
jtol = [0] * (w - 1)
jtor = [0] * (w - 1)
ti=t[i]
# 高さ、位置の順
stack = [[-1, 0]]
for j in range(w - 1):
h=ti[j]
while stack[-1][0] >= h: stack.pop()
jtol[j] = stack[-1][1]
stack.append([h, j + 1])
stack = [[-1, w - 1]]
for j in range(w - 2, -1, -1):
h=ti[j]
while stack[-1][0] >= h: stack.pop()
jtor[j] = stack[-1][1]
stack.append([h, j])
for j in range(w - 1):
tmp = (jtor[j] - jtol[j] + 1) * (ti[j] + 1)
if tmp > ans: ans = tmp
print(ans)
main()
``` | instruction | 0 | 49,500 | 16 | 99,000 |
No | output | 1 | 49,500 | 16 | 99,001 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have a board with an H \times W grid. Each square in the grid is painted in black or white. The square at the i-th row from the top and j-th column from the left is black if the j-th character in S_i is `#`, and white if that character is `.`.
Snuke can perform the following operation on the grid any number of times:
* Select a row or column in the grid, and invert the color of all the squares in that row or column (that is, black squares become white and vice versa).
Then, Snuke draws a rectangle along grid lines. Here, all the squares contained in the rectangle must be painted in black.
Find the maximum possible area of Snuke's rectangle when the operation is performed optimally.
Constraints
* 2 \leq H \leq 2000
* 2 \leq W \leq 2000
* |S_i| = W
* S_i consists of `#` and `.`.
Input
Input is given from Standard Input in the following format:
H W
S_1
S_2
:
S_H
Output
Print the maximum possible area of Snuke's rectangle.
Examples
Input
3 3
..#
##.
.#.
Output
6
Input
3 3
..#
.
.#.
Output
6
Input
4 4
....
....
....
....
Output
16
Input
10 8
...#.#
...#.#
..###.#.
.##.#.#
.#..#.#.
..##.#.#
.#.#..
...#.#..
.#.##
..###
Output
27
Submitted Solution:
```
"""
Writer: SPD_9X2
https://atcoder.jp/contests/arc081/tasks/arc081_d
長方形にできる必要十分条件は、
内側にある四つ角の周り全てに関して、周りにある黒が偶数個
→そのような条件を満たす四つ角グリッドを考えると最大長方形になる
幅1の長方形に関しては全て作れるので、ans初期値はmax(H,W)
"""
def Largest_rectangle_in_histgram(lis):
stk = []
ans = 0
N = len(lis)
for i in range(N):
if len(stk) == 0:
stk.append((lis[i],i))
elif stk[-1][0] < lis[i]:
stk.append((lis[i],i))
elif stk[-1][0] == lis[i]:
pass
else:
lastpos = None
while len(stk) > 0 and stk[-1][0] > lis[i]:
nh,np = stk[-1]
lastpos = np
del stk[-1]
ans = max(ans , (nh+1) * (i-np+1))
stk.append((lis[i] , lastpos))
return ans
H,W = map(int,input().split())
S = []
for i in range(H):
s = list(input())
S.append(s)
#2*2以上
lis = [ [0] * (W-1) for i in range(H-1) ]
for i in range(H-1):
for j in range(W-1):
if S[i][j] == "#":
lis[i][j] += 1
if S[i+1][j] == "#":
lis[i][j] += 1
if S[i][j+1] == "#":
lis[i][j] += 1
if S[i+1][j+1] == "#":
lis[i][j] += 1
lis[i][j] %= 2
del S
hist = [ [0] * W for i in range(H-1) ]
for i in range(H-1):
for j in range(W-1):
if lis[i][j] == 1:
continue
elif i == 0:
hist[i][j] = 1
else:
hist[i][j] = hist[i-1][j] + 1
del lis
ans = max(H,W)
for i in range(H-1):
ans = max(ans , Largest_rectangle_in_histgram(hist[i]))
print (ans)
``` | instruction | 0 | 49,501 | 16 | 99,002 |
No | output | 1 | 49,501 | 16 | 99,003 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have a board with an H \times W grid. Each square in the grid is painted in black or white. The square at the i-th row from the top and j-th column from the left is black if the j-th character in S_i is `#`, and white if that character is `.`.
Snuke can perform the following operation on the grid any number of times:
* Select a row or column in the grid, and invert the color of all the squares in that row or column (that is, black squares become white and vice versa).
Then, Snuke draws a rectangle along grid lines. Here, all the squares contained in the rectangle must be painted in black.
Find the maximum possible area of Snuke's rectangle when the operation is performed optimally.
Constraints
* 2 \leq H \leq 2000
* 2 \leq W \leq 2000
* |S_i| = W
* S_i consists of `#` and `.`.
Input
Input is given from Standard Input in the following format:
H W
S_1
S_2
:
S_H
Output
Print the maximum possible area of Snuke's rectangle.
Examples
Input
3 3
..#
##.
.#.
Output
6
Input
3 3
..#
.
.#.
Output
6
Input
4 4
....
....
....
....
Output
16
Input
10 8
...#.#
...#.#
..###.#.
.##.#.#
.#..#.#.
..##.#.#
.#.#..
...#.#..
.#.##
..###
Output
27
Submitted Solution:
```
def inpl(): return [int(i) for i in input().split()]
H, W = inpl()
ans = max(H, W)
S = [input() for _ in range(H)]
T = [[0]*(W-1)]
for i in range(H-1):
t = []
for j in range(W-1):
r = S[i][j:j+2] + S[i+1][j:j+2]
t.append(r.count('.')%2)
ts = [T[-1][i] + 1 if not k else 0 for i, k in enumerate(t) ]
T.append(ts)
for iT in T[1:]:
stack = []
for i, l in enumerate(iT):
while stack:
w, h = stack[-1]
if h > l:
dw, dh = stack.pop()
ans = max(ans, (dh+1)*(i-dw+1))
continue
break
stack.append((i, l))
while stack:
dw, dh = stack.pop()
ans = max(ans, (dh+1)*(i-dw+2))
print(ans)
``` | instruction | 0 | 49,502 | 16 | 99,004 |
No | output | 1 | 49,502 | 16 | 99,005 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have a board with an H \times W grid. Each square in the grid is painted in black or white. The square at the i-th row from the top and j-th column from the left is black if the j-th character in S_i is `#`, and white if that character is `.`.
Snuke can perform the following operation on the grid any number of times:
* Select a row or column in the grid, and invert the color of all the squares in that row or column (that is, black squares become white and vice versa).
Then, Snuke draws a rectangle along grid lines. Here, all the squares contained in the rectangle must be painted in black.
Find the maximum possible area of Snuke's rectangle when the operation is performed optimally.
Constraints
* 2 \leq H \leq 2000
* 2 \leq W \leq 2000
* |S_i| = W
* S_i consists of `#` and `.`.
Input
Input is given from Standard Input in the following format:
H W
S_1
S_2
:
S_H
Output
Print the maximum possible area of Snuke's rectangle.
Examples
Input
3 3
..#
##.
.#.
Output
6
Input
3 3
..#
.
.#.
Output
6
Input
4 4
....
....
....
....
Output
16
Input
10 8
...#.#
...#.#
..###.#.
.##.#.#
.#..#.#.
..##.#.#
.#.#..
...#.#..
.#.##
..###
Output
27
Submitted Solution:
```
"""
Writer: SPD_9X2
https://atcoder.jp/contests/arc081/tasks/arc081_d
長方形にできる必要十分条件は、
内側にある四つ角の周り全てに関して、周りにある黒が偶数個
→そのような条件を満たす四つ角グリッドを考えると最大長方形になる
幅1の長方形に関しては全て作れるので、ans初期値はmax(H,W)
"""
def Largest_rectangle_in_histgram(lis):
stk = []
ans = 0
N = len(lis)
for i in range(N):
if len(stk) == 0:
stk.append((lis[i],i))
elif stk[-1][0] < lis[i]:
stk.append((lis[i],i))
elif stk[-1][0] == lis[i]:
pass
else:
lastpos = None
while len(stk) > 0 and stk[-1][0] > lis[i]:
nh,np = stk[-1]
lastpos = np
del stk[-1]
ans = max(ans , (nh+1) * (i-np+1))
stk.append((lis[i] , lastpos))
return ans
H,W = map(int,input().split())
S = []
for i in range(H):
s = list(input())
S.append(s)
#2*2以上
lis = [ [0] * (W-1) for i in range(H-1) ]
for i in range(H-1):
for j in range(W-1):
if S[i][j] == "#":
lis[i][j] += 1
if S[i+1][j] == "#":
lis[i][j] += 1
if S[i][j+1] == "#":
lis[i][j] += 1
if S[i+1][j+1] == "#":
lis[i][j] += 1
lis[i][j] %= 2
hist = [ [0] * W for i in range(H-1) ]
for i in range(H-1):
for j in range(W-1):
if lis[i][j] == 1:
continue
elif i == 0:
hist[i][j] = 1
else:
hist[i][j] = hist[i-1][j] + 1
ans = max(H,W)
for i in range(H-1):
ans = max(ans , Largest_rectangle_in_histgram(hist[i]))
print (ans)
``` | instruction | 0 | 49,503 | 16 | 99,006 |
No | output | 1 | 49,503 | 16 | 99,007 |
Provide a correct Python 3 solution for this coding contest problem.
Let N be a positive even number.
We have a permutation of (1, 2, ..., N), p = (p_1, p_2, ..., p_N). Snuke is constructing another permutation of (1, 2, ..., N), q, following the procedure below.
First, let q be an empty sequence. Then, perform the following operation until p becomes empty:
* Select two adjacent elements in p, and call them x and y in order. Remove x and y from p (reducing the length of p by 2), and insert x and y, preserving the original order, at the beginning of q.
When p becomes empty, q will be a permutation of (1, 2, ..., N).
Find the lexicographically smallest permutation that can be obtained as q.
Constraints
* N is an even number.
* 2 ≤ N ≤ 2 × 10^5
* p is a permutation of (1, 2, ..., N).
Input
Input is given from Standard Input in the following format:
N
p_1 p_2 ... p_N
Output
Print the lexicographically smallest permutation, with spaces in between.
Examples
Input
4
3 2 4 1
Output
3 1 2 4
Input
2
1 2
Output
1 2
Input
8
4 6 3 2 8 5 7 1
Output
3 1 2 7 4 6 8 5 | instruction | 0 | 51,160 | 16 | 102,320 |
"Correct Solution:
```
import sys
from heapq import heappop, heappush
class SegTreeMin:
"""
以下のクエリを処理する
1.update: i番目の値をxに更新する
2.get_min: 区間[l, r)の最小値を得る
"""
def __init__(self, n, INF):
"""
:param n: 要素数
:param INF: 初期値(入りうる要素より十分に大きな数)
"""
n2 = 1 << (n - 1).bit_length()
self.offset = n2
self.tree = [INF] * (n2 << 1)
self.INF = INF
@classmethod
def from_array(cls, arr, INF):
ins = cls(len(arr), INF)
ins.tree[ins.offset:ins.offset + len(arr)] = arr
for i in range(ins.offset - 1, 0, -1):
l = i << 1
r = l + 1
ins.tree[i] = min(ins.tree[l], ins.tree[r])
return ins
def update(self, i, x):
"""
i番目の値をxに更新
:param i: index(0-indexed)
:param x: update value
"""
i += self.offset
self.tree[i] = x
while i > 1:
y = self.tree[i ^ 1]
if y <= x:
break
i >>= 1
self.tree[i] = x
def get_min(self, a, b):
"""
[a, b)の最小値を得る
:param a: index(0-indexed)
:param b: index(0-indexed)
"""
result = self.INF
l = a + self.offset
r = b + self.offset
while l < r:
if r & 1:
result = min(result, self.tree[r - 1])
if l & 1:
result = min(result, self.tree[l])
l += 1
l >>= 1
r >>= 1
return result
n, *ppp = map(int, sys.stdin.buffer.read().split())
INF = 10 ** 18
indices = [0] * (n + 1)
even_p = [INF] * n
odd_p = [INF] * n
for i, p in enumerate(ppp):
indices[p] = i
if i % 2 == 0:
even_p[i] = p
else:
odd_p[i] = p
sgt0 = SegTreeMin.from_array(even_p, INF)
sgt1 = SegTreeMin.from_array(odd_p, INF)
sgt = [sgt0, sgt1]
ans = []
heap = []
data = {}
first_p = sgt0.get_min(0, n)
i = indices[first_p]
first_q = sgt1.get_min(i, n)
j = indices[first_q]
heap.append(first_p)
data[first_p] = (first_q, 0, n, i, j)
while heap:
p = heappop(heap)
q, l, r, i, j = data.pop(p)
ans.append(p)
ans.append(q)
if l < i:
k = l % 2
np = sgt[k].get_min(l, i)
ni = indices[np]
nq = sgt[k ^ 1].get_min(ni, i)
nj = indices[nq]
heappush(heap, np)
data[np] = (nq, l, i, ni, nj)
if i + 1 < j:
k = (i + 1) % 2
np = sgt[k].get_min(i + 1, j)
ni = indices[np]
nq = sgt[k ^ 1].get_min(ni, j)
nj = indices[nq]
heappush(heap, np)
data[np] = (nq, i + 1, j, ni, nj)
if j + 1 < r:
k = (j + 1) % 2
np = sgt[k].get_min(j + 1, r)
ni = indices[np]
nq = sgt[k ^ 1].get_min(ni, r)
nj = indices[nq]
heappush(heap, np)
data[np] = (nq, j + 1, r, ni, nj)
print(*ans)
``` | output | 1 | 51,160 | 16 | 102,321 |
Provide a correct Python 3 solution for this coding contest problem.
Let N be a positive even number.
We have a permutation of (1, 2, ..., N), p = (p_1, p_2, ..., p_N). Snuke is constructing another permutation of (1, 2, ..., N), q, following the procedure below.
First, let q be an empty sequence. Then, perform the following operation until p becomes empty:
* Select two adjacent elements in p, and call them x and y in order. Remove x and y from p (reducing the length of p by 2), and insert x and y, preserving the original order, at the beginning of q.
When p becomes empty, q will be a permutation of (1, 2, ..., N).
Find the lexicographically smallest permutation that can be obtained as q.
Constraints
* N is an even number.
* 2 ≤ N ≤ 2 × 10^5
* p is a permutation of (1, 2, ..., N).
Input
Input is given from Standard Input in the following format:
N
p_1 p_2 ... p_N
Output
Print the lexicographically smallest permutation, with spaces in between.
Examples
Input
4
3 2 4 1
Output
3 1 2 4
Input
2
1 2
Output
1 2
Input
8
4 6 3 2 8 5 7 1
Output
3 1 2 7 4 6 8 5 | instruction | 0 | 51,161 | 16 | 102,322 |
"Correct Solution:
```
import sys
readline = sys.stdin.readline
from heapq import heappop as hpp, heappush as hp
class Segtree:
def __init__(self, A, intv, initialize = True, segf = max):
self.N = len(A)
self.N0 = 2**(self.N-1).bit_length()
self.intv = intv
self.segf = segf
if initialize:
self.data = [intv]*self.N0 + A + [intv]*(self.N0 - self.N)
for i in range(self.N0-1, 0, -1):
self.data[i] = self.segf(self.data[2*i], self.data[2*i+1])
else:
self.data = [intv]*(2*self.N0)
def update(self, k, x):
k += self.N0
self.data[k] = x
while k > 0 :
k = k >> 1
self.data[k] = self.segf(self.data[2*k], self.data[2*k+1])
def query(self, l, r):
L, R = l+self.N0, r+self.N0
s = self.intv
while L < R:
if R & 1:
R -= 1
s = self.segf(s, self.data[R])
if L & 1:
s = self.segf(s, self.data[L])
L += 1
L >>= 1
R >>= 1
return s
def binsearch(self, l, r, check, reverse = False):
L, R = l+self.N0, r+self.N0
SL, SR = [], []
while L < R:
if R & 1:
R -= 1
SR.append(R)
if L & 1:
SL.append(L)
L += 1
L >>= 1
R >>= 1
if reverse:
for idx in (SR + SL[::-1]):
if check(self.data[idx]):
break
else:
return -1
while idx < self.N0:
if check(self.data[2*idx+1]):
idx = 2*idx + 1
else:
idx = 2*idx
return idx
else:
for idx in (SL + SR[::-1]):
if check(self.data[idx]):
break
else:
return -1
while idx < self.N0:
if check(self.data[2*idx]):
idx = 2*idx
else:
idx = 2*idx + 1
return idx
N = int(readline())
inf = 1<<32
P = list(map(int, readline().split()))
Pi = [None]*(N+1)
for i in range(N):
Pi[P[i]] = i
inf = 1<<32
Peven = [P[i] if not i&1 else inf for i in range(N)]
Podd = [P[i] if i&1 else inf for i in range(N)]
Teven = Segtree(Peven, inf, initialize = True, segf = min)
Todd = Segtree(Podd, inf, initialize = True, segf = min)
N0 = 2**(N-1).bit_length()
Q = [(Teven.query(0, N0), 0, N0)]
for i in range(N//2):
t1, l, r = hpp(Q)
K = []
if not l&1:
p1 = Pi[t1]
t2 = Todd.query(p1, r)
p2 = Pi[t2]
Teven.update(p1, inf)
Todd.update(p2, inf)
else:
p1 = Pi[t1]
t2 = Teven.query(p1, r)
p2 = Pi[t2]
Todd.update(p1, inf)
Teven.update(p2, inf)
if l < p1:
K.append((l, p1))
if p2 < r:
K.append((p2+1, r))
if p1 + 1 < p2:
K.append((p1+1, p2))
for l, r in K:
if not l&1:
mq = Teven.query(l, r)
else:
mq = Todd.query(l, r)
hp(Q, (mq, l, r))
sys.stdout.write('{} {} '.format(t1, t2))
sys.stdout.write('\n')
``` | output | 1 | 51,161 | 16 | 102,323 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.