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 |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Determine if an N-sided polygon (not necessarily convex) with sides of length L_1, L_2, ..., L_N can be drawn in a two-dimensional plane.
You can use the following theorem:
Theorem: an N-sided polygon satisfying the condition can be drawn if and only if the longest side is strictly shorter than the sum of the lengths of the other N-1 sides.
Constraints
* All values in input are integers.
* 3 \leq N \leq 10
* 1 \leq L_i \leq 100
Input
Input is given from Standard Input in the following format:
N
L_1 L_2 ... L_N
Output
If an N-sided polygon satisfying the condition can be drawn, print `Yes`; otherwise, print `No`.
Examples
Input
4
3 8 5 1
Output
Yes
Input
4
3 8 4 1
Output
No
Input
10
1 8 10 5 8 12 34 100 11 3
Output
No
Submitted Solution:
```
N = input()
lst = input().split(" ")
lst2 = []
for i in lst:
int_i = int(i)
print(int_i)
lst2.append(int_i)
max = max(lst2)
sum = sum(lst2)
if sum - max < max:
print("YES")
else:
print("NO")
#input()
``` | instruction | 0 | 82,423 | 23 | 164,846 |
No | output | 1 | 82,423 | 23 | 164,847 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Determine if an N-sided polygon (not necessarily convex) with sides of length L_1, L_2, ..., L_N can be drawn in a two-dimensional plane.
You can use the following theorem:
Theorem: an N-sided polygon satisfying the condition can be drawn if and only if the longest side is strictly shorter than the sum of the lengths of the other N-1 sides.
Constraints
* All values in input are integers.
* 3 \leq N \leq 10
* 1 \leq L_i \leq 100
Input
Input is given from Standard Input in the following format:
N
L_1 L_2 ... L_N
Output
If an N-sided polygon satisfying the condition can be drawn, print `Yes`; otherwise, print `No`.
Examples
Input
4
3 8 5 1
Output
Yes
Input
4
3 8 4 1
Output
No
Input
10
1 8 10 5 8 12 34 100 11 3
Output
No
Submitted Solution:
```
N = input()
lst = input().split(" ")
lst2 = []
for i in lst:
int_i = int(i)
print(int_i)
lst2.append(int_i)
print(lst2)
max = max(lst2)
sum = sum(lst2)
if sum - max < max:
print("YES")
else:
print("NO")
#input()
``` | instruction | 0 | 82,424 | 23 | 164,848 |
No | output | 1 | 82,424 | 23 | 164,849 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Determine if an N-sided polygon (not necessarily convex) with sides of length L_1, L_2, ..., L_N can be drawn in a two-dimensional plane.
You can use the following theorem:
Theorem: an N-sided polygon satisfying the condition can be drawn if and only if the longest side is strictly shorter than the sum of the lengths of the other N-1 sides.
Constraints
* All values in input are integers.
* 3 \leq N \leq 10
* 1 \leq L_i \leq 100
Input
Input is given from Standard Input in the following format:
N
L_1 L_2 ... L_N
Output
If an N-sided polygon satisfying the condition can be drawn, print `Yes`; otherwise, print `No`.
Examples
Input
4
3 8 5 1
Output
Yes
Input
4
3 8 4 1
Output
No
Input
10
1 8 10 5 8 12 34 100 11 3
Output
No
Submitted Solution:
```
N = int(input())
L = input().split()
max = 0
total = 0
for i in range(N-1):
if max < int(L[i]):
max = int(L[i])
else:
pass
for i in range(N-1):
total += int(L[i])
total = total - max
if max < total:
print("Yes")
else:
print("No")
``` | instruction | 0 | 82,425 | 23 | 164,850 |
No | output | 1 | 82,425 | 23 | 164,851 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Determine if an N-sided polygon (not necessarily convex) with sides of length L_1, L_2, ..., L_N can be drawn in a two-dimensional plane.
You can use the following theorem:
Theorem: an N-sided polygon satisfying the condition can be drawn if and only if the longest side is strictly shorter than the sum of the lengths of the other N-1 sides.
Constraints
* All values in input are integers.
* 3 \leq N \leq 10
* 1 \leq L_i \leq 100
Input
Input is given from Standard Input in the following format:
N
L_1 L_2 ... L_N
Output
If an N-sided polygon satisfying the condition can be drawn, print `Yes`; otherwise, print `No`.
Examples
Input
4
3 8 5 1
Output
Yes
Input
4
3 8 4 1
Output
No
Input
10
1 8 10 5 8 12 34 100 11 3
Output
No
Submitted Solution:
```
def nyu():
N = int(input())
L = list(map(int,input().split()))
L.sort()
return N,L
def check(N,L):
sum =0
for n in range(N-1):
sum += L[n]
if sum > L[N-1]:
print("YES")
else:
print("NO")
N,L =nyu()
check(N,L)
``` | instruction | 0 | 82,426 | 23 | 164,852 |
No | output | 1 | 82,426 | 23 | 164,853 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given 4n sticks, the length of the i-th stick is a_i.
You have to create n rectangles, each rectangle will consist of exactly 4 sticks from the given set. The rectangle consists of four sides, opposite sides should have equal length and all angles in it should be right. Note that each stick can be used in only one rectangle. Each stick should be used as a side, you cannot break the stick or use it not to the full length.
You want to all rectangles to have equal area. The area of the rectangle with sides a and b is a β
b.
Your task is to say if it is possible to create exactly n rectangles of equal area or not.
You have to answer q independent queries.
Input
The first line of the input contains one integer q (1 β€ q β€ 500) β the number of queries. Then q queries follow.
The first line of the query contains one integer n (1 β€ n β€ 100) β the number of rectangles.
The second line of the query contains 4n integers a_1, a_2, ..., a_{4n} (1 β€ a_i β€ 10^4), where a_i is the length of the i-th stick.
Output
For each query print the answer to it. If it is impossible to create exactly n rectangles of equal area using given sticks, print "NO". Otherwise print "YES".
Example
Input
5
1
1 1 10 10
2
10 5 2 10 1 1 2 5
2
10 5 1 10 5 1 1 1
2
1 1 1 1 1 1 1 1
1
10000 10000 10000 10000
Output
YES
YES
NO
YES
YES | instruction | 0 | 82,676 | 23 | 165,352 |
Tags: greedy, math
Correct Solution:
```
q = int(input())
for _ in range(q):
n = int(input())
array = list(map(int, input().split()))
array.sort()
flag = 1
for i in set(array):
if array.count(i) % 2:
flag = 0
break
if not flag:
print("NO")
continue
k = ((4 * n) // 2) - 1
area = array[0] * array[-1]
for i in range(k + 1):
if array[i] * array[-1 - i] != area:
flag = 0
break
if flag:
print("YES")
else:
print("NO")
``` | output | 1 | 82,676 | 23 | 165,353 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given 4n sticks, the length of the i-th stick is a_i.
You have to create n rectangles, each rectangle will consist of exactly 4 sticks from the given set. The rectangle consists of four sides, opposite sides should have equal length and all angles in it should be right. Note that each stick can be used in only one rectangle. Each stick should be used as a side, you cannot break the stick or use it not to the full length.
You want to all rectangles to have equal area. The area of the rectangle with sides a and b is a β
b.
Your task is to say if it is possible to create exactly n rectangles of equal area or not.
You have to answer q independent queries.
Input
The first line of the input contains one integer q (1 β€ q β€ 500) β the number of queries. Then q queries follow.
The first line of the query contains one integer n (1 β€ n β€ 100) β the number of rectangles.
The second line of the query contains 4n integers a_1, a_2, ..., a_{4n} (1 β€ a_i β€ 10^4), where a_i is the length of the i-th stick.
Output
For each query print the answer to it. If it is impossible to create exactly n rectangles of equal area using given sticks, print "NO". Otherwise print "YES".
Example
Input
5
1
1 1 10 10
2
10 5 2 10 1 1 2 5
2
10 5 1 10 5 1 1 1
2
1 1 1 1 1 1 1 1
1
10000 10000 10000 10000
Output
YES
YES
NO
YES
YES | instruction | 0 | 82,677 | 23 | 165,354 |
Tags: greedy, math
Correct Solution:
```
for _ in range(int(input())):
n = int(input())
a = sorted(list(map(int, input().split())))
pr = a[0]*a[1]*a[-1]*a[-2]
for q in range(0, n*2, 2):
if a[q] != a[q+1] or a[4*n-q-1] != a[4*n-q-2] or a[q]*a[q+1]*a[4*n-q-1]*a[4*n-q-2] != pr:
print('NO')
break
else:
print('YES')
``` | output | 1 | 82,677 | 23 | 165,355 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given 4n sticks, the length of the i-th stick is a_i.
You have to create n rectangles, each rectangle will consist of exactly 4 sticks from the given set. The rectangle consists of four sides, opposite sides should have equal length and all angles in it should be right. Note that each stick can be used in only one rectangle. Each stick should be used as a side, you cannot break the stick or use it not to the full length.
You want to all rectangles to have equal area. The area of the rectangle with sides a and b is a β
b.
Your task is to say if it is possible to create exactly n rectangles of equal area or not.
You have to answer q independent queries.
Input
The first line of the input contains one integer q (1 β€ q β€ 500) β the number of queries. Then q queries follow.
The first line of the query contains one integer n (1 β€ n β€ 100) β the number of rectangles.
The second line of the query contains 4n integers a_1, a_2, ..., a_{4n} (1 β€ a_i β€ 10^4), where a_i is the length of the i-th stick.
Output
For each query print the answer to it. If it is impossible to create exactly n rectangles of equal area using given sticks, print "NO". Otherwise print "YES".
Example
Input
5
1
1 1 10 10
2
10 5 2 10 1 1 2 5
2
10 5 1 10 5 1 1 1
2
1 1 1 1 1 1 1 1
1
10000 10000 10000 10000
Output
YES
YES
NO
YES
YES | instruction | 0 | 82,678 | 23 | 165,356 |
Tags: greedy, math
Correct Solution:
```
q = int(input())
for j in range(q):
n = int(input())
sp = list(map(int, input().split()))
sp.sort()
sqrt = sp[4 * n - 1] * sp[0]
t = True
for i in range(0, 2 * n, 2):
if sp.count(sp[i]) % 2 != 0 or sp.count(sp[4 * n - i - 1]) % 2 != 0:
t = False
break
if sp[4 * n - i - 1] * sp[i] != sqrt:
t = False
break
if t == False:
print("NO")
else:
print("YES")
``` | output | 1 | 82,678 | 23 | 165,357 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given 4n sticks, the length of the i-th stick is a_i.
You have to create n rectangles, each rectangle will consist of exactly 4 sticks from the given set. The rectangle consists of four sides, opposite sides should have equal length and all angles in it should be right. Note that each stick can be used in only one rectangle. Each stick should be used as a side, you cannot break the stick or use it not to the full length.
You want to all rectangles to have equal area. The area of the rectangle with sides a and b is a β
b.
Your task is to say if it is possible to create exactly n rectangles of equal area or not.
You have to answer q independent queries.
Input
The first line of the input contains one integer q (1 β€ q β€ 500) β the number of queries. Then q queries follow.
The first line of the query contains one integer n (1 β€ n β€ 100) β the number of rectangles.
The second line of the query contains 4n integers a_1, a_2, ..., a_{4n} (1 β€ a_i β€ 10^4), where a_i is the length of the i-th stick.
Output
For each query print the answer to it. If it is impossible to create exactly n rectangles of equal area using given sticks, print "NO". Otherwise print "YES".
Example
Input
5
1
1 1 10 10
2
10 5 2 10 1 1 2 5
2
10 5 1 10 5 1 1 1
2
1 1 1 1 1 1 1 1
1
10000 10000 10000 10000
Output
YES
YES
NO
YES
YES | instruction | 0 | 82,679 | 23 | 165,358 |
Tags: greedy, math
Correct Solution:
```
for _ in range(int(input())):
n = int(input())
a = sorted(map(int, input().split()))
p = a[0] * a[-1]
for i in range(0, 4 * n, 2):
if a[i] != a[i + 1] or p != a[i] * a[-i - 1]:
print('NO')
break
else:
print('YES')
``` | output | 1 | 82,679 | 23 | 165,359 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given 4n sticks, the length of the i-th stick is a_i.
You have to create n rectangles, each rectangle will consist of exactly 4 sticks from the given set. The rectangle consists of four sides, opposite sides should have equal length and all angles in it should be right. Note that each stick can be used in only one rectangle. Each stick should be used as a side, you cannot break the stick or use it not to the full length.
You want to all rectangles to have equal area. The area of the rectangle with sides a and b is a β
b.
Your task is to say if it is possible to create exactly n rectangles of equal area or not.
You have to answer q independent queries.
Input
The first line of the input contains one integer q (1 β€ q β€ 500) β the number of queries. Then q queries follow.
The first line of the query contains one integer n (1 β€ n β€ 100) β the number of rectangles.
The second line of the query contains 4n integers a_1, a_2, ..., a_{4n} (1 β€ a_i β€ 10^4), where a_i is the length of the i-th stick.
Output
For each query print the answer to it. If it is impossible to create exactly n rectangles of equal area using given sticks, print "NO". Otherwise print "YES".
Example
Input
5
1
1 1 10 10
2
10 5 2 10 1 1 2 5
2
10 5 1 10 5 1 1 1
2
1 1 1 1 1 1 1 1
1
10000 10000 10000 10000
Output
YES
YES
NO
YES
YES | instruction | 0 | 82,680 | 23 | 165,360 |
Tags: greedy, math
Correct Solution:
```
def check(n, a):
a.sort()
area = a[0] * a[-1]
i = 0;
while i < 2*n:
if (a[i] != a[i+1]): return False
if (a[-(i+1)] != a[-(i+2)]): return False
if a[i] * a[-(i+1)] != area:
return False
i += 2
return True
q = int(input())
for i in range(q):
n = int(input())
a = [int(x) for x in input().split()]
if check(n, a):
print("YES")
else:
print("NO")
``` | output | 1 | 82,680 | 23 | 165,361 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given 4n sticks, the length of the i-th stick is a_i.
You have to create n rectangles, each rectangle will consist of exactly 4 sticks from the given set. The rectangle consists of four sides, opposite sides should have equal length and all angles in it should be right. Note that each stick can be used in only one rectangle. Each stick should be used as a side, you cannot break the stick or use it not to the full length.
You want to all rectangles to have equal area. The area of the rectangle with sides a and b is a β
b.
Your task is to say if it is possible to create exactly n rectangles of equal area or not.
You have to answer q independent queries.
Input
The first line of the input contains one integer q (1 β€ q β€ 500) β the number of queries. Then q queries follow.
The first line of the query contains one integer n (1 β€ n β€ 100) β the number of rectangles.
The second line of the query contains 4n integers a_1, a_2, ..., a_{4n} (1 β€ a_i β€ 10^4), where a_i is the length of the i-th stick.
Output
For each query print the answer to it. If it is impossible to create exactly n rectangles of equal area using given sticks, print "NO". Otherwise print "YES".
Example
Input
5
1
1 1 10 10
2
10 5 2 10 1 1 2 5
2
10 5 1 10 5 1 1 1
2
1 1 1 1 1 1 1 1
1
10000 10000 10000 10000
Output
YES
YES
NO
YES
YES | instruction | 0 | 82,681 | 23 | 165,362 |
Tags: greedy, math
Correct Solution:
```
numberOfQueries = int(input())
for _ in range(numberOfQueries):
numberOfRects = int(input())
sides = list(map(int, input().split()))
sides.sort()
area = sides[0] * sides[4 * numberOfRects - 1]
index = 0
canFormRects = True
for _ in range(numberOfRects):
if (sides[index] != sides[index + 1]
or sides[4 * numberOfRects - index - 1] != sides[4 * numberOfRects - index - 2]
or sides[index] * sides[4 * numberOfRects - 1 - index] != area):
canFormRects = False
break
index += 2
print("YES" if canFormRects else "NO")
``` | output | 1 | 82,681 | 23 | 165,363 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given 4n sticks, the length of the i-th stick is a_i.
You have to create n rectangles, each rectangle will consist of exactly 4 sticks from the given set. The rectangle consists of four sides, opposite sides should have equal length and all angles in it should be right. Note that each stick can be used in only one rectangle. Each stick should be used as a side, you cannot break the stick or use it not to the full length.
You want to all rectangles to have equal area. The area of the rectangle with sides a and b is a β
b.
Your task is to say if it is possible to create exactly n rectangles of equal area or not.
You have to answer q independent queries.
Input
The first line of the input contains one integer q (1 β€ q β€ 500) β the number of queries. Then q queries follow.
The first line of the query contains one integer n (1 β€ n β€ 100) β the number of rectangles.
The second line of the query contains 4n integers a_1, a_2, ..., a_{4n} (1 β€ a_i β€ 10^4), where a_i is the length of the i-th stick.
Output
For each query print the answer to it. If it is impossible to create exactly n rectangles of equal area using given sticks, print "NO". Otherwise print "YES".
Example
Input
5
1
1 1 10 10
2
10 5 2 10 1 1 2 5
2
10 5 1 10 5 1 1 1
2
1 1 1 1 1 1 1 1
1
10000 10000 10000 10000
Output
YES
YES
NO
YES
YES | instruction | 0 | 82,682 | 23 | 165,364 |
Tags: greedy, math
Correct Solution:
```
q=int(input())
for _ in range(q):
n=int(input())
a=list(map(int,input().split()))
a.sort()
base=a[0]*a[-1]
for i in range(0,2*n,2):
if a[i]!=a[i+1]:
print("NO")
break
if a[-i-1]!=a[-i-2]:
print("NO")
break
if a[i]*a[-i-1]!=base:
print("NO")
break
else:
print("YES")
``` | output | 1 | 82,682 | 23 | 165,365 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given 4n sticks, the length of the i-th stick is a_i.
You have to create n rectangles, each rectangle will consist of exactly 4 sticks from the given set. The rectangle consists of four sides, opposite sides should have equal length and all angles in it should be right. Note that each stick can be used in only one rectangle. Each stick should be used as a side, you cannot break the stick or use it not to the full length.
You want to all rectangles to have equal area. The area of the rectangle with sides a and b is a β
b.
Your task is to say if it is possible to create exactly n rectangles of equal area or not.
You have to answer q independent queries.
Input
The first line of the input contains one integer q (1 β€ q β€ 500) β the number of queries. Then q queries follow.
The first line of the query contains one integer n (1 β€ n β€ 100) β the number of rectangles.
The second line of the query contains 4n integers a_1, a_2, ..., a_{4n} (1 β€ a_i β€ 10^4), where a_i is the length of the i-th stick.
Output
For each query print the answer to it. If it is impossible to create exactly n rectangles of equal area using given sticks, print "NO". Otherwise print "YES".
Example
Input
5
1
1 1 10 10
2
10 5 2 10 1 1 2 5
2
10 5 1 10 5 1 1 1
2
1 1 1 1 1 1 1 1
1
10000 10000 10000 10000
Output
YES
YES
NO
YES
YES | instruction | 0 | 82,683 | 23 | 165,366 |
Tags: greedy, math
Correct Solution:
```
from sys import stdout
from sys import stdin
def get():
return stdin.readline().strip()
def getf():
return [int(i) for i in get().split()]
def put(a, end = "\n"):
stdout.write(str(a) + end)
def putf(a, sep = " ", end = "\n"):
stdout.write(sep.join([str(i) for i in a]) + end)
def putff(a, sep = " ", end = "\n"):
[putf(i, sep, end) for i in a]
#from math import ceil, gcd, factorial as fac
from collections import defaultdict as dd
#from bisect import insort, bisect_left as bl, bisect_right as br
def solve(a, n):
d = dd(int)
for i in a:
d[i] += 1
for i in d:
if(d[i] % 2 == 1):
return "NO"
a = []
k = 0
for i in d:
a.extend([i] * (d[i] // 2))
k += (d[i] // 2)
a = sorted(a)
p = a[0] * a[k - 1]
for i in range(k // 2 + k % 2):
if(a[i] * a[k - i - 1] != p):
return "NO"
return "YES"
def main():
q = int(get())
for i in range(q):
n = int(get())
a = getf()
print(solve(sorted(a), n))
main()
``` | output | 1 | 82,683 | 23 | 165,367 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given 4n sticks, the length of the i-th stick is a_i.
You have to create n rectangles, each rectangle will consist of exactly 4 sticks from the given set. The rectangle consists of four sides, opposite sides should have equal length and all angles in it should be right. Note that each stick can be used in only one rectangle. Each stick should be used as a side, you cannot break the stick or use it not to the full length.
You want to all rectangles to have equal area. The area of the rectangle with sides a and b is a β
b.
Your task is to say if it is possible to create exactly n rectangles of equal area or not.
You have to answer q independent queries.
Input
The first line of the input contains one integer q (1 β€ q β€ 500) β the number of queries. Then q queries follow.
The first line of the query contains one integer n (1 β€ n β€ 100) β the number of rectangles.
The second line of the query contains 4n integers a_1, a_2, ..., a_{4n} (1 β€ a_i β€ 10^4), where a_i is the length of the i-th stick.
Output
For each query print the answer to it. If it is impossible to create exactly n rectangles of equal area using given sticks, print "NO". Otherwise print "YES".
Example
Input
5
1
1 1 10 10
2
10 5 2 10 1 1 2 5
2
10 5 1 10 5 1 1 1
2
1 1 1 1 1 1 1 1
1
10000 10000 10000 10000
Output
YES
YES
NO
YES
YES
Submitted Solution:
```
q=int(input())
n=0
a=0
kq=0
b=0
d=0
c=[]
for i in range(q):
n=int(input())
a=list(map(int,input().split()))
a.sort()
kq=1
b=[]
c=[]
b.append(a[0])
d=1
for j in range(1,4*n):
if(a[j]!=a[j-1]):
b.append(a[j])
if((d%2)==1):
kq=0
break
c.append(d)
d=1
else:
d+=1
if(kq==1):
c.append(d)
t=a[0]*a[4*n-2]
for j in range(1,n):
if((a[2*j]*a[4*n-2-2*j])!=t):
kq=0
break
if(kq==0):
print('NO')
else:
print('YES')
else:
print('NO')
``` | instruction | 0 | 82,684 | 23 | 165,368 |
Yes | output | 1 | 82,684 | 23 | 165,369 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given 4n sticks, the length of the i-th stick is a_i.
You have to create n rectangles, each rectangle will consist of exactly 4 sticks from the given set. The rectangle consists of four sides, opposite sides should have equal length and all angles in it should be right. Note that each stick can be used in only one rectangle. Each stick should be used as a side, you cannot break the stick or use it not to the full length.
You want to all rectangles to have equal area. The area of the rectangle with sides a and b is a β
b.
Your task is to say if it is possible to create exactly n rectangles of equal area or not.
You have to answer q independent queries.
Input
The first line of the input contains one integer q (1 β€ q β€ 500) β the number of queries. Then q queries follow.
The first line of the query contains one integer n (1 β€ n β€ 100) β the number of rectangles.
The second line of the query contains 4n integers a_1, a_2, ..., a_{4n} (1 β€ a_i β€ 10^4), where a_i is the length of the i-th stick.
Output
For each query print the answer to it. If it is impossible to create exactly n rectangles of equal area using given sticks, print "NO". Otherwise print "YES".
Example
Input
5
1
1 1 10 10
2
10 5 2 10 1 1 2 5
2
10 5 1 10 5 1 1 1
2
1 1 1 1 1 1 1 1
1
10000 10000 10000 10000
Output
YES
YES
NO
YES
YES
Submitted Solution:
```
import sys
t = int(input())
while t!=0:
t-=1
n = int(input())
arr = list(map(int,input().split(' ')))
arr.sort()
ans = 'YES'
area = arr[0]*arr[4*n-1]
for i in range(0,2*n):
if arr[2*i] != arr[2*i+1] or arr[i]*arr[4*n-i-1]!=area:
ans = 'NO'
print(ans)
``` | instruction | 0 | 82,685 | 23 | 165,370 |
Yes | output | 1 | 82,685 | 23 | 165,371 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given 4n sticks, the length of the i-th stick is a_i.
You have to create n rectangles, each rectangle will consist of exactly 4 sticks from the given set. The rectangle consists of four sides, opposite sides should have equal length and all angles in it should be right. Note that each stick can be used in only one rectangle. Each stick should be used as a side, you cannot break the stick or use it not to the full length.
You want to all rectangles to have equal area. The area of the rectangle with sides a and b is a β
b.
Your task is to say if it is possible to create exactly n rectangles of equal area or not.
You have to answer q independent queries.
Input
The first line of the input contains one integer q (1 β€ q β€ 500) β the number of queries. Then q queries follow.
The first line of the query contains one integer n (1 β€ n β€ 100) β the number of rectangles.
The second line of the query contains 4n integers a_1, a_2, ..., a_{4n} (1 β€ a_i β€ 10^4), where a_i is the length of the i-th stick.
Output
For each query print the answer to it. If it is impossible to create exactly n rectangles of equal area using given sticks, print "NO". Otherwise print "YES".
Example
Input
5
1
1 1 10 10
2
10 5 2 10 1 1 2 5
2
10 5 1 10 5 1 1 1
2
1 1 1 1 1 1 1 1
1
10000 10000 10000 10000
Output
YES
YES
NO
YES
YES
Submitted Solution:
```
for q in range(int(input())):
n = int(input())
a = [int(x) for x in input().split()]
a.sort()
area = a[0] * a[-1]
flag = 0
for i in range(0, 2 * n, 2):
p = a[i]
q = a[i + 1]
r = a[4 * n - i - 1]
s = a[4 * n - i - 2]
#print(p, q, r, s)
if p != q or r != s or p * r != area:
flag = 1
break
if flag:
print("NO")
else:
print("YES")
``` | instruction | 0 | 82,686 | 23 | 165,372 |
Yes | output | 1 | 82,686 | 23 | 165,373 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given 4n sticks, the length of the i-th stick is a_i.
You have to create n rectangles, each rectangle will consist of exactly 4 sticks from the given set. The rectangle consists of four sides, opposite sides should have equal length and all angles in it should be right. Note that each stick can be used in only one rectangle. Each stick should be used as a side, you cannot break the stick or use it not to the full length.
You want to all rectangles to have equal area. The area of the rectangle with sides a and b is a β
b.
Your task is to say if it is possible to create exactly n rectangles of equal area or not.
You have to answer q independent queries.
Input
The first line of the input contains one integer q (1 β€ q β€ 500) β the number of queries. Then q queries follow.
The first line of the query contains one integer n (1 β€ n β€ 100) β the number of rectangles.
The second line of the query contains 4n integers a_1, a_2, ..., a_{4n} (1 β€ a_i β€ 10^4), where a_i is the length of the i-th stick.
Output
For each query print the answer to it. If it is impossible to create exactly n rectangles of equal area using given sticks, print "NO". Otherwise print "YES".
Example
Input
5
1
1 1 10 10
2
10 5 2 10 1 1 2 5
2
10 5 1 10 5 1 1 1
2
1 1 1 1 1 1 1 1
1
10000 10000 10000 10000
Output
YES
YES
NO
YES
YES
Submitted Solution:
```
q = int(input())
for _ in range(q):
n = int(input())
a = sorted(list(map(int, input().split())))
area = a[0] * a[-1]
for i in range(2*n):
if a[2*i] != a[2*i+1] or a[-(2*i+1)] != a[-(2*i+2)]:
print('NO')
break
if a[2*i] * a[-(2*i+1)] != area:
print('NO')
break
else:
print('YES')
``` | instruction | 0 | 82,687 | 23 | 165,374 |
Yes | output | 1 | 82,687 | 23 | 165,375 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given 4n sticks, the length of the i-th stick is a_i.
You have to create n rectangles, each rectangle will consist of exactly 4 sticks from the given set. The rectangle consists of four sides, opposite sides should have equal length and all angles in it should be right. Note that each stick can be used in only one rectangle. Each stick should be used as a side, you cannot break the stick or use it not to the full length.
You want to all rectangles to have equal area. The area of the rectangle with sides a and b is a β
b.
Your task is to say if it is possible to create exactly n rectangles of equal area or not.
You have to answer q independent queries.
Input
The first line of the input contains one integer q (1 β€ q β€ 500) β the number of queries. Then q queries follow.
The first line of the query contains one integer n (1 β€ n β€ 100) β the number of rectangles.
The second line of the query contains 4n integers a_1, a_2, ..., a_{4n} (1 β€ a_i β€ 10^4), where a_i is the length of the i-th stick.
Output
For each query print the answer to it. If it is impossible to create exactly n rectangles of equal area using given sticks, print "NO". Otherwise print "YES".
Example
Input
5
1
1 1 10 10
2
10 5 2 10 1 1 2 5
2
10 5 1 10 5 1 1 1
2
1 1 1 1 1 1 1 1
1
10000 10000 10000 10000
Output
YES
YES
NO
YES
YES
Submitted Solution:
```
q = int(input())
while q>0:
n = int(input())
a = [ int(v) for v in input().split()]
a.sort()
left = 0
right = len(a)-1
area = -1
flag = 0
while left<right:
#print(area)
#new = a[left]*a[right]
#print(new)
if area == -1:
area = a[left] * a[right]
elif not area == (a[left]*a[right]) and ((not a[left+1]==a[left]) or (not a[right-1]==a[right])):
flag = 1
break
left += 2
right -= 2
if flag == 0:
print("YES")
else:
print("NO")
q -= 1
``` | instruction | 0 | 82,688 | 23 | 165,376 |
No | output | 1 | 82,688 | 23 | 165,377 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given 4n sticks, the length of the i-th stick is a_i.
You have to create n rectangles, each rectangle will consist of exactly 4 sticks from the given set. The rectangle consists of four sides, opposite sides should have equal length and all angles in it should be right. Note that each stick can be used in only one rectangle. Each stick should be used as a side, you cannot break the stick or use it not to the full length.
You want to all rectangles to have equal area. The area of the rectangle with sides a and b is a β
b.
Your task is to say if it is possible to create exactly n rectangles of equal area or not.
You have to answer q independent queries.
Input
The first line of the input contains one integer q (1 β€ q β€ 500) β the number of queries. Then q queries follow.
The first line of the query contains one integer n (1 β€ n β€ 100) β the number of rectangles.
The second line of the query contains 4n integers a_1, a_2, ..., a_{4n} (1 β€ a_i β€ 10^4), where a_i is the length of the i-th stick.
Output
For each query print the answer to it. If it is impossible to create exactly n rectangles of equal area using given sticks, print "NO". Otherwise print "YES".
Example
Input
5
1
1 1 10 10
2
10 5 2 10 1 1 2 5
2
10 5 1 10 5 1 1 1
2
1 1 1 1 1 1 1 1
1
10000 10000 10000 10000
Output
YES
YES
NO
YES
YES
Submitted Solution:
```
t=int(input())
for i in range(t):
n=int(input())
d={}
b=[]
l= [int(i) for i in input().split()][:4*n]
l.sort()
#print(l)
for j in l:
d[j]=0
for j in l:
d[j]=d[j]+0.5
for j in l:
if(d[j]>0):
b.append(j)
d[j]-=1
b.sort()
#print(b)
f=[]
for j in range(n):
f.append(b[j]*b[(2*n)-1-j])
#print(f)
if(f.count(f[0])==len(f)):
print("YES")
else:
print("NO")
``` | instruction | 0 | 82,689 | 23 | 165,378 |
No | output | 1 | 82,689 | 23 | 165,379 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given 4n sticks, the length of the i-th stick is a_i.
You have to create n rectangles, each rectangle will consist of exactly 4 sticks from the given set. The rectangle consists of four sides, opposite sides should have equal length and all angles in it should be right. Note that each stick can be used in only one rectangle. Each stick should be used as a side, you cannot break the stick or use it not to the full length.
You want to all rectangles to have equal area. The area of the rectangle with sides a and b is a β
b.
Your task is to say if it is possible to create exactly n rectangles of equal area or not.
You have to answer q independent queries.
Input
The first line of the input contains one integer q (1 β€ q β€ 500) β the number of queries. Then q queries follow.
The first line of the query contains one integer n (1 β€ n β€ 100) β the number of rectangles.
The second line of the query contains 4n integers a_1, a_2, ..., a_{4n} (1 β€ a_i β€ 10^4), where a_i is the length of the i-th stick.
Output
For each query print the answer to it. If it is impossible to create exactly n rectangles of equal area using given sticks, print "NO". Otherwise print "YES".
Example
Input
5
1
1 1 10 10
2
10 5 2 10 1 1 2 5
2
10 5 1 10 5 1 1 1
2
1 1 1 1 1 1 1 1
1
10000 10000 10000 10000
Output
YES
YES
NO
YES
YES
Submitted Solution:
```
#!/usr/bin/env python3
def soln() -> None:
def logic() -> None:
n = int(input())
arr = sorted([int(x) for x in input().split()])
prod = arr[0] * arr[1] * arr[-1] * arr[-2]
while n > 0:
curr = arr.pop() * arr.pop() * arr.pop(0) * arr.pop(0)
if curr != prod:
print('NO')
return
n -= 1
else:
print('YES')
for _ in range(int(input())):
logic()
if __name__ == '__main__':
soln()
``` | instruction | 0 | 82,690 | 23 | 165,380 |
No | output | 1 | 82,690 | 23 | 165,381 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given 4n sticks, the length of the i-th stick is a_i.
You have to create n rectangles, each rectangle will consist of exactly 4 sticks from the given set. The rectangle consists of four sides, opposite sides should have equal length and all angles in it should be right. Note that each stick can be used in only one rectangle. Each stick should be used as a side, you cannot break the stick or use it not to the full length.
You want to all rectangles to have equal area. The area of the rectangle with sides a and b is a β
b.
Your task is to say if it is possible to create exactly n rectangles of equal area or not.
You have to answer q independent queries.
Input
The first line of the input contains one integer q (1 β€ q β€ 500) β the number of queries. Then q queries follow.
The first line of the query contains one integer n (1 β€ n β€ 100) β the number of rectangles.
The second line of the query contains 4n integers a_1, a_2, ..., a_{4n} (1 β€ a_i β€ 10^4), where a_i is the length of the i-th stick.
Output
For each query print the answer to it. If it is impossible to create exactly n rectangles of equal area using given sticks, print "NO". Otherwise print "YES".
Example
Input
5
1
1 1 10 10
2
10 5 2 10 1 1 2 5
2
10 5 1 10 5 1 1 1
2
1 1 1 1 1 1 1 1
1
10000 10000 10000 10000
Output
YES
YES
NO
YES
YES
Submitted Solution:
```
for _ in range(int(input())):
n = int(input())
a = list(map(int,input().split()))
m={}
flag=0
flag2=0
for i in a:
if i in m:
m[i]+=1
else:
m[i]=1
for i in m:
if m[i]%2==0:
flag=1
else:
flag=0
break
if(len(m)%2>3):
flag=0
#print(m , " " , flag)
a=set(a)
a=list(a)
a=sorted(a)
temp = a[0]*a[len(a)-1]
if(len(a)%2==0):
for i in range(int(len(a)/2)):
if(a[i]*a[len(a)-i-1]==temp):
flag2=1
else:
flag2=0
break
elif (len(a)==1):
flag2=1
else:
flag2=0
#print(a , " " ,flag2)
if flag==1 and flag2==1 :
print("YES")
else:
print("NO")
``` | instruction | 0 | 82,691 | 23 | 165,382 |
No | output | 1 | 82,691 | 23 | 165,383 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Based on a peculiar incident at basketball practice, Akari came up with the following competitive programming problem!
You are given n points on the plane, no three of which are collinear. The i-th point initially has a label a_i, in such a way that the labels a_1, a_2, ..., a_n form a permutation of 1, 2, ..., n.
You are allowed to modify the labels through the following operation:
1. Choose two distinct integers i and j between 1 and n.
2. Swap the labels of points i and j, and finally
3. Draw the segment between points i and j.
A sequence of operations is valid if after applying all of the operations in the sequence in order, the k-th point ends up having the label k for all k between 1 and n inclusive, and the drawn segments don't intersect each other internally. Formally, if two of the segments intersect, then they must do so at a common endpoint of both segments.
In particular, all drawn segments must be distinct.
Find any valid sequence of operations, or say that none exist.
Input
The first line contains an integer n (3 β€ n β€ 2000) β the number of points.
The i-th of the following n lines contains three integers x_i, y_i, a_i (-10^6 β€ x_i, y_i β€ 10^6, 1 β€ a_i β€ n), representing that the i-th point has coordinates (x_i, y_i) and initially has label a_i.
It is guaranteed that all points are distinct, no three points are collinear, and the labels a_1, a_2, ..., a_n form a permutation of 1, 2, ..., n.
Output
If it is impossible to perform a valid sequence of operations, print -1.
Otherwise, print an integer k (0 β€ k β€ (n(n - 1))/(2)) β the number of operations to perform, followed by k lines, each containing two integers i and j (1 β€ i, j β€ n, iβ j) β the indices of the points chosen for the operation.
Note that you are not required to minimize or maximize the value of k.
If there are multiple possible answers, you may print any of them.
Examples
Input
5
-1 -2 2
3 0 5
1 3 4
4 -3 3
5 2 1
Output
5
1 2
5 3
4 5
1 5
1 3
Input
3
5 4 1
0 0 2
-3 -2 3
Output
0
Note
The following animation showcases the first sample test case. The black numbers represent the indices of the points, while the boxed orange numbers represent their labels.
<image>
In the second test case, all labels are already in their correct positions, so no operations are necessary. | instruction | 0 | 82,816 | 23 | 165,632 |
Tags: constructive algorithms, geometry, sortings
Correct Solution:
```
import sys,io,os
try:Z=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
except:Z=lambda:sys.stdin.readline().encode()
from math import atan2
from collections import deque
def path(R):
H=deque();H.append(R)
while P[R]>=0:
R=P[R];H.append(R)
if len(H)>2:P[H.popleft()]=H[-1]
return R
def remove_middle(a, b, c):
cross = (a[0] - b[0]) * (c[1] - b[1]) - (a[1] - b[1]) * (c[0] - b[0])
dot = (a[0] - b[0]) * (c[0] - b[0]) + (a[1] - b[1]) * (c[1] - b[1])
return cross < 0 or cross == 0 and dot <= 0
def convex_hull(points):
spoints = sorted(points)
hull = []
for p in spoints + spoints[::-1]:
while len(hull) >= 2 and remove_middle(hull[-2], hull[-1], p):
hull.pop()
hull.append(p)
hull.pop()
return hull
n=int(Z())
p=[]
p2=[]
w=[-1]*n
labels=set()
for i in range(n):
x,y,a=map(int,Z().split())
a-=1
if a!=i:
p.append((x,y,i))
p2.append((x,y))
w[i]=a
labels.add(a)
if not p:print(0);quit()
q=[]
bx,by,bi=p[-1]
L=len(p)-1
for i in range(L):
x,y,l=p[i]
q.append((atan2(y-by,x-bx),(x,y),l))
q.sort()
cycles=[-1]*n
c=0
while labels:
v=labels.pop()
cycles[v]=c
cur=w[v]
while cur!=v:
labels.remove(cur)
cycles[cur]=c
cur=w[cur]
c+=1
K=[-1]*c;P=[-1]*c;S=[1]*c;R=0
moves=[]
ch=convex_hull(p2)
adj1=adj2=None
for i in range(len(ch)):
x,y=ch[i]
if x==bx and y==by:
adj1=ch[(i+1)%len(ch)]
adj2=ch[i-1]
break
for i in range(L):
if (q[i][1]==adj1 and q[i-1][1]==adj2)or(q[i][1]==adj2 and q[i-1][1]==adj1):
continue
l1,l2=q[i][2],q[i-1][2]
a,b=cycles[l1],cycles[l2]
if a!=b:
if K[a]>=0:
if K[b]>=0:
va,vb=path(K[a]),path(K[b])
if va!=vb:
moves.append((l1,l2))
sa,sb=S[va],S[vb]
if sa>sb:P[vb]=va
else:
P[va]=vb
if sa==sb:S[vb]+=1
else:pass
else:K[b]=path(K[a]);moves.append((l1,l2))
else:
if K[b]>=0:K[a]=path(K[b]);moves.append((l1,l2))
else:K[a]=R;K[b]=R;R+=1;moves.append((l1,l2))
for a,b in moves:w[a],w[b]=w[b],w[a]
while w[bi]!=bi:
a=w[bi]
b=w[a]
moves.append((a,bi))
w[bi],w[a]=b,a
print(len(moves))
print('\n'.join(f'{a+1} {b+1}'for a,b in moves))
``` | output | 1 | 82,816 | 23 | 165,633 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Based on a peculiar incident at basketball practice, Akari came up with the following competitive programming problem!
You are given n points on the plane, no three of which are collinear. The i-th point initially has a label a_i, in such a way that the labels a_1, a_2, ..., a_n form a permutation of 1, 2, ..., n.
You are allowed to modify the labels through the following operation:
1. Choose two distinct integers i and j between 1 and n.
2. Swap the labels of points i and j, and finally
3. Draw the segment between points i and j.
A sequence of operations is valid if after applying all of the operations in the sequence in order, the k-th point ends up having the label k for all k between 1 and n inclusive, and the drawn segments don't intersect each other internally. Formally, if two of the segments intersect, then they must do so at a common endpoint of both segments.
In particular, all drawn segments must be distinct.
Find any valid sequence of operations, or say that none exist.
Input
The first line contains an integer n (3 β€ n β€ 2000) β the number of points.
The i-th of the following n lines contains three integers x_i, y_i, a_i (-10^6 β€ x_i, y_i β€ 10^6, 1 β€ a_i β€ n), representing that the i-th point has coordinates (x_i, y_i) and initially has label a_i.
It is guaranteed that all points are distinct, no three points are collinear, and the labels a_1, a_2, ..., a_n form a permutation of 1, 2, ..., n.
Output
If it is impossible to perform a valid sequence of operations, print -1.
Otherwise, print an integer k (0 β€ k β€ (n(n - 1))/(2)) β the number of operations to perform, followed by k lines, each containing two integers i and j (1 β€ i, j β€ n, iβ j) β the indices of the points chosen for the operation.
Note that you are not required to minimize or maximize the value of k.
If there are multiple possible answers, you may print any of them.
Examples
Input
5
-1 -2 2
3 0 5
1 3 4
4 -3 3
5 2 1
Output
5
1 2
5 3
4 5
1 5
1 3
Input
3
5 4 1
0 0 2
-3 -2 3
Output
0
Note
The following animation showcases the first sample test case. The black numbers represent the indices of the points, while the boxed orange numbers represent their labels.
<image>
In the second test case, all labels are already in their correct positions, so no operations are necessary. | instruction | 0 | 82,817 | 23 | 165,634 |
Tags: constructive algorithms, geometry, sortings
Correct Solution:
```
import sys,io,os
try:Z=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
except:Z=lambda:sys.stdin.readline().encode()
from math import atan2;from collections import deque
def path(R):
H=deque();H.append(R)
while P[R]>=0:
R=P[R];H.append(R)
if len(H)>2:P[H.popleft()]=H[-1]
return R
def remove_middle(a,b,c):
cross=(a[0]-b[0])*(c[1]-b[1])-(a[1]-b[1])*(c[0]-b[0])
dot=(a[0]-b[0])*(c[0]-b[0])+(a[1]-b[1])*(c[1]-b[1])
return cross<0 or cross==0 and dot<=0
def convex_hull(points):
spoints=sorted(points);hull=[]
for p in spoints+spoints[::-1]:
while len(hull)>=2 and remove_middle(hull[-2],hull[-1],p):hull.pop()
hull.append(p)
hull.pop();return hull
n=int(Z());p=[];p2=[];w=[-1]*n;labels=set()
for i in range(n):
x,y,a=map(int,Z().split());a-=1
if a!=i:p.append((x,y,i));p2.append((x,y));w[i]=a;labels.add(a)
if not p:print(0);quit()
q=[];bx,by,bi=p[-1];L=len(p)-1
for i in range(L):x,y,l=p[i];q.append((atan2(y-by,x-bx),(x,y),l))
q.sort();cycles=[-1]*n;c=0
while labels:
v=labels.pop();cycles[v]=c;cur=w[v]
while cur!=v:labels.remove(cur);cycles[cur]=c;cur=w[cur]
c+=1
K=[-1]*c;P=[-1]*c;S=[1]*c;R=0;moves=[];ch=convex_hull(p2);adj1=adj2=None
for i in range(len(ch)):
x,y=ch[i]
if x==bx and y==by:adj1=ch[(i+1)%len(ch)];adj2=ch[i-1];break
for i in range(L):
if (q[i][1]==adj1 and q[i-1][1]==adj2)or(q[i][1]==adj2 and q[i-1][1]==adj1):continue
l1,l2=q[i][2],q[i-1][2];a,b=cycles[l1],cycles[l2]
if a!=b:
if K[a]>=0:
if K[b]>=0:
va,vb=path(K[a]),path(K[b])
if va!=vb:
moves.append((l1,l2));sa,sb=S[va],S[vb]
if sa>sb:P[vb]=va
else:
P[va]=vb
if sa==sb:S[vb]+=1
else:pass
else:K[b]=path(K[a]);moves.append((l1,l2))
else:
moves.append((l1,l2))
if K[b]>=0:K[a]=path(K[b])
else:K[a]=R;K[b]=R;R+=1
for a,b in moves:w[a],w[b]=w[b],w[a]
while w[bi]!=bi:a=w[bi];b=w[a];moves.append((a,bi));w[bi],w[a]=b,a
print(len(moves));print('\n'.join(f'{a+1} {b+1}'for a,b in moves))
``` | output | 1 | 82,817 | 23 | 165,635 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Based on a peculiar incident at basketball practice, Akari came up with the following competitive programming problem!
You are given n points on the plane, no three of which are collinear. The i-th point initially has a label a_i, in such a way that the labels a_1, a_2, ..., a_n form a permutation of 1, 2, ..., n.
You are allowed to modify the labels through the following operation:
1. Choose two distinct integers i and j between 1 and n.
2. Swap the labels of points i and j, and finally
3. Draw the segment between points i and j.
A sequence of operations is valid if after applying all of the operations in the sequence in order, the k-th point ends up having the label k for all k between 1 and n inclusive, and the drawn segments don't intersect each other internally. Formally, if two of the segments intersect, then they must do so at a common endpoint of both segments.
In particular, all drawn segments must be distinct.
Find any valid sequence of operations, or say that none exist.
Input
The first line contains an integer n (3 β€ n β€ 2000) β the number of points.
The i-th of the following n lines contains three integers x_i, y_i, a_i (-10^6 β€ x_i, y_i β€ 10^6, 1 β€ a_i β€ n), representing that the i-th point has coordinates (x_i, y_i) and initially has label a_i.
It is guaranteed that all points are distinct, no three points are collinear, and the labels a_1, a_2, ..., a_n form a permutation of 1, 2, ..., n.
Output
If it is impossible to perform a valid sequence of operations, print -1.
Otherwise, print an integer k (0 β€ k β€ (n(n - 1))/(2)) β the number of operations to perform, followed by k lines, each containing two integers i and j (1 β€ i, j β€ n, iβ j) β the indices of the points chosen for the operation.
Note that you are not required to minimize or maximize the value of k.
If there are multiple possible answers, you may print any of them.
Examples
Input
5
-1 -2 2
3 0 5
1 3 4
4 -3 3
5 2 1
Output
5
1 2
5 3
4 5
1 5
1 3
Input
3
5 4 1
0 0 2
-3 -2 3
Output
0
Note
The following animation showcases the first sample test case. The black numbers represent the indices of the points, while the boxed orange numbers represent their labels.
<image>
In the second test case, all labels are already in their correct positions, so no operations are necessary.
Submitted Solution:
```
import sys,io,os
try:Z=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
except:Z=lambda:sys.stdin.readline().encode()
from math import atan2
from collections import deque
def path(R):
H=deque();H.append(R)
while P[R]>=0:
R=P[R];H.append(R)
if len(H)>2:P[H.popleft()]=H[-1]
return R
n=int(Z())
p=[]
w=[-1]*n
labels=set()
for i in range(n):
x,y,a=map(int,Z().split())
a-=1
if a!=i:
p.append((x,y,i))
w[i]=a
labels.add(a)
if not p:print(0);quit()
q=[]
bx,by,bi=p[-1]
L=len(p)-1
for i in range(L):
x,y,_=p[i]
q.append((atan2(y-by,x-bx),i))
q.sort()
cycles=[-1]*n
c=0
while labels:
v=labels.pop()
cycles[v]=c
cur=w[v]
while cur!=v:
labels.remove(cur)
cycles[cur]=c
cur=w[cur]
c+=1
K=[-1]*c;P=[-1]*c;S=[1]*c;R=0
moves=[]
for i in range(L):
l1,l2=q[i][1],q[i-1][1]
a,b=cycles[l1],cycles[l2]
if a!=b:
if K[a]>=0:
if K[b]>=0:
va,vb=path(K[a]),path(K[b])
if va!=vb:
moves.append((l1,l2))
sa,sb=S[va],S[vb]
if sa>sb:P[vb]=va
else:
P[va]=vb
if sa==sb:S[vb]+=1
else:pass
else:K[b]=path(K[a]);moves.append((l1,l2))
else:
if K[b]>=0:K[a]=path(K[b]);moves.append((l1,l2))
else:K[a]=R;K[b]=R;R+=1;moves.append((l1,l2))
for a,b in moves:w[a],w[b]=w[b],w[a]
while w[bi]!=bi:
a=w[bi]
b=w[a]
moves.append((a,bi))
w[bi],w[a]=b,a
print(len(moves))
print('\n'.join(f'{a+1} {b+1}'for a,b in moves))
``` | instruction | 0 | 82,818 | 23 | 165,636 |
No | output | 1 | 82,818 | 23 | 165,637 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is an n Γ m rectangular grid, each cell of the grid contains a single integer: zero or one. Let's call the cell on the i-th row and the j-th column as (i, j).
Let's define a "rectangle" as four integers a, b, c, d (1 β€ a β€ c β€ n; 1 β€ b β€ d β€ m). Rectangle denotes a set of cells of the grid {(x, y) : a β€ x β€ c, b β€ y β€ d}. Let's define a "good rectangle" as a rectangle that includes only the cells with zeros.
You should answer the following q queries: calculate the number of good rectangles all of which cells are in the given rectangle.
Input
There are three integers in the first line: n, m and q (1 β€ n, m β€ 40, 1 β€ q β€ 3Β·105). Each of the next n lines contains m characters β the grid. Consider grid rows are numbered from top to bottom, and grid columns are numbered from left to right. Both columns and rows are numbered starting from 1.
Each of the next q lines contains a query β four integers that describe the current rectangle, a, b, c, d (1 β€ a β€ c β€ n; 1 β€ b β€ d β€ m).
Output
For each query output an answer β a single integer in a separate line.
Examples
Input
5 5 5
00101
00000
00001
01000
00001
1 2 2 4
4 5 4 5
1 2 5 2
2 2 4 5
4 2 5 3
Output
10
1
7
34
5
Input
4 7 5
0000100
0000010
0011000
0000000
1 7 2 7
3 1 3 1
2 3 4 5
1 2 2 7
2 2 4 7
Output
3
1
16
27
52
Note
For the first example, there is a 5 Γ 5 rectangular grid, and the first, the second, and the third queries are represented in the following image.
<image>
* For the first query, there are 10 good rectangles, five 1 Γ 1, two 2 Γ 1, two 1 Γ 2, and one 1 Γ 3.
* For the second query, there is only one 1 Γ 1 good rectangle.
* For the third query, there are 7 good rectangles, four 1 Γ 1, two 2 Γ 1, and one 3 Γ 1.
Submitted Solution:
```
inp = input()
inp = inp.split("\n")
inp = map(lambda x: x.split(" "), inp)
print(inp)
``` | instruction | 0 | 82,910 | 23 | 165,820 |
No | output | 1 | 82,910 | 23 | 165,821 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is an n Γ m rectangular grid, each cell of the grid contains a single integer: zero or one. Let's call the cell on the i-th row and the j-th column as (i, j).
Let's define a "rectangle" as four integers a, b, c, d (1 β€ a β€ c β€ n; 1 β€ b β€ d β€ m). Rectangle denotes a set of cells of the grid {(x, y) : a β€ x β€ c, b β€ y β€ d}. Let's define a "good rectangle" as a rectangle that includes only the cells with zeros.
You should answer the following q queries: calculate the number of good rectangles all of which cells are in the given rectangle.
Input
There are three integers in the first line: n, m and q (1 β€ n, m β€ 40, 1 β€ q β€ 3Β·105). Each of the next n lines contains m characters β the grid. Consider grid rows are numbered from top to bottom, and grid columns are numbered from left to right. Both columns and rows are numbered starting from 1.
Each of the next q lines contains a query β four integers that describe the current rectangle, a, b, c, d (1 β€ a β€ c β€ n; 1 β€ b β€ d β€ m).
Output
For each query output an answer β a single integer in a separate line.
Examples
Input
5 5 5
00101
00000
00001
01000
00001
1 2 2 4
4 5 4 5
1 2 5 2
2 2 4 5
4 2 5 3
Output
10
1
7
34
5
Input
4 7 5
0000100
0000010
0011000
0000000
1 7 2 7
3 1 3 1
2 3 4 5
1 2 2 7
2 2 4 7
Output
3
1
16
27
52
Note
For the first example, there is a 5 Γ 5 rectangular grid, and the first, the second, and the third queries are represented in the following image.
<image>
* For the first query, there are 10 good rectangles, five 1 Γ 1, two 2 Γ 1, two 1 Γ 2, and one 1 Γ 3.
* For the second query, there is only one 1 Γ 1 good rectangle.
* For the third query, there are 7 good rectangles, four 1 Γ 1, two 2 Γ 1, and one 3 Γ 1.
Submitted Solution:
```
inp = input()
inp = inp.split("\n")
inp = list(map(lambda x: x.split(" "), inp))
print(inp)
``` | instruction | 0 | 82,911 | 23 | 165,822 |
No | output | 1 | 82,911 | 23 | 165,823 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n points on the plane. The polygon formed from all the n points is strictly convex, that is, the polygon is convex, and there are no three collinear points (i.e. lying in the same straight line). The points are numbered from 1 to n, in clockwise order.
We define the distance between two points p_1 = (x_1, y_1) and p_2 = (x_2, y_2) as their Manhattan distance: $$$d(p_1, p_2) = |x_1 - x_2| + |y_1 - y_2|.$$$
Furthermore, we define the perimeter of a polygon, as the sum of Manhattan distances between all adjacent pairs of points on it; if the points on the polygon are ordered as p_1, p_2, β¦, p_k (k β₯ 3), then the perimeter of the polygon is d(p_1, p_2) + d(p_2, p_3) + β¦ + d(p_k, p_1).
For some parameter k, let's consider all the polygons that can be formed from the given set of points, having any k vertices, such that the polygon is not self-intersecting. For each such polygon, let's consider its perimeter. Over all such perimeters, we define f(k) to be the maximal perimeter.
Please note, when checking whether a polygon is self-intersecting, that the edges of a polygon are still drawn as straight lines. For instance, in the following pictures:
<image>
In the middle polygon, the order of points (p_1, p_3, p_2, p_4) is not valid, since it is a self-intersecting polygon. The right polygon (whose edges resemble the Manhattan distance) has the same order and is not self-intersecting, but we consider edges as straight lines. The correct way to draw this polygon is (p_1, p_2, p_3, p_4), which is the left polygon.
Your task is to compute f(3), f(4), β¦, f(n). In other words, find the maximum possible perimeter for each possible number of points (i.e. 3 to n).
Input
The first line contains a single integer n (3 β€ n β€ 3β
10^5) β the number of points.
Each of the next n lines contains two integers x_i and y_i (-10^8 β€ x_i, y_i β€ 10^8) β the coordinates of point p_i.
The set of points is guaranteed to be convex, all points are distinct, the points are ordered in clockwise order, and there will be no three collinear points.
Output
For each i (3β€ iβ€ n), output f(i).
Examples
Input
4
2 4
4 3
3 0
1 3
Output
12 14
Input
3
0 0
0 2
2 0
Output
8
Note
In the first example, for f(3), we consider four possible polygons:
* (p_1, p_2, p_3), with perimeter 12.
* (p_1, p_2, p_4), with perimeter 8.
* (p_1, p_3, p_4), with perimeter 12.
* (p_2, p_3, p_4), with perimeter 12.
For f(4), there is only one option, taking all the given points. Its perimeter 14.
In the second example, there is only one possible polygon. Its perimeter is 8. | instruction | 0 | 83,392 | 23 | 166,784 |
Tags: dp, geometry
Correct Solution:
```
n=int(input())
tl=tr=bl=br=top=bot=left=right=-200000000
for i in range(n):
a,b=map(int,input().split())
top=max(top,b)
bot=max(bot,-b)
right=max(right,a)
left=max(left,-a)
tr=max(tr,a+b)
tl=max(tl,b-a)
br=max(br,a-b)
bl=max(bl,-a-b)
print(str(2*max(top+left+br,top+right+bl,bot+left+tr,bot+right+tl))+(n-3)*(" "+str(2*(top+bot+left+right))))
``` | output | 1 | 83,392 | 23 | 166,785 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n points on the plane. The polygon formed from all the n points is strictly convex, that is, the polygon is convex, and there are no three collinear points (i.e. lying in the same straight line). The points are numbered from 1 to n, in clockwise order.
We define the distance between two points p_1 = (x_1, y_1) and p_2 = (x_2, y_2) as their Manhattan distance: $$$d(p_1, p_2) = |x_1 - x_2| + |y_1 - y_2|.$$$
Furthermore, we define the perimeter of a polygon, as the sum of Manhattan distances between all adjacent pairs of points on it; if the points on the polygon are ordered as p_1, p_2, β¦, p_k (k β₯ 3), then the perimeter of the polygon is d(p_1, p_2) + d(p_2, p_3) + β¦ + d(p_k, p_1).
For some parameter k, let's consider all the polygons that can be formed from the given set of points, having any k vertices, such that the polygon is not self-intersecting. For each such polygon, let's consider its perimeter. Over all such perimeters, we define f(k) to be the maximal perimeter.
Please note, when checking whether a polygon is self-intersecting, that the edges of a polygon are still drawn as straight lines. For instance, in the following pictures:
<image>
In the middle polygon, the order of points (p_1, p_3, p_2, p_4) is not valid, since it is a self-intersecting polygon. The right polygon (whose edges resemble the Manhattan distance) has the same order and is not self-intersecting, but we consider edges as straight lines. The correct way to draw this polygon is (p_1, p_2, p_3, p_4), which is the left polygon.
Your task is to compute f(3), f(4), β¦, f(n). In other words, find the maximum possible perimeter for each possible number of points (i.e. 3 to n).
Input
The first line contains a single integer n (3 β€ n β€ 3β
10^5) β the number of points.
Each of the next n lines contains two integers x_i and y_i (-10^8 β€ x_i, y_i β€ 10^8) β the coordinates of point p_i.
The set of points is guaranteed to be convex, all points are distinct, the points are ordered in clockwise order, and there will be no three collinear points.
Output
For each i (3β€ iβ€ n), output f(i).
Examples
Input
4
2 4
4 3
3 0
1 3
Output
12 14
Input
3
0 0
0 2
2 0
Output
8
Note
In the first example, for f(3), we consider four possible polygons:
* (p_1, p_2, p_3), with perimeter 12.
* (p_1, p_2, p_4), with perimeter 8.
* (p_1, p_3, p_4), with perimeter 12.
* (p_2, p_3, p_4), with perimeter 12.
For f(4), there is only one option, taking all the given points. Its perimeter 14.
In the second example, there is only one possible polygon. Its perimeter is 8. | instruction | 0 | 83,393 | 23 | 166,786 |
Tags: dp, geometry
Correct Solution:
```
n = int(input())
north = -100000000
south = 100000000
east = -100000000
west = 100000000
ne = -200000000
nw = -200000000
se = -200000000
sw = -200000000
for i in range(n):
x,y = map(int,input().split())
north = max(north,y)
east = max(east,x)
south = min(south,y)
west = min(west,x)
ne = max(ne,x+y)
nw = max(nw,y-x)
se = max(se,x-y)
sw = max(sw,-1*x-y)
best = 2*(ne-south-west)
best = max(best,2*(nw-south+east))
best = max(best,2*(se+north-west))
best = max(best,2*(sw+north+east))
ans = str(best)
peri = 2*(north-south+east-west)
ans += (" "+str(peri))*(n-3)
print(ans)
``` | output | 1 | 83,393 | 23 | 166,787 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n points on the plane. The polygon formed from all the n points is strictly convex, that is, the polygon is convex, and there are no three collinear points (i.e. lying in the same straight line). The points are numbered from 1 to n, in clockwise order.
We define the distance between two points p_1 = (x_1, y_1) and p_2 = (x_2, y_2) as their Manhattan distance: $$$d(p_1, p_2) = |x_1 - x_2| + |y_1 - y_2|.$$$
Furthermore, we define the perimeter of a polygon, as the sum of Manhattan distances between all adjacent pairs of points on it; if the points on the polygon are ordered as p_1, p_2, β¦, p_k (k β₯ 3), then the perimeter of the polygon is d(p_1, p_2) + d(p_2, p_3) + β¦ + d(p_k, p_1).
For some parameter k, let's consider all the polygons that can be formed from the given set of points, having any k vertices, such that the polygon is not self-intersecting. For each such polygon, let's consider its perimeter. Over all such perimeters, we define f(k) to be the maximal perimeter.
Please note, when checking whether a polygon is self-intersecting, that the edges of a polygon are still drawn as straight lines. For instance, in the following pictures:
<image>
In the middle polygon, the order of points (p_1, p_3, p_2, p_4) is not valid, since it is a self-intersecting polygon. The right polygon (whose edges resemble the Manhattan distance) has the same order and is not self-intersecting, but we consider edges as straight lines. The correct way to draw this polygon is (p_1, p_2, p_3, p_4), which is the left polygon.
Your task is to compute f(3), f(4), β¦, f(n). In other words, find the maximum possible perimeter for each possible number of points (i.e. 3 to n).
Input
The first line contains a single integer n (3 β€ n β€ 3β
10^5) β the number of points.
Each of the next n lines contains two integers x_i and y_i (-10^8 β€ x_i, y_i β€ 10^8) β the coordinates of point p_i.
The set of points is guaranteed to be convex, all points are distinct, the points are ordered in clockwise order, and there will be no three collinear points.
Output
For each i (3β€ iβ€ n), output f(i).
Examples
Input
4
2 4
4 3
3 0
1 3
Output
12 14
Input
3
0 0
0 2
2 0
Output
8
Note
In the first example, for f(3), we consider four possible polygons:
* (p_1, p_2, p_3), with perimeter 12.
* (p_1, p_2, p_4), with perimeter 8.
* (p_1, p_3, p_4), with perimeter 12.
* (p_2, p_3, p_4), with perimeter 12.
For f(4), there is only one option, taking all the given points. Its perimeter 14.
In the second example, there is only one possible polygon. Its perimeter is 8. | instruction | 0 | 83,394 | 23 | 166,788 |
Tags: dp, geometry
Correct Solution:
```
from collections import namedtuple
import sys
XY = namedtuple('XY', 'x y')
n = int(input())
pg = [XY(*[int(w) for w in input().split()]) for _ in range(n)]
minx = min(p.x for p in pg)
miny = min(p.y for p in pg)
maxx = max(p.x for p in pg)
maxy = max(p.y for p in pg)
p4 = 2 * ((maxx - minx) + (maxy - miny))
p3 = p4 - 2 * min([min(p.x - minx, maxx - p.x) + min(p.y - miny, maxy - p.y) for p in pg])
print(p3, *([p4] * (n-3)))
``` | output | 1 | 83,394 | 23 | 166,789 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given n points on the plane. The polygon formed from all the n points is strictly convex, that is, the polygon is convex, and there are no three collinear points (i.e. lying in the same straight line). The points are numbered from 1 to n, in clockwise order.
We define the distance between two points p_1 = (x_1, y_1) and p_2 = (x_2, y_2) as their Manhattan distance: $$$d(p_1, p_2) = |x_1 - x_2| + |y_1 - y_2|.$$$
Furthermore, we define the perimeter of a polygon, as the sum of Manhattan distances between all adjacent pairs of points on it; if the points on the polygon are ordered as p_1, p_2, β¦, p_k (k β₯ 3), then the perimeter of the polygon is d(p_1, p_2) + d(p_2, p_3) + β¦ + d(p_k, p_1).
For some parameter k, let's consider all the polygons that can be formed from the given set of points, having any k vertices, such that the polygon is not self-intersecting. For each such polygon, let's consider its perimeter. Over all such perimeters, we define f(k) to be the maximal perimeter.
Please note, when checking whether a polygon is self-intersecting, that the edges of a polygon are still drawn as straight lines. For instance, in the following pictures:
<image>
In the middle polygon, the order of points (p_1, p_3, p_2, p_4) is not valid, since it is a self-intersecting polygon. The right polygon (whose edges resemble the Manhattan distance) has the same order and is not self-intersecting, but we consider edges as straight lines. The correct way to draw this polygon is (p_1, p_2, p_3, p_4), which is the left polygon.
Your task is to compute f(3), f(4), β¦, f(n). In other words, find the maximum possible perimeter for each possible number of points (i.e. 3 to n).
Input
The first line contains a single integer n (3 β€ n β€ 3β
10^5) β the number of points.
Each of the next n lines contains two integers x_i and y_i (-10^8 β€ x_i, y_i β€ 10^8) β the coordinates of point p_i.
The set of points is guaranteed to be convex, all points are distinct, the points are ordered in clockwise order, and there will be no three collinear points.
Output
For each i (3β€ iβ€ n), output f(i).
Examples
Input
4
2 4
4 3
3 0
1 3
Output
12 14
Input
3
0 0
0 2
2 0
Output
8
Note
In the first example, for f(3), we consider four possible polygons:
* (p_1, p_2, p_3), with perimeter 12.
* (p_1, p_2, p_4), with perimeter 8.
* (p_1, p_3, p_4), with perimeter 12.
* (p_2, p_3, p_4), with perimeter 12.
For f(4), there is only one option, taking all the given points. Its perimeter 14.
In the second example, there is only one possible polygon. Its perimeter is 8.
Submitted Solution:
```
n=int(input())
tl=tr=bl=br=top=bot=left=right=-200000000
for i in range(n):
a,b=map(int,input().split())
top=max(top,b)
bot=max(bot,-b)
right=max(right,a)
left=max(left,-a)
tr=max(tr,a+b)
tl=max(tl,b-a)
br=max(br,a-b)
bl=max(bl,-a-b)
print(top,bot,right,left,tl,tr,bl,br)
print(str(2*max(top+left+br,top+right+bl,bot+left+tr,bot+right+tl))+(n-3)*(" "+str(2*(top+bot+left+right))))
``` | instruction | 0 | 83,395 | 23 | 166,790 |
No | output | 1 | 83,395 | 23 | 166,791 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Cybermen and the Daleks have long been the Doctor's main enemies. Everyone knows that both these species enjoy destroying everything they encounter. However, a little-known fact about them is that they both also love taking Turing tests!
Heidi designed a series of increasingly difficult tasks for them to spend their time on, which would allow the Doctor enough time to save innocent lives!
The funny part is that these tasks would be very easy for a human to solve.
The first task is as follows. There are some points on the plane. All but one of them are on the boundary of an axis-aligned square (its sides are parallel to the axes). Identify that point.
Input
The first line contains an integer n (2 β€ n β€ 10).
Each of the following 4n + 1 lines contains two integers x_i, y_i (0 β€ x_i, y_i β€ 50), describing the coordinates of the next point.
It is guaranteed that there are at least n points on each side of the square and all 4n + 1 points are distinct.
Output
Print two integers β the coordinates of the point that is not on the boundary of the square.
Examples
Input
2
0 0
0 1
0 2
1 0
1 1
1 2
2 0
2 1
2 2
Output
1 1
Input
2
0 0
0 1
0 2
0 3
1 0
1 2
2 0
2 1
2 2
Output
0 3
Note
In both examples, the square has four sides x=0, x=2, y=0, y=2. | instruction | 0 | 83,440 | 23 | 166,880 |
Tags: implementation
Correct Solution:
```
def find_inside_point(points, maxx, minx, maxy, miny):
# print('inside point')
for x, y in points:
if minx < x < maxx and miny < y < maxy:
print(x, y)
return
def find_outside_point(points, maxx, minx, maxy, miny):
# print('outside point')
maxx_points = [ (x, y) for x, y in points if x == maxx ]
minx_points = [ (x, y) for x, y in points if x == minx ]
maxy_points = [ (x, y) for x, y in points if y == maxy ]
miny_points = [ (x, y) for x, y in points if y == miny ]
if len(maxx_points) == 1: print(*maxx_points[0])
elif len(minx_points) == 1: print(*minx_points[0])
elif len(maxy_points) == 1: print(*maxy_points[0])
else: print(*miny_points[0])
def process(n, points):
xs, ys = [ x for x, _ in points ], [ y for _, y in points ]
maxx, minx = max(xs), min(xs)
maxy, miny = max(ys), min(ys)
# count = sum([ 1 for x, y in points if minx < x < maxx and miny < y < maxy])
if maxx - minx == maxy - miny: find_inside_point(points, maxx, minx, maxy, miny)
else: find_outside_point(points, maxx, minx, maxy, miny)
if __name__ == "__main__":
n = int(input())
points = []
for _ in range(4*n+1):
x, y = [ int(z) for z in input().split() ]
# print(x, y)
points.append((x, y))
process(n, points)
``` | output | 1 | 83,440 | 23 | 166,881 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Cybermen and the Daleks have long been the Doctor's main enemies. Everyone knows that both these species enjoy destroying everything they encounter. However, a little-known fact about them is that they both also love taking Turing tests!
Heidi designed a series of increasingly difficult tasks for them to spend their time on, which would allow the Doctor enough time to save innocent lives!
The funny part is that these tasks would be very easy for a human to solve.
The first task is as follows. There are some points on the plane. All but one of them are on the boundary of an axis-aligned square (its sides are parallel to the axes). Identify that point.
Input
The first line contains an integer n (2 β€ n β€ 10).
Each of the following 4n + 1 lines contains two integers x_i, y_i (0 β€ x_i, y_i β€ 50), describing the coordinates of the next point.
It is guaranteed that there are at least n points on each side of the square and all 4n + 1 points are distinct.
Output
Print two integers β the coordinates of the point that is not on the boundary of the square.
Examples
Input
2
0 0
0 1
0 2
1 0
1 1
1 2
2 0
2 1
2 2
Output
1 1
Input
2
0 0
0 1
0 2
0 3
1 0
1 2
2 0
2 1
2 2
Output
0 3
Note
In both examples, the square has four sides x=0, x=2, y=0, y=2. | instruction | 0 | 83,441 | 23 | 166,882 |
Tags: implementation
Correct Solution:
```
N = int(input())
#N,B = [int(x) for x in arr.split(' ')]
#arr = input()
#A = [int(x) for x in arr.split(' ')]
x_freq = {}
y_freq = {}
data = []
for i in range(4*N+1):
arr = input()
x,y = [int(x) for x in arr.split(' ')]
data.append([x,y])
if x not in x_freq:
x_freq[x] = 1
else:
x_freq[x] += 1
if y not in y_freq:
y_freq[y] = 1
else:
y_freq[y] += 1
x_inteval = []
y_inteval = []
for num in x_freq:
if x_freq[num]>=(N):
x_inteval.append(num)
for num in y_freq:
if y_freq[num]>=(N):
y_inteval.append(num)
x_inteval = [min(x_inteval),max(x_inteval)]
y_inteval = [min(y_inteval),max(y_inteval)]
#print(x_inteval,y_inteval)
for p in data:
if (p[0] not in x_inteval) and (p[1] not in y_inteval):
print(p[0],p[1])
quit()
elif p[0]<x_inteval[0] or p[0]>x_inteval[1]:
print(p[0],p[1])
quit()
elif p[1]<y_inteval[0] or p[1]>y_inteval[1]:
print(p[0],p[1])
quit()
``` | output | 1 | 83,441 | 23 | 166,883 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Cybermen and the Daleks have long been the Doctor's main enemies. Everyone knows that both these species enjoy destroying everything they encounter. However, a little-known fact about them is that they both also love taking Turing tests!
Heidi designed a series of increasingly difficult tasks for them to spend their time on, which would allow the Doctor enough time to save innocent lives!
The funny part is that these tasks would be very easy for a human to solve.
The first task is as follows. There are some points on the plane. All but one of them are on the boundary of an axis-aligned square (its sides are parallel to the axes). Identify that point.
Input
The first line contains an integer n (2 β€ n β€ 10).
Each of the following 4n + 1 lines contains two integers x_i, y_i (0 β€ x_i, y_i β€ 50), describing the coordinates of the next point.
It is guaranteed that there are at least n points on each side of the square and all 4n + 1 points are distinct.
Output
Print two integers β the coordinates of the point that is not on the boundary of the square.
Examples
Input
2
0 0
0 1
0 2
1 0
1 1
1 2
2 0
2 1
2 2
Output
1 1
Input
2
0 0
0 1
0 2
0 3
1 0
1 2
2 0
2 1
2 2
Output
0 3
Note
In both examples, the square has four sides x=0, x=2, y=0, y=2. | instruction | 0 | 83,442 | 23 | 166,884 |
Tags: implementation
Correct Solution:
```
import sys
import math as m
def sort(a):
mid = m.ceil(len(a)/2)
if len(a) == 1:
return a
else:
al = sort(a[:mid])
ar = sort(a[mid:])
i = 0
j = 0
sa = []
c = []
while i < len(al) or j < len(ar):
if i == len(al):
sa.append(ar[j])
j += 1
elif j == len(ar):
sa.append(al[i])
i += 1
elif al[i]>ar[j]:
sa.append(ar[j])
j += 1
else:
sa.append(al[i])
i += 1
return sa
def main():
input = sys.stdin.readline()
n = int(input)
x = []
y = []
for i in range(4*n+1):
input = sys.stdin.readline()
X, Y = [int(j) for j in input.split()]
x.append(X)
y.append(Y)
xs = sort(x)
ys = sort(y)
px = 0
py = 0
if xs[0] != xs[1]:
X = xs[0]
elif xs[4*n-1] != xs[4*n]:
X = xs[4*n]
else:
px = 1
if ys[0] != ys[1]:
Y = ys[0]
elif ys[4 * n - 1] != ys[4 * n]:
Y = ys[4 * n]
else:
py = 1
if px and not(py):
i = 0
while i < 4*n+1 and y[i] != Y:
i += 1
X = x[i]
if py and not(px):
i = 0
while i < 4 * n + 1 and x[i] != X:
i += 1
Y = y[i]
if px and py:
i = 0
while x[i] == min(x) or x[i] == max(x) or y[i] == min(y) or y[i] == max(y):
i += 1
X, Y = x[i], y[i]
print(X,Y)
if __name__ == '__main__':
main()
``` | output | 1 | 83,442 | 23 | 166,885 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Cybermen and the Daleks have long been the Doctor's main enemies. Everyone knows that both these species enjoy destroying everything they encounter. However, a little-known fact about them is that they both also love taking Turing tests!
Heidi designed a series of increasingly difficult tasks for them to spend their time on, which would allow the Doctor enough time to save innocent lives!
The funny part is that these tasks would be very easy for a human to solve.
The first task is as follows. There are some points on the plane. All but one of them are on the boundary of an axis-aligned square (its sides are parallel to the axes). Identify that point.
Input
The first line contains an integer n (2 β€ n β€ 10).
Each of the following 4n + 1 lines contains two integers x_i, y_i (0 β€ x_i, y_i β€ 50), describing the coordinates of the next point.
It is guaranteed that there are at least n points on each side of the square and all 4n + 1 points are distinct.
Output
Print two integers β the coordinates of the point that is not on the boundary of the square.
Examples
Input
2
0 0
0 1
0 2
1 0
1 1
1 2
2 0
2 1
2 2
Output
1 1
Input
2
0 0
0 1
0 2
0 3
1 0
1 2
2 0
2 1
2 2
Output
0 3
Note
In both examples, the square has four sides x=0, x=2, y=0, y=2. | instruction | 0 | 83,443 | 23 | 166,886 |
Tags: implementation
Correct Solution:
```
import math
n = int(input())
arr = []
for i in range(4*n + 1):
arr.append(list(map(int,input().split())))
for g in range(len(arr)):
xMin = math.inf
xMax = -1* math.inf
yMin = math.inf
yMax = -1* math.inf
fl = True
for i in range(4*n + 1):
if i!=g:
a,b = arr[i]
xMin = min(xMin,a)
xMax = max(xMax, a)
yMin = min(b,yMin)
yMax = max(b,yMax)
for i in range(4*n + 1):
if i != g:
if (arr[i][0] != xMax and arr[i][0] != xMin)and(arr[i][1] != yMax and arr[i][1] != yMin):
fl=False
break
if fl and yMax-yMin ==xMax-xMin:
print(arr[g][0],arr[g][1])
break
``` | output | 1 | 83,443 | 23 | 166,887 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Cybermen and the Daleks have long been the Doctor's main enemies. Everyone knows that both these species enjoy destroying everything they encounter. However, a little-known fact about them is that they both also love taking Turing tests!
Heidi designed a series of increasingly difficult tasks for them to spend their time on, which would allow the Doctor enough time to save innocent lives!
The funny part is that these tasks would be very easy for a human to solve.
The first task is as follows. There are some points on the plane. All but one of them are on the boundary of an axis-aligned square (its sides are parallel to the axes). Identify that point.
Input
The first line contains an integer n (2 β€ n β€ 10).
Each of the following 4n + 1 lines contains two integers x_i, y_i (0 β€ x_i, y_i β€ 50), describing the coordinates of the next point.
It is guaranteed that there are at least n points on each side of the square and all 4n + 1 points are distinct.
Output
Print two integers β the coordinates of the point that is not on the boundary of the square.
Examples
Input
2
0 0
0 1
0 2
1 0
1 1
1 2
2 0
2 1
2 2
Output
1 1
Input
2
0 0
0 1
0 2
0 3
1 0
1 2
2 0
2 1
2 2
Output
0 3
Note
In both examples, the square has four sides x=0, x=2, y=0, y=2. | instruction | 0 | 83,444 | 23 | 166,888 |
Tags: implementation
Correct Solution:
```
n = int(input())
arr = []
for i in range(4*n + 1):
str_ = input()
x, y = str_.split()
arr.append((int(x), int(y)))
arr.sort()
n1 = 4*n+1
i = 1
while arr[i][0] == arr[i-1][0]:
i += 1
if i == 1:
print(str(arr[0][0]) + ' ' + str(arr[0][1]))
exit()
low_x = arr[0][0]
i = n1-2
while arr[i][0] == arr[i+1][0]:
i -= 1
if i == n1-2:
print(str(arr[n1-1][0]) + ' ' + str(arr[n1-1][1]))
exit()
high_x = arr[n1-1][0]
for i in range(n1):
arr[i] = (arr[i][1], arr[i][0])
arr.sort()
i = 1
while arr[i][0] == arr[i-1][0]:
i += 1
if i == 1:
print(str(arr[0][1]) + ' ' + str(arr[0][0]))
exit()
low_y = arr[0][0]
i = n1-2
while arr[i][0] == arr[i+1][0]:
i -= 1
if i == n1-2:
print(str(arr[n1-1][1]) + ' ' + str(arr[n1-1][0]))
exit()
high_y = arr[n1-1][0]
for i in range(n1):
arr[i] = (arr[i][1], arr[i][0])
for i in range(n1):
if not (arr[i][0] == low_x or arr[i][0] == high_x or arr[i][1] == low_y or arr[i][1] == high_y):
print(str(arr[i][0]) + ' ' + str(arr[i][1]))
exit()
``` | output | 1 | 83,444 | 23 | 166,889 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Cybermen and the Daleks have long been the Doctor's main enemies. Everyone knows that both these species enjoy destroying everything they encounter. However, a little-known fact about them is that they both also love taking Turing tests!
Heidi designed a series of increasingly difficult tasks for them to spend their time on, which would allow the Doctor enough time to save innocent lives!
The funny part is that these tasks would be very easy for a human to solve.
The first task is as follows. There are some points on the plane. All but one of them are on the boundary of an axis-aligned square (its sides are parallel to the axes). Identify that point.
Input
The first line contains an integer n (2 β€ n β€ 10).
Each of the following 4n + 1 lines contains two integers x_i, y_i (0 β€ x_i, y_i β€ 50), describing the coordinates of the next point.
It is guaranteed that there are at least n points on each side of the square and all 4n + 1 points are distinct.
Output
Print two integers β the coordinates of the point that is not on the boundary of the square.
Examples
Input
2
0 0
0 1
0 2
1 0
1 1
1 2
2 0
2 1
2 2
Output
1 1
Input
2
0 0
0 1
0 2
0 3
1 0
1 2
2 0
2 1
2 2
Output
0 3
Note
In both examples, the square has four sides x=0, x=2, y=0, y=2. | instruction | 0 | 83,445 | 23 | 166,890 |
Tags: implementation
Correct Solution:
```
# -*- coding: utf-8 -*-
import sys
from operator import itemgetter
from fractions import gcd
from math import ceil, floor
from copy import deepcopy
from itertools import accumulate
from collections import Counter
import math
from functools import reduce
from bisect import bisect_right
sys.setrecursionlimit(200000)
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
def debug(x): print("debug: ", x, file=sys.stderr)
# template
def main():
n = ii()
a = [tuple(mi()) for i in range(4 * n + 1)]
# print(a)
for x in range(60):
for y in range(60):
for m in range(60):
ans = []
for i in range(4 * n + 1):
if ((x == a[i][0] or x + m == a[i][0]) and y <= a[i][1] <= y+m) or ((y == a[i][1] or y + m == a[i][1]) and x <= a[i][0] <= x+m):
continue
else:
ans.append(a[i])
if len(ans) == 1:
# print(x, y, m)
print(ans[0][0], ans[0][1])
sys.exit()
if __name__ == '__main__':
main()
``` | output | 1 | 83,445 | 23 | 166,891 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Cybermen and the Daleks have long been the Doctor's main enemies. Everyone knows that both these species enjoy destroying everything they encounter. However, a little-known fact about them is that they both also love taking Turing tests!
Heidi designed a series of increasingly difficult tasks for them to spend their time on, which would allow the Doctor enough time to save innocent lives!
The funny part is that these tasks would be very easy for a human to solve.
The first task is as follows. There are some points on the plane. All but one of them are on the boundary of an axis-aligned square (its sides are parallel to the axes). Identify that point.
Input
The first line contains an integer n (2 β€ n β€ 10).
Each of the following 4n + 1 lines contains two integers x_i, y_i (0 β€ x_i, y_i β€ 50), describing the coordinates of the next point.
It is guaranteed that there are at least n points on each side of the square and all 4n + 1 points are distinct.
Output
Print two integers β the coordinates of the point that is not on the boundary of the square.
Examples
Input
2
0 0
0 1
0 2
1 0
1 1
1 2
2 0
2 1
2 2
Output
1 1
Input
2
0 0
0 1
0 2
0 3
1 0
1 2
2 0
2 1
2 2
Output
0 3
Note
In both examples, the square has four sides x=0, x=2, y=0, y=2. | instruction | 0 | 83,446 | 23 | 166,892 |
Tags: implementation
Correct Solution:
```
import io, os
input = io.StringIO(os.read(0, os.fstat(0).st_size).decode()).readline
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())
n = ii()
a = [li() for _ in range(4 * n + 1)]
lox = min(p[0] for p in a)
hix = max(p[0] for p in a)
loy = min(p[1] for p in a)
hiy = max(p[1] for p in a)
loxs = [i for i in range(len(a)) if a[i][0] == lox]
hixs = [i for i in range(len(a)) if a[i][0] == hix]
loys = [i for i in range(len(a)) if a[i][1] == loy]
hiys = [i for i in range(len(a)) if a[i][1] == hiy]
singles = [s for s in (loxs, hixs, loys, hiys) if len(s) == 1]
if not singles:
alls = set(loxs + hixs + loys + hiys)
ans = [i for i in range(len(a)) if i not in alls][0]
else:
ans = singles[0][0]
print(*a[ans])
``` | output | 1 | 83,446 | 23 | 166,893 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Cybermen and the Daleks have long been the Doctor's main enemies. Everyone knows that both these species enjoy destroying everything they encounter. However, a little-known fact about them is that they both also love taking Turing tests!
Heidi designed a series of increasingly difficult tasks for them to spend their time on, which would allow the Doctor enough time to save innocent lives!
The funny part is that these tasks would be very easy for a human to solve.
The first task is as follows. There are some points on the plane. All but one of them are on the boundary of an axis-aligned square (its sides are parallel to the axes). Identify that point.
Input
The first line contains an integer n (2 β€ n β€ 10).
Each of the following 4n + 1 lines contains two integers x_i, y_i (0 β€ x_i, y_i β€ 50), describing the coordinates of the next point.
It is guaranteed that there are at least n points on each side of the square and all 4n + 1 points are distinct.
Output
Print two integers β the coordinates of the point that is not on the boundary of the square.
Examples
Input
2
0 0
0 1
0 2
1 0
1 1
1 2
2 0
2 1
2 2
Output
1 1
Input
2
0 0
0 1
0 2
0 3
1 0
1 2
2 0
2 1
2 2
Output
0 3
Note
In both examples, the square has four sides x=0, x=2, y=0, y=2. | instruction | 0 | 83,447 | 23 | 166,894 |
Tags: implementation
Correct Solution:
```
#!/usr/bin/env python3
import sys
import math
import cProfile
DEBUG = False
if DEBUG:
sys.stdin = open('input.txt')
pr = cProfile.Profile()
pr.enable()
n = sys.stdin.readline()
n = int(n)
# Init global variables.
points = []
for i in range(4 * n + 1):
x, y = sys.stdin.readline().split()
points.append((int(x), int(y)))
for i in range(4 * n + 1):
p = points[:]
del p[i]
p = [{'key': _, 'value': 0} for _ in p]
p.sort(key=lambda x:x['key'][0])
tot1 = 0
tot2 = 0
for item in p:
if item['key'][0] == p[0]['key'][0]:
tot1 = tot1 + 1
item['value'] = 1
if item['key'][0] == p[-1]['key'][0]:
tot2 = tot2 + 1
item['value'] = 1
if tot1 < n or tot2 < n:
continue
p.sort(key=lambda x:x['key'][1])
tot1 = 0
tot2 = 0
for item in p:
if item['key'][1] == p[0]['key'][1]:
tot1 = tot1 + 1
item['value'] = 1
if item['key'][1] == p[-1]['key'][1]:
tot2 = tot2 + 1
item['value'] = 1
if tot1 < n or tot2 < n:
continue
if all([_['value'] for _ in p]):
break
print(points[i][0], points[i][1])
if DEBUG:
pr.disable()
pr.print_stats()
``` | output | 1 | 83,447 | 23 | 166,895 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Cybermen and the Daleks have long been the Doctor's main enemies. Everyone knows that both these species enjoy destroying everything they encounter. However, a little-known fact about them is that they both also love taking Turing tests!
Heidi designed a series of increasingly difficult tasks for them to spend their time on, which would allow the Doctor enough time to save innocent lives!
The funny part is that these tasks would be very easy for a human to solve.
The first task is as follows. There are some points on the plane. All but one of them are on the boundary of an axis-aligned square (its sides are parallel to the axes). Identify that point.
Input
The first line contains an integer n (2 β€ n β€ 10).
Each of the following 4n + 1 lines contains two integers x_i, y_i (0 β€ x_i, y_i β€ 50), describing the coordinates of the next point.
It is guaranteed that there are at least n points on each side of the square and all 4n + 1 points are distinct.
Output
Print two integers β the coordinates of the point that is not on the boundary of the square.
Examples
Input
2
0 0
0 1
0 2
1 0
1 1
1 2
2 0
2 1
2 2
Output
1 1
Input
2
0 0
0 1
0 2
0 3
1 0
1 2
2 0
2 1
2 2
Output
0 3
Note
In both examples, the square has four sides x=0, x=2, y=0, y=2.
Submitted Solution:
```
import sys
from math import log2
import bisect
import heapq
# from collections import deque
# from types import GeneratorType
# def bootstrap(func, stack=[]):
# def wrapped_function(*args, **kwargs):
# if stack:
# return func(*args, **kwargs)
# else:
# call = func(*args, **kwargs)
# while True:
# if type(call) is GeneratorType:
# stack.append(call)
# call = next(call)
# else:
# stack.pop()
# if not stack:
# break
# call = stack[-1].send(call)
# return call
# return wrapped_function
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 18
MOD = 10**9+7
n = int(ri())
arr = []
for i in range(4*n+1):
temp = Ri()
arr.append(temp)
flag = False
tans = []
for i in range(0,51):
for j in range(i+1,51):
for k in range(0,51):
cnt = 0
ans = []
x1,x2,y1,y2 = i,j,k,(k+(j-i))
flag = False
for r in arr:
a,b = r
if ((a==x1 or a==x2 ) and y1 <= b <= y2) or ((b==y1 or b==y2 ) and x1 <= a <= x2):
continue
else:
cnt+=1
ans = [a,b]
# print(cnt)
if cnt == 1 :
# print("sf")
flag = True
tans = ans
break
if flag :
break
if flag :
break
print(*tans)
``` | instruction | 0 | 83,448 | 23 | 166,896 |
Yes | output | 1 | 83,448 | 23 | 166,897 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Cybermen and the Daleks have long been the Doctor's main enemies. Everyone knows that both these species enjoy destroying everything they encounter. However, a little-known fact about them is that they both also love taking Turing tests!
Heidi designed a series of increasingly difficult tasks for them to spend their time on, which would allow the Doctor enough time to save innocent lives!
The funny part is that these tasks would be very easy for a human to solve.
The first task is as follows. There are some points on the plane. All but one of them are on the boundary of an axis-aligned square (its sides are parallel to the axes). Identify that point.
Input
The first line contains an integer n (2 β€ n β€ 10).
Each of the following 4n + 1 lines contains two integers x_i, y_i (0 β€ x_i, y_i β€ 50), describing the coordinates of the next point.
It is guaranteed that there are at least n points on each side of the square and all 4n + 1 points are distinct.
Output
Print two integers β the coordinates of the point that is not on the boundary of the square.
Examples
Input
2
0 0
0 1
0 2
1 0
1 1
1 2
2 0
2 1
2 2
Output
1 1
Input
2
0 0
0 1
0 2
0 3
1 0
1 2
2 0
2 1
2 2
Output
0 3
Note
In both examples, the square has four sides x=0, x=2, y=0, y=2.
Submitted Solution:
```
from collections import defaultdict
n = int(input())
dx = defaultdict(int)
dy = defaultdict(int)
mx = my = 0
lx = ly = 100
s = set()
for i in range(4 * n + 1):
x, y = map(int, input().split())
s.add((x, y))
dx[x] += 1
dy[y] += 1
if dx[x] > 1:
if x > mx:
mx = x
if x < lx:
lx = x
if dy[y] > 1:
if y > my:
my = y
if y < ly:
ly = y
for el in s:
if ((lx < el[0] < mx) and (ly < el[1] < my)) or el[0] < lx or el[0] > mx or el[1] < ly or el[1] > my:
print(*el)
``` | instruction | 0 | 83,449 | 23 | 166,898 |
Yes | output | 1 | 83,449 | 23 | 166,899 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Cybermen and the Daleks have long been the Doctor's main enemies. Everyone knows that both these species enjoy destroying everything they encounter. However, a little-known fact about them is that they both also love taking Turing tests!
Heidi designed a series of increasingly difficult tasks for them to spend their time on, which would allow the Doctor enough time to save innocent lives!
The funny part is that these tasks would be very easy for a human to solve.
The first task is as follows. There are some points on the plane. All but one of them are on the boundary of an axis-aligned square (its sides are parallel to the axes). Identify that point.
Input
The first line contains an integer n (2 β€ n β€ 10).
Each of the following 4n + 1 lines contains two integers x_i, y_i (0 β€ x_i, y_i β€ 50), describing the coordinates of the next point.
It is guaranteed that there are at least n points on each side of the square and all 4n + 1 points are distinct.
Output
Print two integers β the coordinates of the point that is not on the boundary of the square.
Examples
Input
2
0 0
0 1
0 2
1 0
1 1
1 2
2 0
2 1
2 2
Output
1 1
Input
2
0 0
0 1
0 2
0 3
1 0
1 2
2 0
2 1
2 2
Output
0 3
Note
In both examples, the square has four sides x=0, x=2, y=0, y=2.
Submitted Solution:
```
# https://codeforces.com/contest/1184/problem/C1
n = int(input())
p = []
dx = {}
dy = {}
min_x = None
max_x = None
min_y = None
max_y = None
for _ in range(4*n+1):
x, y = map(int, input().split())
p.append([x, y])
if x not in dx:
dx[x] = 0
dx[x] += 1
if y not in dy:
dy[y] = 0
dy[y] += 1
for x in sorted(dx.keys()):
if dx[x] >= n:
min_x = x
break
for x in sorted(dx.keys())[::-1]:
if dx[x] >= n:
max_x = x
break
for y in sorted(dy.keys()):
if dy[y] >= n:
min_y = y
break
for y in sorted(dy.keys())[::-1]:
if dy[y] >= n:
max_y = y
break
outlier = None
#print((min_x, max_x), (min_y, max_y))
for x, y in p:
if (x-min_x)*(x-max_x) <= 0 and (y-min_y)*(y-max_y) <= 0:
if (x-min_x)*(x-max_x) < 0 and (y-min_y)*(y-max_y) < 0:
outlier = x, y
break
else:
outlier = x, y
break
print(' '.join([str(x) for x in outlier]))
#2
#0 0
#0 1
#0 2
#1 0
#1 1
#1 2
#2 0
#2 1
#2 2
``` | instruction | 0 | 83,450 | 23 | 166,900 |
Yes | output | 1 | 83,450 | 23 | 166,901 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Cybermen and the Daleks have long been the Doctor's main enemies. Everyone knows that both these species enjoy destroying everything they encounter. However, a little-known fact about them is that they both also love taking Turing tests!
Heidi designed a series of increasingly difficult tasks for them to spend their time on, which would allow the Doctor enough time to save innocent lives!
The funny part is that these tasks would be very easy for a human to solve.
The first task is as follows. There are some points on the plane. All but one of them are on the boundary of an axis-aligned square (its sides are parallel to the axes). Identify that point.
Input
The first line contains an integer n (2 β€ n β€ 10).
Each of the following 4n + 1 lines contains two integers x_i, y_i (0 β€ x_i, y_i β€ 50), describing the coordinates of the next point.
It is guaranteed that there are at least n points on each side of the square and all 4n + 1 points are distinct.
Output
Print two integers β the coordinates of the point that is not on the boundary of the square.
Examples
Input
2
0 0
0 1
0 2
1 0
1 1
1 2
2 0
2 1
2 2
Output
1 1
Input
2
0 0
0 1
0 2
0 3
1 0
1 2
2 0
2 1
2 2
Output
0 3
Note
In both examples, the square has four sides x=0, x=2, y=0, y=2.
Submitted Solution:
```
#!/usr/bin/env python3
import sys
import math
import cProfile
DEBUG = False
if DEBUG:
sys.stdin = open('input.txt')
pr = cProfile.Profile()
pr.enable()
n = sys.stdin.readline()
n = int(n)
# Init global variables.
points = []
for i in range(4 * n + 1):
x, y = sys.stdin.readline().split()
points.append((int(x), int(y)))
for k in range(4 * n + 1):
p = points[:]
del p[k]
x_cnt = {}
y_cnt = {}
for i in range(4 * n):
x_cnt[p[i][0]] = x_cnt.get(p[i][0], 0) + 1
p.sort(key=lambda x:x[1])
for i in range(4 * n):
y_cnt[p[i][1]] = y_cnt.get(p[i][1], 0) + 1
x_v = list(x_cnt.values())
y_v = list(y_cnt.values())
if x_v[0] >= n and x_v[-1] >= n and y_v[0] >= n and y_v[-1] >= n:
break
print(points[k][0], points[k][1])
if DEBUG:
pr.disable()
pr.print_stats()
``` | instruction | 0 | 83,453 | 23 | 166,906 |
No | output | 1 | 83,453 | 23 | 166,907 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Cybermen and the Daleks have long been the Doctor's main enemies. Everyone knows that both these species enjoy destroying everything they encounter. However, a little-known fact about them is that they both also love taking Turing tests!
Heidi designed a series of increasingly difficult tasks for them to spend their time on, which would allow the Doctor enough time to save innocent lives!
The funny part is that these tasks would be very easy for a human to solve.
The first task is as follows. There are some points on the plane. All but one of them are on the boundary of an axis-aligned square (its sides are parallel to the axes). Identify that point.
Input
The first line contains an integer n (2 β€ n β€ 10).
Each of the following 4n + 1 lines contains two integers x_i, y_i (0 β€ x_i, y_i β€ 50), describing the coordinates of the next point.
It is guaranteed that there are at least n points on each side of the square and all 4n + 1 points are distinct.
Output
Print two integers β the coordinates of the point that is not on the boundary of the square.
Examples
Input
2
0 0
0 1
0 2
1 0
1 1
1 2
2 0
2 1
2 2
Output
1 1
Input
2
0 0
0 1
0 2
0 3
1 0
1 2
2 0
2 1
2 2
Output
0 3
Note
In both examples, the square has four sides x=0, x=2, y=0, y=2.
Submitted Solution:
```
# !/usr/bin/env python3
# encoding: UTF-8
# Modified: <07/Jul/2019 04:42:45 PM>
# βͺ H4WK3yEδΉ‘
# Mohd. Farhan Tahir
# Indian Institute Of Information Technology (IIIT), Gwalior
import sys
import os
from io import IOBase, BytesIO
from math import sqrt
def dist(a, b):
return (a[0] - b[0])**2 + (a[1] - b[1])**2
def validsquare(a, b, c, d):
p = [a, b, c, d]
p.sort()
x1, y1 = a[0], a[1]
x2, y2 = b[0], b[1]
from math import atan2, degrees
ang = abs(degrees(atan2(y2 - y1, x2 - x1)))
if ang == 90 or ang == 0:
return dist(p[0], p[1]) == dist(p[1], p[3]) and dist(p[1], p[3]) == dist(p[3], p[2]) and dist(p[3], p[2]) == dist(p[2], p[0]) and dist(p[0], p[3]) == dist(p[1], p[2])
return ang
def main():
n = int(input())
points = [0] * (4 * n + 1)
for i in range(4 * n + 1):
a, b = get_ints()
points[i] = (a, b)
l = 4 * n + 1
points.sort()
for i in range(l):
for j in range(i + 1, l):
for k in range(j + 1, l):
for m in range(k + 1, l):
a, b, c, d = points[i], points[j], points[k], points[m]
if (validsquare(a, b, c, d)) == True:
mnx = min(a[0], b[0], c[0], d[0])
mxx = max(a[0], b[0], c[0], d[0])
mny = min(a[1], b[1], c[1], d[1])
mxy = max(a[1], b[1], c[1], d[1])
cnt = 0
op = []
for point in points:
x = point[0]
y = point[1]
if (x in a or x in b or x in c or x in d or y in a or y in b or y in c or y in d) and x >= mnx and x <= mxx and y >= mny and y <= mxy:
cnt += 1
else:
op.append((x, y))
if cnt == 4 * n:
print(op[0][0], op[0][1])
return
BUFSIZE = 8192
class FastIO(BytesIO):
newlines = 0
def __init__(self, file):
self._file = file
self._fd = file.fileno()
self.writable = "x" in file.mode or "w" in file.mode
self.write = super(FastIO, self).write if self.writable else None
def _fill(self):
s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
return s
def read(self):
while self._fill():
pass
return super(FastIO, self).read()
def readline(self):
while self.newlines == 0:
s = self._fill()
self.newlines = s.count(b"\n") + (not s)
self.newlines -= 1
return super(FastIO, self).readline()
def flush(self):
if self.writable:
os.write(self._fd, self.getvalue())
self.truncate(0), self.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
py2 = round(0.5)
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
if py2 == 1:
self.write = self.buffer.write
self.read = self.buffer.read
self.readline = self.buffer.readline
else:
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
def get_array(): return list(map(int, sys.stdin.readline().split()))
def get_ints(): return map(int, sys.stdin.readline().split())
def input(): return sys.stdin.readline().strip()
if __name__ == "__main__":
main()
``` | instruction | 0 | 83,454 | 23 | 166,908 |
No | output | 1 | 83,454 | 23 | 166,909 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Cybermen and the Daleks have long been the Doctor's main enemies. Everyone knows that both these species enjoy destroying everything they encounter. However, a little-known fact about them is that they both also love taking Turing tests!
Heidi designed a series of increasingly difficult tasks for them to spend their time on, which would allow the Doctor enough time to save innocent lives!
The funny part is that these tasks would be very easy for a human to solve.
The first task is as follows. There are some points on the plane. All but one of them are on the boundary of an axis-aligned square (its sides are parallel to the axes). Identify that point.
Input
The first line contains an integer n (2 β€ n β€ 10).
Each of the following 4n + 1 lines contains two integers x_i, y_i (0 β€ x_i, y_i β€ 50), describing the coordinates of the next point.
It is guaranteed that there are at least n points on each side of the square and all 4n + 1 points are distinct.
Output
Print two integers β the coordinates of the point that is not on the boundary of the square.
Examples
Input
2
0 0
0 1
0 2
1 0
1 1
1 2
2 0
2 1
2 2
Output
1 1
Input
2
0 0
0 1
0 2
0 3
1 0
1 2
2 0
2 1
2 2
Output
0 3
Note
In both examples, the square has four sides x=0, x=2, y=0, y=2.
Submitted Solution:
```
n = int(input())
points = list(tuple(map(int, input().split())) for i in range(4*n + 1))
xs = list(sorted(points))
ys = list(sorted(points, key = lambda x: (x[1], x[0])))
xsize = xs[-1][0] - xs[0][0]
ysize = ys[-1][1] - ys[0][1]
if xsize == ysize:
for p in points:
if p[0] != xs[0][0] and p[0] != xs[-1][0] and p[1] != ys[-1][1] and p[1] != ys[0][1]:
print(p[0], p[1])
else:
if xs[-2][0] - xs[0][0] == ysize:
print(xs[-1][0], xs[-1][1])
elif xs[-1][0] - xs[1][0] == ysize:
print(xs[0][0], xs[0][1])
elif ys[-2][0] - ys[0][0] == xsize:
print(ys[-1][0], ys[-1][1])
elif ys[-1][0] - ys[1][0] == xsize:
print(ys[0][0], ys[0][1])
``` | instruction | 0 | 83,455 | 23 | 166,910 |
No | output | 1 | 83,455 | 23 | 166,911 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A binary matrix is called good if every even length square sub-matrix has an odd number of ones.
Given a binary matrix a consisting of n rows and m columns, determine the minimum number of cells you need to change to make it good, or report that there is no way to make it good at all.
All the terms above have their usual meanings β refer to the Notes section for their formal definitions.
Input
The first line of input contains two integers n and m (1 β€ n β€ m β€ 10^6 and nβ
m β€ 10^6) β the number of rows and columns in a, respectively.
The following n lines each contain m characters, each of which is one of 0 and 1. If the j-th character on the i-th line is 1, then a_{i,j} = 1. Similarly, if the j-th character on the i-th line is 0, then a_{i,j} = 0.
Output
Output the minimum number of cells you need to change to make a good, or output -1 if it's not possible at all.
Examples
Input
3 3
101
001
110
Output
2
Input
7 15
000100001010010
100111010110001
101101111100100
010000111111010
111010010100001
000011001111101
111111011010011
Output
-1
Note
In the first case, changing a_{1,1} to 0 and a_{2,2} to 1 is enough.
You can verify that there is no way to make the matrix in the second case good.
Some definitions β
* A binary matrix is one in which every element is either 1 or 0.
* A sub-matrix is described by 4 parameters β r_1, r_2, c_1, and c_2; here, 1 β€ r_1 β€ r_2 β€ n and 1 β€ c_1 β€ c_2 β€ m.
* This sub-matrix contains all elements a_{i,j} that satisfy both r_1 β€ i β€ r_2 and c_1 β€ j β€ c_2.
* A sub-matrix is, further, called an even length square if r_2-r_1 = c_2-c_1 and r_2-r_1+1 is divisible by 2.
Submitted Solution:
```
import sys
def input():
return sys.stdin.readline().rstrip()
def input_split():
return [int(i) for i in input().split()]
# testCases = int(input())
# answers = []
# for _ in range(testCases):
#take input
n, m = input_split()
grid = []
for _ in range(n):
grid.append([int(i) for i in input()])
# def binary(a):
# def is_good_square(grid, row, col):
# ans = 0
# for i in range(row, row + 2):
# for j in range(col, col + 2):
# if grid[i][j] == '1':
# ans += 1
# return ans
if n >= 4 and m >= 4:
ans = -1
elif n< 2 or m < 2:
ans = 0
else:
# oss = list(range(2**(n*m)))
if n == 2 or m == 2:
if n == 2:
arr = []
for i in range(m):
arr.append((grid[0][i] + grid[1][i])%2)
elif m == 2:
arr = []
for i in range(n):
arr.append((grid[i][0] + grid[i][1])%2)
cost1 = 0
cost2 = 0
current = 0
for i in range(len(arr)):
cost1 += abs(current - arr[i])
cost2 += abs((1-current) - arr[i])
current = 1 - current
ans = min(cost1, cost2)
elif n == 3 or m == 3:
if n == 3:
arr1 = []
arr2 = []
for i in range(m):
arr1.append((grid[0][i] + grid[1][i])%2)
arr2.append((grid[1][i] + grid[2][i])%2)
else:
#m must be 3
arr1 = []
arr2 = []
for i in range(n):
arr1.append((grid[i][0] + grid[i][1])%2)
arr2.append((grid[i][1] + grid[i][2])%2)
#analysis
#case1
# start = 0
# cost1 = 0
cost1 = 0
cost2 = 0
cost3 = 0
cost4 = 0
current = 0
for i in range(len(arr1)):
cost1 += max(abs(current - arr1[i]),abs(current - arr2[i]) )
cost3 += max(abs(current - arr1[i]),abs((1-current) - arr2[i]) )
cost2 += max(abs((1-current) - arr1[i]), abs((1-current) - arr2[i]))
cost4 += max(abs((1-current) - arr1[i]), abs((current) - arr2[i]))
current = 1 - current
ans = min(cost1, cost2, cost3, cost4)
print(ans)
# answers.append(ans)
# print(*answers, sep = '\n')
``` | instruction | 0 | 83,581 | 23 | 167,162 |
Yes | output | 1 | 83,581 | 23 | 167,163 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A binary matrix is called good if every even length square sub-matrix has an odd number of ones.
Given a binary matrix a consisting of n rows and m columns, determine the minimum number of cells you need to change to make it good, or report that there is no way to make it good at all.
All the terms above have their usual meanings β refer to the Notes section for their formal definitions.
Input
The first line of input contains two integers n and m (1 β€ n β€ m β€ 10^6 and nβ
m β€ 10^6) β the number of rows and columns in a, respectively.
The following n lines each contain m characters, each of which is one of 0 and 1. If the j-th character on the i-th line is 1, then a_{i,j} = 1. Similarly, if the j-th character on the i-th line is 0, then a_{i,j} = 0.
Output
Output the minimum number of cells you need to change to make a good, or output -1 if it's not possible at all.
Examples
Input
3 3
101
001
110
Output
2
Input
7 15
000100001010010
100111010110001
101101111100100
010000111111010
111010010100001
000011001111101
111111011010011
Output
-1
Note
In the first case, changing a_{1,1} to 0 and a_{2,2} to 1 is enough.
You can verify that there is no way to make the matrix in the second case good.
Some definitions β
* A binary matrix is one in which every element is either 1 or 0.
* A sub-matrix is described by 4 parameters β r_1, r_2, c_1, and c_2; here, 1 β€ r_1 β€ r_2 β€ n and 1 β€ c_1 β€ c_2 β€ m.
* This sub-matrix contains all elements a_{i,j} that satisfy both r_1 β€ i β€ r_2 and c_1 β€ j β€ c_2.
* A sub-matrix is, further, called an even length square if r_2-r_1 = c_2-c_1 and r_2-r_1+1 is divisible by 2.
Submitted Solution:
```
# by the authority of GOD author: manhar singh sachdev #
import os,sys
from io import BytesIO, IOBase
def main():
n,m = map(int,input().split())
arr = [list(input().strip()) for _ in range(n)]
if n >= 4 and m >= 4:
print(-1)
elif n == 1 or m == 1:
print(0)
else:
ans = 10**10
if m==3 or n==3:
pos = ['000','100','010','001','110','101','011','111']
if m == 3:
for i in pos:
fin = (arr[0][0]==i[0])+(arr[0][1]==i[1])+(arr[0][2]==i[2])
fis,sec = (int(i[0])+int(i[1])+1)%2,(int(i[1])+int(i[2])+1)%2
for j in range(1,n):
s = 0
if (int(arr[j][0])+int(arr[j][1]))%2 != fis:
s += 1
if (int(arr[j][1])+int(arr[j][2]))%2 != sec:
s += 1
if s == 2:
s -= 1
fin += s
fis ^= 1
sec ^= 1
ans = min(ans,fin)
elif n == 3:
for i in pos:
fin = (arr[0][0]==i[0])+(arr[1][0]==i[1])+(arr[2][0]==i[2])
fis,sec = (int(i[0])+int(i[1])+1)%2,(int(i[1])+int(i[2])+1)%2
for j in range(1,m):
s = 0
if (int(arr[0][j])+int(arr[1][j]))%2 != fis:
s += 1
if (int(arr[1][j])+int(arr[2][j]))%2 != sec:
s += 1
if s == 2:
s -= 1
fin += s
fis ^= 1
sec ^= 1
ans = min(ans,fin)
elif m==2 or n==2:
pos = ['00', '10', '01', '11']
if m == 2:
for i in pos:
fin = (arr[0][0]==i[0])+(arr[0][1]==i[1])
fis = (int(i[0])+int(i[1])+1)%2
for j in range(1,n):
s = 0
if (int(arr[j][0])+int(arr[j][1]))%2!=fis:
s += 1
fin += s
fis ^= 1
ans = min(ans, fin)
elif n == 2:
for i in pos:
fin = (arr[0][0] == i[0]) + (arr[1][0] == i[1])
fis = (int(i[0])+int(i[1])+1)%2
for j in range(1,m):
s = 0
if (int(arr[0][j])+int(arr[1][j])) % 2 != fis:
s += 1
fin += s
fis ^= 1
ans = min(ans, fin)
print(ans)
#Fast IO Region
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
if __name__ == '__main__':
main()
``` | instruction | 0 | 83,582 | 23 | 167,164 |
Yes | output | 1 | 83,582 | 23 | 167,165 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A binary matrix is called good if every even length square sub-matrix has an odd number of ones.
Given a binary matrix a consisting of n rows and m columns, determine the minimum number of cells you need to change to make it good, or report that there is no way to make it good at all.
All the terms above have their usual meanings β refer to the Notes section for their formal definitions.
Input
The first line of input contains two integers n and m (1 β€ n β€ m β€ 10^6 and nβ
m β€ 10^6) β the number of rows and columns in a, respectively.
The following n lines each contain m characters, each of which is one of 0 and 1. If the j-th character on the i-th line is 1, then a_{i,j} = 1. Similarly, if the j-th character on the i-th line is 0, then a_{i,j} = 0.
Output
Output the minimum number of cells you need to change to make a good, or output -1 if it's not possible at all.
Examples
Input
3 3
101
001
110
Output
2
Input
7 15
000100001010010
100111010110001
101101111100100
010000111111010
111010010100001
000011001111101
111111011010011
Output
-1
Note
In the first case, changing a_{1,1} to 0 and a_{2,2} to 1 is enough.
You can verify that there is no way to make the matrix in the second case good.
Some definitions β
* A binary matrix is one in which every element is either 1 or 0.
* A sub-matrix is described by 4 parameters β r_1, r_2, c_1, and c_2; here, 1 β€ r_1 β€ r_2 β€ n and 1 β€ c_1 β€ c_2 β€ m.
* This sub-matrix contains all elements a_{i,j} that satisfy both r_1 β€ i β€ r_2 and c_1 β€ j β€ c_2.
* A sub-matrix is, further, called an even length square if r_2-r_1 = c_2-c_1 and r_2-r_1+1 is divisible by 2.
Submitted Solution:
```
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
if n == 1 or m == 1:
print(0)
exit()
field = []
for _ in range(n):
field.append([int(item) for item in input().rstrip()])
if n < m:
n, m = m, n
nfield = []
for col in zip(*field):
nfield.append(list(col))
field = nfield[:]
nums = []
for line in field:
val = 0
for i, item in enumerate(line):
val += item << i
nums.append(val)
if m == 2:
ans = n * m
for i in range(2):
parity = i
diff = 0
for j, num in enumerate(nums):
if parity == 0:
diff += min(bin(num ^ 3).count("1"), bin(num ^ 0).count("1"))
else:
diff += min(bin(num ^ 1).count("1"), bin(num ^ 2).count("1"))
parity = 1 - parity
ans = min(ans, diff)
elif m == 3:
ans = n * m
# Check 000, 010, 101, 111
for i in range(2):
parity = i
diff = 0
for j, num in enumerate(nums):
if parity == 0:
c1 = bin(num ^ 5).count("1")
c2 = bin(num ^ 2).count("1")
if c1 < c2:
diff += c1
else:
diff += c2
else:
c1 = bin(num ^ 0).count("1")
c2 = bin(num ^ 7).count("1")
if c1 < c2:
diff += c1
else:
diff += c2
parity = 1 - parity
ans = min(ans, diff)
for i in range(2):
parity = i
diff = 0
for j, num in enumerate(nums):
if parity == 0:
c1 = bin(num ^ 1).count("1")
c2 = bin(num ^ 6).count("1")
if c1 < c2:
diff += c1
else:
diff += c2
else:
c1 = bin(num ^ 4).count("1")
c2 = bin(num ^ 3).count("1")
if c1 < c2:
diff += c1
else:
diff += c2
parity = 1 - parity
ans = min(ans, diff)
# Check 001, 011, 100, 110
# states = [1, 3, 4, 6]
# dp = [[n * m] * 4 for _ in range(n+1)]
# for i in range(4):
# dp[0][i] = 0
# for i, num in enumerate(nums):
# for j, frm in enumerate(states):
# for k, too in enumerate(states):
# if frm == too or frm ^ too == 7:
# continue
# dp[i+1][k] = min(dp[i+1][k], dp[i][j] + bin(too ^ num).count("1"))
# for i in range(4):
# ans = min(ans, dp[n][i])
else:
print(-1)
exit()
print(ans)
``` | instruction | 0 | 83,583 | 23 | 167,166 |
Yes | output | 1 | 83,583 | 23 | 167,167 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A binary matrix is called good if every even length square sub-matrix has an odd number of ones.
Given a binary matrix a consisting of n rows and m columns, determine the minimum number of cells you need to change to make it good, or report that there is no way to make it good at all.
All the terms above have their usual meanings β refer to the Notes section for their formal definitions.
Input
The first line of input contains two integers n and m (1 β€ n β€ m β€ 10^6 and nβ
m β€ 10^6) β the number of rows and columns in a, respectively.
The following n lines each contain m characters, each of which is one of 0 and 1. If the j-th character on the i-th line is 1, then a_{i,j} = 1. Similarly, if the j-th character on the i-th line is 0, then a_{i,j} = 0.
Output
Output the minimum number of cells you need to change to make a good, or output -1 if it's not possible at all.
Examples
Input
3 3
101
001
110
Output
2
Input
7 15
000100001010010
100111010110001
101101111100100
010000111111010
111010010100001
000011001111101
111111011010011
Output
-1
Note
In the first case, changing a_{1,1} to 0 and a_{2,2} to 1 is enough.
You can verify that there is no way to make the matrix in the second case good.
Some definitions β
* A binary matrix is one in which every element is either 1 or 0.
* A sub-matrix is described by 4 parameters β r_1, r_2, c_1, and c_2; here, 1 β€ r_1 β€ r_2 β€ n and 1 β€ c_1 β€ c_2 β€ m.
* This sub-matrix contains all elements a_{i,j} that satisfy both r_1 β€ i β€ r_2 and c_1 β€ j β€ c_2.
* A sub-matrix is, further, called an even length square if r_2-r_1 = c_2-c_1 and r_2-r_1+1 is divisible by 2.
Submitted Solution:
```
#!/usr/bin/env pypy3
from sys import stdin, stdout, exit
def input():
return stdin.readline().strip()
def match_same(col):
if len(set(col)) == 1:
return 0
return 1
def match_exact(p, q):
ret = 0
for a,b in zip(p,q):
if a != b:
ret += 1
return ret
def match_diff(col):
if len(set(col)) == 1: return 1
if len(col) == 2: return 0
return min(
match_exact(col, (0,1,0)),
match_exact(col, (1,0,1))
)
def match_sd(col):
return min(
match_exact(col, (1,1,0)),
match_exact(col, (0,0,1))
)
def match_ds(col):
return min(
match_exact(col, (0,1,1)),
match_exact(col, (1,0,0))
)
def match(col, is_same):
if is_same:
return match_same(col)
else:
return match_diff(col)
def match_3(col, at_sd):
if at_sd:
return match_sd(col)
else:
return match_ds(col)
def ans_s(A):
is_same = True
ret = 0
for col in A:
ret += match(col, is_same)
is_same = not is_same
return ret
def ans_d(A):
is_same = False
ret = 0
for col in A:
ret += match(col, is_same)
is_same = not is_same
return ret
def ans_sd(A):
if len(A[0]) != 3: return float("inf")
at_sd = True
ret = 0
for col in A:
ret += match_3(col, at_sd)
at_sd = not at_sd
return ret
def ans_ds(A):
if len(A[0]) != 3: return float("inf")
at_sd = False
ret = 0
for col in A:
ret += match_3(col, at_sd)
at_sd = not at_sd
return ret
def ans(A):
return min(ans_s(A), ans_d(A), ans_sd(A), ans_ds(A))
n, m = input().split()
n = int(n)
m = int(m)
A = []
for _ in range(n):
A += [input()]
if n >= 4:
A = [tuple(map(int, row)) for row in A]
print(-1)
exit(0)
if n == 1:
print(0)
exit(0)
A = zip(*A)
A = [list(map(int, row)) for row in A]
print(ans(A))
``` | instruction | 0 | 83,584 | 23 | 167,168 |
Yes | output | 1 | 83,584 | 23 | 167,169 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A binary matrix is called good if every even length square sub-matrix has an odd number of ones.
Given a binary matrix a consisting of n rows and m columns, determine the minimum number of cells you need to change to make it good, or report that there is no way to make it good at all.
All the terms above have their usual meanings β refer to the Notes section for their formal definitions.
Input
The first line of input contains two integers n and m (1 β€ n β€ m β€ 10^6 and nβ
m β€ 10^6) β the number of rows and columns in a, respectively.
The following n lines each contain m characters, each of which is one of 0 and 1. If the j-th character on the i-th line is 1, then a_{i,j} = 1. Similarly, if the j-th character on the i-th line is 0, then a_{i,j} = 0.
Output
Output the minimum number of cells you need to change to make a good, or output -1 if it's not possible at all.
Examples
Input
3 3
101
001
110
Output
2
Input
7 15
000100001010010
100111010110001
101101111100100
010000111111010
111010010100001
000011001111101
111111011010011
Output
-1
Note
In the first case, changing a_{1,1} to 0 and a_{2,2} to 1 is enough.
You can verify that there is no way to make the matrix in the second case good.
Some definitions β
* A binary matrix is one in which every element is either 1 or 0.
* A sub-matrix is described by 4 parameters β r_1, r_2, c_1, and c_2; here, 1 β€ r_1 β€ r_2 β€ n and 1 β€ c_1 β€ c_2 β€ m.
* This sub-matrix contains all elements a_{i,j} that satisfy both r_1 β€ i β€ r_2 and c_1 β€ j β€ c_2.
* A sub-matrix is, further, called an even length square if r_2-r_1 = c_2-c_1 and r_2-r_1+1 is divisible by 2.
Submitted Solution:
```
import sys
sys.setrecursionlimit(10 ** 5)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]
h, w = MI()
aa = [list(map(int, list(SI()))) for _ in range(h)]
if min(h, w) > 3:
print(-1)
exit()
if min(h, w) == 1:
print(0)
exit()
if min(h, w) == 2:
if h != 2:
h, w = w, h
aa = [list(row) for row in zip(*aa)]
ans = 0
s = aa[0][0] ^ aa[1][0]
for j in range(w - 1):
if j - 1 < 0: s ^= aa[0][j + 1] ^ aa[1][j + 1]
else: s ^= aa[0][j + 1] ^ aa[1][j + 1] ^ aa[0][j - 1] ^ aa[1][j - 1]
if s == 0:
aa[1][j + 1] ^= 1
s ^= 1
ans += 1
print(ans)
if min(h, w) == 3:
if h != 3:
h, w = w, h
aa = [list(row) for row in zip(*aa)]
#p2D(aa)
# bb = [[0] * (w - 1) for _ in range(2)]
ij=[]
ans = 0
s1 = aa[0][0] ^ aa[1][0]
s2 = aa[1][0] ^ aa[2][0]
for j in range(w - 1):
s1 ^= aa[0][j + 1] ^ aa[1][j + 1]
s2 ^= aa[2][j + 1] ^ aa[1][j + 1]
if j - 1 >= 0:
s1 ^= aa[0][j - 1] ^ aa[1][j - 1]
s2 ^= aa[2][j - 1] ^ aa[1][j - 1]
if s1 == 0 and s2 == 0:
ans += 1
s1 ^= 1
s2 ^= 1
aa[1][j + 1] ^= 1
ij.append((1,j+1))
elif s1 == 0:
ans += 1
s1 ^= 1
aa[0][j + 1] ^= 1
ij.append((0,j+1))
elif s2 == 0:
ans += 1
s2 ^= 1
aa[2][j + 1] ^= 1
ij.append((2,j+1))
ans1 = ans
for i,j in ij:aa[i][j]^=1
ans = 0
s1 = aa[0][-1] ^ aa[1][-1]
s2 = aa[1][-1] ^ aa[2][-1]
for j in range(w - 2, -1, -1):
s1 ^= aa[0][j] ^ aa[1][j]
s2 ^= aa[2][j] ^ aa[1][j]
if j + 2 <= w - 1:
s1 ^= aa[0][j + 2] ^ aa[1][j + 2]
s2 ^= aa[2][j + 2] ^ aa[1][j + 2]
if s1 == 0 and s2 == 0:
ans += 1
s1 ^= 1
s2 ^= 1
aa[1][j] ^= 1
elif s1 == 0:
ans += 1
s1 ^= 1
aa[0][j] ^= 1
elif s2 == 0:
ans += 1
s2 ^= 1
aa[2][j] ^= 1
# bb[0][j] = s1
# bb[1][j] = s2
# p2D(bb)
print(min(ans,ans1))
``` | instruction | 0 | 83,585 | 23 | 167,170 |
No | output | 1 | 83,585 | 23 | 167,171 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A binary matrix is called good if every even length square sub-matrix has an odd number of ones.
Given a binary matrix a consisting of n rows and m columns, determine the minimum number of cells you need to change to make it good, or report that there is no way to make it good at all.
All the terms above have their usual meanings β refer to the Notes section for their formal definitions.
Input
The first line of input contains two integers n and m (1 β€ n β€ m β€ 10^6 and nβ
m β€ 10^6) β the number of rows and columns in a, respectively.
The following n lines each contain m characters, each of which is one of 0 and 1. If the j-th character on the i-th line is 1, then a_{i,j} = 1. Similarly, if the j-th character on the i-th line is 0, then a_{i,j} = 0.
Output
Output the minimum number of cells you need to change to make a good, or output -1 if it's not possible at all.
Examples
Input
3 3
101
001
110
Output
2
Input
7 15
000100001010010
100111010110001
101101111100100
010000111111010
111010010100001
000011001111101
111111011010011
Output
-1
Note
In the first case, changing a_{1,1} to 0 and a_{2,2} to 1 is enough.
You can verify that there is no way to make the matrix in the second case good.
Some definitions β
* A binary matrix is one in which every element is either 1 or 0.
* A sub-matrix is described by 4 parameters β r_1, r_2, c_1, and c_2; here, 1 β€ r_1 β€ r_2 β€ n and 1 β€ c_1 β€ c_2 β€ m.
* This sub-matrix contains all elements a_{i,j} that satisfy both r_1 β€ i β€ r_2 and c_1 β€ j β€ c_2.
* A sub-matrix is, further, called an even length square if r_2-r_1 = c_2-c_1 and r_2-r_1+1 is divisible by 2.
Submitted Solution:
```
from sys import stdin, exit
from bisect import bisect_left as bl, bisect_right as br
input = lambda: stdin.readline()[:-1]
intput = lambda: int(input())
sinput = lambda: input().split()
intsput = lambda: map(int, sinput())
def dprint(*args, **kwargs):
if debugging:
print(*args, **kwargs)
debugging = 1
# Code
n, m = intsput()
grid = []
for _ in range(n):
grid.append(list(map(int, input())))
if n >= 4 and m >= 4:
print(-1)
exit(0)
if n == 1 or m == 1:
print(0)
exit(0)
if n == 2:
odds_in_odds = 0
evens_in_evens = 0
for i in range(m):
val = grid[0][i] + grid[1][i]
if i % 2:
if val % 2:
odds_in_odds += 1
else:
if val % 2 == 0:
evens_in_evens += 1
changes = odds_in_odds + evens_in_evens
ans = min(n - changes, changes)
print(ans)
exit(0)
if m == 2:
odds_in_odds = 0
evens_in_evens = 0
for i in range(n):
val = grid[i][0] + grid[i][1]
if i % 2:
if val % 2:
odds_in_odds += 1
else:
if val % 2 == 0:
evens_in_evens += 1
changes = odds_in_odds + evens_in_evens
ans = min(n - changes, changes)
print(ans)
exit(0)
if n == 3:
odds_in_odds = set()
evens_in_evens = set()
for i in range(m):
val = grid[0][i] + grid[1][i]
if i % 2:
if val % 2:
odds_in_odds.add(i)
else:
if val % 2 == 0:
evens_in_evens.add(i)
odds_in_odds_ = 0
odd_extra_changes = 0
xxx = 0
evens_in_evens_ = 0
even_extra_changes = 0
yyy = 0
for i in range(m):
val = grid[1][i] + grid[2][i]
if i % 2:
if val % 2:
odds_in_odds_ += 1
if i not in odds_in_odds:
odd_extra_changes += 1
else:
if i in odds_in_odds:
xxx += 1
else:
if val % 2 == 0:
evens_in_evens_ += 1
if i not in evens_in_evens:
even_extra_changes += 1
else:
if i in evens_in_evens:
yyy += 1
a = len(odds_in_odds) + len(evens_in_evens) + odd_extra_changes + even_extra_changes
b = len(odds_in_odds) + len(evens_in_evens) + n - odds_in_odds_ - evens_in_evens_
c = n - len(odds_in_odds) - len(evens_in_evens) + xxx + yyy
d = n - len(odds_in_odds) - len(evens_in_evens) + odds_in_odds_ + evens_in_evens_
print(min(a, b, c, d))
exit(0)
if m == 3:
odds_in_odds = set()
evens_in_evens = set()
for i in range(n):
val = grid[i][0] + grid[i][0]
if i % 2:
if val % 2:
odds_in_odds.add(i)
else:
if val % 2 == 0:
evens_in_evens.add(i)
odds_in_odds_ = 0
odd_extra_changes = 0
xxx = 0
evens_in_evens_ = 0
even_extra_changes = 0
yyy = 0
for i in range(n):
val = grid[i][1] + grid[i][2]
if i % 2:
if val % 2:
odds_in_odds_ += 1
if i not in odds_in_odds:
odd_extra_changes += 1
else:
if i in odds_in_odds:
xxx += 1
else:
if val % 2 == 0:
evens_in_evens_ += 1
if i not in evens_in_evens:
even_extra_changes += 1
else:
if i in evens_in_evens:
yyy += 1
a = len(odds_in_odds) + len(evens_in_evens) + odd_extra_changes + even_extra_changes
b = len(odds_in_odds) + len(evens_in_evens) + n - odds_in_odds_ - evens_in_evens_
c = n - len(odds_in_odds) - len(evens_in_evens) + xxx + yyy
d = n - len(odds_in_odds) - len(evens_in_evens) + odds_in_odds_ + evens_in_evens_
print(min(a, b, c, d))
exit(0)
``` | instruction | 0 | 83,586 | 23 | 167,172 |
No | output | 1 | 83,586 | 23 | 167,173 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A binary matrix is called good if every even length square sub-matrix has an odd number of ones.
Given a binary matrix a consisting of n rows and m columns, determine the minimum number of cells you need to change to make it good, or report that there is no way to make it good at all.
All the terms above have their usual meanings β refer to the Notes section for their formal definitions.
Input
The first line of input contains two integers n and m (1 β€ n β€ m β€ 10^6 and nβ
m β€ 10^6) β the number of rows and columns in a, respectively.
The following n lines each contain m characters, each of which is one of 0 and 1. If the j-th character on the i-th line is 1, then a_{i,j} = 1. Similarly, if the j-th character on the i-th line is 0, then a_{i,j} = 0.
Output
Output the minimum number of cells you need to change to make a good, or output -1 if it's not possible at all.
Examples
Input
3 3
101
001
110
Output
2
Input
7 15
000100001010010
100111010110001
101101111100100
010000111111010
111010010100001
000011001111101
111111011010011
Output
-1
Note
In the first case, changing a_{1,1} to 0 and a_{2,2} to 1 is enough.
You can verify that there is no way to make the matrix in the second case good.
Some definitions β
* A binary matrix is one in which every element is either 1 or 0.
* A sub-matrix is described by 4 parameters β r_1, r_2, c_1, and c_2; here, 1 β€ r_1 β€ r_2 β€ n and 1 β€ c_1 β€ c_2 β€ m.
* This sub-matrix contains all elements a_{i,j} that satisfy both r_1 β€ i β€ r_2 and c_1 β€ j β€ c_2.
* A sub-matrix is, further, called an even length square if r_2-r_1 = c_2-c_1 and r_2-r_1+1 is divisible by 2.
Submitted Solution:
```
from functools import lru_cache
from sys import stdin, stdout
import sys
# from math import *
# from collections import deque
# sys.setrecursionlimit(int(2e5))
# input = stdin.readline
# print = stdout.write
# dp=[-1]*100000
n,m=map(int,input().split())
ar=[]
for i in range(n):
ar.append(list(map(int,list(input()))))
if(min(n,m)==1):
print(0)
elif(min(n,m)>3):
print(-1)
else:
if(n<=3):
if(n==2):
temp=0
count1=0
for i in range(m):
if(temp==0):
if ar[0][i]+ar[1][i]==1:
count1+=1
else:
if (ar[0][i]+ar[1][i])%2==0:
count1+=1
temp^=1
temp=1
count2=0
for i in range(m):
if(temp==0):
if ar[0][i]+ar[1][i]==1:
count2+=1
else:
if (ar[0][i]+ar[1][i])%2==0:
count2+=1
temp^=1
print(min(count1,count2))
else:
temp1=0
temp2=0
count1=0
for i in range(m):
a,b,c=ar[0][i],ar[1][i],ar[2][i]
if(temp1==0 and temp2==0):
total=a+b+c
count1+=min(3-total,total)
elif(temp1==1 and temp2==1):
if(a==0 and b==1 and c==0):
continue
elif(a==1 and b==0 and c==1):
continue
count1+=1
elif(temp1==0 and temp2==1):
c1=1-a+1-b+c
c2=a+b+1-c
count1+=min(c1,c2)
else:
c1=1-a+b+c
c2=a+1-b+1-c
count1+=min(c1,c2)
temp1^=1
temp2^=1
temp1=1
temp2=1
count2=0
for i in range(m):
a,b,c=ar[0][i],ar[1][i],ar[2][i]
if(temp1==0 and temp2==0):
total=a+b+c
count2+=min(3-total,total)
elif(temp1==1 and temp2==1):
if(a==0 and b==1 and c==0):
continue
elif(a==1 and b==0 and c==1):
continue
count2+=1
elif(temp1==0 and temp2==1):
c1=1-a+1-b+c
c2=a+b+1-c
count2+=min(c1,c2)
else:
c1=1-a+b+c
c2=a+1-b+1-c
count2+=min(c1,c2)
temp1^=1
temp2^=1
temp1=0
temp2=1
count3=0
for i in range(m):
a,b,c=ar[0][i],ar[1][i],ar[2][i]
if(temp1==0 and temp2==0):
total=a+b+c
count3+=min(3-total,total)
elif(temp1==1 and temp2==1):
if(a==0 and b==1 and c==0):
continue
elif(a==1 and b==0 and c==1):
continue
count3+=1
elif(temp1==0 and temp2==1):
c1=1-a+1-b+c
c2=a+b+1-c
count3+=min(c1,c2)
else:
c1=1-a+b+c
c2=a+1-b+1-c
count3+=min(c1,c2)
temp1^=1
temp2^=1
temp1=1
temp2=0
count4=0
for i in range(m):
a,b,c=ar[0][i],ar[1][i],ar[2][i]
if(temp1==0 and temp2==0):
total=a+b+c
count4+=min(3-total,total)
elif(temp1==1 and temp2==1):
if(a==0 and b==1 and c==0):
continue
elif(a==1 and b==0 and c==1):
continue
count4+=1
elif(temp1==0 and temp2==1):
c1=1-a+1-b+c
c2=a+b+1-c
count4+=min(c1,c2)
else:
c1=1-a+b+c
c2=a+1-b+1-c
count4+=min(c1,c2)
temp1^=1
temp2^=1
print(min(count1,count2,count3,count4))
elif(m<=3):
if(m==2):
temp=0
count1=0
for i in range(n):
if(temp==0):
if ar[i][0]+ar[i][1]==1:
count1+=1
else:
if (ar[i][0]+ar[i][1])%2==0:
count1+=1
temp^=1
temp=1
count2=0
for i in range(n):
if(temp==0):
if ar[i][0]+ar[i][1]==1:
count2+=1
else:
if (ar[i][0]+ar[i][1])%2==0:
count2+=1
temp^=1
print(min(count1,count2))
else:
temp1=0
temp2=0
count1=0
for i in range(n):
a,b,c=ar[i][0],ar[i][1],ar[i][2]
if(temp1==0 and temp2==0):
total=a+b+c
count1+=min(3-total,total)
elif(temp1==1 and temp2==1):
if(a==0 and b==1 and c==0):
continue
elif(a==1 and b==0 and c==1):
continue
count1+=1
elif(temp1==0 and temp2==1):
c1=1-a+1-b+c
c2=a+b+1-c
count1+=min(c1,c2)
else:
c1=1-a+b+c
c2=a+1-b+1-c
count1+=min(c1,c2)
temp1^=1
temp2^=1
temp1=1
temp2=1
count2=0
for i in range(n):
a,b,c=ar[i][0],ar[i][1],ar[i][2]
if(temp1==0 and temp2==0):
total=a+b+c
count2+=min(3-total,total)
elif(temp1==1 and temp2==1):
if(a==0 and b==1 and c==0):
continue
elif(a==1 and b==0 and c==1):
continue
count2+=1
elif(temp1==0 and temp2==1):
c1=1-a+1-b+c
c2=a+b+1-c
count2+=min(c1,c2)
else:
c1=1-a+b+c
c2=a+1-b+1-c
count2+=min(c1,c2)
temp1^=1
temp2^=1
temp1=0
temp2=1
count3=0
for i in range(n):
a,b,c=ar[i][0],ar[i][1],ar[i][2]
if(temp1==0 and temp2==0):
total=a+b+c
count3+=min(3-total,total)
elif(temp1==1 and temp2==1):
if(a==0 and b==1 and c==0):
continue
elif(a==1 and b==0 and c==1):
continue
count3+=1
elif(temp1==0 and temp2==1):
c1=1-a+1-b+c
c2=a+b+1-c
count3+=min(c1,c2)
else:
c1=1-a+b+c
c2=a+1-b+1-c
count3+=min(c1,c2)
temp1^=1
temp2^=1
temp1=1
temp2=0
count4=0
for i in range(m):
a,b,c=ar[i][0],ar[i][1],ar[i][2]
if(temp1==0 and temp2==0):
total=a+b+c
count4+=min(3-total,total)
elif(temp1==1 and temp2==1):
if(a==0 and b==1 and c==0):
continue
elif(a==1 and b==0 and c==1):
continue
count4+=1
elif(temp1==0 and temp2==1):
c1=1-a+1-b+c
c2=a+b+1-c
count4+=min(c1,c2)
else:
c1=1-a+b+c
c2=a+1-b+1-c
count4+=min(c1,c2)
temp1^=1
temp2^=1
print(min(count1,count2,count3,count4))
``` | instruction | 0 | 83,587 | 23 | 167,174 |
No | output | 1 | 83,587 | 23 | 167,175 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.