message stringlengths 2 44.5k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 276 109k | cluster float64 23 23 | __index_level_0__ int64 552 217k |
|---|---|---|---|---|---|
Provide a correct Python 3 solution for this coding contest problem.
Amidakuji is a traditional method of lottery in Japan.
To make an amidakuji, we first draw W parallel vertical lines, and then draw horizontal lines that connect them. The length of each vertical line is H+1 [cm], and the endpoints of the horizontal lines must be at 1, 2, 3, ..., or H [cm] from the top of a vertical line.
A valid amidakuji is an amidakuji that satisfies the following conditions:
* No two horizontal lines share an endpoint.
* The two endpoints of each horizontal lines must be at the same height.
* A horizontal line must connect adjacent vertical lines.
<image>
Find the number of the valid amidakuji that satisfy the following condition, modulo 1\ 000\ 000\ 007: if we trace the path from the top of the leftmost vertical line to the bottom, always following horizontal lines when we encounter them, we reach the bottom of the K-th vertical line from the left.
For example, in the following amidakuji, we will reach the bottom of the fourth vertical line from the left.
<image>
Constraints
* H is an integer between 1 and 100 (inclusive).
* W is an integer between 1 and 8 (inclusive).
* K is an integer between 1 and W (inclusive).
Input
Input is given from Standard Input in the following format:
H W K
Output
Print the number of the amidakuji that satisfy the condition, modulo 1\ 000\ 000\ 007.
Examples
Input
1 3 2
Output
1
Input
1 3 1
Output
2
Input
2 3 3
Output
1
Input
2 3 1
Output
5
Input
7 1 1
Output
1
Input
15 8 5
Output
437760187 | instruction | 0 | 89,063 | 23 | 178,126 |
"Correct Solution:
```
h,w,k = map(int,input().split())
mod = 10**9+7
dp = [[0]*(w+2) for _ in range(h+1)]
dp[0][1] = 1
#左右の余白を埋める場合の数
ref = [1,2,3,5,8,13,21]
pat = lambda l,r:ref[max(l,0)]*ref[max(r,0)]
for i in range(h):
for j in range(1,w+1):
dp[i+1][j] = dp[i][j-1]*pat(j-3,w-j-1) + dp[i][j]*pat(j-2,w-j-1) + dp[i][j+1]*pat(j-2,w-j-2)
dp[i+1][j] %= mod
print(dp[-1][k])
``` | output | 1 | 89,063 | 23 | 178,127 |
Provide a correct Python 3 solution for this coding contest problem.
Amidakuji is a traditional method of lottery in Japan.
To make an amidakuji, we first draw W parallel vertical lines, and then draw horizontal lines that connect them. The length of each vertical line is H+1 [cm], and the endpoints of the horizontal lines must be at 1, 2, 3, ..., or H [cm] from the top of a vertical line.
A valid amidakuji is an amidakuji that satisfies the following conditions:
* No two horizontal lines share an endpoint.
* The two endpoints of each horizontal lines must be at the same height.
* A horizontal line must connect adjacent vertical lines.
<image>
Find the number of the valid amidakuji that satisfy the following condition, modulo 1\ 000\ 000\ 007: if we trace the path from the top of the leftmost vertical line to the bottom, always following horizontal lines when we encounter them, we reach the bottom of the K-th vertical line from the left.
For example, in the following amidakuji, we will reach the bottom of the fourth vertical line from the left.
<image>
Constraints
* H is an integer between 1 and 100 (inclusive).
* W is an integer between 1 and 8 (inclusive).
* K is an integer between 1 and W (inclusive).
Input
Input is given from Standard Input in the following format:
H W K
Output
Print the number of the amidakuji that satisfy the condition, modulo 1\ 000\ 000\ 007.
Examples
Input
1 3 2
Output
1
Input
1 3 1
Output
2
Input
2 3 3
Output
1
Input
2 3 1
Output
5
Input
7 1 1
Output
1
Input
15 8 5
Output
437760187 | instruction | 0 | 89,064 | 23 | 178,128 |
"Correct Solution:
```
h,w,k = (int(x) for x in input().split())
MOD = 1000000007
dp=[[0]*(w+2) for _ in range(h+2)]
fib = [0]*(w+1)
# 初期条件
fib[1] = 1
dp[0][1] = 1
# フィボナッチ
for i in range(2,w+1):
fib[i] = fib[i-1] + fib[i-2]
for i in range(1, h+1):
for j in range(1, w+1):
dp[i][j] = (dp[i - 1][j - 1]*fib[j - 1]*fib[w - j + 1]+dp[i - 1][j]*fib[j]*fib[w - j + 1]+dp[i - 1][j + 1]*fib[j]*fib[w - j])%MOD
print(dp[h][k])
``` | output | 1 | 89,064 | 23 | 178,129 |
Provide a correct Python 3 solution for this coding contest problem.
Amidakuji is a traditional method of lottery in Japan.
To make an amidakuji, we first draw W parallel vertical lines, and then draw horizontal lines that connect them. The length of each vertical line is H+1 [cm], and the endpoints of the horizontal lines must be at 1, 2, 3, ..., or H [cm] from the top of a vertical line.
A valid amidakuji is an amidakuji that satisfies the following conditions:
* No two horizontal lines share an endpoint.
* The two endpoints of each horizontal lines must be at the same height.
* A horizontal line must connect adjacent vertical lines.
<image>
Find the number of the valid amidakuji that satisfy the following condition, modulo 1\ 000\ 000\ 007: if we trace the path from the top of the leftmost vertical line to the bottom, always following horizontal lines when we encounter them, we reach the bottom of the K-th vertical line from the left.
For example, in the following amidakuji, we will reach the bottom of the fourth vertical line from the left.
<image>
Constraints
* H is an integer between 1 and 100 (inclusive).
* W is an integer between 1 and 8 (inclusive).
* K is an integer between 1 and W (inclusive).
Input
Input is given from Standard Input in the following format:
H W K
Output
Print the number of the amidakuji that satisfy the condition, modulo 1\ 000\ 000\ 007.
Examples
Input
1 3 2
Output
1
Input
1 3 1
Output
2
Input
2 3 3
Output
1
Input
2 3 1
Output
5
Input
7 1 1
Output
1
Input
15 8 5
Output
437760187 | instruction | 0 | 89,065 | 23 | 178,130 |
"Correct Solution:
```
H, W, K = map(int, input().split())
dp = [[0 for _ in range(W)] for _ in range(H + 1)]
dp[0][0] = 1
for i in range(1, H + 1):
for j in range(W):
for k in range(2 ** (W - 1)):
if bin(k).count("11") >= 1:
continue
if j + 1 <= W - 1 and (k >> j) & 1:
dp[i][j] += dp[i - 1][j + 1]
elif j - 1 >= 0 and (k >> (j - 1)) & 1:
dp[i][j] += dp[i - 1][j - 1]
else:
dp[i][j] += dp[i - 1][j]
print(dp[H][K - 1] % (10 ** 9 + 7))
``` | output | 1 | 89,065 | 23 | 178,131 |
Provide a correct Python 3 solution for this coding contest problem.
Amidakuji is a traditional method of lottery in Japan.
To make an amidakuji, we first draw W parallel vertical lines, and then draw horizontal lines that connect them. The length of each vertical line is H+1 [cm], and the endpoints of the horizontal lines must be at 1, 2, 3, ..., or H [cm] from the top of a vertical line.
A valid amidakuji is an amidakuji that satisfies the following conditions:
* No two horizontal lines share an endpoint.
* The two endpoints of each horizontal lines must be at the same height.
* A horizontal line must connect adjacent vertical lines.
<image>
Find the number of the valid amidakuji that satisfy the following condition, modulo 1\ 000\ 000\ 007: if we trace the path from the top of the leftmost vertical line to the bottom, always following horizontal lines when we encounter them, we reach the bottom of the K-th vertical line from the left.
For example, in the following amidakuji, we will reach the bottom of the fourth vertical line from the left.
<image>
Constraints
* H is an integer between 1 and 100 (inclusive).
* W is an integer between 1 and 8 (inclusive).
* K is an integer between 1 and W (inclusive).
Input
Input is given from Standard Input in the following format:
H W K
Output
Print the number of the amidakuji that satisfy the condition, modulo 1\ 000\ 000\ 007.
Examples
Input
1 3 2
Output
1
Input
1 3 1
Output
2
Input
2 3 3
Output
1
Input
2 3 1
Output
5
Input
7 1 1
Output
1
Input
15 8 5
Output
437760187 | instruction | 0 | 89,066 | 23 | 178,132 |
"Correct Solution:
```
MOD = 10**9 + 7
H, W, K = map(int, input().split())
fibs = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
def getFib(i):
return fibs[i+2]
numLs, numCs, numRs = [0]*W, [0]*W, [0]*W
for j in range(W):
numCs[j] = getFib(j-1) * getFib(W-1-j-1)
numLs[j] = getFib(j-2) * getFib(W-1-j-1)
numRs[j] = getFib(j-1) * getFib(W-1-j-2)
dp = [[0]*W for _ in range(H+1)]
dp[0][0] = 1
for i in range(H):
for j in range(W):
dp[i+1][j] += dp[i][j] * numCs[j]
if j > 0:
dp[i+1][j-1] += dp[i][j] * numLs[j]
if j < W-1:
dp[i+1][j+1] += dp[i][j] * numRs[j]
for j in range(W):
dp[i+1][j] %= MOD
print(dp[H][K-1])
``` | output | 1 | 89,066 | 23 | 178,133 |
Provide a correct Python 3 solution for this coding contest problem.
Amidakuji is a traditional method of lottery in Japan.
To make an amidakuji, we first draw W parallel vertical lines, and then draw horizontal lines that connect them. The length of each vertical line is H+1 [cm], and the endpoints of the horizontal lines must be at 1, 2, 3, ..., or H [cm] from the top of a vertical line.
A valid amidakuji is an amidakuji that satisfies the following conditions:
* No two horizontal lines share an endpoint.
* The two endpoints of each horizontal lines must be at the same height.
* A horizontal line must connect adjacent vertical lines.
<image>
Find the number of the valid amidakuji that satisfy the following condition, modulo 1\ 000\ 000\ 007: if we trace the path from the top of the leftmost vertical line to the bottom, always following horizontal lines when we encounter them, we reach the bottom of the K-th vertical line from the left.
For example, in the following amidakuji, we will reach the bottom of the fourth vertical line from the left.
<image>
Constraints
* H is an integer between 1 and 100 (inclusive).
* W is an integer between 1 and 8 (inclusive).
* K is an integer between 1 and W (inclusive).
Input
Input is given from Standard Input in the following format:
H W K
Output
Print the number of the amidakuji that satisfy the condition, modulo 1\ 000\ 000\ 007.
Examples
Input
1 3 2
Output
1
Input
1 3 1
Output
2
Input
2 3 3
Output
1
Input
2 3 1
Output
5
Input
7 1 1
Output
1
Input
15 8 5
Output
437760187 | instruction | 0 | 89,067 | 23 | 178,134 |
"Correct Solution:
```
h,w,k = map(int,input().split())
if w == 1:
print(1)
exit()
a = [0]*(w+2)
a[1] = 1
f = [0]*(w-1)
p = 0
q = 1
for i in range(w-1):
f[i] = p+q
q = p + q
p = q - p
f.append(1)
b = []
mod = 10**9+7
for i in range(w):
if i == 0:
b.append([0,f[w-2],f[w-3]])
elif i == w-1:
b.append([f[w-3],f[w-2],0])
else:
b.append([f[i-2]*f[w-i-2],f[i-1]*f[w-i-2],f[i-1]*f[w-i-3]])
for _ in range(h):
newa = [0]*(w+2)
for i in range(1,w+1):
newa[i] = (a[i-1]*b[i-1][0]+a[i]*b[i-1][1]+a[i+1]*b[i-1][2])%mod
a = newa
print(a[k])
``` | output | 1 | 89,067 | 23 | 178,135 |
Provide a correct Python 3 solution for this coding contest problem.
Amidakuji is a traditional method of lottery in Japan.
To make an amidakuji, we first draw W parallel vertical lines, and then draw horizontal lines that connect them. The length of each vertical line is H+1 [cm], and the endpoints of the horizontal lines must be at 1, 2, 3, ..., or H [cm] from the top of a vertical line.
A valid amidakuji is an amidakuji that satisfies the following conditions:
* No two horizontal lines share an endpoint.
* The two endpoints of each horizontal lines must be at the same height.
* A horizontal line must connect adjacent vertical lines.
<image>
Find the number of the valid amidakuji that satisfy the following condition, modulo 1\ 000\ 000\ 007: if we trace the path from the top of the leftmost vertical line to the bottom, always following horizontal lines when we encounter them, we reach the bottom of the K-th vertical line from the left.
For example, in the following amidakuji, we will reach the bottom of the fourth vertical line from the left.
<image>
Constraints
* H is an integer between 1 and 100 (inclusive).
* W is an integer between 1 and 8 (inclusive).
* K is an integer between 1 and W (inclusive).
Input
Input is given from Standard Input in the following format:
H W K
Output
Print the number of the amidakuji that satisfy the condition, modulo 1\ 000\ 000\ 007.
Examples
Input
1 3 2
Output
1
Input
1 3 1
Output
2
Input
2 3 3
Output
1
Input
2 3 1
Output
5
Input
7 1 1
Output
1
Input
15 8 5
Output
437760187 | instruction | 0 | 89,068 | 23 | 178,136 |
"Correct Solution:
```
# -*- coding: utf-8 -*-
"""
Created on Sat Jan 5 10:49:47 2019
@author: Yamazaki Kenichi
"""
H,W,K = map(int, input().split())
mod = 10**9 +7
a = [1,1,2,3,5,8,13,21]
T = [[-1 for i in range(9)] for i in range(H+1) ]
def n(h,k):
if T[h][k] != -1:
return T[h][k]
res = 0
if h == 1:
if k == 1 or k == 2:
T[h][k] = a[W-k]
return a[W-k]
else:
T[h][k] = 0
return 0
res += n(h-1,k)*(a[k-1] * a[W-k])
if k != 1:
res += n(h-1,k-1)*(a[k-1-1] * a[W-k])
if k != W:
res += n(h-1,k+1)*(a[k-1] * a[W-k-1])
T[h][k] = res
return res % mod
ans = n(H,K)
print(ans)
``` | output | 1 | 89,068 | 23 | 178,137 |
Provide a correct Python 3 solution for this coding contest problem.
Amidakuji is a traditional method of lottery in Japan.
To make an amidakuji, we first draw W parallel vertical lines, and then draw horizontal lines that connect them. The length of each vertical line is H+1 [cm], and the endpoints of the horizontal lines must be at 1, 2, 3, ..., or H [cm] from the top of a vertical line.
A valid amidakuji is an amidakuji that satisfies the following conditions:
* No two horizontal lines share an endpoint.
* The two endpoints of each horizontal lines must be at the same height.
* A horizontal line must connect adjacent vertical lines.
<image>
Find the number of the valid amidakuji that satisfy the following condition, modulo 1\ 000\ 000\ 007: if we trace the path from the top of the leftmost vertical line to the bottom, always following horizontal lines when we encounter them, we reach the bottom of the K-th vertical line from the left.
For example, in the following amidakuji, we will reach the bottom of the fourth vertical line from the left.
<image>
Constraints
* H is an integer between 1 and 100 (inclusive).
* W is an integer between 1 and 8 (inclusive).
* K is an integer between 1 and W (inclusive).
Input
Input is given from Standard Input in the following format:
H W K
Output
Print the number of the amidakuji that satisfy the condition, modulo 1\ 000\ 000\ 007.
Examples
Input
1 3 2
Output
1
Input
1 3 1
Output
2
Input
2 3 3
Output
1
Input
2 3 1
Output
5
Input
7 1 1
Output
1
Input
15 8 5
Output
437760187 | instruction | 0 | 89,069 | 23 | 178,138 |
"Correct Solution:
```
H,W,K=map(int,input().split())
dp=[[0]*(W+1) for _ in range(H+1)]
dp[0][0]=1
mod=10**9+7
for h in range(H):
for b in range(1<<(W-1)):
if "11" in bin(b):continue
b<<=1
for w in range(W):
if b&(1<<w):
dp[h+1][w]+=dp[h][w-1]
elif b&(1<<(w+1)):
dp[h+1][w]+=dp[h][w+1]
else:
dp[h+1][w]+=dp[h][w]
dp[h+1][w]%=mod
print(dp[H][K-1]%mod)
``` | output | 1 | 89,069 | 23 | 178,139 |
Provide a correct Python 3 solution for this coding contest problem.
Pablo Squarson is a well-known cubism artist. This year's theme for Pablo Squarson is "Squares". Today we are visiting his studio to see how his masterpieces are given birth.
At the center of his studio, there is a huuuuuge table and beside it are many, many squares of the same size. Pablo Squarson puts one of the squares on the table. Then he places some other squares on the table in sequence. It seems his methodical nature forces him to place each square side by side to the one that he already placed on, with machine-like precision.
Oh! The first piece of artwork is done. Pablo Squarson seems satisfied with it. Look at his happy face.
Oh, what's wrong with Pablo? He is tearing his hair! Oh, I see. He wants to find a box that fits the new piece of work but he has trouble figuring out its size. Let's help him!
Your mission is to write a program that takes instructions that record how Pablo made a piece of his artwork and computes its width and height. It is known that the size of each square is 1. You may assume that Pablo does not put a square on another.
I hear someone murmured "A smaller box will do". No, poor Pablo, shaking his head, is grumbling "My square style does not seem to be understood by illiterates".
<image>
Input
The input consists of a number of datasets. Each dataset represents the way Pablo made a piece of his artwork. The format of a dataset is as follows.
> N
n1 d1
n2 d2
...
nN-1 dN-1
The first line contains the number of squares (= N) used to make the piece of artwork. The number is a positive integer and is smaller than 200.
The remaining (N-1) lines in the dataset are square placement instructions. The line "ni di" indicates placement of the square numbered i (≤ N-1). The rules of numbering squares are as follows. The first square is numbered "zero". Subsequently placed squares are numbered 1, 2, ..., (N-1). Note that the input does not give any placement instruction to the first square, which is numbered zero.
A square placement instruction for the square numbered i, namely "ni di", directs it to be placed next to the one that is numbered ni, towards the direction given by di, which denotes leftward (= 0), downward (= 1), rightward (= 2), and upward (= 3).
For example, pieces of artwork corresponding to the four datasets shown in Sample Input are depicted below. Squares are labeled by their numbers.
<image>
The end of the input is indicated by a line that contains a single zero.
Output
For each dataset, output a line that contains the width and the height of the piece of artwork as decimal numbers, separated by a space. Each line should not contain any other characters.
Sample Input
1
5
0 0
0 1
0 2
0 3
12
0 0
1 0
2 0
3 1
4 1
5 1
6 2
7 2
8 2
9 3
10 3
10
0 2
1 2
2 2
3 2
2 1
5 1
6 1
7 1
8 1
0
Output for the Sample Input
1 1
3 3
4 4
5 6
Example
Input
1
5
0 0
0 1
0 2
0 3
12
0 0
1 0
2 0
3 1
4 1
5 1
6 2
7 2
8 2
9 3
10 3
10
0 2
1 2
2 2
3 2
2 1
5 1
6 1
7 1
8 1
0
Output
1 1
3 3
4 4
5 6 | instruction | 0 | 89,176 | 23 | 178,352 |
"Correct Solution:
```
'''
hardest 2.
Aizu Online Judge 1165: Pablo Squarson's Headache
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1165
## ?§£??¬
??£?????¢?????????????????£?????§???????????¢?????\????????????????????¢???????°????????????¨???????????????????????????????????§???
??£?????¢???????????¢???????????????????????????????????¨???????????¶???????????????
?´°????????¬?????????????????????????????§?????????????????\???????????????????????§?§£?????????
1. ?°´????????????x???,?????´?????????y?????¨?????????
2. ???????????£?????¢??????????????§?¨????(0, 0)??¨????????????????????£?????¢?????§?¨?????±???????
3. ????????¢???????????? (?????£?????¢???x??§?¨?????????§???) - (?????£?????¢???x??§?¨????????°????) + 1
4. ????????¢???????????????(?????£?????¢???y??§?¨?????????§???) - (?????£?????¢???y??§?¨????????°????) + 1
?????±???????????????????????°?????????????????????(AOJ?????????????????????????????????????????????????????¨????????????????????????)
'''
adjacent_vectors = [
(-1, 0), # left
(0, -1), # down
(1, 0), # right
(0, 1) # up
]
while True:
num_squares = int(input())
if num_squares == 0:
break
x_coordinates = [0] # x??§?¨?????????????
y_coordinates = [0] # y??§?¨?????????????
for _ in range(num_squares-1):
# adjacent_square: ??£??\????????£?????¢?????????
adjacent_square, direction = map(int, input().split())
x = x_coordinates[adjacent_square] # ??£??\????????£?????¢???x??§?¨?
y = y_coordinates[adjacent_square] # ??£??\????????£?????¢???y??§?¨?
(dx, dy) = adjacent_vectors[direction]
x_coordinates.append(x + dx)
y_coordinates.append(y + dy)
max_x = max(x_coordinates)
min_x = min(x_coordinates)
max_y = max(y_coordinates)
min_y = min(y_coordinates)
print(max_x - min_x + 1, max_y - min_y + 1)
``` | output | 1 | 89,176 | 23 | 178,353 |
Provide a correct Python 3 solution for this coding contest problem.
Pablo Squarson is a well-known cubism artist. This year's theme for Pablo Squarson is "Squares". Today we are visiting his studio to see how his masterpieces are given birth.
At the center of his studio, there is a huuuuuge table and beside it are many, many squares of the same size. Pablo Squarson puts one of the squares on the table. Then he places some other squares on the table in sequence. It seems his methodical nature forces him to place each square side by side to the one that he already placed on, with machine-like precision.
Oh! The first piece of artwork is done. Pablo Squarson seems satisfied with it. Look at his happy face.
Oh, what's wrong with Pablo? He is tearing his hair! Oh, I see. He wants to find a box that fits the new piece of work but he has trouble figuring out its size. Let's help him!
Your mission is to write a program that takes instructions that record how Pablo made a piece of his artwork and computes its width and height. It is known that the size of each square is 1. You may assume that Pablo does not put a square on another.
I hear someone murmured "A smaller box will do". No, poor Pablo, shaking his head, is grumbling "My square style does not seem to be understood by illiterates".
<image>
Input
The input consists of a number of datasets. Each dataset represents the way Pablo made a piece of his artwork. The format of a dataset is as follows.
> N
n1 d1
n2 d2
...
nN-1 dN-1
The first line contains the number of squares (= N) used to make the piece of artwork. The number is a positive integer and is smaller than 200.
The remaining (N-1) lines in the dataset are square placement instructions. The line "ni di" indicates placement of the square numbered i (≤ N-1). The rules of numbering squares are as follows. The first square is numbered "zero". Subsequently placed squares are numbered 1, 2, ..., (N-1). Note that the input does not give any placement instruction to the first square, which is numbered zero.
A square placement instruction for the square numbered i, namely "ni di", directs it to be placed next to the one that is numbered ni, towards the direction given by di, which denotes leftward (= 0), downward (= 1), rightward (= 2), and upward (= 3).
For example, pieces of artwork corresponding to the four datasets shown in Sample Input are depicted below. Squares are labeled by their numbers.
<image>
The end of the input is indicated by a line that contains a single zero.
Output
For each dataset, output a line that contains the width and the height of the piece of artwork as decimal numbers, separated by a space. Each line should not contain any other characters.
Sample Input
1
5
0 0
0 1
0 2
0 3
12
0 0
1 0
2 0
3 1
4 1
5 1
6 2
7 2
8 2
9 3
10 3
10
0 2
1 2
2 2
3 2
2 1
5 1
6 1
7 1
8 1
0
Output for the Sample Input
1 1
3 3
4 4
5 6
Example
Input
1
5
0 0
0 1
0 2
0 3
12
0 0
1 0
2 0
3 1
4 1
5 1
6 2
7 2
8 2
9 3
10 3
10
0 2
1 2
2 2
3 2
2 1
5 1
6 1
7 1
8 1
0
Output
1 1
3 3
4 4
5 6 | instruction | 0 | 89,177 | 23 | 178,354 |
"Correct Solution:
```
def main():
while True:
sq_sum = int(input())
if sq_sum == 0: break
abs_list = [[0, 0]]
for i in range(sq_sum - 1):
n, d = map(int, input().split())
abs_list.append(abs_p(abs_list, n, d))
xlist = []
ylist = []
for i in range(len(abs_list)):
xlist.append(abs_list[i][0])
ylist.append(abs_list[i][1])
print(str(max(xlist) - min(xlist) + 1) + " " + str(max(ylist) - min(ylist) + 1))
return 0
def abs_p(abs_list, fromm, wch):
if wch == 0:return[abs_list[fromm][0] - 1, abs_list[fromm][1]]
if wch == 1:return[abs_list[fromm][0], abs_list[fromm][1] + 1]
if wch == 2:return[abs_list[fromm][0] + 1, abs_list[fromm][1]]
if wch == 3:return[abs_list[fromm][0], abs_list[fromm][1] - 1]
return 0
main()
``` | output | 1 | 89,177 | 23 | 178,355 |
Provide a correct Python 3 solution for this coding contest problem.
Pablo Squarson is a well-known cubism artist. This year's theme for Pablo Squarson is "Squares". Today we are visiting his studio to see how his masterpieces are given birth.
At the center of his studio, there is a huuuuuge table and beside it are many, many squares of the same size. Pablo Squarson puts one of the squares on the table. Then he places some other squares on the table in sequence. It seems his methodical nature forces him to place each square side by side to the one that he already placed on, with machine-like precision.
Oh! The first piece of artwork is done. Pablo Squarson seems satisfied with it. Look at his happy face.
Oh, what's wrong with Pablo? He is tearing his hair! Oh, I see. He wants to find a box that fits the new piece of work but he has trouble figuring out its size. Let's help him!
Your mission is to write a program that takes instructions that record how Pablo made a piece of his artwork and computes its width and height. It is known that the size of each square is 1. You may assume that Pablo does not put a square on another.
I hear someone murmured "A smaller box will do". No, poor Pablo, shaking his head, is grumbling "My square style does not seem to be understood by illiterates".
<image>
Input
The input consists of a number of datasets. Each dataset represents the way Pablo made a piece of his artwork. The format of a dataset is as follows.
> N
n1 d1
n2 d2
...
nN-1 dN-1
The first line contains the number of squares (= N) used to make the piece of artwork. The number is a positive integer and is smaller than 200.
The remaining (N-1) lines in the dataset are square placement instructions. The line "ni di" indicates placement of the square numbered i (≤ N-1). The rules of numbering squares are as follows. The first square is numbered "zero". Subsequently placed squares are numbered 1, 2, ..., (N-1). Note that the input does not give any placement instruction to the first square, which is numbered zero.
A square placement instruction for the square numbered i, namely "ni di", directs it to be placed next to the one that is numbered ni, towards the direction given by di, which denotes leftward (= 0), downward (= 1), rightward (= 2), and upward (= 3).
For example, pieces of artwork corresponding to the four datasets shown in Sample Input are depicted below. Squares are labeled by their numbers.
<image>
The end of the input is indicated by a line that contains a single zero.
Output
For each dataset, output a line that contains the width and the height of the piece of artwork as decimal numbers, separated by a space. Each line should not contain any other characters.
Sample Input
1
5
0 0
0 1
0 2
0 3
12
0 0
1 0
2 0
3 1
4 1
5 1
6 2
7 2
8 2
9 3
10 3
10
0 2
1 2
2 2
3 2
2 1
5 1
6 1
7 1
8 1
0
Output for the Sample Input
1 1
3 3
4 4
5 6
Example
Input
1
5
0 0
0 1
0 2
0 3
12
0 0
1 0
2 0
3 1
4 1
5 1
6 2
7 2
8 2
9 3
10 3
10
0 2
1 2
2 2
3 2
2 1
5 1
6 1
7 1
8 1
0
Output
1 1
3 3
4 4
5 6 | instruction | 0 | 89,178 | 23 | 178,356 |
"Correct Solution:
```
def solve(N, nd):
dire = [(0,-1), (-1,0), (0,1), (1,0)]
table = [[0]*(2*N+1) for i in range(2*N+1)]
table[N][N] = 1
position = [None]*N
position[0] = (N, N)
for i,ndi in enumerate(nd,start=1):
n, d = ndi
y, x = position[n]
ny, nx = y+dire[d][0], x+dire[d][1]
table[ny][nx] = 1
position[i] = (ny, nx)
left, right, top, bottom = 2*N, 0, 2*N, 0
for i in range(2*N):
for j in range(2*N):
if (table[i][j]):
left = min(left, j)
right = max(right, j)
top = min(top, i)
bottom = max(bottom, i)
return (right-left+1, bottom-top+1)
def main():
ans = []
while True:
N = int(input())
if (not N):
break
nd = [list(map(int, input().split())) for i in range(N-1)]
ans.append(solve(N, nd))
for i in ans:
print(*i)
main()
``` | output | 1 | 89,178 | 23 | 178,357 |
Provide a correct Python 3 solution for this coding contest problem.
Pablo Squarson is a well-known cubism artist. This year's theme for Pablo Squarson is "Squares". Today we are visiting his studio to see how his masterpieces are given birth.
At the center of his studio, there is a huuuuuge table and beside it are many, many squares of the same size. Pablo Squarson puts one of the squares on the table. Then he places some other squares on the table in sequence. It seems his methodical nature forces him to place each square side by side to the one that he already placed on, with machine-like precision.
Oh! The first piece of artwork is done. Pablo Squarson seems satisfied with it. Look at his happy face.
Oh, what's wrong with Pablo? He is tearing his hair! Oh, I see. He wants to find a box that fits the new piece of work but he has trouble figuring out its size. Let's help him!
Your mission is to write a program that takes instructions that record how Pablo made a piece of his artwork and computes its width and height. It is known that the size of each square is 1. You may assume that Pablo does not put a square on another.
I hear someone murmured "A smaller box will do". No, poor Pablo, shaking his head, is grumbling "My square style does not seem to be understood by illiterates".
<image>
Input
The input consists of a number of datasets. Each dataset represents the way Pablo made a piece of his artwork. The format of a dataset is as follows.
> N
n1 d1
n2 d2
...
nN-1 dN-1
The first line contains the number of squares (= N) used to make the piece of artwork. The number is a positive integer and is smaller than 200.
The remaining (N-1) lines in the dataset are square placement instructions. The line "ni di" indicates placement of the square numbered i (≤ N-1). The rules of numbering squares are as follows. The first square is numbered "zero". Subsequently placed squares are numbered 1, 2, ..., (N-1). Note that the input does not give any placement instruction to the first square, which is numbered zero.
A square placement instruction for the square numbered i, namely "ni di", directs it to be placed next to the one that is numbered ni, towards the direction given by di, which denotes leftward (= 0), downward (= 1), rightward (= 2), and upward (= 3).
For example, pieces of artwork corresponding to the four datasets shown in Sample Input are depicted below. Squares are labeled by their numbers.
<image>
The end of the input is indicated by a line that contains a single zero.
Output
For each dataset, output a line that contains the width and the height of the piece of artwork as decimal numbers, separated by a space. Each line should not contain any other characters.
Sample Input
1
5
0 0
0 1
0 2
0 3
12
0 0
1 0
2 0
3 1
4 1
5 1
6 2
7 2
8 2
9 3
10 3
10
0 2
1 2
2 2
3 2
2 1
5 1
6 1
7 1
8 1
0
Output for the Sample Input
1 1
3 3
4 4
5 6
Example
Input
1
5
0 0
0 1
0 2
0 3
12
0 0
1 0
2 0
3 1
4 1
5 1
6 2
7 2
8 2
9 3
10 3
10
0 2
1 2
2 2
3 2
2 1
5 1
6 1
7 1
8 1
0
Output
1 1
3 3
4 4
5 6 | instruction | 0 | 89,179 | 23 | 178,358 |
"Correct Solution:
```
D = ((-1,0),(0,1),(1,0),(0,-1))
while 1:
N = int(input())
if not N:break
min_x = min_y = max_x = max_y = 0
a = [(0,0)]
for i in range(N-1):
n1, d1 = list(map(int, input().split()))
spam = (lambda x: (x[0] + D[d1][0], x[1] + D[d1][1]))(a[n1])
min_x = min(spam[0],min_x)
min_y = min(spam[1],min_y)
max_x = max(spam[0],max_x)
max_y = max(spam[1],max_y)
a.append(spam)
print('%d %d' % (max_x - min_x + 1, max_y - min_y + 1))
``` | output | 1 | 89,179 | 23 | 178,359 |
Provide a correct Python 3 solution for this coding contest problem.
Pablo Squarson is a well-known cubism artist. This year's theme for Pablo Squarson is "Squares". Today we are visiting his studio to see how his masterpieces are given birth.
At the center of his studio, there is a huuuuuge table and beside it are many, many squares of the same size. Pablo Squarson puts one of the squares on the table. Then he places some other squares on the table in sequence. It seems his methodical nature forces him to place each square side by side to the one that he already placed on, with machine-like precision.
Oh! The first piece of artwork is done. Pablo Squarson seems satisfied with it. Look at his happy face.
Oh, what's wrong with Pablo? He is tearing his hair! Oh, I see. He wants to find a box that fits the new piece of work but he has trouble figuring out its size. Let's help him!
Your mission is to write a program that takes instructions that record how Pablo made a piece of his artwork and computes its width and height. It is known that the size of each square is 1. You may assume that Pablo does not put a square on another.
I hear someone murmured "A smaller box will do". No, poor Pablo, shaking his head, is grumbling "My square style does not seem to be understood by illiterates".
<image>
Input
The input consists of a number of datasets. Each dataset represents the way Pablo made a piece of his artwork. The format of a dataset is as follows.
> N
n1 d1
n2 d2
...
nN-1 dN-1
The first line contains the number of squares (= N) used to make the piece of artwork. The number is a positive integer and is smaller than 200.
The remaining (N-1) lines in the dataset are square placement instructions. The line "ni di" indicates placement of the square numbered i (≤ N-1). The rules of numbering squares are as follows. The first square is numbered "zero". Subsequently placed squares are numbered 1, 2, ..., (N-1). Note that the input does not give any placement instruction to the first square, which is numbered zero.
A square placement instruction for the square numbered i, namely "ni di", directs it to be placed next to the one that is numbered ni, towards the direction given by di, which denotes leftward (= 0), downward (= 1), rightward (= 2), and upward (= 3).
For example, pieces of artwork corresponding to the four datasets shown in Sample Input are depicted below. Squares are labeled by their numbers.
<image>
The end of the input is indicated by a line that contains a single zero.
Output
For each dataset, output a line that contains the width and the height of the piece of artwork as decimal numbers, separated by a space. Each line should not contain any other characters.
Sample Input
1
5
0 0
0 1
0 2
0 3
12
0 0
1 0
2 0
3 1
4 1
5 1
6 2
7 2
8 2
9 3
10 3
10
0 2
1 2
2 2
3 2
2 1
5 1
6 1
7 1
8 1
0
Output for the Sample Input
1 1
3 3
4 4
5 6
Example
Input
1
5
0 0
0 1
0 2
0 3
12
0 0
1 0
2 0
3 1
4 1
5 1
6 2
7 2
8 2
9 3
10 3
10
0 2
1 2
2 2
3 2
2 1
5 1
6 1
7 1
8 1
0
Output
1 1
3 3
4 4
5 6 | instruction | 0 | 89,180 | 23 | 178,360 |
"Correct Solution:
```
while True:
n = int(input())
if n == 0: break
xs = [(0, 0)]
dic = [(-1, 0), (0, 1), (1, 0), (0, -1)]
maxX, minX, maxY, minY = 0, 0, 0, 0
for i in range(n - 1):
n, d = map(int, input().split())
xs.append((xs[n][0] + dic[d][0], xs[n][1] + dic[d][1]))
if xs[-1][0] > maxX: maxX = xs[-1][0]
elif xs[-1][0] < minX: minX = xs[-1][0]
if xs[-1][1] > maxY: maxY = xs[-1][1]
elif xs[-1][1] < minY: minY = xs[-1][1]
print(maxX - minX + 1, maxY - minY + 1)
``` | output | 1 | 89,180 | 23 | 178,361 |
Provide a correct Python 3 solution for this coding contest problem.
Pablo Squarson is a well-known cubism artist. This year's theme for Pablo Squarson is "Squares". Today we are visiting his studio to see how his masterpieces are given birth.
At the center of his studio, there is a huuuuuge table and beside it are many, many squares of the same size. Pablo Squarson puts one of the squares on the table. Then he places some other squares on the table in sequence. It seems his methodical nature forces him to place each square side by side to the one that he already placed on, with machine-like precision.
Oh! The first piece of artwork is done. Pablo Squarson seems satisfied with it. Look at his happy face.
Oh, what's wrong with Pablo? He is tearing his hair! Oh, I see. He wants to find a box that fits the new piece of work but he has trouble figuring out its size. Let's help him!
Your mission is to write a program that takes instructions that record how Pablo made a piece of his artwork and computes its width and height. It is known that the size of each square is 1. You may assume that Pablo does not put a square on another.
I hear someone murmured "A smaller box will do". No, poor Pablo, shaking his head, is grumbling "My square style does not seem to be understood by illiterates".
<image>
Input
The input consists of a number of datasets. Each dataset represents the way Pablo made a piece of his artwork. The format of a dataset is as follows.
> N
n1 d1
n2 d2
...
nN-1 dN-1
The first line contains the number of squares (= N) used to make the piece of artwork. The number is a positive integer and is smaller than 200.
The remaining (N-1) lines in the dataset are square placement instructions. The line "ni di" indicates placement of the square numbered i (≤ N-1). The rules of numbering squares are as follows. The first square is numbered "zero". Subsequently placed squares are numbered 1, 2, ..., (N-1). Note that the input does not give any placement instruction to the first square, which is numbered zero.
A square placement instruction for the square numbered i, namely "ni di", directs it to be placed next to the one that is numbered ni, towards the direction given by di, which denotes leftward (= 0), downward (= 1), rightward (= 2), and upward (= 3).
For example, pieces of artwork corresponding to the four datasets shown in Sample Input are depicted below. Squares are labeled by their numbers.
<image>
The end of the input is indicated by a line that contains a single zero.
Output
For each dataset, output a line that contains the width and the height of the piece of artwork as decimal numbers, separated by a space. Each line should not contain any other characters.
Sample Input
1
5
0 0
0 1
0 2
0 3
12
0 0
1 0
2 0
3 1
4 1
5 1
6 2
7 2
8 2
9 3
10 3
10
0 2
1 2
2 2
3 2
2 1
5 1
6 1
7 1
8 1
0
Output for the Sample Input
1 1
3 3
4 4
5 6
Example
Input
1
5
0 0
0 1
0 2
0 3
12
0 0
1 0
2 0
3 1
4 1
5 1
6 2
7 2
8 2
9 3
10 3
10
0 2
1 2
2 2
3 2
2 1
5 1
6 1
7 1
8 1
0
Output
1 1
3 3
4 4
5 6 | instruction | 0 | 89,181 | 23 | 178,362 |
"Correct Solution:
```
d = [[-1,0],[0,1],[1,0],[0,-1]]
while True:
n = int(input())
if not(n): break
# l = [[1,1]]
w,h = [1],[1]
for i in range(n-1):
l = list(map(int,input().split()))
w.append(w[l[0]]+d[l[1]][0])
h.append(h[l[0]]+d[l[1]][1])
print(max(w)-min(w)+1,max(h)-min(h)+1)
``` | output | 1 | 89,181 | 23 | 178,363 |
Provide a correct Python 3 solution for this coding contest problem.
Pablo Squarson is a well-known cubism artist. This year's theme for Pablo Squarson is "Squares". Today we are visiting his studio to see how his masterpieces are given birth.
At the center of his studio, there is a huuuuuge table and beside it are many, many squares of the same size. Pablo Squarson puts one of the squares on the table. Then he places some other squares on the table in sequence. It seems his methodical nature forces him to place each square side by side to the one that he already placed on, with machine-like precision.
Oh! The first piece of artwork is done. Pablo Squarson seems satisfied with it. Look at his happy face.
Oh, what's wrong with Pablo? He is tearing his hair! Oh, I see. He wants to find a box that fits the new piece of work but he has trouble figuring out its size. Let's help him!
Your mission is to write a program that takes instructions that record how Pablo made a piece of his artwork and computes its width and height. It is known that the size of each square is 1. You may assume that Pablo does not put a square on another.
I hear someone murmured "A smaller box will do". No, poor Pablo, shaking his head, is grumbling "My square style does not seem to be understood by illiterates".
<image>
Input
The input consists of a number of datasets. Each dataset represents the way Pablo made a piece of his artwork. The format of a dataset is as follows.
> N
n1 d1
n2 d2
...
nN-1 dN-1
The first line contains the number of squares (= N) used to make the piece of artwork. The number is a positive integer and is smaller than 200.
The remaining (N-1) lines in the dataset are square placement instructions. The line "ni di" indicates placement of the square numbered i (≤ N-1). The rules of numbering squares are as follows. The first square is numbered "zero". Subsequently placed squares are numbered 1, 2, ..., (N-1). Note that the input does not give any placement instruction to the first square, which is numbered zero.
A square placement instruction for the square numbered i, namely "ni di", directs it to be placed next to the one that is numbered ni, towards the direction given by di, which denotes leftward (= 0), downward (= 1), rightward (= 2), and upward (= 3).
For example, pieces of artwork corresponding to the four datasets shown in Sample Input are depicted below. Squares are labeled by their numbers.
<image>
The end of the input is indicated by a line that contains a single zero.
Output
For each dataset, output a line that contains the width and the height of the piece of artwork as decimal numbers, separated by a space. Each line should not contain any other characters.
Sample Input
1
5
0 0
0 1
0 2
0 3
12
0 0
1 0
2 0
3 1
4 1
5 1
6 2
7 2
8 2
9 3
10 3
10
0 2
1 2
2 2
3 2
2 1
5 1
6 1
7 1
8 1
0
Output for the Sample Input
1 1
3 3
4 4
5 6
Example
Input
1
5
0 0
0 1
0 2
0 3
12
0 0
1 0
2 0
3 1
4 1
5 1
6 2
7 2
8 2
9 3
10 3
10
0 2
1 2
2 2
3 2
2 1
5 1
6 1
7 1
8 1
0
Output
1 1
3 3
4 4
5 6 | instruction | 0 | 89,182 | 23 | 178,364 |
"Correct Solution:
```
def main():
D = ((-1,0), (0,-1), (1,0), (0,1))
while True:
n = int(input())
if n==0:
exit()
sx = [0]
sy = [0]
for i in range(n-1):
ni, di = [int(x) for x in input().split()]
sx.append(sx[ni]+D[di][0])
sy.append(sy[ni]+D[di][1])
w = max(sx)-min(sx)+1
h = max(sy)-min(sy)+1
print(w,h)
if __name__ == '__main__':
main()
``` | output | 1 | 89,182 | 23 | 178,365 |
Provide a correct Python 3 solution for this coding contest problem.
Pablo Squarson is a well-known cubism artist. This year's theme for Pablo Squarson is "Squares". Today we are visiting his studio to see how his masterpieces are given birth.
At the center of his studio, there is a huuuuuge table and beside it are many, many squares of the same size. Pablo Squarson puts one of the squares on the table. Then he places some other squares on the table in sequence. It seems his methodical nature forces him to place each square side by side to the one that he already placed on, with machine-like precision.
Oh! The first piece of artwork is done. Pablo Squarson seems satisfied with it. Look at his happy face.
Oh, what's wrong with Pablo? He is tearing his hair! Oh, I see. He wants to find a box that fits the new piece of work but he has trouble figuring out its size. Let's help him!
Your mission is to write a program that takes instructions that record how Pablo made a piece of his artwork and computes its width and height. It is known that the size of each square is 1. You may assume that Pablo does not put a square on another.
I hear someone murmured "A smaller box will do". No, poor Pablo, shaking his head, is grumbling "My square style does not seem to be understood by illiterates".
<image>
Input
The input consists of a number of datasets. Each dataset represents the way Pablo made a piece of his artwork. The format of a dataset is as follows.
> N
n1 d1
n2 d2
...
nN-1 dN-1
The first line contains the number of squares (= N) used to make the piece of artwork. The number is a positive integer and is smaller than 200.
The remaining (N-1) lines in the dataset are square placement instructions. The line "ni di" indicates placement of the square numbered i (≤ N-1). The rules of numbering squares are as follows. The first square is numbered "zero". Subsequently placed squares are numbered 1, 2, ..., (N-1). Note that the input does not give any placement instruction to the first square, which is numbered zero.
A square placement instruction for the square numbered i, namely "ni di", directs it to be placed next to the one that is numbered ni, towards the direction given by di, which denotes leftward (= 0), downward (= 1), rightward (= 2), and upward (= 3).
For example, pieces of artwork corresponding to the four datasets shown in Sample Input are depicted below. Squares are labeled by their numbers.
<image>
The end of the input is indicated by a line that contains a single zero.
Output
For each dataset, output a line that contains the width and the height of the piece of artwork as decimal numbers, separated by a space. Each line should not contain any other characters.
Sample Input
1
5
0 0
0 1
0 2
0 3
12
0 0
1 0
2 0
3 1
4 1
5 1
6 2
7 2
8 2
9 3
10 3
10
0 2
1 2
2 2
3 2
2 1
5 1
6 1
7 1
8 1
0
Output for the Sample Input
1 1
3 3
4 4
5 6
Example
Input
1
5
0 0
0 1
0 2
0 3
12
0 0
1 0
2 0
3 1
4 1
5 1
6 2
7 2
8 2
9 3
10 3
10
0 2
1 2
2 2
3 2
2 1
5 1
6 1
7 1
8 1
0
Output
1 1
3 3
4 4
5 6 | instruction | 0 | 89,183 | 23 | 178,366 |
"Correct Solution:
```
while True:
N=int(input())
if N==0:break
t=[0]
y=[0]
lst=list(range(N))
for k in lst[1:]:
[x,d]=input().split()
[x,d]=[int(x),int(d)]
if d==0:
t=t+[t[x]]
y=y+[y[x]-1]
if d==1:
t=t+[t[x]-1]
y=y+[y[x]]
if d==2:
t=t+[t[x]]
y=y+[y[x]+1]
if d==3:
t=t+[t[x]+1]
y=y+[y[x]]
ht=0
lt=0
hy=0
ly=0
for f in range(N):
if ht<t[f]:
ht+=1
if lt>t[f]:
lt-=1
if hy<y[f]:
hy+=1
if ly>y[f]:
ly-=1
print(hy-ly+1,ht-lt+1)
``` | output | 1 | 89,183 | 23 | 178,367 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Pablo Squarson is a well-known cubism artist. This year's theme for Pablo Squarson is "Squares". Today we are visiting his studio to see how his masterpieces are given birth.
At the center of his studio, there is a huuuuuge table and beside it are many, many squares of the same size. Pablo Squarson puts one of the squares on the table. Then he places some other squares on the table in sequence. It seems his methodical nature forces him to place each square side by side to the one that he already placed on, with machine-like precision.
Oh! The first piece of artwork is done. Pablo Squarson seems satisfied with it. Look at his happy face.
Oh, what's wrong with Pablo? He is tearing his hair! Oh, I see. He wants to find a box that fits the new piece of work but he has trouble figuring out its size. Let's help him!
Your mission is to write a program that takes instructions that record how Pablo made a piece of his artwork and computes its width and height. It is known that the size of each square is 1. You may assume that Pablo does not put a square on another.
I hear someone murmured "A smaller box will do". No, poor Pablo, shaking his head, is grumbling "My square style does not seem to be understood by illiterates".
<image>
Input
The input consists of a number of datasets. Each dataset represents the way Pablo made a piece of his artwork. The format of a dataset is as follows.
> N
n1 d1
n2 d2
...
nN-1 dN-1
The first line contains the number of squares (= N) used to make the piece of artwork. The number is a positive integer and is smaller than 200.
The remaining (N-1) lines in the dataset are square placement instructions. The line "ni di" indicates placement of the square numbered i (≤ N-1). The rules of numbering squares are as follows. The first square is numbered "zero". Subsequently placed squares are numbered 1, 2, ..., (N-1). Note that the input does not give any placement instruction to the first square, which is numbered zero.
A square placement instruction for the square numbered i, namely "ni di", directs it to be placed next to the one that is numbered ni, towards the direction given by di, which denotes leftward (= 0), downward (= 1), rightward (= 2), and upward (= 3).
For example, pieces of artwork corresponding to the four datasets shown in Sample Input are depicted below. Squares are labeled by their numbers.
<image>
The end of the input is indicated by a line that contains a single zero.
Output
For each dataset, output a line that contains the width and the height of the piece of artwork as decimal numbers, separated by a space. Each line should not contain any other characters.
Sample Input
1
5
0 0
0 1
0 2
0 3
12
0 0
1 0
2 0
3 1
4 1
5 1
6 2
7 2
8 2
9 3
10 3
10
0 2
1 2
2 2
3 2
2 1
5 1
6 1
7 1
8 1
0
Output for the Sample Input
1 1
3 3
4 4
5 6
Example
Input
1
5
0 0
0 1
0 2
0 3
12
0 0
1 0
2 0
3 1
4 1
5 1
6 2
7 2
8 2
9 3
10 3
10
0 2
1 2
2 2
3 2
2 1
5 1
6 1
7 1
8 1
0
Output
1 1
3 3
4 4
5 6
Submitted Solution:
```
while True:
N = int(input())
if N==0:
break
squa = [[0,0]]
xmax, xmin, ymax, ymin = 0, 0, 0, 0
for i in range(N-1):
n, d = map(int, input().split())
if d==0:
squa.append([squa[n][0]-1, squa[n][1]])
xmin = min(xmin, squa[n][0]-1)
elif d==1:
squa.append([squa[n][0], squa[n][1]-1])
ymin = min(ymin, squa[n][1]-1)
elif d==2:
squa.append([squa[n][0]+1, squa[n][1]])
xmax = max(xmax, squa[n][0]+1)
elif d==3:
squa.append([squa[n][0], squa[n][1]+1])
ymax = max(ymax, squa[n][1]+1)
print(xmax-xmin+1, ymax-ymin+1)
``` | instruction | 0 | 89,184 | 23 | 178,368 |
Yes | output | 1 | 89,184 | 23 | 178,369 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Pablo Squarson is a well-known cubism artist. This year's theme for Pablo Squarson is "Squares". Today we are visiting his studio to see how his masterpieces are given birth.
At the center of his studio, there is a huuuuuge table and beside it are many, many squares of the same size. Pablo Squarson puts one of the squares on the table. Then he places some other squares on the table in sequence. It seems his methodical nature forces him to place each square side by side to the one that he already placed on, with machine-like precision.
Oh! The first piece of artwork is done. Pablo Squarson seems satisfied with it. Look at his happy face.
Oh, what's wrong with Pablo? He is tearing his hair! Oh, I see. He wants to find a box that fits the new piece of work but he has trouble figuring out its size. Let's help him!
Your mission is to write a program that takes instructions that record how Pablo made a piece of his artwork and computes its width and height. It is known that the size of each square is 1. You may assume that Pablo does not put a square on another.
I hear someone murmured "A smaller box will do". No, poor Pablo, shaking his head, is grumbling "My square style does not seem to be understood by illiterates".
<image>
Input
The input consists of a number of datasets. Each dataset represents the way Pablo made a piece of his artwork. The format of a dataset is as follows.
> N
n1 d1
n2 d2
...
nN-1 dN-1
The first line contains the number of squares (= N) used to make the piece of artwork. The number is a positive integer and is smaller than 200.
The remaining (N-1) lines in the dataset are square placement instructions. The line "ni di" indicates placement of the square numbered i (≤ N-1). The rules of numbering squares are as follows. The first square is numbered "zero". Subsequently placed squares are numbered 1, 2, ..., (N-1). Note that the input does not give any placement instruction to the first square, which is numbered zero.
A square placement instruction for the square numbered i, namely "ni di", directs it to be placed next to the one that is numbered ni, towards the direction given by di, which denotes leftward (= 0), downward (= 1), rightward (= 2), and upward (= 3).
For example, pieces of artwork corresponding to the four datasets shown in Sample Input are depicted below. Squares are labeled by their numbers.
<image>
The end of the input is indicated by a line that contains a single zero.
Output
For each dataset, output a line that contains the width and the height of the piece of artwork as decimal numbers, separated by a space. Each line should not contain any other characters.
Sample Input
1
5
0 0
0 1
0 2
0 3
12
0 0
1 0
2 0
3 1
4 1
5 1
6 2
7 2
8 2
9 3
10 3
10
0 2
1 2
2 2
3 2
2 1
5 1
6 1
7 1
8 1
0
Output for the Sample Input
1 1
3 3
4 4
5 6
Example
Input
1
5
0 0
0 1
0 2
0 3
12
0 0
1 0
2 0
3 1
4 1
5 1
6 2
7 2
8 2
9 3
10 3
10
0 2
1 2
2 2
3 2
2 1
5 1
6 1
7 1
8 1
0
Output
1 1
3 3
4 4
5 6
Submitted Solution:
```
if __name__ == "__main__":
while True:
N = int(input())
if N == 0:
break
# 左, 下, 右, 上
wak = {0: [0, 0]}
ml = float("inf")
md = float("inf")
mr = -float("inf")
mu = -float("inf")
for i in range(1, N):
n, d = map(int, input().split())
if d == 0:
wak[i] = [wak[n][0] - 1, wak[n][1]]
elif d == 1:
wak[i] = [wak[n][0], wak[n][1] - 1]
elif d == 2:
wak[i] = [wak[n][0] + 1, wak[n][1]]
elif d == 3:
wak[i] = [wak[n][0], wak[n][1] + 1]
for k, v in wak.items():
ml = min(v[0], ml)
md = min(v[1], md)
mr = max(v[0], mr)
mu = max(v[1], mu)
print(abs(mr - ml) + 1, abs(mu - md) + 1)
# print(wak)
# print("--------------------")
``` | instruction | 0 | 89,185 | 23 | 178,370 |
Yes | output | 1 | 89,185 | 23 | 178,371 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Pablo Squarson is a well-known cubism artist. This year's theme for Pablo Squarson is "Squares". Today we are visiting his studio to see how his masterpieces are given birth.
At the center of his studio, there is a huuuuuge table and beside it are many, many squares of the same size. Pablo Squarson puts one of the squares on the table. Then he places some other squares on the table in sequence. It seems his methodical nature forces him to place each square side by side to the one that he already placed on, with machine-like precision.
Oh! The first piece of artwork is done. Pablo Squarson seems satisfied with it. Look at his happy face.
Oh, what's wrong with Pablo? He is tearing his hair! Oh, I see. He wants to find a box that fits the new piece of work but he has trouble figuring out its size. Let's help him!
Your mission is to write a program that takes instructions that record how Pablo made a piece of his artwork and computes its width and height. It is known that the size of each square is 1. You may assume that Pablo does not put a square on another.
I hear someone murmured "A smaller box will do". No, poor Pablo, shaking his head, is grumbling "My square style does not seem to be understood by illiterates".
<image>
Input
The input consists of a number of datasets. Each dataset represents the way Pablo made a piece of his artwork. The format of a dataset is as follows.
> N
n1 d1
n2 d2
...
nN-1 dN-1
The first line contains the number of squares (= N) used to make the piece of artwork. The number is a positive integer and is smaller than 200.
The remaining (N-1) lines in the dataset are square placement instructions. The line "ni di" indicates placement of the square numbered i (≤ N-1). The rules of numbering squares are as follows. The first square is numbered "zero". Subsequently placed squares are numbered 1, 2, ..., (N-1). Note that the input does not give any placement instruction to the first square, which is numbered zero.
A square placement instruction for the square numbered i, namely "ni di", directs it to be placed next to the one that is numbered ni, towards the direction given by di, which denotes leftward (= 0), downward (= 1), rightward (= 2), and upward (= 3).
For example, pieces of artwork corresponding to the four datasets shown in Sample Input are depicted below. Squares are labeled by their numbers.
<image>
The end of the input is indicated by a line that contains a single zero.
Output
For each dataset, output a line that contains the width and the height of the piece of artwork as decimal numbers, separated by a space. Each line should not contain any other characters.
Sample Input
1
5
0 0
0 1
0 2
0 3
12
0 0
1 0
2 0
3 1
4 1
5 1
6 2
7 2
8 2
9 3
10 3
10
0 2
1 2
2 2
3 2
2 1
5 1
6 1
7 1
8 1
0
Output for the Sample Input
1 1
3 3
4 4
5 6
Example
Input
1
5
0 0
0 1
0 2
0 3
12
0 0
1 0
2 0
3 1
4 1
5 1
6 2
7 2
8 2
9 3
10 3
10
0 2
1 2
2 2
3 2
2 1
5 1
6 1
7 1
8 1
0
Output
1 1
3 3
4 4
5 6
Submitted Solution:
```
while 1:
n=int(input())
if not n:break
p=[(0,0)]
b=[0,0]
for _ in range(n-1):
idx,d=map(int,input().split())
b=list(p[idx])
if d==0:
b[0]-=1
elif d==1:
b[1]-=1
elif d==2:
b[0]+=1
elif d==3:
b[1]+=1
p.append(tuple(b))
w=len({i[0] for i in p})
h=len({i[1] for i in p})
print(w,h)
``` | instruction | 0 | 89,186 | 23 | 178,372 |
Yes | output | 1 | 89,186 | 23 | 178,373 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Pablo Squarson is a well-known cubism artist. This year's theme for Pablo Squarson is "Squares". Today we are visiting his studio to see how his masterpieces are given birth.
At the center of his studio, there is a huuuuuge table and beside it are many, many squares of the same size. Pablo Squarson puts one of the squares on the table. Then he places some other squares on the table in sequence. It seems his methodical nature forces him to place each square side by side to the one that he already placed on, with machine-like precision.
Oh! The first piece of artwork is done. Pablo Squarson seems satisfied with it. Look at his happy face.
Oh, what's wrong with Pablo? He is tearing his hair! Oh, I see. He wants to find a box that fits the new piece of work but he has trouble figuring out its size. Let's help him!
Your mission is to write a program that takes instructions that record how Pablo made a piece of his artwork and computes its width and height. It is known that the size of each square is 1. You may assume that Pablo does not put a square on another.
I hear someone murmured "A smaller box will do". No, poor Pablo, shaking his head, is grumbling "My square style does not seem to be understood by illiterates".
<image>
Input
The input consists of a number of datasets. Each dataset represents the way Pablo made a piece of his artwork. The format of a dataset is as follows.
> N
n1 d1
n2 d2
...
nN-1 dN-1
The first line contains the number of squares (= N) used to make the piece of artwork. The number is a positive integer and is smaller than 200.
The remaining (N-1) lines in the dataset are square placement instructions. The line "ni di" indicates placement of the square numbered i (≤ N-1). The rules of numbering squares are as follows. The first square is numbered "zero". Subsequently placed squares are numbered 1, 2, ..., (N-1). Note that the input does not give any placement instruction to the first square, which is numbered zero.
A square placement instruction for the square numbered i, namely "ni di", directs it to be placed next to the one that is numbered ni, towards the direction given by di, which denotes leftward (= 0), downward (= 1), rightward (= 2), and upward (= 3).
For example, pieces of artwork corresponding to the four datasets shown in Sample Input are depicted below. Squares are labeled by their numbers.
<image>
The end of the input is indicated by a line that contains a single zero.
Output
For each dataset, output a line that contains the width and the height of the piece of artwork as decimal numbers, separated by a space. Each line should not contain any other characters.
Sample Input
1
5
0 0
0 1
0 2
0 3
12
0 0
1 0
2 0
3 1
4 1
5 1
6 2
7 2
8 2
9 3
10 3
10
0 2
1 2
2 2
3 2
2 1
5 1
6 1
7 1
8 1
0
Output for the Sample Input
1 1
3 3
4 4
5 6
Example
Input
1
5
0 0
0 1
0 2
0 3
12
0 0
1 0
2 0
3 1
4 1
5 1
6 2
7 2
8 2
9 3
10 3
10
0 2
1 2
2 2
3 2
2 1
5 1
6 1
7 1
8 1
0
Output
1 1
3 3
4 4
5 6
Submitted Solution:
```
ans_list = []
while True:
N = int(input())
if N == 0:
break
square = [[0, 0]]
for i in range(N - 1):
n, d = map(int, input().split())
#print(n, d)
if d == 0:
square.append([square[n][0], square[n][1] - 1])
elif d == 2:
square.append([square[n][0], square[n][1] + 1])
elif d == 1:
square.append([square[n][0] - 1, square[n][1]])
elif d == 3:
#print(100, square, square[n - 1])
square.append([square[n][0] + 1, square[n][1]])
#print(square)
mini = 10 ** 10
minj = 10 ** 10
maxi = -10 ** 9
maxj = -10 ** 9
if N == 1:
ans_list.append([1, 1])
else:
for i in range(len(square)):
mini = min(square[i][0], mini)
minj = min(square[i][1], minj)
maxi = max(square[i][0], maxi)
maxj = max(square[i][1], maxj)
#print(maxi, maxj, mini, minj)
ans_list.append([maxj - minj + 1, maxi - mini + 1])
for i in ans_list:
print(i[0], i[1])
``` | instruction | 0 | 89,187 | 23 | 178,374 |
Yes | output | 1 | 89,187 | 23 | 178,375 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Pablo Squarson is a well-known cubism artist. This year's theme for Pablo Squarson is "Squares". Today we are visiting his studio to see how his masterpieces are given birth.
At the center of his studio, there is a huuuuuge table and beside it are many, many squares of the same size. Pablo Squarson puts one of the squares on the table. Then he places some other squares on the table in sequence. It seems his methodical nature forces him to place each square side by side to the one that he already placed on, with machine-like precision.
Oh! The first piece of artwork is done. Pablo Squarson seems satisfied with it. Look at his happy face.
Oh, what's wrong with Pablo? He is tearing his hair! Oh, I see. He wants to find a box that fits the new piece of work but he has trouble figuring out its size. Let's help him!
Your mission is to write a program that takes instructions that record how Pablo made a piece of his artwork and computes its width and height. It is known that the size of each square is 1. You may assume that Pablo does not put a square on another.
I hear someone murmured "A smaller box will do". No, poor Pablo, shaking his head, is grumbling "My square style does not seem to be understood by illiterates".
<image>
Input
The input consists of a number of datasets. Each dataset represents the way Pablo made a piece of his artwork. The format of a dataset is as follows.
> N
n1 d1
n2 d2
...
nN-1 dN-1
The first line contains the number of squares (= N) used to make the piece of artwork. The number is a positive integer and is smaller than 200.
The remaining (N-1) lines in the dataset are square placement instructions. The line "ni di" indicates placement of the square numbered i (≤ N-1). The rules of numbering squares are as follows. The first square is numbered "zero". Subsequently placed squares are numbered 1, 2, ..., (N-1). Note that the input does not give any placement instruction to the first square, which is numbered zero.
A square placement instruction for the square numbered i, namely "ni di", directs it to be placed next to the one that is numbered ni, towards the direction given by di, which denotes leftward (= 0), downward (= 1), rightward (= 2), and upward (= 3).
For example, pieces of artwork corresponding to the four datasets shown in Sample Input are depicted below. Squares are labeled by their numbers.
<image>
The end of the input is indicated by a line that contains a single zero.
Output
For each dataset, output a line that contains the width and the height of the piece of artwork as decimal numbers, separated by a space. Each line should not contain any other characters.
Sample Input
1
5
0 0
0 1
0 2
0 3
12
0 0
1 0
2 0
3 1
4 1
5 1
6 2
7 2
8 2
9 3
10 3
10
0 2
1 2
2 2
3 2
2 1
5 1
6 1
7 1
8 1
0
Output for the Sample Input
1 1
3 3
4 4
5 6
Example
Input
1
5
0 0
0 1
0 2
0 3
12
0 0
1 0
2 0
3 1
4 1
5 1
6 2
7 2
8 2
9 3
10 3
10
0 2
1 2
2 2
3 2
2 1
5 1
6 1
7 1
8 1
0
Output
1 1
3 3
4 4
5 6
Submitted Solution:
```
while True:
n = int(input())
if n == 0 : break
w, h = 1, 1
edges = [[0], [0], [0], [0]] #[left, bottom, right, top]
for i in range(1, n):
p, d = map(int, input().split())
if d == 0 or d == 2:
if p in edges[d]:
w += 1
edges[d] = [i]
if p in edges[1]:
edges[1].append(i)
if p in edges[3]:
edges[3].append(i)
elif d == 1 or d == 3:
if p in edges[d]:
h += 1
edges[d] = [i]
if p in edges[0]:
edges[0].append(i)
if p in edges[2]:
edges[2].append(i)
#print(edges)
print(w,h)
``` | instruction | 0 | 89,188 | 23 | 178,376 |
No | output | 1 | 89,188 | 23 | 178,377 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Pablo Squarson is a well-known cubism artist. This year's theme for Pablo Squarson is "Squares". Today we are visiting his studio to see how his masterpieces are given birth.
At the center of his studio, there is a huuuuuge table and beside it are many, many squares of the same size. Pablo Squarson puts one of the squares on the table. Then he places some other squares on the table in sequence. It seems his methodical nature forces him to place each square side by side to the one that he already placed on, with machine-like precision.
Oh! The first piece of artwork is done. Pablo Squarson seems satisfied with it. Look at his happy face.
Oh, what's wrong with Pablo? He is tearing his hair! Oh, I see. He wants to find a box that fits the new piece of work but he has trouble figuring out its size. Let's help him!
Your mission is to write a program that takes instructions that record how Pablo made a piece of his artwork and computes its width and height. It is known that the size of each square is 1. You may assume that Pablo does not put a square on another.
I hear someone murmured "A smaller box will do". No, poor Pablo, shaking his head, is grumbling "My square style does not seem to be understood by illiterates".
<image>
Input
The input consists of a number of datasets. Each dataset represents the way Pablo made a piece of his artwork. The format of a dataset is as follows.
> N
n1 d1
n2 d2
...
nN-1 dN-1
The first line contains the number of squares (= N) used to make the piece of artwork. The number is a positive integer and is smaller than 200.
The remaining (N-1) lines in the dataset are square placement instructions. The line "ni di" indicates placement of the square numbered i (≤ N-1). The rules of numbering squares are as follows. The first square is numbered "zero". Subsequently placed squares are numbered 1, 2, ..., (N-1). Note that the input does not give any placement instruction to the first square, which is numbered zero.
A square placement instruction for the square numbered i, namely "ni di", directs it to be placed next to the one that is numbered ni, towards the direction given by di, which denotes leftward (= 0), downward (= 1), rightward (= 2), and upward (= 3).
For example, pieces of artwork corresponding to the four datasets shown in Sample Input are depicted below. Squares are labeled by their numbers.
<image>
The end of the input is indicated by a line that contains a single zero.
Output
For each dataset, output a line that contains the width and the height of the piece of artwork as decimal numbers, separated by a space. Each line should not contain any other characters.
Sample Input
1
5
0 0
0 1
0 2
0 3
12
0 0
1 0
2 0
3 1
4 1
5 1
6 2
7 2
8 2
9 3
10 3
10
0 2
1 2
2 2
3 2
2 1
5 1
6 1
7 1
8 1
0
Output for the Sample Input
1 1
3 3
4 4
5 6
Example
Input
1
5
0 0
0 1
0 2
0 3
12
0 0
1 0
2 0
3 1
4 1
5 1
6 2
7 2
8 2
9 3
10 3
10
0 2
1 2
2 2
3 2
2 1
5 1
6 1
7 1
8 1
0
Output
1 1
3 3
4 4
5 6
Submitted Solution:
```
while True:
N=int(input())
if N==0:break
t=[0]
y=[0]
lst=list(range(N))
for k in lst[1:]:
[x,d]=input().split()
[x,d]=[int(x),int(d)]
if d==0:
t=t+[t[x]]
y=y+[y[x]-1]
if d==1:
t=t+[t[x]-1]
y=y+[y[x]]
if d==2:
t=t+[t[x]]
y=y+[y[x]+1]
if d==3:
t=t+[t[x]+1]
y=y+[y[x]]
ht=0
lt=0
hy=0
ly=0
for f in range(N):
if ht<t[f]:
ht+=1
if lt>t[f]:
lt-=1
if hy<y[f]:
hy+=1
if ly>y[f]:
ly-=1
print(ht-lt+1,hy-ly+1)
``` | instruction | 0 | 89,189 | 23 | 178,378 |
No | output | 1 | 89,189 | 23 | 178,379 |
Provide a correct Python 3 solution for this coding contest problem.
Given a matrix (H × W) which contains only 1 and 0, find the area of the largest square matrix which only contains 0s.
Constraints
* 1 ≤ H, W ≤ 1,400
Input
H W
c1,1 c1,2 ... c1,W
c2,1 c2,2 ... c2,W
:
cH,1 cH,2 ... cH,W
In the first line, two integers H and W separated by a space character are given. In the following H lines, ci,j, elements of the H × W matrix, are given.
Output
Print the area (the number of 0s) of the largest square.
Example
Input
4 5
0 0 1 0 0
1 0 0 0 0
0 0 0 1 0
0 0 0 1 0
Output
4 | instruction | 0 | 89,218 | 23 | 178,436 |
"Correct Solution:
```
import sys
# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
# import heapq
import decimal
# import statistics
import queue
# import numpy as np
sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353
ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
# ===CODE===
eps = 10 ** (-9)
def main():
h, w = ns()
mat = [na() for _ in range(h)]
dp = [[0 for _ in range(w)] for __ in range(h)]
ans = 0
for i in range(h):
for j in range(w):
if mat[i][j]:
continue
if mat[i][j] == 0:
dp[i][j] = 1
if i > 0 and j > 0:
dp[i][j] = min(dp[i - 1][j - 1], dp[i - 1][j], dp[i][j - 1]) + 1
ans = max(ans, dp[i][j])
print(ans ** 2)
if __name__ == '__main__':
main()
``` | output | 1 | 89,218 | 23 | 178,437 |
Provide a correct Python 3 solution for this coding contest problem.
Given a matrix (H × W) which contains only 1 and 0, find the area of the largest square matrix which only contains 0s.
Constraints
* 1 ≤ H, W ≤ 1,400
Input
H W
c1,1 c1,2 ... c1,W
c2,1 c2,2 ... c2,W
:
cH,1 cH,2 ... cH,W
In the first line, two integers H and W separated by a space character are given. In the following H lines, ci,j, elements of the H × W matrix, are given.
Output
Print the area (the number of 0s) of the largest square.
Example
Input
4 5
0 0 1 0 0
1 0 0 0 0
0 0 0 1 0
0 0 0 1 0
Output
4 | instruction | 0 | 89,219 | 23 | 178,438 |
"Correct Solution:
```
H, W = map(int, input().split())
S = [list(map(int, input().split())) for i in range(H)]
dp = [[0]*(W) for i in range(H)]
for i in range(H):
for j in range(W):
if S[i][j] == 0:
dp[i][j] = min(dp[i-1][j-1], dp[i-1][j], dp[i][j-1])+1
# print(max([max([max(a) for a in dp])**2]))
print(max([max(a) for a in dp])**2)
``` | output | 1 | 89,219 | 23 | 178,439 |
Provide a correct Python 3 solution for this coding contest problem.
Given a matrix (H × W) which contains only 1 and 0, find the area of the largest square matrix which only contains 0s.
Constraints
* 1 ≤ H, W ≤ 1,400
Input
H W
c1,1 c1,2 ... c1,W
c2,1 c2,2 ... c2,W
:
cH,1 cH,2 ... cH,W
In the first line, two integers H and W separated by a space character are given. In the following H lines, ci,j, elements of the H × W matrix, are given.
Output
Print the area (the number of 0s) of the largest square.
Example
Input
4 5
0 0 1 0 0
1 0 0 0 0
0 0 0 1 0
0 0 0 1 0
Output
4 | instruction | 0 | 89,220 | 23 | 178,440 |
"Correct Solution:
```
h, w = map(int, input().split( ))
#c = [ [0] * w ]
#下の奴がまずい。各行が同一のアドレス指してる。上も一応変えておく。
#DP = [ [0] * w ] * ( h + 1 )
c=[[0 for _ in range(w)]]
DP = [[0 for _ in range(w)] for __ in range(h+1)]
for _ in range(h):
c_tmp = list(map(int, input().split( )))
c.append( c_tmp )
for i in range(w):
for j in range(1,h+1):
if c[j][i] == 1:
DP[j][i] = 0
else:
DP[j][i] = min(DP[j-1][i],DP[j][i-1],DP[j-1][i-1])+1
mx =0
for i in range(h+1):
mx =max(mx,max(DP[i]))
print(mx**2)
``` | output | 1 | 89,220 | 23 | 178,441 |
Provide a correct Python 3 solution for this coding contest problem.
Given a matrix (H × W) which contains only 1 and 0, find the area of the largest square matrix which only contains 0s.
Constraints
* 1 ≤ H, W ≤ 1,400
Input
H W
c1,1 c1,2 ... c1,W
c2,1 c2,2 ... c2,W
:
cH,1 cH,2 ... cH,W
In the first line, two integers H and W separated by a space character are given. In the following H lines, ci,j, elements of the H × W matrix, are given.
Output
Print the area (the number of 0s) of the largest square.
Example
Input
4 5
0 0 1 0 0
1 0 0 0 0
0 0 0 1 0
0 0 0 1 0
Output
4 | instruction | 0 | 89,221 | 23 | 178,442 |
"Correct Solution:
```
# DPL_3_A: Largest Square
import sys
H, W = map(int, sys.stdin.readline().strip().split())
dp = [[0] * (W + 1) for _ in range(H + 1)]
for h in range(1, H + 1):
c = list(map(int, sys.stdin.readline().strip().split()))
dirty = [i for i, x in enumerate(c) if x == 1]
for w in dirty:
dp[h][w + 1] = 'dirty'
ans = 0
for h in range(1, H + 1):
for w in range(1, W + 1):
if dp[h][w] == 'dirty':
dp[h][w] =0
continue
dp[h][w] = min(dp[h][w - 1], dp[h - 1][w - 1], dp[h - 1][w]) + 1
ans = max(dp[h][w], ans)
print(ans ** 2)
``` | output | 1 | 89,221 | 23 | 178,443 |
Provide a correct Python 3 solution for this coding contest problem.
Given a matrix (H × W) which contains only 1 and 0, find the area of the largest square matrix which only contains 0s.
Constraints
* 1 ≤ H, W ≤ 1,400
Input
H W
c1,1 c1,2 ... c1,W
c2,1 c2,2 ... c2,W
:
cH,1 cH,2 ... cH,W
In the first line, two integers H and W separated by a space character are given. In the following H lines, ci,j, elements of the H × W matrix, are given.
Output
Print the area (the number of 0s) of the largest square.
Example
Input
4 5
0 0 1 0 0
1 0 0 0 0
0 0 0 1 0
0 0 0 1 0
Output
4 | instruction | 0 | 89,222 | 23 | 178,444 |
"Correct Solution:
```
import sys
import itertools
h, w = map(int, sys.stdin.readline().split())
dp = [[0] * w for _ in range(h)]
G = [[int(j) for j in sys.stdin.readline().split()] for _ in range(h)]
for x in range(h):
dp[x][0] = 1 if G[x][0] == 0 else 0
for y in range(w):
dp[0][y] = 1 if G[0][y] == 0 else 0
for i in range(1, h):
for j in range(1, w):
if(G[i][j] == 0):
dp[i][j] = min(dp[i - 1][j - 1], dp[i - 1][j], dp[i][j - 1]) + 1
print(max(max(i) for i in dp) ** 2)
``` | output | 1 | 89,222 | 23 | 178,445 |
Provide a correct Python 3 solution for this coding contest problem.
Given a matrix (H × W) which contains only 1 and 0, find the area of the largest square matrix which only contains 0s.
Constraints
* 1 ≤ H, W ≤ 1,400
Input
H W
c1,1 c1,2 ... c1,W
c2,1 c2,2 ... c2,W
:
cH,1 cH,2 ... cH,W
In the first line, two integers H and W separated by a space character are given. In the following H lines, ci,j, elements of the H × W matrix, are given.
Output
Print the area (the number of 0s) of the largest square.
Example
Input
4 5
0 0 1 0 0
1 0 0 0 0
0 0 0 1 0
0 0 0 1 0
Output
4 | instruction | 0 | 89,223 | 23 | 178,446 |
"Correct Solution:
```
# -*- coding: utf-8 -*-
import sys
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7
H,W=MAP()
# 四方に一回り大きいグリッドを作る
grid = list2d(H+2, W+2, 0)
for i in range(1, H+1):
row = LIST()
for j in range(1, W+1):
grid[i][j] = row[j-1]
# dp[i][j] := i,jを右端とする最大正方形の辺の長さ
dp=list2d(H+2, W+2, 0)
for i in range(1, H+1):
for j in range(1, W+1):
if grid[i][j]!=1:
# i,jが汚れマスでなければ、左、左上、上から遷移させてくる
dp[i][j]=min(dp[i-1][j], dp[i][j-1], dp[i-1][j-1])+1
mx=0
for i in range(1, H+1):
mx=max(mx, max(dp[i]))
print(mx**2)
``` | output | 1 | 89,223 | 23 | 178,447 |
Provide a correct Python 3 solution for this coding contest problem.
Given a matrix (H × W) which contains only 1 and 0, find the area of the largest square matrix which only contains 0s.
Constraints
* 1 ≤ H, W ≤ 1,400
Input
H W
c1,1 c1,2 ... c1,W
c2,1 c2,2 ... c2,W
:
cH,1 cH,2 ... cH,W
In the first line, two integers H and W separated by a space character are given. In the following H lines, ci,j, elements of the H × W matrix, are given.
Output
Print the area (the number of 0s) of the largest square.
Example
Input
4 5
0 0 1 0 0
1 0 0 0 0
0 0 0 1 0
0 0 0 1 0
Output
4 | instruction | 0 | 89,224 | 23 | 178,448 |
"Correct Solution:
```
# DPL 3 A
def solve():
H, W = map(int, input().split())
c = [list(map(int, input().split())) for _ in range(H)]
dp = [[0] * (W+1) for _ in range(H+1)]
ans = 0
for i in range(1, H+1):
for j in range(1, W+1):
if c[i-1][j-1] == 1:
dp[i][j] == 0
else:
dp[i][j] = min(dp[i-1][j], dp[i][j-1], dp[i-1][j-1]) + 1
ans = max(ans, dp[i][j])
print(ans**2)
if __name__ == "__main__":
solve()
``` | output | 1 | 89,224 | 23 | 178,449 |
Provide a correct Python 3 solution for this coding contest problem.
Given a matrix (H × W) which contains only 1 and 0, find the area of the largest square matrix which only contains 0s.
Constraints
* 1 ≤ H, W ≤ 1,400
Input
H W
c1,1 c1,2 ... c1,W
c2,1 c2,2 ... c2,W
:
cH,1 cH,2 ... cH,W
In the first line, two integers H and W separated by a space character are given. In the following H lines, ci,j, elements of the H × W matrix, are given.
Output
Print the area (the number of 0s) of the largest square.
Example
Input
4 5
0 0 1 0 0
1 0 0 0 0
0 0 0 1 0
0 0 0 1 0
Output
4 | instruction | 0 | 89,225 | 23 | 178,450 |
"Correct Solution:
```
H, W = map(int, input().split())
c = []
for i in range(H):
c.append([int(i) for i in input().split()])
dp = [[0 for i in range(W)] for i in range(H)]
maxwidth = 0
for i in range(H):
for j in range(W):
dp[i][j] = (c[i][j] + 1) % 2
maxwidth |= dp[i][j]
for i in range(1, H):
for j in range(1, W):
if c[i][j]:
dp[i][j] = 0
else:
dp[i][j] = min(dp[i-1][j], dp[i-1][j-1], dp[i][j-1]) + 1
maxwidth = max(maxwidth,dp[i][j])
print(maxwidth**2)
``` | output | 1 | 89,225 | 23 | 178,451 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given a matrix (H × W) which contains only 1 and 0, find the area of the largest square matrix which only contains 0s.
Constraints
* 1 ≤ H, W ≤ 1,400
Input
H W
c1,1 c1,2 ... c1,W
c2,1 c2,2 ... c2,W
:
cH,1 cH,2 ... cH,W
In the first line, two integers H and W separated by a space character are given. In the following H lines, ci,j, elements of the H × W matrix, are given.
Output
Print the area (the number of 0s) of the largest square.
Example
Input
4 5
0 0 1 0 0
1 0 0 0 0
0 0 0 1 0
0 0 0 1 0
Output
4
Submitted Solution:
```
# -*- coding: utf-8 -*-
from itertools import chain
if __name__ == '__main__':
H, W = map(int, input().split())
C = []
dp = []
for i in range(H):
l = input().split()
C.append([int(x) for x in l])
dp.append([(int(x) + 1) % 2 for x in l])
for i in range(1, H):
for j in range(1, W):
if C[i][j] == 0:
dp[i][j] = min(dp[i - 1][j], dp[i][j - 1],
dp[i - 1][j - 1]) + 1
max_width = max(list(chain.from_iterable(dp)))
print(max_width**2)
``` | instruction | 0 | 89,226 | 23 | 178,452 |
Yes | output | 1 | 89,226 | 23 | 178,453 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given a matrix (H × W) which contains only 1 and 0, find the area of the largest square matrix which only contains 0s.
Constraints
* 1 ≤ H, W ≤ 1,400
Input
H W
c1,1 c1,2 ... c1,W
c2,1 c2,2 ... c2,W
:
cH,1 cH,2 ... cH,W
In the first line, two integers H and W separated by a space character are given. In the following H lines, ci,j, elements of the H × W matrix, are given.
Output
Print the area (the number of 0s) of the largest square.
Example
Input
4 5
0 0 1 0 0
1 0 0 0 0
0 0 0 1 0
0 0 0 1 0
Output
4
Submitted Solution:
```
import sys
h, w = map(int, sys.stdin.readline().split())
dp = [[0] * w for _ in range(h)]
G = [[int(j) for j in sys.stdin.readline().split()] for _ in range(h)]
for x in range(h):
dp[x][0] = 1 if G[x][0] == 0 else 0
for y in range(w):
dp[0][y] = 1 if G[0][y] == 0 else 0
for i in range(1, h):
for j in range(1, w):
if(G[i][j] == 0):
dp[i][j] = min(dp[i - 1][j - 1], dp[i - 1][j], dp[i][j - 1]) + 1
print(max([max(item) for item in dp])**2)
``` | instruction | 0 | 89,227 | 23 | 178,454 |
Yes | output | 1 | 89,227 | 23 | 178,455 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given a matrix (H × W) which contains only 1 and 0, find the area of the largest square matrix which only contains 0s.
Constraints
* 1 ≤ H, W ≤ 1,400
Input
H W
c1,1 c1,2 ... c1,W
c2,1 c2,2 ... c2,W
:
cH,1 cH,2 ... cH,W
In the first line, two integers H and W separated by a space character are given. In the following H lines, ci,j, elements of the H × W matrix, are given.
Output
Print the area (the number of 0s) of the largest square.
Example
Input
4 5
0 0 1 0 0
1 0 0 0 0
0 0 0 1 0
0 0 0 1 0
Output
4
Submitted Solution:
```
H,W = map(int,input().split())
M = [[0]*(W+1) for _ in range(H+1)]
for i in range(H):
M[i+1][1:] = list(map(int,input().split()))
dp = [[0]*(W+1) for _ in range(H+1)]
for h in range(1,H+1):
for w in range(1,W+1):
if M[h][w] == 0:
dp[h][w] = min(dp[h-1][w-1],dp[h-1][w],dp[h][w-1]) + 1
else:
dp[h][w] = 0
print(max([max(x) for x in dp])**2)
``` | instruction | 0 | 89,228 | 23 | 178,456 |
Yes | output | 1 | 89,228 | 23 | 178,457 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given a matrix (H × W) which contains only 1 and 0, find the area of the largest square matrix which only contains 0s.
Constraints
* 1 ≤ H, W ≤ 1,400
Input
H W
c1,1 c1,2 ... c1,W
c2,1 c2,2 ... c2,W
:
cH,1 cH,2 ... cH,W
In the first line, two integers H and W separated by a space character are given. In the following H lines, ci,j, elements of the H × W matrix, are given.
Output
Print the area (the number of 0s) of the largest square.
Example
Input
4 5
0 0 1 0 0
1 0 0 0 0
0 0 0 1 0
0 0 0 1 0
Output
4
Submitted Solution:
```
if __name__ == "__main__":
H, W = map(lambda x: int(x), input().split())
dp = [list(map(int, input().split())) for _ in range(H)]
for h in range(H):
for w in range(W):
dp[h][w] ^= 1 # 0 -> 1, 1 -> 0
for h in range(1, H):
for w in range(1, W):
if dp[h][w]:
dp[h][w] = min(dp[h - 1][w - 1], dp[h - 1][w], dp[h][w - 1])
dp[h][w] += 1
print(max(w for h in dp for w in h) ** 2) # type: ignore
``` | instruction | 0 | 89,229 | 23 | 178,458 |
Yes | output | 1 | 89,229 | 23 | 178,459 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given a matrix (H × W) which contains only 1 and 0, find the area of the largest square matrix which only contains 0s.
Constraints
* 1 ≤ H, W ≤ 1,400
Input
H W
c1,1 c1,2 ... c1,W
c2,1 c2,2 ... c2,W
:
cH,1 cH,2 ... cH,W
In the first line, two integers H and W separated by a space character are given. In the following H lines, ci,j, elements of the H × W matrix, are given.
Output
Print the area (the number of 0s) of the largest square.
Example
Input
4 5
0 0 1 0 0
1 0 0 0 0
0 0 0 1 0
0 0 0 1 0
Output
4
Submitted Solution:
```
H, W = map(int, input().split())
c = []
for i in range(H):
c.append([int(i) for i in input().split()])
dp = [[0 for i in range(W)] for i in range(H)]
dp[0][0] = 1 if c[0][0] == 0 else 0
for j in range(W):
if c[0][0] == 1:
dp[0][j] = 0
else:
dp[0][j] = 1
for j in range(H):
if c[0][0] == 1:
dp[j][0] = 0
else:
dp[j][0] = 1
for i in range(1, H):
for j in range(1, W):
dp[i][j] = min(dp[i-1][j], dp[i-1][j-1], dp[i][j-1]) + 1
print(dp[H-1][W-1])
``` | instruction | 0 | 89,230 | 23 | 178,460 |
No | output | 1 | 89,230 | 23 | 178,461 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given a matrix (H × W) which contains only 1 and 0, find the area of the largest square matrix which only contains 0s.
Constraints
* 1 ≤ H, W ≤ 1,400
Input
H W
c1,1 c1,2 ... c1,W
c2,1 c2,2 ... c2,W
:
cH,1 cH,2 ... cH,W
In the first line, two integers H and W separated by a space character are given. In the following H lines, ci,j, elements of the H × W matrix, are given.
Output
Print the area (the number of 0s) of the largest square.
Example
Input
4 5
0 0 1 0 0
1 0 0 0 0
0 0 0 1 0
0 0 0 1 0
Output
4
Submitted Solution:
```
def solve():
H, W = map(int, input().split())
c = []
for _ in range(H):
c.append(list(map(int, input().split())))
dp = [0] * (W+1)*(H+1)
for i in range(H):
for j in range(W):
if c[i][j] == 0:
dp[i+1 + H*(j+1)] = min(dp[i + H*j], dp[i+1 + H*j], dp[i + H*(j+1)]) + 1
print(max(dp)**2)
if __name__ == '__main__':
solve()
``` | instruction | 0 | 89,231 | 23 | 178,462 |
No | output | 1 | 89,231 | 23 | 178,463 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given a matrix (H × W) which contains only 1 and 0, find the area of the largest square matrix which only contains 0s.
Constraints
* 1 ≤ H, W ≤ 1,400
Input
H W
c1,1 c1,2 ... c1,W
c2,1 c2,2 ... c2,W
:
cH,1 cH,2 ... cH,W
In the first line, two integers H and W separated by a space character are given. In the following H lines, ci,j, elements of the H × W matrix, are given.
Output
Print the area (the number of 0s) of the largest square.
Example
Input
4 5
0 0 1 0 0
1 0 0 0 0
0 0 0 1 0
0 0 0 1 0
Output
4
Submitted Solution:
```
import sys
h, w = map(int, sys.stdin.readline().split())
dp = [[0] * w for _ in range(h)]
G = [list(map(int, i.split())) for i in sys.stdin.readlines()]
for x in range(h):
dp[x][0] = 1 if G[x][0] == 0 else 0
for y in range(w):
dp[0][y] = 1 if G[0][y] == 0 else 0
for i in range(1, h):
for j in range(1, w):
if(G[i][j] == 0):
dp[i][j] = min(dp[i - 1][j - 1], dp[i - 1][j], dp[i][j - 1]) + 1
print(max(sum(dp, [])) ** 2)
``` | instruction | 0 | 89,232 | 23 | 178,464 |
No | output | 1 | 89,232 | 23 | 178,465 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given a matrix (H × W) which contains only 1 and 0, find the area of the largest square matrix which only contains 0s.
Constraints
* 1 ≤ H, W ≤ 1,400
Input
H W
c1,1 c1,2 ... c1,W
c2,1 c2,2 ... c2,W
:
cH,1 cH,2 ... cH,W
In the first line, two integers H and W separated by a space character are given. In the following H lines, ci,j, elements of the H × W matrix, are given.
Output
Print the area (the number of 0s) of the largest square.
Example
Input
4 5
0 0 1 0 0
1 0 0 0 0
0 0 0 1 0
0 0 0 1 0
Output
4
Submitted Solution:
```
def counting(k, v, square):
square += 1
for _ in range(square):
for r in range(k, k + square):
if r > len(matrix) - 1:
return False
for c in range(v, v + square):
if c > len(matrix[k]) - 1:
return False
if matrix[r][c] == '1':
return False
return True
line = input().split(' ')
answer = [[0 for _ in range(int(line[1]))] for _ in range(int(line[0]))]
matrix = []
maximum = 0
is_over = False
ggg = 0
for _ in range(int(line[0])):
row = input().split(' ')
matrix.append(row)
for i in range(len(matrix)):
for j in range(len(matrix[i])):
ggg += 1
for m in range(min(int(line[0]), int(line[1]))):
res = counting(i, j, maximum)
if res:
maximum += 1
else:
break
print(1 if maximum == 0 else maximum * maximum)
``` | instruction | 0 | 89,233 | 23 | 178,466 |
No | output | 1 | 89,233 | 23 | 178,467 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 ≤ x ≤ x_2 and y_1 ≤ y ≤ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 ≤ n ≤ 100 000), the number of points in Pavel's records.
The second line contains 2 ⋅ n integers a_1, a_2, ..., a_{2 ⋅ n} (1 ≤ a_i ≤ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). | instruction | 0 | 89,250 | 23 | 178,500 |
Tags: brute force, implementation, math, sortings
Correct Solution:
```
def photo(n,m):
if n<=1:
return 0
m=m.split()
m=[int(m[i]) for i in range(len(m))]
m.sort()
x1=m[len(m)-1]-m[0]
c=m[1:len(m)-1]
differ=[(c[i+n-1]-c[i]) for i in range(len(c)+2-n-1)]
y1=min(differ)
result=[x1*y1]
x=(m[n-1]-m[0])*(m[len(m)-1]-m[n])
result.append(x)
return min(result)
print(photo(int(input().strip()),input().strip()))
``` | output | 1 | 89,250 | 23 | 178,501 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 ≤ x ≤ x_2 and y_1 ≤ y ≤ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 ≤ n ≤ 100 000), the number of points in Pavel's records.
The second line contains 2 ⋅ n integers a_1, a_2, ..., a_{2 ⋅ n} (1 ≤ a_i ≤ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). | instruction | 0 | 89,251 | 23 | 178,502 |
Tags: brute force, implementation, math, sortings
Correct Solution:
```
from sys import stdin, stdout
# string input
n = int(stdin.readline())
arr = [int(x) for x in stdin.readline().split()]
arr.sort()
x1 = arr[0]
x2 = arr[n-1]
y1 = arr[n]
y2 = arr[(2*n) - 1]
mini = (x2-x1)*(y2-y1)
for i in range(1, n):
j = i + n - 1
x1 = arr[i]
x2 = arr[j]
y1 = arr[0]
y2 = arr[2*n -1]
prod = (x2-x1)*(y2-y1)
if (prod < mini):
mini = prod
print(mini)
# print to stdout
#stdout.write(str(summation))
``` | output | 1 | 89,251 | 23 | 178,503 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 ≤ x ≤ x_2 and y_1 ≤ y ≤ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 ≤ n ≤ 100 000), the number of points in Pavel's records.
The second line contains 2 ⋅ n integers a_1, a_2, ..., a_{2 ⋅ n} (1 ≤ a_i ≤ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). | instruction | 0 | 89,252 | 23 | 178,504 |
Tags: brute force, implementation, math, sortings
Correct Solution:
```
# -*- coding: utf-8 -*-
"""
Created on Mon Jul 30 14:37:45 2018
@author: Amrita
"""
N = int(input())
Ns = list(map(int,input().strip().split()))
Ns.sort()
diff1 = Ns[N-1] - Ns[0]
diff2 = Ns[-1] - Ns[N]
best = diff1*diff2
diff_ends = Ns[-1] - Ns[0]
for x in range(N):
diff = (Ns[x+N-1] - Ns[x]) * diff_ends
if diff < best:
best = diff
print(best)
``` | output | 1 | 89,252 | 23 | 178,505 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 ≤ x ≤ x_2 and y_1 ≤ y ≤ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 ≤ n ≤ 100 000), the number of points in Pavel's records.
The second line contains 2 ⋅ n integers a_1, a_2, ..., a_{2 ⋅ n} (1 ≤ a_i ≤ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). | instruction | 0 | 89,253 | 23 | 178,506 |
Tags: brute force, implementation, math, sortings
Correct Solution:
```
n=int(input())
a=sorted(map(int,input().split()))
print(min([(a[n-1]-a[0])*(a[-1]-a[n])]+[(a[-1]-a[0])*(a[i+n-1]-a[i])
for i in range(n)]))
# Made By Mostafa_Khaled
``` | output | 1 | 89,253 | 23 | 178,507 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 ≤ x ≤ x_2 and y_1 ≤ y ≤ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 ≤ n ≤ 100 000), the number of points in Pavel's records.
The second line contains 2 ⋅ n integers a_1, a_2, ..., a_{2 ⋅ n} (1 ≤ a_i ≤ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). | instruction | 0 | 89,254 | 23 | 178,508 |
Tags: brute force, implementation, math, sortings
Correct Solution:
```
n = int(input())
nums = [int(i) for i in input().split()]
if n == 1:
print(0)
else:
nums.sort()
area_1 = None
for i in range(1,n):
temp = (nums[-1]-nums[0])*(nums[i+n-1]-nums[i])
if area_1 is None or temp < area_1:
area_1 = temp
temp = (nums[n-1]-nums[0])*(nums[-1]-nums[n])
if temp < area_1:
area_1 = temp
print(area_1)
``` | output | 1 | 89,254 | 23 | 178,509 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 ≤ x ≤ x_2 and y_1 ≤ y ≤ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 ≤ n ≤ 100 000), the number of points in Pavel's records.
The second line contains 2 ⋅ n integers a_1, a_2, ..., a_{2 ⋅ n} (1 ≤ a_i ≤ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). | instruction | 0 | 89,255 | 23 | 178,510 |
Tags: brute force, implementation, math, sortings
Correct Solution:
```
if __name__ == "__main__":
n = int(input())
s = sorted(map(int, input().split()))
h = s[2 * n - 1] - s[0]
best = (s[n-1] - s[0]) * (s[2*n - 1] - s[n])
for i in range(1, n):
w = s[i + n - 1] - s[i]
new = h * w
if new < best:
best = new
print(best)
``` | output | 1 | 89,255 | 23 | 178,511 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 ≤ x ≤ x_2 and y_1 ≤ y ≤ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 ≤ n ≤ 100 000), the number of points in Pavel's records.
The second line contains 2 ⋅ n integers a_1, a_2, ..., a_{2 ⋅ n} (1 ≤ a_i ≤ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). | instruction | 0 | 89,256 | 23 | 178,512 |
Tags: brute force, implementation, math, sortings
Correct Solution:
```
import sys
import math
import bisect
def input():
return sys.stdin.readline().strip()
def iinput():
return int(input())
def finput():
return float(input())
def tinput():
return input().split()
def rinput():
return map(int, tinput())
def rlinput():
return list(rinput())
def modst(a, s):
res = 1
while s:
if s % 2:
res *= a
a *= a
s //= 2
return res
def size(x1, y1, x2, y2):
return ((x1 + x2) ** 2 + (y1 + y2) ** 2) ** 0.5
def d(sum_size, size_x_y):
rerurn (sum_size ** 2 - 8 * size_x_y) ** 0.5
def main():
n = iinput()
a = rlinput()
a.sort()
if n == 1:
return 0
q = 1e10
for i in range(1, n):
q = min(q, a[i + n - 1] - a[i])
return min((a[2 * n - 1] - a[0]) * q, (a[n - 1] - a[0]) * (a[2 * n - 1] - a[n]))
print(main())
``` | output | 1 | 89,256 | 23 | 178,513 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 ≤ x ≤ x_2 and y_1 ≤ y ≤ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 ≤ n ≤ 100 000), the number of points in Pavel's records.
The second line contains 2 ⋅ n integers a_1, a_2, ..., a_{2 ⋅ n} (1 ≤ a_i ≤ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). | instruction | 0 | 89,257 | 23 | 178,514 |
Tags: brute force, implementation, math, sortings
Correct Solution:
```
import heapq
from math import sqrt
from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
dic = defaultdict(int)
if n == 1:
print(0)
exit()
for v in a:
dic[v] += 1
for v, j in dic.items():
if j >= n:
print(0)
exit()
a.sort()
m = n - 1
c = a[2*n - 1] - a[m + 1]
d = a[m] - a[0]
tmp = a[2 * n - 1] - a[0]
aim = c * d / tmp
d = [c * d]
for i in range(n + 1):
t = a[i + n - 1] - a[i]
if t <= aim:
d.append(t * tmp)
print(min(d))
``` | output | 1 | 89,257 | 23 | 178,515 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 ≤ x ≤ x_2 and y_1 ≤ y ≤ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 ≤ n ≤ 100 000), the number of points in Pavel's records.
The second line contains 2 ⋅ n integers a_1, a_2, ..., a_{2 ⋅ n} (1 ≤ a_i ≤ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)).
Submitted Solution:
```
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
n_, n = n, 2 * n
C = Counter(a)
if max(C.values()) >= n_:
print(0)
exit()
a_s = sorted(a)
ans_1 = (a_s[n_ - 1] - a_s[0]) * (a_s[n - 1] - a_s[n_])
a0 = a_s[-1] - a_s[0]
b0 = a0
for i in range(n_ - 1):
b0 = min(b0, a_s[i + n_] - a_s[i + 1])
ans_2 = a0 * b0
ans = min(ans_1, ans_2)
print(ans)
``` | instruction | 0 | 89,258 | 23 | 178,516 |
Yes | output | 1 | 89,258 | 23 | 178,517 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 ≤ x ≤ x_2 and y_1 ≤ y ≤ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 ≤ n ≤ 100 000), the number of points in Pavel's records.
The second line contains 2 ⋅ n integers a_1, a_2, ..., a_{2 ⋅ n} (1 ≤ a_i ≤ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)).
Submitted Solution:
```
'''input
4
1 1 2 2 2 2 3 3
'''
n = int(input())
a = sorted(map(int, input().split()))
x1, y2 = a[0], a[-1]
x2, y1 = a[n-1], a[n]
m = (x1 - x2) * (y1 - y2)
x1, x2 = a[0], a[-1]
for i in range(1, n):
y1, y2 = a[i], a[i+n-1]
m = min(m, (x1 - x2) * (y1 - y2))
print(m)
``` | instruction | 0 | 89,259 | 23 | 178,518 |
Yes | output | 1 | 89,259 | 23 | 178,519 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 ≤ x ≤ x_2 and y_1 ≤ y ≤ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 ≤ n ≤ 100 000), the number of points in Pavel's records.
The second line contains 2 ⋅ n integers a_1, a_2, ..., a_{2 ⋅ n} (1 ≤ a_i ≤ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)).
Submitted Solution:
```
n = int(input())
l = input().split()
l = [int(i) for i in l]
l.sort()
m = (l[2*n - 1] - l[n])*(l[n - 1] - l[0])
for i in range(1,n):
if m > (l[2*n - 1] - l[0])*(l[i + n - 1] - l[i]):
m = (l[2*n - 1] - l[0])*(l[i + n - 1] - l[i]);
print(m)
``` | instruction | 0 | 89,260 | 23 | 178,520 |
Yes | output | 1 | 89,260 | 23 | 178,521 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 ≤ x ≤ x_2 and y_1 ≤ y ≤ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 ≤ n ≤ 100 000), the number of points in Pavel's records.
The second line contains 2 ⋅ n integers a_1, a_2, ..., a_{2 ⋅ n} (1 ≤ a_i ≤ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)).
Submitted Solution:
```
n= int(input())
l = sorted(list(map(int,input().split())))
ret = (l[n-1]-l[0])*(l[-1]-l[n])
if ret>0:
for x,y in zip(l[1:n],l[n:-1]):
ret = min(ret, (y-x)*(l[-1]-l[0]))
print(ret)
``` | instruction | 0 | 89,261 | 23 | 178,522 |
Yes | output | 1 | 89,261 | 23 | 178,523 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 ≤ x ≤ x_2 and y_1 ≤ y ≤ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 ≤ n ≤ 100 000), the number of points in Pavel's records.
The second line contains 2 ⋅ n integers a_1, a_2, ..., a_{2 ⋅ n} (1 ≤ a_i ≤ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)).
Submitted Solution:
```
class State:
def __init__(self, x, y):
self.x = sorted(x)
self.y = sorted(y)
def area(self):
return (max(self.x) - min(self.x)) * (max(self.y) - min(self.y))
def __repr__(self):
return f"State with area {self.area()}, x={self.x}, y={self.y}"
def try_switching_first(state):
# Switching first elemnts of the array
candidate_x = state.x[1:] + state.y[-1:]
candidate_y = state.y[1:] + state.x[-1:]
candiadte_state = State(candidate_x, candidate_y)
if candiadte_state.area() < state.area():
return True, candiadte_state
else:
return False, state
def try_switching_last(state):
# Switching first elemnts of the array
candidate_x = state.x[:-1] + state.y[:1]
candidate_y = state.y[:-1] + state.x[-1:]
candiadte_state = State(candidate_x, candidate_y)
if candiadte_state.area() < state.area():
return True, candiadte_state
else:
return False, state
def optimize_untill_done(s):
result, new_state = try_switching_first(s)
print("New:", new_state)
if result:
# print(f"Switching first worked. New state {new_state}")
return optimize_untill_done(new_state)
result, new_state = try_switching_last(s)
if result:
# print(f"Switching last worked. New state {new_state}")
return optimize_untill_done(new_state)
return s.area()
if __name__ == "__main__":
n = int(input())
data = list(map(int, input().split()))
s = State(data[:n], data[n:])
print(optimize_untill_done(s))
``` | instruction | 0 | 89,262 | 23 | 178,524 |
No | output | 1 | 89,262 | 23 | 178,525 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.