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 tags and a correct Python 3 solution for this coding contest problem.
You are given a following process.
There is a platform with n columns. 1 × 1 squares are appearing one after another in some columns on this platform. If there are no squares in the column, a square will occupy the bottom row. Otherwise a square will appear at the top of the highest square of this column.
When all of the n columns have at least one square in them, the bottom row is being removed. You will receive 1 point for this, and all the squares left will fall down one row.
You task is to calculate the amount of points you will receive.
Input
The first line of input contain 2 integer numbers n and m (1 ≤ n, m ≤ 1000) — the length of the platform and the number of the squares.
The next line contain m integer numbers c_1, c_2, ..., c_m (1 ≤ c_i ≤ n) — column in which i-th square will appear.
Output
Print one integer — the amount of points you will receive.
Example
Input
3 9
1 1 2 2 2 3 1 2 3
Output
2
Note
In the sample case the answer will be equal to 2 because after the appearing of 6-th square will be removed one row (counts of the squares on the platform will look like [2~ 3~ 1], and after removing one row will be [1~ 2~ 0]).
After the appearing of 9-th square counts will be [2~ 3~ 1], and after removing one row it will look like [1~ 2~ 0].
So the answer will be equal to 2. | instruction | 0 | 102,660 | 23 | 205,320 |
Tags: implementation
Correct Solution:
```
def main():
[n_columns, n_squares] = [int(_) for _ in input().split()]
columns = [0] * n_columns
squares = [int(_) for _ in input().split()]
points = 0
for square in squares:
columns[square - 1] += 1
if 0 not in columns:
points += 1
for i in range(n_columns):
columns[i] -= 1
print(points)
if __name__ == '__main__':
main()
``` | output | 1 | 102,660 | 23 | 205,321 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a following process.
There is a platform with n columns. 1 × 1 squares are appearing one after another in some columns on this platform. If there are no squares in the column, a square will occupy the bottom row. Otherwise a square will appear at the top of the highest square of this column.
When all of the n columns have at least one square in them, the bottom row is being removed. You will receive 1 point for this, and all the squares left will fall down one row.
You task is to calculate the amount of points you will receive.
Input
The first line of input contain 2 integer numbers n and m (1 ≤ n, m ≤ 1000) — the length of the platform and the number of the squares.
The next line contain m integer numbers c_1, c_2, ..., c_m (1 ≤ c_i ≤ n) — column in which i-th square will appear.
Output
Print one integer — the amount of points you will receive.
Example
Input
3 9
1 1 2 2 2 3 1 2 3
Output
2
Note
In the sample case the answer will be equal to 2 because after the appearing of 6-th square will be removed one row (counts of the squares on the platform will look like [2~ 3~ 1], and after removing one row will be [1~ 2~ 0]).
After the appearing of 9-th square counts will be [2~ 3~ 1], and after removing one row it will look like [1~ 2~ 0].
So the answer will be equal to 2. | instruction | 0 | 102,661 | 23 | 205,322 |
Tags: implementation
Correct Solution:
```
n, m = map(int, input().split(' '))
l = list(map(int, input().split(' ')))
bonus = 0
cul = [0 for _ in range(n)]
for i in (l):
i = i-1
cul[i] = cul[i] + 1
ans = min(cul)
print(ans)
``` | output | 1 | 102,661 | 23 | 205,323 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a following process.
There is a platform with n columns. 1 × 1 squares are appearing one after another in some columns on this platform. If there are no squares in the column, a square will occupy the bottom row. Otherwise a square will appear at the top of the highest square of this column.
When all of the n columns have at least one square in them, the bottom row is being removed. You will receive 1 point for this, and all the squares left will fall down one row.
You task is to calculate the amount of points you will receive.
Input
The first line of input contain 2 integer numbers n and m (1 ≤ n, m ≤ 1000) — the length of the platform and the number of the squares.
The next line contain m integer numbers c_1, c_2, ..., c_m (1 ≤ c_i ≤ n) — column in which i-th square will appear.
Output
Print one integer — the amount of points you will receive.
Example
Input
3 9
1 1 2 2 2 3 1 2 3
Output
2
Note
In the sample case the answer will be equal to 2 because after the appearing of 6-th square will be removed one row (counts of the squares on the platform will look like [2~ 3~ 1], and after removing one row will be [1~ 2~ 0]).
After the appearing of 9-th square counts will be [2~ 3~ 1], and after removing one row it will look like [1~ 2~ 0].
So the answer will be equal to 2. | instruction | 0 | 102,663 | 23 | 205,326 |
Tags: implementation
Correct Solution:
```
t = 1
while t:
t-=1
n, m = map(int, input().split())
ls = list(map(int, input().split()))
hash = [0 for _ in range(n)]
for item in ls:
hash[item-1]+=1
print(min(hash))
``` | output | 1 | 102,663 | 23 | 205,327 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a following process.
There is a platform with n columns. 1 × 1 squares are appearing one after another in some columns on this platform. If there are no squares in the column, a square will occupy the bottom row. Otherwise a square will appear at the top of the highest square of this column.
When all of the n columns have at least one square in them, the bottom row is being removed. You will receive 1 point for this, and all the squares left will fall down one row.
You task is to calculate the amount of points you will receive.
Input
The first line of input contain 2 integer numbers n and m (1 ≤ n, m ≤ 1000) — the length of the platform and the number of the squares.
The next line contain m integer numbers c_1, c_2, ..., c_m (1 ≤ c_i ≤ n) — column in which i-th square will appear.
Output
Print one integer — the amount of points you will receive.
Example
Input
3 9
1 1 2 2 2 3 1 2 3
Output
2
Note
In the sample case the answer will be equal to 2 because after the appearing of 6-th square will be removed one row (counts of the squares on the platform will look like [2~ 3~ 1], and after removing one row will be [1~ 2~ 0]).
After the appearing of 9-th square counts will be [2~ 3~ 1], and after removing one row it will look like [1~ 2~ 0].
So the answer will be equal to 2. | instruction | 0 | 102,664 | 23 | 205,328 |
Tags: implementation
Correct Solution:
```
from collections import Counter
n,m=map(int,input().split())
l=list(map(int,input().split()))
c=Counter(l)
if len(c) == n :
print(min(c.values()))
else :
print("0")
``` | output | 1 | 102,664 | 23 | 205,329 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a following process.
There is a platform with n columns. 1 × 1 squares are appearing one after another in some columns on this platform. If there are no squares in the column, a square will occupy the bottom row. Otherwise a square will appear at the top of the highest square of this column.
When all of the n columns have at least one square in them, the bottom row is being removed. You will receive 1 point for this, and all the squares left will fall down one row.
You task is to calculate the amount of points you will receive.
Input
The first line of input contain 2 integer numbers n and m (1 ≤ n, m ≤ 1000) — the length of the platform and the number of the squares.
The next line contain m integer numbers c_1, c_2, ..., c_m (1 ≤ c_i ≤ n) — column in which i-th square will appear.
Output
Print one integer — the amount of points you will receive.
Example
Input
3 9
1 1 2 2 2 3 1 2 3
Output
2
Note
In the sample case the answer will be equal to 2 because after the appearing of 6-th square will be removed one row (counts of the squares on the platform will look like [2~ 3~ 1], and after removing one row will be [1~ 2~ 0]).
After the appearing of 9-th square counts will be [2~ 3~ 1], and after removing one row it will look like [1~ 2~ 0].
So the answer will be equal to 2.
Submitted Solution:
```
n,m=map(int,input().split())
mas=[0]*(n+1)
mas[0]=10**5
a=list(map(int,input().split()))
for i in a:
mas[i]+=1
print(min(mas))
``` | instruction | 0 | 102,665 | 23 | 205,330 |
Yes | output | 1 | 102,665 | 23 | 205,331 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a following process.
There is a platform with n columns. 1 × 1 squares are appearing one after another in some columns on this platform. If there are no squares in the column, a square will occupy the bottom row. Otherwise a square will appear at the top of the highest square of this column.
When all of the n columns have at least one square in them, the bottom row is being removed. You will receive 1 point for this, and all the squares left will fall down one row.
You task is to calculate the amount of points you will receive.
Input
The first line of input contain 2 integer numbers n and m (1 ≤ n, m ≤ 1000) — the length of the platform and the number of the squares.
The next line contain m integer numbers c_1, c_2, ..., c_m (1 ≤ c_i ≤ n) — column in which i-th square will appear.
Output
Print one integer — the amount of points you will receive.
Example
Input
3 9
1 1 2 2 2 3 1 2 3
Output
2
Note
In the sample case the answer will be equal to 2 because after the appearing of 6-th square will be removed one row (counts of the squares on the platform will look like [2~ 3~ 1], and after removing one row will be [1~ 2~ 0]).
After the appearing of 9-th square counts will be [2~ 3~ 1], and after removing one row it will look like [1~ 2~ 0].
So the answer will be equal to 2.
Submitted Solution:
```
n, m = map(int, input().split())
l = list(map(int, input().split()))
l_set = list(set(l))
if len(l_set) != n:
print(0)
exit()
lp = []
for i in l_set:
lp.append(l.count(i))
print(min(lp))
``` | instruction | 0 | 102,666 | 23 | 205,332 |
Yes | output | 1 | 102,666 | 23 | 205,333 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a following process.
There is a platform with n columns. 1 × 1 squares are appearing one after another in some columns on this platform. If there are no squares in the column, a square will occupy the bottom row. Otherwise a square will appear at the top of the highest square of this column.
When all of the n columns have at least one square in them, the bottom row is being removed. You will receive 1 point for this, and all the squares left will fall down one row.
You task is to calculate the amount of points you will receive.
Input
The first line of input contain 2 integer numbers n and m (1 ≤ n, m ≤ 1000) — the length of the platform and the number of the squares.
The next line contain m integer numbers c_1, c_2, ..., c_m (1 ≤ c_i ≤ n) — column in which i-th square will appear.
Output
Print one integer — the amount of points you will receive.
Example
Input
3 9
1 1 2 2 2 3 1 2 3
Output
2
Note
In the sample case the answer will be equal to 2 because after the appearing of 6-th square will be removed one row (counts of the squares on the platform will look like [2~ 3~ 1], and after removing one row will be [1~ 2~ 0]).
After the appearing of 9-th square counts will be [2~ 3~ 1], and after removing one row it will look like [1~ 2~ 0].
So the answer will be equal to 2.
Submitted Solution:
```
n,m = map(int,input().split(' '))
arr= list(map(int,input().split(' ')))
l=n*[0]
for i in range(0,m):
l[arr[i]-1]+=1
print(min(l))
``` | instruction | 0 | 102,667 | 23 | 205,334 |
Yes | output | 1 | 102,667 | 23 | 205,335 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a following process.
There is a platform with n columns. 1 × 1 squares are appearing one after another in some columns on this platform. If there are no squares in the column, a square will occupy the bottom row. Otherwise a square will appear at the top of the highest square of this column.
When all of the n columns have at least one square in them, the bottom row is being removed. You will receive 1 point for this, and all the squares left will fall down one row.
You task is to calculate the amount of points you will receive.
Input
The first line of input contain 2 integer numbers n and m (1 ≤ n, m ≤ 1000) — the length of the platform and the number of the squares.
The next line contain m integer numbers c_1, c_2, ..., c_m (1 ≤ c_i ≤ n) — column in which i-th square will appear.
Output
Print one integer — the amount of points you will receive.
Example
Input
3 9
1 1 2 2 2 3 1 2 3
Output
2
Note
In the sample case the answer will be equal to 2 because after the appearing of 6-th square will be removed one row (counts of the squares on the platform will look like [2~ 3~ 1], and after removing one row will be [1~ 2~ 0]).
After the appearing of 9-th square counts will be [2~ 3~ 1], and after removing one row it will look like [1~ 2~ 0].
So the answer will be equal to 2.
Submitted Solution:
```
# import sys
# sys.stdin=open("input1.in","r")
# sys.stdout=open("output2.out","w")
m,n=map(int,input().split())
Arr=[0]*(m)
L=list(map(int,input().split()))
for i in range(n):
Arr[L[i]-1]+=1
print(min(Arr))
``` | instruction | 0 | 102,668 | 23 | 205,336 |
Yes | output | 1 | 102,668 | 23 | 205,337 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a following process.
There is a platform with n columns. 1 × 1 squares are appearing one after another in some columns on this platform. If there are no squares in the column, a square will occupy the bottom row. Otherwise a square will appear at the top of the highest square of this column.
When all of the n columns have at least one square in them, the bottom row is being removed. You will receive 1 point for this, and all the squares left will fall down one row.
You task is to calculate the amount of points you will receive.
Input
The first line of input contain 2 integer numbers n and m (1 ≤ n, m ≤ 1000) — the length of the platform and the number of the squares.
The next line contain m integer numbers c_1, c_2, ..., c_m (1 ≤ c_i ≤ n) — column in which i-th square will appear.
Output
Print one integer — the amount of points you will receive.
Example
Input
3 9
1 1 2 2 2 3 1 2 3
Output
2
Note
In the sample case the answer will be equal to 2 because after the appearing of 6-th square will be removed one row (counts of the squares on the platform will look like [2~ 3~ 1], and after removing one row will be [1~ 2~ 0]).
After the appearing of 9-th square counts will be [2~ 3~ 1], and after removing one row it will look like [1~ 2~ 0].
So the answer will be equal to 2.
Submitted Solution:
```
n, m = [int(i) for i in input().split(" ")]
A = [int(i) for i in input().split(" ")]
cur = [0]*n
sc=0
for i in A:
cur[i-1] += i
if min(cur)>0:
sc+=1
k = min(cur)
cur = [i-k for i in cur]
print(sc)
``` | instruction | 0 | 102,669 | 23 | 205,338 |
No | output | 1 | 102,669 | 23 | 205,339 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a following process.
There is a platform with n columns. 1 × 1 squares are appearing one after another in some columns on this platform. If there are no squares in the column, a square will occupy the bottom row. Otherwise a square will appear at the top of the highest square of this column.
When all of the n columns have at least one square in them, the bottom row is being removed. You will receive 1 point for this, and all the squares left will fall down one row.
You task is to calculate the amount of points you will receive.
Input
The first line of input contain 2 integer numbers n and m (1 ≤ n, m ≤ 1000) — the length of the platform and the number of the squares.
The next line contain m integer numbers c_1, c_2, ..., c_m (1 ≤ c_i ≤ n) — column in which i-th square will appear.
Output
Print one integer — the amount of points you will receive.
Example
Input
3 9
1 1 2 2 2 3 1 2 3
Output
2
Note
In the sample case the answer will be equal to 2 because after the appearing of 6-th square will be removed one row (counts of the squares on the platform will look like [2~ 3~ 1], and after removing one row will be [1~ 2~ 0]).
After the appearing of 9-th square counts will be [2~ 3~ 1], and after removing one row it will look like [1~ 2~ 0].
So the answer will be equal to 2.
Submitted Solution:
```
x = input().split(' ')
n = int(x[0])
m = int(x[1])
c = input().split(' ')
def calc(n,m,c):
a = []
res = 0
try:
for i in range(n):
a.append(0)
for e in range(m):
a[int(c[e])-1] = 1
if (all(a)):
res += 1
a = [j-1 for j in a]
return(res)
except:
return('Invalid data')
res = calc(n,m,c)
print(res)
``` | instruction | 0 | 102,670 | 23 | 205,340 |
No | output | 1 | 102,670 | 23 | 205,341 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a following process.
There is a platform with n columns. 1 × 1 squares are appearing one after another in some columns on this platform. If there are no squares in the column, a square will occupy the bottom row. Otherwise a square will appear at the top of the highest square of this column.
When all of the n columns have at least one square in them, the bottom row is being removed. You will receive 1 point for this, and all the squares left will fall down one row.
You task is to calculate the amount of points you will receive.
Input
The first line of input contain 2 integer numbers n and m (1 ≤ n, m ≤ 1000) — the length of the platform and the number of the squares.
The next line contain m integer numbers c_1, c_2, ..., c_m (1 ≤ c_i ≤ n) — column in which i-th square will appear.
Output
Print one integer — the amount of points you will receive.
Example
Input
3 9
1 1 2 2 2 3 1 2 3
Output
2
Note
In the sample case the answer will be equal to 2 because after the appearing of 6-th square will be removed one row (counts of the squares on the platform will look like [2~ 3~ 1], and after removing one row will be [1~ 2~ 0]).
After the appearing of 9-th square counts will be [2~ 3~ 1], and after removing one row it will look like [1~ 2~ 0].
So the answer will be equal to 2.
Submitted Solution:
```
a = input()
arr = input().split()
arr = list(map(int, arr))
arr.sort()
cur = arr[0]
counter = 0
occur = []
for i in range(len(arr)):
if (arr[i] != cur):
cur = arr[i]
occur.append(counter)
counter = 0
counter += 1
occur.append(counter)
occur.sort()
if (occur[0] == 1):
print(0)
else:
print(occur[0])
``` | instruction | 0 | 102,671 | 23 | 205,342 |
No | output | 1 | 102,671 | 23 | 205,343 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a following process.
There is a platform with n columns. 1 × 1 squares are appearing one after another in some columns on this platform. If there are no squares in the column, a square will occupy the bottom row. Otherwise a square will appear at the top of the highest square of this column.
When all of the n columns have at least one square in them, the bottom row is being removed. You will receive 1 point for this, and all the squares left will fall down one row.
You task is to calculate the amount of points you will receive.
Input
The first line of input contain 2 integer numbers n and m (1 ≤ n, m ≤ 1000) — the length of the platform and the number of the squares.
The next line contain m integer numbers c_1, c_2, ..., c_m (1 ≤ c_i ≤ n) — column in which i-th square will appear.
Output
Print one integer — the amount of points you will receive.
Example
Input
3 9
1 1 2 2 2 3 1 2 3
Output
2
Note
In the sample case the answer will be equal to 2 because after the appearing of 6-th square will be removed one row (counts of the squares on the platform will look like [2~ 3~ 1], and after removing one row will be [1~ 2~ 0]).
After the appearing of 9-th square counts will be [2~ 3~ 1], and after removing one row it will look like [1~ 2~ 0].
So the answer will be equal to 2.
Submitted Solution:
```
#author: Harshad
n, m = map(int, input().split())
list_ = list(map(int, input().split()))
freq = [0]*(n+1)
for ele in list_:
freq[ele] += 1
res = n+1
for i in range(1, n+1):
res = min(res, freq[i])
print(res)
``` | instruction | 0 | 102,672 | 23 | 205,344 |
No | output | 1 | 102,672 | 23 | 205,345 |
Provide a correct Python 3 solution for this coding contest problem.
There is a n × n grid D where each cell contains either 1 or 0.
Your task is to create a program that takes the gird data as input and computes the greatest number of consecutive 1s in either vertical, horizontal, or diagonal direction.
For example, the consecutive 1s with greatest number in the figure below is circled by the dashed-line.
<image>
The size of the grid n is an integer where 2 ≤ n ≤ 255.
Input
The input is a sequence of datasets. The end of the input is indicated by a line containing one zero. Each dataset is formatted as follows:
n
D11 D12 ... D1n
D21 D22 ... D2n
.
.
Dn1 Dn2 ... Dnn
Output
For each dataset, print the greatest number of consecutive 1s.
Example
Input
5
00011
00101
01000
10101
00010
8
11000001
10110111
01100111
01111010
11111111
01011010
10100010
10000001
2
01
00
3
000
000
000
0
Output
4
8
1
0 | instruction | 0 | 102,819 | 23 | 205,638 |
"Correct Solution:
```
while 1:
n = int(input())
if n == 0:
break
L = [input() for i in range(n)]
ans = 0
for i in range(n):
cnt = 0
for j in range(n):
if L[i][j] == '1':
cnt += 1
else:
if ans < cnt:
ans = cnt
cnt = 0
if ans < cnt:
ans = cnt
cnt = 0
for j in range(n):
if L[j][i] == '1':
cnt += 1
else:
if ans < cnt:
ans = cnt
cnt = 0
if ans < cnt:
ans = cnt
for i in range(n):
cnt = 0
for j in range(n-i):
if L[i+j][j] == '1':
cnt += 1
else:
if ans < cnt:
ans = cnt
cnt = 0
if ans < cnt:
ans = cnt
cnt = 0
for j in range(n-i):
if L[j][i+j] == '1':
cnt += 1
else:
if ans < cnt:
ans = cnt
cnt = 0
if ans < cnt:
ans = cnt
cnt = 0
for j in range(i+1):
if L[i-j][j] == '1':
cnt += 1
else:
if ans < cnt:
ans = cnt
cnt = 0
if ans < cnt:
ans = cnt
cnt = 0
for j in range(n-i):
if L[i+j][n-1-j] == '1':
cnt += 1
else:
if ans < cnt:
ans = cnt
cnt = 0
if ans < cnt:
ans = cnt
print(ans)
``` | output | 1 | 102,819 | 23 | 205,639 |
Provide a correct Python 3 solution for this coding contest problem.
There is a n × n grid D where each cell contains either 1 or 0.
Your task is to create a program that takes the gird data as input and computes the greatest number of consecutive 1s in either vertical, horizontal, or diagonal direction.
For example, the consecutive 1s with greatest number in the figure below is circled by the dashed-line.
<image>
The size of the grid n is an integer where 2 ≤ n ≤ 255.
Input
The input is a sequence of datasets. The end of the input is indicated by a line containing one zero. Each dataset is formatted as follows:
n
D11 D12 ... D1n
D21 D22 ... D2n
.
.
Dn1 Dn2 ... Dnn
Output
For each dataset, print the greatest number of consecutive 1s.
Example
Input
5
00011
00101
01000
10101
00010
8
11000001
10110111
01100111
01111010
11111111
01011010
10100010
10000001
2
01
00
3
000
000
000
0
Output
4
8
1
0 | instruction | 0 | 102,820 | 23 | 205,640 |
"Correct Solution:
```
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0151&lang=jp
"""
import sys
from sys import stdin
input = stdin.readline
def main(args):
while True:
n = int(input())
if n == 0:
break
data = [list(map(int, list(input().strip('\n')))) for _ in range(n)]
# ???(North)??????(West)?????????(NorthWest)?????????(NorthEast) ????????????????????????1???????????£?¶???????????????????????????????
N = [[0] * n for _ in range(n)]
W = [[0] * n for _ in range(n)]
NW = [[0] * n for _ in range(n)]
NE = [[0] * n for _ in range(n)]
N_max = 0 # ???????????????????????§?????£?¶???????1????????§?????°
W_max = 0
NW_max = 0
NE_max = 0
for i in range(n):
for j in range(n):
c = data[i][j] # ????????????data[i][j]?????????????????§???????????§?????????????¨???¶
# North??????
ni = i - 1
if ni < 0:
N[i][j] = c
if N[i][j] > N_max:
N_max = N[i][j]
else:
if c == 1:
N[i][j] = N[ni][j] + 1
if N[i][j] > N_max:
N_max = N[i][j]
else:
N[i][j] = 0
# West??????
nj = j - 1
if nj < 0:
W[i][j] = c
if W[i][j] > W_max:
W_max = W[i][j]
else:
if c == 1:
W[i][j] = W[i][nj] + 1
if W[i][j] > W_max:
W_max = W[i][j]
else:
W[i][j] = 0
# North West??????
ni = i - 1
nj = j - 1
if ni < 0 or nj < 0:
NW[i][j] = c
if NW[i][j] > NW_max:
NW_max = NW[i][j]
else:
if c == 1:
NW[i][j] = NW[ni][nj] + 1
if NW[i][j] > NW_max:
NW_max = NW[i][j]
else:
NW[i][j] = 0
# North East??????
ni = i - 1
nj = j + 1
if ni < 0 or nj >= n:
NE[i][j] = c
if NE[i][j] > NE_max:
NE_max = NE[i][j]
else:
if c == 1:
NE[i][j] = NE[ni][nj] + 1
if NE[i][j] > NE_max:
NE_max = NE[i][j]
else:
NE[i][j] = 0
print(max(N_max, W_max, NW_max, NE_max))
if __name__ == '__main__':
main(sys.argv[1:])
``` | output | 1 | 102,820 | 23 | 205,641 |
Provide a correct Python 3 solution for this coding contest problem.
There is a n × n grid D where each cell contains either 1 or 0.
Your task is to create a program that takes the gird data as input and computes the greatest number of consecutive 1s in either vertical, horizontal, or diagonal direction.
For example, the consecutive 1s with greatest number in the figure below is circled by the dashed-line.
<image>
The size of the grid n is an integer where 2 ≤ n ≤ 255.
Input
The input is a sequence of datasets. The end of the input is indicated by a line containing one zero. Each dataset is formatted as follows:
n
D11 D12 ... D1n
D21 D22 ... D2n
.
.
Dn1 Dn2 ... Dnn
Output
For each dataset, print the greatest number of consecutive 1s.
Example
Input
5
00011
00101
01000
10101
00010
8
11000001
10110111
01100111
01111010
11111111
01011010
10100010
10000001
2
01
00
3
000
000
000
0
Output
4
8
1
0 | instruction | 0 | 102,821 | 23 | 205,642 |
"Correct Solution:
```
def scanning_area(grid, length, point_list, stride_x, stride_y):
area = [[0 for _ in range(length + 1)] for __ in range(length + 1)]
max_length = 0
for row, col in point_list:
if grid[row][col] == "1":
area[row + stride_y][col + stride_x] = area[row][col] + 1
max_length = max(max_length, area[row + stride_y][col + stride_x])
return max_length
def create_point_list(length):
points = []
for count, r in enumerate(range(length - 1, 0, -1), 1):
row = r
for col in range(0, count, 1):
points.append((row, col))
row += 1
for index in range(0, length):
points.append((index, index))
for lp in range(1, length):
row = 0
for col in range(lp, length):
points.append((row, col))
row += 1
return points
while True:
length = int(input())
if length == 0:
break
grid = [input() for _ in range(length)]
point_list = [[row, col] for row in range(length) for col in range(length)]
line_length1 = scanning_area(grid, length, point_list, 1, 0)
line_length2 = scanning_area(grid, length, point_list, 0, 1)
point_list = create_point_list(length)
line_length3 = scanning_area(grid, length, point_list, 1, 1)
point_list.reverse()
line_length4 = scanning_area(grid, length, point_list, -1, 1)
max_length = max(line_length1, line_length2, line_length3, line_length4)
print(max_length)
``` | output | 1 | 102,821 | 23 | 205,643 |
Provide a correct Python 3 solution for this coding contest problem.
There is a n × n grid D where each cell contains either 1 or 0.
Your task is to create a program that takes the gird data as input and computes the greatest number of consecutive 1s in either vertical, horizontal, or diagonal direction.
For example, the consecutive 1s with greatest number in the figure below is circled by the dashed-line.
<image>
The size of the grid n is an integer where 2 ≤ n ≤ 255.
Input
The input is a sequence of datasets. The end of the input is indicated by a line containing one zero. Each dataset is formatted as follows:
n
D11 D12 ... D1n
D21 D22 ... D2n
.
.
Dn1 Dn2 ... Dnn
Output
For each dataset, print the greatest number of consecutive 1s.
Example
Input
5
00011
00101
01000
10101
00010
8
11000001
10110111
01100111
01111010
11111111
01011010
10100010
10000001
2
01
00
3
000
000
000
0
Output
4
8
1
0 | instruction | 0 | 102,822 | 23 | 205,644 |
"Correct Solution:
```
# coding: utf-8
# Your code here!
while True:
n = int(input())
if n == 0:
break
table = [[0 for i in range(n)] for j in range(n)]
for l in range(n):
line = input()
for m in range(n):
table[l][m] = int(line[m])
t = 0
ans = 0
for i in range(n):
for j in range(n):
if table[i][j] > 0:
t += 1
else:
ans = max(t, ans)
t = 0
ans = max(t, ans)
t = 0
for i in range(n):
for j in range(n):
if table[j][i] > 0:
t += 1
else:
ans = max(t, ans)
t = 0
ans = max(t, ans)
t = 0
for c in range(n):
for j in range(c+1):
if table[c-j][j] > 0:
t += 1
else:
ans = max(t, ans)
t = 0
ans = max(t, ans)
t = 0
for c in range(n):
for j in range(c+1):
if table[n-1-(c-j)][n-1-j] > 0:
t += 1
else:
ans = max(t, ans)
t = 0
ans = max(t, ans)
t = 0
for c in range(n):
for j in range(c+1):
if table[n-1-(c-j)][j] > 0:
t += 1
else:
ans = max(t, ans)
t = 0
ans = max(t, ans)
t = 0
for c in range(n):
for j in range(c+1):
if table[c-j][n-1-j] > 0:
t += 1
else:
ans = max(t, ans)
t = 0
ans = max(t, ans)
t = 0
print(ans)
``` | output | 1 | 102,822 | 23 | 205,645 |
Provide a correct Python 3 solution for this coding contest problem.
There is a n × n grid D where each cell contains either 1 or 0.
Your task is to create a program that takes the gird data as input and computes the greatest number of consecutive 1s in either vertical, horizontal, or diagonal direction.
For example, the consecutive 1s with greatest number in the figure below is circled by the dashed-line.
<image>
The size of the grid n is an integer where 2 ≤ n ≤ 255.
Input
The input is a sequence of datasets. The end of the input is indicated by a line containing one zero. Each dataset is formatted as follows:
n
D11 D12 ... D1n
D21 D22 ... D2n
.
.
Dn1 Dn2 ... Dnn
Output
For each dataset, print the greatest number of consecutive 1s.
Example
Input
5
00011
00101
01000
10101
00010
8
11000001
10110111
01100111
01111010
11111111
01011010
10100010
10000001
2
01
00
3
000
000
000
0
Output
4
8
1
0 | instruction | 0 | 102,823 | 23 | 205,646 |
"Correct Solution:
```
# Aizu Problem 00151: Grid
#
import sys, math, os, bisect
# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
sys.stdin = open("sample-input.txt", "rt")
def grid_length(n, grid):
L = 0
for row in grid:
L = max(L, max([len(_) for _ in row.split('0')]))
for c in range(n):
col = ''.join([grid[r][c] for r in range(n)])
L = max(L, max([len(_) for _ in col.split('0')]))
for row in range(-n, 2 * n):
diag = ''.join([grid[row+c][c] for c in range(n) if 0 <= row + c < n])
L = max(L, max([len(_) for _ in diag.split('0')]))
diag = ''.join([grid[row-c][c] for c in range(n) if 0 <= row - c < n])
L = max(L, max([len(_) for _ in diag.split('0')]))
return L
while True:
n = int(input())
if n == 0:
break
grid = [input().strip() for _ in range(n)]
print(grid_length(n, grid))
``` | output | 1 | 102,823 | 23 | 205,647 |
Provide a correct Python 3 solution for this coding contest problem.
There is a n × n grid D where each cell contains either 1 or 0.
Your task is to create a program that takes the gird data as input and computes the greatest number of consecutive 1s in either vertical, horizontal, or diagonal direction.
For example, the consecutive 1s with greatest number in the figure below is circled by the dashed-line.
<image>
The size of the grid n is an integer where 2 ≤ n ≤ 255.
Input
The input is a sequence of datasets. The end of the input is indicated by a line containing one zero. Each dataset is formatted as follows:
n
D11 D12 ... D1n
D21 D22 ... D2n
.
.
Dn1 Dn2 ... Dnn
Output
For each dataset, print the greatest number of consecutive 1s.
Example
Input
5
00011
00101
01000
10101
00010
8
11000001
10110111
01100111
01111010
11111111
01011010
10100010
10000001
2
01
00
3
000
000
000
0
Output
4
8
1
0 | instruction | 0 | 102,824 | 23 | 205,648 |
"Correct Solution:
```
def main():
while True:
n = int(input())
if n == 0:
break
mp = ["0" + input() + "0" for _ in range(n)]
mp.insert(0, "0" * (n + 2))
mp.append("0" * (n + 2))
score = [[[0] * 4 for _ in range(n + 2)] for _ in range(n + 2)]
max_score = 0
for i in range(1, n + 1):
for j in range(1, n + 1):
if mp[i][j] == "1":
score[i][j][0] = score[i - 1][j][0] + 1
score[i][j][1] = score[i][j - 1][1] + 1
score[i][j][2] = score[i - 1][j - 1][2] + 1
score[i][j][3] = score[i - 1][j + 1][3] + 1
max_score = max(max_score, score[i][j][0], score[i][j][1], score[i][j][2], score[i][j][3])
else:
for k in range(4):
score[i][j][k] = 0
print(max_score)
main()
``` | output | 1 | 102,824 | 23 | 205,649 |
Provide a correct Python 3 solution for this coding contest problem.
There is a n × n grid D where each cell contains either 1 or 0.
Your task is to create a program that takes the gird data as input and computes the greatest number of consecutive 1s in either vertical, horizontal, or diagonal direction.
For example, the consecutive 1s with greatest number in the figure below is circled by the dashed-line.
<image>
The size of the grid n is an integer where 2 ≤ n ≤ 255.
Input
The input is a sequence of datasets. The end of the input is indicated by a line containing one zero. Each dataset is formatted as follows:
n
D11 D12 ... D1n
D21 D22 ... D2n
.
.
Dn1 Dn2 ... Dnn
Output
For each dataset, print the greatest number of consecutive 1s.
Example
Input
5
00011
00101
01000
10101
00010
8
11000001
10110111
01100111
01111010
11111111
01011010
10100010
10000001
2
01
00
3
000
000
000
0
Output
4
8
1
0 | instruction | 0 | 102,825 | 23 | 205,650 |
"Correct Solution:
```
def main():
while True:
n = int(input())
if n == 0:
break
mp = ["0" + input() + "0" for _ in range(n)]
mp.insert(0, "0" * (n + 2))
mp.append("0" * (n + 2))
score = [[[0] * 4 for _ in range(n + 2)] for _ in range(n + 2)]
max_score = 0
for i in range(1, n + 1):
for j in range(1, n + 1):
if mp[i][j] == "1":
score[i][j][0] = score[i - 1][j][0] + 1
score[i][j][1] = score[i][j - 1][1] + 1
score[i][j][2] = score[i - 1][j - 1][2] + 1
score[i][j][3] = score[i - 1][j + 1][3] + 1
max_score = max(max_score, score[i][j][0], score[i][j][1], score[i][j][2], score[i][j][3])
print(max_score)
main()
``` | output | 1 | 102,825 | 23 | 205,651 |
Provide a correct Python 3 solution for this coding contest problem.
There is a n × n grid D where each cell contains either 1 or 0.
Your task is to create a program that takes the gird data as input and computes the greatest number of consecutive 1s in either vertical, horizontal, or diagonal direction.
For example, the consecutive 1s with greatest number in the figure below is circled by the dashed-line.
<image>
The size of the grid n is an integer where 2 ≤ n ≤ 255.
Input
The input is a sequence of datasets. The end of the input is indicated by a line containing one zero. Each dataset is formatted as follows:
n
D11 D12 ... D1n
D21 D22 ... D2n
.
.
Dn1 Dn2 ... Dnn
Output
For each dataset, print the greatest number of consecutive 1s.
Example
Input
5
00011
00101
01000
10101
00010
8
11000001
10110111
01100111
01111010
11111111
01011010
10100010
10000001
2
01
00
3
000
000
000
0
Output
4
8
1
0 | instruction | 0 | 102,826 | 23 | 205,652 |
"Correct Solution:
```
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0151&lang=jp
"""
import sys
from sys import stdin
input = stdin.readline
def main(args):
while True:
n = int(input())
if n == 0:
break
data = [list(map(int, list(input().strip('\n')))) for _ in range(n)]
if n == 1: # ????????????1?????????????????????
print(data[0][0])
continue
# ???(North)??????(West)?????????(NorthWest)?????????(NorthEast) ????????????????????????1???????????£?¶???????????????????????????????
N = [[0] * n for _ in range(n)]
W = [[0] * n for _ in range(n)]
NW = [[0] * n for _ in range(n)]
NE = [[0] * n for _ in range(n)]
N_max = 0 # ???????????????????????§?????£?¶???????1????????§?????°
W_max = 0
NW_max = 0
NE_max = 0
for i in range(n):
for j in range(n):
c = data[i][j] # ????????????data[i][j]?????????????????§???????????§?????????????¨???¶
# North??????
ni = i - 1
if ni < 0:
N[i][j] = c
if N[i][j] > N_max:
N_max = N[i][j]
else:
if c == 1:
N[i][j] = N[ni][j] + 1
if N[i][j] > N_max:
N_max = N[i][j]
else:
N[i][j] = 0
# West??????
nj = j - 1
if nj < 0:
W[i][j] = c
if W[i][j] > W_max:
W_max = W[i][j]
else:
if c == 1:
W[i][j] = W[i][nj] + 1
if W[i][j] > W_max:
W_max = W[i][j]
else:
W[i][j] = 0
# North West??????
ni = i - 1
nj = j - 1
if ni < 0 or nj < 0:
NW[i][j] = c
if NW[i][j] > NW_max:
NW_max = NW[i][j]
else:
if c == 1:
NW[i][j] = NW[ni][nj] + 1
if NW[i][j] > NW_max:
NW_max = NW[i][j]
else:
NW[i][j] = 0
# North East??????
ni = i - 1
nj = j + 1
if ni < 0 or nj >= n:
NE[i][j] = c
if NE[i][j] > NE_max:
NE_max = NE[i][j]
else:
if c == 1:
NE[i][j] = NE[ni][nj] + 1
if NE[i][j] > NE_max:
NE_max = NE[i][j]
else:
NE[i][j] = 0
print(max(N_max, W_max, NW_max, NE_max))
if __name__ == '__main__':
main(sys.argv[1:])
``` | output | 1 | 102,826 | 23 | 205,653 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a n × n grid D where each cell contains either 1 or 0.
Your task is to create a program that takes the gird data as input and computes the greatest number of consecutive 1s in either vertical, horizontal, or diagonal direction.
For example, the consecutive 1s with greatest number in the figure below is circled by the dashed-line.
<image>
The size of the grid n is an integer where 2 ≤ n ≤ 255.
Input
The input is a sequence of datasets. The end of the input is indicated by a line containing one zero. Each dataset is formatted as follows:
n
D11 D12 ... D1n
D21 D22 ... D2n
.
.
Dn1 Dn2 ... Dnn
Output
For each dataset, print the greatest number of consecutive 1s.
Example
Input
5
00011
00101
01000
10101
00010
8
11000001
10110111
01100111
01111010
11111111
01011010
10100010
10000001
2
01
00
3
000
000
000
0
Output
4
8
1
0
Submitted Solution:
```
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0151&lang=jp
"""
import sys
from sys import stdin
input = stdin.readline
def main(args):
while True:
n = int(input())
if n == 0:
break
data = [list(map(int, list(input().strip()))) for _ in range(n)]
# ???(North)??????(West)?????????(NorthWest)?????????(NorthEast) ????????????????????????1???????????£?¶???????????????????????????????
N = [[0] * n for _ in range(n)]
W = [[0] * n for _ in range(n)]
NW = [[0] * n for _ in range(n)]
NE = [[0] * n for _ in range(n)]
N_max = 0 # ???????????????????????§?????£?¶???????1????????§?????°
W_max = 0
NW_max = 0
NE_max = 0
for i in range(n):
for j in range(n):
c = data[i][j] # ????????????data[i][j]?????????????????§???????????§?????????????¨???¶
# North??????
ni = i - 1
if ni < 0:
N[i][j] = c
else:
if c == 1:
N[i][j] = N[ni][j] + 1
if N[i][j] > N_max:
N_max = N[i][j]
else:
N[i][j] = 0
# West??????
nj = j - 1
if nj < 0:
W[i][j] = c
else:
if c == 1:
W[i][j] = W[i][nj] + 1
if W[i][j] > W_max:
W_max = W[i][j]
else:
W[i][j] = 0
# North West??????
ni = i - 1
nj = j - 1
if ni < 0 or nj < 0:
NW[i][j] = c
else:
if c == 1:
NW[i][j] = NW[ni][nj] + 1
if NW[i][j] > NW_max:
NW_max = NW[i][j]
else:
NW[i][j] = 0
# North East??????
ni = i - 1
nj = j + 1
if ni < 0 or nj >= n:
NE[i][j] = c
else:
if c == 1:
NE[i][j] = NE[ni][nj] + 1
if NE[i][j] > NE_max:
NE_max = NE[i][j]
else:
NE[i][j] = 0
print(max(N_max, W_max, NW_max, NE_max))
if __name__ == '__main__':
main(sys.argv[1:])
``` | instruction | 0 | 102,827 | 23 | 205,654 |
No | output | 1 | 102,827 | 23 | 205,655 |
Provide a correct Python 3 solution for this coding contest problem.
Example
Input
2 10 6
4 4 E
6 4 W
Output
2 | instruction | 0 | 102,845 | 23 | 205,690 |
"Correct Solution:
```
# from (x,y) to SW (0,0) by (-1,-1)
def raySW(x,y):
return x - y
n,w,d=map(int,input().split())
def toRange(xyf):
sx,sy,f = xyf
x=int(sx)
y=int(sy)
if f == 'S':
s = raySW(x,y)
t = w - raySW(w-x,y) # flip in X
return (s,t)
if f == 'E':
s = w - raySW(w-x,y) # flip in X
t = w + d + raySW(w-x,d-y) # flip in both X and Y
return (s,t)
if f == 'N':
s = w + d + raySW(w-x,d-y) # flip in both X and Y
t = w + d + w - raySW(x,d-y) # flip in Y
return (s,t)
if f == 'W':
s = w + d + w - raySW(x,d-y) # flip in Y
t = w + d + w + d + raySW(x,y)
return (s,t) if t <= w+d+w+d else (s-w-w-d-d,t-w-w-d-d)
exit(-1)
xyfs=[input().split() for _ in range(n)]
def swap(xy):
x,y=xy
return (y,x)
stso=list(map(swap,list(map(toRange,xyfs))))
sts=sorted(stso)
def contains(s,t,r):
if t <= r <= s: return True
if t <= r+d+d+w+w <= s: return True
if t <= r-d-d-w-w <= s: return True
return False
def findMin(sts):
c = 0
r = w+w+d+d+w+w+d+d+w+w+d+d
for s,t in sts:
if not contains(s,t,r): # put a new clock at t
c += 1
r = s
return c
# stupid concat?
mins=[findMin(sts[i:] + sts[:i]) for i in range(n)]
print(min(mins))
``` | output | 1 | 102,845 | 23 | 205,691 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The city park of IT City contains n east to west paths and n north to south paths. Each east to west path crosses each north to south path, so there are n2 intersections.
The city funded purchase of five benches. To make it seems that there are many benches it was decided to place them on as many paths as possible. Obviously this requirement is satisfied by the following scheme: each bench is placed on a cross of paths and each path contains not more than one bench.
Help the park administration count the number of ways to place the benches.
Input
The only line of the input contains one integer n (5 ≤ n ≤ 100) — the number of east to west paths and north to south paths.
Output
Output one integer — the number of ways to place the benches.
Examples
Input
5
Output
120
Submitted Solution:
```
import sys
def fact(n):
ret = 1
for x in range(1, n + 1):
ret = ret * x
return ret
def C(n, k):
return fact(n) // (fact(k) * (fact(n - k)))
n = int(input())
print(C(n, 5) * C(n, 5) * 120)
``` | instruction | 0 | 103,318 | 23 | 206,636 |
Yes | output | 1 | 103,318 | 23 | 206,637 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The city park of IT City contains n east to west paths and n north to south paths. Each east to west path crosses each north to south path, so there are n2 intersections.
The city funded purchase of five benches. To make it seems that there are many benches it was decided to place them on as many paths as possible. Obviously this requirement is satisfied by the following scheme: each bench is placed on a cross of paths and each path contains not more than one bench.
Help the park administration count the number of ways to place the benches.
Input
The only line of the input contains one integer n (5 ≤ n ≤ 100) — the number of east to west paths and north to south paths.
Output
Output one integer — the number of ways to place the benches.
Examples
Input
5
Output
120
Submitted Solution:
```
n = int(input())
print(n ** 2 * (n - 1) ** 2 * (n - 2) ** 2 * (n - 3) ** 2 * (n - 4) ** 2 // 120)
``` | instruction | 0 | 103,319 | 23 | 206,638 |
Yes | output | 1 | 103,319 | 23 | 206,639 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The city park of IT City contains n east to west paths and n north to south paths. Each east to west path crosses each north to south path, so there are n2 intersections.
The city funded purchase of five benches. To make it seems that there are many benches it was decided to place them on as many paths as possible. Obviously this requirement is satisfied by the following scheme: each bench is placed on a cross of paths and each path contains not more than one bench.
Help the park administration count the number of ways to place the benches.
Input
The only line of the input contains one integer n (5 ≤ n ≤ 100) — the number of east to west paths and north to south paths.
Output
Output one integer — the number of ways to place the benches.
Examples
Input
5
Output
120
Submitted Solution:
```
def fact(n):
return 1 if n < 2 else n * fact(n - 1)
def C(n, k):
return fact(n) // fact(n - k) // fact(k)
n = int(input())
print(C(n, 5) * n * (n - 1) * (n - 2) * (n - 3) * (n - 4))
``` | instruction | 0 | 103,320 | 23 | 206,640 |
Yes | output | 1 | 103,320 | 23 | 206,641 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The city park of IT City contains n east to west paths and n north to south paths. Each east to west path crosses each north to south path, so there are n2 intersections.
The city funded purchase of five benches. To make it seems that there are many benches it was decided to place them on as many paths as possible. Obviously this requirement is satisfied by the following scheme: each bench is placed on a cross of paths and each path contains not more than one bench.
Help the park administration count the number of ways to place the benches.
Input
The only line of the input contains one integer n (5 ≤ n ≤ 100) — the number of east to west paths and north to south paths.
Output
Output one integer — the number of ways to place the benches.
Examples
Input
5
Output
120
Submitted Solution:
```
from sys import stdin
import functools
import operator
num = int(stdin.readline())
def fac(n):
if n == 0:
return 1
return functools.reduce(operator.mul, range(1, n + 1))
def combinations(n, k):
return fac(n) // (fac(k) * fac(n - k))
print(combinations(num, 5) * fac(num) // fac(num - 5))
``` | instruction | 0 | 103,321 | 23 | 206,642 |
Yes | output | 1 | 103,321 | 23 | 206,643 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The city park of IT City contains n east to west paths and n north to south paths. Each east to west path crosses each north to south path, so there are n2 intersections.
The city funded purchase of five benches. To make it seems that there are many benches it was decided to place them on as many paths as possible. Obviously this requirement is satisfied by the following scheme: each bench is placed on a cross of paths and each path contains not more than one bench.
Help the park administration count the number of ways to place the benches.
Input
The only line of the input contains one integer n (5 ≤ n ≤ 100) — the number of east to west paths and north to south paths.
Output
Output one integer — the number of ways to place the benches.
Examples
Input
5
Output
120
Submitted Solution:
```
a=int(input())
print(a*(a-1)*(a-2)*(a-3)*(a-4))
``` | instruction | 0 | 103,322 | 23 | 206,644 |
No | output | 1 | 103,322 | 23 | 206,645 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The city park of IT City contains n east to west paths and n north to south paths. Each east to west path crosses each north to south path, so there are n2 intersections.
The city funded purchase of five benches. To make it seems that there are many benches it was decided to place them on as many paths as possible. Obviously this requirement is satisfied by the following scheme: each bench is placed on a cross of paths and each path contains not more than one bench.
Help the park administration count the number of ways to place the benches.
Input
The only line of the input contains one integer n (5 ≤ n ≤ 100) — the number of east to west paths and north to south paths.
Output
Output one integer — the number of ways to place the benches.
Examples
Input
5
Output
120
Submitted Solution:
```
import operator
import math
def c(n,k):
return int(math.factorial(n)*math.factorial(n)/(math.factorial(k)*math.factorial(n-k)*math.factorial(n-k)))
x=int(input())
print(c(x,5))
``` | instruction | 0 | 103,323 | 23 | 206,646 |
No | output | 1 | 103,323 | 23 | 206,647 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The city park of IT City contains n east to west paths and n north to south paths. Each east to west path crosses each north to south path, so there are n2 intersections.
The city funded purchase of five benches. To make it seems that there are many benches it was decided to place them on as many paths as possible. Obviously this requirement is satisfied by the following scheme: each bench is placed on a cross of paths and each path contains not more than one bench.
Help the park administration count the number of ways to place the benches.
Input
The only line of the input contains one integer n (5 ≤ n ≤ 100) — the number of east to west paths and north to south paths.
Output
Output one integer — the number of ways to place the benches.
Examples
Input
5
Output
120
Submitted Solution:
```
n=int(input())
res=1
for i in range(2,n+1,+1):
res*=i
if n==6:
res=res*n
print(int(res))
``` | instruction | 0 | 103,324 | 23 | 206,648 |
No | output | 1 | 103,324 | 23 | 206,649 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The city park of IT City contains n east to west paths and n north to south paths. Each east to west path crosses each north to south path, so there are n2 intersections.
The city funded purchase of five benches. To make it seems that there are many benches it was decided to place them on as many paths as possible. Obviously this requirement is satisfied by the following scheme: each bench is placed on a cross of paths and each path contains not more than one bench.
Help the park administration count the number of ways to place the benches.
Input
The only line of the input contains one integer n (5 ≤ n ≤ 100) — the number of east to west paths and north to south paths.
Output
Output one integer — the number of ways to place the benches.
Examples
Input
5
Output
120
Submitted Solution:
```
n=int(input())
T=1;
for i in range(1,n+1):
T=T*i
print(T)
``` | instruction | 0 | 103,325 | 23 | 206,650 |
No | output | 1 | 103,325 | 23 | 206,651 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Masha's little brother draw two points on a sheet of paper. After that, he draws some circles and gave the sheet to his sister.
Masha has just returned from geometry lesson so she instantly noticed some interesting facts about brother's drawing.
At first, the line going through two points, that brother drew, doesn't intersect or touch any circle.
Also, no two circles intersect or touch, and there is no pair of circles such that one circle is located inside another.
Moreover, for each circle, Masha drew a square of the minimal area with sides parallel axis such that this circle is located inside the square and noticed that there is no two squares intersect or touch and there is no pair of squares such that one square is located inside other.
Now Masha wants to draw circle of minimal possible radius such that it goes through two points that brother drew and doesn't intersect any other circle, but other circles can touch Masha's circle and can be located inside it.
It's guaranteed, that answer won't exceed 1012. It should be held for hacks as well.
Input
First line contains four integers x1, y1, x2, y2 ( - 105 ≤ x1, y1, x2, y2 ≤ 105) — coordinates of points that brother drew. First point has coordinates (x1, y1) and second point has coordinates (x2, y2). These two points are different.
The second line contains single integer n (1 ≤ n ≤ 105) — the number of circles that brother drew.
Next n lines contains descriptions of circles. Each line contains three integers xi, yi, ri ( - 105 ≤ xi, yi ≤ 105, 1 ≤ ri ≤ 105) describing circle with center (xi, yi) and radius ri.
Output
Output smallest real number, that it's possible to draw a circle with such radius through given points in such a way that it doesn't intersect other circles.
The output is considered correct if it has a relative or absolute error of at most 10 - 4.
Examples
Input
2 4 7 13
3
3 0 1
12 4 2
-4 14 2
Output
5.1478150705
Input
-2 3 10 -10
2
7 0 3
-5 -5 2
Output
9.1481831923
Note
<image> <image>
Submitted Solution:
```
# -*- coding: utf-8 -*-
import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
#import matplotlib.pyplot as plt
"""
created by shhuan at 2017/11/4 01:33
"""
x1, y1, x2, y2 = map(int, input().split())
n = int(input())
C = []
for i in range(n):
C.append([int(x) for x in input().split()])
def check(X, Y, R):
for x, y, r in C:
d = math.sqrt((X-x)**2 + (Y-y)**2)
if abs(R-r) < d < R+r:
return False
return True
hi = 10**12
lo = 0
L = math.sqrt((x1-x2)**2 + (y1-y2)**2) / 2
L2 = L**2
xm, ym = (x1+x2)/2, (y1+y2)/2
xm2, ym2 = xm**2, ym**2
vectv = x2-x1, y2-y1
dy, dx = y2-y1, x2-x1
c = dy/dx
c2 = c**2
c21 = c2+1
d = c*ym + xm
e = d - xm
e2 = e**2
f = (e*c+ym)/c21
f2 = f**2
rd = L2+ym2+e2
if check(xm, ym, L):
print(L)
exit(0)
XY = []
# plt.figure()
# fig, ax = plt.subplots()
# circles = []
while abs(hi-lo) > 10**-7:
R = lo + (hi-lo)/2
g = (R**2-rd)/c21 + f2
if g <= 0:
lo = R
continue
Y = math.sqrt(g)
Y1 = Y + f
Y2 = -Y + f
X1 = -c*Y1 + d
X2 = -c*Y2 + d
# if R < 20:
# circles.append(plt.Circle((X1, Y1), R, color='g'))
# circles.append(plt.Circle((X2, Y2), R, color='g'))
if check(X1, Y1, R):
XY = X1, Y1
hi = R
elif check(X2, Y2, R):
XY = X2, Y2
hi = R
else:
lo = R
print(lo)
# xs = [x for x, _, _ in C]
# ys = [y for _, y, _ in C]
# xlim = [min(xs), max(xs)]
# ylim = [min(ys), max(ys)]
# ll, lr = min(xlim[0], ylim[0], XY[0], XY[1])-R, max(xlim[1], ylim[1], XY[0], XY[1])+R
# ax.set_xlim([ll, lr])
# ax.set_ylim([ll, lr])
#
# for x, y, r in C:
# circles.append(plt.Circle((x, y), r, color='b'))
# plt.plot([x1, x2], [y1, y2])
#
# circles.append(plt.Circle(XY, R, color='r'))
# for c in circles:
# ax.add_artist(c)
# c.set_clip_box(ax.bbox)
# # c.set_edgecolor(color)
# c.set_facecolor("none") # "none" not None
# # c.set_alpha(alpha)
#
# plt.show()
``` | instruction | 0 | 103,399 | 23 | 206,798 |
No | output | 1 | 103,399 | 23 | 206,799 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Masha's little brother draw two points on a sheet of paper. After that, he draws some circles and gave the sheet to his sister.
Masha has just returned from geometry lesson so she instantly noticed some interesting facts about brother's drawing.
At first, the line going through two points, that brother drew, doesn't intersect or touch any circle.
Also, no two circles intersect or touch, and there is no pair of circles such that one circle is located inside another.
Moreover, for each circle, Masha drew a square of the minimal area with sides parallel axis such that this circle is located inside the square and noticed that there is no two squares intersect or touch and there is no pair of squares such that one square is located inside other.
Now Masha wants to draw circle of minimal possible radius such that it goes through two points that brother drew and doesn't intersect any other circle, but other circles can touch Masha's circle and can be located inside it.
It's guaranteed, that answer won't exceed 1012. It should be held for hacks as well.
Input
First line contains four integers x1, y1, x2, y2 ( - 105 ≤ x1, y1, x2, y2 ≤ 105) — coordinates of points that brother drew. First point has coordinates (x1, y1) and second point has coordinates (x2, y2). These two points are different.
The second line contains single integer n (1 ≤ n ≤ 105) — the number of circles that brother drew.
Next n lines contains descriptions of circles. Each line contains three integers xi, yi, ri ( - 105 ≤ xi, yi ≤ 105, 1 ≤ ri ≤ 105) describing circle with center (xi, yi) and radius ri.
Output
Output smallest real number, that it's possible to draw a circle with such radius through given points in such a way that it doesn't intersect other circles.
The output is considered correct if it has a relative or absolute error of at most 10 - 4.
Examples
Input
2 4 7 13
3
3 0 1
12 4 2
-4 14 2
Output
5.1478150705
Input
-2 3 10 -10
2
7 0 3
-5 -5 2
Output
9.1481831923
Note
<image> <image>
Submitted Solution:
```
import math
# from matplotlib.patches import Circle as pyC
# import matplotlib.pyplot as plt
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
def copy(self):
return Point(self.x, self.y)
def unitize(self):
return self.copy() / self.length()
def length(self):
return math.sqrt(self.x ** 2 + self.y ** 2)
def rotate(self, other):
return Point(self.x * other.x - self.y * other.y, self.x * other.y + self.y * other.x)
def __add__(self, other):
return Point(self.x + other.x, self.y + other.y)
def __sub__(self, other):
return Point(self.x - other.x, self.y - other.y)
def __mul__(self, other):
if isinstance(other, Point):
return self.x * other.x + self.y * other.y
else:
return Point(self.x * other, self.y * other)
def __truediv__(self, other):
return Point(self.x / other, self.y / other)
def __repr__(self):
return self.__str__()
def __str__(self):
return "<Point x: %s, y: %s>"%(self.x, self.y)
class Circle:
def __init__(self, p, r):
self.p = p
self.r = r
def read():
return (map(int, input().split()))
def checkCircle(circle):
for c in circles:
if c.r + circle.r - 0.0001 > (c.p - circle.p).length() > abs(c.r - circle.r) + 0.0001:
return False
return True
def generateCircle(circle):
M = (circle.p - O).rotate(Point(Du.y, Du.x))
_ML = M.x ** 2 + M.y ** 2
_CR = circle.r**2
_HH = P**2 - _CR - _ML
A = 4 * M.x**2 - 4 * _CR
B = 4 * M.x * _HH + 8 * M.x * _CR
C = _HH**2 - 4 * _CR * _ML
Delta = B**2 - 4 * A * C
_Delta = math.sqrt(Delta)
X1 = Point((-B + _Delta) / 2 / A, 0)
X2 = Point((-B - _Delta) / 2 / A, 0)
R1 = (Point(0, P) - X1).length()
R2 = (Point(0, P) - X2).length()
C1 = Circle(X1.rotate(Point(Du.y, -Du.x)) + O, R1)
C2 = Circle(X2.rotate(Point(Du.y, -Du.x)) + O, R2)
# print([P, Mt, M, (R1, R2)])
# print([X1, X2])
if R1 < R2:
return X1, C1, X2, C2
else:
return X2, C2, X1, C1
def main():
simple = Circle((p1 + p2) / 2, (p1 - p2).length() / 2)
if checkCircle(simple):
return simple.r
minR = None
for circle in circles:
c1, c2 = generateCircle(circle)
# print([c1.p.x, c1.p.y, c1.r])
# print([c2.p.x, c2.p.y, c2.r])
# ax.add_patch(pyC(xy = (c1.p.x, c1.p.y), radius = c1.r, alpha = 0.5))
# ax.add_patch(pyC(xy = (c2.p.x, c2.p.y), radius = c2.r, alpha = 0.5))
if minR is None or minR > c1.r:
if checkCircle(c1):
minR = c1.r
if minR is None or minR > c2.r:
if checkCircle(c2):
minR = c2.r
return minR
class Intervals:
def __init__(self):
self.l = []
# self.add(1, 5.5)
def add(self, a, b):
t = -1
tt = -1
flag = False
for i, s in enumerate(self.l):
if t == -1:
if s[0] > a:
t = i
flag = True
elif s[0] <= a < s[1] - DURATION:
t = i
if b <= s[1]:
return
if t != -1:
if s[0] + DURATION < b <= s[1]:
tt = i
else:
break
# print([a, b])
if t == -1:
self.l.append((a, b))
else:
k = (min(self.l[i][0], a), max(self.l[tt][1], b))
if tt == -1:
if flag:
k = (k[0], b)
else:
del self.l[t:]
else:
del self.l[t:tt + 1]
self.l.insert(t, k)
# print(self.l)
def min(self):
if len(self.l) == 0:
return 10**12
elif self.l[0][0] == 0:
return self.l[0][1]
else:
return self.l[0][0]
DURATION = 0.0001
(x1, y1, x2, y2) = read()
p1 = Point(x1, y1)
p2 = Point(x2, y2)
D = p1 - p2
P = D.length() / 2
O = (p1 + p2) / 2
Du = D.unitize()
# fig = plt.figure()
# ax = fig.add_subplot(111)
circles = []
lP = Intervals()
lN = Intervals()
(n, ) = read()
for i in range(n):
cx, cy, cr = read()
# ax.add_patch(pyC(xy = (cx, cy), radius = cr, alpha = 0.5))
c = Circle(Point(cx, cy), cr)
# circles.append(c)
x1, c1, x2, c2 = generateCircle(c)
if x1.x > 0:
if x2.x < 0:
lP.add(0, c1.r)
lN.add(0, c2.r)
else:
lP.add(c1.r, c2.r)
else:
if x2.x > 0:
lP.add(0, c2.r)
lN.add(0, c1.r)
else:
lN.add(c1.r, c2.r)
# print([cx, cy, cr, c1.r, c2.r])
# print(l.l)
# print([lP.min(), lN.min()])
lP.add(0, P)
lN.add(0, P)
print(min(lP.min(), lN.min()))
# x, y = 0, 0
# ax.plot(x, y, 'ro')
# plt.show()
``` | instruction | 0 | 103,400 | 23 | 206,800 |
No | output | 1 | 103,400 | 23 | 206,801 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Masha's little brother draw two points on a sheet of paper. After that, he draws some circles and gave the sheet to his sister.
Masha has just returned from geometry lesson so she instantly noticed some interesting facts about brother's drawing.
At first, the line going through two points, that brother drew, doesn't intersect or touch any circle.
Also, no two circles intersect or touch, and there is no pair of circles such that one circle is located inside another.
Moreover, for each circle, Masha drew a square of the minimal area with sides parallel axis such that this circle is located inside the square and noticed that there is no two squares intersect or touch and there is no pair of squares such that one square is located inside other.
Now Masha wants to draw circle of minimal possible radius such that it goes through two points that brother drew and doesn't intersect any other circle, but other circles can touch Masha's circle and can be located inside it.
It's guaranteed, that answer won't exceed 1012. It should be held for hacks as well.
Input
First line contains four integers x1, y1, x2, y2 ( - 105 ≤ x1, y1, x2, y2 ≤ 105) — coordinates of points that brother drew. First point has coordinates (x1, y1) and second point has coordinates (x2, y2). These two points are different.
The second line contains single integer n (1 ≤ n ≤ 105) — the number of circles that brother drew.
Next n lines contains descriptions of circles. Each line contains three integers xi, yi, ri ( - 105 ≤ xi, yi ≤ 105, 1 ≤ ri ≤ 105) describing circle with center (xi, yi) and radius ri.
Output
Output smallest real number, that it's possible to draw a circle with such radius through given points in such a way that it doesn't intersect other circles.
The output is considered correct if it has a relative or absolute error of at most 10 - 4.
Examples
Input
2 4 7 13
3
3 0 1
12 4 2
-4 14 2
Output
5.1478150705
Input
-2 3 10 -10
2
7 0 3
-5 -5 2
Output
9.1481831923
Note
<image> <image>
Submitted Solution:
```
# -*- coding: utf-8 -*-
import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
# import matplotlib.pyplot as plt
"""
created by shhuan at 2017/11/4 01:33
"""
x1, y1, x2, y2 = map(int, input().split())
n = int(input())
C = []
for i in range(n):
C.append([int(x) for x in input().split()])
def check(X, Y, R):
for x, y, r in C:
d = math.sqrt((X-x)**2 + (Y-y)**2)
if abs(R-r) < d - 1e-5 and d + 1e-5 < R+r:
return False, (x, y, r)
return True, None
def check2(c1, c2):
if not c2:
return True
x1, y1, r1 = c1
x2, y2, r2 = c2
d = math.sqrt((x1-x2)**2 +(y1-y2)**2)
return not (abs(r1-r2) < d < r1+r2)
hi = 10**12
lo = 0
L = math.sqrt((x1-x2)**2 + (y1-y2)**2) / 2
L2 = L**2
xm, ym = (x1+x2)/2, (y1+y2)/2
xm2, ym2 = xm**2, ym**2
vectv = x2-x1, y2-y1
dy, dx = y2-y1, x2-x1
c = dy/dx
c2 = c**2
c21 = c2+1
d = c*ym + xm
e = d - xm
e2 = e**2
f = (e*c+ym)/c21
f2 = f**2
rd = L2+ym2+e2
def cal(R):
g = (R ** 2 - rd) / c21 + f2
if abs(g) < 1e-6:
g = 0
if g < 0:
return []
Y = math.sqrt(g)
Y1 = Y + f
Y2 = -Y + f
X1 = -c * Y1 + d
X2 = -c * Y2 + d
return [(X1, Y1), (X2, Y2)]
R = L
while True:
XY = cal(R)
X1, Y1 = XY[0]
u1, c1 = check(X1, Y1, R)
if u1:
break
lo = R
hi = 1e12
while abs(lo-hi) > 1e-6:
r = lo + (hi-lo) / 2
xy = cal(r)
X1, Y1 = xy[0]
if check2((X1, Y1, r), c1):
hi = r
else:
lo = r
if abs(R-lo) < 1e-6:
break
R = lo
ans = R
R = L
while True:
XY = cal(R)
X2, Y2 = XY[1]
u2, c2 = check(X2, Y2, R)
if u2:
break
lo = R
hi = 1e12
while abs(lo-hi) > 1e-6:
r = lo + (hi-lo) / 2
xy = cal(r)
X2, Y2 = xy[1]
if check2((X2, Y2, r), c2):
hi = r
else:
lo = r
if abs(R-lo) < 1e-6:
break
R = lo
ans = min(ans, R)
R = ans
print(ans)
# XY = cal(ans)
#
# plt.figure()
# fig, ax = plt.subplots()
# circles = []
# xs = [x for x, _, _ in C]
# ys = [y for _, y, _ in C]
# xlim = [min(xs), max(xs)]
# ylim = [min(ys), max(ys)]
# ll, lr = min(xlim[0], ylim[0])-R, max(xlim[1], ylim[1])+R
# ax.set_xlim([ll, lr])
# ax.set_ylim([ll, lr])
#
# for x, y, r in C:
# circles.append(plt.Circle((x, y), r, color='b'))
#
#
# plt.plot([x1, x2], [y1, y2])
#
# circles.append(plt.Circle(XY[0], R, color='r'))
# circles.append(plt.Circle(XY[1], R, color='r'))
# for c in circles:
# ax.add_artist(c)
# c.set_clip_box(ax.bbox)
# c.set_facecolor("none") # "none" not None
#
# plt.show()
``` | instruction | 0 | 103,401 | 23 | 206,802 |
No | output | 1 | 103,401 | 23 | 206,803 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Masha's little brother draw two points on a sheet of paper. After that, he draws some circles and gave the sheet to his sister.
Masha has just returned from geometry lesson so she instantly noticed some interesting facts about brother's drawing.
At first, the line going through two points, that brother drew, doesn't intersect or touch any circle.
Also, no two circles intersect or touch, and there is no pair of circles such that one circle is located inside another.
Moreover, for each circle, Masha drew a square of the minimal area with sides parallel axis such that this circle is located inside the square and noticed that there is no two squares intersect or touch and there is no pair of squares such that one square is located inside other.
Now Masha wants to draw circle of minimal possible radius such that it goes through two points that brother drew and doesn't intersect any other circle, but other circles can touch Masha's circle and can be located inside it.
It's guaranteed, that answer won't exceed 1012. It should be held for hacks as well.
Input
First line contains four integers x1, y1, x2, y2 ( - 105 ≤ x1, y1, x2, y2 ≤ 105) — coordinates of points that brother drew. First point has coordinates (x1, y1) and second point has coordinates (x2, y2). These two points are different.
The second line contains single integer n (1 ≤ n ≤ 105) — the number of circles that brother drew.
Next n lines contains descriptions of circles. Each line contains three integers xi, yi, ri ( - 105 ≤ xi, yi ≤ 105, 1 ≤ ri ≤ 105) describing circle with center (xi, yi) and radius ri.
Output
Output smallest real number, that it's possible to draw a circle with such radius through given points in such a way that it doesn't intersect other circles.
The output is considered correct if it has a relative or absolute error of at most 10 - 4.
Examples
Input
2 4 7 13
3
3 0 1
12 4 2
-4 14 2
Output
5.1478150705
Input
-2 3 10 -10
2
7 0 3
-5 -5 2
Output
9.1481831923
Note
<image> <image>
Submitted Solution:
```
import math
# from matplotlib.patches import Circle as pyC
# import matplotlib.pyplot as plt
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
def copy(self):
return Point(self.x, self.y)
def unitize(self):
return self.copy() / self.length()
def length(self):
return math.sqrt(self.x ** 2 + self.y ** 2)
def rotate(self, other):
return Point(self.x * other.x - self.y * other.y, self.x * other.y + self.y * other.x)
def __add__(self, other):
return Point(self.x + other.x, self.y + other.y)
def __sub__(self, other):
return Point(self.x - other.x, self.y - other.y)
def __mul__(self, other):
if isinstance(other, Point):
return self.x * other.x + self.y * other.y
else:
return Point(self.x * other, self.y * other)
def __truediv__(self, other):
return Point(self.x / other, self.y / other)
def __repr__(self):
return self.__str__()
def __str__(self):
return "<Point x: %s, y: %s>"%(self.x, self.y)
class Circle:
def __init__(self, p, r):
self.p = p
self.r = r
def read():
return (map(int, input().split()))
def checkCircle(circle):
for c in circles:
if c.r + circle.r - 0.0001 > (c.p - circle.p).length() > abs(c.r - circle.r) + 0.0001:
return False
return True
def generateCircle(circle):
M = (circle.p - O).rotate(Point(Du.y, Du.x))
_ML = M.x ** 2 + M.y ** 2
_CR = circle.r**2
_HH = P**2 - _CR - _ML
A = 4 * M.x**2 - 4 * _CR
B = 4 * M.x * _HH + 8 * M.x * _CR
C = _HH**2 - 4 * _CR * _ML
Delta = B**2 - 4 * A * C
_Delta = math.sqrt(Delta)
X1 = Point((-B + _Delta) / 2 / A, 0)
X2 = Point((-B - _Delta) / 2 / A, 0)
R1 = (Point(0, P) - X1).length()
R2 = (Point(0, P) - X2).length()
C1 = Circle(X1.rotate(Point(Du.y, -Du.x)) + O, R1)
C2 = Circle(X2.rotate(Point(Du.y, -Du.x)) + O, R2)
# print([P, Mt, M, (R1, R2)])
# print([X1, X2])
if R1 < R2:
return X1, C1, X2, C2
else:
return X2, C2, X1, C1
def main():
simple = Circle((p1 + p2) / 2, (p1 - p2).length() / 2)
if checkCircle(simple):
return simple.r
minR = None
for circle in circles:
c1, c2 = generateCircle(circle)
# print([c1.p.x, c1.p.y, c1.r])
# print([c2.p.x, c2.p.y, c2.r])
# ax.add_patch(pyC(xy = (c1.p.x, c1.p.y), radius = c1.r, alpha = 0.5))
# ax.add_patch(pyC(xy = (c2.p.x, c2.p.y), radius = c2.r, alpha = 0.5))
if minR is None or minR > c1.r:
if checkCircle(c1):
minR = c1.r
if minR is None or minR > c2.r:
if checkCircle(c2):
minR = c2.r
return minR
class Intervals:
def __init__(self):
self.l = []
# self.add(1, 5.5)
def add(self, a, b):
t = -1
tt = -1
flag = False
for i, s in enumerate(self.l):
if t == -1:
if s[0] > a:
t = i
flag = True
elif s[0] <= a < s[1] - DURATION:
t = i
if b <= s[1]:
return
if t != -1:
if s[0] + DURATION < b:
tt = i
elif s[0] >= b:
break
# print([a, b])
if t == -1:
self.l.append((a, b))
else:
k = (min(self.l[i][0], a), max(self.l[tt][1], b))
if tt == -1:
if flag:
k = (k[0], b)
else:
del self.l[t:]
else:
del self.l[t:tt + 1]
self.l.insert(t, k)
# print(self.l)
def min(self):
if len(self.l) == 0:
return 10**12
elif self.l[0][0] == 0:
return self.l[0][1]
else:
return self.l[0][0]
DURATION = 0.0001
(x1, y1, x2, y2) = read()
p1 = Point(x1, y1)
p2 = Point(x2, y2)
D = p1 - p2
P = D.length() / 2
O = (p1 + p2) / 2
Du = D.unitize()
# fig = plt.figure()
# ax = fig.add_subplot(111)
circles = []
lP = Intervals()
lN = Intervals()
(n, ) = read()
for i in range(n):
cx, cy, cr = read()
# ax.add_patch(pyC(xy = (cx, cy), radius = cr, alpha = 0.5))
c = Circle(Point(cx, cy), cr)
# circles.append(c)
x1, c1, x2, c2 = generateCircle(c)
if x1.x > 0:
if x2.x < 0:
lP.add(0, c1.r)
lN.add(0, c2.r)
else:
lP.add(c1.r, c2.r)
else:
if x2.x > 0:
lP.add(0, c2.r)
lN.add(0, c1.r)
else:
lN.add(c1.r, c2.r)
# print([cx, cy, cr, c1.r, c2.r])
# print(l.l)
# print([lP.min(), lN.min()])
lP.add(0, P)
lN.add(0, P)
print(min(lP.min(), lN.min()))
# x, y = 0, 0
# ax.plot(x, y, 'ro')
# plt.show()
``` | instruction | 0 | 103,402 | 23 | 206,804 |
No | output | 1 | 103,402 | 23 | 206,805 |
Provide a correct Python 3 solution for this coding contest problem.
An open-top box having a square bottom is placed on the floor. You see a number of needles vertically planted on its bottom.
You want to place a largest possible spheric balloon touching the box bottom, interfering with none of the side walls nor the needles.
Java Specific: Submitted Java programs may not use "java.awt.geom.Area". You may use it for your debugging purposes.
Figure H.1 shows an example of a box with needles and the corresponding largest spheric balloon. It corresponds to the first dataset of the sample input below.
<image>
Figure H.1. The upper shows an example layout and the lower shows the largest spheric balloon that can be placed.
Input
The input is a sequence of datasets. Each dataset is formatted as follows.
n w
x1 y1 h1
:
xn yn hn
The first line of a dataset contains two positive integers, n and w, separated by a space. n represents the number of needles, and w represents the height of the side walls.
The bottom of the box is a 100 × 100 square. The corners of the bottom face are placed at positions (0, 0, 0), (0, 100, 0), (100, 100, 0), and (100, 0, 0).
Each of the n lines following the first line contains three integers, xi, yi, and hi. (xi, yi, 0) and hi represent the base position and the height of the i-th needle. No two needles stand at the same position.
You can assume that 1 ≤ n ≤ 10, 10 ≤ w ≤ 200, 0 < xi < 100, 0 < yi < 100 and 1 ≤ hi ≤ 200. You can ignore the thicknesses of the needles and the walls.
The end of the input is indicated by a line of two zeros. The number of datasets does not exceed 1000.
Output
For each dataset, output a single line containing the maximum radius of a balloon that can touch the bottom of the box without interfering with the side walls or the needles. The output should not contain an error greater than 0.0001.
Example
Input
5 16
70 66 40
38 52 20
40 35 10
70 30 10
20 60 10
1 100
54 75 200
1 10
90 10 1
1 11
54 75 200
3 10
53 60 1
61 38 1
45 48 1
4 10
20 20 10
20 80 10
80 20 10
80 80 10
0 0
Output
26.00000
39.00000
130.00000
49.49777
85.00000
95.00000 | instruction | 0 | 103,616 | 23 | 207,232 |
"Correct Solution:
```
from math import sqrt
def getcircle(nee, R): #針にぶつかる範囲の円
(x, y, h) = nee
if R <= h:
return (x, y, R)
r = sqrt(R**2 - (R-h)**2)
return (x, y, r)
def crosscircle(c1, c2): #円の交点
(x1, y1, r1) = c1
(x2, y2, r2) = c2
if (x1-x2)**2 + (y1-y2)**2 > (r1+r2)**2:
return ()
elif x1 == x2 and y1 == y2:
return ()
elif (x1-x2)**2 + (y1-y2)**2 == (r1+r2)**2:
x = (x1*r2+x2*r1)/(r1+r2)
y = (y1*r2+y2*r1)/(r1+r2)
return ((x, y),)
elif y1 == y2:
x = (r1**2-r2**2-x1**2+x2**2)/(2*(x2-x1))
if y1**2-(y1**2-r1**2+(x-x1)**2) >= 0:
yans1 = y1+sqrt(y1**2-(y1**2-r1**2+(x-x1)**2))
yans2 = y1-sqrt(y1**2-(y1**2-r1**2+(x-x1)**2))
return ((x, yans1), (x, yans2))
else:
return ()
elif x1 == x2:
y = (r1**2-r2**2-y1**2+y2**2)/(2*(y2-y1))
if x1**2-(x1**2-r1**2+(y-y1)**2) >= 0:
xans1 = x1+sqrt(x1**2-(x1**2-r1**2+(y-y1)**2))
xans2 = x1-sqrt(x1**2-(x1**2-r1**2+(y-y1)**2))
return ((xans1, y), (xans2, y))
else:
return ()
else:
A = ((x1-x2)/(y1-y2))**2 + 1
B = (x1-x2)*(r1**2-r2**2-x1**2+x2**2+(y1-y2)**2)/(y1-y2)**2 - 2*x1
C = ((r1**2-r2**2-x1**2+x2**2+(y1-y2)**2)/(2*(y1-y2)))**2 + x1**2 - r1**2
if B**2 - 4*A*C >= 0:
xans1 = (-B+sqrt(B**2-4*A*C))/(2*A)
xans2 = (-B-sqrt(B**2-4*A*C))/(2*A)
yans1 = -((r1**2-r2**2-x1**2+x2**2-y1**2+y2**2))/(2*(y1-y2))-xans1*(x1-x2)/(y1-y2)
yans2 = -((r1**2-r2**2-x1**2+x2**2-y1**2+y2**2))/(2*(y1-y2))-xans2*(x1-x2)/(y1-y2)
return ((xans1, yans1), (xans2, yans2))
else:
return ()
while True:
n, w = map(int, input().split())
if n == w == 0:
break
nees = [tuple(map(float, input().split())) for i in range(n)]
eps = 0.000001
U = 130
L = 0
while U - L > 0.0001:
ok = False
R = (U+L)/2
cirs = []
points = []
if R > w:
l = sqrt(R**2 - (R-w)**2) #球が壁にぶつからない範囲の正方形(l<=x<=100-l, l<=y<=100-l)
else:
l = R
if l >= 100-l:
U = R
continue
for nee in nees:
c = getcircle(nee, R)
cirs.append(c)
for c in cirs: #正方形と円の交点をリストに入れる
(x, y, r) = c
if abs(l-x) <= r:
if l <= y+sqrt(r**2-(x-l)**2) <= 100-l:
points.append((l,y+sqrt(r**2-(x-l)**2)))
if l <= y-sqrt(r**2-(x-l)**2) <= 100-l:
points.append((l,y-sqrt(r**2-(x-l)**2)))
if abs(l-y) <= r:
if l <= x+sqrt(r**2-(y-l)**2) <= 100-l:
points.append((x+sqrt(r**2-(y-l)**2),y))
if l <= x-sqrt(r**2-(y-l)**2) <= 100-l:
points.append((x-sqrt(r**2-(y-l)**2),y))
if abs(100-l-x) <= r:
if l <= y+sqrt(r**2-(x+l-100)**2) <= 100-l:
points.append((100-l,y+sqrt(r**2-(x+l-100)**2)))
if l <= y-sqrt(r**2-(x+l-100)**2) <= 100-l:
points.append((100-l,y-sqrt(r**2-(x+l-100)**2)))
if abs(100-l-y) <= r:
if l <= x+sqrt(r**2-(100-l-y)**2) <= 100-l:
points.append((x+sqrt(r**2-(100-l-y)**2),y))
if l <= x-sqrt(r**2-(100-l-y)**2) <= 100-l:
points.append((x-sqrt(r**2-(100-l-y)**2),y))
for i in range(n): #円と円の交点をリストに入れる
if n != 1 and i != n-1:
for j in range(i+1, n):
p = crosscircle(cirs[i], cirs[j])
if p == ():
continue
for a in p:
if l <= a[0] <= 100-l and l <= a[1] <= 100-l:
points.append(a)
points.append((l,l)) #正方形の四隅をリストに入れる
points.append((100-l,l))
points.append((l,100-l))
points.append((100-l,100-l))
for p in points: #リスト内の点が円の内部にないか判定する
if not l <= p[0] <=100-l:
continue
if not l <= p[1] <=100-l:
continue
pok = True
for c in cirs:
if (p[0]-c[0])**2 + (p[1]-c[1])**2 <= (c[2]-eps)**2:
pok = False
break
if pok:
ok = True
break
if ok:
L = R
else:
U = R
print(R)
``` | output | 1 | 103,616 | 23 | 207,233 |
Provide a correct Python 3 solution for this coding contest problem.
An open-top box having a square bottom is placed on the floor. You see a number of needles vertically planted on its bottom.
You want to place a largest possible spheric balloon touching the box bottom, interfering with none of the side walls nor the needles.
Java Specific: Submitted Java programs may not use "java.awt.geom.Area". You may use it for your debugging purposes.
Figure H.1 shows an example of a box with needles and the corresponding largest spheric balloon. It corresponds to the first dataset of the sample input below.
<image>
Figure H.1. The upper shows an example layout and the lower shows the largest spheric balloon that can be placed.
Input
The input is a sequence of datasets. Each dataset is formatted as follows.
n w
x1 y1 h1
:
xn yn hn
The first line of a dataset contains two positive integers, n and w, separated by a space. n represents the number of needles, and w represents the height of the side walls.
The bottom of the box is a 100 × 100 square. The corners of the bottom face are placed at positions (0, 0, 0), (0, 100, 0), (100, 100, 0), and (100, 0, 0).
Each of the n lines following the first line contains three integers, xi, yi, and hi. (xi, yi, 0) and hi represent the base position and the height of the i-th needle. No two needles stand at the same position.
You can assume that 1 ≤ n ≤ 10, 10 ≤ w ≤ 200, 0 < xi < 100, 0 < yi < 100 and 1 ≤ hi ≤ 200. You can ignore the thicknesses of the needles and the walls.
The end of the input is indicated by a line of two zeros. The number of datasets does not exceed 1000.
Output
For each dataset, output a single line containing the maximum radius of a balloon that can touch the bottom of the box without interfering with the side walls or the needles. The output should not contain an error greater than 0.0001.
Example
Input
5 16
70 66 40
38 52 20
40 35 10
70 30 10
20 60 10
1 100
54 75 200
1 10
90 10 1
1 11
54 75 200
3 10
53 60 1
61 38 1
45 48 1
4 10
20 20 10
20 80 10
80 20 10
80 80 10
0 0
Output
26.00000
39.00000
130.00000
49.49777
85.00000
95.00000 | instruction | 0 | 103,617 | 23 | 207,234 |
"Correct Solution:
```
from math import sqrt
def get_cross_point_of_circles(x1, y1, r1, x2, y2, r2):
rr0 = (x2 - x1) ** 2 + (y2 - y1) ** 2
xd = x2 - x1
yd = y2 - y1
rr1 = r1 ** 2
rr2 = r2 ** 2
cv = (rr0 + rr1 - rr2)
sv2 = 4 * rr0 * rr1 - cv ** 2
if sv2 < 0:
return None
sv = sqrt(sv2)
return (
(x1 + (cv * xd - sv * yd) / (2. * rr0), y1 + (cv * yd + sv * xd) / (2. * rr0)),
(x1 + (cv * xd + sv * yd) / (2. * rr0), y1 + (cv * yd - sv * xd) / (2. * rr0)),
)
def get_solution_of_quadratic(a, b, c):
if b**2 >= 4*a*c:
return {(-b + sqrt(b**2 - 4*a*c))/(2*a), (-b - sqrt(b**2 - 4*a*c))/(2*a)}
else:
return {}
def get_nearest_wall(x, y):
if y <= x:
if y <= 100 - x:
return x, 0
else:
return 100, y
else:
if y <= 100 - x:
return 0, y
else:
return x, 100
while True:
n, w = map(int, input().split())
if n == w == 0:
break
xyh = [tuple(map(float, input().split())) for _ in range(n)]
# 目いっぱいでもOKか
m = (2500+w**2) / (2*w) if w < 50 else 50
P = (50, 50, m)
flag0 = True
for k in range(n):
if (50 - xyh[k][0]) ** 2 + (50 - xyh[k][1]) ** 2 + max(.0, m - xyh[k][2]) ** 2 <= m ** 2:
flag0 = False
if flag0:
print(m)
continue
l = 0
r = 130
while abs(r - l) >= 0.0001:
m = (l + r) / 2
flag = False
for i in range(n):
if n != 1 and i != n - 1:
# needle二つで抑えられる点
for j in range(i + 1, n):
h1 = min(xyh[i][2], m)
h2 = min(xyh[j][2], m)
P = get_cross_point_of_circles(xyh[i][0], xyh[i][1], sqrt(2 * h1 * m - h1 ** 2),
xyh[j][0], xyh[j][1], sqrt(2 * h2 * m - h2 ** 2))
if P is None:
continue
for p in P:
if 0 <= p[0] <= 100 and 0 <= p[1] <= 100:
wx, wy = get_nearest_wall(p[0], p[1])
if (wx - p[0]) ** 2 + (wy - p[1]) ** 2 + max(0, m - w) ** 2 >= m ** 2:
flag2 = True
for k in range(n):
if k != i and k != j:
if (p[0] - xyh[k][0]) ** 2 + (p[1] - xyh[k][1]) ** 2 \
+ max(.0, m - xyh[k][2]) ** 2 <= m ** 2:
flag2 = False
if flag2:
flag = True
# needle一つで抑える
x, y, h = xyh[i]
h = min(h, m)
S1 = get_solution_of_quadratic(2, -2 * (x + y), x ** 2 + y ** 2 - 2 * m * h + h ** 2)
S2 = get_solution_of_quadratic(2, -2 * (x + 100 - y), x ** 2 + (100 - y) ** 2 - 2 * m * h + h ** 2)
for s in S1:
if 0 <= s <= 100:
wx, wy = get_nearest_wall(s, s)
if (wx - s) ** 2 + (wy - s) ** 2 + max(0, m - w) ** 2 >= m ** 2:
flag2 = True
for k in range(n):
if k != i:
if (s - xyh[k][0]) ** 2 + (s - xyh[k][1]) ** 2 \
+ max(.0, m - xyh[k][2]) ** 2 <= m ** 2:
flag2 = False
if flag2:
flag = True
for s in S2:
if 0 <= s <= 100:
wx, wy = get_nearest_wall(s, 100 - s)
if (wx - s) ** 2 + (wy - (100 - s)) ** 2 + max(0, m - w) ** 2 >= m ** 2:
flag2 = True
for k in range(n):
if k != i:
if (s - xyh[k][0]) ** 2 + ((100 - s) - xyh[k][1]) ** 2 \
+ max(.0, m - xyh[k][2]) ** 2 <= m ** 2:
flag2 = False
if flag2:
flag = True
if flag:
l = m
else:
r = m
print(m)
``` | output | 1 | 103,617 | 23 | 207,235 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Consider a table of size n × m, initially fully white. Rows are numbered 1 through n from top to bottom, columns 1 through m from left to right. Some square inside the table with odd side length was painted black. Find the center of this square.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 115) — the number of rows and the number of columns in the table.
The i-th of the next n lines contains a string of m characters s_{i1} s_{i2} … s_{im} (s_{ij} is 'W' for white cells and 'B' for black cells), describing the i-th row of the table.
Output
Output two integers r and c (1 ≤ r ≤ n, 1 ≤ c ≤ m) separated by a space — the row and column numbers of the center of the black square.
Examples
Input
5 6
WWBBBW
WWBBBW
WWBBBW
WWWWWW
WWWWWW
Output
2 4
Input
3 3
WWW
BWW
WWW
Output
2 1
Submitted Solution:
```
[n, m] = [int(x) for x in input().split()]; L = []; I = []; s = 0
for i in range(n):
r = input()
L.append(r)
if 'B' in r: s += 1; I.append(i)
print(min(I)+(len(I)//2)+1, L[min(I)].index('B')+(len(I)//2)+1)
``` | instruction | 0 | 103,689 | 23 | 207,378 |
Yes | output | 1 | 103,689 | 23 | 207,379 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Consider a table of size n × m, initially fully white. Rows are numbered 1 through n from top to bottom, columns 1 through m from left to right. Some square inside the table with odd side length was painted black. Find the center of this square.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 115) — the number of rows and the number of columns in the table.
The i-th of the next n lines contains a string of m characters s_{i1} s_{i2} … s_{im} (s_{ij} is 'W' for white cells and 'B' for black cells), describing the i-th row of the table.
Output
Output two integers r and c (1 ≤ r ≤ n, 1 ≤ c ≤ m) separated by a space — the row and column numbers of the center of the black square.
Examples
Input
5 6
WWBBBW
WWBBBW
WWBBBW
WWWWWW
WWWWWW
Output
2 4
Input
3 3
WWW
BWW
WWW
Output
2 1
Submitted Solution:
```
p=0
z=0
r,c=0,0
a=[]
n,m=map(int,input().split())
for i in range(n):
a.append(input())
for i in range(n):
for k in range(m):
if a[i][k]=='B':
p = 1
for x in range(k,m):
if a[i][x]=='B':
z+=1
r = int(i + 1 + ((z - 1) / 2))
c = int(k + 1 + ((z - 1) / 2))
break
if p==1:
break
print(r,c)
``` | instruction | 0 | 103,690 | 23 | 207,380 |
Yes | output | 1 | 103,690 | 23 | 207,381 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Consider a table of size n × m, initially fully white. Rows are numbered 1 through n from top to bottom, columns 1 through m from left to right. Some square inside the table with odd side length was painted black. Find the center of this square.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 115) — the number of rows and the number of columns in the table.
The i-th of the next n lines contains a string of m characters s_{i1} s_{i2} … s_{im} (s_{ij} is 'W' for white cells and 'B' for black cells), describing the i-th row of the table.
Output
Output two integers r and c (1 ≤ r ≤ n, 1 ≤ c ≤ m) separated by a space — the row and column numbers of the center of the black square.
Examples
Input
5 6
WWBBBW
WWBBBW
WWBBBW
WWWWWW
WWWWWW
Output
2 4
Input
3 3
WWW
BWW
WWW
Output
2 1
Submitted Solution:
```
n, m = map(int, input().split())
for i in range(n):
A = input()
if 'B' in A:
p = A.find('B') + 1
l = A.count('B')
print(i + 1 + (l - 1) // 2, p + (l - 1) // 2)
exit()
``` | instruction | 0 | 103,691 | 23 | 207,382 |
Yes | output | 1 | 103,691 | 23 | 207,383 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Consider a table of size n × m, initially fully white. Rows are numbered 1 through n from top to bottom, columns 1 through m from left to right. Some square inside the table with odd side length was painted black. Find the center of this square.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 115) — the number of rows and the number of columns in the table.
The i-th of the next n lines contains a string of m characters s_{i1} s_{i2} … s_{im} (s_{ij} is 'W' for white cells and 'B' for black cells), describing the i-th row of the table.
Output
Output two integers r and c (1 ≤ r ≤ n, 1 ≤ c ≤ m) separated by a space — the row and column numbers of the center of the black square.
Examples
Input
5 6
WWBBBW
WWBBBW
WWBBBW
WWWWWW
WWWWWW
Output
2 4
Input
3 3
WWW
BWW
WWW
Output
2 1
Submitted Solution:
```
n, m = map(int, input().split())
s = ["W" + input() + "W" for _ in range(n)]
s = ["W" * (m + 2)] + s + ["W" * (m + 2)]
start_m = None
end_m = None
for i in range(n + 2):
for j in range(m + 2):
if start_m is None and s[i][j] == "W":
continue
if start_m is None and s[i][j] == "B":
start_m = j
continue
if start_m is not None and s[i][j] == "B":
continue
if start_m is not None and s[i][j] == "W":
end_m = j - 1
break
if end_m is not None:
break
start_n = None
end_n = None
for j in range(m + 2):
for i in range(n + 2):
if start_n is None and s[i][j] == "B":
start_n = i
continue
if start_n is not None and s[i][j] == "B":
continue
if start_n is not None and s[i][j] == "W":
end_n = i - 1
break
if end_n is not None:
break
print((start_n + end_n) // 2, (start_m + end_m) // 2)
``` | instruction | 0 | 103,692 | 23 | 207,384 |
Yes | output | 1 | 103,692 | 23 | 207,385 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Consider a table of size n × m, initially fully white. Rows are numbered 1 through n from top to bottom, columns 1 through m from left to right. Some square inside the table with odd side length was painted black. Find the center of this square.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 115) — the number of rows and the number of columns in the table.
The i-th of the next n lines contains a string of m characters s_{i1} s_{i2} … s_{im} (s_{ij} is 'W' for white cells and 'B' for black cells), describing the i-th row of the table.
Output
Output two integers r and c (1 ≤ r ≤ n, 1 ≤ c ≤ m) separated by a space — the row and column numbers of the center of the black square.
Examples
Input
5 6
WWBBBW
WWBBBW
WWBBBW
WWWWWW
WWWWWW
Output
2 4
Input
3 3
WWW
BWW
WWW
Output
2 1
Submitted Solution:
```
a = list(input().split(' '))
n , m = int(a[0]), int(a[1])
a = []
for _ in range(n):
a.append(list(input()))
x = 0
x_begin, y_begin = -1, -1
for i in range(n):
res = 0
for j in range(n):
if a[i][j] == 'B':
if y_begin == -1:
y_begin = j
res += 1
x = max(x, res)
for j in range(m):
for i in range(n):
if a[i][j] == 'B':
if x_begin == -1:
x_begin = i
print(x_begin + x//2 + 1, y_begin + x//2 + 1)
``` | instruction | 0 | 103,693 | 23 | 207,386 |
No | output | 1 | 103,693 | 23 | 207,387 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Consider a table of size n × m, initially fully white. Rows are numbered 1 through n from top to bottom, columns 1 through m from left to right. Some square inside the table with odd side length was painted black. Find the center of this square.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 115) — the number of rows and the number of columns in the table.
The i-th of the next n lines contains a string of m characters s_{i1} s_{i2} … s_{im} (s_{ij} is 'W' for white cells and 'B' for black cells), describing the i-th row of the table.
Output
Output two integers r and c (1 ≤ r ≤ n, 1 ≤ c ≤ m) separated by a space — the row and column numbers of the center of the black square.
Examples
Input
5 6
WWBBBW
WWBBBW
WWBBBW
WWWWWW
WWWWWW
Output
2 4
Input
3 3
WWW
BWW
WWW
Output
2 1
Submitted Solution:
```
n, m = map(int, input().split())
a = []
for i in range(m):
b = input()
a.append(b)
if 'B' in b:
l = b.find('B')
r = b.rfind('B')
d = (l + r) // 2
print(1 + i + (r - l) // 2, d + 1)
break
``` | instruction | 0 | 103,694 | 23 | 207,388 |
No | output | 1 | 103,694 | 23 | 207,389 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Consider a table of size n × m, initially fully white. Rows are numbered 1 through n from top to bottom, columns 1 through m from left to right. Some square inside the table with odd side length was painted black. Find the center of this square.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 115) — the number of rows and the number of columns in the table.
The i-th of the next n lines contains a string of m characters s_{i1} s_{i2} … s_{im} (s_{ij} is 'W' for white cells and 'B' for black cells), describing the i-th row of the table.
Output
Output two integers r and c (1 ≤ r ≤ n, 1 ≤ c ≤ m) separated by a space — the row and column numbers of the center of the black square.
Examples
Input
5 6
WWBBBW
WWBBBW
WWBBBW
WWWWWW
WWWWWW
Output
2 4
Input
3 3
WWW
BWW
WWW
Output
2 1
Submitted Solution:
```
num = input().split(" ")
n = int(num[0])
m = int(num[1])
table = list()
for i in range(n):
table.append(input())
for i in range(n):
flag = True
for j in range(len(table[i])):
if table[i][j] == 'B':
row = i
col = j
while col + 2 < m and row + 2 < n and table[i][col + 2] == 'B' and table[row + 2][j] == 'B':
col += 2
row += 2
if row == i:
x = i
y = j
else:
x = i + row / 2
y = j + row / 2
print (x + 1, " ", y + 1)
flag = False
break
if not flag:
break
``` | instruction | 0 | 103,695 | 23 | 207,390 |
No | output | 1 | 103,695 | 23 | 207,391 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Consider a table of size n × m, initially fully white. Rows are numbered 1 through n from top to bottom, columns 1 through m from left to right. Some square inside the table with odd side length was painted black. Find the center of this square.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 115) — the number of rows and the number of columns in the table.
The i-th of the next n lines contains a string of m characters s_{i1} s_{i2} … s_{im} (s_{ij} is 'W' for white cells and 'B' for black cells), describing the i-th row of the table.
Output
Output two integers r and c (1 ≤ r ≤ n, 1 ≤ c ≤ m) separated by a space — the row and column numbers of the center of the black square.
Examples
Input
5 6
WWBBBW
WWBBBW
WWBBBW
WWWWWW
WWWWWW
Output
2 4
Input
3 3
WWW
BWW
WWW
Output
2 1
Submitted Solution:
```
r, c = [int(x) for x in input().strip().split()]
board = [input().strip() for i in range(r)]
b = False
count = 1
start = None
for i in range(r):
for j in range(c):
if board[i][j] == 'B' and not b:
b = True
start = (i,j)
elif b and board[i][j] == 'B':
count += 1
elif b:
l = count // 2 + 1
print(str(start[0] + l) + " " + str(start[1] + l))
exit()
``` | instruction | 0 | 103,696 | 23 | 207,392 |
No | output | 1 | 103,696 | 23 | 207,393 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
Input
The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive ( > 0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement.
Output
Print a single number — the sum of all edges of the parallelepiped.
Examples
Input
1 1 1
Output
12
Input
4 6 6
Output
28
Note
In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3. | instruction | 0 | 103,945 | 23 | 207,890 |
Tags: brute force, geometry, math
Correct Solution:
```
import math
ar = []
for i in input().split(' '):
ar.append(int(i))
b = math.sqrt((ar[0]*ar[1])/ar[2])
a = ar[0]/b
c = ar[2]/a
print(int(4*(a+b+c)))
``` | output | 1 | 103,945 | 23 | 207,891 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
Input
The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive ( > 0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement.
Output
Print a single number — the sum of all edges of the parallelepiped.
Examples
Input
1 1 1
Output
12
Input
4 6 6
Output
28
Note
In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3. | instruction | 0 | 103,946 | 23 | 207,892 |
Tags: brute force, geometry, math
Correct Solution:
```
s1,s2,s3=map(int,input().split())
a=int((s1*s3//s2)**0.5)
b=int((s1*s2//s3)**0.5)
c=int((s2*s3//s1)**0.5)
print(4*(a+b+c))
``` | output | 1 | 103,946 | 23 | 207,893 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
Input
The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive ( > 0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement.
Output
Print a single number — the sum of all edges of the parallelepiped.
Examples
Input
1 1 1
Output
12
Input
4 6 6
Output
28
Note
In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3. | instruction | 0 | 103,947 | 23 | 207,894 |
Tags: brute force, geometry, math
Correct Solution:
```
a,b,c = list(map(int,input().split()))
import math
c = math.sqrt((c*b)/a)
b = b/c
a = a/b
print(int(sum([4*a,4*b,4*c])))
``` | output | 1 | 103,947 | 23 | 207,895 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
Input
The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive ( > 0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement.
Output
Print a single number — the sum of all edges of the parallelepiped.
Examples
Input
1 1 1
Output
12
Input
4 6 6
Output
28
Note
In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3. | instruction | 0 | 103,948 | 23 | 207,896 |
Tags: brute force, geometry, math
Correct Solution:
```
a,b,c=map(int,input().split())
v=(a*b*c)**0.5 #l*b*h
print(int(4*(v/a+v/b+v/c)))
``` | output | 1 | 103,948 | 23 | 207,897 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
Input
The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive ( > 0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement.
Output
Print a single number — the sum of all edges of the parallelepiped.
Examples
Input
1 1 1
Output
12
Input
4 6 6
Output
28
Note
In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3. | instruction | 0 | 103,949 | 23 | 207,898 |
Tags: brute force, geometry, math
Correct Solution:
```
import math
a,b,c=map(int,input().split())
x=math.sqrt(a*b/c)
y=math.sqrt(b*c/a)
z=math.sqrt(a*c/b)
print(int((x+y+z)*4))
``` | output | 1 | 103,949 | 23 | 207,899 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
Input
The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive ( > 0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement.
Output
Print a single number — the sum of all edges of the parallelepiped.
Examples
Input
1 1 1
Output
12
Input
4 6 6
Output
28
Note
In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3. | instruction | 0 | 103,950 | 23 | 207,900 |
Tags: brute force, geometry, math
Correct Solution:
```
import math
s1, s2, s3 = map(int, input().split())
v2 = s1*s2*s3
print(int(4 * (math.sqrt(v2 / (s1 * s1)) + math.sqrt(v2 / (s2 * s2)) + math.sqrt(v2 / (s3 * s3)))))
``` | output | 1 | 103,950 | 23 | 207,901 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.