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.
There is an image with a height of H pixels and a width of W pixels. Each of the pixels is represented by either `.` or `*`. The character representing the pixel at the i-th row from the top and the j-th column from the left, is denoted by C_{i,j}.
Extend this image vertically so that its height is doubled. That is, print a image with a height of 2H pixels and a width of W pixels where the pixel at the i-th row and j-th column is equal to C_{(i+1)/2,j} (the result of division is rounded down).
Constraints
* 1≦H, W≦100
* C_{i,j} is either `.` or `*`.
Input
The input is given from Standard Input in the following format:
H W
C_{1,1}...C_{1,W}
:
C_{H,1}...C_{H,W}
Output
Print the extended image.
Examples
Input
2 2
*.
.*
Output
*.
*.
.*
.*
Input
1 4
***.
Output
***.
***.
Input
9 20
.....***....***.....
....*...*..*...*....
...*.....**.....*...
...*.....*......*...
....*.....*....*....
.....**..*...**.....
.......*..*.*.......
........**.*........
.........**.........
Output
.....***....***.....
.....***....***.....
....*...*..*...*....
....*...*..*...*....
...*.....**.....*...
...*.....**.....*...
...*.....*......*...
...*.....*......*...
....*.....*....*....
....*.....*....*....
.....**..*...**.....
.....**..*...**.....
.......*..*.*.......
.......*..*.*.......
........**.*........
........**.*........
.........**.........
.........**......... | instruction | 0 | 17,573 | 23 | 35,146 |
"Correct Solution:
```
h = int(input().split()[0])
for i in range(h):
line = input()
print(line)
print(line)
``` | output | 1 | 17,573 | 23 | 35,147 |
Provide a correct Python 3 solution for this coding contest problem.
There is an image with a height of H pixels and a width of W pixels. Each of the pixels is represented by either `.` or `*`. The character representing the pixel at the i-th row from the top and the j-th column from the left, is denoted by C_{i,j}.
Extend this image vertically so that its height is doubled. That is, print a image with a height of 2H pixels and a width of W pixels where the pixel at the i-th row and j-th column is equal to C_{(i+1)/2,j} (the result of division is rounded down).
Constraints
* 1≦H, W≦100
* C_{i,j} is either `.` or `*`.
Input
The input is given from Standard Input in the following format:
H W
C_{1,1}...C_{1,W}
:
C_{H,1}...C_{H,W}
Output
Print the extended image.
Examples
Input
2 2
*.
.*
Output
*.
*.
.*
.*
Input
1 4
***.
Output
***.
***.
Input
9 20
.....***....***.....
....*...*..*...*....
...*.....**.....*...
...*.....*......*...
....*.....*....*....
.....**..*...**.....
.......*..*.*.......
........**.*........
.........**.........
Output
.....***....***.....
.....***....***.....
....*...*..*...*....
....*...*..*...*....
...*.....**.....*...
...*.....**.....*...
...*.....*......*...
...*.....*......*...
....*.....*....*....
....*.....*....*....
.....**..*...**.....
.....**..*...**.....
.......*..*.*.......
.......*..*.*.......
........**.*........
........**.*........
.........**.........
.........**......... | instruction | 0 | 17,574 | 23 | 35,148 |
"Correct Solution:
```
h,m=map(int,input().split())
a=[input()for i in range(h)]
for i in a:
print(i)
print(i)
``` | output | 1 | 17,574 | 23 | 35,149 |
Provide a correct Python 3 solution for this coding contest problem.
There is an image with a height of H pixels and a width of W pixels. Each of the pixels is represented by either `.` or `*`. The character representing the pixel at the i-th row from the top and the j-th column from the left, is denoted by C_{i,j}.
Extend this image vertically so that its height is doubled. That is, print a image with a height of 2H pixels and a width of W pixels where the pixel at the i-th row and j-th column is equal to C_{(i+1)/2,j} (the result of division is rounded down).
Constraints
* 1≦H, W≦100
* C_{i,j} is either `.` or `*`.
Input
The input is given from Standard Input in the following format:
H W
C_{1,1}...C_{1,W}
:
C_{H,1}...C_{H,W}
Output
Print the extended image.
Examples
Input
2 2
*.
.*
Output
*.
*.
.*
.*
Input
1 4
***.
Output
***.
***.
Input
9 20
.....***....***.....
....*...*..*...*....
...*.....**.....*...
...*.....*......*...
....*.....*....*....
.....**..*...**.....
.......*..*.*.......
........**.*........
.........**.........
Output
.....***....***.....
.....***....***.....
....*...*..*...*....
....*...*..*...*....
...*.....**.....*...
...*.....**.....*...
...*.....*......*...
...*.....*......*...
....*.....*....*....
....*.....*....*....
.....**..*...**.....
.....**..*...**.....
.......*..*.*.......
.......*..*.*.......
........**.*........
........**.*........
.........**.........
.........**......... | instruction | 0 | 17,575 | 23 | 35,150 |
"Correct Solution:
```
for i in range(int(input().split()[0])):
a = input()
print(a, a, sep='\n')
``` | output | 1 | 17,575 | 23 | 35,151 |
Provide a correct Python 3 solution for this coding contest problem.
There is an image with a height of H pixels and a width of W pixels. Each of the pixels is represented by either `.` or `*`. The character representing the pixel at the i-th row from the top and the j-th column from the left, is denoted by C_{i,j}.
Extend this image vertically so that its height is doubled. That is, print a image with a height of 2H pixels and a width of W pixels where the pixel at the i-th row and j-th column is equal to C_{(i+1)/2,j} (the result of division is rounded down).
Constraints
* 1≦H, W≦100
* C_{i,j} is either `.` or `*`.
Input
The input is given from Standard Input in the following format:
H W
C_{1,1}...C_{1,W}
:
C_{H,1}...C_{H,W}
Output
Print the extended image.
Examples
Input
2 2
*.
.*
Output
*.
*.
.*
.*
Input
1 4
***.
Output
***.
***.
Input
9 20
.....***....***.....
....*...*..*...*....
...*.....**.....*...
...*.....*......*...
....*.....*....*....
.....**..*...**.....
.......*..*.*.......
........**.*........
.........**.........
Output
.....***....***.....
.....***....***.....
....*...*..*...*....
....*...*..*...*....
...*.....**.....*...
...*.....**.....*...
...*.....*......*...
...*.....*......*...
....*.....*....*....
....*.....*....*....
.....**..*...**.....
.....**..*...**.....
.......*..*.*.......
.......*..*.*.......
........**.*........
........**.*........
.........**.........
.........**......... | instruction | 0 | 17,576 | 23 | 35,152 |
"Correct Solution:
```
h,w = map(int, input().split())
for _ in range(h):
row = input()
print(row)
print(row)
``` | output | 1 | 17,576 | 23 | 35,153 |
Provide a correct Python 3 solution for this coding contest problem.
There is an image with a height of H pixels and a width of W pixels. Each of the pixels is represented by either `.` or `*`. The character representing the pixel at the i-th row from the top and the j-th column from the left, is denoted by C_{i,j}.
Extend this image vertically so that its height is doubled. That is, print a image with a height of 2H pixels and a width of W pixels where the pixel at the i-th row and j-th column is equal to C_{(i+1)/2,j} (the result of division is rounded down).
Constraints
* 1≦H, W≦100
* C_{i,j} is either `.` or `*`.
Input
The input is given from Standard Input in the following format:
H W
C_{1,1}...C_{1,W}
:
C_{H,1}...C_{H,W}
Output
Print the extended image.
Examples
Input
2 2
*.
.*
Output
*.
*.
.*
.*
Input
1 4
***.
Output
***.
***.
Input
9 20
.....***....***.....
....*...*..*...*....
...*.....**.....*...
...*.....*......*...
....*.....*....*....
.....**..*...**.....
.......*..*.*.......
........**.*........
.........**.........
Output
.....***....***.....
.....***....***.....
....*...*..*...*....
....*...*..*...*....
...*.....**.....*...
...*.....**.....*...
...*.....*......*...
...*.....*......*...
....*.....*....*....
....*.....*....*....
.....**..*...**.....
.....**..*...**.....
.......*..*.*.......
.......*..*.*.......
........**.*........
........**.*........
.........**.........
.........**......... | instruction | 0 | 17,577 | 23 | 35,154 |
"Correct Solution:
```
H,W=map(int,input().split())
for i in range(H):
S=input()
print(S)
print(S)
``` | output | 1 | 17,577 | 23 | 35,155 |
Provide a correct Python 3 solution for this coding contest problem.
There is an image with a height of H pixels and a width of W pixels. Each of the pixels is represented by either `.` or `*`. The character representing the pixel at the i-th row from the top and the j-th column from the left, is denoted by C_{i,j}.
Extend this image vertically so that its height is doubled. That is, print a image with a height of 2H pixels and a width of W pixels where the pixel at the i-th row and j-th column is equal to C_{(i+1)/2,j} (the result of division is rounded down).
Constraints
* 1≦H, W≦100
* C_{i,j} is either `.` or `*`.
Input
The input is given from Standard Input in the following format:
H W
C_{1,1}...C_{1,W}
:
C_{H,1}...C_{H,W}
Output
Print the extended image.
Examples
Input
2 2
*.
.*
Output
*.
*.
.*
.*
Input
1 4
***.
Output
***.
***.
Input
9 20
.....***....***.....
....*...*..*...*....
...*.....**.....*...
...*.....*......*...
....*.....*....*....
.....**..*...**.....
.......*..*.*.......
........**.*........
.........**.........
Output
.....***....***.....
.....***....***.....
....*...*..*...*....
....*...*..*...*....
...*.....**.....*...
...*.....**.....*...
...*.....*......*...
...*.....*......*...
....*.....*....*....
....*.....*....*....
.....**..*...**.....
.....**..*...**.....
.......*..*.*.......
.......*..*.*.......
........**.*........
........**.*........
.........**.........
.........**......... | instruction | 0 | 17,578 | 23 | 35,156 |
"Correct Solution:
```
h,w=map(int,input().split())
for i in range(h):
s=input()
print(s+'\n'+s)
``` | output | 1 | 17,578 | 23 | 35,157 |
Provide a correct Python 3 solution for this coding contest problem.
There is an image with a height of H pixels and a width of W pixels. Each of the pixels is represented by either `.` or `*`. The character representing the pixel at the i-th row from the top and the j-th column from the left, is denoted by C_{i,j}.
Extend this image vertically so that its height is doubled. That is, print a image with a height of 2H pixels and a width of W pixels where the pixel at the i-th row and j-th column is equal to C_{(i+1)/2,j} (the result of division is rounded down).
Constraints
* 1≦H, W≦100
* C_{i,j} is either `.` or `*`.
Input
The input is given from Standard Input in the following format:
H W
C_{1,1}...C_{1,W}
:
C_{H,1}...C_{H,W}
Output
Print the extended image.
Examples
Input
2 2
*.
.*
Output
*.
*.
.*
.*
Input
1 4
***.
Output
***.
***.
Input
9 20
.....***....***.....
....*...*..*...*....
...*.....**.....*...
...*.....*......*...
....*.....*....*....
.....**..*...**.....
.......*..*.*.......
........**.*........
.........**.........
Output
.....***....***.....
.....***....***.....
....*...*..*...*....
....*...*..*...*....
...*.....**.....*...
...*.....**.....*...
...*.....*......*...
...*.....*......*...
....*.....*....*....
....*.....*....*....
.....**..*...**.....
.....**..*...**.....
.......*..*.*.......
.......*..*.*.......
........**.*........
........**.*........
.........**.........
.........**......... | instruction | 0 | 17,579 | 23 | 35,158 |
"Correct Solution:
```
h, w = [int(i) for i in input().split()]
for hi in range(h):
s = input()
print(s)
print(s)
``` | output | 1 | 17,579 | 23 | 35,159 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is an image with a height of H pixels and a width of W pixels. Each of the pixels is represented by either `.` or `*`. The character representing the pixel at the i-th row from the top and the j-th column from the left, is denoted by C_{i,j}.
Extend this image vertically so that its height is doubled. That is, print a image with a height of 2H pixels and a width of W pixels where the pixel at the i-th row and j-th column is equal to C_{(i+1)/2,j} (the result of division is rounded down).
Constraints
* 1≦H, W≦100
* C_{i,j} is either `.` or `*`.
Input
The input is given from Standard Input in the following format:
H W
C_{1,1}...C_{1,W}
:
C_{H,1}...C_{H,W}
Output
Print the extended image.
Examples
Input
2 2
*.
.*
Output
*.
*.
.*
.*
Input
1 4
***.
Output
***.
***.
Input
9 20
.....***....***.....
....*...*..*...*....
...*.....**.....*...
...*.....*......*...
....*.....*....*....
.....**..*...**.....
.......*..*.*.......
........**.*........
.........**.........
Output
.....***....***.....
.....***....***.....
....*...*..*...*....
....*...*..*...*....
...*.....**.....*...
...*.....**.....*...
...*.....*......*...
...*.....*......*...
....*.....*....*....
....*.....*....*....
.....**..*...**.....
.....**..*...**.....
.......*..*.*.......
.......*..*.*.......
........**.*........
........**.*........
.........**.........
.........**.........
Submitted Solution:
```
H, W = map(int, input().split())
for i in range(H):
S = input()
print(S+'\n'+S)
``` | instruction | 0 | 17,580 | 23 | 35,160 |
Yes | output | 1 | 17,580 | 23 | 35,161 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is an image with a height of H pixels and a width of W pixels. Each of the pixels is represented by either `.` or `*`. The character representing the pixel at the i-th row from the top and the j-th column from the left, is denoted by C_{i,j}.
Extend this image vertically so that its height is doubled. That is, print a image with a height of 2H pixels and a width of W pixels where the pixel at the i-th row and j-th column is equal to C_{(i+1)/2,j} (the result of division is rounded down).
Constraints
* 1≦H, W≦100
* C_{i,j} is either `.` or `*`.
Input
The input is given from Standard Input in the following format:
H W
C_{1,1}...C_{1,W}
:
C_{H,1}...C_{H,W}
Output
Print the extended image.
Examples
Input
2 2
*.
.*
Output
*.
*.
.*
.*
Input
1 4
***.
Output
***.
***.
Input
9 20
.....***....***.....
....*...*..*...*....
...*.....**.....*...
...*.....*......*...
....*.....*....*....
.....**..*...**.....
.......*..*.*.......
........**.*........
.........**.........
Output
.....***....***.....
.....***....***.....
....*...*..*...*....
....*...*..*...*....
...*.....**.....*...
...*.....**.....*...
...*.....*......*...
...*.....*......*...
....*.....*....*....
....*.....*....*....
.....**..*...**.....
.....**..*...**.....
.......*..*.*.......
.......*..*.*.......
........**.*........
........**.*........
.........**.........
.........**.........
Submitted Solution:
```
for i in range(int(input().split()[0])): print((lambda s: s + '\n' + s)(input()))
``` | instruction | 0 | 17,581 | 23 | 35,162 |
Yes | output | 1 | 17,581 | 23 | 35,163 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is an image with a height of H pixels and a width of W pixels. Each of the pixels is represented by either `.` or `*`. The character representing the pixel at the i-th row from the top and the j-th column from the left, is denoted by C_{i,j}.
Extend this image vertically so that its height is doubled. That is, print a image with a height of 2H pixels and a width of W pixels where the pixel at the i-th row and j-th column is equal to C_{(i+1)/2,j} (the result of division is rounded down).
Constraints
* 1≦H, W≦100
* C_{i,j} is either `.` or `*`.
Input
The input is given from Standard Input in the following format:
H W
C_{1,1}...C_{1,W}
:
C_{H,1}...C_{H,W}
Output
Print the extended image.
Examples
Input
2 2
*.
.*
Output
*.
*.
.*
.*
Input
1 4
***.
Output
***.
***.
Input
9 20
.....***....***.....
....*...*..*...*....
...*.....**.....*...
...*.....*......*...
....*.....*....*....
.....**..*...**.....
.......*..*.*.......
........**.*........
.........**.........
Output
.....***....***.....
.....***....***.....
....*...*..*...*....
....*...*..*...*....
...*.....**.....*...
...*.....**.....*...
...*.....*......*...
...*.....*......*...
....*.....*....*....
....*.....*....*....
.....**..*...**.....
.....**..*...**.....
.......*..*.*.......
.......*..*.*.......
........**.*........
........**.*........
.........**.........
.........**.........
Submitted Solution:
```
h,w=map(int,input().split())
for i in range(h):
t=input()
print(t)
print(t)
``` | instruction | 0 | 17,582 | 23 | 35,164 |
Yes | output | 1 | 17,582 | 23 | 35,165 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is an image with a height of H pixels and a width of W pixels. Each of the pixels is represented by either `.` or `*`. The character representing the pixel at the i-th row from the top and the j-th column from the left, is denoted by C_{i,j}.
Extend this image vertically so that its height is doubled. That is, print a image with a height of 2H pixels and a width of W pixels where the pixel at the i-th row and j-th column is equal to C_{(i+1)/2,j} (the result of division is rounded down).
Constraints
* 1≦H, W≦100
* C_{i,j} is either `.` or `*`.
Input
The input is given from Standard Input in the following format:
H W
C_{1,1}...C_{1,W}
:
C_{H,1}...C_{H,W}
Output
Print the extended image.
Examples
Input
2 2
*.
.*
Output
*.
*.
.*
.*
Input
1 4
***.
Output
***.
***.
Input
9 20
.....***....***.....
....*...*..*...*....
...*.....**.....*...
...*.....*......*...
....*.....*....*....
.....**..*...**.....
.......*..*.*.......
........**.*........
.........**.........
Output
.....***....***.....
.....***....***.....
....*...*..*...*....
....*...*..*...*....
...*.....**.....*...
...*.....**.....*...
...*.....*......*...
...*.....*......*...
....*.....*....*....
....*.....*....*....
.....**..*...**.....
.....**..*...**.....
.......*..*.*.......
.......*..*.*.......
........**.*........
........**.*........
.........**.........
.........**.........
Submitted Solution:
```
x,y = map(int,input().split())
for i in range(x):
s = input()
print(s)
print(s)
``` | instruction | 0 | 17,583 | 23 | 35,166 |
Yes | output | 1 | 17,583 | 23 | 35,167 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is an image with a height of H pixels and a width of W pixels. Each of the pixels is represented by either `.` or `*`. The character representing the pixel at the i-th row from the top and the j-th column from the left, is denoted by C_{i,j}.
Extend this image vertically so that its height is doubled. That is, print a image with a height of 2H pixels and a width of W pixels where the pixel at the i-th row and j-th column is equal to C_{(i+1)/2,j} (the result of division is rounded down).
Constraints
* 1≦H, W≦100
* C_{i,j} is either `.` or `*`.
Input
The input is given from Standard Input in the following format:
H W
C_{1,1}...C_{1,W}
:
C_{H,1}...C_{H,W}
Output
Print the extended image.
Examples
Input
2 2
*.
.*
Output
*.
*.
.*
.*
Input
1 4
***.
Output
***.
***.
Input
9 20
.....***....***.....
....*...*..*...*....
...*.....**.....*...
...*.....*......*...
....*.....*....*....
.....**..*...**.....
.......*..*.*.......
........**.*........
.........**.........
Output
.....***....***.....
.....***....***.....
....*...*..*...*....
....*...*..*...*....
...*.....**.....*...
...*.....**.....*...
...*.....*......*...
...*.....*......*...
....*.....*....*....
....*.....*....*....
.....**..*...**.....
.....**..*...**.....
.......*..*.*.......
.......*..*.*.......
........**.*........
........**.*........
.........**.........
.........**.........
Submitted Solution:
```
h,w =map(int,input().split())
c =[[str(i) for i in input()] for _ in range(h)]
for i in range(2*h):
if i <h:
print("".join(c[i]))
elif i >= h:
print("".join(c[i-h]))
``` | instruction | 0 | 17,584 | 23 | 35,168 |
No | output | 1 | 17,584 | 23 | 35,169 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is an image with a height of H pixels and a width of W pixels. Each of the pixels is represented by either `.` or `*`. The character representing the pixel at the i-th row from the top and the j-th column from the left, is denoted by C_{i,j}.
Extend this image vertically so that its height is doubled. That is, print a image with a height of 2H pixels and a width of W pixels where the pixel at the i-th row and j-th column is equal to C_{(i+1)/2,j} (the result of division is rounded down).
Constraints
* 1≦H, W≦100
* C_{i,j} is either `.` or `*`.
Input
The input is given from Standard Input in the following format:
H W
C_{1,1}...C_{1,W}
:
C_{H,1}...C_{H,W}
Output
Print the extended image.
Examples
Input
2 2
*.
.*
Output
*.
*.
.*
.*
Input
1 4
***.
Output
***.
***.
Input
9 20
.....***....***.....
....*...*..*...*....
...*.....**.....*...
...*.....*......*...
....*.....*....*....
.....**..*...**.....
.......*..*.*.......
........**.*........
.........**.........
Output
.....***....***.....
.....***....***.....
....*...*..*...*....
....*...*..*...*....
...*.....**.....*...
...*.....**.....*...
...*.....*......*...
...*.....*......*...
....*.....*....*....
....*.....*....*....
.....**..*...**.....
.....**..*...**.....
.......*..*.*.......
.......*..*.*.......
........**.*........
........**.*........
.........**.........
.........**.........
Submitted Solution:
```
H, W = map(int, input().split())
C = []
for i in range(W):
C.append(input())
for i in range(W):
print(C[i])
print(C[i])
``` | instruction | 0 | 17,585 | 23 | 35,170 |
No | output | 1 | 17,585 | 23 | 35,171 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is an image with a height of H pixels and a width of W pixels. Each of the pixels is represented by either `.` or `*`. The character representing the pixel at the i-th row from the top and the j-th column from the left, is denoted by C_{i,j}.
Extend this image vertically so that its height is doubled. That is, print a image with a height of 2H pixels and a width of W pixels where the pixel at the i-th row and j-th column is equal to C_{(i+1)/2,j} (the result of division is rounded down).
Constraints
* 1≦H, W≦100
* C_{i,j} is either `.` or `*`.
Input
The input is given from Standard Input in the following format:
H W
C_{1,1}...C_{1,W}
:
C_{H,1}...C_{H,W}
Output
Print the extended image.
Examples
Input
2 2
*.
.*
Output
*.
*.
.*
.*
Input
1 4
***.
Output
***.
***.
Input
9 20
.....***....***.....
....*...*..*...*....
...*.....**.....*...
...*.....*......*...
....*.....*....*....
.....**..*...**.....
.......*..*.*.......
........**.*........
.........**.........
Output
.....***....***.....
.....***....***.....
....*...*..*...*....
....*...*..*...*....
...*.....**.....*...
...*.....**.....*...
...*.....*......*...
...*.....*......*...
....*.....*....*....
....*.....*....*....
.....**..*...**.....
.....**..*...**.....
.......*..*.*.......
.......*..*.*.......
........**.*........
........**.*........
.........**.........
.........**.........
Submitted Solution:
```
h,w = map(int,input().split())
l = list(map(str,input().split()))
for i in range(len(l)):
print(l[i])
print(l[i])
``` | instruction | 0 | 17,586 | 23 | 35,172 |
No | output | 1 | 17,586 | 23 | 35,173 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is an image with a height of H pixels and a width of W pixels. Each of the pixels is represented by either `.` or `*`. The character representing the pixel at the i-th row from the top and the j-th column from the left, is denoted by C_{i,j}.
Extend this image vertically so that its height is doubled. That is, print a image with a height of 2H pixels and a width of W pixels where the pixel at the i-th row and j-th column is equal to C_{(i+1)/2,j} (the result of division is rounded down).
Constraints
* 1≦H, W≦100
* C_{i,j} is either `.` or `*`.
Input
The input is given from Standard Input in the following format:
H W
C_{1,1}...C_{1,W}
:
C_{H,1}...C_{H,W}
Output
Print the extended image.
Examples
Input
2 2
*.
.*
Output
*.
*.
.*
.*
Input
1 4
***.
Output
***.
***.
Input
9 20
.....***....***.....
....*...*..*...*....
...*.....**.....*...
...*.....*......*...
....*.....*....*....
.....**..*...**.....
.......*..*.*.......
........**.*........
.........**.........
Output
.....***....***.....
.....***....***.....
....*...*..*...*....
....*...*..*...*....
...*.....**.....*...
...*.....**.....*...
...*.....*......*...
...*.....*......*...
....*.....*....*....
....*.....*....*....
.....**..*...**.....
.....**..*...**.....
.......*..*.*.......
.......*..*.*.......
........**.*........
........**.*........
.........**.........
.........**.........
Submitted Solution:
```
h = int(input()[0])
image = []
for i in range(h):
row = input()
print(row+"\n"+row)
``` | instruction | 0 | 17,587 | 23 | 35,174 |
No | output | 1 | 17,587 | 23 | 35,175 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Squareland national forest is divided into equal 1 × 1 square plots aligned with north-south and east-west directions. Each plot can be uniquely described by integer Cartesian coordinates (x, y) of its south-west corner.
Three friends, Alice, Bob, and Charlie are going to buy three distinct plots of land A, B, C in the forest. Initially, all plots in the forest (including the plots A, B, C) are covered by trees. The friends want to visit each other, so they want to clean some of the plots from trees. After cleaning, one should be able to reach any of the plots A, B, C from any other one of those by moving through adjacent cleared plots. Two plots are adjacent if they share a side.
<image> For example, A=(0,0), B=(1,1), C=(2,2). The minimal number of plots to be cleared is 5. One of the ways to do it is shown with the gray color.
Of course, the friends don't want to strain too much. Help them find out the smallest number of plots they need to clean from trees.
Input
The first line contains two integers x_A and y_A — coordinates of the plot A (0 ≤ x_A, y_A ≤ 1000). The following two lines describe coordinates (x_B, y_B) and (x_C, y_C) of plots B and C respectively in the same format (0 ≤ x_B, y_B, x_C, y_C ≤ 1000). It is guaranteed that all three plots are distinct.
Output
On the first line print a single integer k — the smallest number of plots needed to be cleaned from trees. The following k lines should contain coordinates of all plots needed to be cleaned. All k plots should be distinct. You can output the plots in any order.
If there are multiple solutions, print any of them.
Examples
Input
0 0
1 1
2 2
Output
5
0 0
1 0
1 1
1 2
2 2
Input
0 0
2 0
1 1
Output
4
0 0
1 0
1 1
2 0
Note
The first example is shown on the picture in the legend.
The second example is illustrated with the following image:
<image> | instruction | 0 | 17,723 | 23 | 35,446 |
Tags: implementation, math
Correct Solution:
```
import sys
from io import StringIO
from atexit import register
## Modified from https://github.com/Cheran-Senthil/PyRival. Cheran Senthilkumar
BUFFER = StringIO(sys.stdin.read())
def input(): return BUFFER.readline().rstrip()
sys.stdout = StringIO()
register (lambda: sys.__stdout__.write(sys.stdout.getvalue()))
###
def Rdi(): return int(input())
def Rd(f = int): return [f(x) for x in input().split()]
def PrintF(arr): return ' '.join('{:.10f}'.format(x) for x in arr)
def Debug(x): print("\033[0;31m{}\033[0m".format(x), file=sys.stderr)
###
co = [Rd(), Rd(), Rd()]
co.sort()
xA, yA = co[0]
xB, yB = co[1]
xC, yC = co[2]
ans = set([tuple(c) for c in co])
tmp = xA
while tmp < xB:
tmp += 1
new = (tmp, yA)
ans.add(new)
tmp = yA
while tmp < yB:
tmp += 1
new = (xB, tmp)
ans.add(new)
while tmp > yB:
tmp -= 1
new = (xB, tmp)
ans.add(new)
lo = min(yA, yB)
hi = max(yA, yB)
while lo > yC:
lo -= 1
new = (xB, lo)
ans.add(new)
while hi < yC:
hi += 1
new = (xB, hi)
ans.add(new)
tmp = xB
while tmp < xC:
tmp += 1
new = (tmp, yC)
ans.add(new)
print(len(ans))
for a in ans: print(*a)
``` | output | 1 | 17,723 | 23 | 35,447 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Squareland national forest is divided into equal 1 × 1 square plots aligned with north-south and east-west directions. Each plot can be uniquely described by integer Cartesian coordinates (x, y) of its south-west corner.
Three friends, Alice, Bob, and Charlie are going to buy three distinct plots of land A, B, C in the forest. Initially, all plots in the forest (including the plots A, B, C) are covered by trees. The friends want to visit each other, so they want to clean some of the plots from trees. After cleaning, one should be able to reach any of the plots A, B, C from any other one of those by moving through adjacent cleared plots. Two plots are adjacent if they share a side.
<image> For example, A=(0,0), B=(1,1), C=(2,2). The minimal number of plots to be cleared is 5. One of the ways to do it is shown with the gray color.
Of course, the friends don't want to strain too much. Help them find out the smallest number of plots they need to clean from trees.
Input
The first line contains two integers x_A and y_A — coordinates of the plot A (0 ≤ x_A, y_A ≤ 1000). The following two lines describe coordinates (x_B, y_B) and (x_C, y_C) of plots B and C respectively in the same format (0 ≤ x_B, y_B, x_C, y_C ≤ 1000). It is guaranteed that all three plots are distinct.
Output
On the first line print a single integer k — the smallest number of plots needed to be cleaned from trees. The following k lines should contain coordinates of all plots needed to be cleaned. All k plots should be distinct. You can output the plots in any order.
If there are multiple solutions, print any of them.
Examples
Input
0 0
1 1
2 2
Output
5
0 0
1 0
1 1
1 2
2 2
Input
0 0
2 0
1 1
Output
4
0 0
1 0
1 1
2 0
Note
The first example is shown on the picture in the legend.
The second example is illustrated with the following image:
<image> | instruction | 0 | 17,724 | 23 | 35,448 |
Tags: implementation, math
Correct Solution:
```
ax, ay = map(int, input().split())
bx, by = map(int, input().split())
cx, cy = map(int, input().split())
def f(cx, ax, bx, cy, ay, by):
mxy = max(ay, by, cy)
mny = min(ay, by, cy)
print(abs(cx - bx) + mxy - mny + 1)
for i in range(mny, mxy + 1):
print(ax, i)
if cx <= bx:
for i in range(cx, ax):
print(i, cy)
for i in range(ax + 1, bx + 1):
print(i, by)
else:
for i in range(bx, ax):
print(i, by)
for i in range(ax + 1, cx + 1):
print(i, cy)
if cx <= ax <= bx or bx <= ax <= cx:
f(cx, ax, bx, cy, ay, by)
elif cx <= bx <= ax or ax <= bx <= cx:
f(cx, bx, ax, cy, by, ay)
elif bx <= cx <= ax or ax <= cx <= bx:
f(bx, cx, ax, by, cy, ay)
``` | output | 1 | 17,724 | 23 | 35,449 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Squareland national forest is divided into equal 1 × 1 square plots aligned with north-south and east-west directions. Each plot can be uniquely described by integer Cartesian coordinates (x, y) of its south-west corner.
Three friends, Alice, Bob, and Charlie are going to buy three distinct plots of land A, B, C in the forest. Initially, all plots in the forest (including the plots A, B, C) are covered by trees. The friends want to visit each other, so they want to clean some of the plots from trees. After cleaning, one should be able to reach any of the plots A, B, C from any other one of those by moving through adjacent cleared plots. Two plots are adjacent if they share a side.
<image> For example, A=(0,0), B=(1,1), C=(2,2). The minimal number of plots to be cleared is 5. One of the ways to do it is shown with the gray color.
Of course, the friends don't want to strain too much. Help them find out the smallest number of plots they need to clean from trees.
Input
The first line contains two integers x_A and y_A — coordinates of the plot A (0 ≤ x_A, y_A ≤ 1000). The following two lines describe coordinates (x_B, y_B) and (x_C, y_C) of plots B and C respectively in the same format (0 ≤ x_B, y_B, x_C, y_C ≤ 1000). It is guaranteed that all three plots are distinct.
Output
On the first line print a single integer k — the smallest number of plots needed to be cleaned from trees. The following k lines should contain coordinates of all plots needed to be cleaned. All k plots should be distinct. You can output the plots in any order.
If there are multiple solutions, print any of them.
Examples
Input
0 0
1 1
2 2
Output
5
0 0
1 0
1 1
1 2
2 2
Input
0 0
2 0
1 1
Output
4
0 0
1 0
1 1
2 0
Note
The first example is shown on the picture in the legend.
The second example is illustrated with the following image:
<image> | instruction | 0 | 17,725 | 23 | 35,450 |
Tags: implementation, math
Correct Solution:
```
xx=[]
yy=[]
for _ in range(3):
a,b=map(int,input().split())
xx.append(a)
yy.append(b)
print(max(xx)-min(xx)+max(yy)-min(yy)+1)
w=sorted(zip(xx,yy))
for x in range(w[0][0],w[1][0]):
print(x,w[0][1])
for x in range(w[1][0]+1,w[2][0]+1):
print(x,w[2][1])
for y in range(min(yy),max(yy)+1):
print(w[1][0],y)
``` | output | 1 | 17,725 | 23 | 35,451 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Squareland national forest is divided into equal 1 × 1 square plots aligned with north-south and east-west directions. Each plot can be uniquely described by integer Cartesian coordinates (x, y) of its south-west corner.
Three friends, Alice, Bob, and Charlie are going to buy three distinct plots of land A, B, C in the forest. Initially, all plots in the forest (including the plots A, B, C) are covered by trees. The friends want to visit each other, so they want to clean some of the plots from trees. After cleaning, one should be able to reach any of the plots A, B, C from any other one of those by moving through adjacent cleared plots. Two plots are adjacent if they share a side.
<image> For example, A=(0,0), B=(1,1), C=(2,2). The minimal number of plots to be cleared is 5. One of the ways to do it is shown with the gray color.
Of course, the friends don't want to strain too much. Help them find out the smallest number of plots they need to clean from trees.
Input
The first line contains two integers x_A and y_A — coordinates of the plot A (0 ≤ x_A, y_A ≤ 1000). The following two lines describe coordinates (x_B, y_B) and (x_C, y_C) of plots B and C respectively in the same format (0 ≤ x_B, y_B, x_C, y_C ≤ 1000). It is guaranteed that all three plots are distinct.
Output
On the first line print a single integer k — the smallest number of plots needed to be cleaned from trees. The following k lines should contain coordinates of all plots needed to be cleaned. All k plots should be distinct. You can output the plots in any order.
If there are multiple solutions, print any of them.
Examples
Input
0 0
1 1
2 2
Output
5
0 0
1 0
1 1
1 2
2 2
Input
0 0
2 0
1 1
Output
4
0 0
1 0
1 1
2 0
Note
The first example is shown on the picture in the legend.
The second example is illustrated with the following image:
<image> | instruction | 0 | 17,726 | 23 | 35,452 |
Tags: implementation, math
Correct Solution:
```
xx = []
yy = []
for _ in range(3):
x, y = map(int, input().split())
xx.append(x)
yy.append(y)
print(max(xx)-min(xx)+max(yy)-min(yy)+1)
w = sorted(zip(xx, yy))
for x in range(w[0][0], w[1][0]):
print(x, w[0][1])
for x in range(w[2][0], w[1][0], -1):
print(x, w[2][1])
for y in range(min(yy), max(yy)+1):
print(w[1][0], y)
``` | output | 1 | 17,726 | 23 | 35,453 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Squareland national forest is divided into equal 1 × 1 square plots aligned with north-south and east-west directions. Each plot can be uniquely described by integer Cartesian coordinates (x, y) of its south-west corner.
Three friends, Alice, Bob, and Charlie are going to buy three distinct plots of land A, B, C in the forest. Initially, all plots in the forest (including the plots A, B, C) are covered by trees. The friends want to visit each other, so they want to clean some of the plots from trees. After cleaning, one should be able to reach any of the plots A, B, C from any other one of those by moving through adjacent cleared plots. Two plots are adjacent if they share a side.
<image> For example, A=(0,0), B=(1,1), C=(2,2). The minimal number of plots to be cleared is 5. One of the ways to do it is shown with the gray color.
Of course, the friends don't want to strain too much. Help them find out the smallest number of plots they need to clean from trees.
Input
The first line contains two integers x_A and y_A — coordinates of the plot A (0 ≤ x_A, y_A ≤ 1000). The following two lines describe coordinates (x_B, y_B) and (x_C, y_C) of plots B and C respectively in the same format (0 ≤ x_B, y_B, x_C, y_C ≤ 1000). It is guaranteed that all three plots are distinct.
Output
On the first line print a single integer k — the smallest number of plots needed to be cleaned from trees. The following k lines should contain coordinates of all plots needed to be cleaned. All k plots should be distinct. You can output the plots in any order.
If there are multiple solutions, print any of them.
Examples
Input
0 0
1 1
2 2
Output
5
0 0
1 0
1 1
1 2
2 2
Input
0 0
2 0
1 1
Output
4
0 0
1 0
1 1
2 0
Note
The first example is shown on the picture in the legend.
The second example is illustrated with the following image:
<image> | instruction | 0 | 17,727 | 23 | 35,454 |
Tags: implementation, math
Correct Solution:
```
from collections import defaultdict
import math
def ncr(n,m):
return math.factorial(n)//((math.factorial(m)*math.factorial(n-m)))
def gcd(n,m):
return math.gcd(n,m)
t=1
for t1 in range(0,t):
order=[]
for i in range(0,3):
x,y=map(int,input().split())
order.append((x,y))
'''dis=[]
for i in range(0,3):
A=cor[i]
B=cor[(i+1)%3]
temp=max(abs(A[0]-B[0]),abs(A[1]-B[1]))
dis.append((temp,(A,B)))
dis=sorted(dis,key=lambda x: x[0])
order=[]
order.append(dis[0][1][0])
order.append(dis[0][1][1])
order.append(dis[1][1][1])
print(order)
cor=[]
for i in range(0,2):
A=order[i]
B=order[i+1]
x1=order[i][0]
y1=order[i][1]
x2=order[i+1][0]
y2=order[i+1][1]
if x1<x2:
while(x1<x2):
cor.append((x1,y1))
x1+=1
cor.append((x1,y1))
else:
while(x2<x1):
cor.append((x2,y2))
x2+=1
cor.append((x2,y2))
if y1<=y2:
while(y1<y2):
cor.append((x1,y1))
y1+=1
cor.append((x1,y1))
else:
while(y2<y1):
cor.append((x2,y2))
y2+=1
cor.append((x2,y2))
print(A,B,cor)
cor=list(set(cor))
print(len(cor))
for i in cor:
print(i[0],i[1])'''
order.sort()
#print(cor)
#print(order)
ans=[]
for i in range(0,2):
if(i%2==0):
x1=order[i][0]
y1=order[i][1]
x2=order[i+1][0]
y2=order[i+1][1]
while(x1<x2):
ans.append((x1,y1))
x1+=1
ans.append((x1,y1))
if y1<=y2:
while(y1<y2):
ans.append((x1,y1))
y1+=1
ans.append((x1,y1))
else:
while(y2<y1):
ans.append((x1,y2))
y2+=1
ans.append((x1,y2))
else:
x1=order[i][0]
y1=order[i][1]
x2=order[i+1][0]
y2=order[i+1][1]
#print(x1,y1,x2,y2)
while(x2>x1):
ans.append((x2,y2))
x2-=1
ans.append((x2,y2))
if y1<=y2:
while(y1<y2):
ans.append((x2,y1))
y1+=1
ans.append((x2,y1))
else:
while(y2<y1):
ans.append((x2,y2))
y2+=1
ans.append((x2,y2))
#print(ans)
ans=list(set(ans))
print(len(ans))
for i in ans:
print(i[0],i[1])
``` | output | 1 | 17,727 | 23 | 35,455 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Squareland national forest is divided into equal 1 × 1 square plots aligned with north-south and east-west directions. Each plot can be uniquely described by integer Cartesian coordinates (x, y) of its south-west corner.
Three friends, Alice, Bob, and Charlie are going to buy three distinct plots of land A, B, C in the forest. Initially, all plots in the forest (including the plots A, B, C) are covered by trees. The friends want to visit each other, so they want to clean some of the plots from trees. After cleaning, one should be able to reach any of the plots A, B, C from any other one of those by moving through adjacent cleared plots. Two plots are adjacent if they share a side.
<image> For example, A=(0,0), B=(1,1), C=(2,2). The minimal number of plots to be cleared is 5. One of the ways to do it is shown with the gray color.
Of course, the friends don't want to strain too much. Help them find out the smallest number of plots they need to clean from trees.
Input
The first line contains two integers x_A and y_A — coordinates of the plot A (0 ≤ x_A, y_A ≤ 1000). The following two lines describe coordinates (x_B, y_B) and (x_C, y_C) of plots B and C respectively in the same format (0 ≤ x_B, y_B, x_C, y_C ≤ 1000). It is guaranteed that all three plots are distinct.
Output
On the first line print a single integer k — the smallest number of plots needed to be cleaned from trees. The following k lines should contain coordinates of all plots needed to be cleaned. All k plots should be distinct. You can output the plots in any order.
If there are multiple solutions, print any of them.
Examples
Input
0 0
1 1
2 2
Output
5
0 0
1 0
1 1
1 2
2 2
Input
0 0
2 0
1 1
Output
4
0 0
1 0
1 1
2 0
Note
The first example is shown on the picture in the legend.
The second example is illustrated with the following image:
<image> | instruction | 0 | 17,728 | 23 | 35,456 |
Tags: implementation, math
Correct Solution:
```
def func1(a,b,c,d,e):
j = max(c, d, e)
k = min(c, d, e)
print(j-k+1+abs(b-a))
for i in range(k,j+1):
print(str(a)+" "+str(i))
if a<b:
for i in range(a+1,b+1):
print(str(i)+" "+str(e))
else:
for i in range(b,a):
print(str(i)+" "+str(e))
def func2(a,b,c,d,e):
j = max(c, d, e)
k = min(c, d, e)
print(j-k+1+abs(b-a))
for i in range(k,j+1):
print(str(i)+" "+str(a))
if a<b:
for i in range(a+1,b+1):
print(str(e)+" "+str(i))
else:
for i in range(b,a):
print(str(e)+" "+str(i))
x1,y1=map(int,input().split())
x2,y2=map(int,input().split())
x3,y3=map(int,input().split())
if x1==x2 and x2==x3:
a=max(y1,y2,y3)
b=min(y1,y2,y3)
print(a-b+1)
for i in range(b,a+1):
print(str(x1)+" "+str(i))
elif y1==y2 and y2==y3:
a=max(x1,x2,x3)
b=min(x1,x2,x3)
print(a-b+1)
for i in range(b,a+1):
print(str(i)+" "+str(y1))
elif x1==x2:
func1(x1,x3,y1,y2,y3)
elif x2==x3:
func1(x2,x1, y2, y3,y1)
elif x1==x3:
func1(x1,x2, y1,y3,y2)
elif y1==y2:
func2(y1,y3,x1,x2,x3)
elif y2==y3:
func2(y2,y1, x2, x3,x1)
elif y1==y3:
func2(y1,y2, x1,x3,x2)
else:
l=[(x1,y1),(x2,y2),(x3,y3)]
l.sort()
if l[1][1]==max(l[0][1],l[1][1],l[2][1]):
if l[2][1]-l[0][1]>0:
print(l[2][0] - l[0][0] + 1 - l[0][1]+l[1][1])
for i in range(l[0][0], l[2][0]+1):
print(str(i) + " " + str(l[2][1]))
for i in range(l[0][1],l[2][1]):
print(str(l[0][0])+" "+str(i))
for i in range(l[2][1]+1,l[1][1]+1):
print(str(l[1][0])+" "+str(i))
else:
print(l[2][0] - l[0][0] + 1 - l[2][1] + l[1][1])
for i in range(l[0][0], l[2][0] + 1):
print(str(i) + " " + str(l[0][1]))
for i in range(l[2][1],l[0][1]):
print(str(l[2][0])+" "+str(i))
for i in range(l[0][1]+1,l[1][1]+1):
print(str(l[1][0])+" "+str(i))
elif l[1][1]==min(l[0][1],l[1][1],l[2][1]):
if l[2][1]-l[0][1]>0:
print(l[2][0] - l[0][0] + 1 - l[1][1]+l[2][1])
for i in range(l[0][0], l[2][0] + 1):
print(str(i)+ " " + str(l[0][1]))
for i in range(l[1][1],l[0][1]):
print(str(l[1][0])+" "+str(i))
for i in range(l[0][1]+1,l[2][1]+1):
print(str(l[2][0])+" "+str(i))
else:
print(l[2][0] - l[0][0] + 1 - l[1][1] + l[0][1])
for i in range(l[0][0], l[2][0] + 1):
print(str(i) + " " + str(l[2][1]))
for i in range(l[1][1],l[2][1]):
print(str(l[1][0])+" "+str(i))
for i in range(l[2][1]+1,l[0][1]+1):
print(str(l[0][0])+" "+str(i))
else:
if l[2][1]-l[0][1]>0:
print(l[2][0] - l[0][0] + l[2][1] - l[0][1] + 1)
for i in range(l[0][1], l[1][1]):
print(str(l[0][0]) + " " + str(i))
for i in range(l[0][0], l[2][0]):
print(str(i) + " " + str(l[1][1]))
for i in range(l[1][1], l[2][1] + 1):
print(str(l[2][0]) + " " + str(i))
else:
print(l[2][0] - l[0][0] + l[0][1] - l[2][1] + 1)
for i in range(l[2][1], l[1][1]+1):
print(str(l[2][0]) + " " + str(i))
for i in range(l[0][0], l[2][0]):
print(str(i) + " " + str(l[1][1]))
for i in range(l[1][1]+1, l[0][1] + 1):
print(str(l[0][0]) + " " + str(i))
``` | output | 1 | 17,728 | 23 | 35,457 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Squareland national forest is divided into equal 1 × 1 square plots aligned with north-south and east-west directions. Each plot can be uniquely described by integer Cartesian coordinates (x, y) of its south-west corner.
Three friends, Alice, Bob, and Charlie are going to buy three distinct plots of land A, B, C in the forest. Initially, all plots in the forest (including the plots A, B, C) are covered by trees. The friends want to visit each other, so they want to clean some of the plots from trees. After cleaning, one should be able to reach any of the plots A, B, C from any other one of those by moving through adjacent cleared plots. Two plots are adjacent if they share a side.
<image> For example, A=(0,0), B=(1,1), C=(2,2). The minimal number of plots to be cleared is 5. One of the ways to do it is shown with the gray color.
Of course, the friends don't want to strain too much. Help them find out the smallest number of plots they need to clean from trees.
Input
The first line contains two integers x_A and y_A — coordinates of the plot A (0 ≤ x_A, y_A ≤ 1000). The following two lines describe coordinates (x_B, y_B) and (x_C, y_C) of plots B and C respectively in the same format (0 ≤ x_B, y_B, x_C, y_C ≤ 1000). It is guaranteed that all three plots are distinct.
Output
On the first line print a single integer k — the smallest number of plots needed to be cleaned from trees. The following k lines should contain coordinates of all plots needed to be cleaned. All k plots should be distinct. You can output the plots in any order.
If there are multiple solutions, print any of them.
Examples
Input
0 0
1 1
2 2
Output
5
0 0
1 0
1 1
1 2
2 2
Input
0 0
2 0
1 1
Output
4
0 0
1 0
1 1
2 0
Note
The first example is shown on the picture in the legend.
The second example is illustrated with the following image:
<image> | instruction | 0 | 17,729 | 23 | 35,458 |
Tags: implementation, math
Correct Solution:
```
def connect(x1, y1, x2, y2):
a = set()
if x2 > x1:
for i in range(x1, x2+1): a.add((i, y1))
if y2 > y1:
for j in range(y1, y2+1): a.add((x2, j))
else:
for j in range(y2, y1+1): a.add((x2, j))
else:
for i in range(x2, x1+1): a.add((i, y2))
if y2 > y1:
for j in range(y1, y2+1): a.add((x1, j))
else:
for j in range(y2, y1+1): a.add((x1, j))
return a
x1, y1 = map(int, input().split())
x2, y2 = map(int, input().split())
x3, y3 = map(int, input().split())
a = connect(x1, y1, x2, y2)
b = connect(x1, y1, x3, y3)
c = connect(x3, y3, x2, y2)
ans = a.union(b)
for ai in a:
t = connect(*ai, x3, y3)
if len(a.union(t)) < len(ans):
ans = a.union(t)
for ai in b:
t = connect(*ai, x2, y2)
if len(b.union(t)) < len(ans):
ans = b.union(t)
for ai in c:
t = connect(*ai, x1, y1)
if len(c.union(t)) < len(ans):
ans = c.union(t)
print(len(ans))
for ps in ans:
print(*ps)
``` | output | 1 | 17,729 | 23 | 35,459 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Squareland national forest is divided into equal 1 × 1 square plots aligned with north-south and east-west directions. Each plot can be uniquely described by integer Cartesian coordinates (x, y) of its south-west corner.
Three friends, Alice, Bob, and Charlie are going to buy three distinct plots of land A, B, C in the forest. Initially, all plots in the forest (including the plots A, B, C) are covered by trees. The friends want to visit each other, so they want to clean some of the plots from trees. After cleaning, one should be able to reach any of the plots A, B, C from any other one of those by moving through adjacent cleared plots. Two plots are adjacent if they share a side.
<image> For example, A=(0,0), B=(1,1), C=(2,2). The minimal number of plots to be cleared is 5. One of the ways to do it is shown with the gray color.
Of course, the friends don't want to strain too much. Help them find out the smallest number of plots they need to clean from trees.
Input
The first line contains two integers x_A and y_A — coordinates of the plot A (0 ≤ x_A, y_A ≤ 1000). The following two lines describe coordinates (x_B, y_B) and (x_C, y_C) of plots B and C respectively in the same format (0 ≤ x_B, y_B, x_C, y_C ≤ 1000). It is guaranteed that all three plots are distinct.
Output
On the first line print a single integer k — the smallest number of plots needed to be cleaned from trees. The following k lines should contain coordinates of all plots needed to be cleaned. All k plots should be distinct. You can output the plots in any order.
If there are multiple solutions, print any of them.
Examples
Input
0 0
1 1
2 2
Output
5
0 0
1 0
1 1
1 2
2 2
Input
0 0
2 0
1 1
Output
4
0 0
1 0
1 1
2 0
Note
The first example is shown on the picture in the legend.
The second example is illustrated with the following image:
<image> | instruction | 0 | 17,730 | 23 | 35,460 |
Tags: implementation, math
Correct Solution:
```
points = []
mx = 0
for i in range(3):
points.append(list(map(int, input().split())))
points = sorted(points, key=lambda x: x[0])
k = 1
x, y = points[0][0], points[0][1]
x2, y2 = points[1][0], points[1][1]
coor = [[points[0][0], points[0][1]]]
mx = y
mn = y
while True:
if x < x2:
x += 1
elif y < y2:
y += 1
mx = y
elif y > y2:
y -= 1
mn = y
else:
break
k+=1
coor.append([x, y])
x3, y3 = points[2][0], points[2][1]
if mn <= y3 <= mx:
y = y3
elif y3 < mn:
y = mn
elif y3 > mx:
y = mx
while True:
if y < y3:
y += 1
elif y > y3:
y -= 1
elif x < x3:
x+=1
else:
break
k += 1
coor.append([x, y])
print(k)
for i in coor:
print(*i)
``` | output | 1 | 17,730 | 23 | 35,461 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Squareland national forest is divided into equal 1 × 1 square plots aligned with north-south and east-west directions. Each plot can be uniquely described by integer Cartesian coordinates (x, y) of its south-west corner.
Three friends, Alice, Bob, and Charlie are going to buy three distinct plots of land A, B, C in the forest. Initially, all plots in the forest (including the plots A, B, C) are covered by trees. The friends want to visit each other, so they want to clean some of the plots from trees. After cleaning, one should be able to reach any of the plots A, B, C from any other one of those by moving through adjacent cleared plots. Two plots are adjacent if they share a side.
<image> For example, A=(0,0), B=(1,1), C=(2,2). The minimal number of plots to be cleared is 5. One of the ways to do it is shown with the gray color.
Of course, the friends don't want to strain too much. Help them find out the smallest number of plots they need to clean from trees.
Input
The first line contains two integers x_A and y_A — coordinates of the plot A (0 ≤ x_A, y_A ≤ 1000). The following two lines describe coordinates (x_B, y_B) and (x_C, y_C) of plots B and C respectively in the same format (0 ≤ x_B, y_B, x_C, y_C ≤ 1000). It is guaranteed that all three plots are distinct.
Output
On the first line print a single integer k — the smallest number of plots needed to be cleaned from trees. The following k lines should contain coordinates of all plots needed to be cleaned. All k plots should be distinct. You can output the plots in any order.
If there are multiple solutions, print any of them.
Examples
Input
0 0
1 1
2 2
Output
5
0 0
1 0
1 1
1 2
2 2
Input
0 0
2 0
1 1
Output
4
0 0
1 0
1 1
2 0
Note
The first example is shown on the picture in the legend.
The second example is illustrated with the following image:
<image>
Submitted Solution:
```
# list(map(int, input().split()))
# map(int, input().split())
class Coord():
def __init__(self, x, y):
self.x = x
self.y = y
def cdist(c1, c2):
return abs(c1.x - c2.x) + abs(c1.y - c2.y)
def dist(x1, y1, x2, y2):
return abs(x1 - x2) + abs(y1 - y2)
x1, y1 = list(map(int, input().split()))
x2, y2 = list(map(int, input().split()))
x3, y3 = list(map(int, input().split()))
cs = [Coord(x1, y1), Coord(x2, y2), Coord(x3, y3)]
s = set()
s.add(tuple([x1, y1]))
s.add(tuple([x2, y2]))
s.add(tuple([x3, y3]))
shifts = [[0, 1], [1, 0], [0, -1], [-1, 0]]
for i in range(3):
cur = cs[i]
other = []
for j in range(3):
if j != i:
other.append(cs[j])
cur_x = cur.x
cur_y = cur.y
while True:
cnt = 0
for sh in shifts:
new_x, new_y = cur_x + sh[0], cur_y + sh[1]
flag = 0
for oth in other:
oth_x, oth_y = oth.x, oth.y
if dist(cur_x, cur_y, oth_x, oth_y) > dist(new_x, new_y, oth_x, oth_y):
pass
else:
flag += 1
if flag:
cnt += 1
continue
s.add(tuple([new_x, new_y]))
cur_x, cur_y = new_x, new_y
break
if cnt == 4:
break
arr = list(s)
print(len(arr))
for a in arr:
print(*a)
``` | instruction | 0 | 17,731 | 23 | 35,462 |
Yes | output | 1 | 17,731 | 23 | 35,463 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Squareland national forest is divided into equal 1 × 1 square plots aligned with north-south and east-west directions. Each plot can be uniquely described by integer Cartesian coordinates (x, y) of its south-west corner.
Three friends, Alice, Bob, and Charlie are going to buy three distinct plots of land A, B, C in the forest. Initially, all plots in the forest (including the plots A, B, C) are covered by trees. The friends want to visit each other, so they want to clean some of the plots from trees. After cleaning, one should be able to reach any of the plots A, B, C from any other one of those by moving through adjacent cleared plots. Two plots are adjacent if they share a side.
<image> For example, A=(0,0), B=(1,1), C=(2,2). The minimal number of plots to be cleared is 5. One of the ways to do it is shown with the gray color.
Of course, the friends don't want to strain too much. Help them find out the smallest number of plots they need to clean from trees.
Input
The first line contains two integers x_A and y_A — coordinates of the plot A (0 ≤ x_A, y_A ≤ 1000). The following two lines describe coordinates (x_B, y_B) and (x_C, y_C) of plots B and C respectively in the same format (0 ≤ x_B, y_B, x_C, y_C ≤ 1000). It is guaranteed that all three plots are distinct.
Output
On the first line print a single integer k — the smallest number of plots needed to be cleaned from trees. The following k lines should contain coordinates of all plots needed to be cleaned. All k plots should be distinct. You can output the plots in any order.
If there are multiple solutions, print any of them.
Examples
Input
0 0
1 1
2 2
Output
5
0 0
1 0
1 1
1 2
2 2
Input
0 0
2 0
1 1
Output
4
0 0
1 0
1 1
2 0
Note
The first example is shown on the picture in the legend.
The second example is illustrated with the following image:
<image>
Submitted Solution:
```
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
a, b, c = sorted([a,b,c])
ans = []
for i in range(min(a[1],b[1],c[1]),max(a[1],b[1],c[1])+1):
ans.append((b[0],i))
for i in range(a[0],b[0]+1):
ans.append((i,a[1]))
for i in range(b[0],c[0]+1):
ans.append((i,c[1]))
ans=set(ans)
print(len(ans))
for i in ans:
print(*i)
``` | instruction | 0 | 17,732 | 23 | 35,464 |
Yes | output | 1 | 17,732 | 23 | 35,465 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Squareland national forest is divided into equal 1 × 1 square plots aligned with north-south and east-west directions. Each plot can be uniquely described by integer Cartesian coordinates (x, y) of its south-west corner.
Three friends, Alice, Bob, and Charlie are going to buy three distinct plots of land A, B, C in the forest. Initially, all plots in the forest (including the plots A, B, C) are covered by trees. The friends want to visit each other, so they want to clean some of the plots from trees. After cleaning, one should be able to reach any of the plots A, B, C from any other one of those by moving through adjacent cleared plots. Two plots are adjacent if they share a side.
<image> For example, A=(0,0), B=(1,1), C=(2,2). The minimal number of plots to be cleared is 5. One of the ways to do it is shown with the gray color.
Of course, the friends don't want to strain too much. Help them find out the smallest number of plots they need to clean from trees.
Input
The first line contains two integers x_A and y_A — coordinates of the plot A (0 ≤ x_A, y_A ≤ 1000). The following two lines describe coordinates (x_B, y_B) and (x_C, y_C) of plots B and C respectively in the same format (0 ≤ x_B, y_B, x_C, y_C ≤ 1000). It is guaranteed that all three plots are distinct.
Output
On the first line print a single integer k — the smallest number of plots needed to be cleaned from trees. The following k lines should contain coordinates of all plots needed to be cleaned. All k plots should be distinct. You can output the plots in any order.
If there are multiple solutions, print any of them.
Examples
Input
0 0
1 1
2 2
Output
5
0 0
1 0
1 1
1 2
2 2
Input
0 0
2 0
1 1
Output
4
0 0
1 0
1 1
2 0
Note
The first example is shown on the picture in the legend.
The second example is illustrated with the following image:
<image>
Submitted Solution:
```
xy1 = list(map(int, input().split(" ")))
xy2 = list(map(int, input().split(" ")))
xy3 = list(map(int, input().split(" ")))
x = max(abs(xy1[0]-xy2[0]), abs(xy3[0]-xy2[0]), abs(xy3[0]-xy1[0]))
y = max(abs(xy1[1]-xy2[1]), abs(xy3[1]-xy2[1]), abs(xy3[1]-xy1[1]))
r = x + y + 1
def sortlist(l1,l2,l3):
if l1[0] <= l2[0] <= l3[0]:
return [l1, l2, l3]
if l2[0] < l1[0] <= l3[0]:
return [l2, l1, l3]
if l3[0] < l2[0] < l1[0]:
return [l3, l2, l1]
if l1[0] <= l3[0] < l2[0]:
return [l1, l3, l2]
if l2[0] <= l3[0] < l1[0]:
return [l2, l3, l1]
if l3[0] < l1[0] <= l2[0]:
return [l3, l1, l2]
result = []
xy_list = sortlist(xy1, xy2, xy3)
for i in range(xy_list[0][0], xy_list[1][0]+1):
if [i, xy_list[0][1]] not in result:
result.append([i, xy_list[0][1]])
for j in range(min(xy_list[0][1], xy_list[2][1], xy_list[1][1]), max(xy_list[0][1], xy_list[2][1], xy_list[2][1], xy_list[1][1])+1):
if [xy_list[1][0], j] not in result:
result.append([xy_list[1][0], j])
for k in range(xy_list[1][0]+1, xy_list[2][0]+1):
if [k, xy_list[2][1]] not in result:
result.append([k, xy_list[2][1]])
print(r)
for l in result:
print(l[0], l[1])
``` | instruction | 0 | 17,733 | 23 | 35,466 |
Yes | output | 1 | 17,733 | 23 | 35,467 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Squareland national forest is divided into equal 1 × 1 square plots aligned with north-south and east-west directions. Each plot can be uniquely described by integer Cartesian coordinates (x, y) of its south-west corner.
Three friends, Alice, Bob, and Charlie are going to buy three distinct plots of land A, B, C in the forest. Initially, all plots in the forest (including the plots A, B, C) are covered by trees. The friends want to visit each other, so they want to clean some of the plots from trees. After cleaning, one should be able to reach any of the plots A, B, C from any other one of those by moving through adjacent cleared plots. Two plots are adjacent if they share a side.
<image> For example, A=(0,0), B=(1,1), C=(2,2). The minimal number of plots to be cleared is 5. One of the ways to do it is shown with the gray color.
Of course, the friends don't want to strain too much. Help them find out the smallest number of plots they need to clean from trees.
Input
The first line contains two integers x_A and y_A — coordinates of the plot A (0 ≤ x_A, y_A ≤ 1000). The following two lines describe coordinates (x_B, y_B) and (x_C, y_C) of plots B and C respectively in the same format (0 ≤ x_B, y_B, x_C, y_C ≤ 1000). It is guaranteed that all three plots are distinct.
Output
On the first line print a single integer k — the smallest number of plots needed to be cleaned from trees. The following k lines should contain coordinates of all plots needed to be cleaned. All k plots should be distinct. You can output the plots in any order.
If there are multiple solutions, print any of them.
Examples
Input
0 0
1 1
2 2
Output
5
0 0
1 0
1 1
1 2
2 2
Input
0 0
2 0
1 1
Output
4
0 0
1 0
1 1
2 0
Note
The first example is shown on the picture in the legend.
The second example is illustrated with the following image:
<image>
Submitted Solution:
```
xa,ya=[int(k) for k in input().split()]
xb,yb=[int(k) for k in input().split()]
xc,yc=[int(k) for k in input().split()]
D={}
D[xa]=ya
D[xb]=yb
D[xc]=yc
X=[xa,xb,xc]
Y=[ya,yb,yc]
X.sort()
Y.sort()
ans=X[2]-X[0]+Y[2]-Y[0]+1
print(ans)
for i in range(Y[0],Y[2]+1):
print(X[1],i)
for i in range(X[0],X[1]):
print(i,D[X[0]])
for i in range(X[1]+1,X[2]+1):
print(i,D[X[2]])
``` | instruction | 0 | 17,734 | 23 | 35,468 |
Yes | output | 1 | 17,734 | 23 | 35,469 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Squareland national forest is divided into equal 1 × 1 square plots aligned with north-south and east-west directions. Each plot can be uniquely described by integer Cartesian coordinates (x, y) of its south-west corner.
Three friends, Alice, Bob, and Charlie are going to buy three distinct plots of land A, B, C in the forest. Initially, all plots in the forest (including the plots A, B, C) are covered by trees. The friends want to visit each other, so they want to clean some of the plots from trees. After cleaning, one should be able to reach any of the plots A, B, C from any other one of those by moving through adjacent cleared plots. Two plots are adjacent if they share a side.
<image> For example, A=(0,0), B=(1,1), C=(2,2). The minimal number of plots to be cleared is 5. One of the ways to do it is shown with the gray color.
Of course, the friends don't want to strain too much. Help them find out the smallest number of plots they need to clean from trees.
Input
The first line contains two integers x_A and y_A — coordinates of the plot A (0 ≤ x_A, y_A ≤ 1000). The following two lines describe coordinates (x_B, y_B) and (x_C, y_C) of plots B and C respectively in the same format (0 ≤ x_B, y_B, x_C, y_C ≤ 1000). It is guaranteed that all three plots are distinct.
Output
On the first line print a single integer k — the smallest number of plots needed to be cleaned from trees. The following k lines should contain coordinates of all plots needed to be cleaned. All k plots should be distinct. You can output the plots in any order.
If there are multiple solutions, print any of them.
Examples
Input
0 0
1 1
2 2
Output
5
0 0
1 0
1 1
1 2
2 2
Input
0 0
2 0
1 1
Output
4
0 0
1 0
1 1
2 0
Note
The first example is shown on the picture in the legend.
The second example is illustrated with the following image:
<image>
Submitted Solution:
```
x_A, y_A = list(map(int, input().split()))
x_B, y_B = list(map(int, input().split()))
x_C, y_C = list(map(int, input().split()))
"""
WAY_X = max(x_A, x_B, x_C) - min(x_A, x_B, x_C) + 1
WAY_y = max(y_A, y_B, y_C) - min(y_A, y_B, y_C) + 1
if x_A == x_B == x_C or y_A == y_B == y_C:
cross = 0
elif x_A == x_B or x_A == x_C or x_B == x_C:
cross = 1
elif y_A == x_B or y_A == y_C or y_B == y_C:
cross = 1
else:
cross = 2
print(WAY_X, WAY_y, cross)
"""
if x_A >= x_B >= x_C:
x_A, x_B, x_C = x_C, x_B, x_A
y_A, y_B, y_C = y_C, y_B, y_A
elif x_A >= x_C >= x_B:
x_A, x_B, x_C = x_B, x_C, x_A
y_A, y_B, y_C = y_B, y_C, y_A
elif x_B >= x_A >= x_C:
x_A, x_B, x_C = x_C, x_A, x_B
y_A, y_B, y_C = y_C, y_A, y_B
elif x_B >= x_C >= x_A:
x_A, x_B, x_C = x_A, x_C, x_B
y_A, y_B, y_C = y_A, y_C, y_B
elif x_C >= x_A >= x_B:
x_A, x_B, x_C = x_B, x_A, x_C
y_A, y_B, y_C = y_B, y_A, y_C
pos_x, pos_y = x_A, min(y_A, y_B, y_C)
count = 1
ans = ''
while pos_x < x_B:
ans += str(pos_x) + ' ' + str(y_A) + '\n'
pos_x += 1
count += 1
while pos_y != max(y_C, y_A, y_B):
ans += str(x_B) + ' ' + str(pos_y) + '\n'
pos_y += 1
count += 1
while pos_x < x_C:
ans += str(pos_x) + ' ' + str(y_C) + '\n'
pos_x += 1
count += 1
ans += str(pos_x) + ' ' + str(y_C)
print(count)
print(ans)
``` | instruction | 0 | 17,735 | 23 | 35,470 |
No | output | 1 | 17,735 | 23 | 35,471 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Squareland national forest is divided into equal 1 × 1 square plots aligned with north-south and east-west directions. Each plot can be uniquely described by integer Cartesian coordinates (x, y) of its south-west corner.
Three friends, Alice, Bob, and Charlie are going to buy three distinct plots of land A, B, C in the forest. Initially, all plots in the forest (including the plots A, B, C) are covered by trees. The friends want to visit each other, so they want to clean some of the plots from trees. After cleaning, one should be able to reach any of the plots A, B, C from any other one of those by moving through adjacent cleared plots. Two plots are adjacent if they share a side.
<image> For example, A=(0,0), B=(1,1), C=(2,2). The minimal number of plots to be cleared is 5. One of the ways to do it is shown with the gray color.
Of course, the friends don't want to strain too much. Help them find out the smallest number of plots they need to clean from trees.
Input
The first line contains two integers x_A and y_A — coordinates of the plot A (0 ≤ x_A, y_A ≤ 1000). The following two lines describe coordinates (x_B, y_B) and (x_C, y_C) of plots B and C respectively in the same format (0 ≤ x_B, y_B, x_C, y_C ≤ 1000). It is guaranteed that all three plots are distinct.
Output
On the first line print a single integer k — the smallest number of plots needed to be cleaned from trees. The following k lines should contain coordinates of all plots needed to be cleaned. All k plots should be distinct. You can output the plots in any order.
If there are multiple solutions, print any of them.
Examples
Input
0 0
1 1
2 2
Output
5
0 0
1 0
1 1
1 2
2 2
Input
0 0
2 0
1 1
Output
4
0 0
1 0
1 1
2 0
Note
The first example is shown on the picture in the legend.
The second example is illustrated with the following image:
<image>
Submitted Solution:
```
ax, ay = map(int, input().split())
bx, by = map(int, input().split())
cx, cy = map(int, input().split())
def f(cx, ax, bx):
mxy = max(ay, by, cy)
mny = min(ay, by, cy)
print(abs(cx - bx) + mxy - mny + 1)
for i in range(mny, mxy + 1):
print(ax, i)
if cx <= bx:
for i in range(cx, ax):
print(i, cy)
for i in range(ax + 1, bx + 1):
print(i, by)
else:
for i in range(bx, ax):
print(i, by)
for i in range(ax + 1, cx + 1):
print(i, cy)
if cx <= ax <= bx or bx <= ax <= cx:
f(cx, ax, bx)
elif cx <= bx <= ax or ax <= bx <= cx:
f(cx, bx, ax)
elif bx <= cx <= ax or ax <= cx <= bx:
f(bx, cx, ax)
``` | instruction | 0 | 17,736 | 23 | 35,472 |
No | output | 1 | 17,736 | 23 | 35,473 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Squareland national forest is divided into equal 1 × 1 square plots aligned with north-south and east-west directions. Each plot can be uniquely described by integer Cartesian coordinates (x, y) of its south-west corner.
Three friends, Alice, Bob, and Charlie are going to buy three distinct plots of land A, B, C in the forest. Initially, all plots in the forest (including the plots A, B, C) are covered by trees. The friends want to visit each other, so they want to clean some of the plots from trees. After cleaning, one should be able to reach any of the plots A, B, C from any other one of those by moving through adjacent cleared plots. Two plots are adjacent if they share a side.
<image> For example, A=(0,0), B=(1,1), C=(2,2). The minimal number of plots to be cleared is 5. One of the ways to do it is shown with the gray color.
Of course, the friends don't want to strain too much. Help them find out the smallest number of plots they need to clean from trees.
Input
The first line contains two integers x_A and y_A — coordinates of the plot A (0 ≤ x_A, y_A ≤ 1000). The following two lines describe coordinates (x_B, y_B) and (x_C, y_C) of plots B and C respectively in the same format (0 ≤ x_B, y_B, x_C, y_C ≤ 1000). It is guaranteed that all three plots are distinct.
Output
On the first line print a single integer k — the smallest number of plots needed to be cleaned from trees. The following k lines should contain coordinates of all plots needed to be cleaned. All k plots should be distinct. You can output the plots in any order.
If there are multiple solutions, print any of them.
Examples
Input
0 0
1 1
2 2
Output
5
0 0
1 0
1 1
1 2
2 2
Input
0 0
2 0
1 1
Output
4
0 0
1 0
1 1
2 0
Note
The first example is shown on the picture in the legend.
The second example is illustrated with the following image:
<image>
Submitted Solution:
```
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
print(c[0]-a[0]+max(a[1], b[1], c[1])-min(a[1], b[1], c[1])+1)
for i in range(a[0],b[0]):
print('{} {}'.format(i,a[1]))
for i in range(min(a[1],b[1],c[1]),max(a[1],b[1],c[1])+1):
print('{} {}'.format(b[0],i))
for i in range(b[0]+1,c[0]+1):
print('{} {}'.format(i,c[1]))
``` | instruction | 0 | 17,737 | 23 | 35,474 |
No | output | 1 | 17,737 | 23 | 35,475 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Squareland national forest is divided into equal 1 × 1 square plots aligned with north-south and east-west directions. Each plot can be uniquely described by integer Cartesian coordinates (x, y) of its south-west corner.
Three friends, Alice, Bob, and Charlie are going to buy three distinct plots of land A, B, C in the forest. Initially, all plots in the forest (including the plots A, B, C) are covered by trees. The friends want to visit each other, so they want to clean some of the plots from trees. After cleaning, one should be able to reach any of the plots A, B, C from any other one of those by moving through adjacent cleared plots. Two plots are adjacent if they share a side.
<image> For example, A=(0,0), B=(1,1), C=(2,2). The minimal number of plots to be cleared is 5. One of the ways to do it is shown with the gray color.
Of course, the friends don't want to strain too much. Help them find out the smallest number of plots they need to clean from trees.
Input
The first line contains two integers x_A and y_A — coordinates of the plot A (0 ≤ x_A, y_A ≤ 1000). The following two lines describe coordinates (x_B, y_B) and (x_C, y_C) of plots B and C respectively in the same format (0 ≤ x_B, y_B, x_C, y_C ≤ 1000). It is guaranteed that all three plots are distinct.
Output
On the first line print a single integer k — the smallest number of plots needed to be cleaned from trees. The following k lines should contain coordinates of all plots needed to be cleaned. All k plots should be distinct. You can output the plots in any order.
If there are multiple solutions, print any of them.
Examples
Input
0 0
1 1
2 2
Output
5
0 0
1 0
1 1
1 2
2 2
Input
0 0
2 0
1 1
Output
4
0 0
1 0
1 1
2 0
Note
The first example is shown on the picture in the legend.
The second example is illustrated with the following image:
<image>
Submitted Solution:
```
def connect(x1, y1, x2, y2):
a = set()
if x2 > x1:
for i in range(x1, x2+1): a.add((i, y1))
if y2 > y1:
for j in range(y1, y2+1): a.add((x2, j))
else:
for j in range(y2, y1+1): a.add((x2, j))
else:
for i in range(x2, x1+1): a.add((i, y1))
if y2 > y1:
for j in range(y1, y2+1): a.add((x1, j))
else:
for j in range(y2, y1+1): a.add((x1, j))
return a
x1, y1 = map(int, input().split())
x2, y2 = map(int, input().split())
x3, y3 = map(int, input().split())
a = connect(x1, y1, x2, y2)
ans = a.union(connect(x1, y1, x3, y3))
for ai in a:
t = connect(*ai, x3, y3)
if len(a.union(t)) < len(ans):
ans = a.union(t)
print(len(ans))
for ps in ans:
print(*ps)
``` | instruction | 0 | 17,738 | 23 | 35,476 |
No | output | 1 | 17,738 | 23 | 35,477 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given the set of vectors on the plane, each of them starting at the origin. Your task is to find a pair of vectors with the minimal non-oriented angle between them.
Non-oriented angle is non-negative value, minimal between clockwise and counterclockwise direction angles. Non-oriented angle is always between 0 and π. For example, opposite directions vectors have angle equals to π.
Input
First line of the input contains a single integer n (2 ≤ n ≤ 100 000) — the number of vectors.
The i-th of the following n lines contains two integers xi and yi (|x|, |y| ≤ 10 000, x2 + y2 > 0) — the coordinates of the i-th vector. Vectors are numbered from 1 to n in order of appearing in the input. It is guaranteed that no two vectors in the input share the same direction (but they still can have opposite directions).
Output
Print two integer numbers a and b (a ≠ b) — a pair of indices of vectors with the minimal non-oriented angle. You can print the numbers in any order. If there are many possible answers, print any.
Examples
Input
4
-1 0
0 -1
1 0
1 1
Output
3 4
Input
6
-1 0
0 -1
1 0
1 1
-4 -5
-4 -6
Output
6 5 | instruction | 0 | 18,107 | 23 | 36,214 |
Tags: geometry, sortings
Correct Solution:
```
from math import sqrt
class vector:
x, y, index = 0, 0, -1
def __init__(self, x, y, index):
self.x = x
self.y = y
self.index = index
def __lt__(self, other):
if self.x * other.x < 0:
return self.x > 0
if self.x == 0 and other.x == 0:
return self.y > other.y
if self.x == 0 and other.x < 0 or self.x < 0 and other.x == 0:
self.y * other.x > other.y * self.x
return self.y * other.x < other.y * self.x
def __str__(self):
return str(self.x) + " " + str(self.y) + " " + str(self.index)
def dot(A, B):
res = A.x * B.x + A.y * B.y
if res < 0:
return -res*res
else:
return res*res
def mod_sq(A):
return A.x * A.x + A.y * A.y
n = int(input())
arr = []
for i in range(n):
temp = [int(i) for i in input().split()]
arr.append(vector(temp[0], temp[1], i))
arr.sort()
for i in range(n):
arr.append(arr[i])
ans = [0, 1]
D, M = dot(arr[0], arr[1]), (mod_sq(arr[0]) * mod_sq(arr[1]))
for i in range(2*n-1):
tD, tM = dot(arr[i], arr[i+1]), (mod_sq(arr[i]) * mod_sq(arr[i+1]))
if tD * M > D * tM:
D = tD
M = tM
ans = [i, i+1]
print(arr[ans[0]].index+1, arr[ans[1]].index+1)
``` | output | 1 | 18,107 | 23 | 36,215 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given the set of vectors on the plane, each of them starting at the origin. Your task is to find a pair of vectors with the minimal non-oriented angle between them.
Non-oriented angle is non-negative value, minimal between clockwise and counterclockwise direction angles. Non-oriented angle is always between 0 and π. For example, opposite directions vectors have angle equals to π.
Input
First line of the input contains a single integer n (2 ≤ n ≤ 100 000) — the number of vectors.
The i-th of the following n lines contains two integers xi and yi (|x|, |y| ≤ 10 000, x2 + y2 > 0) — the coordinates of the i-th vector. Vectors are numbered from 1 to n in order of appearing in the input. It is guaranteed that no two vectors in the input share the same direction (but they still can have opposite directions).
Output
Print two integer numbers a and b (a ≠ b) — a pair of indices of vectors with the minimal non-oriented angle. You can print the numbers in any order. If there are many possible answers, print any.
Examples
Input
4
-1 0
0 -1
1 0
1 1
Output
3 4
Input
6
-1 0
0 -1
1 0
1 1
-4 -5
-4 -6
Output
6 5 | instruction | 0 | 18,108 | 23 | 36,216 |
Tags: geometry, sortings
Correct Solution:
```
from collections import namedtuple
from math import sqrt
from functools import cmp_to_key
Vec = namedtuple("Vec", "x y index")
Fraction = namedtuple("Fraction", "num denom")
def fraction_comp(a, b):
return a.num*b.denom > b.num*a.denom
def angle_comp(v):
result = v.x / sqrt(v.x*v.x + v.y*v.y)
if (v.y < 0):
result = -2 - result
return result
def angle(v1, v2):
x1, y1 = v1.x, v1.y
x2, y2 = v2.x, v2.y
result = (x1*x2 + y1*y2) / (sqrt(x1*x1 + y1*y1)*sqrt(x2*x2 + y2*y2))
sign = -1 if (x1*x2 + y1*y2) < 0 else 1
return Fraction(sign*(x1*x2 + y1*y2)**2, (x1*x1 + y1*y1)*(x2*x2 + y2*y2))
n = int(input())
points = []
for i in range(n):
x, y = tuple(map(int, input().split()))
points.append(Vec(x, y, i))
points.sort(key=angle_comp)
points.reverse()
ans = (points[0].index + 1, points[n - 1].index + 1)
minAngleCos = angle(points[0], points[n - 1])
for i in range(n - 1):
currAngleCos = angle(points[i], points[i + 1])
if (fraction_comp(currAngleCos, minAngleCos)):
minAngleCos = currAngleCos
ans = (points[i].index + 1, points[i + 1].index + 1)
print(ans[0], ans[1], sep=' ')
``` | output | 1 | 18,108 | 23 | 36,217 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given the set of vectors on the plane, each of them starting at the origin. Your task is to find a pair of vectors with the minimal non-oriented angle between them.
Non-oriented angle is non-negative value, minimal between clockwise and counterclockwise direction angles. Non-oriented angle is always between 0 and π. For example, opposite directions vectors have angle equals to π.
Input
First line of the input contains a single integer n (2 ≤ n ≤ 100 000) — the number of vectors.
The i-th of the following n lines contains two integers xi and yi (|x|, |y| ≤ 10 000, x2 + y2 > 0) — the coordinates of the i-th vector. Vectors are numbered from 1 to n in order of appearing in the input. It is guaranteed that no two vectors in the input share the same direction (but they still can have opposite directions).
Output
Print two integer numbers a and b (a ≠ b) — a pair of indices of vectors with the minimal non-oriented angle. You can print the numbers in any order. If there are many possible answers, print any.
Examples
Input
4
-1 0
0 -1
1 0
1 1
Output
3 4
Input
6
-1 0
0 -1
1 0
1 1
-4 -5
-4 -6
Output
6 5 | instruction | 0 | 18,109 | 23 | 36,218 |
Tags: geometry, sortings
Correct Solution:
```
# FSX sb
def work():
def dot(x, y):
return x[0]*y[0]+x[1]*y[1]
n = int(input())
p = []
for i in range(n):
x, y = map(int, input().split(' '))
k = (20000 if y > 0 else -20000) if x == 0 else y / x
l2 = x * x + y * y
p.append((x, y, i+1, x >= 0, k, l2))
p.sort(key=lambda item: (item[3], item[4]))
p.append(p[0])
ans1 = p[0][2]
ans2 = p[1][2]
ans_up = dot(p[0], p[1])
ans_down = p[0][5]*p[1][5]
for i in range(1, n):
now_up = dot(p[i], p[i+1])
now_down = p[i][5]*p[i+1][5]
if (now_up >= 0 and ans_up <= 0) or (now_up > 0 and ans_up > 0 and (now_up * now_up * ans_down > ans_up * ans_up * now_down)) or (now_up < 0 and ans_up < 0 and (now_up * now_up * ans_down < ans_up * ans_up * now_down)):
ans_up = now_up
ans_down = now_down
ans1 = p[i][2]
ans2 = p[i + 1][2]
print(ans1, ans2)
if __name__ == "__main__":
work()
``` | output | 1 | 18,109 | 23 | 36,219 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given the set of vectors on the plane, each of them starting at the origin. Your task is to find a pair of vectors with the minimal non-oriented angle between them.
Non-oriented angle is non-negative value, minimal between clockwise and counterclockwise direction angles. Non-oriented angle is always between 0 and π. For example, opposite directions vectors have angle equals to π.
Input
First line of the input contains a single integer n (2 ≤ n ≤ 100 000) — the number of vectors.
The i-th of the following n lines contains two integers xi and yi (|x|, |y| ≤ 10 000, x2 + y2 > 0) — the coordinates of the i-th vector. Vectors are numbered from 1 to n in order of appearing in the input. It is guaranteed that no two vectors in the input share the same direction (but they still can have opposite directions).
Output
Print two integer numbers a and b (a ≠ b) — a pair of indices of vectors with the minimal non-oriented angle. You can print the numbers in any order. If there are many possible answers, print any.
Examples
Input
4
-1 0
0 -1
1 0
1 1
Output
3 4
Input
6
-1 0
0 -1
1 0
1 1
-4 -5
-4 -6
Output
6 5 | instruction | 0 | 18,110 | 23 | 36,220 |
Tags: geometry, sortings
Correct Solution:
```
import math
def dot(a, b):
return a[0] * b[0] + a[1] * b[1]
def cross(a, b):
return abs(a[0] * b[1] - a[1] * b[0])
n = int(input())
vectors = []
for i in range(n):
x, y = [int(x) for x in input().strip().split()]
vectors.append((i + 1, math.atan2(y, x), (x, y)))
vectors.sort(key=lambda x: x[1])
vectors.append(vectors[0])
mind = dot(vectors[0][2], vectors[1][2])
minc = cross(vectors[0][2], vectors[1][2])
lpair = (vectors[0][0], vectors[1][0])
for i in range(1, len(vectors) - 1):
td = dot(vectors[i][2], vectors[i + 1][2])
tc = cross(vectors[i][2], vectors[i + 1][2])
if td * minc - tc * mind > 0:
mind = td
minc = tc
lpair = (vectors[i][0], vectors[i + 1][0])
print(*lpair)
'''
cosx = v.w/(|v||w|)
sinx = |v*w|/(|v||w|)
tanx = |v*w|/v.w
td * minc - tc * mind > 0
td * minc > tc * mind
minc/mind > tc / td
'''
``` | output | 1 | 18,110 | 23 | 36,221 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given the set of vectors on the plane, each of them starting at the origin. Your task is to find a pair of vectors with the minimal non-oriented angle between them.
Non-oriented angle is non-negative value, minimal between clockwise and counterclockwise direction angles. Non-oriented angle is always between 0 and π. For example, opposite directions vectors have angle equals to π.
Input
First line of the input contains a single integer n (2 ≤ n ≤ 100 000) — the number of vectors.
The i-th of the following n lines contains two integers xi and yi (|x|, |y| ≤ 10 000, x2 + y2 > 0) — the coordinates of the i-th vector. Vectors are numbered from 1 to n in order of appearing in the input. It is guaranteed that no two vectors in the input share the same direction (but they still can have opposite directions).
Output
Print two integer numbers a and b (a ≠ b) — a pair of indices of vectors with the minimal non-oriented angle. You can print the numbers in any order. If there are many possible answers, print any.
Examples
Input
4
-1 0
0 -1
1 0
1 1
Output
3 4
Input
6
-1 0
0 -1
1 0
1 1
-4 -5
-4 -6
Output
6 5 | instruction | 0 | 18,111 | 23 | 36,222 |
Tags: geometry, sortings
Correct Solution:
```
from functools import cmp_to_key
n = int(input())
def dot(p1,p2):
x1,y1 = p1
x2,y2 = p2
return x1 * x2 + y1 * y2
def cross(p1,p2):
x1,y1 = p1
x2,y2 = p2
return x1 * y2 - x2 * y1
def top(p):
x,y = p
return y > 0 or (y == 0 and x > 0)
def polarCmp(p1,p2):
res = False
ta = top(p1)
tb = top(p2)
if (ta != tb):
res = ta
else:
res = cross(p1,p2) > 0
return -1 if res else 1
def angleLess(a1, b1, a2, b2):
p1 = (dot(a1, b1), abs(cross(a1, b1)))
p2 = (dot(a2, b2), abs(cross(a2, b2)))
return cross(p1, p2) > 0
vals = []
for _ in range(n):
x, y = map(int, input().split())
vals.append( (x,y) )
svals = sorted(vals,key = cmp_to_key(polarCmp))
idx1,idx2 = 0,1
for k in range(2,n):
if angleLess(svals[k-1],svals[k],svals[idx1],svals[idx2]):
idx1,idx2 = k-1,k
if angleLess(svals[n-1],svals[0],svals[idx1],svals[idx2]):
idx1,idx2 = n-1,0
res1 = res2 = -1
for k in range(n):
if vals[k] == svals[idx1]:
res1 = k
if vals[k] == svals[idx2]:
res2 = k
print(res1+1, res2+1)
``` | output | 1 | 18,111 | 23 | 36,223 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given the set of vectors on the plane, each of them starting at the origin. Your task is to find a pair of vectors with the minimal non-oriented angle between them.
Non-oriented angle is non-negative value, minimal between clockwise and counterclockwise direction angles. Non-oriented angle is always between 0 and π. For example, opposite directions vectors have angle equals to π.
Input
First line of the input contains a single integer n (2 ≤ n ≤ 100 000) — the number of vectors.
The i-th of the following n lines contains two integers xi and yi (|x|, |y| ≤ 10 000, x2 + y2 > 0) — the coordinates of the i-th vector. Vectors are numbered from 1 to n in order of appearing in the input. It is guaranteed that no two vectors in the input share the same direction (but they still can have opposite directions).
Output
Print two integer numbers a and b (a ≠ b) — a pair of indices of vectors with the minimal non-oriented angle. You can print the numbers in any order. If there are many possible answers, print any.
Examples
Input
4
-1 0
0 -1
1 0
1 1
Output
3 4
Input
6
-1 0
0 -1
1 0
1 1
-4 -5
-4 -6
Output
6 5 | instruction | 0 | 18,112 | 23 | 36,224 |
Tags: geometry, sortings
Correct Solution:
```
from math import atan2
inner = lambda a, b: a[0] * b[0] + a[1] * b[1]
outer = lambda a, b: a[0] * b[1] - a[1] * b[0]
N = int(input())
vectors = []
for i in range(N):
x, y = map(int, input().split())
vectors.append((atan2(y, x), (x, y), i + 1))
vectors.sort()
diff = []
for i in range(N):
diff.append([inner(vectors[i][1], vectors[(i+1)%N][1]), abs(outer(vectors[i][1], vectors[(i+1)%N][1])), vectors[i][2], vectors[(i+1)%N][2]])
min_diff = diff[0]
for d in diff:
if outer(d[:2], min_diff[:2]) > 0: min_diff = d
print(min_diff[2], min_diff[3])
``` | output | 1 | 18,112 | 23 | 36,225 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given the set of vectors on the plane, each of them starting at the origin. Your task is to find a pair of vectors with the minimal non-oriented angle between them.
Non-oriented angle is non-negative value, minimal between clockwise and counterclockwise direction angles. Non-oriented angle is always between 0 and π. For example, opposite directions vectors have angle equals to π.
Input
First line of the input contains a single integer n (2 ≤ n ≤ 100 000) — the number of vectors.
The i-th of the following n lines contains two integers xi and yi (|x|, |y| ≤ 10 000, x2 + y2 > 0) — the coordinates of the i-th vector. Vectors are numbered from 1 to n in order of appearing in the input. It is guaranteed that no two vectors in the input share the same direction (but they still can have opposite directions).
Output
Print two integer numbers a and b (a ≠ b) — a pair of indices of vectors with the minimal non-oriented angle. You can print the numbers in any order. If there are many possible answers, print any.
Examples
Input
4
-1 0
0 -1
1 0
1 1
Output
3 4
Input
6
-1 0
0 -1
1 0
1 1
-4 -5
-4 -6
Output
6 5 | instruction | 0 | 18,113 | 23 | 36,226 |
Tags: geometry, sortings
Correct Solution:
```
from math import atan2
def dot(a, b):
return a[0]*b[0] + a[1]*b[1]
def cross(a, b):
return a[0]*b[1] - a[1]*b[0]
n = int(input())
a = []
for i in range(0, n):
[x, y] = map(int, input().split())
a.append([i + 1, [x, y]])
a.sort(key=lambda x: atan2(x[1][0], x[1][1]))
a.append(a[0])
for i in range(1, len(a)):
a[i-1].append([dot(a[i-1][1], a[i][1]), abs(cross(a[i-1][1], a[i][1]))])
best = a[0]
ma = [a[0][0], a[1][0]]
for i in range(1, len(a)):
if cross(a[i][2], best[2]) > 0:
best = a[i]
ma = [a[i][0], a[i+1][0]]
print(ma[0], ma[1])
``` | output | 1 | 18,113 | 23 | 36,227 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given the set of vectors on the plane, each of them starting at the origin. Your task is to find a pair of vectors with the minimal non-oriented angle between them.
Non-oriented angle is non-negative value, minimal between clockwise and counterclockwise direction angles. Non-oriented angle is always between 0 and π. For example, opposite directions vectors have angle equals to π.
Input
First line of the input contains a single integer n (2 ≤ n ≤ 100 000) — the number of vectors.
The i-th of the following n lines contains two integers xi and yi (|x|, |y| ≤ 10 000, x2 + y2 > 0) — the coordinates of the i-th vector. Vectors are numbered from 1 to n in order of appearing in the input. It is guaranteed that no two vectors in the input share the same direction (but they still can have opposite directions).
Output
Print two integer numbers a and b (a ≠ b) — a pair of indices of vectors with the minimal non-oriented angle. You can print the numbers in any order. If there are many possible answers, print any.
Examples
Input
4
-1 0
0 -1
1 0
1 1
Output
3 4
Input
6
-1 0
0 -1
1 0
1 1
-4 -5
-4 -6
Output
6 5 | instruction | 0 | 18,114 | 23 | 36,228 |
Tags: geometry, sortings
Correct Solution:
```
from math import atan2
inner = lambda a, b: a[0] * b[0] + a[1] * b[1]
outer = lambda a, b: a[0] * b[1] - a[1] * b[0]
vectors = []
for i in range(int(input())):
x, y = map(int, input().split())
vectors.append((atan2(y, x), (x, y), i + 1))
vectors.sort()
diff = [(inner(vec1, vec2), abs(outer(vec1, vec2)), i, j) for (angle1, vec1, i), (angle2, vec2, j) in zip(vectors, vectors[1:] + vectors[:1])]
min_diff = diff[0]
for d in diff:
if outer(d[:2], min_diff[:2]) > 0: min_diff = d
print(min_diff[2], min_diff[3])
``` | output | 1 | 18,114 | 23 | 36,229 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given the set of vectors on the plane, each of them starting at the origin. Your task is to find a pair of vectors with the minimal non-oriented angle between them.
Non-oriented angle is non-negative value, minimal between clockwise and counterclockwise direction angles. Non-oriented angle is always between 0 and π. For example, opposite directions vectors have angle equals to π.
Input
First line of the input contains a single integer n (2 ≤ n ≤ 100 000) — the number of vectors.
The i-th of the following n lines contains two integers xi and yi (|x|, |y| ≤ 10 000, x2 + y2 > 0) — the coordinates of the i-th vector. Vectors are numbered from 1 to n in order of appearing in the input. It is guaranteed that no two vectors in the input share the same direction (but they still can have opposite directions).
Output
Print two integer numbers a and b (a ≠ b) — a pair of indices of vectors with the minimal non-oriented angle. You can print the numbers in any order. If there are many possible answers, print any.
Examples
Input
4
-1 0
0 -1
1 0
1 1
Output
3 4
Input
6
-1 0
0 -1
1 0
1 1
-4 -5
-4 -6
Output
6 5
Submitted Solution:
```
import math
from decimal import Decimal
from decimal import *
def dot(a, b):
return a[0] * b[0] + a[1] * b[1]
#点积 A*B=|A|*B|*cos=a1*b1+a2*b2
def cross(a, b):
return a[0] * b[1] - a[1] * b[0]
#叉积 |AxB|=|a|*|b|*sin
def ans():
for i in range(0, n):
[x, y] = map(int, input().split())
k = []
# x = int(input(""))
# y = int(input(""))
k.append(x)
k.append(y)
a.append([i + 1, k])
a.sort(key=lambda x: math.atan2(x[1][0], x[1][1]))
a.append(a[0])
for i in range(1, len(a)):
a[i - 1].append([dot(a[i - 1][1], a[i][1]), abs(cross(a[i - 1][1], a[i][1]))])
# print(a)
best = a[0]
ma = [a[0][0], a[1][0]]
for i in range(1, len(a)):
if cross(a[i][2], best[2]) > 0:
best = a[i]
ma = [a[i][0], a[i + 1][0]]
print(ma[0], ma[1])
n = int(input(""))
a = []
ans()
``` | instruction | 0 | 18,115 | 23 | 36,230 |
Yes | output | 1 | 18,115 | 23 | 36,231 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given the set of vectors on the plane, each of them starting at the origin. Your task is to find a pair of vectors with the minimal non-oriented angle between them.
Non-oriented angle is non-negative value, minimal between clockwise and counterclockwise direction angles. Non-oriented angle is always between 0 and π. For example, opposite directions vectors have angle equals to π.
Input
First line of the input contains a single integer n (2 ≤ n ≤ 100 000) — the number of vectors.
The i-th of the following n lines contains two integers xi and yi (|x|, |y| ≤ 10 000, x2 + y2 > 0) — the coordinates of the i-th vector. Vectors are numbered from 1 to n in order of appearing in the input. It is guaranteed that no two vectors in the input share the same direction (but they still can have opposite directions).
Output
Print two integer numbers a and b (a ≠ b) — a pair of indices of vectors with the minimal non-oriented angle. You can print the numbers in any order. If there are many possible answers, print any.
Examples
Input
4
-1 0
0 -1
1 0
1 1
Output
3 4
Input
6
-1 0
0 -1
1 0
1 1
-4 -5
-4 -6
Output
6 5
Submitted Solution:
```
from functools import cmp_to_key
n = int(input())
x = [0 for i in range(n)]
y = [0 for i in range(n)]
for i in range(n):
x[i], y[i] = map(int, input().strip().split(" "))
vp = []
vm = []
for i in range(n):
if y[i] >= 0:
vp.append(i)
else:
vm.append(i)
def cmp1(i, j):
xi = (1 if x[i] > 0 else -1)
xj = (1 if x[j] > 0 else -1)
b = xi * x[i] * x[i] * (x[j] * x[j] + y[j] * y[j]) > xj * x[j] * x[j] * (x[i] * x[i] + y[i] * y[i])
return (-1 if b else 1)
def cmp2(i, j):
xi = (1 if x[i] > 0 else -1)
xj = (1 if x[j] > 0 else -1)
b = xi * x[i] * x[i] * (x[j] * x[j] + y[j] * y[j]) < xj * x[j] * x[j] * (x[i] * x[i] + y[i] * y[i])
return (-1 if b else 1)
vp = sorted(vp, key=cmp_to_key(cmp1))
vm = sorted(vm, key=cmp_to_key(cmp2))
vp = vp + vm
vp.append(vp[0])
a = 0
b = 0
man = -2
mad = 1
for i in range(n):
j = vp[i]
k = vp[i + 1]
tan = x[j] * x[k] + y[j] * y[k]
p = (tan > 0)
tan = tan * tan * (1 if p else -1)
tad = (x[j] * x[j] + y[j] * y[j]) * (x[k] * x[k] + y[k] * y[k])
if man * tad < tan * mad:
man = tan
mad = tad
a = j
b = k
print("{} {}".format(a + 1, b + 1))
``` | instruction | 0 | 18,116 | 23 | 36,232 |
Yes | output | 1 | 18,116 | 23 | 36,233 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given the set of vectors on the plane, each of them starting at the origin. Your task is to find a pair of vectors with the minimal non-oriented angle between them.
Non-oriented angle is non-negative value, minimal between clockwise and counterclockwise direction angles. Non-oriented angle is always between 0 and π. For example, opposite directions vectors have angle equals to π.
Input
First line of the input contains a single integer n (2 ≤ n ≤ 100 000) — the number of vectors.
The i-th of the following n lines contains two integers xi and yi (|x|, |y| ≤ 10 000, x2 + y2 > 0) — the coordinates of the i-th vector. Vectors are numbered from 1 to n in order of appearing in the input. It is guaranteed that no two vectors in the input share the same direction (but they still can have opposite directions).
Output
Print two integer numbers a and b (a ≠ b) — a pair of indices of vectors with the minimal non-oriented angle. You can print the numbers in any order. If there are many possible answers, print any.
Examples
Input
4
-1 0
0 -1
1 0
1 1
Output
3 4
Input
6
-1 0
0 -1
1 0
1 1
-4 -5
-4 -6
Output
6 5
Submitted Solution:
```
from math import atan2
from functools import cmp_to_key
N = int(input())
V = []
for i in range(N):
x, y = map(int, input().split())
V.append((x, y, i))
V.sort(key=lambda z: atan2(z[1], z[0]))
D = [(V[i - 1], V[i]) for i in range(N)]
def cmp(z1, z2):
v11, v12 = z1
v21, v22 = z2
x11, y11, _ = v11
x12, y12, _ = v12
x21, y21, _ = v21
x22, y22, _ = v22
p1 = x11 * x12 + y11 * y12
p2 = x21 * x22 + y21 * y22
if p1 >= 0 and p2 <= 0:
return 1
if p1 <= 0 and p2 >= 0:
return -1
q1 = (p1**2) * (x21**2 + y21**2) * (x22**2 + y22**2)
q2 = (p2**2) * (x11**2 + y11**2) * (x12**2 + y12**2)
if q1 == q2:
return 0
if p1 >= 0 and p2 >= 0:
return 1 if q1 > q2 else -1
if p1 <= 0 and p2 <= 0:
return 1 if q1 < q2 else -1
a1, a2 = max(D, key=cmp_to_key(cmp))
_, _, idx1 = a1
_, _, idx2 = a2
print(idx1 + 1, idx2 + 1)
``` | instruction | 0 | 18,117 | 23 | 36,234 |
Yes | output | 1 | 18,117 | 23 | 36,235 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given the set of vectors on the plane, each of them starting at the origin. Your task is to find a pair of vectors with the minimal non-oriented angle between them.
Non-oriented angle is non-negative value, minimal between clockwise and counterclockwise direction angles. Non-oriented angle is always between 0 and π. For example, opposite directions vectors have angle equals to π.
Input
First line of the input contains a single integer n (2 ≤ n ≤ 100 000) — the number of vectors.
The i-th of the following n lines contains two integers xi and yi (|x|, |y| ≤ 10 000, x2 + y2 > 0) — the coordinates of the i-th vector. Vectors are numbered from 1 to n in order of appearing in the input. It is guaranteed that no two vectors in the input share the same direction (but they still can have opposite directions).
Output
Print two integer numbers a and b (a ≠ b) — a pair of indices of vectors with the minimal non-oriented angle. You can print the numbers in any order. If there are many possible answers, print any.
Examples
Input
4
-1 0
0 -1
1 0
1 1
Output
3 4
Input
6
-1 0
0 -1
1 0
1 1
-4 -5
-4 -6
Output
6 5
Submitted Solution:
```
import sys
# sys.stdin = open('ivo.in')
def getkos(x, y):
temp = (x[0] * y[0] + x[1] * y[1])
mul = -1 if temp < 0 else 1
return (mul * temp ** 2, (x[0] ** 2 + x[1] ** 2) * (y[0] ** 2 + y[1] ** 2))
class Drob:
def __init__(self, num, denom):
self.num = num
self.denom = denom
def __lt__(self, object):
return self.num * object.denom < object.num * self.denom
n = int(sys.stdin.readline())
positive = []
negative = []
for i in range(n):
x = tuple(map(int, sys.stdin.readline().split())) + (i,)
if x[1] > 0:
positive.append(x)
else:
negative.append(x)
positive.sort(key=lambda x: Drob((-1 if x[0] > 0 else 1) * x[0]**2 , (x[1] ** 2 + x[0] ** 2)))
negative.sort(key=lambda x: Drob((1 if x[0] > 0 else -1) * x[0]**2 , (x[1] ** 2 + x[0] ** 2)))
#negative.sort(key=lambda x,y: x[0] - y[0] if x[0] != y[0] else (y[1] - x[1]) * x[0])
all = positive + negative
# print(all)
biggest = [-1.1, 1]
bi = 0
bj = 1
for i in range(n):
nxt = (i + 1) % n
prev = (i + n - 1) % n
kos1 = getkos(all[i], all[nxt])
if kos1[1] * biggest[0] < kos1[0] * biggest[1]:
biggest = kos1
bi = all[i][2]
bj = all[nxt][2]
kos2 = getkos(all[i], all[prev])
if kos2[1] * biggest[0] < kos2[0] * biggest[1]:
biggest = kos2
bi = all[i][2]
bj = all[prev][2]
# print("{} kos1: {} kos2: {}".format(i, kos1, kos2))
# print(biggest)
print("%d %d" % (bi + 1, bj+ 1))
``` | instruction | 0 | 18,118 | 23 | 36,236 |
Yes | output | 1 | 18,118 | 23 | 36,237 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given the set of vectors on the plane, each of them starting at the origin. Your task is to find a pair of vectors with the minimal non-oriented angle between them.
Non-oriented angle is non-negative value, minimal between clockwise and counterclockwise direction angles. Non-oriented angle is always between 0 and π. For example, opposite directions vectors have angle equals to π.
Input
First line of the input contains a single integer n (2 ≤ n ≤ 100 000) — the number of vectors.
The i-th of the following n lines contains two integers xi and yi (|x|, |y| ≤ 10 000, x2 + y2 > 0) — the coordinates of the i-th vector. Vectors are numbered from 1 to n in order of appearing in the input. It is guaranteed that no two vectors in the input share the same direction (but they still can have opposite directions).
Output
Print two integer numbers a and b (a ≠ b) — a pair of indices of vectors with the minimal non-oriented angle. You can print the numbers in any order. If there are many possible answers, print any.
Examples
Input
4
-1 0
0 -1
1 0
1 1
Output
3 4
Input
6
-1 0
0 -1
1 0
1 1
-4 -5
-4 -6
Output
6 5
Submitted Solution:
```
from math import atan, pi, degrees
ar, minn, p1, p2 = [], 360, 0, 0
for i in range(int(input())):
x, y = map(int, input().split())
if x == 0 and y >= 0:
ar.append((degrees(pi / 2), i + 1))
elif x == 0 and y <= 0:
ar.append((degrees(1.5 * pi), i + 1))
else:
angle = atan(y / x)
if x > 0 and y > 0:
ar.append((degrees(angle), i + 1))
elif x < 0 and y > 0:
ar.append((degrees(-angle + pi), i + 1))
elif x < 0 and y < 0:
ar.append((degrees(pi + angle), i + 1))
elif x > 0 and y < 0:
ar.append((degrees(2 * pi + angle), i + 1))
elif x > 0 and y == 0:
ar.append((degrees(0), i + 1))
elif x < 0 and y == 0:
ar.append((degrees(pi), i + 1))
ar.sort()
# print(ar)s
for x in range(0, len(ar)):
temp = abs(ar[(x + 1) % len(ar)][0] - ar[x][0])
# print(temp)
if temp > 180:
temp = 360 - temp
if temp < minn:
minn = temp
p1 = ar[x][1]
p2 = ar[(x + 1) % len(ar)][1]
print(p1, p2)
``` | instruction | 0 | 18,119 | 23 | 36,238 |
No | output | 1 | 18,119 | 23 | 36,239 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given the set of vectors on the plane, each of them starting at the origin. Your task is to find a pair of vectors with the minimal non-oriented angle between them.
Non-oriented angle is non-negative value, minimal between clockwise and counterclockwise direction angles. Non-oriented angle is always between 0 and π. For example, opposite directions vectors have angle equals to π.
Input
First line of the input contains a single integer n (2 ≤ n ≤ 100 000) — the number of vectors.
The i-th of the following n lines contains two integers xi and yi (|x|, |y| ≤ 10 000, x2 + y2 > 0) — the coordinates of the i-th vector. Vectors are numbered from 1 to n in order of appearing in the input. It is guaranteed that no two vectors in the input share the same direction (but they still can have opposite directions).
Output
Print two integer numbers a and b (a ≠ b) — a pair of indices of vectors with the minimal non-oriented angle. You can print the numbers in any order. If there are many possible answers, print any.
Examples
Input
4
-1 0
0 -1
1 0
1 1
Output
3 4
Input
6
-1 0
0 -1
1 0
1 1
-4 -5
-4 -6
Output
6 5
Submitted Solution:
```
from math import atan2
def dot(a, b):
return a[0]*b[0] + a[1]*b[1]
def cross(a, b):
return a[0]*b[1] - a[1]*b[0]
n = int(input())
a = []
for i in range(0, n):
[x, y] = map(int, input().split())
a.append([i + 1, [x, y]])
a.sort(key=lambda x: atan2(x[1][0], x[1][1]))
a.append(a[0])
for i in range(1, len(a)):
a[i-1].append([dot(a[i-1][1], a[i][1]), abs(cross(a[i-1][1], a[i][1]))])
best = a[0]
ma = [a[0][0], a[1][0]]
for i in range(1, len(a)):
if cross(a[i][2], best[2]) > 0:
best = a[i]
ma = [a[i][0], a[i+1][0]]
``` | instruction | 0 | 18,120 | 23 | 36,240 |
No | output | 1 | 18,120 | 23 | 36,241 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given the set of vectors on the plane, each of them starting at the origin. Your task is to find a pair of vectors with the minimal non-oriented angle between them.
Non-oriented angle is non-negative value, minimal between clockwise and counterclockwise direction angles. Non-oriented angle is always between 0 and π. For example, opposite directions vectors have angle equals to π.
Input
First line of the input contains a single integer n (2 ≤ n ≤ 100 000) — the number of vectors.
The i-th of the following n lines contains two integers xi and yi (|x|, |y| ≤ 10 000, x2 + y2 > 0) — the coordinates of the i-th vector. Vectors are numbered from 1 to n in order of appearing in the input. It is guaranteed that no two vectors in the input share the same direction (but they still can have opposite directions).
Output
Print two integer numbers a and b (a ≠ b) — a pair of indices of vectors with the minimal non-oriented angle. You can print the numbers in any order. If there are many possible answers, print any.
Examples
Input
4
-1 0
0 -1
1 0
1 1
Output
3 4
Input
6
-1 0
0 -1
1 0
1 1
-4 -5
-4 -6
Output
6 5
Submitted Solution:
```
import sys
# sys.stdin = open('ivo.in')
def getkos(x, y):
temp = (x[0] * y[0] + x[1] * y[1])
mul = -1 if temp < 0 else 1
return (mul * temp ** 2, (x[0] ** 2 + x[1] ** 2) * (y[0] ** 2 + y[1] ** 2))
n = int(sys.stdin.readline())
positive = []
negative = []
for i in range(n):
x = tuple(map(int, sys.stdin.readline().split())) + (i,)
if x[1] > 0:
positive.append(x)
else:
negative.append(x)
positive.sort(key=lambda x: (-x[0], ( x[1] * x[0])))
negative.sort(key=lambda x: (x[0], (-1 * x[1] * x[0])))
#negative.sort(key=lambda x,y: x[0] - y[0] if x[0] != y[0] else (y[1] - x[1]) * x[0])
all = positive + negative
biggest = [0, 1]
bi = 0
bj = 1
for i in range(n):
nxt = (i + 1) % n
prev = (i + n - 1) % n
kos1 = getkos(all[i], all[nxt])
if kos1[1] * biggest[0] < kos1[0] * biggest[1]:
biggest = kos1
bi = all[i][2]
bj = all[nxt][2]
kos2 = getkos(all[i], all[prev])
if kos2[1] * biggest[0] < kos2[0] * biggest[1]:
biggest = kos2
bi = all[i][2]
bj = all[prev][2]
print("%d %d" % (bi + 1, bj+ 1))
``` | instruction | 0 | 18,121 | 23 | 36,242 |
No | output | 1 | 18,121 | 23 | 36,243 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given the set of vectors on the plane, each of them starting at the origin. Your task is to find a pair of vectors with the minimal non-oriented angle between them.
Non-oriented angle is non-negative value, minimal between clockwise and counterclockwise direction angles. Non-oriented angle is always between 0 and π. For example, opposite directions vectors have angle equals to π.
Input
First line of the input contains a single integer n (2 ≤ n ≤ 100 000) — the number of vectors.
The i-th of the following n lines contains two integers xi and yi (|x|, |y| ≤ 10 000, x2 + y2 > 0) — the coordinates of the i-th vector. Vectors are numbered from 1 to n in order of appearing in the input. It is guaranteed that no two vectors in the input share the same direction (but they still can have opposite directions).
Output
Print two integer numbers a and b (a ≠ b) — a pair of indices of vectors with the minimal non-oriented angle. You can print the numbers in any order. If there are many possible answers, print any.
Examples
Input
4
-1 0
0 -1
1 0
1 1
Output
3 4
Input
6
-1 0
0 -1
1 0
1 1
-4 -5
-4 -6
Output
6 5
Submitted Solution:
```
from math import atan2,pi
n = int(input())
a = []
for i in range(n):
x,y = map(int,input().split(' '))
angle = atan2(y,x)
a.append([2*pi+angle if angle < 0 else angle,i])
a.sort()
minn = float('inf')
ans = 0,0
for i in range(1,n):
if a[i][0]-a[i-1][0]<minn:
minn = a[i][0]-a[i-1][0]
ans = a[i][1]+1,a[i-1][1]+1
if a[n-1][0]>pi:
if a[0][0] - (a[n-1][0]-2*pi) < minn:
ans = a[0][1]+1,a[n-1][1]+1
print(ans[0],ans[1])
``` | instruction | 0 | 18,122 | 23 | 36,244 |
No | output | 1 | 18,122 | 23 | 36,245 |
Provide a correct Python 3 solution for this coding contest problem.
Seiji Hayashi had been a professor of the Nisshinkan Samurai School in the domain of Aizu for a long time in the 18th century. In order to reward him for his meritorious career in education, Katanobu Matsudaira, the lord of the domain of Aizu, had decided to grant him a rectangular estate within a large field in the Aizu Basin. Although the size (width and height) of the estate was strictly specified by the lord, he was allowed to choose any location for the estate in the field. Inside the field which had also a rectangular shape, many Japanese persimmon trees, whose fruit was one of the famous products of the Aizu region known as 'Mishirazu Persimmon', were planted. Since persimmon was Hayashi's favorite fruit, he wanted to have as many persimmon trees as possible in the estate given by the lord.
For example, in Figure 1, the entire field is a rectangular grid whose width and height are 10 and 8 respectively. Each asterisk (*) represents a place of a persimmon tree. If the specified width and height of the estate are 4 and 3 respectively, the area surrounded by the solid line contains the most persimmon trees. Similarly, if the estate's width is 6 and its height is 4, the area surrounded by the dashed line has the most, and if the estate's width and height are 3 and 4 respectively, the area surrounded by the dotted line contains the most persimmon trees. Note that the width and height cannot be swapped; the sizes 4 by 3 and 3 by 4 are different, as shown in Figure 1.
<image>
---
Figure 1: Examples of Rectangular Estates
Your task is to find the estate of a given size (width and height) that contains the largest number of persimmon trees.
Input
The input consists of multiple data sets. Each data set is given in the following format.
> N
> W` `H
> x1` `y1
> x2` `y2
> ...
> xN` `yN
> S` `T
>
N is the number of persimmon trees, which is a positive integer less than 500. W and H are the width and the height of the entire field respectively. You can assume that both W and H are positive integers whose values are less than 100. For each i (1 <= i <= N), xi and yi are coordinates of the i-th persimmon tree in the grid. Note that the origin of each coordinate is 1. You can assume that 1 <= xi <= W and 1 <= yi <= H, and no two trees have the same positions. But you should not assume that the persimmon trees are sorted in some order according to their positions. Lastly, S and T are positive integers of the width and height respectively of the estate given by the lord. You can also assume that 1 <= S <= W and 1 <= T <= H.
The end of the input is indicated by a line that solely contains a zero.
Output
For each data set, you are requested to print one line containing the maximum possible number of persimmon trees that can be included in an estate of the given size.
Example
Input
16
10 8
2 2
2 5
2 7
3 3
3 8
4 2
4 5
4 8
6 4
6 7
7 5
7 8
8 1
8 4
9 6
10 3
4 3
8
6 4
1 2
2 1
2 4
3 4
4 2
5 3
6 1
6 2
3 2
0
Output
4
3 | instruction | 0 | 18,490 | 23 | 36,980 |
"Correct Solution:
```
# AOJ 1125: Get Many Persimmon Trees
# Python3 2018.7.14 bal4u
s = [[0 for x in range(105)] for y in range(105)]
while True:
N = int(input())
if N == 0: break
a = [[0 for x in range(105)] for y in range(105)]
W, H = map(int, input().split())
for i in range(N):
x, y = map(int, input().split())
a[y][x] = 1
for y in range(1, H+1):
for x in range(1, W+1): s[y][x] = s[y][x-1] + a[y][x]
S, T = map(int, input().split())
ans = 0
for y in range(H-T+1):
for x in range(W-S+1):
k = 0
for i in range(1, T+1): k += s[y+i][x+S]-s[y+i][x];
ans = max(ans, k)
print(ans)
``` | output | 1 | 18,490 | 23 | 36,981 |
Provide a correct Python 3 solution for this coding contest problem.
Seiji Hayashi had been a professor of the Nisshinkan Samurai School in the domain of Aizu for a long time in the 18th century. In order to reward him for his meritorious career in education, Katanobu Matsudaira, the lord of the domain of Aizu, had decided to grant him a rectangular estate within a large field in the Aizu Basin. Although the size (width and height) of the estate was strictly specified by the lord, he was allowed to choose any location for the estate in the field. Inside the field which had also a rectangular shape, many Japanese persimmon trees, whose fruit was one of the famous products of the Aizu region known as 'Mishirazu Persimmon', were planted. Since persimmon was Hayashi's favorite fruit, he wanted to have as many persimmon trees as possible in the estate given by the lord.
For example, in Figure 1, the entire field is a rectangular grid whose width and height are 10 and 8 respectively. Each asterisk (*) represents a place of a persimmon tree. If the specified width and height of the estate are 4 and 3 respectively, the area surrounded by the solid line contains the most persimmon trees. Similarly, if the estate's width is 6 and its height is 4, the area surrounded by the dashed line has the most, and if the estate's width and height are 3 and 4 respectively, the area surrounded by the dotted line contains the most persimmon trees. Note that the width and height cannot be swapped; the sizes 4 by 3 and 3 by 4 are different, as shown in Figure 1.
<image>
---
Figure 1: Examples of Rectangular Estates
Your task is to find the estate of a given size (width and height) that contains the largest number of persimmon trees.
Input
The input consists of multiple data sets. Each data set is given in the following format.
> N
> W` `H
> x1` `y1
> x2` `y2
> ...
> xN` `yN
> S` `T
>
N is the number of persimmon trees, which is a positive integer less than 500. W and H are the width and the height of the entire field respectively. You can assume that both W and H are positive integers whose values are less than 100. For each i (1 <= i <= N), xi and yi are coordinates of the i-th persimmon tree in the grid. Note that the origin of each coordinate is 1. You can assume that 1 <= xi <= W and 1 <= yi <= H, and no two trees have the same positions. But you should not assume that the persimmon trees are sorted in some order according to their positions. Lastly, S and T are positive integers of the width and height respectively of the estate given by the lord. You can also assume that 1 <= S <= W and 1 <= T <= H.
The end of the input is indicated by a line that solely contains a zero.
Output
For each data set, you are requested to print one line containing the maximum possible number of persimmon trees that can be included in an estate of the given size.
Example
Input
16
10 8
2 2
2 5
2 7
3 3
3 8
4 2
4 5
4 8
6 4
6 7
7 5
7 8
8 1
8 4
9 6
10 3
4 3
8
6 4
1 2
2 1
2 4
3 4
4 2
5 3
6 1
6 2
3 2
0
Output
4
3 | instruction | 0 | 18,491 | 23 | 36,982 |
"Correct Solution:
```
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**3
eps = 1.0 / 10**10
mod = 10**9+7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
class Ruiwa():
def __init__(self, a):
self.H = h = len(a)
self.W = w = len(a[0])
self.R = r = a
for i in range(h):
for j in range(1,w):
r[i][j] += r[i][j-1]
for i in range(1,h):
for j in range(w):
r[i][j] += r[i-1][j]
def search(self, x1, y1, x2, y2):
if x1 > x2 or y1 > y2:
return 0
r = self.R
rr = r[y2][x2]
if x1 > 0 and y1 > 0:
return rr - r[y1-1][x2] - r[y2][x1-1] + r[y1-1][x1-1]
if x1 > 0:
rr -= r[y2][x1-1]
if y1 > 0:
rr -= r[y1-1][x2]
return rr
def main():
rr = []
while True:
n = I()
if n == 0:
break
w,h = LI()
xy = [LI_() for _ in range(n)]
s,t = LI()
a = [[0]*w for _ in range(h)]
for x,y in xy:
a[y][x] = 1
rui = Ruiwa(a)
r = 0
for i in range(h-t+1):
for j in range(w-s+1):
tr = rui.search(j,i,j+s-1,i+t-1)
if r < tr:
r = tr
rr.append(r)
return '\n'.join(map(str, rr))
print(main())
``` | output | 1 | 18,491 | 23 | 36,983 |
Provide a correct Python 3 solution for this coding contest problem.
Seiji Hayashi had been a professor of the Nisshinkan Samurai School in the domain of Aizu for a long time in the 18th century. In order to reward him for his meritorious career in education, Katanobu Matsudaira, the lord of the domain of Aizu, had decided to grant him a rectangular estate within a large field in the Aizu Basin. Although the size (width and height) of the estate was strictly specified by the lord, he was allowed to choose any location for the estate in the field. Inside the field which had also a rectangular shape, many Japanese persimmon trees, whose fruit was one of the famous products of the Aizu region known as 'Mishirazu Persimmon', were planted. Since persimmon was Hayashi's favorite fruit, he wanted to have as many persimmon trees as possible in the estate given by the lord.
For example, in Figure 1, the entire field is a rectangular grid whose width and height are 10 and 8 respectively. Each asterisk (*) represents a place of a persimmon tree. If the specified width and height of the estate are 4 and 3 respectively, the area surrounded by the solid line contains the most persimmon trees. Similarly, if the estate's width is 6 and its height is 4, the area surrounded by the dashed line has the most, and if the estate's width and height are 3 and 4 respectively, the area surrounded by the dotted line contains the most persimmon trees. Note that the width and height cannot be swapped; the sizes 4 by 3 and 3 by 4 are different, as shown in Figure 1.
<image>
---
Figure 1: Examples of Rectangular Estates
Your task is to find the estate of a given size (width and height) that contains the largest number of persimmon trees.
Input
The input consists of multiple data sets. Each data set is given in the following format.
> N
> W` `H
> x1` `y1
> x2` `y2
> ...
> xN` `yN
> S` `T
>
N is the number of persimmon trees, which is a positive integer less than 500. W and H are the width and the height of the entire field respectively. You can assume that both W and H are positive integers whose values are less than 100. For each i (1 <= i <= N), xi and yi are coordinates of the i-th persimmon tree in the grid. Note that the origin of each coordinate is 1. You can assume that 1 <= xi <= W and 1 <= yi <= H, and no two trees have the same positions. But you should not assume that the persimmon trees are sorted in some order according to their positions. Lastly, S and T are positive integers of the width and height respectively of the estate given by the lord. You can also assume that 1 <= S <= W and 1 <= T <= H.
The end of the input is indicated by a line that solely contains a zero.
Output
For each data set, you are requested to print one line containing the maximum possible number of persimmon trees that can be included in an estate of the given size.
Example
Input
16
10 8
2 2
2 5
2 7
3 3
3 8
4 2
4 5
4 8
6 4
6 7
7 5
7 8
8 1
8 4
9 6
10 3
4 3
8
6 4
1 2
2 1
2 4
3 4
4 2
5 3
6 1
6 2
3 2
0
Output
4
3 | instruction | 0 | 18,492 | 23 | 36,984 |
"Correct Solution:
```
def main(n):
w, h = map(int, input().split())
xy = [list(map(lambda x:int(x)-1, input().split())) for i in range(n)]
s, t = map(int, input().split())
field = [[0] * w for i in range(h)]
for x, y in xy:
field[y][x] = 1
ans = 0
for y in range(h - t + 1):
for x in range(w - s + 1):
b = 0
for yi in range(t):
for xi in range(s):
b += field[y + yi][x + xi]
ans = max(ans, b)
print(ans)
while 1:
n = int(input())
if n == 0:
break
main(n)
``` | output | 1 | 18,492 | 23 | 36,985 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.