message stringlengths 2 44.5k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 276 109k | cluster float64 23 23 | __index_level_0__ int64 552 217k |
|---|---|---|---|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 ≤ y < x ≤ 100 000) — the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer — the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>.
In the second sample test, Memory can do <image>.
In the third sample test, Memory can do: <image>
<image>. | instruction | 0 | 5,486 | 23 | 10,972 |
Tags: greedy, math
Correct Solution:
```
y, x = map(int, input().split())
def f(a):
a = sorted(a)
if a[0] == y:
return 0
a[0] = min(sum(a[1:]) - 1, y)
return 1 + f(a)
print(f([x, x, x]))
``` | output | 1 | 5,486 | 23 | 10,973 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 ≤ y < x ≤ 100 000) — the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer — the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>.
In the second sample test, Memory can do <image>.
In the third sample test, Memory can do: <image>
<image>. | instruction | 0 | 5,487 | 23 | 10,974 |
Tags: greedy, math
Correct Solution:
```
s=input().split()
tr=int(s[0])
gl=int(s[1])
list=list(range(3))
list[0]=gl
list[1]=gl
list[2]=gl
b=0
while list[0]!=tr or list[1]!=tr or list[2]!=tr:
if (list[1]+list[2]-1)>tr:
if list[0]!=tr:
list[0]=tr
b+=1
else:
if list[0]!=tr:
list[0]=list[1]+list[2]-1
b+=1
if (list[0]+list[2]-1)>tr:
if list[1]!=tr:
list[1]=tr
b+=1
else:
if list[1]!=tr:
list[1]=list[0]+list[2]-1
b+=1
if (list[0]+list[1]-1)>tr:
if list[2]!=tr:
list[2]=tr
b+=1
else:
if list[2]!=tr:
list[2]=list[0]+list[1]-1
b+=1
print(b)
``` | output | 1 | 5,487 | 23 | 10,975 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 ≤ y < x ≤ 100 000) — the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer — the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>.
In the second sample test, Memory can do <image>.
In the third sample test, Memory can do: <image>
<image>. | instruction | 0 | 5,488 | 23 | 10,976 |
Tags: greedy, math
Correct Solution:
```
x, y = map(int, input().split())
a = b = c = y
ans = 0
while min(a, b, c) != x:
arr = list(sorted([a, b, c]))
arr[0] = min(x, arr[1] + arr[2] - 1)
a, b, c = arr
ans += 1
print(ans)
``` | output | 1 | 5,488 | 23 | 10,977 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 ≤ y < x ≤ 100 000) — the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer — the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>.
In the second sample test, Memory can do <image>.
In the third sample test, Memory can do: <image>
<image>. | instruction | 0 | 5,489 | 23 | 10,978 |
Tags: greedy, math
Correct Solution:
```
#!/usr/bin/env python
#-*-coding:utf-8 -*-
x,y=map(int,input().split())
N=3
L=N*[y]
y=i=0
while x>L[i]:
j=(1+i)%N
L[i]=L[(i-1)%N]-1+L[j]
i=j
y+=1
print(y)
``` | output | 1 | 5,489 | 23 | 10,979 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 ≤ y < x ≤ 100 000) — the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer — the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>.
In the second sample test, Memory can do <image>.
In the third sample test, Memory can do: <image>
<image>.
Submitted Solution:
```
s, t = map(int, input().split())
s = [s, s, s]
t = [t, t, t]
it = 0
i = 0
while s[i] != t[i]:
t[i] = min(s[i], t[(i+1)%3] + t[(i+2)%3] - 1)
it += 1
i = (i+1)%3
print(it)
``` | instruction | 0 | 5,490 | 23 | 10,980 |
Yes | output | 1 | 5,490 | 23 | 10,981 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 ≤ y < x ≤ 100 000) — the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer — the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>.
In the second sample test, Memory can do <image>.
In the third sample test, Memory can do: <image>
<image>.
Submitted Solution:
```
x, y = list(map(int, input().split()))
a = [y] * 3
ans = 0
while (1):
if (a[0] == x and a[1] == x and a[2] == x):
break
a[0] = min(x, a[1] + a[2] - 1)
a.sort()
ans += 1
print(ans)
``` | instruction | 0 | 5,491 | 23 | 10,982 |
Yes | output | 1 | 5,491 | 23 | 10,983 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 ≤ y < x ≤ 100 000) — the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer — the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>.
In the second sample test, Memory can do <image>.
In the third sample test, Memory can do: <image>
<image>.
Submitted Solution:
```
# import itertools
import bisect
# import math
from collections import defaultdict
import os
import sys
from io import BytesIO, IOBase
# sys.setrecursionlimit(10 ** 5)
ii = lambda: int(input())
lmii = lambda: list(map(int, input().split()))
slmii = lambda: sorted(map(int, input().split()))
li = lambda: list(input())
mii = lambda: map(int, input().split())
msi = lambda: map(str, input().split())
def gcd(a, b):
if b == 0: return a
return gcd(b, a % b)
def lcm(a, b): return (a * b) // gcd(a, b)
def main():
# for _ in " " * int(input()):
x, y = mii()
cnt = 0
a, b, c = y, y, y
while max(a, b, c) < x:
ss = sorted([a, b, c])
a = ss[0]
b = ss[1]
c = ss[2]
a = min(x, b + c - 1)
cnt += 1
print(cnt + 2)
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 | 5,492 | 23 | 10,984 |
Yes | output | 1 | 5,492 | 23 | 10,985 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 ≤ y < x ≤ 100 000) — the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer — the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>.
In the second sample test, Memory can do <image>.
In the third sample test, Memory can do: <image>
<image>.
Submitted Solution:
```
import sys
def fastio():
from io import StringIO
from atexit import register
global input
sys.stdin = StringIO(sys.stdin.read())
input = lambda : sys.stdin.readline().rstrip('\r\n')
sys.stdout = StringIO()
register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()
INF = 10**20
MOD = 10**9 + 7
I = lambda:list(map(int,input().split()))
from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br
r, l = I()
a = [l, l, l]
ans = 0
while a[-1] != r or a[0] != r:
x = a[1] + a[2]
a[0] = min(r, x - 1)
a.sort()
ans += 1
print(ans)
``` | instruction | 0 | 5,493 | 23 | 10,986 |
Yes | output | 1 | 5,493 | 23 | 10,987 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 ≤ y < x ≤ 100 000) — the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer — the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>.
In the second sample test, Memory can do <image>.
In the third sample test, Memory can do: <image>
<image>.
Submitted Solution:
```
x, y = map(int, input().split())
counter = 0
x, y = min(x,y), max(x,y)
x1 = x
x2 = x
x3 = x
while y > x1 and y > x2 and y > x3:
if x1 != y:
x1 = min(x1 + x2 - 1, y)
counter += 1
if x2 != y:
x2 = min(x1 + x3 - 1, y)
counter += 1
if x3 != y:
x3 = min(x1 + x2 - 1, y)
counter += 1
print(counter)
``` | instruction | 0 | 5,494 | 23 | 10,988 |
No | output | 1 | 5,494 | 23 | 10,989 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 ≤ y < x ≤ 100 000) — the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer — the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>.
In the second sample test, Memory can do <image>.
In the third sample test, Memory can do: <image>
<image>.
Submitted Solution:
```
#!/usr/bin/env python
#-*-coding:utf-8 -*-
y,x=map(int,input().split())
N=3
L=N*[y]
y=i=0
while x>L[i]:
j=(1+i)%N
L[i]=L[(i-1)%N]-1+L[j]
i=j
y+=1
print(y)
``` | instruction | 0 | 5,495 | 23 | 10,990 |
No | output | 1 | 5,495 | 23 | 10,991 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 ≤ y < x ≤ 100 000) — the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer — the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>.
In the second sample test, Memory can do <image>.
In the third sample test, Memory can do: <image>
<image>.
Submitted Solution:
```
x, y = list(map(int, input().split()))
a = [3] * y
ans = 0
while (1):
if (a[0] == x and a[1] == x and a[2] == x):
break
a[0] = min(x, a[1] + a[2] - 1)
a.sort()
ans += 1
print(ans)
``` | instruction | 0 | 5,496 | 23 | 10,992 |
No | output | 1 | 5,496 | 23 | 10,993 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 ≤ y < x ≤ 100 000) — the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer — the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>.
In the second sample test, Memory can do <image>.
In the third sample test, Memory can do: <image>
<image>.
Submitted Solution:
```
import math
x, y = map(int, input().split())
m = math.floor(x / y)
res = math.ceil(math.log(m, 2))
print(3 + res)
``` | instruction | 0 | 5,497 | 23 | 10,994 |
No | output | 1 | 5,497 | 23 | 10,995 |
Provide a correct Python 3 solution for this coding contest problem.
Ordinary Jigsaw puzzles are solved with visual hints; players solve a puzzle with the picture which the puzzle shows on finish, and the diverse patterns of pieces. Such Jigsaw puzzles may be suitable for human players, because they require abilities of pattern recognition and imagination.
On the other hand, "Jigsaw puzzles" described below may be just the things for simple-minded computers.
As shown in Figure 1, a puzzle is composed of nine square pieces, and each of the four edges of a piece is labeled with one of the following eight symbols:
"R", "G", "B", "W", "r", "g", "b", and "w".
<image>
---
Figure 1: The nine pieces of a puzzle
In a completed puzzle, the nine pieces are arranged in a 3 x 3 grid, and each of the 12 pairs of edges facing each other must be labeled with one of the following four combinations of symbols:
"R" with "r", "G" with "g", "B" with "b", and "W" with "w".
For example, an edge labeled "R" can only face an edge with "r". Figure 2 is an example of a completed state of a puzzle. In the figure, edges under this restriction are indicated by shadowing their labels. The player can freely move and rotate the pieces, but cannot turn them over. There are no symbols on the reverse side of a piece !
<image>
---
Figure 2: A completed puzzle example
Each piece is represented by a sequence of the four symbols on the piece, starting with the symbol of the top edge, followed by the symbols of the right edge, the bottom edge, and the left edge. For example, gwgW represents the leftmost piece in Figure 1. Note that the same piece can be represented as wgWg, gWgw or Wgwg since you can rotate it in 90, 180 or 270 degrees.
The mission for you is to create a program which counts the number of solutions. It is needless to say that these numbers must be multiples of four, because, as shown in Figure 3, a configuration created by rotating a solution in 90, 180 or 270 degrees is also a solution.
<image>
---
Figure 3: Four obvious variations for a completed puzzle
A term "rotationally equal" is defined; if two different pieces are identical when one piece is rotated (in 90, 180 or 270 degrees), they are rotationally equal. For example, WgWr and WrWg are rotationally equal.
Another term "rotationally symmetric" is defined; if a piece is rotationally equal to itself, it is rotationally symmetric. For example, a piece gWgW is rotationally symmetric.
Given puzzles satisfy the following three conditions:
1. There is no identical pair of pieces in a puzzle.
2. There is no rotationally equal pair of pieces in a puzzle.
3. There is no rotationally symmetric piece in a puzzle.
Input
The input consists of multiple puzzles.
N
Puzzle1
Puzzle2
. . .
PuzzleN
N is the number of puzzles. Each Puzzlei gives a puzzle with a single line of 44 characters, consisting of four-character representations of the nine pieces of the puzzle, separated by a space character. For example, the following line represents the puzzle in Figure 1.
gwgW RBbW GWrb GRRb BWGr Rbgw rGbR gBrg GRwb
Output
For each Puzzlei , the number of its solutions should be the output, each in a separate line.
Example
Input
6
WwRR wwrg RRGb rGBG RGrb RrRg RGrg rgBB Wrgr
RrGb WWGR rGgb Wbrg wgBb GgBg WbBG Wwwg WWGG
RBbr Wrbr wGGG wggR WgGR WBWb WRgB wBgG WBgG
wBrg rGgb WRrB WWbw wRRB RbbB WRrb wrbb WgrG
WrwB WWww wRRB WGGb Wbbg WBgG WrbG Wrww RBgg
WWgg RBrr Rggr RGBg Wbgr WGbg WBbr WGWB GGGg
Output
40
8
32
4
12
0 | instruction | 0 | 5,746 | 23 | 11,492 |
"Correct Solution:
```
p_ch = [True] * 9
rot = ((0, 1, 2, 3), (1, 2, 3, 0), (2, 3, 0, 1), (3, 0, 1, 2))
adj = ['c'] * 13
# record indices of right and botoom adjacent edge label. 12 is invalid.
rec_adj = [[0, 2], [1, 3], [12, 4], [5, 7], [6, 8], [12, 9], [10, 12],
[11, 12], [12, 12]]
# refernce indices to top and left adjacent edge label. 12 is invalid.
ref_adj = [[12, 12], [12, 0], [12, 1], [2, 12], [3, 5], [4, 6], [7, 12],
[8, 10], [9, 11]]
tr = dict(zip("RGBWrgbw", "rgbwRGBW"))
def dfs(i = 0, a = []):
if i == 9:
global ans
ans += 1
else:
for j, p in enumerate(pieces):
if p_ch[j]:
ati, ali = ref_adj[i]
for t, r, b, l in rot:
if ati == 12 or tr[p[t]] == adj[ati]:
if ali == 12 or tr[p[l]] == adj[ali]:
ari, abi = rec_adj[i]
adj[ari] = p[r]
adj[abi] = p[b]
p_ch[j] = False
dfs(i + 1)
p_ch[j] = True
from sys import stdin
file_input = stdin
N = int(file_input.readline())
for line in file_input:
pieces = line.split()
ans = 0
dfs()
print(ans)
``` | output | 1 | 5,746 | 23 | 11,493 |
Provide a correct Python 3 solution for this coding contest problem.
Problem statement
There are rectangles with vertical and horizontal lengths of h and w, and square squares with a side length of 1 are spread inside. If the upper left cell is (0,0) and the cell to the right of j below (0,0) is represented as (i, j), (i, j) is i + j. If is even, it is painted red, and if it is odd, it is painted blue.
Now, the upper left vertex of (0,0) and the lower right vertex of (h − 1, w − 1) are connected by a line segment. If the length of the red part through which this line segment passes is a and the length of the blue part is b, the ratio a: b is an integer ratio. Express a: b in the simplest way (with relatively prime integers).
input
T
h_1 \ w_1
...
h_T \ w_T
One file contains T inputs. The T in the first line and the vertical and horizontal lengths h_i and w_i in the Tth input are input in the 1 + i line.
Constraint
* An integer
* 1 ≤ T ≤ 1000
* 1 ≤ h_i, w_i ≤ 109
output
Output the answer for each case separated by 1 and separated by spaces. It spans T lines in total.
sample
Sample input 1
3
twenty three
3 3
4 3
Sample output 1
1 1
Ten
1 1
<image>
Example
Input
3
2 3
3 3
4 3
Output
1 1
1 0
1 1 | instruction | 0 | 5,778 | 23 | 11,556 |
"Correct Solution:
```
def gcd(a,b):
if a == 0:
return b
else:
return gcd(b%a,a)
t = int(input())
while t:
t -= 1
a,b = map(int, input().split())
c = gcd(a,b)
a = a//c
b = b//c
if a == b:
ans1 = 1
ans2 = 0
elif a % 2 == 0 or b % 2 == 0:
ans1 = 1
ans2 = 1
else:
ans1 = a*b//2+1
ans2 = a*b//2
print(ans1,ans2)
``` | output | 1 | 5,778 | 23 | 11,557 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two rectangles on a plane. The centers of both rectangles are located in the origin of coordinates (meaning the center of the rectangle's symmetry). The first rectangle's sides are parallel to the coordinate axes: the length of the side that is parallel to the Ox axis, equals w, the length of the side that is parallel to the Oy axis, equals h. The second rectangle can be obtained by rotating the first rectangle relative to the origin of coordinates by angle α.
<image>
Your task is to find the area of the region which belongs to both given rectangles. This region is shaded in the picture.
Input
The first line contains three integers w, h, α (1 ≤ w, h ≤ 106; 0 ≤ α ≤ 180). Angle α is given in degrees.
Output
In a single line print a real number — the area of the region which belongs to both given rectangles.
The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 6.
Examples
Input
1 1 45
Output
0.828427125
Input
6 4 30
Output
19.668384925
Note
The second sample has been drawn on the picture above. | instruction | 0 | 6,095 | 23 | 12,190 |
Tags: geometry
Correct Solution:
```
#!/usr/bin/python3
from math import sin, cos, pi, atan2
w, h, a = tuple(map(int, input().split()))
if a in [0, 180]:
print(w * h)
elif a == 90:
print(min(w, h)**2)
else:
a *= pi / 180
w /= 2
h /= 2
base = [(w, h), (-w, h), (-w, -h), (w, -h)]
rot = [(x * cos(a) - y * sin(a), x * sin(a) + y * cos(a)) for x, y in base]
pol = []
for i, j in zip(range(-1, 3), range(4)):
t = (w - rot[i][0]) / (rot[j][0] - rot[i][0])
if 0 <= t <= 1:
pol.append((w, rot[i][1] + (rot[j][1] - rot[i][1]) * t))
t = (-w - rot[i][0]) / (rot[j][0] - rot[i][0])
if 0 <= t <= 1:
pol.append((-w, rot[i][1] + (rot[j][1] - rot[i][1]) * t))
t = (h - rot[i][1]) / (rot[j][1] - rot[i][1])
if 0 <= t <= 1:
pol.append((rot[i][0] + (rot[j][0] - rot[i][0]) * t, h))
t = (-h - rot[i][1]) / (rot[j][1] - rot[i][1])
if 0 <= t <= 1:
pol.append((rot[i][0] + (rot[j][0] - rot[i][0]) * t, -h))
pol.sort(key=lambda x: atan2(*x))
print('%0.9f' % (sum([abs(pol[i][0] * pol[j][1] - pol[i][1] * pol[j][0]) for i, j in zip(range(-1, len(pol) - 1), range(len(pol)))]) / 2))
``` | output | 1 | 6,095 | 23 | 12,191 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two rectangles on a plane. The centers of both rectangles are located in the origin of coordinates (meaning the center of the rectangle's symmetry). The first rectangle's sides are parallel to the coordinate axes: the length of the side that is parallel to the Ox axis, equals w, the length of the side that is parallel to the Oy axis, equals h. The second rectangle can be obtained by rotating the first rectangle relative to the origin of coordinates by angle α.
<image>
Your task is to find the area of the region which belongs to both given rectangles. This region is shaded in the picture.
Input
The first line contains three integers w, h, α (1 ≤ w, h ≤ 106; 0 ≤ α ≤ 180). Angle α is given in degrees.
Output
In a single line print a real number — the area of the region which belongs to both given rectangles.
The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 6.
Examples
Input
1 1 45
Output
0.828427125
Input
6 4 30
Output
19.668384925
Note
The second sample has been drawn on the picture above. | instruction | 0 | 6,096 | 23 | 12,192 |
Tags: geometry
Correct Solution:
```
import os
import sys
from io import BytesIO, IOBase
import math
def main():
pass
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")
def binary(n):
return (bin(n).replace("0b", ""))
def decimal(s):
return (int(s, 2))
def pow2(n):
p = 0
while (n > 1):
n //= 2
p += 1
return (p)
def primeFactors(n):
l=[]
while n % 2 == 0:
l.append(2)
n = n / 2
for i in range(3, int(math.sqrt(n)) + 1, 2):
while n % i == 0:
l.append(i)
n = n / i
if n > 2:
l.append(int(n))
return (l)
def isPrime(n):
if (n == 1):
return (False)
else:
root = int(n ** 0.5)
root += 1
for i in range(2, root):
if (n % i == 0):
return (False)
return (True)
def maxPrimeFactors(n):
maxPrime = -1
while n % 2 == 0:
maxPrime = 2
n >>= 1
for i in range(3, int(math.sqrt(n)) + 1, 2):
while n % i == 0:
maxPrime = i
n = n / i
if n > 2:
maxPrime = n
return int(maxPrime)
w,h,a=map(int,input().split())
if(a==0 or a==180):
print(w*h)
else:
w,h=max(w,h),min(w,h)
if(a>90):
a=180-a
a=(a*math.pi)/180
#print(h*(1+math.cos(a)),w*math.sin(a))
if(h*(1+math.cos(a))< w*math.sin(a)):
print(pow(h,2)/math.sin(a))
else:
#print("HEY")
#print(math.sin(a))
x=h-w*((math.cos(a)+1)/math.sin(a))
t=math.tan(a)-((math.cos(a)+1)*(math.cos(a)+1)/(math.cos(a)*math.sin(a)))
x=x/t
x=abs(x)
b2=w-x-(x/math.cos(a))
b2=abs(b2)
h2=b2/math.tan(a)
h2=abs(h2)
h1=h-h2-(h2/math.cos(a))
h1=abs(h1)
tbm=((x*h1)+(b2*h2))
#print(x,h1,h2,b2)
print((h*w)-tbm)
``` | output | 1 | 6,096 | 23 | 12,193 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two rectangles on a plane. The centers of both rectangles are located in the origin of coordinates (meaning the center of the rectangle's symmetry). The first rectangle's sides are parallel to the coordinate axes: the length of the side that is parallel to the Ox axis, equals w, the length of the side that is parallel to the Oy axis, equals h. The second rectangle can be obtained by rotating the first rectangle relative to the origin of coordinates by angle α.
<image>
Your task is to find the area of the region which belongs to both given rectangles. This region is shaded in the picture.
Input
The first line contains three integers w, h, α (1 ≤ w, h ≤ 106; 0 ≤ α ≤ 180). Angle α is given in degrees.
Output
In a single line print a real number — the area of the region which belongs to both given rectangles.
The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 6.
Examples
Input
1 1 45
Output
0.828427125
Input
6 4 30
Output
19.668384925
Note
The second sample has been drawn on the picture above. | instruction | 0 | 6,097 | 23 | 12,194 |
Tags: geometry
Correct Solution:
```
from math import sin, cos, tan, atan, pi
def main():
w, h, a = map(int, input().split())
a = min(a, 180 - a) * pi / 180
if h > w:
h, w = w, h
if h * (1 + cos(a)) < w * sin(a):
res = h * h / sin(a)
else:
res = h * w - ((w - h * tan(a / 2)) ** 2 * tan(a) + (h - w * tan(a / 2)) ** 2 * tan(a)) / 4
print('{:.9f}'.format(res))
if __name__ == '__main__':
main()
# Made By Mostafa_Khaled
``` | output | 1 | 6,097 | 23 | 12,195 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two rectangles on a plane. The centers of both rectangles are located in the origin of coordinates (meaning the center of the rectangle's symmetry). The first rectangle's sides are parallel to the coordinate axes: the length of the side that is parallel to the Ox axis, equals w, the length of the side that is parallel to the Oy axis, equals h. The second rectangle can be obtained by rotating the first rectangle relative to the origin of coordinates by angle α.
<image>
Your task is to find the area of the region which belongs to both given rectangles. This region is shaded in the picture.
Input
The first line contains three integers w, h, α (1 ≤ w, h ≤ 106; 0 ≤ α ≤ 180). Angle α is given in degrees.
Output
In a single line print a real number — the area of the region which belongs to both given rectangles.
The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 6.
Examples
Input
1 1 45
Output
0.828427125
Input
6 4 30
Output
19.668384925
Note
The second sample has been drawn on the picture above. | instruction | 0 | 6,098 | 23 | 12,196 |
Tags: geometry
Correct Solution:
```
import math
def rot_by_a(p, a):
return (p[0] * math.cos(a) - p[1] * math.sin(a),
p[0] * math.sin(a) + p[1] * math.cos(a))
h, w, alpha = map(int, input().split())
if h > w:
h, w = w, h
if alpha > 90:
alpha = 180 - alpha
ang = math.radians(alpha)
b = 2 * math.atan(h / w) # why not * 2 ?
#print(math.degrees(b))
if alpha == 0:
# print("one")
print(h * w)
elif alpha == 90:
# print("two")
print(h * h)
elif ang > b:
# print("three")
side = h / math.sin(ang)
print(side * h)
else:
# print("four")
left_top = (w / 2, h / 2)
rot_left_top = rot_by_a(left_top, ang)
tri_h = rot_left_top[1] - left_top[1]
tri_base = tri_h / math.tan(ang) + tri_h / math.tan(math.pi / 2 - ang)
longer_cathetus = tri_base * math.cos(ang)
smaller_tri_smaller_cathetus = w - tri_base - longer_cathetus
smaller_tri_longer_cathetus = smaller_tri_smaller_cathetus / math.tan(ang)
print(w * h - tri_base * tri_h - smaller_tri_smaller_cathetus * smaller_tri_longer_cathetus)
``` | output | 1 | 6,098 | 23 | 12,197 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two rectangles on a plane. The centers of both rectangles are located in the origin of coordinates (meaning the center of the rectangle's symmetry). The first rectangle's sides are parallel to the coordinate axes: the length of the side that is parallel to the Ox axis, equals w, the length of the side that is parallel to the Oy axis, equals h. The second rectangle can be obtained by rotating the first rectangle relative to the origin of coordinates by angle α.
<image>
Your task is to find the area of the region which belongs to both given rectangles. This region is shaded in the picture.
Input
The first line contains three integers w, h, α (1 ≤ w, h ≤ 106; 0 ≤ α ≤ 180). Angle α is given in degrees.
Output
In a single line print a real number — the area of the region which belongs to both given rectangles.
The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 6.
Examples
Input
1 1 45
Output
0.828427125
Input
6 4 30
Output
19.668384925
Note
The second sample has been drawn on the picture above.
Submitted Solution:
```
import math
def rot_by_a(p, a):
return (p[0] * math.cos(a) - p[1] * math.sin(a),
p[0] * math.sin(a) + p[1] * math.cos(a))
h, w, alpha = map(int, input().split())
if h > w:
h, w = w, h
if alpha > 90:
alpha = 180 - alpha
ang = math.radians(alpha)
b = math.tan(h / w) # why not * 2 ?
if alpha == 0:
print(h * w)
#elif alpha == 90:
# print(h * h)
elif ang > b:
side = h / math.sin(ang)
print(side * h)
else:
left_top = (w / 2, h / 2)
rot_left_top = rot_by_a(left_top, ang)
tri_h = rot_left_top[1] - left_top[1]
tri_base = tri_h * math.tan(ang) + tri_h / math.tan(math.pi / 2 - ang)
longer_cathetus = tri_base * math.cos(ang)
smaller_tri_smaller_cathetus = w - tri_base - longer_cathetus
smaller_tri_longer_cathetus = smaller_tri_smaller_cathetus / math.tan(ang)
print(w * h - tri_base * tri_h - smaller_tri_smaller_cathetus * smaller_tri_longer_cathetus)
``` | instruction | 0 | 6,099 | 23 | 12,198 |
No | output | 1 | 6,099 | 23 | 12,199 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two rectangles on a plane. The centers of both rectangles are located in the origin of coordinates (meaning the center of the rectangle's symmetry). The first rectangle's sides are parallel to the coordinate axes: the length of the side that is parallel to the Ox axis, equals w, the length of the side that is parallel to the Oy axis, equals h. The second rectangle can be obtained by rotating the first rectangle relative to the origin of coordinates by angle α.
<image>
Your task is to find the area of the region which belongs to both given rectangles. This region is shaded in the picture.
Input
The first line contains three integers w, h, α (1 ≤ w, h ≤ 106; 0 ≤ α ≤ 180). Angle α is given in degrees.
Output
In a single line print a real number — the area of the region which belongs to both given rectangles.
The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 6.
Examples
Input
1 1 45
Output
0.828427125
Input
6 4 30
Output
19.668384925
Note
The second sample has been drawn on the picture above.
Submitted Solution:
```
import math
def rot_by_a(p, a):
return (p[0] * math.cos(a) - p[1] * math.sin(a),
p[0] * math.sin(a) + p[1] * math.cos(a))
h, w, alpha = map(int, input().split())
if h > w:
h, w = w, h
if alpha > 90:
alpha = 180 - alpha
ang = math.radians(alpha)
b = math.tan(h / w) # why not * 2 ?
if alpha == 0:
print(h * w)
elif alpha == 90:
print(h * h)
elif ang > b:
side = h / math.sin(ang)
print(side * h)
else:
left_top = (w / 2, h / 2)
rot_left_top = rot_by_a(left_top, ang)
tri_h = rot_left_top[1] - left_top[1]
tri_base = tri_h * math.tan(ang) + tri_h / math.tan(math.pi / 2 - ang)
longer_cathetus = tri_base * math.cos(ang)
smaller_tri_smaller_cathetus = w - tri_base - longer_cathetus
smaller_tri_longer_cathetus = smaller_tri_smaller_cathetus / math.tan(ang)
print(w * h - tri_base * tri_h - smaller_tri_smaller_cathetus * smaller_tri_longer_cathetus)
``` | instruction | 0 | 6,100 | 23 | 12,200 |
No | output | 1 | 6,100 | 23 | 12,201 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two rectangles on a plane. The centers of both rectangles are located in the origin of coordinates (meaning the center of the rectangle's symmetry). The first rectangle's sides are parallel to the coordinate axes: the length of the side that is parallel to the Ox axis, equals w, the length of the side that is parallel to the Oy axis, equals h. The second rectangle can be obtained by rotating the first rectangle relative to the origin of coordinates by angle α.
<image>
Your task is to find the area of the region which belongs to both given rectangles. This region is shaded in the picture.
Input
The first line contains three integers w, h, α (1 ≤ w, h ≤ 106; 0 ≤ α ≤ 180). Angle α is given in degrees.
Output
In a single line print a real number — the area of the region which belongs to both given rectangles.
The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 6.
Examples
Input
1 1 45
Output
0.828427125
Input
6 4 30
Output
19.668384925
Note
The second sample has been drawn on the picture above.
Submitted Solution:
```
import math
def rot_by_a(p, a):
return (p[0] * math.cos(a) - p[1] * math.sin(a),
p[0] * math.sin(a) + p[1] * math.cos(a))
h, w, alpha = map(int, input().split())
if h > w:
h, w = w, h
if alpha > 90:
alpha = 180 - alpha
ang = math.radians(alpha)
b = math.tan(h / w) # why not * 2 ?
if alpha == 0:
print(h * w)
elif alpha == 90:
print(float(h * h))
elif ang > b:
side = h / math.sin(ang)
print(side * h)
else:
left_top = (w / 2, h / 2)
rot_left_top = rot_by_a(left_top, ang)
tri_h = rot_left_top[1] - left_top[1]
tri_base = tri_h * math.tan(ang) + tri_h / math.tan(math.pi / 2 - ang)
longer_cathetus = tri_base * math.cos(ang)
smaller_tri_smaller_cathetus = w - tri_base - longer_cathetus
smaller_tri_longer_cathetus = smaller_tri_smaller_cathetus / math.tan(ang)
print(w * h - tri_base * tri_h - smaller_tri_smaller_cathetus * smaller_tri_longer_cathetus)
``` | instruction | 0 | 6,101 | 23 | 12,202 |
No | output | 1 | 6,101 | 23 | 12,203 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two rectangles on a plane. The centers of both rectangles are located in the origin of coordinates (meaning the center of the rectangle's symmetry). The first rectangle's sides are parallel to the coordinate axes: the length of the side that is parallel to the Ox axis, equals w, the length of the side that is parallel to the Oy axis, equals h. The second rectangle can be obtained by rotating the first rectangle relative to the origin of coordinates by angle α.
<image>
Your task is to find the area of the region which belongs to both given rectangles. This region is shaded in the picture.
Input
The first line contains three integers w, h, α (1 ≤ w, h ≤ 106; 0 ≤ α ≤ 180). Angle α is given in degrees.
Output
In a single line print a real number — the area of the region which belongs to both given rectangles.
The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 6.
Examples
Input
1 1 45
Output
0.828427125
Input
6 4 30
Output
19.668384925
Note
The second sample has been drawn on the picture above.
Submitted Solution:
```
import math
def rot_by_a(p, a):
return (p[0] * math.cos(a) - p[1] * math.sin(a),
p[0] * math.sin(a) + p[1] * math.cos(a))
h, w, alpha = map(int, input().split())
if h > w:
h, w = w, h
if alpha > 90:
alpha = 180 - alpha
ang = math.radians(alpha)
b = math.tan(h / w) # why not * 2 ?
if alpha == 0:
print(h * w)
elif ang > b:
side = h / math.sin(ang)
print(side * h)
else:
left_top = (w / 2, h / 2)
rot_left_top = rot_by_a(left_top, ang)
tri_h = rot_left_top[1] - left_top[1]
tri_base = tri_h / math.tan(ang) + tri_h / math.tan(math.pi / 2 - ang)
longer_cathetus = tri_base * math.cos(ang)
smaller_tri_smaller_cathetus = w - tri_base - longer_cathetus
smaller_tri_longer_cathetus = smaller_tri_smaller_cathetus / math.tan(ang)
print(w * h - tri_base * tri_h - smaller_tri_smaller_cathetus * smaller_tri_longer_cathetus)
``` | instruction | 0 | 6,102 | 23 | 12,204 |
No | output | 1 | 6,102 | 23 | 12,205 |
Provide a correct Python 3 solution for this coding contest problem.
There are N dots in a two-dimensional plane. The coordinates of the i-th dot are (x_i, y_i).
We will repeat the following operation as long as possible:
* Choose four integers a, b, c, d (a \neq c, b \neq d) such that there are dots at exactly three of the positions (a, b), (a, d), (c, b) and (c, d), and add a dot at the remaining position.
We can prove that we can only do this operation a finite number of times. Find the maximum number of times we can do the operation.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq x_i, y_i \leq 10^5
* If i \neq j, x_i \neq x_j or y_i \neq y_j.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
x_1 y_1
:
x_N y_N
Output
Print the maximum number of times we can do the operation.
Examples
Input
3
1 1
5 1
5 5
Output
1
Input
2
10 10
20 20
Output
0
Input
9
1 1
2 1
3 1
4 1
5 1
1 2
1 3
1 4
1 5
Output
16 | instruction | 0 | 6,413 | 23 | 12,826 |
"Correct Solution:
```
import sys
from collections import defaultdict
import queue
n = int(sys.stdin.readline())
graph = defaultdict(list)
X, Y = [[] for i in range(n)], [[] for i in range(n)]
atX, atY = defaultdict(list), defaultdict(list)
for i in range(n):
a, b = map(int, sys.stdin.readline().split())
a -= 1; b-= 1
X[i] = a; Y[i] = b
atX[X[i]].append(i)
atY[Y[i]].append(i)
visX = set(); visY = set()
found = [False]*n
ans = n*(-1)
for root in range(n):
if found[root]: continue
usedX, usedY = set(), set()
que = queue.Queue()
que.put(root)
found[root] = True
usedX.add(X[root])
usedY.add(Y[root])
while not que.empty():
cur = que.get()
toVisit = []
if X[cur] not in visX:
visX.add(X[cur])
for ele in atX[X[cur]]:
toVisit.append(ele)
if Y[cur] not in visY:
visY.add(Y[cur])
for ele in atY[Y[cur]]:
toVisit.append(ele)
for ele in toVisit:
if found[ele]: continue
found[ele] = True
usedX.add(X[ele])
usedY.add(Y[ele])
que.put(ele)
ans += len(usedX)*len(usedY)
print(ans)
``` | output | 1 | 6,413 | 23 | 12,827 |
Provide a correct Python 3 solution for this coding contest problem.
There are N dots in a two-dimensional plane. The coordinates of the i-th dot are (x_i, y_i).
We will repeat the following operation as long as possible:
* Choose four integers a, b, c, d (a \neq c, b \neq d) such that there are dots at exactly three of the positions (a, b), (a, d), (c, b) and (c, d), and add a dot at the remaining position.
We can prove that we can only do this operation a finite number of times. Find the maximum number of times we can do the operation.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq x_i, y_i \leq 10^5
* If i \neq j, x_i \neq x_j or y_i \neq y_j.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
x_1 y_1
:
x_N y_N
Output
Print the maximum number of times we can do the operation.
Examples
Input
3
1 1
5 1
5 5
Output
1
Input
2
10 10
20 20
Output
0
Input
9
1 1
2 1
3 1
4 1
5 1
1 2
1 3
1 4
1 5
Output
16 | instruction | 0 | 6,414 | 23 | 12,828 |
"Correct Solution:
```
from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = float("inf")
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)
class UnionFind():
def __init__(self, N):
self.rank = [0] * N
self.par = [i for i in range(N)]
self.counter = [1] * N
def find(self, x):
if self.par[x] == x:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
if x != y:
z = self.counter[x] + self.counter[y]
self.counter[x], self.counter[y] = z, z
if self.rank[x] < self.rank[y]:
self.par[x] = y
else:
self.par[y] = x
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
def size(self, x):
x = self.find(x)
return self.counter[x]
def same(self, x, y):
return self.find(x) == self.find(y)
N = int(input())
uf = UnionFind(N)
x_dict={}
y_dict={}
xy = []
for i in range(N):
x,y = map(int,input().split())
if x in x_dict:
uf.unite(i,x_dict[x])
else:
x_dict[x]=i
if y in y_dict:
uf.unite(i,y_dict[y])
else:
y_dict[y]=i
xy.append((x,y))
unite_dict={}
for i in range(N):
ur = uf.find(i)
unite_dict.setdefault(ur,[set(),set()])
unite_dict[ur][0].add(xy[i][0])
unite_dict[ur][1].add(xy[i][1])
p = 0
for k,v in unite_dict.items():
p +=len(v[0])*len(v[1])
print(p-N)
``` | output | 1 | 6,414 | 23 | 12,829 |
Provide a correct Python 3 solution for this coding contest problem.
There are N dots in a two-dimensional plane. The coordinates of the i-th dot are (x_i, y_i).
We will repeat the following operation as long as possible:
* Choose four integers a, b, c, d (a \neq c, b \neq d) such that there are dots at exactly three of the positions (a, b), (a, d), (c, b) and (c, d), and add a dot at the remaining position.
We can prove that we can only do this operation a finite number of times. Find the maximum number of times we can do the operation.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq x_i, y_i \leq 10^5
* If i \neq j, x_i \neq x_j or y_i \neq y_j.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
x_1 y_1
:
x_N y_N
Output
Print the maximum number of times we can do the operation.
Examples
Input
3
1 1
5 1
5 5
Output
1
Input
2
10 10
20 20
Output
0
Input
9
1 1
2 1
3 1
4 1
5 1
1 2
1 3
1 4
1 5
Output
16 | instruction | 0 | 6,415 | 23 | 12,830 |
"Correct Solution:
```
# 長方形の4点のうち3点が必要なので自明からほど遠い
# x,yを2部グラフ、格子を辺とみなす
# 連結成分ごとに張られる......
n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
mx =0
my = 0
for i in range(n):
mx = max(mx,xy[i][0])
my = max(my,xy[i][1])
*p, = range(mx+my+1)
rank = [1]*(mx+my+1)
for i in range(n):
xy[i][1] += mx
def root(x):
if x == p[x]:
return x
p[x] = y = root(p[x])
return y
def unite(x, y):
px = root(x); py = root(y)
if px == py:
return 0
rx = rank[px]; ry = rank[py]
if ry < rx:
p[py] = px
elif rx < ry:
p[px] = py
else:
p[py] = px
rank[px] += 1
return 1
for x,y in xy:
unite (x,y)
xp = [0]*(mx+my+1)
yp = [0]*(mx+my+1)
for i in range(mx+my+1):
if i<=mx:
xp[root(i)]+=1#p[i]では不十分
else:
yp[root(i)]+=1
ans = 0
for i in range(mx+my+1):
ans += xp[i]*yp[i]
ans -= n
print(ans)
``` | output | 1 | 6,415 | 23 | 12,831 |
Provide a correct Python 3 solution for this coding contest problem.
There are N dots in a two-dimensional plane. The coordinates of the i-th dot are (x_i, y_i).
We will repeat the following operation as long as possible:
* Choose four integers a, b, c, d (a \neq c, b \neq d) such that there are dots at exactly three of the positions (a, b), (a, d), (c, b) and (c, d), and add a dot at the remaining position.
We can prove that we can only do this operation a finite number of times. Find the maximum number of times we can do the operation.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq x_i, y_i \leq 10^5
* If i \neq j, x_i \neq x_j or y_i \neq y_j.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
x_1 y_1
:
x_N y_N
Output
Print the maximum number of times we can do the operation.
Examples
Input
3
1 1
5 1
5 5
Output
1
Input
2
10 10
20 20
Output
0
Input
9
1 1
2 1
3 1
4 1
5 1
1 2
1 3
1 4
1 5
Output
16 | instruction | 0 | 6,416 | 23 | 12,832 |
"Correct Solution:
```
n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
xtoy = {}
ytox = {}
for x, y in xy:
if x not in xtoy:
xtoy[x] = []
xtoy[x].append(y)
if y not in ytox:
ytox[y] = []
ytox[y].append(x)
ret = 0
while len(xtoy) > 0:
x = next(iter(xtoy))
xs = set()
ys = set()
xs.add(x)
q = [(x, None)]
while len(q) > 0:
(xx, yy) = q.pop(0)
if xx is not None:
for y in xtoy.pop(xx):
if y not in ys:
ys.add(y)
q.append((None, y))
if yy is not None:
for x in ytox.pop(yy):
if x not in xs:
xs.add(x)
q.append((x, None))
ret += len(xs) * len(ys)
print(ret - n)
``` | output | 1 | 6,416 | 23 | 12,833 |
Provide a correct Python 3 solution for this coding contest problem.
There are N dots in a two-dimensional plane. The coordinates of the i-th dot are (x_i, y_i).
We will repeat the following operation as long as possible:
* Choose four integers a, b, c, d (a \neq c, b \neq d) such that there are dots at exactly three of the positions (a, b), (a, d), (c, b) and (c, d), and add a dot at the remaining position.
We can prove that we can only do this operation a finite number of times. Find the maximum number of times we can do the operation.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq x_i, y_i \leq 10^5
* If i \neq j, x_i \neq x_j or y_i \neq y_j.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
x_1 y_1
:
x_N y_N
Output
Print the maximum number of times we can do the operation.
Examples
Input
3
1 1
5 1
5 5
Output
1
Input
2
10 10
20 20
Output
0
Input
9
1 1
2 1
3 1
4 1
5 1
1 2
1 3
1 4
1 5
Output
16 | instruction | 0 | 6,417 | 23 | 12,834 |
"Correct Solution:
```
import sys
input = sys.stdin.readline
max_n = 10**5
ans = 0
n = int(input())
class UnionFind:
def __init__(self, n):
self.par = [i for i in range(n)]
self.sizea = [1 if _ < n//2 else 0 for _ in range(n)]
self.sizeb = [0 if _ < n//2 else 1 for _ in range(n)]
self.sizec = [1 for _ in range(n)]
self.rank = [0] * (n)
def find(self, x):
if self.par[x] == x:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
def is_root(self, x):
if self.par[x] == x:
return True
else:
return False
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x != y:
if self.rank[x] < self.rank[y]:
x, y = y, x
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
self.par[y] = x
self.sizea[x] += self.sizea[y]
self.sizeb[x] += self.sizeb[y]
self.sizec[x] += self.sizec[y]
else:
self.sizec[x] += 1
def get_size(self, x):
x = self.find(x)
return self.sizea[x],self.sizeb[x],self.sizec[x]
uf = UnionFind(2*max_n)
for _ in range(n):
x,y = map(int, input().split())
x -= 1
y += max_n - 1
uf.union(x, y)
for i in range(max_n):
if uf.is_root(i):
a,b,c = uf.get_size(i)
if a*b > 1:
ans += a*b -(c-1)
print(ans)
``` | output | 1 | 6,417 | 23 | 12,835 |
Provide a correct Python 3 solution for this coding contest problem.
There are N dots in a two-dimensional plane. The coordinates of the i-th dot are (x_i, y_i).
We will repeat the following operation as long as possible:
* Choose four integers a, b, c, d (a \neq c, b \neq d) such that there are dots at exactly three of the positions (a, b), (a, d), (c, b) and (c, d), and add a dot at the remaining position.
We can prove that we can only do this operation a finite number of times. Find the maximum number of times we can do the operation.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq x_i, y_i \leq 10^5
* If i \neq j, x_i \neq x_j or y_i \neq y_j.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
x_1 y_1
:
x_N y_N
Output
Print the maximum number of times we can do the operation.
Examples
Input
3
1 1
5 1
5 5
Output
1
Input
2
10 10
20 20
Output
0
Input
9
1 1
2 1
3 1
4 1
5 1
1 2
1 3
1 4
1 5
Output
16 | instruction | 0 | 6,418 | 23 | 12,836 |
"Correct Solution:
```
# https://drken1215.hatenablog.com/entry/2019/06/23/004700
# https://atcoder.jp/contests/abc131/submissions/7975278
# https://tjkendev.github.io/procon-library/python/union_find/union_find.html
def main():
from collections import Counter
import sys
input = sys.stdin.readline
MX = 10 ** 5 + 10
*p, = [r for r in range(MX * 2)]
def root(x):
if x == p[x]:
return x
p[x] = y = root(p[x])
return y
def unite(x, y):
px = root(x)
py = root(y)
if px == py:
return 0
if px < py:
p[py] = px
else:
p[px] = py
return 1
n = int(input())
for _ in range(n):
x, y = (int(x) - 1 for x in input().split()) # [1,)->[0,)
unite(x, y + MX)
ctr_x = Counter(root(r) for r in range(MX))
ctr_y = Counter(root(r) for r in range(MX, MX * 2))
rs = set(ctr_x.keys())
rs.update(ctr_y.keys())
ans = sum(ctr_x[r] * ctr_y[r] for r in rs) - n
print(ans)
if __name__ == '__main__':
main()
``` | output | 1 | 6,418 | 23 | 12,837 |
Provide a correct Python 3 solution for this coding contest problem.
There are N dots in a two-dimensional plane. The coordinates of the i-th dot are (x_i, y_i).
We will repeat the following operation as long as possible:
* Choose four integers a, b, c, d (a \neq c, b \neq d) such that there are dots at exactly three of the positions (a, b), (a, d), (c, b) and (c, d), and add a dot at the remaining position.
We can prove that we can only do this operation a finite number of times. Find the maximum number of times we can do the operation.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq x_i, y_i \leq 10^5
* If i \neq j, x_i \neq x_j or y_i \neq y_j.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
x_1 y_1
:
x_N y_N
Output
Print the maximum number of times we can do the operation.
Examples
Input
3
1 1
5 1
5 5
Output
1
Input
2
10 10
20 20
Output
0
Input
9
1 1
2 1
3 1
4 1
5 1
1 2
1 3
1 4
1 5
Output
16 | instruction | 0 | 6,419 | 23 | 12,838 |
"Correct Solution:
```
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
V=100005
n=int(input())
E=[[] for _ in range(V*2)]
for _ in range(n):
x,y=map(int,input().split())
y+=V
E[x].append(y)
E[y].append(x)
visited=[0]*(2*V)
def dfs(v):
if(visited[v]): return
visited[v]=1
cnt[v//V]+=1
for nv in E[v]: dfs(nv)
ans=[0]
for v in range(2*V):
if(visited[v]): continue
cnt=[0]*2 # 連結成分のx,yの個数
dfs(v)
ans[0]+=cnt[0]*cnt[1]
print(ans[0]-n)
resolve()
``` | output | 1 | 6,419 | 23 | 12,839 |
Provide a correct Python 3 solution for this coding contest problem.
There are N dots in a two-dimensional plane. The coordinates of the i-th dot are (x_i, y_i).
We will repeat the following operation as long as possible:
* Choose four integers a, b, c, d (a \neq c, b \neq d) such that there are dots at exactly three of the positions (a, b), (a, d), (c, b) and (c, d), and add a dot at the remaining position.
We can prove that we can only do this operation a finite number of times. Find the maximum number of times we can do the operation.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq x_i, y_i \leq 10^5
* If i \neq j, x_i \neq x_j or y_i \neq y_j.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
x_1 y_1
:
x_N y_N
Output
Print the maximum number of times we can do the operation.
Examples
Input
3
1 1
5 1
5 5
Output
1
Input
2
10 10
20 20
Output
0
Input
9
1 1
2 1
3 1
4 1
5 1
1 2
1 3
1 4
1 5
Output
16 | instruction | 0 | 6,420 | 23 | 12,840 |
"Correct Solution:
```
import sys
sys.setrecursionlimit(10 ** 7)
def dfs(G, F, crr, pre, ret, st):
F[crr] = False
if crr < 10**5:
ret[0] += 1
else:
ret[1] += 1
for nxt in G[crr]:
if nxt == pre:
continue
p, q = crr, nxt
if q < p:
p, q = q, p
if not (p, q) in st:
st.add((p, q))
ret[2] += 1
if F[nxt]:
dfs(G, F, nxt, crr, ret, st)
def main():
n = int(input())
G = [[] for _ in range(2 * 10**5)]
for _ in range(n):
x, y = map(int, input().split())
x, y = x-1, y-1 + 10**5
G[x].append(y)
G[y].append(x)
F = [True]*(2* 10**5)
ans = 0
st = set()
for i in range(2 * 10**5):
if F[i] and len(G[i]) > 0:
tmp = [0]*3
dfs(G, F, i, -1, tmp, st)
ans += tmp[0] * tmp[1] - tmp[2]
print(ans)
if __name__ == "__main__":
main()
``` | output | 1 | 6,420 | 23 | 12,841 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N dots in a two-dimensional plane. The coordinates of the i-th dot are (x_i, y_i).
We will repeat the following operation as long as possible:
* Choose four integers a, b, c, d (a \neq c, b \neq d) such that there are dots at exactly three of the positions (a, b), (a, d), (c, b) and (c, d), and add a dot at the remaining position.
We can prove that we can only do this operation a finite number of times. Find the maximum number of times we can do the operation.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq x_i, y_i \leq 10^5
* If i \neq j, x_i \neq x_j or y_i \neq y_j.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
x_1 y_1
:
x_N y_N
Output
Print the maximum number of times we can do the operation.
Examples
Input
3
1 1
5 1
5 5
Output
1
Input
2
10 10
20 20
Output
0
Input
9
1 1
2 1
3 1
4 1
5 1
1 2
1 3
1 4
1 5
Output
16
Submitted Solution:
```
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def YesNo(x): return 'Yes' if x else 'No'
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 II(): return int(sys.stdin.readline())
def SI(): return input()
from collections import defaultdict
def main():
N = II()
xy = []
for _ in range(N):
xy.append(LI())
xy2g = defaultdict(int)
g2xy = defaultdict(set)
for x, y in xy:
y = -y
gx = xy2g[x]
gy = xy2g[y]
if gx != gy and gx != 0 and gy != 0: # merge
if len(g2xy[gx]) < len(g2xy[gy]):
gx, gy = gy, gx
for xy in g2xy[gy]:
xy2g[xy] = gx
g2xy[gx] |= g2xy[gy]
g2xy[gy].clear()
else:
g = gx or gy or x
xy2g[x] = xy2g[y] = g
g2xy[g] |= {x, y}
ans = -N
for xys in g2xy.values():
nx = 0
for xy in xys:
if xy > 0:
nx += 1
ny = len(xys) - nx
ans += nx * ny
return ans
print(main())
``` | instruction | 0 | 6,421 | 23 | 12,842 |
Yes | output | 1 | 6,421 | 23 | 12,843 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N dots in a two-dimensional plane. The coordinates of the i-th dot are (x_i, y_i).
We will repeat the following operation as long as possible:
* Choose four integers a, b, c, d (a \neq c, b \neq d) such that there are dots at exactly three of the positions (a, b), (a, d), (c, b) and (c, d), and add a dot at the remaining position.
We can prove that we can only do this operation a finite number of times. Find the maximum number of times we can do the operation.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq x_i, y_i \leq 10^5
* If i \neq j, x_i \neq x_j or y_i \neq y_j.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
x_1 y_1
:
x_N y_N
Output
Print the maximum number of times we can do the operation.
Examples
Input
3
1 1
5 1
5 5
Output
1
Input
2
10 10
20 20
Output
0
Input
9
1 1
2 1
3 1
4 1
5 1
1 2
1 3
1 4
1 5
Output
16
Submitted Solution:
```
from collections import deque
N = int(input())
V = set()
E = {}
for _ in range(N):
x,y = map(int, input().split())
y += 100010
V.add(x)
V.add(y)
if x not in E:
E[x] = [y]
else:
E[x].append(y)
if y not in E:
E[y] = [x]
else:
E[y].append(x)
#print(V)
#print(E)
## DFS
visited = [ False ] * 200020
willSearch = [ False ] * 200020
Q = deque()
ans = 0
for v in V:
if visited[v]:
continue
Q.append(v)
xcount, ycount = 0,0
edge_count = 0
while len(Q) > 0:
now = Q.pop()
visited[now] = True
if now > 100005:
ycount += 1
else:
xcount += 1
for nxt in E[now]:
edge_count += 1
if visited[nxt] or willSearch[nxt]:
continue
#print(v,now,nxt)
willSearch[nxt] = True
Q.append(nxt)
#print(v,xcount, ycount, edge_count)
ans += xcount * ycount
ans -= edge_count // 2
print(ans)
``` | instruction | 0 | 6,422 | 23 | 12,844 |
Yes | output | 1 | 6,422 | 23 | 12,845 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N dots in a two-dimensional plane. The coordinates of the i-th dot are (x_i, y_i).
We will repeat the following operation as long as possible:
* Choose four integers a, b, c, d (a \neq c, b \neq d) such that there are dots at exactly three of the positions (a, b), (a, d), (c, b) and (c, d), and add a dot at the remaining position.
We can prove that we can only do this operation a finite number of times. Find the maximum number of times we can do the operation.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq x_i, y_i \leq 10^5
* If i \neq j, x_i \neq x_j or y_i \neq y_j.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
x_1 y_1
:
x_N y_N
Output
Print the maximum number of times we can do the operation.
Examples
Input
3
1 1
5 1
5 5
Output
1
Input
2
10 10
20 20
Output
0
Input
9
1 1
2 1
3 1
4 1
5 1
1 2
1 3
1 4
1 5
Output
16
Submitted Solution:
```
# reference -> https://atcoder.jp/contests/abc131/submissions/10358162
import sys
sys.setrecursionlimit(100000)
# 再帰的に連結部分の辺の数を求める
# 同じ辺を2回ずつ数えるので、最終的には2で割る
def solve(x, x_set, y_set, x2y, y2x):
num_e = 0
if x in x2y:
x_set.add(x)
yl = x2y.pop(x)
num_e += len(yl)
for y in yl:
num_e += solve(y, y_set, x_set, y2x, x2y)
return num_e
N = int(input())
X2Y = {}
Y2X = {}
for i in range(N):
x, y = map(int, input().split())
if x in X2Y:
X2Y[x].append(y)
else:
X2Y[x] = [y]
if y in Y2X:
Y2X[y].append(x)
else:
Y2X[y] = [x]
ans = 0
while X2Y:
x = next(iter(X2Y)) # まだスタートに選んでいないxを取り出す
x_set = set() # 上のxと連結であるxの集合
y_set = set() # 上のxと連結であるyの集合
num_e = solve(x, x_set, y_set, X2Y, Y2X)
ans += len(x_set)*len(y_set) - num_e//2
print(ans)
``` | instruction | 0 | 6,423 | 23 | 12,846 |
Yes | output | 1 | 6,423 | 23 | 12,847 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N dots in a two-dimensional plane. The coordinates of the i-th dot are (x_i, y_i).
We will repeat the following operation as long as possible:
* Choose four integers a, b, c, d (a \neq c, b \neq d) such that there are dots at exactly three of the positions (a, b), (a, d), (c, b) and (c, d), and add a dot at the remaining position.
We can prove that we can only do this operation a finite number of times. Find the maximum number of times we can do the operation.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq x_i, y_i \leq 10^5
* If i \neq j, x_i \neq x_j or y_i \neq y_j.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
x_1 y_1
:
x_N y_N
Output
Print the maximum number of times we can do the operation.
Examples
Input
3
1 1
5 1
5 5
Output
1
Input
2
10 10
20 20
Output
0
Input
9
1 1
2 1
3 1
4 1
5 1
1 2
1 3
1 4
1 5
Output
16
Submitted Solution:
```
from collections import Counter
def main():
MAX = 10 ** 5 + 1
data = [-1] * (2 * MAX)
def find(x):
if data[x] < 0:
return x
else:
data[x] = find(data[x])
return data[x]
def union(x, y):
x, y = find(x), find(y)
if x != y:
if data[y] < data[x]:
x, y = y, x
data[x] += data[y]
data[y] = x
return (x != y)
N, *XY = map(int, open(0).read().split())
for x, y in zip(*[iter(XY)] * 2):
union(x, y + MAX)
X = Counter(find(i) for i in range(MAX))
Y = Counter(find(i) for i in range(MAX, MAX * 2))
res = sum(X[i] * Y[i] for i in range(MAX * 2))
print(res - N)
if __name__ == '__main__':
main()
``` | instruction | 0 | 6,424 | 23 | 12,848 |
Yes | output | 1 | 6,424 | 23 | 12,849 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N dots in a two-dimensional plane. The coordinates of the i-th dot are (x_i, y_i).
We will repeat the following operation as long as possible:
* Choose four integers a, b, c, d (a \neq c, b \neq d) such that there are dots at exactly three of the positions (a, b), (a, d), (c, b) and (c, d), and add a dot at the remaining position.
We can prove that we can only do this operation a finite number of times. Find the maximum number of times we can do the operation.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq x_i, y_i \leq 10^5
* If i \neq j, x_i \neq x_j or y_i \neq y_j.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
x_1 y_1
:
x_N y_N
Output
Print the maximum number of times we can do the operation.
Examples
Input
3
1 1
5 1
5 5
Output
1
Input
2
10 10
20 20
Output
0
Input
9
1 1
2 1
3 1
4 1
5 1
1 2
1 3
1 4
1 5
Output
16
Submitted Solution:
```
def solve():
N = int(input())
XY = [[int(i) for i in input().split()] for i in range(N)]
if N < 3: return 0
setY = set()
XYdict = {}
for x, y in XY:
setY.add(y)
if x not in XYdict:
XYdict[x] = set([y])
else:
XYdict[x].add(y)
ans = 0
for i in XYdict:
for j in XYdict:
if i == j: continue
_and = XYdict[i] & XYdict[j]
if len(_and) == 0: continue
xor = XYdict[i] ^ XYdict[j]
l = len(xor)
if l == 0: continue
ans += l
XYdict[i] |= xor
XYdict[j] |= xor
return ans
print(solve())
``` | instruction | 0 | 6,425 | 23 | 12,850 |
No | output | 1 | 6,425 | 23 | 12,851 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N dots in a two-dimensional plane. The coordinates of the i-th dot are (x_i, y_i).
We will repeat the following operation as long as possible:
* Choose four integers a, b, c, d (a \neq c, b \neq d) such that there are dots at exactly three of the positions (a, b), (a, d), (c, b) and (c, d), and add a dot at the remaining position.
We can prove that we can only do this operation a finite number of times. Find the maximum number of times we can do the operation.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq x_i, y_i \leq 10^5
* If i \neq j, x_i \neq x_j or y_i \neq y_j.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
x_1 y_1
:
x_N y_N
Output
Print the maximum number of times we can do the operation.
Examples
Input
3
1 1
5 1
5 5
Output
1
Input
2
10 10
20 20
Output
0
Input
9
1 1
2 1
3 1
4 1
5 1
1 2
1 3
1 4
1 5
Output
16
Submitted Solution:
```
N = int(input().strip())
X = {}
Y = {}
for _ in range(N):
x, y = map(int, input().strip().split())
if x not in X: X[x] = set()
X[x].add(y)
if y not in Y: Y[y] = set()
Y[y].add(x)
count = 0
for x, y_set in X.items():
if len(y_set) < 2:
continue
for y in y_set:
x_set = Y[y]
if len(x_set) < 2:
continue
for _x in x_set:
if x == _x:
continue
count += len(y_set - X[_x])
X[_x] = y_set | X[_x]
print(count)
``` | instruction | 0 | 6,426 | 23 | 12,852 |
No | output | 1 | 6,426 | 23 | 12,853 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N dots in a two-dimensional plane. The coordinates of the i-th dot are (x_i, y_i).
We will repeat the following operation as long as possible:
* Choose four integers a, b, c, d (a \neq c, b \neq d) such that there are dots at exactly three of the positions (a, b), (a, d), (c, b) and (c, d), and add a dot at the remaining position.
We can prove that we can only do this operation a finite number of times. Find the maximum number of times we can do the operation.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq x_i, y_i \leq 10^5
* If i \neq j, x_i \neq x_j or y_i \neq y_j.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
x_1 y_1
:
x_N y_N
Output
Print the maximum number of times we can do the operation.
Examples
Input
3
1 1
5 1
5 5
Output
1
Input
2
10 10
20 20
Output
0
Input
9
1 1
2 1
3 1
4 1
5 1
1 2
1 3
1 4
1 5
Output
16
Submitted Solution:
```
from collections import defaultdict
import sys
input = sys.stdin.readline
n = int(input())
xy = [list(map(int,input().split())) for i in range(n)]
graph = [[] for i in range(2*10**5+1)]
ans = 0
for x,y in xy:
y += 10**5
graph[x].append(y)
graph[y].append(x)
ans -= 1
vis = [0 for i in range(2*10**5+1)]
for i in range(1,2*10**5+1):
if vis[i]:
continue
stack = [i]
nx = 0
ny = 0
while stack:
x = stack.pop()
if x > 10**5:
ny += 1
else:
nx += 1
vis[x] = 1
for y in graph[x]:
if not vis[y]:
stack.append(y)
ans += nx*ny
print(ans)
``` | instruction | 0 | 6,427 | 23 | 12,854 |
No | output | 1 | 6,427 | 23 | 12,855 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N dots in a two-dimensional plane. The coordinates of the i-th dot are (x_i, y_i).
We will repeat the following operation as long as possible:
* Choose four integers a, b, c, d (a \neq c, b \neq d) such that there are dots at exactly three of the positions (a, b), (a, d), (c, b) and (c, d), and add a dot at the remaining position.
We can prove that we can only do this operation a finite number of times. Find the maximum number of times we can do the operation.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq x_i, y_i \leq 10^5
* If i \neq j, x_i \neq x_j or y_i \neq y_j.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
x_1 y_1
:
x_N y_N
Output
Print the maximum number of times we can do the operation.
Examples
Input
3
1 1
5 1
5 5
Output
1
Input
2
10 10
20 20
Output
0
Input
9
1 1
2 1
3 1
4 1
5 1
1 2
1 3
1 4
1 5
Output
16
Submitted Solution:
```
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def YesNo(x): return 'Yes' if x else 'No'
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 II(): return int(sys.stdin.readline())
def SI(): return input()
from collections import defaultdict
def main():
N = II()
xy = []
for _ in range(N):
xy.append(LI())
x2g = defaultdict(int)
y2g = defaultdict(int)
g2y = defaultdict(set)
g2x = defaultdict(set)
for x, y in xy:
gx = x2g[x]
gy = y2g[y]
if gx > 0 and gy > 0: # merge
if len(g2x[gx]) + len(g2y[gx]) < len(g2x[gy]) + len(g2x[gy]):
gx, gy = gy, gx
for x in g2x[gy]:
x2g[x] = gx
for y in g2y[gy]:
y2g[y] = gx
g2y[gx] |= g2y[gy]
g2x[gx] |= g2x[gy]
g2y[gy] = set()
g2x[gy] = set()
elif gx > 0:
y2g[y] = gx
g2y[gx].add(y)
elif gy > 0:
x2g[x] = gy
g2x[gy].add(x)
else:
x2g[x] = x
y2g[y] = x
g2x[x].add(x)
g2y[x].add(y)
ans = -N
for g in g2x.keys():
if g2x[g]:
ans += len(g2x[g]) * len(g2y[g])
return ans
print(main())
``` | instruction | 0 | 6,428 | 23 | 12,856 |
No | output | 1 | 6,428 | 23 | 12,857 |
Provide a correct Python 3 solution for this coding contest problem.
There are four points: $A(x_1, y_1)$, $B(x_2, y_2)$, $C(x_3, y_3)$, and $D(x_4, y_4)$. Write a program which determines whether the line $AB$ and the line $CD$ are parallel. If those two lines are parallel, your program should prints "YES" and if not prints "NO".
Input
Input consists of several datasets. In the first line, you are given the number of datasets $n$ ($n \leq 100$). There will be $n$ lines where each line correspondgs to each dataset. Each dataset consists of eight real numbers:
$x_1$ $y_1$ $x_2$ $y_2$ $x_3$ $y_3$ $x_4$ $y_4$
You can assume that $-100 \leq x_1, y_1, x_2, y_2, x_3, y_3, x_4, y_4 \leq 100$. Each value is a real number with at most 5 digits after the decimal point.
Output
For each dataset, print "YES" or "NO" in a line.
Example
Input
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
Output
YES
NO | instruction | 0 | 6,493 | 23 | 12,986 |
"Correct Solution:
```
EPS = 10**-10
n = int(input())
pos = []
for _ in range(n):
pos.append(list(map(float, input().split())))
for i in range(n):
vec_ax = pos[i][2]-pos[i][0]
vec_ay = pos[i][3]-pos[i][1]
vec_bx = pos[i][6]-pos[i][4]
vec_by = pos[i][7]-pos[i][5]
if abs(vec_bx*vec_ay - vec_by*vec_ax) < EPS:
print("YES")
else:
print("NO")
``` | output | 1 | 6,493 | 23 | 12,987 |
Provide a correct Python 3 solution for this coding contest problem.
There are four points: $A(x_1, y_1)$, $B(x_2, y_2)$, $C(x_3, y_3)$, and $D(x_4, y_4)$. Write a program which determines whether the line $AB$ and the line $CD$ are parallel. If those two lines are parallel, your program should prints "YES" and if not prints "NO".
Input
Input consists of several datasets. In the first line, you are given the number of datasets $n$ ($n \leq 100$). There will be $n$ lines where each line correspondgs to each dataset. Each dataset consists of eight real numbers:
$x_1$ $y_1$ $x_2$ $y_2$ $x_3$ $y_3$ $x_4$ $y_4$
You can assume that $-100 \leq x_1, y_1, x_2, y_2, x_3, y_3, x_4, y_4 \leq 100$. Each value is a real number with at most 5 digits after the decimal point.
Output
For each dataset, print "YES" or "NO" in a line.
Example
Input
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
Output
YES
NO | instruction | 0 | 6,494 | 23 | 12,988 |
"Correct Solution:
```
def cross_product(a,b):
return (a.conjugate()*b).imag
N = int(input().strip())
for _ in range(N):
P = list(map(float,input().strip().split()))
for i in range(len(P)):
P[i] = int(P[i]*1000000.0)
z = complex(P[0]-P[2],P[1]-P[3])
w = complex(P[4]-P[6],P[5]-P[7])
if abs(cross_product(z,w)) < 1:
print("YES")
else:
print("NO")
``` | output | 1 | 6,494 | 23 | 12,989 |
Provide a correct Python 3 solution for this coding contest problem.
There are four points: $A(x_1, y_1)$, $B(x_2, y_2)$, $C(x_3, y_3)$, and $D(x_4, y_4)$. Write a program which determines whether the line $AB$ and the line $CD$ are parallel. If those two lines are parallel, your program should prints "YES" and if not prints "NO".
Input
Input consists of several datasets. In the first line, you are given the number of datasets $n$ ($n \leq 100$). There will be $n$ lines where each line correspondgs to each dataset. Each dataset consists of eight real numbers:
$x_1$ $y_1$ $x_2$ $y_2$ $x_3$ $y_3$ $x_4$ $y_4$
You can assume that $-100 \leq x_1, y_1, x_2, y_2, x_3, y_3, x_4, y_4 \leq 100$. Each value is a real number with at most 5 digits after the decimal point.
Output
For each dataset, print "YES" or "NO" in a line.
Example
Input
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
Output
YES
NO | instruction | 0 | 6,495 | 23 | 12,990 |
"Correct Solution:
```
import math
import cmath
def cross_product(a,b):
return (a.conjugate()*b).imag
n = int(input())
for i in range(n):
L = list(map(float,input().split()))
a,b,c,d = [complex(L[j*2],L[j*2+1]) for j in range(4)]
vec_A = b-a
vec_B = d-c
if abs(cross_product(vec_A,vec_B)) < 1e-11:
print('YES')
else:
print('NO')
``` | output | 1 | 6,495 | 23 | 12,991 |
Provide a correct Python 3 solution for this coding contest problem.
There are four points: $A(x_1, y_1)$, $B(x_2, y_2)$, $C(x_3, y_3)$, and $D(x_4, y_4)$. Write a program which determines whether the line $AB$ and the line $CD$ are parallel. If those two lines are parallel, your program should prints "YES" and if not prints "NO".
Input
Input consists of several datasets. In the first line, you are given the number of datasets $n$ ($n \leq 100$). There will be $n$ lines where each line correspondgs to each dataset. Each dataset consists of eight real numbers:
$x_1$ $y_1$ $x_2$ $y_2$ $x_3$ $y_3$ $x_4$ $y_4$
You can assume that $-100 \leq x_1, y_1, x_2, y_2, x_3, y_3, x_4, y_4 \leq 100$. Each value is a real number with at most 5 digits after the decimal point.
Output
For each dataset, print "YES" or "NO" in a line.
Example
Input
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
Output
YES
NO | instruction | 0 | 6,496 | 23 | 12,992 |
"Correct Solution:
```
E = 10 ** -10
def check(lst):
x1, y1, x2, y2, x3, y3, x4, y4 = lst
vabx, vaby = x2 - x1, y2 - y1
vcdx, vcdy = x4 - x3, y4 - y3
if abs(vabx * vcdy - vcdx * vaby) < E:
return True
else:
return False
n = int(input())
for _ in range(n):
plst = list(map(float, input().split()))
print("YES" if check(plst) else "NO")
``` | output | 1 | 6,496 | 23 | 12,993 |
Provide a correct Python 3 solution for this coding contest problem.
There are four points: $A(x_1, y_1)$, $B(x_2, y_2)$, $C(x_3, y_3)$, and $D(x_4, y_4)$. Write a program which determines whether the line $AB$ and the line $CD$ are parallel. If those two lines are parallel, your program should prints "YES" and if not prints "NO".
Input
Input consists of several datasets. In the first line, you are given the number of datasets $n$ ($n \leq 100$). There will be $n$ lines where each line correspondgs to each dataset. Each dataset consists of eight real numbers:
$x_1$ $y_1$ $x_2$ $y_2$ $x_3$ $y_3$ $x_4$ $y_4$
You can assume that $-100 \leq x_1, y_1, x_2, y_2, x_3, y_3, x_4, y_4 \leq 100$. Each value is a real number with at most 5 digits after the decimal point.
Output
For each dataset, print "YES" or "NO" in a line.
Example
Input
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
Output
YES
NO | instruction | 0 | 6,497 | 23 | 12,994 |
"Correct Solution:
```
n = int(input())
for _ in range(n):
x1, y1, x2, y2, x3, y3, x4, y4 = map(float, input().split())
abx = x2 - x1
aby = y2 - y1
cdx = x4 - x3
cdy = y4 - y3
if abs(aby * cdx) < 1e-10 and abs(cdy * abx) < 1e-10:
print(['NO', 'YES'][abs(abx - cdx) < 1e-10 or abs(aby - cdy) < 1e-10])
elif abs(aby * cdx - cdy * abx) < 1e-10:
print('YES')
else:
print('NO')
``` | output | 1 | 6,497 | 23 | 12,995 |
Provide a correct Python 3 solution for this coding contest problem.
There are four points: $A(x_1, y_1)$, $B(x_2, y_2)$, $C(x_3, y_3)$, and $D(x_4, y_4)$. Write a program which determines whether the line $AB$ and the line $CD$ are parallel. If those two lines are parallel, your program should prints "YES" and if not prints "NO".
Input
Input consists of several datasets. In the first line, you are given the number of datasets $n$ ($n \leq 100$). There will be $n$ lines where each line correspondgs to each dataset. Each dataset consists of eight real numbers:
$x_1$ $y_1$ $x_2$ $y_2$ $x_3$ $y_3$ $x_4$ $y_4$
You can assume that $-100 \leq x_1, y_1, x_2, y_2, x_3, y_3, x_4, y_4 \leq 100$. Each value is a real number with at most 5 digits after the decimal point.
Output
For each dataset, print "YES" or "NO" in a line.
Example
Input
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
Output
YES
NO | instruction | 0 | 6,498 | 23 | 12,996 |
"Correct Solution:
```
import math
def equal(x, y):
return math.fabs(x - y) <= 10 ** (-10)
def spam(_x1, _y1, _x2, _y2):
if _x1 > _x2:
return _x1, _y1, _x2, _y2
else:
return _x2, _y2, _x1, _y1
for i in range(int(input())):
x1, y1, x2, y2, x3, y3, x4, y4 = list(map(float, input().split()))
b1 = (x1 - x2, y1 - y2)
b2 = (x3 - x4, y3 - y4)
p = 0 if b2[0] != 0 else 1
q = 1 if b2[0] != 0 else 0
t = b1[p]/b2[p]
if equal(b1[q], b2[q] * t):
print('YES')
else:
print('NO')
``` | output | 1 | 6,498 | 23 | 12,997 |
Provide a correct Python 3 solution for this coding contest problem.
There are four points: $A(x_1, y_1)$, $B(x_2, y_2)$, $C(x_3, y_3)$, and $D(x_4, y_4)$. Write a program which determines whether the line $AB$ and the line $CD$ are parallel. If those two lines are parallel, your program should prints "YES" and if not prints "NO".
Input
Input consists of several datasets. In the first line, you are given the number of datasets $n$ ($n \leq 100$). There will be $n$ lines where each line correspondgs to each dataset. Each dataset consists of eight real numbers:
$x_1$ $y_1$ $x_2$ $y_2$ $x_3$ $y_3$ $x_4$ $y_4$
You can assume that $-100 \leq x_1, y_1, x_2, y_2, x_3, y_3, x_4, y_4 \leq 100$. Each value is a real number with at most 5 digits after the decimal point.
Output
For each dataset, print "YES" or "NO" in a line.
Example
Input
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
Output
YES
NO | instruction | 0 | 6,499 | 23 | 12,998 |
"Correct Solution:
```
n = int(input())
for i in range(n):
x1, y1, x2, y2, x3, y3, x4, y4 = map(float, input().split())
v1x = x1 - x2
v1y = y1 - y2
v2x = x3 - x4
v2y = y3 - y4
if abs(v1x * v2y - v2x * v1y) < 10 ** -10 :
print("YES")
else:
print("NO")
``` | output | 1 | 6,499 | 23 | 12,999 |
Provide a correct Python 3 solution for this coding contest problem.
There are four points: $A(x_1, y_1)$, $B(x_2, y_2)$, $C(x_3, y_3)$, and $D(x_4, y_4)$. Write a program which determines whether the line $AB$ and the line $CD$ are parallel. If those two lines are parallel, your program should prints "YES" and if not prints "NO".
Input
Input consists of several datasets. In the first line, you are given the number of datasets $n$ ($n \leq 100$). There will be $n$ lines where each line correspondgs to each dataset. Each dataset consists of eight real numbers:
$x_1$ $y_1$ $x_2$ $y_2$ $x_3$ $y_3$ $x_4$ $y_4$
You can assume that $-100 \leq x_1, y_1, x_2, y_2, x_3, y_3, x_4, y_4 \leq 100$. Each value is a real number with at most 5 digits after the decimal point.
Output
For each dataset, print "YES" or "NO" in a line.
Example
Input
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
Output
YES
NO | instruction | 0 | 6,500 | 23 | 13,000 |
"Correct Solution:
```
# AOJ 0021: Parallelism
# Python3 2018.6.15 bal4u
EPS = 1e-11
def dot(a, b):
return a.real*b.real + a.imag*b.imag
def cross(a, b):
return a.real*b.imag - a.imag*b.real
def norm(a):
return a.real**2 + a.imag**2
def project(line, p):
base = line[1]-line[0]
r = dot(p-line[0], base) / norm(base)
return line[0] + base*r
def symmetric_Point(line, p):
return p + 2*(project(line, p)-p)
def isParallelLL(line1, line2):
t = cross(line1[1]-line1[0], line2[1]-line2[0])
return -EPS <= t and t <= EPS
for _ in range(int(input())):
p = list(map(float, input().split()))
p1 = complex(p[0], p[1])
p2 = complex(p[2], p[3])
p3 = complex(p[4], p[5])
p4 = complex(p[6], p[7])
print('YES' if isParallelLL([p1,p2], [p3,p4]) else 'NO')
``` | output | 1 | 6,500 | 23 | 13,001 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are four points: $A(x_1, y_1)$, $B(x_2, y_2)$, $C(x_3, y_3)$, and $D(x_4, y_4)$. Write a program which determines whether the line $AB$ and the line $CD$ are parallel. If those two lines are parallel, your program should prints "YES" and if not prints "NO".
Input
Input consists of several datasets. In the first line, you are given the number of datasets $n$ ($n \leq 100$). There will be $n$ lines where each line correspondgs to each dataset. Each dataset consists of eight real numbers:
$x_1$ $y_1$ $x_2$ $y_2$ $x_3$ $y_3$ $x_4$ $y_4$
You can assume that $-100 \leq x_1, y_1, x_2, y_2, x_3, y_3, x_4, y_4 \leq 100$. Each value is a real number with at most 5 digits after the decimal point.
Output
For each dataset, print "YES" or "NO" in a line.
Example
Input
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
Output
YES
NO
Submitted Solution:
```
for i in range(int(input())):
ax, ay, bx, by, cx, cy, dx, dy = map(float, input().split())
if ax==bx or cx==dx:
print("YES" if ax==bx and cx==dx and ay!=by and cy!=dy else "NO")
else:
print("YES" if abs((ay-by)/(ax-bx)-(cy-dy)/(cx-dx))<1e-10 else "NO")
``` | instruction | 0 | 6,501 | 23 | 13,002 |
Yes | output | 1 | 6,501 | 23 | 13,003 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are four points: $A(x_1, y_1)$, $B(x_2, y_2)$, $C(x_3, y_3)$, and $D(x_4, y_4)$. Write a program which determines whether the line $AB$ and the line $CD$ are parallel. If those two lines are parallel, your program should prints "YES" and if not prints "NO".
Input
Input consists of several datasets. In the first line, you are given the number of datasets $n$ ($n \leq 100$). There will be $n$ lines where each line correspondgs to each dataset. Each dataset consists of eight real numbers:
$x_1$ $y_1$ $x_2$ $y_2$ $x_3$ $y_3$ $x_4$ $y_4$
You can assume that $-100 \leq x_1, y_1, x_2, y_2, x_3, y_3, x_4, y_4 \leq 100$. Each value is a real number with at most 5 digits after the decimal point.
Output
For each dataset, print "YES" or "NO" in a line.
Example
Input
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
Output
YES
NO
Submitted Solution:
```
N=int(input())
for _ in range(N):
p=list(map(float,input().split()))
a,b,c,d=map(lambda x:complex(*x),[p[:2],p[2:4],p[4:6],p[6:]])
print(['NO','YES'][abs(((a-b).conjugate()*(c-d)).imag)<1e-11])
``` | instruction | 0 | 6,502 | 23 | 13,004 |
Yes | output | 1 | 6,502 | 23 | 13,005 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are four points: $A(x_1, y_1)$, $B(x_2, y_2)$, $C(x_3, y_3)$, and $D(x_4, y_4)$. Write a program which determines whether the line $AB$ and the line $CD$ are parallel. If those two lines are parallel, your program should prints "YES" and if not prints "NO".
Input
Input consists of several datasets. In the first line, you are given the number of datasets $n$ ($n \leq 100$). There will be $n$ lines where each line correspondgs to each dataset. Each dataset consists of eight real numbers:
$x_1$ $y_1$ $x_2$ $y_2$ $x_3$ $y_3$ $x_4$ $y_4$
You can assume that $-100 \leq x_1, y_1, x_2, y_2, x_3, y_3, x_4, y_4 \leq 100$. Each value is a real number with at most 5 digits after the decimal point.
Output
For each dataset, print "YES" or "NO" in a line.
Example
Input
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
Output
YES
NO
Submitted Solution:
```
n=int(input())
for j in range(n):
p=[float(i) for i in input().split()]
if round((p[2]-p[0])*(p[7]-p[5])-(p[3]-p[1])*(p[6]-p[4]),10)==0:
print("YES")
else:
print("NO")
``` | instruction | 0 | 6,503 | 23 | 13,006 |
Yes | output | 1 | 6,503 | 23 | 13,007 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are four points: $A(x_1, y_1)$, $B(x_2, y_2)$, $C(x_3, y_3)$, and $D(x_4, y_4)$. Write a program which determines whether the line $AB$ and the line $CD$ are parallel. If those two lines are parallel, your program should prints "YES" and if not prints "NO".
Input
Input consists of several datasets. In the first line, you are given the number of datasets $n$ ($n \leq 100$). There will be $n$ lines where each line correspondgs to each dataset. Each dataset consists of eight real numbers:
$x_1$ $y_1$ $x_2$ $y_2$ $x_3$ $y_3$ $x_4$ $y_4$
You can assume that $-100 \leq x_1, y_1, x_2, y_2, x_3, y_3, x_4, y_4 \leq 100$. Each value is a real number with at most 5 digits after the decimal point.
Output
For each dataset, print "YES" or "NO" in a line.
Example
Input
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
Output
YES
NO
Submitted Solution:
```
for _ in range(int(input())):
x1,y1,x2,y2,x3,y3,x4,y4=map(float,input().split())
if abs((x2 - x1)*(y4 - y3) - (y2 - y1)*(x4 - x3)) < 1e-10:
print("YES")
else:
print("NO")
``` | instruction | 0 | 6,504 | 23 | 13,008 |
Yes | output | 1 | 6,504 | 23 | 13,009 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.