message stringlengths 2 16.2k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 575 109k | cluster float64 16 16 | __index_level_0__ int64 1.15k 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N squares arranged in a row, numbered 1, 2, ..., N from left to right. You are given a string S of length N consisting of `.` and `#`. If the i-th character of S is `#`, Square i contains a rock; if the i-th character of S is `.`, Square i is empty.
In the beginning, Snuke stands on Square A, and Fnuke stands on Square B.
You can repeat the following operation any number of times:
* Choose Snuke or Fnuke, and make him jump one or two squares to the right. The destination must be one of the squares, and it must not contain a rock or the other person.
You want to repeat this operation so that Snuke will stand on Square C and Fnuke will stand on Square D.
Determine whether this is possible.
Constraints
* 4 \leq N \leq 200\ 000
* S is a string of length N consisting of `.` and `#`.
* 1 \leq A, B, C, D \leq N
* Square A, B, C and D do not contain a rock.
* A, B, C and D are all different.
* A < B
* A < C
* B < D
Input
Input is given from Standard Input in the following format:
N A B C D
S
Output
Print `Yes` if the objective is achievable, and `No` if it is not.
Examples
Input
7 1 3 6 7
.#..#..
Output
Yes
Input
7 1 3 7 6
.#..#..
Output
No
Input
15 1 3 15 13
...#.#...#.#...
Output
Yes
Submitted Solution:
```
n,a,b,c,d=list(map(int,input().split()))
s=input()
if c<d:
for i in range(b,d):
if s[i]=='#' and s[i+1]=='#':
print('No')
exit(0)
for i in range(a,c):
if s[i]=='#' and s[i+1]=='#':
print('No')
exit(0)
print('Yes')
else:
for i in range(b,min(d,n-1)):
if s[i-1]=='.' and s[i]=='.' and s[i+1]=='.':
break
else:
print('No')
exit(0)
for i in range(a,c):
if s[i]=='#' and s[i+1]=='#':
print('No')
exit(0)
for i in range(b,d):
if s[i]=='#' and s[i+1]=='#':
print('No')
exit(0)
print('Yes')
``` | instruction | 0 | 38,388 | 16 | 76,776 |
No | output | 1 | 38,388 | 16 | 76,777 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N squares arranged in a row, numbered 1, 2, ..., N from left to right. You are given a string S of length N consisting of `.` and `#`. If the i-th character of S is `#`, Square i contains a rock; if the i-th character of S is `.`, Square i is empty.
In the beginning, Snuke stands on Square A, and Fnuke stands on Square B.
You can repeat the following operation any number of times:
* Choose Snuke or Fnuke, and make him jump one or two squares to the right. The destination must be one of the squares, and it must not contain a rock or the other person.
You want to repeat this operation so that Snuke will stand on Square C and Fnuke will stand on Square D.
Determine whether this is possible.
Constraints
* 4 \leq N \leq 200\ 000
* S is a string of length N consisting of `.` and `#`.
* 1 \leq A, B, C, D \leq N
* Square A, B, C and D do not contain a rock.
* A, B, C and D are all different.
* A < B
* A < C
* B < D
Input
Input is given from Standard Input in the following format:
N A B C D
S
Output
Print `Yes` if the objective is achievable, and `No` if it is not.
Examples
Input
7 1 3 6 7
.#..#..
Output
Yes
Input
7 1 3 7 6
.#..#..
Output
No
Input
15 1 3 15 13
...#.#...#.#...
Output
Yes
Submitted Solution:
```
n, a, b, c, d = map(int, input().split())
s = input()
index1 = s[a:c-a-1].find("##")
index2 = s[b:d-b-1].find("##")
if index1 != -1 or index2 != -1:
print("No")
elif c < d :
print("Yes")
elif s[int(max([b-2, 0])):d-b+2].find("...") != -1 : #s[d+1]またはs[d-1]が"#"のとき、つまり途中でsnukeがhnukeをこす
print("Yes")
else :
print("No")
``` | instruction | 0 | 38,389 | 16 | 76,778 |
No | output | 1 | 38,389 | 16 | 76,779 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N squares arranged in a row, numbered 1, 2, ..., N from left to right. You are given a string S of length N consisting of `.` and `#`. If the i-th character of S is `#`, Square i contains a rock; if the i-th character of S is `.`, Square i is empty.
In the beginning, Snuke stands on Square A, and Fnuke stands on Square B.
You can repeat the following operation any number of times:
* Choose Snuke or Fnuke, and make him jump one or two squares to the right. The destination must be one of the squares, and it must not contain a rock or the other person.
You want to repeat this operation so that Snuke will stand on Square C and Fnuke will stand on Square D.
Determine whether this is possible.
Constraints
* 4 \leq N \leq 200\ 000
* S is a string of length N consisting of `.` and `#`.
* 1 \leq A, B, C, D \leq N
* Square A, B, C and D do not contain a rock.
* A, B, C and D are all different.
* A < B
* A < C
* B < D
Input
Input is given from Standard Input in the following format:
N A B C D
S
Output
Print `Yes` if the objective is achievable, and `No` if it is not.
Examples
Input
7 1 3 6 7
.#..#..
Output
Yes
Input
7 1 3 7 6
.#..#..
Output
No
Input
15 1 3 15 13
...#.#...#.#...
Output
Yes
Submitted Solution:
```
import sys
input = sys.stdin.readline
N, A, B, C, D = map(int, input().split())
S = list(input())[: -1]
tri = 0
for i in range(min(A, B) - 1, N - 1):
if S[i] == "#" and (S[i + 1] == "#"):
print("No")
exit(0)
for i in range(min(A, B) - 1, D - 1):
if S[i] == "." and (S[i - 1] == ".") and (S[i + 1] == "."): tri = 1
if C <= D:
print("Yes")
else:
if tri: print("Yes")
else: print("No")
``` | instruction | 0 | 38,390 | 16 | 76,780 |
No | output | 1 | 38,390 | 16 | 76,781 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N squares arranged in a row, numbered 1, 2, ..., N from left to right. You are given a string S of length N consisting of `.` and `#`. If the i-th character of S is `#`, Square i contains a rock; if the i-th character of S is `.`, Square i is empty.
In the beginning, Snuke stands on Square A, and Fnuke stands on Square B.
You can repeat the following operation any number of times:
* Choose Snuke or Fnuke, and make him jump one or two squares to the right. The destination must be one of the squares, and it must not contain a rock or the other person.
You want to repeat this operation so that Snuke will stand on Square C and Fnuke will stand on Square D.
Determine whether this is possible.
Constraints
* 4 \leq N \leq 200\ 000
* S is a string of length N consisting of `.` and `#`.
* 1 \leq A, B, C, D \leq N
* Square A, B, C and D do not contain a rock.
* A, B, C and D are all different.
* A < B
* A < C
* B < D
Input
Input is given from Standard Input in the following format:
N A B C D
S
Output
Print `Yes` if the objective is achievable, and `No` if it is not.
Examples
Input
7 1 3 6 7
.#..#..
Output
Yes
Input
7 1 3 7 6
.#..#..
Output
No
Input
15 1 3 15 13
...#.#...#.#...
Output
Yes
Submitted Solution:
```
number_of_masu, firstsunuke, firstfunuke, lastsunuke, lastfunuke = map(int, input().split())
s = str(input())
tobenaiflag = 0
nukaseruflag = 0
lastfunuke -= 1
lastsunuke -= 1
firstsunuke -= 1
firstfunuke -= 1
# for i in range(firstsunuke, lastsunuke-1):
# if s[i] == '#' and s[i+1] == '#':
# tobenaiflag += 1
# break
# for k in range(firstfunuke, lastfunuke-1):
# if s[k] == '#' and s[k+1] == '#':
# tobenaiflag += 1
# break
tobenaiflag = 1
if lastfunuke < lastsunuke:
for j in range(max(firstsunuke, firstfunuke)-1, lastfunuke-1):
if s[j] == '.' and s[j+1] == '.' and s[j+2] == '.':
nukaseruflag += 1
break
else:
nukaseruflag += 1
if tobenaiflag == 0 and nukaseruflag == 1:
print('Yes')
else:
print('No')
``` | instruction | 0 | 38,391 | 16 | 76,782 |
No | output | 1 | 38,391 | 16 | 76,783 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke found a random number generator. It generates an integer between 0 and 2^N-1 (inclusive). An integer sequence A_0, A_1, \cdots, A_{2^N-1} represents the probability that each of these integers is generated. The integer i (0 \leq i \leq 2^N-1) is generated with probability A_i / S, where S = \sum_{i=0}^{2^N-1} A_i. The process of generating an integer is done independently each time the generator is executed.
Snuke has an integer X, which is now 0. He can perform the following operation any number of times:
* Generate an integer v with the generator and replace X with X \oplus v, where \oplus denotes the bitwise XOR.
For each integer i (0 \leq i \leq 2^N-1), find the expected number of operations until X becomes i, and print it modulo 998244353. More formally, represent the expected number of operations as an irreducible fraction P/Q. Then, there exists a unique integer R such that R \times Q \equiv P \mod 998244353,\ 0 \leq R < 998244353, so print this R.
We can prove that, for every i, the expected number of operations until X becomes i is a finite rational number, and its integer representation modulo 998244353 can be defined.
Constraints
* 1 \leq N \leq 18
* 1 \leq A_i \leq 1000
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_0 A_1 \cdots A_{2^N-1}
Output
Print 2^N lines. The (i+1)-th line (0 \leq i \leq 2^N-1) should contain the expected number of operations until X becomes i, modulo 998244353.
Examples
Input
2
1 1 1 1
Output
0
4
4
4
Input
2
1 2 1 2
Output
0
499122180
4
499122180
Input
4
337 780 799 10 796 875 331 223 941 67 148 483 390 565 116 355
Output
0
468683018
635850749
96019779
657074071
24757563
745107950
665159588
551278361
143136064
557841197
185790407
988018173
247117461
129098626
789682908 | instruction | 0 | 41,874 | 16 | 83,748 |
"Correct Solution:
```
# Σ(i ^ j = k) ai * bj = ckという形で式が表されるとき
# fwht(a)*fwht(b)=fwht(c)が成り立ち高速化できる
# すごく必死に考えると
# a = [p0 p1 p2 ... p2^N-1]
# b = [x0 x1 x2 ... x2^N-1]
# c = [2^N-1 -1 -1 -1 .... -1]
# とするとうまいことaとcに変数が入らない形になるのでfwht(c)/fwht(a)を計算し
# fwht(b)がわかるのでこれを逆変換すればbが求められる
# なお逆変換は b = fwht(fwht(b)) / 要素数で求められる、なぜかは知らない
# またまたなぜかは知らないがこうして求めた答えは各要素に定数が足されたものになるらしい
# 今回はx0 = 0と分かっているのbを[0 x1-x0 ... x2^N-1-x0]と補正してやればよい
N = int(input())
A = [int(i) for i in input().split()]
MOD = 998244353
NN = 1 << N
def fwht(a) :
i = 1
while i < NN :
j = 0
while j < NN :
for k in range(i) :
x, y = a[j+k], a[i+j+k]
a[j+k], a[i+j+k] = (x + y) % MOD, (x - y) % MOD
j += i << 1
i <<= 1
def inv(x) :
return pow(x, MOD - 2, MOD)
s = inv(sum(A) % MOD)
for i in range(NN) :
A[i] = (A[i] * s) % MOD
A[0] = (A[0] - 1) % MOD
fwht(A)
B = [- 1] * (NN)
B[0] = (NN-1) % MOD
fwht(B)
C = [(inv(A[i]) * B[i]) % MOD for i in range(NN)]
fwht(C)
for i in range(NN) :
C[i] = (C[i] * inv(NN)) % MOD
for i in range(NN) :
print((C[i] - C[0]) % MOD)
``` | output | 1 | 41,874 | 16 | 83,749 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke found a random number generator. It generates an integer between 0 and 2^N-1 (inclusive). An integer sequence A_0, A_1, \cdots, A_{2^N-1} represents the probability that each of these integers is generated. The integer i (0 \leq i \leq 2^N-1) is generated with probability A_i / S, where S = \sum_{i=0}^{2^N-1} A_i. The process of generating an integer is done independently each time the generator is executed.
Snuke has an integer X, which is now 0. He can perform the following operation any number of times:
* Generate an integer v with the generator and replace X with X \oplus v, where \oplus denotes the bitwise XOR.
For each integer i (0 \leq i \leq 2^N-1), find the expected number of operations until X becomes i, and print it modulo 998244353. More formally, represent the expected number of operations as an irreducible fraction P/Q. Then, there exists a unique integer R such that R \times Q \equiv P \mod 998244353,\ 0 \leq R < 998244353, so print this R.
We can prove that, for every i, the expected number of operations until X becomes i is a finite rational number, and its integer representation modulo 998244353 can be defined.
Constraints
* 1 \leq N \leq 18
* 1 \leq A_i \leq 1000
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_0 A_1 \cdots A_{2^N-1}
Output
Print 2^N lines. The (i+1)-th line (0 \leq i \leq 2^N-1) should contain the expected number of operations until X becomes i, modulo 998244353.
Examples
Input
2
1 1 1 1
Output
0
4
4
4
Input
2
1 2 1 2
Output
0
499122180
4
499122180
Input
4
337 780 799 10 796 875 331 223 941 67 148 483 390 565 116 355
Output
0
468683018
635850749
96019779
657074071
24757563
745107950
665159588
551278361
143136064
557841197
185790407
988018173
247117461
129098626
789682908
Submitted Solution:
```
import sys
sys.setrecursionlimit(10000)
input = sys.stdin.readline
def g(l):
if not l:
return 0, 0
m,s = max(l), sum(l)
if 2*m > s:
return 2*m - s, (s-m)
return s % 2, s//2
def f(v, vs):
ks = []
r = 0
rkoma = 0
for u in d[v]:
if u in vs:
continue
vs.add(u)
k1, k2, koma = f(u, vs)
ks.append(k1)
rkoma += koma
r += k2
r1, r2 = g(ks)
# r1 深さの和、r2 操作の回数
rkoma += km[v]
# print(v, r1 + rkoma, r + r2, rkoma)
return r1 + rkoma, r + r2, rkoma
N = int(input())
km = [0] + [int(i) for i in str(input().strip())]
d = [set() for _ in range(N+1)]
for _ in range(N-1):
x, y = map(int, input().split())
d[x].add(y)
d[y].add(x)
r = 10**10
for i in range(N):
a, b, c = f(i+1, {i+1})
if a == c:
r = min(r, b)
print(r if r != 10**10 else -1)
``` | instruction | 0 | 41,875 | 16 | 83,750 |
No | output | 1 | 41,875 | 16 | 83,751 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke found a random number generator. It generates an integer between 0 and 2^N-1 (inclusive). An integer sequence A_0, A_1, \cdots, A_{2^N-1} represents the probability that each of these integers is generated. The integer i (0 \leq i \leq 2^N-1) is generated with probability A_i / S, where S = \sum_{i=0}^{2^N-1} A_i. The process of generating an integer is done independently each time the generator is executed.
Snuke has an integer X, which is now 0. He can perform the following operation any number of times:
* Generate an integer v with the generator and replace X with X \oplus v, where \oplus denotes the bitwise XOR.
For each integer i (0 \leq i \leq 2^N-1), find the expected number of operations until X becomes i, and print it modulo 998244353. More formally, represent the expected number of operations as an irreducible fraction P/Q. Then, there exists a unique integer R such that R \times Q \equiv P \mod 998244353,\ 0 \leq R < 998244353, so print this R.
We can prove that, for every i, the expected number of operations until X becomes i is a finite rational number, and its integer representation modulo 998244353 can be defined.
Constraints
* 1 \leq N \leq 18
* 1 \leq A_i \leq 1000
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_0 A_1 \cdots A_{2^N-1}
Output
Print 2^N lines. The (i+1)-th line (0 \leq i \leq 2^N-1) should contain the expected number of operations until X becomes i, modulo 998244353.
Examples
Input
2
1 1 1 1
Output
0
4
4
4
Input
2
1 2 1 2
Output
0
499122180
4
499122180
Input
4
337 780 799 10 796 875 331 223 941 67 148 483 390 565 116 355
Output
0
468683018
635850749
96019779
657074071
24757563
745107950
665159588
551278361
143136064
557841197
185790407
988018173
247117461
129098626
789682908
Submitted Solution:
```
print("wakaranai")
``` | instruction | 0 | 41,876 | 16 | 83,752 |
No | output | 1 | 41,876 | 16 | 83,753 |
Provide a correct Python 3 solution for this coding contest problem.
We have N sticks with negligible thickness. The length of the i-th stick is A_i.
Snuke wants to select four different sticks from these sticks and form a rectangle (including a square), using the sticks as its sides. Find the maximum possible area of the rectangle.
Constraints
* 4 \leq N \leq 10^5
* 1 \leq A_i \leq 10^9
* A_i is an integer.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
Output
Print the maximum possible area of the rectangle. If no rectangle can be formed, print 0.
Examples
Input
6
3 1 2 4 2 1
Output
2
Input
4
1 2 3 4
Output
0
Input
10
3 3 3 3 4 4 4 5 5 5
Output
20 | instruction | 0 | 41,925 | 16 | 83,850 |
"Correct Solution:
```
n=int(input())
a=sorted(list(map(int,input().split())),reverse=True)
i=0
arr=[]
while i<n-1:
if a[i]==a[i+1]:
arr.append(a[i])
i+=2
else:
i+=1
if len(arr)==2:
print(arr[0]*arr[1])
exit()
print(0)
``` | output | 1 | 41,925 | 16 | 83,851 |
Provide a correct Python 3 solution for this coding contest problem.
We have N sticks with negligible thickness. The length of the i-th stick is A_i.
Snuke wants to select four different sticks from these sticks and form a rectangle (including a square), using the sticks as its sides. Find the maximum possible area of the rectangle.
Constraints
* 4 \leq N \leq 10^5
* 1 \leq A_i \leq 10^9
* A_i is an integer.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
Output
Print the maximum possible area of the rectangle. If no rectangle can be formed, print 0.
Examples
Input
6
3 1 2 4 2 1
Output
2
Input
4
1 2 3 4
Output
0
Input
10
3 3 3 3 4 4 4 5 5 5
Output
20 | instruction | 0 | 41,926 | 16 | 83,852 |
"Correct Solution:
```
N=int(input())
A=list(map(int,input().split()))
long1=0
long2=0
A=sorted(A)
pair=1
for i in range(N-1):
if A[i]==A[i+1] and pair==1:
long2=long1
long1=A[i]
pair=0
else:
pair=1
if long2==0:
ans=0
else:
ans=long1*long2
print(ans)
``` | output | 1 | 41,926 | 16 | 83,853 |
Provide a correct Python 3 solution for this coding contest problem.
We have N sticks with negligible thickness. The length of the i-th stick is A_i.
Snuke wants to select four different sticks from these sticks and form a rectangle (including a square), using the sticks as its sides. Find the maximum possible area of the rectangle.
Constraints
* 4 \leq N \leq 10^5
* 1 \leq A_i \leq 10^9
* A_i is an integer.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
Output
Print the maximum possible area of the rectangle. If no rectangle can be formed, print 0.
Examples
Input
6
3 1 2 4 2 1
Output
2
Input
4
1 2 3 4
Output
0
Input
10
3 3 3 3 4 4 4 5 5 5
Output
20 | instruction | 0 | 41,927 | 16 | 83,854 |
"Correct Solution:
```
n=int(input())
a=[int(x) for x in input().split()]
a.sort()
lar=sec=i=0
while(i<n-1):
if a[i]==a[i+1]:
i+=1
if a[i]>lar:
sec=lar
lar=a[i]
elif a[i]>sec:
sec=a[i]
i+=1
print(lar*sec)
``` | output | 1 | 41,927 | 16 | 83,855 |
Provide a correct Python 3 solution for this coding contest problem.
We have N sticks with negligible thickness. The length of the i-th stick is A_i.
Snuke wants to select four different sticks from these sticks and form a rectangle (including a square), using the sticks as its sides. Find the maximum possible area of the rectangle.
Constraints
* 4 \leq N \leq 10^5
* 1 \leq A_i \leq 10^9
* A_i is an integer.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
Output
Print the maximum possible area of the rectangle. If no rectangle can be formed, print 0.
Examples
Input
6
3 1 2 4 2 1
Output
2
Input
4
1 2 3 4
Output
0
Input
10
3 3 3 3 4 4 4 5 5 5
Output
20 | instruction | 0 | 41,928 | 16 | 83,856 |
"Correct Solution:
```
from collections import Counter as C
_ = input()
a = C([int(x) for x in input().split()])
b = []
for k, v in a.items():
for _ in range(v // 2):
b.append(k)
else:
if 2 <= len(b):
b.sort()
print(b[-1] * b[-2])
else:
print(0)
``` | output | 1 | 41,928 | 16 | 83,857 |
Provide a correct Python 3 solution for this coding contest problem.
We have N sticks with negligible thickness. The length of the i-th stick is A_i.
Snuke wants to select four different sticks from these sticks and form a rectangle (including a square), using the sticks as its sides. Find the maximum possible area of the rectangle.
Constraints
* 4 \leq N \leq 10^5
* 1 \leq A_i \leq 10^9
* A_i is an integer.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
Output
Print the maximum possible area of the rectangle. If no rectangle can be formed, print 0.
Examples
Input
6
3 1 2 4 2 1
Output
2
Input
4
1 2 3 4
Output
0
Input
10
3 3 3 3 4 4 4 5 5 5
Output
20 | instruction | 0 | 41,929 | 16 | 83,858 |
"Correct Solution:
```
N = int(input())
A = sorted([int(_) for _ in input().split()], reverse=True)
e = []
pre = 0
for i in range(N):
if pre == A[i]:
e.append(A[i])
if len(e) >= 2: break
pre = 0
else:
pre = A[i]
if len(e) < 2: print(0)
else: print(e[0] * e[1])
``` | output | 1 | 41,929 | 16 | 83,859 |
Provide a correct Python 3 solution for this coding contest problem.
We have N sticks with negligible thickness. The length of the i-th stick is A_i.
Snuke wants to select four different sticks from these sticks and form a rectangle (including a square), using the sticks as its sides. Find the maximum possible area of the rectangle.
Constraints
* 4 \leq N \leq 10^5
* 1 \leq A_i \leq 10^9
* A_i is an integer.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
Output
Print the maximum possible area of the rectangle. If no rectangle can be formed, print 0.
Examples
Input
6
3 1 2 4 2 1
Output
2
Input
4
1 2 3 4
Output
0
Input
10
3 3 3 3 4 4 4 5 5 5
Output
20 | instruction | 0 | 41,930 | 16 | 83,860 |
"Correct Solution:
```
N=int(input())
A=list(map(int,input().split()))
D,L={},[0,0]
for a in A:
if a not in D:D[a]=1
else:
L.append(a)
del D[a]
L.sort(reverse=True)
print(L[0]*L[1])
``` | output | 1 | 41,930 | 16 | 83,861 |
Provide a correct Python 3 solution for this coding contest problem.
We have N sticks with negligible thickness. The length of the i-th stick is A_i.
Snuke wants to select four different sticks from these sticks and form a rectangle (including a square), using the sticks as its sides. Find the maximum possible area of the rectangle.
Constraints
* 4 \leq N \leq 10^5
* 1 \leq A_i \leq 10^9
* A_i is an integer.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
Output
Print the maximum possible area of the rectangle. If no rectangle can be formed, print 0.
Examples
Input
6
3 1 2 4 2 1
Output
2
Input
4
1 2 3 4
Output
0
Input
10
3 3 3 3 4 4 4 5 5 5
Output
20 | instruction | 0 | 41,931 | 16 | 83,862 |
"Correct Solution:
```
from collections import Counter
n=int(input())
c=Counter(list(map(int, input().split())))
l=list()
for k,v in c.items():
for _ in range(v//2):
l.append(k)
l.sort()
l.reverse()
if len(l)>=2:
print(l[0]*l[1])
else:
print(0)
``` | output | 1 | 41,931 | 16 | 83,863 |
Provide a correct Python 3 solution for this coding contest problem.
We have N sticks with negligible thickness. The length of the i-th stick is A_i.
Snuke wants to select four different sticks from these sticks and form a rectangle (including a square), using the sticks as its sides. Find the maximum possible area of the rectangle.
Constraints
* 4 \leq N \leq 10^5
* 1 \leq A_i \leq 10^9
* A_i is an integer.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
Output
Print the maximum possible area of the rectangle. If no rectangle can be formed, print 0.
Examples
Input
6
3 1 2 4 2 1
Output
2
Input
4
1 2 3 4
Output
0
Input
10
3 3 3 3 4 4 4 5 5 5
Output
20 | instruction | 0 | 41,932 | 16 | 83,864 |
"Correct Solution:
```
n=int(input())
a=list(map(int,input().split()))
a.sort()
a.reverse()
j=[];x=-2
for i in range(n-1):
if a[i]==a[i+1] and x!=i:
j.append(a[i])
x=i+1
if len(j)>=2:
break
j.append(0)
j.append(0)
print(j[0]*j[1])
``` | output | 1 | 41,932 | 16 | 83,865 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have N sticks with negligible thickness. The length of the i-th stick is A_i.
Snuke wants to select four different sticks from these sticks and form a rectangle (including a square), using the sticks as its sides. Find the maximum possible area of the rectangle.
Constraints
* 4 \leq N \leq 10^5
* 1 \leq A_i \leq 10^9
* A_i is an integer.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
Output
Print the maximum possible area of the rectangle. If no rectangle can be formed, print 0.
Examples
Input
6
3 1 2 4 2 1
Output
2
Input
4
1 2 3 4
Output
0
Input
10
3 3 3 3 4 4 4 5 5 5
Output
20
Submitted Solution:
```
from collections import Counter
n = int(input())
A = list(map(int, input().split()))
c = Counter(A)
pair = []
# print(c)
for x, cnt in c.items():
pair += [x] * (cnt//2)
# print(pair)
pair.sort()
ans = 0
if len(pair) >= 2:
ans = pair[-1] * pair[-2]
print(ans)
``` | instruction | 0 | 41,933 | 16 | 83,866 |
Yes | output | 1 | 41,933 | 16 | 83,867 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have N sticks with negligible thickness. The length of the i-th stick is A_i.
Snuke wants to select four different sticks from these sticks and form a rectangle (including a square), using the sticks as its sides. Find the maximum possible area of the rectangle.
Constraints
* 4 \leq N \leq 10^5
* 1 \leq A_i \leq 10^9
* A_i is an integer.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
Output
Print the maximum possible area of the rectangle. If no rectangle can be formed, print 0.
Examples
Input
6
3 1 2 4 2 1
Output
2
Input
4
1 2 3 4
Output
0
Input
10
3 3 3 3 4 4 4 5 5 5
Output
20
Submitted Solution:
```
n = int(input())
a = sorted(list(map(int,input().split())),reverse = True)
use = []
flag = -1
for i in range(n):
if flag == a[i]:
use.append(a[i])
flag = -1
else:
flag = a[i]
if len(use)<2:
print(0)
else:
use.sort(reverse =True)
print(use[0]*use[1])
``` | instruction | 0 | 41,934 | 16 | 83,868 |
Yes | output | 1 | 41,934 | 16 | 83,869 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have N sticks with negligible thickness. The length of the i-th stick is A_i.
Snuke wants to select four different sticks from these sticks and form a rectangle (including a square), using the sticks as its sides. Find the maximum possible area of the rectangle.
Constraints
* 4 \leq N \leq 10^5
* 1 \leq A_i \leq 10^9
* A_i is an integer.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
Output
Print the maximum possible area of the rectangle. If no rectangle can be formed, print 0.
Examples
Input
6
3 1 2 4 2 1
Output
2
Input
4
1 2 3 4
Output
0
Input
10
3 3 3 3 4 4 4 5 5 5
Output
20
Submitted Solution:
```
N = int(input())
A = sorted(list(map(int,input().split())),reverse=True)
for i in range(N-1):
if A[i]==A[i+1]:
A[i+1]=0
else:
A[i]=0
A.sort(reverse=True)
print(A[0]*A[1])
``` | instruction | 0 | 41,935 | 16 | 83,870 |
Yes | output | 1 | 41,935 | 16 | 83,871 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have N sticks with negligible thickness. The length of the i-th stick is A_i.
Snuke wants to select four different sticks from these sticks and form a rectangle (including a square), using the sticks as its sides. Find the maximum possible area of the rectangle.
Constraints
* 4 \leq N \leq 10^5
* 1 \leq A_i \leq 10^9
* A_i is an integer.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
Output
Print the maximum possible area of the rectangle. If no rectangle can be formed, print 0.
Examples
Input
6
3 1 2 4 2 1
Output
2
Input
4
1 2 3 4
Output
0
Input
10
3 3 3 3 4 4 4 5 5 5
Output
20
Submitted Solution:
```
from collections import Counter
n=int(input())
A=Counter(list(map(int,input().split())))
x=[0,0]
for a in A:
if A[a]>1:x.append(a)
if A[a]>3:x.append(a)
x.sort()
print(x[-1]*x[-2])
``` | instruction | 0 | 41,936 | 16 | 83,872 |
Yes | output | 1 | 41,936 | 16 | 83,873 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have N sticks with negligible thickness. The length of the i-th stick is A_i.
Snuke wants to select four different sticks from these sticks and form a rectangle (including a square), using the sticks as its sides. Find the maximum possible area of the rectangle.
Constraints
* 4 \leq N \leq 10^5
* 1 \leq A_i \leq 10^9
* A_i is an integer.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
Output
Print the maximum possible area of the rectangle. If no rectangle can be formed, print 0.
Examples
Input
6
3 1 2 4 2 1
Output
2
Input
4
1 2 3 4
Output
0
Input
10
3 3 3 3 4 4 4 5 5 5
Output
20
Submitted Solution:
```
import collections
n = int(input())
a = [int(i) for i in input().split()]
a.sort
a = a[::-1]
x,answer = collections.Counter(a),[]
while a != []:
if x[a[0]]>=4 and len(answer)==0:
answer = [a[0],a[0]]
break
elif x[a[0]]>=2:
answer.append(a[0])
if len(answer)==2:
break
a = a[x[a[0]]:]
if len(answer)==2:
print(answer[0]*answer[1])
else:
print(0)
``` | instruction | 0 | 41,937 | 16 | 83,874 |
No | output | 1 | 41,937 | 16 | 83,875 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have N sticks with negligible thickness. The length of the i-th stick is A_i.
Snuke wants to select four different sticks from these sticks and form a rectangle (including a square), using the sticks as its sides. Find the maximum possible area of the rectangle.
Constraints
* 4 \leq N \leq 10^5
* 1 \leq A_i \leq 10^9
* A_i is an integer.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
Output
Print the maximum possible area of the rectangle. If no rectangle can be formed, print 0.
Examples
Input
6
3 1 2 4 2 1
Output
2
Input
4
1 2 3 4
Output
0
Input
10
3 3 3 3 4 4 4 5 5 5
Output
20
Submitted Solution:
```
Flag = False
LS = 0
SS = 0
for T in range(0,len(A)):
if LS==0 and A[T][1]>=4:
Sq = A[T][0]**2
Flag = True
break
if A[T][1]>=2:
if LS==0:
LS = A[T][0]
else:
SS = A[T][0]
Sq = LS*SS
Flag = True
break
if Flag:
print(Sq)
else:
print(0)
``` | instruction | 0 | 41,938 | 16 | 83,876 |
No | output | 1 | 41,938 | 16 | 83,877 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have N sticks with negligible thickness. The length of the i-th stick is A_i.
Snuke wants to select four different sticks from these sticks and form a rectangle (including a square), using the sticks as its sides. Find the maximum possible area of the rectangle.
Constraints
* 4 \leq N \leq 10^5
* 1 \leq A_i \leq 10^9
* A_i is an integer.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
Output
Print the maximum possible area of the rectangle. If no rectangle can be formed, print 0.
Examples
Input
6
3 1 2 4 2 1
Output
2
Input
4
1 2 3 4
Output
0
Input
10
3 3 3 3 4 4 4 5 5 5
Output
20
Submitted Solution:
```
N = int(input())
st = input().split()
A = [0 for i in range(N)]
for i in range(N):
A[i] = int(st[i])
A.sort(reverse = True)
U = []
for i in range(N-1):
if A[i] == A[i+1]:
U.append(A[i])
A[i] = -1
A[i+1] = -1
if len(U) >= 2:
break
print(U[0] * U[1])
``` | instruction | 0 | 41,939 | 16 | 83,878 |
No | output | 1 | 41,939 | 16 | 83,879 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have N sticks with negligible thickness. The length of the i-th stick is A_i.
Snuke wants to select four different sticks from these sticks and form a rectangle (including a square), using the sticks as its sides. Find the maximum possible area of the rectangle.
Constraints
* 4 \leq N \leq 10^5
* 1 \leq A_i \leq 10^9
* A_i is an integer.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
Output
Print the maximum possible area of the rectangle. If no rectangle can be formed, print 0.
Examples
Input
6
3 1 2 4 2 1
Output
2
Input
4
1 2 3 4
Output
0
Input
10
3 3 3 3 4 4 4 5 5 5
Output
20
Submitted Solution:
```
# -*- coding: utf-8 -*-
n = int(input())
a = list(map(int,input().split()))
def array_count(arr):
arr_target = [[]]
cnt = 1
for i in range(1,len(arr)):
if arr[i] == arr[i-1]:
cnt += 1
else:
arr_target.append([arr[i-1],cnt])
cnt = 1
arr_target.append([arr[len(arr)-1],cnt])
del arr_target[0]
return arr_target
a.sort()
a = array_count(a)
b = []
for i in range(len(a)):
if a[i][1] >= 2:
b.append(a[i][0])
b.sort()
b.reverse()
if len(b) <= 1:
print(0)
else:
print(b[0]*b[1])
``` | instruction | 0 | 41,940 | 16 | 83,880 |
No | output | 1 | 41,940 | 16 | 83,881 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke is playing a puzzle game. In this game, you are given a rectangular board of dimensions R × C, filled with numbers. Each integer i from 1 through N is written twice, at the coordinates (x_{i,1},y_{i,1}) and (x_{i,2},y_{i,2}).
The objective is to draw a curve connecting the pair of points where the same integer is written, for every integer from 1 through N. Here, the curves may not go outside the board or cross each other.
Determine whether this is possible.
Constraints
* 1 ≤ R,C ≤ 10^8
* 1 ≤ N ≤ 10^5
* 0 ≤ x_{i,1},x_{i,2} ≤ R(1 ≤ i ≤ N)
* 0 ≤ y_{i,1},y_{i,2} ≤ C(1 ≤ i ≤ N)
* All given points are distinct.
* All input values are integers.
Input
Input is given from Standard Input in the following format:
R C N
x_{1,1} y_{1,1} x_{1,2} y_{1,2}
:
x_{N,1} y_{N,1} x_{N,2} y_{N,2}
Output
Print `YES` if the objective is achievable; print `NO` otherwise.
Examples
Input
4 2 3
0 1 3 1
1 1 4 1
2 0 2 2
Output
YES
Input
2 2 4
0 0 2 2
2 0 0 1
0 2 1 2
1 1 2 1
Output
NO
Input
5 5 7
0 0 2 4
2 3 4 5
3 5 5 2
5 5 5 4
0 3 5 1
2 2 4 4
0 5 4 1
Output
YES
Input
1 1 2
0 0 1 1
1 0 0 1
Output
NO | instruction | 0 | 43,662 | 16 | 87,324 |
"Correct Solution:
```
import sys
input = sys.stdin.buffer.readline
R, C, N = map(int, input().split())
class Bit:
def __init__(self, n):
self.size = n
self.tree = [0] * (n + 1)
def sum(self, i):
s = 0
while i > 0:
s += self.tree[i]
i -= i & -i
return s
def add(self, i, x):
while i <= self.size:
self.tree[i] += x
i += i & -i
def check(x, y):
if x == 0:
return y
elif x == R:
return R + C + C - y
elif y == 0:
return C + R + C + R - x
elif y == C:
return C + x
else:
return -1
lr_list_raw = []
z_list = []
for i in range(N):
x1, y1, x2, y2 = map(int, input().split())
z1, z2 = check(x1, y1), check(x2, y2)
if z1 >= 0 and z2 >= 0:
lr_list_raw.append((min(z1, z2), max(z1, z2)))
z_list.append(z1)
z_list.append(z2)
z_list.sort()
idx = {zi: i+1 for i, zi in enumerate(z_list)}
lr_list = []
for l_raw, r_raw in lr_list_raw:
lr_list.append((idx[l_raw], idx[r_raw]))
'''
print(z_list)
print(idx)
print(lr_list_raw)
'''
bit = Bit(max(idx.values()) + 3)
for l, r in lr_list:
if (bit.sum(r) - bit.sum(l)) % 2 == 1:
print('NO')
exit()
bit.add(l, 1)
bit.add(r, 1)
print('YES')
``` | output | 1 | 43,662 | 16 | 87,325 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke is playing a puzzle game. In this game, you are given a rectangular board of dimensions R × C, filled with numbers. Each integer i from 1 through N is written twice, at the coordinates (x_{i,1},y_{i,1}) and (x_{i,2},y_{i,2}).
The objective is to draw a curve connecting the pair of points where the same integer is written, for every integer from 1 through N. Here, the curves may not go outside the board or cross each other.
Determine whether this is possible.
Constraints
* 1 ≤ R,C ≤ 10^8
* 1 ≤ N ≤ 10^5
* 0 ≤ x_{i,1},x_{i,2} ≤ R(1 ≤ i ≤ N)
* 0 ≤ y_{i,1},y_{i,2} ≤ C(1 ≤ i ≤ N)
* All given points are distinct.
* All input values are integers.
Input
Input is given from Standard Input in the following format:
R C N
x_{1,1} y_{1,1} x_{1,2} y_{1,2}
:
x_{N,1} y_{N,1} x_{N,2} y_{N,2}
Output
Print `YES` if the objective is achievable; print `NO` otherwise.
Examples
Input
4 2 3
0 1 3 1
1 1 4 1
2 0 2 2
Output
YES
Input
2 2 4
0 0 2 2
2 0 0 1
0 2 1 2
1 1 2 1
Output
NO
Input
5 5 7
0 0 2 4
2 3 4 5
3 5 5 2
5 5 5 4
0 3 5 1
2 2 4 4
0 5 4 1
Output
YES
Input
1 1 2
0 0 1 1
1 0 0 1
Output
NO | instruction | 0 | 43,663 | 16 | 87,326 |
"Correct Solution:
```
w, h, n = map(int, input().split())
vec = []
l = []
b = []
r = []
t = []
for i in range(n):
x, y, x1, y1 = map(int, input().split())
c = [x, y, x1, y1]
if( ((c[0] == 0 or c[0] == w) or (c[1] == 0 or c[1] == h)) and ((c[2] == 0 or c[2] == w) or (c[3] == 0 or c[3] == h)) ):
if x == 0:
l.append([x, y, i])
elif y == 0:
t.append([x, y, i])
elif x == w:
r.append([x, y, i])
elif y == h:
b.append([x, y, i])
if x1 == 0:
l.append([x1, y1, i])
elif y1 == 0:
t.append([x1, y1, i])
elif x1 == w:
r.append([x1, y1, i])
elif y1 == h:
b.append([x1, y1, i])
sorted_node = (
sorted(l, key=lambda x: x[1])
+ sorted(b, key=lambda x: x[0])
+ sorted(r, key=lambda x: x[1], reverse=True)
+ sorted(t, key=lambda x: x[0], reverse=True)
)
stack = []
for node in sorted_node:
if not stack or stack[-1] != node[2]:
stack.append(node[2])
else:
stack.pop()
print("NO" if stack else "YES")
``` | output | 1 | 43,663 | 16 | 87,327 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke is playing a puzzle game. In this game, you are given a rectangular board of dimensions R × C, filled with numbers. Each integer i from 1 through N is written twice, at the coordinates (x_{i,1},y_{i,1}) and (x_{i,2},y_{i,2}).
The objective is to draw a curve connecting the pair of points where the same integer is written, for every integer from 1 through N. Here, the curves may not go outside the board or cross each other.
Determine whether this is possible.
Constraints
* 1 ≤ R,C ≤ 10^8
* 1 ≤ N ≤ 10^5
* 0 ≤ x_{i,1},x_{i,2} ≤ R(1 ≤ i ≤ N)
* 0 ≤ y_{i,1},y_{i,2} ≤ C(1 ≤ i ≤ N)
* All given points are distinct.
* All input values are integers.
Input
Input is given from Standard Input in the following format:
R C N
x_{1,1} y_{1,1} x_{1,2} y_{1,2}
:
x_{N,1} y_{N,1} x_{N,2} y_{N,2}
Output
Print `YES` if the objective is achievable; print `NO` otherwise.
Examples
Input
4 2 3
0 1 3 1
1 1 4 1
2 0 2 2
Output
YES
Input
2 2 4
0 0 2 2
2 0 0 1
0 2 1 2
1 1 2 1
Output
NO
Input
5 5 7
0 0 2 4
2 3 4 5
3 5 5 2
5 5 5 4
0 3 5 1
2 2 4 4
0 5 4 1
Output
YES
Input
1 1 2
0 0 1 1
1 0 0 1
Output
NO | instruction | 0 | 43,664 | 16 | 87,328 |
"Correct Solution:
```
import sys
input = sys.stdin.readline
from collections import deque
R,C,N=map(int,input().split())
table=[]
def f(i,j):
if i==0:
return j
if j==C:
return C+i
if i==R:
return R+C+C-j
if j==0:
return R+R+C+C-i
for i in range(N):
a,b,c,d=map(int,input().split())
if (0<a<R and 0<b<C) or (0<c<R and 0<d<C):
continue
table.append((f(a,b),i))
table.append((f(c, d), i))
table.sort()
H=deque()
for i in range(len(table)):
if len(H)!=0 and H[-1]==table[i][1]:
H.pop()
else:
H.append(table[i][1])
#print(H,table)
while len(H)!=0 and H[0]==H[-1]:
H.popleft()
H.pop()
if len(H)==0:
print('YES')
else:
print('NO')
``` | output | 1 | 43,664 | 16 | 87,329 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke is playing a puzzle game. In this game, you are given a rectangular board of dimensions R × C, filled with numbers. Each integer i from 1 through N is written twice, at the coordinates (x_{i,1},y_{i,1}) and (x_{i,2},y_{i,2}).
The objective is to draw a curve connecting the pair of points where the same integer is written, for every integer from 1 through N. Here, the curves may not go outside the board or cross each other.
Determine whether this is possible.
Constraints
* 1 ≤ R,C ≤ 10^8
* 1 ≤ N ≤ 10^5
* 0 ≤ x_{i,1},x_{i,2} ≤ R(1 ≤ i ≤ N)
* 0 ≤ y_{i,1},y_{i,2} ≤ C(1 ≤ i ≤ N)
* All given points are distinct.
* All input values are integers.
Input
Input is given from Standard Input in the following format:
R C N
x_{1,1} y_{1,1} x_{1,2} y_{1,2}
:
x_{N,1} y_{N,1} x_{N,2} y_{N,2}
Output
Print `YES` if the objective is achievable; print `NO` otherwise.
Examples
Input
4 2 3
0 1 3 1
1 1 4 1
2 0 2 2
Output
YES
Input
2 2 4
0 0 2 2
2 0 0 1
0 2 1 2
1 1 2 1
Output
NO
Input
5 5 7
0 0 2 4
2 3 4 5
3 5 5 2
5 5 5 4
0 3 5 1
2 2 4 4
0 5 4 1
Output
YES
Input
1 1 2
0 0 1 1
1 0 0 1
Output
NO | instruction | 0 | 43,665 | 16 | 87,330 |
"Correct Solution:
```
R, C, N = map(int, input().split())
def calc(x, y):
if x == 0 or y == C:
return x + y
return 2*R + 2*C - x - y
A = {}
for i in range(N):
x1, y1, x2, y2 = map(int, input().split())
if not ((x1 in [0, R] or y1 in [0, C]) and (x2 in [0, R] or y2 in [0, C])):
continue
A[calc(x1, y1)] = i
A[calc(x2, y2)] = i
st = []
for i, a in sorted(A.items()):
if st and st[-1] == a:
st.pop()
elif a is not None:
st.append(a)
print('YES' if not st else 'NO')
``` | output | 1 | 43,665 | 16 | 87,331 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke is playing a puzzle game. In this game, you are given a rectangular board of dimensions R × C, filled with numbers. Each integer i from 1 through N is written twice, at the coordinates (x_{i,1},y_{i,1}) and (x_{i,2},y_{i,2}).
The objective is to draw a curve connecting the pair of points where the same integer is written, for every integer from 1 through N. Here, the curves may not go outside the board or cross each other.
Determine whether this is possible.
Constraints
* 1 ≤ R,C ≤ 10^8
* 1 ≤ N ≤ 10^5
* 0 ≤ x_{i,1},x_{i,2} ≤ R(1 ≤ i ≤ N)
* 0 ≤ y_{i,1},y_{i,2} ≤ C(1 ≤ i ≤ N)
* All given points are distinct.
* All input values are integers.
Input
Input is given from Standard Input in the following format:
R C N
x_{1,1} y_{1,1} x_{1,2} y_{1,2}
:
x_{N,1} y_{N,1} x_{N,2} y_{N,2}
Output
Print `YES` if the objective is achievable; print `NO` otherwise.
Examples
Input
4 2 3
0 1 3 1
1 1 4 1
2 0 2 2
Output
YES
Input
2 2 4
0 0 2 2
2 0 0 1
0 2 1 2
1 1 2 1
Output
NO
Input
5 5 7
0 0 2 4
2 3 4 5
3 5 5 2
5 5 5 4
0 3 5 1
2 2 4 4
0 5 4 1
Output
YES
Input
1 1 2
0 0 1 1
1 0 0 1
Output
NO | instruction | 0 | 43,666 | 16 | 87,332 |
"Correct Solution:
```
import sys
input = sys.stdin.readline
def main():
R, C, N = map(int, input().split())
xyxy = [list(map(int, input().split())) for i in range(N)]
r = []
for i in range(N):
x1, y1, x2, y2 = xyxy[i]
# どちらも周上にある場合は周上の座標に変換してから記録
if ((x1 == 0 or x1 == R) or (y1 == 0 or y1 == C)) and ((x2 == 0 or x2 == R) or (y2 == 0 or y2 == C)):
# 1つ目
if x1 == 0:
r.append((y1, i))
elif x1 == R:
r.append((C - y1 + C + R, i))
elif y1 == 0:
r.append((R - x1 + C * 2 + R, i))
else:
r.append((x1 + C, i))
# 2つ目
if x2 == 0:
r.append((y2, i))
elif x2 == R:
r.append((C - y2 + C + R, i))
elif y2 == 0:
r.append((R - x2 + C * 2 + R, i))
else:
r.append((x2 + C, i))
r = sorted(r)
# print(r)
stack = []
for i in range(len(r)):
if len(stack) > 0:
if stack[-1] == r[i][1]:
stack.pop()
else:
stack.append(r[i][1])
else:
stack.append(r[i][1])
if len(stack) > 0:
print("NO")
else:
print("YES")
if __name__ == "__main__":
main()
``` | output | 1 | 43,666 | 16 | 87,333 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke is playing a puzzle game. In this game, you are given a rectangular board of dimensions R × C, filled with numbers. Each integer i from 1 through N is written twice, at the coordinates (x_{i,1},y_{i,1}) and (x_{i,2},y_{i,2}).
The objective is to draw a curve connecting the pair of points where the same integer is written, for every integer from 1 through N. Here, the curves may not go outside the board or cross each other.
Determine whether this is possible.
Constraints
* 1 ≤ R,C ≤ 10^8
* 1 ≤ N ≤ 10^5
* 0 ≤ x_{i,1},x_{i,2} ≤ R(1 ≤ i ≤ N)
* 0 ≤ y_{i,1},y_{i,2} ≤ C(1 ≤ i ≤ N)
* All given points are distinct.
* All input values are integers.
Input
Input is given from Standard Input in the following format:
R C N
x_{1,1} y_{1,1} x_{1,2} y_{1,2}
:
x_{N,1} y_{N,1} x_{N,2} y_{N,2}
Output
Print `YES` if the objective is achievable; print `NO` otherwise.
Examples
Input
4 2 3
0 1 3 1
1 1 4 1
2 0 2 2
Output
YES
Input
2 2 4
0 0 2 2
2 0 0 1
0 2 1 2
1 1 2 1
Output
NO
Input
5 5 7
0 0 2 4
2 3 4 5
3 5 5 2
5 5 5 4
0 3 5 1
2 2 4 4
0 5 4 1
Output
YES
Input
1 1 2
0 0 1 1
1 0 0 1
Output
NO | instruction | 0 | 43,667 | 16 | 87,334 |
"Correct Solution:
```
from collections import deque
def f(x, y):
if x == 0:
return y
if y == 0:
return -x
if x == r:
return -(x + y)
if y == c:
return x + y
r, c, n = map(int, input().split())
xy = []
lxy = 0
for i in range(n):
x1, y1, x2, y2 = map(int, input().split())
d = []
if min(x1, y1) == 0 or x1 == r or y1 == c:
d.append([f(x1, y1), i])
if min(x2, y2) == 0 or x2 == r or y2 == c:
d.append([f(x2, y2), i])
if len(d) == 2:
xy.append(d[0])
xy.append(d[1])
lxy += 2
xy.sort()
q = deque()
for i in range(lxy):
if not q:
q.append(xy[i][1])
else:
if q[-1] == xy[i][1]:
q.pop()
else:
q.append(xy[i][1])
print("YES" if not q else "NO")
``` | output | 1 | 43,667 | 16 | 87,335 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke is playing a puzzle game. In this game, you are given a rectangular board of dimensions R × C, filled with numbers. Each integer i from 1 through N is written twice, at the coordinates (x_{i,1},y_{i,1}) and (x_{i,2},y_{i,2}).
The objective is to draw a curve connecting the pair of points where the same integer is written, for every integer from 1 through N. Here, the curves may not go outside the board or cross each other.
Determine whether this is possible.
Constraints
* 1 ≤ R,C ≤ 10^8
* 1 ≤ N ≤ 10^5
* 0 ≤ x_{i,1},x_{i,2} ≤ R(1 ≤ i ≤ N)
* 0 ≤ y_{i,1},y_{i,2} ≤ C(1 ≤ i ≤ N)
* All given points are distinct.
* All input values are integers.
Input
Input is given from Standard Input in the following format:
R C N
x_{1,1} y_{1,1} x_{1,2} y_{1,2}
:
x_{N,1} y_{N,1} x_{N,2} y_{N,2}
Output
Print `YES` if the objective is achievable; print `NO` otherwise.
Examples
Input
4 2 3
0 1 3 1
1 1 4 1
2 0 2 2
Output
YES
Input
2 2 4
0 0 2 2
2 0 0 1
0 2 1 2
1 1 2 1
Output
NO
Input
5 5 7
0 0 2 4
2 3 4 5
3 5 5 2
5 5 5 4
0 3 5 1
2 2 4 4
0 5 4 1
Output
YES
Input
1 1 2
0 0 1 1
1 0 0 1
Output
NO | instruction | 0 | 43,668 | 16 | 87,336 |
"Correct Solution:
```
from cmath import phase
r,c,n = map(int,input().split())
l = list()
for i in range(n):
w,x,y,z = map(int,input().split())
if (w in (0,r) or x in (0,c)) and (y in (0,r) or z in (0,c)):
l.append((i,w-r/2+(x-c/2)*1j))
l.append((i,y-r/2+(z-c/2)*1j))
l.sort(key=lambda t: phase(t[1]))
p = list()
for x,c in l:
if p == [] or p[-1] != x:
p.append(x)
else:
p.pop()
ans = ["NO", "YES"]
print(ans[p==[]])
``` | output | 1 | 43,668 | 16 | 87,337 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke is playing a puzzle game. In this game, you are given a rectangular board of dimensions R × C, filled with numbers. Each integer i from 1 through N is written twice, at the coordinates (x_{i,1},y_{i,1}) and (x_{i,2},y_{i,2}).
The objective is to draw a curve connecting the pair of points where the same integer is written, for every integer from 1 through N. Here, the curves may not go outside the board or cross each other.
Determine whether this is possible.
Constraints
* 1 ≤ R,C ≤ 10^8
* 1 ≤ N ≤ 10^5
* 0 ≤ x_{i,1},x_{i,2} ≤ R(1 ≤ i ≤ N)
* 0 ≤ y_{i,1},y_{i,2} ≤ C(1 ≤ i ≤ N)
* All given points are distinct.
* All input values are integers.
Input
Input is given from Standard Input in the following format:
R C N
x_{1,1} y_{1,1} x_{1,2} y_{1,2}
:
x_{N,1} y_{N,1} x_{N,2} y_{N,2}
Output
Print `YES` if the objective is achievable; print `NO` otherwise.
Examples
Input
4 2 3
0 1 3 1
1 1 4 1
2 0 2 2
Output
YES
Input
2 2 4
0 0 2 2
2 0 0 1
0 2 1 2
1 1 2 1
Output
NO
Input
5 5 7
0 0 2 4
2 3 4 5
3 5 5 2
5 5 5 4
0 3 5 1
2 2 4 4
0 5 4 1
Output
YES
Input
1 1 2
0 0 1 1
1 0 0 1
Output
NO | instruction | 0 | 43,669 | 16 | 87,338 |
"Correct Solution:
```
import sys
input = sys.stdin.readline
r,c,n = map(int,input().split())
xy = [list(map(int,input().split())) for i in range(n)]
ls = []
for x1,y1,x2,y2 in xy:
if (x1 in (0,r) or y1 in (0,c)) and (x2 in (0,r) or y2 in (0,c)):
k = []
for x,y in ((x1,y1),(x2,y2)):
if x == 0:
s = 2*r+2*c-y
if x == r:
s = r+y
if y == 0:
s = x
if y == c:
s = 2*r+c-x
k.append(s)
t = len(ls)//2+1
ls.append((k[0],t))
ls.append((k[1],t))
if not ls:
print("YES")
exit()
ls.sort()
lsi = list(map(list,zip(*ls)))[1]
m = len(lsi)
stack = []
for i in lsi:
if not stack:
stack.append(i)
else:
if stack[-1] == i:
stack.pop()
else:
stack.append(i)
if stack:
print("NO")
else:
print("YES")
``` | output | 1 | 43,669 | 16 | 87,339 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke is playing a puzzle game. In this game, you are given a rectangular board of dimensions R × C, filled with numbers. Each integer i from 1 through N is written twice, at the coordinates (x_{i,1},y_{i,1}) and (x_{i,2},y_{i,2}).
The objective is to draw a curve connecting the pair of points where the same integer is written, for every integer from 1 through N. Here, the curves may not go outside the board or cross each other.
Determine whether this is possible.
Constraints
* 1 ≤ R,C ≤ 10^8
* 1 ≤ N ≤ 10^5
* 0 ≤ x_{i,1},x_{i,2} ≤ R(1 ≤ i ≤ N)
* 0 ≤ y_{i,1},y_{i,2} ≤ C(1 ≤ i ≤ N)
* All given points are distinct.
* All input values are integers.
Input
Input is given from Standard Input in the following format:
R C N
x_{1,1} y_{1,1} x_{1,2} y_{1,2}
:
x_{N,1} y_{N,1} x_{N,2} y_{N,2}
Output
Print `YES` if the objective is achievable; print `NO` otherwise.
Examples
Input
4 2 3
0 1 3 1
1 1 4 1
2 0 2 2
Output
YES
Input
2 2 4
0 0 2 2
2 0 0 1
0 2 1 2
1 1 2 1
Output
NO
Input
5 5 7
0 0 2 4
2 3 4 5
3 5 5 2
5 5 5 4
0 3 5 1
2 2 4 4
0 5 4 1
Output
YES
Input
1 1 2
0 0 1 1
1 0 0 1
Output
NO
Submitted Solution:
```
import sys
input = lambda: sys.stdin.readline().rstrip()
def calc(a, b):
if b == 0: return a
if a == R: return b + R
if b == C: return R + C + (R - a)
if a == 0: return R + C + R + (C - b)
R, C, N = map(int, input().split())
A = []
for i in range(N):
x1, y1, x2, y2 = map(int, input().split())
if (x1 == 0 or x1 == R or y1 == 0 or y1 == C) and (x2 == 0 or x2 == R or y2 == 0 or y2 == C):
A.append((calc(x1, y1), i))
A.append((calc(x2, y2), i))
A = [l[1] for l in sorted(A, key = lambda x: x[0])]
B = []
while A:
while len(B) and A[-1] == B[-1]:
A.pop()
B.pop()
if A:
B.append(A.pop())
print("NO" if len(B) else "YES")
``` | instruction | 0 | 43,670 | 16 | 87,340 |
Yes | output | 1 | 43,670 | 16 | 87,341 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke is playing a puzzle game. In this game, you are given a rectangular board of dimensions R × C, filled with numbers. Each integer i from 1 through N is written twice, at the coordinates (x_{i,1},y_{i,1}) and (x_{i,2},y_{i,2}).
The objective is to draw a curve connecting the pair of points where the same integer is written, for every integer from 1 through N. Here, the curves may not go outside the board or cross each other.
Determine whether this is possible.
Constraints
* 1 ≤ R,C ≤ 10^8
* 1 ≤ N ≤ 10^5
* 0 ≤ x_{i,1},x_{i,2} ≤ R(1 ≤ i ≤ N)
* 0 ≤ y_{i,1},y_{i,2} ≤ C(1 ≤ i ≤ N)
* All given points are distinct.
* All input values are integers.
Input
Input is given from Standard Input in the following format:
R C N
x_{1,1} y_{1,1} x_{1,2} y_{1,2}
:
x_{N,1} y_{N,1} x_{N,2} y_{N,2}
Output
Print `YES` if the objective is achievable; print `NO` otherwise.
Examples
Input
4 2 3
0 1 3 1
1 1 4 1
2 0 2 2
Output
YES
Input
2 2 4
0 0 2 2
2 0 0 1
0 2 1 2
1 1 2 1
Output
NO
Input
5 5 7
0 0 2 4
2 3 4 5
3 5 5 2
5 5 5 4
0 3 5 1
2 2 4 4
0 5 4 1
Output
YES
Input
1 1 2
0 0 1 1
1 0 0 1
Output
NO
Submitted Solution:
```
R,C,N = map(int,input().split())
edges = []
def convert(x,y):
if y == 0:
return x
if x == R:
return R+y
if y == C:
return R+C+R-x
if x == 0:
return R+C+R+C-y
else:
return -1
for i in range(N):
a,b,c,d = map(int, input().split())
p,q = convert(a,b),convert(c,d)
if p >= 0 and q >= 0:
edges.append((p,q) if p < q else (q,p))
edges.sort()
# print(edges)
stack = [R+R+C+C]
flag = 'YES'
for a,b in edges:
while a >= stack[-1]:
stack.pop()
if b > stack[-1]:
flag = 'NO'
break
else:
stack.append(b)
print(flag)
``` | instruction | 0 | 43,671 | 16 | 87,342 |
Yes | output | 1 | 43,671 | 16 | 87,343 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke is playing a puzzle game. In this game, you are given a rectangular board of dimensions R × C, filled with numbers. Each integer i from 1 through N is written twice, at the coordinates (x_{i,1},y_{i,1}) and (x_{i,2},y_{i,2}).
The objective is to draw a curve connecting the pair of points where the same integer is written, for every integer from 1 through N. Here, the curves may not go outside the board or cross each other.
Determine whether this is possible.
Constraints
* 1 ≤ R,C ≤ 10^8
* 1 ≤ N ≤ 10^5
* 0 ≤ x_{i,1},x_{i,2} ≤ R(1 ≤ i ≤ N)
* 0 ≤ y_{i,1},y_{i,2} ≤ C(1 ≤ i ≤ N)
* All given points are distinct.
* All input values are integers.
Input
Input is given from Standard Input in the following format:
R C N
x_{1,1} y_{1,1} x_{1,2} y_{1,2}
:
x_{N,1} y_{N,1} x_{N,2} y_{N,2}
Output
Print `YES` if the objective is achievable; print `NO` otherwise.
Examples
Input
4 2 3
0 1 3 1
1 1 4 1
2 0 2 2
Output
YES
Input
2 2 4
0 0 2 2
2 0 0 1
0 2 1 2
1 1 2 1
Output
NO
Input
5 5 7
0 0 2 4
2 3 4 5
3 5 5 2
5 5 5 4
0 3 5 1
2 2 4 4
0 5 4 1
Output
YES
Input
1 1 2
0 0 1 1
1 0 0 1
Output
NO
Submitted Solution:
```
R, C, N = map(int, input().split())
points = []
def dist(x, y):
if x == 0:
return R * 2 + C + (C - y)
if x == R:
return R + y
if y == 0:
return x
if y == C:
return R + C + (R - x)
for i in range(N):
x1, y1, x2, y2 = map(int, input().split())
if ((x1 == 0 or x1 == R) or (y1 == 0 or y1 == C)) and ((x2 == 0 or x2 == R) or (y2 == 0 or y2 == C)):
points.append((i + 1, dist(x1, y1)))
points.append((i + 1, dist(x2, y2)))
points.sort(key=lambda p: p[1])
l = []
for point in points:
if len(l) == 0:
l.append(point[0])
continue
if point[0] == l[-1]:
l.pop()
else:
l.append(point[0])
if len(l) == 0:
print("YES")
else:
print("NO")
``` | instruction | 0 | 43,672 | 16 | 87,344 |
Yes | output | 1 | 43,672 | 16 | 87,345 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke is playing a puzzle game. In this game, you are given a rectangular board of dimensions R × C, filled with numbers. Each integer i from 1 through N is written twice, at the coordinates (x_{i,1},y_{i,1}) and (x_{i,2},y_{i,2}).
The objective is to draw a curve connecting the pair of points where the same integer is written, for every integer from 1 through N. Here, the curves may not go outside the board or cross each other.
Determine whether this is possible.
Constraints
* 1 ≤ R,C ≤ 10^8
* 1 ≤ N ≤ 10^5
* 0 ≤ x_{i,1},x_{i,2} ≤ R(1 ≤ i ≤ N)
* 0 ≤ y_{i,1},y_{i,2} ≤ C(1 ≤ i ≤ N)
* All given points are distinct.
* All input values are integers.
Input
Input is given from Standard Input in the following format:
R C N
x_{1,1} y_{1,1} x_{1,2} y_{1,2}
:
x_{N,1} y_{N,1} x_{N,2} y_{N,2}
Output
Print `YES` if the objective is achievable; print `NO` otherwise.
Examples
Input
4 2 3
0 1 3 1
1 1 4 1
2 0 2 2
Output
YES
Input
2 2 4
0 0 2 2
2 0 0 1
0 2 1 2
1 1 2 1
Output
NO
Input
5 5 7
0 0 2 4
2 3 4 5
3 5 5 2
5 5 5 4
0 3 5 1
2 2 4 4
0 5 4 1
Output
YES
Input
1 1 2
0 0 1 1
1 0 0 1
Output
NO
Submitted Solution:
```
def main():
from bisect import bisect_left as bl
class BIT():
def __init__(self, member):
self.member_list = sorted(member)
self.member_dict = {v: i+1 for i, v in enumerate(self.member_list)}
self.n = len(member)
self.maxmember = self.member_list[-1]
self.minmember = self.member_list[0]
self.maxbit = 2**(len(bin(self.n))-3)
self.bit = [0]*(self.n+1)
self.allsum = 0
# 要素iにvを追加する
def add(self, i, v):
x = self.member_dict[i]
self.allsum += v
while x < self.n + 1:
self.bit[x] += v
x += x & (-x)
# 位置0からiまでの和(sum(bit[:i]))を計算する
def sum(self, i):
ret = 0
x = i
while x > 0:
ret += self.bit[x]
x -= x & (-x)
return ret
# 位置iからjまでの和(sum(bit[i:j]))を計算する
def sum_range(self, i, j):
return self.sum(j) - self.sum(i)
# 和がw以上となる最小のインデックスを求める
def lowerbound(self, w):
if w <= 0:
return 0
x, k = 0, self.maxbit
while k:
if x+k <= self.n and self.bit[x+k] < w:
w -= self.bit[x+k]
x += k
k //= 2
return x
# vに一番近いv以上の値を求める
def greater(self, v):
if v > self.maxmember:
return None
p = self.sum(bl(self.member_list, v))
if p == self.allsum:
return None
return self.member_list[self.lowerbound(p+1)]
# vに一番近いv以下の値を求める
def smaller(self, v):
if v < self.minmember:
return None
b = bl(self.member_list, v)
if b == self.n:
b -= 1
elif self.member_list[b] != v:
b -= 1
p = self.sum(b+1)
if p == 0:
return None
return self.member_list[self.lowerbound(p)]
r, c, n = map(int, input().split())
xyzw = [list(map(int, input().split())) for _ in [0]*n]
outer = []
for x, y, z, w in xyzw:
if x in [0, r] or y in [0, c]:
if z in [0, r] or w in [0, c]:
if y == 0:
p = x
elif x == r:
p = r+y
elif y == c:
p = 2*r+c-x
else:
p = 2*r+2*c-y
if w == 0:
q = z
elif z == r:
q = r+w
elif w == c:
q = 2*r+c-z
else:
q = 2*r+2*c-w
if p > q:
p, q = q, p
outer.append((p, q))
member = [i for i, j in outer]+[j for i, j in outer]+[-1]+[2*r+2*c+1]
bit = BIT(member)
bit.add(-1, 1)
bit.add(2*r+2*c+1, 1)
outer.sort(key=lambda x: x[0]-x[1])
for a, b in outer:
if bit.greater(a) < b:
print("NO")
return
bit.add(a, 1)
bit.add(b, 1)
print("YES")
main()
``` | instruction | 0 | 43,673 | 16 | 87,346 |
Yes | output | 1 | 43,673 | 16 | 87,347 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke is playing a puzzle game. In this game, you are given a rectangular board of dimensions R × C, filled with numbers. Each integer i from 1 through N is written twice, at the coordinates (x_{i,1},y_{i,1}) and (x_{i,2},y_{i,2}).
The objective is to draw a curve connecting the pair of points where the same integer is written, for every integer from 1 through N. Here, the curves may not go outside the board or cross each other.
Determine whether this is possible.
Constraints
* 1 ≤ R,C ≤ 10^8
* 1 ≤ N ≤ 10^5
* 0 ≤ x_{i,1},x_{i,2} ≤ R(1 ≤ i ≤ N)
* 0 ≤ y_{i,1},y_{i,2} ≤ C(1 ≤ i ≤ N)
* All given points are distinct.
* All input values are integers.
Input
Input is given from Standard Input in the following format:
R C N
x_{1,1} y_{1,1} x_{1,2} y_{1,2}
:
x_{N,1} y_{N,1} x_{N,2} y_{N,2}
Output
Print `YES` if the objective is achievable; print `NO` otherwise.
Examples
Input
4 2 3
0 1 3 1
1 1 4 1
2 0 2 2
Output
YES
Input
2 2 4
0 0 2 2
2 0 0 1
0 2 1 2
1 1 2 1
Output
NO
Input
5 5 7
0 0 2 4
2 3 4 5
3 5 5 2
5 5 5 4
0 3 5 1
2 2 4 4
0 5 4 1
Output
YES
Input
1 1 2
0 0 1 1
1 0 0 1
Output
NO
Submitted Solution:
```
import sys
R,C,N = [int(i) for i in input().split()]
lec = [[0] * (C+1) for i in range(R+1)]
x1 = [0]*N
x2 = [0]*N
y1 = [0]*N
y2 = [0]*N
ngx1 = []
ngx2 = []
ngy1 = []
ngy2 = []
for i in range(0,N):
x1[i], y1[i], x2[i], y2[i] = [int(i) for i in input().split()]
for i in range(0,N):
if (x1[i] in [0,R] or y1[i] in [0,C]) and (x2[i] in [0,R] or y2[i] in [0,C]):
ngx1.append(x1[i])
ngx2.append(x2[i])
ngy1.append(y1[i])
ngy2.append(y2[i])
if len(ngx1) in [0,1]:
print('YES')
sys.exit()
else:
for j in range(1,len(ngx1)):
for i in range(j,len(ngx1)):
tc=(ngx1[0]-ngx2[0])*(ngy1[i]-ngy1[0])+(ngy1[0]-ngy2[0])*(ngx1[0]-ngx1[i])
td=(ngx1[0]-ngx2[0])*(ngy2[i]-ngy1[0])+(ngy1[0]-ngy2[0])*(ngx1[0]-ngx2[i])
if tc*td<0:
print('NO')
sys.exit()
print('YES')
``` | instruction | 0 | 43,674 | 16 | 87,348 |
No | output | 1 | 43,674 | 16 | 87,349 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke is playing a puzzle game. In this game, you are given a rectangular board of dimensions R × C, filled with numbers. Each integer i from 1 through N is written twice, at the coordinates (x_{i,1},y_{i,1}) and (x_{i,2},y_{i,2}).
The objective is to draw a curve connecting the pair of points where the same integer is written, for every integer from 1 through N. Here, the curves may not go outside the board or cross each other.
Determine whether this is possible.
Constraints
* 1 ≤ R,C ≤ 10^8
* 1 ≤ N ≤ 10^5
* 0 ≤ x_{i,1},x_{i,2} ≤ R(1 ≤ i ≤ N)
* 0 ≤ y_{i,1},y_{i,2} ≤ C(1 ≤ i ≤ N)
* All given points are distinct.
* All input values are integers.
Input
Input is given from Standard Input in the following format:
R C N
x_{1,1} y_{1,1} x_{1,2} y_{1,2}
:
x_{N,1} y_{N,1} x_{N,2} y_{N,2}
Output
Print `YES` if the objective is achievable; print `NO` otherwise.
Examples
Input
4 2 3
0 1 3 1
1 1 4 1
2 0 2 2
Output
YES
Input
2 2 4
0 0 2 2
2 0 0 1
0 2 1 2
1 1 2 1
Output
NO
Input
5 5 7
0 0 2 4
2 3 4 5
3 5 5 2
5 5 5 4
0 3 5 1
2 2 4 4
0 5 4 1
Output
YES
Input
1 1 2
0 0 1 1
1 0 0 1
Output
NO
Submitted Solution:
```
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def main():
R,C,N = LI()
a = []
def ff(x,y):
if x == 0:
return (0,y)
if x == R:
return (R,-y)
if y == 0:
return (R+1, -x)
return (1, x)
for _ in range(N):
x1,y1,x2,y2 = LI()
if (0 < x1 < R and 0 < y1 < C) or (0 < x2 < R and 0 < y2 < C):
continue
a.append((ff(x1,y1),_))
a.append((ff(x2,y2),_))
a.sort()
b = [a[i][1] for i in range(len(a))]
s = [None] * (len(b))
si = -1
for c in b:
if si < -1:
si += 1
s[0] = c
continue
if s[si] == c:
si -= 1
else:
si += 1
s[si] = c
if len(s) > 2:
return 'NO'
return 'YES'
print(main())
``` | instruction | 0 | 43,675 | 16 | 87,350 |
No | output | 1 | 43,675 | 16 | 87,351 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke is playing a puzzle game. In this game, you are given a rectangular board of dimensions R × C, filled with numbers. Each integer i from 1 through N is written twice, at the coordinates (x_{i,1},y_{i,1}) and (x_{i,2},y_{i,2}).
The objective is to draw a curve connecting the pair of points where the same integer is written, for every integer from 1 through N. Here, the curves may not go outside the board or cross each other.
Determine whether this is possible.
Constraints
* 1 ≤ R,C ≤ 10^8
* 1 ≤ N ≤ 10^5
* 0 ≤ x_{i,1},x_{i,2} ≤ R(1 ≤ i ≤ N)
* 0 ≤ y_{i,1},y_{i,2} ≤ C(1 ≤ i ≤ N)
* All given points are distinct.
* All input values are integers.
Input
Input is given from Standard Input in the following format:
R C N
x_{1,1} y_{1,1} x_{1,2} y_{1,2}
:
x_{N,1} y_{N,1} x_{N,2} y_{N,2}
Output
Print `YES` if the objective is achievable; print `NO` otherwise.
Examples
Input
4 2 3
0 1 3 1
1 1 4 1
2 0 2 2
Output
YES
Input
2 2 4
0 0 2 2
2 0 0 1
0 2 1 2
1 1 2 1
Output
NO
Input
5 5 7
0 0 2 4
2 3 4 5
3 5 5 2
5 5 5 4
0 3 5 1
2 2 4 4
0 5 4 1
Output
YES
Input
1 1 2
0 0 1 1
1 0 0 1
Output
NO
Submitted Solution:
```
r,c,n = map(int,input().split())
a = [list(map(int, input().split())) for _ in range(n)]
iru = []
for i in range(n):
if ((a[i][0] == 0 or a[i][0] == r or a[i][1] == 0 or a[i][1] == c) and (a[i][2] == 0 or a[i][2] == r or a[i][3] == 0 or a[i][3] == c)):
b = a[i]
b1 = [b[0],b[1]]
b2 = [b[2],b[3]]
if b1[0] == 0:
b1 = b1[1]
elif b1[1] == c:
b1 = b1[0] + b1[1]
elif b1[0] == r:
b1 = c*2 +r -b1[1]
else:
b1 = c*2 + r*2 -2 - b1[0]
if b2[0] == 0:
b2 = b2[1]
elif b2[1] == c:
b2 = b2[0] + b2[1]
elif b2[0] == r:
b2 = c*2 +r -b2[1]
else:
b2 = c*2 + r*2 -2 - b2[0]
if b1 > b2:
tmp = b1 +0
b1 = b2 +0
b2 = tmp + 0
iru.append([b1,b2])
iru = sorted(iru)
if len(iru) <= 1:
print("YES")
else:
ato = 0
for i in range(len(iru)):
b = iru[i]
if (b[0]< ato and ato < b[1]):
print("NO")
exit()
if ato < b[1]:
ato = b[1]
print("YES")
``` | instruction | 0 | 43,676 | 16 | 87,352 |
No | output | 1 | 43,676 | 16 | 87,353 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke is playing a puzzle game. In this game, you are given a rectangular board of dimensions R × C, filled with numbers. Each integer i from 1 through N is written twice, at the coordinates (x_{i,1},y_{i,1}) and (x_{i,2},y_{i,2}).
The objective is to draw a curve connecting the pair of points where the same integer is written, for every integer from 1 through N. Here, the curves may not go outside the board or cross each other.
Determine whether this is possible.
Constraints
* 1 ≤ R,C ≤ 10^8
* 1 ≤ N ≤ 10^5
* 0 ≤ x_{i,1},x_{i,2} ≤ R(1 ≤ i ≤ N)
* 0 ≤ y_{i,1},y_{i,2} ≤ C(1 ≤ i ≤ N)
* All given points are distinct.
* All input values are integers.
Input
Input is given from Standard Input in the following format:
R C N
x_{1,1} y_{1,1} x_{1,2} y_{1,2}
:
x_{N,1} y_{N,1} x_{N,2} y_{N,2}
Output
Print `YES` if the objective is achievable; print `NO` otherwise.
Examples
Input
4 2 3
0 1 3 1
1 1 4 1
2 0 2 2
Output
YES
Input
2 2 4
0 0 2 2
2 0 0 1
0 2 1 2
1 1 2 1
Output
NO
Input
5 5 7
0 0 2 4
2 3 4 5
3 5 5 2
5 5 5 4
0 3 5 1
2 2 4 4
0 5 4 1
Output
YES
Input
1 1 2
0 0 1 1
1 0 0 1
Output
NO
Submitted Solution:
```
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def main():
R,C,N = LI()
a = []
def ff(x,y):
if x == 0:
return (0,y)
if x == R:
return (R,-y)
if y == 0:
return (R+1, -x)
return (1, x)
for _ in range(N):
x1,y1,x2,y2 = LI()
if (0 < x1 < R and 0 < y1 < C) or (0 < x2 < R and 0 < y2 < C):
continue
a.append((ff(x1,y1),_))
a.append((ff(x2,y2),_))
a.sort()
b = [a[i][1] for i in range(len(a))]
s = []
for c in b:
if not s:
s.append(c)
continue
if c == s[-1]:
s = s[:-1]
else:
s.append(c)
if len(s) > 2:
return 'NO'
return 'YES'
print(main())
``` | instruction | 0 | 43,677 | 16 | 87,354 |
No | output | 1 | 43,677 | 16 | 87,355 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has a calculator. It has a display and two buttons.
Initially, the display shows an integer x. Snuke wants to change this value into another integer y, by pressing the following two buttons some number of times in arbitrary order:
* Button A: When pressed, the value on the display is incremented by 1.
* Button B: When pressed, the sign of the value on the display is reversed.
Find the minimum number of times Snuke needs to press the buttons to achieve his objective. It can be shown that the objective is always achievable regardless of the values of the integers x and y.
Constraints
* x and y are integers.
* |x|, |y| ≤ 10^9
* x and y are different.
Input
The input is given from Standard Input in the following format:
x y
Output
Print the minimum number of times Snuke needs to press the buttons to achieve his objective.
Examples
Input
10 20
Output
10
Input
10 -10
Output
1
Input
-10 -20
Output
12 | instruction | 0 | 43,678 | 16 | 87,356 |
"Correct Solution:
```
x, y = map(int, input().split())
diff = abs(abs(x)-abs(y))
if abs(x) < abs(y):
if x < 0:
diff += 1
if y < 0:
diff += 1
else:
if x > 0:
diff += 1
if y > 0:
diff += 1
print(diff)
``` | output | 1 | 43,678 | 16 | 87,357 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has a calculator. It has a display and two buttons.
Initially, the display shows an integer x. Snuke wants to change this value into another integer y, by pressing the following two buttons some number of times in arbitrary order:
* Button A: When pressed, the value on the display is incremented by 1.
* Button B: When pressed, the sign of the value on the display is reversed.
Find the minimum number of times Snuke needs to press the buttons to achieve his objective. It can be shown that the objective is always achievable regardless of the values of the integers x and y.
Constraints
* x and y are integers.
* |x|, |y| ≤ 10^9
* x and y are different.
Input
The input is given from Standard Input in the following format:
x y
Output
Print the minimum number of times Snuke needs to press the buttons to achieve his objective.
Examples
Input
10 20
Output
10
Input
10 -10
Output
1
Input
-10 -20
Output
12 | instruction | 0 | 43,679 | 16 | 87,358 |
"Correct Solution:
```
x, y = map(int, input().split())
print(min(a for a in [y - x, y + x + 1, -y - x + 1, -y + x + 2] if a >= 0))
``` | output | 1 | 43,679 | 16 | 87,359 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has a calculator. It has a display and two buttons.
Initially, the display shows an integer x. Snuke wants to change this value into another integer y, by pressing the following two buttons some number of times in arbitrary order:
* Button A: When pressed, the value on the display is incremented by 1.
* Button B: When pressed, the sign of the value on the display is reversed.
Find the minimum number of times Snuke needs to press the buttons to achieve his objective. It can be shown that the objective is always achievable regardless of the values of the integers x and y.
Constraints
* x and y are integers.
* |x|, |y| ≤ 10^9
* x and y are different.
Input
The input is given from Standard Input in the following format:
x y
Output
Print the minimum number of times Snuke needs to press the buttons to achieve his objective.
Examples
Input
10 20
Output
10
Input
10 -10
Output
1
Input
-10 -20
Output
12 | instruction | 0 | 43,680 | 16 | 87,360 |
"Correct Solution:
```
x, y = map(int,input().split())
ans = abs(abs(x)-abs(y))
if x * y > 0 and y >= x:
pass
elif x * y < 0:
ans += 1
elif x * y == 0:
if x > y:
ans += 1
else:
ans += 2
print(ans)
``` | output | 1 | 43,680 | 16 | 87,361 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has a calculator. It has a display and two buttons.
Initially, the display shows an integer x. Snuke wants to change this value into another integer y, by pressing the following two buttons some number of times in arbitrary order:
* Button A: When pressed, the value on the display is incremented by 1.
* Button B: When pressed, the sign of the value on the display is reversed.
Find the minimum number of times Snuke needs to press the buttons to achieve his objective. It can be shown that the objective is always achievable regardless of the values of the integers x and y.
Constraints
* x and y are integers.
* |x|, |y| ≤ 10^9
* x and y are different.
Input
The input is given from Standard Input in the following format:
x y
Output
Print the minimum number of times Snuke needs to press the buttons to achieve his objective.
Examples
Input
10 20
Output
10
Input
10 -10
Output
1
Input
-10 -20
Output
12 | instruction | 0 | 43,681 | 16 | 87,362 |
"Correct Solution:
```
x,y=map(int,input().split())
count=0
xlist=[x,-x,x,-x]
ylist=[y,y,-y,-y]
numlist=[0,1,1,2]
ans=10**9+7
for i in range(4):
if xlist[i] <= ylist[i]:
ans=min(ans,numlist[i]+ylist[i]-xlist[i])
print(ans)
``` | output | 1 | 43,681 | 16 | 87,363 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has a calculator. It has a display and two buttons.
Initially, the display shows an integer x. Snuke wants to change this value into another integer y, by pressing the following two buttons some number of times in arbitrary order:
* Button A: When pressed, the value on the display is incremented by 1.
* Button B: When pressed, the sign of the value on the display is reversed.
Find the minimum number of times Snuke needs to press the buttons to achieve his objective. It can be shown that the objective is always achievable regardless of the values of the integers x and y.
Constraints
* x and y are integers.
* |x|, |y| ≤ 10^9
* x and y are different.
Input
The input is given from Standard Input in the following format:
x y
Output
Print the minimum number of times Snuke needs to press the buttons to achieve his objective.
Examples
Input
10 20
Output
10
Input
10 -10
Output
1
Input
-10 -20
Output
12 | instruction | 0 | 43,682 | 16 | 87,364 |
"Correct Solution:
```
x, y= map(int,input().split())
ans = 10000000000
if x <= y:
ans = y-x
if -x <= y:
ans = min(y+x+1,ans)
if x <= -y:
ans = min(-y-x+1,ans)
if -x <= -y:
ans = min(-y+x+2,ans)
print(ans)
``` | output | 1 | 43,682 | 16 | 87,365 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has a calculator. It has a display and two buttons.
Initially, the display shows an integer x. Snuke wants to change this value into another integer y, by pressing the following two buttons some number of times in arbitrary order:
* Button A: When pressed, the value on the display is incremented by 1.
* Button B: When pressed, the sign of the value on the display is reversed.
Find the minimum number of times Snuke needs to press the buttons to achieve his objective. It can be shown that the objective is always achievable regardless of the values of the integers x and y.
Constraints
* x and y are integers.
* |x|, |y| ≤ 10^9
* x and y are different.
Input
The input is given from Standard Input in the following format:
x y
Output
Print the minimum number of times Snuke needs to press the buttons to achieve his objective.
Examples
Input
10 20
Output
10
Input
10 -10
Output
1
Input
-10 -20
Output
12 | instruction | 0 | 43,683 | 16 | 87,366 |
"Correct Solution:
```
a,b = map(int,input().split())
y = abs(abs(a)-abs(b))
if 0 < b < a or b < a < 0:
print(y+2)
elif a*b < 0 or (a == 0 and b < 0) or (a > 0 and b == 0):
print(y+1)
else:
print(y)
``` | output | 1 | 43,683 | 16 | 87,367 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has a calculator. It has a display and two buttons.
Initially, the display shows an integer x. Snuke wants to change this value into another integer y, by pressing the following two buttons some number of times in arbitrary order:
* Button A: When pressed, the value on the display is incremented by 1.
* Button B: When pressed, the sign of the value on the display is reversed.
Find the minimum number of times Snuke needs to press the buttons to achieve his objective. It can be shown that the objective is always achievable regardless of the values of the integers x and y.
Constraints
* x and y are integers.
* |x|, |y| ≤ 10^9
* x and y are different.
Input
The input is given from Standard Input in the following format:
x y
Output
Print the minimum number of times Snuke needs to press the buttons to achieve his objective.
Examples
Input
10 20
Output
10
Input
10 -10
Output
1
Input
-10 -20
Output
12 | instruction | 0 | 43,684 | 16 | 87,368 |
"Correct Solution:
```
x,y = (int(i) for i in input().split())
res = abs(y-x)*2
res = y-x if y>=x else res
res = min(res,-y-x+1) if -y>=x else res
res = min(res,y+x+1) if y>=-x else res
res = min(res,x-y+2) if x>y else res
print(res)
``` | output | 1 | 43,684 | 16 | 87,369 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has a calculator. It has a display and two buttons.
Initially, the display shows an integer x. Snuke wants to change this value into another integer y, by pressing the following two buttons some number of times in arbitrary order:
* Button A: When pressed, the value on the display is incremented by 1.
* Button B: When pressed, the sign of the value on the display is reversed.
Find the minimum number of times Snuke needs to press the buttons to achieve his objective. It can be shown that the objective is always achievable regardless of the values of the integers x and y.
Constraints
* x and y are integers.
* |x|, |y| ≤ 10^9
* x and y are different.
Input
The input is given from Standard Input in the following format:
x y
Output
Print the minimum number of times Snuke needs to press the buttons to achieve his objective.
Examples
Input
10 20
Output
10
Input
10 -10
Output
1
Input
-10 -20
Output
12 | instruction | 0 | 43,685 | 16 | 87,370 |
"Correct Solution:
```
a, b = map(int, input().split())
ans = 0
if a * b < 0:
ans += 1
elif (a > 0 and b == 0) or (a == 0 and b < 0):
ans += 1
elif b < a:
ans += 2
ans += abs(abs(a) - abs(b))
print(ans)
``` | output | 1 | 43,685 | 16 | 87,371 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has a calculator. It has a display and two buttons.
Initially, the display shows an integer x. Snuke wants to change this value into another integer y, by pressing the following two buttons some number of times in arbitrary order:
* Button A: When pressed, the value on the display is incremented by 1.
* Button B: When pressed, the sign of the value on the display is reversed.
Find the minimum number of times Snuke needs to press the buttons to achieve his objective. It can be shown that the objective is always achievable regardless of the values of the integers x and y.
Constraints
* x and y are integers.
* |x|, |y| ≤ 10^9
* x and y are different.
Input
The input is given from Standard Input in the following format:
x y
Output
Print the minimum number of times Snuke needs to press the buttons to achieve his objective.
Examples
Input
10 20
Output
10
Input
10 -10
Output
1
Input
-10 -20
Output
12
Submitted Solution:
```
x, y = map(int, input().split())
print(min(max(y-x, x-y+2), abs(y+x)+1))
``` | instruction | 0 | 43,686 | 16 | 87,372 |
Yes | output | 1 | 43,686 | 16 | 87,373 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has a calculator. It has a display and two buttons.
Initially, the display shows an integer x. Snuke wants to change this value into another integer y, by pressing the following two buttons some number of times in arbitrary order:
* Button A: When pressed, the value on the display is incremented by 1.
* Button B: When pressed, the sign of the value on the display is reversed.
Find the minimum number of times Snuke needs to press the buttons to achieve his objective. It can be shown that the objective is always achievable regardless of the values of the integers x and y.
Constraints
* x and y are integers.
* |x|, |y| ≤ 10^9
* x and y are different.
Input
The input is given from Standard Input in the following format:
x y
Output
Print the minimum number of times Snuke needs to press the buttons to achieve his objective.
Examples
Input
10 20
Output
10
Input
10 -10
Output
1
Input
-10 -20
Output
12
Submitted Solution:
```
x,y = map(int,input().split())
a = y-x if y-x >= 0 else float("inf")
b = y+x+1 if y+x >= 0 else float("inf")
c = x-y+2 if x-y >=0 else float('inf')
d = -(y+x)+1 if x+y <=0 else float('inf')
print(min(a,b,c,d))
``` | instruction | 0 | 43,687 | 16 | 87,374 |
Yes | output | 1 | 43,687 | 16 | 87,375 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has a calculator. It has a display and two buttons.
Initially, the display shows an integer x. Snuke wants to change this value into another integer y, by pressing the following two buttons some number of times in arbitrary order:
* Button A: When pressed, the value on the display is incremented by 1.
* Button B: When pressed, the sign of the value on the display is reversed.
Find the minimum number of times Snuke needs to press the buttons to achieve his objective. It can be shown that the objective is always achievable regardless of the values of the integers x and y.
Constraints
* x and y are integers.
* |x|, |y| ≤ 10^9
* x and y are different.
Input
The input is given from Standard Input in the following format:
x y
Output
Print the minimum number of times Snuke needs to press the buttons to achieve his objective.
Examples
Input
10 20
Output
10
Input
10 -10
Output
1
Input
-10 -20
Output
12
Submitted Solution:
```
x,y = map(int, input().split())
m = 10**10
for i in (0,1):
for j in (0,1):
if y*(-1)**j-x*(-1)**i>=0:
cur = y*(-1)**j-x*(-1)**i + i + j
if m>cur:
m = cur
print(m)
``` | instruction | 0 | 43,688 | 16 | 87,376 |
Yes | output | 1 | 43,688 | 16 | 87,377 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.