message stringlengths 2 44.5k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 276 109k | cluster float64 23 23 | __index_level_0__ int64 552 217k |
|---|---|---|---|---|---|
Provide a correct Python 3 solution for this coding contest problem.
For given $N$ points in the 2D Euclidean plane, find the distance of the shortest tour that meets the following criteria:
* Visit the points according to the following steps:
1. It starts from the leftmost point (starting point), goes strictly from left to right, and then visits the rightmost point (turn-around point).
2. Then it starts from the turn-around point, goes strictly from right to left, and then back to the starting point.
* Through the processes 1. 2., the tour must visit each point at least once.
Constraints
* $2 \leq N \leq 1000$
* $-1000 \leq x_i, y_i \leq 1000$
* $x_i$ differ from each other
* The given points are already sorted by x-coordinates
Input
The input data is given in the following format:
$N$
$x_1$ $y_1$
$x_2$ $y_2$
...
$x_N$ $y_N$
Output
Print the distance of the shortest tour in a line. The output should not have an error greater than 0.0001.
Examples
Input
3
0 0
1 1
2 0
Output
4.82842712
Input
4
0 1
1 2
2 0
3 1
Output
7.30056308
Input
5
0 0
1 2
2 1
3 2
4 0
Output
10.94427191 | instruction | 0 | 4,137 | 23 | 8,274 |
"Correct Solution:
```
import sys
sys.setrecursionlimit(1000000)
def calc(p1, p2, v):
dists_v = dists[v]
if v == n - 1:
return dists_v[p1] + dists_v[p2]
if visited[p1][p2]:
return dp[p1][p2]
dp[p1][p2] = min(dists_v[p1] + calc(p2, v, v + 1), dists_v[p2] + calc(p1, v, v + 1))
visited[p1][p2] = True
return dp[p1][p2]
n = int(input())
points = [complex(*map(int, input().split())) for _ in range(n)]
dists = [[abs(p1 - p2) for p2 in points] for p1 in points]
visited = [[False] * n for _ in range(n)]
dp = [[0] * n for _ in range(n)]
print(calc(0, 0, 0))
``` | output | 1 | 4,137 | 23 | 8,275 |
Provide a correct Python 3 solution for this coding contest problem.
For given $N$ points in the 2D Euclidean plane, find the distance of the shortest tour that meets the following criteria:
* Visit the points according to the following steps:
1. It starts from the leftmost point (starting point), goes strictly from left to right, and then visits the rightmost point (turn-around point).
2. Then it starts from the turn-around point, goes strictly from right to left, and then back to the starting point.
* Through the processes 1. 2., the tour must visit each point at least once.
Constraints
* $2 \leq N \leq 1000$
* $-1000 \leq x_i, y_i \leq 1000$
* $x_i$ differ from each other
* The given points are already sorted by x-coordinates
Input
The input data is given in the following format:
$N$
$x_1$ $y_1$
$x_2$ $y_2$
...
$x_N$ $y_N$
Output
Print the distance of the shortest tour in a line. The output should not have an error greater than 0.0001.
Examples
Input
3
0 0
1 1
2 0
Output
4.82842712
Input
4
0 1
1 2
2 0
3 1
Output
7.30056308
Input
5
0 0
1 2
2 1
3 2
4 0
Output
10.94427191 | instruction | 0 | 4,138 | 23 | 8,276 |
"Correct Solution:
```
#!python3
import sys
from math import sqrt
sys.setrecursionlimit(1000000)
iim = lambda: map(int, input().rstrip().split())
def resolve():
N = int(input())
P = [list(iim()) for i in range(N)]
def dist(i, j):
x = P[i][0] - P[j][0]
y = P[i][1] - P[j][1]
return sqrt(x*x + y*y)
def tsp(i, j, k):
if i == 0 and j == 0:
return dist(0, 1) + tsp(0, 1, 0)
else:
if dp[i][j]: return dp[i][j]
if k == N: return dist(i, j)
d1 = dist(i, k) + tsp(k, j, k + 1)
d2 = dist(j, k) + tsp(i, k, k + 1)
d = d1 if d1 < d2 else d2
dp[i][j] = d
return d
dp = [[0]*N for i in range(N)]
print(tsp(0,0,0))
if __name__ == "__main__":
resolve()
``` | output | 1 | 4,138 | 23 | 8,277 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For given $N$ points in the 2D Euclidean plane, find the distance of the shortest tour that meets the following criteria:
* Visit the points according to the following steps:
1. It starts from the leftmost point (starting point), goes strictly from left to right, and then visits the rightmost point (turn-around point).
2. Then it starts from the turn-around point, goes strictly from right to left, and then back to the starting point.
* Through the processes 1. 2., the tour must visit each point at least once.
Constraints
* $2 \leq N \leq 1000$
* $-1000 \leq x_i, y_i \leq 1000$
* $x_i$ differ from each other
* The given points are already sorted by x-coordinates
Input
The input data is given in the following format:
$N$
$x_1$ $y_1$
$x_2$ $y_2$
...
$x_N$ $y_N$
Output
Print the distance of the shortest tour in a line. The output should not have an error greater than 0.0001.
Examples
Input
3
0 0
1 1
2 0
Output
4.82842712
Input
4
0 1
1 2
2 0
3 1
Output
7.30056308
Input
5
0 0
1 2
2 1
3 2
4 0
Output
10.94427191
Submitted Solution:
```
import sys
sys.setrecursionlimit(1000)
def calc(p1, p2, v):
dists_v = dists[v]
if v == n - 1:
return dists_v[p1] + dists_v[p2]
if visited[p1][p2]:
return dp[p1][p2]
dp[p1][p2] = min(dists_v[p1] + calc(p2, v, v + 1), dists_v[p2] + calc(p1, v, v + 1))
visited[p1][p2] = True
return dp[p1][p2]
n = int(input())
points = [complex(*map(int, input().split())) for _ in range(n)]
dists = [[abs(p1 - p2) for p2 in points] for p1 in points]
visited = [[False] * n for _ in range(n)]
dp = [[0] * n for _ in range(n)]
print(calc(0, 0, 0))
``` | instruction | 0 | 4,139 | 23 | 8,278 |
No | output | 1 | 4,139 | 23 | 8,279 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For given $N$ points in the 2D Euclidean plane, find the distance of the shortest tour that meets the following criteria:
* Visit the points according to the following steps:
1. It starts from the leftmost point (starting point), goes strictly from left to right, and then visits the rightmost point (turn-around point).
2. Then it starts from the turn-around point, goes strictly from right to left, and then back to the starting point.
* Through the processes 1. 2., the tour must visit each point at least once.
Constraints
* $2 \leq N \leq 1000$
* $-1000 \leq x_i, y_i \leq 1000$
* $x_i$ differ from each other
* The given points are already sorted by x-coordinates
Input
The input data is given in the following format:
$N$
$x_1$ $y_1$
$x_2$ $y_2$
...
$x_N$ $y_N$
Output
Print the distance of the shortest tour in a line. The output should not have an error greater than 0.0001.
Examples
Input
3
0 0
1 1
2 0
Output
4.82842712
Input
4
0 1
1 2
2 0
3 1
Output
7.30056308
Input
5
0 0
1 2
2 1
3 2
4 0
Output
10.94427191
Submitted Solution:
```
def calc(p1, p2, v):
dists_v = dists[v]
if v == n - 1:
return dists_v[p1] + dists_v[p2]
if visited[p1][p2]:
return dp[p1][p2]
dp[p1][p2] = min(dists_v[p1] + calc(p2, v, v + 1), dists_v[p2] + calc(p1, v, v + 1))
visited[p1][p2] = True
return dp[p1][p2]
n = int(input())
points = [complex(*map(int, input().split())) for _ in range(n)]
dists = [[abs(p1 - p2) for p2 in points] for p1 in points]
visited = [[False] * n for _ in range(n)]
dp = [[0] * n for _ in range(n)]
print(calc(0, 0, 0))
``` | instruction | 0 | 4,140 | 23 | 8,280 |
No | output | 1 | 4,140 | 23 | 8,281 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are a set of points S on the plane. This set doesn't contain the origin O(0, 0), and for each two distinct points in the set A and B, the triangle OAB has strictly positive area.
Consider a set of pairs of points (P1, P2), (P3, P4), ..., (P2k - 1, P2k). We'll call the set good if and only if:
* k β₯ 2.
* All Pi are distinct, and each Pi is an element of S.
* For any two pairs (P2i - 1, P2i) and (P2j - 1, P2j), the circumcircles of triangles OP2i - 1P2j - 1 and OP2iP2j have a single common point, and the circumcircle of triangles OP2i - 1P2j and OP2iP2j - 1 have a single common point.
Calculate the number of good sets of pairs modulo 1000000007 (109 + 7).
Input
The first line contains a single integer n (1 β€ n β€ 1000) β the number of points in S. Each of the next n lines contains four integers ai, bi, ci, di (0 β€ |ai|, |ci| β€ 50; 1 β€ bi, di β€ 50; (ai, ci) β (0, 0)). These integers represent a point <image>.
No two points coincide.
Output
Print a single integer β the answer to the problem modulo 1000000007 (109 + 7).
Examples
Input
10
-46 46 0 36
0 20 -24 48
-50 50 -49 49
-20 50 8 40
-15 30 14 28
4 10 -4 5
6 15 8 10
-20 50 -3 15
4 34 -16 34
16 34 2 17
Output
2
Input
10
30 30 -26 26
0 15 -36 36
-28 28 -34 34
10 10 0 4
-8 20 40 50
9 45 12 30
6 15 7 35
36 45 -8 20
-16 34 -4 34
4 34 8 17
Output
4
Input
10
0 20 38 38
-30 30 -13 13
-11 11 16 16
30 30 0 37
6 30 -4 10
6 15 12 15
-4 5 -10 25
-16 20 4 10
8 17 -2 17
16 34 2 17
Output
10
Submitted Solution:
```
from fractions import Fraction
from collections import defaultdict
MOD = 10**9 + 7
n, p = int(input()), []
for yo in range(n):
a, b, c, d = map(int, input().split())
down = a * a * d * d + b * b * c * c
p.append((Fraction(a * b * d * d, down), Fraction(c * d * b * b, down)))
mids = defaultdict(int)
for i in range(n):
for j in range(i + 1, n):
mids[(p[i][0] + p[j][0], p[i][1] + p[j][1])] += 1
ans = 0
for cnt in mids.values():
ans += pow(2, cnt, MOD) - cnt - 1
ans = ((ans % MOD) + MOD) % MOD
print(ans)
``` | instruction | 0 | 4,532 | 23 | 9,064 |
No | output | 1 | 4,532 | 23 | 9,065 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
An n Γ n square matrix is special, if:
* it is binary, that is, each cell contains either a 0, or a 1;
* the number of ones in each row and column equals 2.
You are given n and the first m rows of the matrix. Print the number of special n Γ n matrices, such that the first m rows coincide with the given ones.
As the required value can be rather large, print the remainder after dividing the value by the given number mod.
Input
The first line of the input contains three integers n, m, mod (2 β€ n β€ 500, 0 β€ m β€ n, 2 β€ mod β€ 109). Then m lines follow, each of them contains n characters β the first rows of the required special matrices. Each of these lines contains exactly two characters '1', the rest characters are '0'. Each column of the given m Γ n table contains at most two numbers one.
Output
Print the remainder after dividing the required value by number mod.
Examples
Input
3 1 1000
011
Output
2
Input
4 4 100500
0110
1010
0101
1001
Output
1
Note
For the first test the required matrices are:
011
101
110
011
110
101
In the second test the required matrix is already fully given, so the answer is 1.
Submitted Solution:
```
n, m, od = map(int, input().split())
ones_in_c = [0 for i in range(n)]
for i in range(m):
inp = input()
for j in range(n):
ones_in_c[j] = ones_in_c[j]+1 if inp[j] == '1' else ones_in_c[j]
need2 = ones_in_c.count(0)
need1 = ones_in_c.count(1)
rows_left = n-m
dp = {}
def count_rows(need1, need2, rows_left):
global n, od
if (need1, need2, rows_left) in dp:
return dp[(need1, need2, rows_left)]
if rows_left == 1:
return 1
total = 0
if need1 >= 2:
total += rows_left*(rows_left-1)/2*count_rows(need1-2, need2, rows_left-1)
if need2 >=1 and need1 >= 1:
total += rows_left*(rows_left-1)/2*count_rows(need1, need2-1, rows_left-1)
if need2 >= 2:
total += rows_left*(rows_left-1)/2*count_rows(need1+2, need2-2, rows_left-1)
#print(need1, need2, rows_left, total)
return total % od
#print(need1, need2, rows_left)
if need2*2 + need1 != 2*rows_left:
print(0)
else:
if rows_left == 0:
print(1)
else:
print(int(count_rows(need1, need2, rows_left)))
``` | instruction | 0 | 4,592 | 23 | 9,184 |
No | output | 1 | 4,592 | 23 | 9,185 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
An n Γ n square matrix is special, if:
* it is binary, that is, each cell contains either a 0, or a 1;
* the number of ones in each row and column equals 2.
You are given n and the first m rows of the matrix. Print the number of special n Γ n matrices, such that the first m rows coincide with the given ones.
As the required value can be rather large, print the remainder after dividing the value by the given number mod.
Input
The first line of the input contains three integers n, m, mod (2 β€ n β€ 500, 0 β€ m β€ n, 2 β€ mod β€ 109). Then m lines follow, each of them contains n characters β the first rows of the required special matrices. Each of these lines contains exactly two characters '1', the rest characters are '0'. Each column of the given m Γ n table contains at most two numbers one.
Output
Print the remainder after dividing the required value by number mod.
Examples
Input
3 1 1000
011
Output
2
Input
4 4 100500
0110
1010
0101
1001
Output
1
Note
For the first test the required matrices are:
011
101
110
011
110
101
In the second test the required matrix is already fully given, so the answer is 1.
Submitted Solution:
```
n, m, mod = [int(x) for x in input().split()]
from functools import lru_cache
@lru_cache(maxsize=None)
def rec(twos, ones):
global mod
if twos == 0 and ones == 0:
return 1
if twos != 0 and ones == 0:
return 0
else:
count = 0
# we can pick two from ones if there are at least two:
if (ones >= 2):
a = ones*(ones-1)//2
b = rec(twos, ones-2)
count += (a*b) % mod
if (ones >= 1 and twos >= 1):
a = ones*twos
b = rec(twos-1, ones)
count += (a*b) % mod
return count % mod
# we read the beginning matrix and calculate the starting position
matrix = []
for i in range(0, m):
matrix.append([int(x) for x in input()])
twocount = 0
onecount = 0
for c in range(0, n):
# for each column count the number of ones in it
count = 0
for r in range(0, m):
# r is the row, c is the column
if (matrix[r][c] == 1):
count += 1
if count == 2:
twocount += 1
elif count == 1:
onecount += 1
ones = onecount
twos = n - onecount - twocount
print(rec(twos, ones))
``` | instruction | 0 | 4,593 | 23 | 9,186 |
No | output | 1 | 4,593 | 23 | 9,187 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
An n Γ n square matrix is special, if:
* it is binary, that is, each cell contains either a 0, or a 1;
* the number of ones in each row and column equals 2.
You are given n and the first m rows of the matrix. Print the number of special n Γ n matrices, such that the first m rows coincide with the given ones.
As the required value can be rather large, print the remainder after dividing the value by the given number mod.
Input
The first line of the input contains three integers n, m, mod (2 β€ n β€ 500, 0 β€ m β€ n, 2 β€ mod β€ 109). Then m lines follow, each of them contains n characters β the first rows of the required special matrices. Each of these lines contains exactly two characters '1', the rest characters are '0'. Each column of the given m Γ n table contains at most two numbers one.
Output
Print the remainder after dividing the required value by number mod.
Examples
Input
3 1 1000
011
Output
2
Input
4 4 100500
0110
1010
0101
1001
Output
1
Note
For the first test the required matrices are:
011
101
110
011
110
101
In the second test the required matrix is already fully given, so the answer is 1.
Submitted Solution:
```
n, m, od = map(int, input().split())
ones_in_c = [0 for i in range(n)]
for i in range(m):
inp = input()
for j in range(n):
ones_in_c[j] = ones_in_c[j]+1 if inp[j] == '1' else ones_in_c[j]
need2 = ones_in_c.count(0)
need1 = ones_in_c.count(1)
rows_left = n-m
dp = {}
def count_rows(need1, need2, rows_left):
global n, od
if (need1, need2, rows_left) in dp:
return dp[(need1, need2, rows_left)]
if rows_left == 1:
return 1
total = 0
if need1 >= 2:
total += rows_left*(rows_left-1)/2*count_rows(need1-2, need2, rows_left-1)
if need2 >=1 and need1 >= 1:
total += rows_left*(rows_left-1)/2*count_rows(need1, need2-1, rows_left-1)
if need2 >= 2:
total += rows_left*(rows_left-1)/2*count_rows(need1+2, need2-2, rows_left-1)
print(need1, need2, rows_left, total)
return total % od
#print(need1, need2, rows_left)
if need2*2 + need1 != 2*rows_left:
print(0)
else:
if rows_left == 0:
print(1)
print(count_rows(need1, need2, rows_left))
``` | instruction | 0 | 4,594 | 23 | 9,188 |
No | output | 1 | 4,594 | 23 | 9,189 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
An n Γ n square matrix is special, if:
* it is binary, that is, each cell contains either a 0, or a 1;
* the number of ones in each row and column equals 2.
You are given n and the first m rows of the matrix. Print the number of special n Γ n matrices, such that the first m rows coincide with the given ones.
As the required value can be rather large, print the remainder after dividing the value by the given number mod.
Input
The first line of the input contains three integers n, m, mod (2 β€ n β€ 500, 0 β€ m β€ n, 2 β€ mod β€ 109). Then m lines follow, each of them contains n characters β the first rows of the required special matrices. Each of these lines contains exactly two characters '1', the rest characters are '0'. Each column of the given m Γ n table contains at most two numbers one.
Output
Print the remainder after dividing the required value by number mod.
Examples
Input
3 1 1000
011
Output
2
Input
4 4 100500
0110
1010
0101
1001
Output
1
Note
For the first test the required matrices are:
011
101
110
011
110
101
In the second test the required matrix is already fully given, so the answer is 1.
Submitted Solution:
```
n, m, od = map(int, input().split())
ones_in_c = [0 for i in range(n)]
for i in range(m):
inp = input()
for j in range(n):
ones_in_c[j] = ones_in_c[j]+1 if inp[j] == '1' else ones_in_c[j]
need2 = ones_in_c.count(0)
need1 = ones_in_c.count(1)
rows_left = n-m
dp = {}
def count_rows(need1, need2, rows_left):
global n, od
if (need1, need2, rows_left) in dp:
return dp[(need1, need2, rows_left)]
if rows_left == 1:
return 1
total = 0
if need1 >= 2:
total += rows_left*(rows_left-1)/2*count_rows(need1-2, need2, rows_left-1)
if need2 >=1 and need1 >= 1:
total += rows_left*(rows_left-1)/2*count_rows(need1, need2-1, rows_left-1)
if need2 >= 2:
total += rows_left*(rows_left-1)/2*count_rows(need1+2, need2-2, rows_left-1)
#print(need1, need2, rows_left, total)
return total % od
#print(need1, need2, rows_left)
if need2*2 + need1 != 2*rows_left:
print(0)
else:
if rows_left == 0:
print(1)
print(int(count_rows(need1, need2, rows_left)))
``` | instruction | 0 | 4,595 | 23 | 9,190 |
No | output | 1 | 4,595 | 23 | 9,191 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which judges wheather given length of three side form a right triangle. Print "YES" if the given sides (integers) form a right triangle, "NO" if not so.
Constraints
* 1 β€ length of the side β€ 1,000
* N β€ 1,000
Input
Input consists of several data sets. In the first line, the number of data set, N is given. Then, N lines follow, each line corresponds to a data set. A data set consists of three integers separated by a single space.
Output
For each data set, print "YES" or "NO".
Example
Input
3
4 3 5
4 3 6
8 8 8
Output
YES
NO
NO | instruction | 0 | 4,931 | 23 | 9,862 |
"Correct Solution:
```
n=int(input())
a_list=[]
for i in range(n):
k=list(map(int,input().split(" ")))
L,M,N=sorted(k)
if L**2+M**2==N**2:
a_list.append("YES")
else:
a_list.append("NO")
for i in a_list:
print(i)
``` | output | 1 | 4,931 | 23 | 9,863 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which judges wheather given length of three side form a right triangle. Print "YES" if the given sides (integers) form a right triangle, "NO" if not so.
Constraints
* 1 β€ length of the side β€ 1,000
* N β€ 1,000
Input
Input consists of several data sets. In the first line, the number of data set, N is given. Then, N lines follow, each line corresponds to a data set. A data set consists of three integers separated by a single space.
Output
For each data set, print "YES" or "NO".
Example
Input
3
4 3 5
4 3 6
8 8 8
Output
YES
NO
NO | instruction | 0 | 4,932 | 23 | 9,864 |
"Correct Solution:
```
n=int(input())
for i in range(n):
x=list(map(int,input().split()))
a,b,c=sorted(x)
if a**2+b**2==c**2:
print('YES')
else:
print('NO')
``` | output | 1 | 4,932 | 23 | 9,865 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which judges wheather given length of three side form a right triangle. Print "YES" if the given sides (integers) form a right triangle, "NO" if not so.
Constraints
* 1 β€ length of the side β€ 1,000
* N β€ 1,000
Input
Input consists of several data sets. In the first line, the number of data set, N is given. Then, N lines follow, each line corresponds to a data set. A data set consists of three integers separated by a single space.
Output
For each data set, print "YES" or "NO".
Example
Input
3
4 3 5
4 3 6
8 8 8
Output
YES
NO
NO | instruction | 0 | 4,933 | 23 | 9,866 |
"Correct Solution:
```
num=int(input())
for i in range(num):
a=list(map(int,input().split(" ")))
a.sort()
if(a[0]**2+a[1]**2==a[2]**2):
print("YES")
else:
print("NO")
``` | output | 1 | 4,933 | 23 | 9,867 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which judges wheather given length of three side form a right triangle. Print "YES" if the given sides (integers) form a right triangle, "NO" if not so.
Constraints
* 1 β€ length of the side β€ 1,000
* N β€ 1,000
Input
Input consists of several data sets. In the first line, the number of data set, N is given. Then, N lines follow, each line corresponds to a data set. A data set consists of three integers separated by a single space.
Output
For each data set, print "YES" or "NO".
Example
Input
3
4 3 5
4 3 6
8 8 8
Output
YES
NO
NO | instruction | 0 | 4,934 | 23 | 9,868 |
"Correct Solution:
```
n = int(input())
for _ in range(n):
a, b, c = sorted([int(x) for x in input().split()])
if c*c == b*b + a*a:
print("YES")
else:
print("NO")
``` | output | 1 | 4,934 | 23 | 9,869 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which judges wheather given length of three side form a right triangle. Print "YES" if the given sides (integers) form a right triangle, "NO" if not so.
Constraints
* 1 β€ length of the side β€ 1,000
* N β€ 1,000
Input
Input consists of several data sets. In the first line, the number of data set, N is given. Then, N lines follow, each line corresponds to a data set. A data set consists of three integers separated by a single space.
Output
For each data set, print "YES" or "NO".
Example
Input
3
4 3 5
4 3 6
8 8 8
Output
YES
NO
NO | instruction | 0 | 4,935 | 23 | 9,870 |
"Correct Solution:
```
n=int(input())
r=[sorted(list(map(int,input().split()))) for _ in range(n)]
for i in range(n):
if r[i][0]**2+r[i][1]**2==r[i][2]**2:
print('YES')
else:
print('NO')
``` | output | 1 | 4,935 | 23 | 9,871 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which judges wheather given length of three side form a right triangle. Print "YES" if the given sides (integers) form a right triangle, "NO" if not so.
Constraints
* 1 β€ length of the side β€ 1,000
* N β€ 1,000
Input
Input consists of several data sets. In the first line, the number of data set, N is given. Then, N lines follow, each line corresponds to a data set. A data set consists of three integers separated by a single space.
Output
For each data set, print "YES" or "NO".
Example
Input
3
4 3 5
4 3 6
8 8 8
Output
YES
NO
NO | instruction | 0 | 4,936 | 23 | 9,872 |
"Correct Solution:
```
n = int(input())
for _ in range(n):
tr = list(map(int, input().split()))
c = max(tr)
tr.remove(c)
wa = sum(map((lambda x: x**2), tr))
if c**2 == wa: print('YES')
else: print('NO')
``` | output | 1 | 4,936 | 23 | 9,873 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which judges wheather given length of three side form a right triangle. Print "YES" if the given sides (integers) form a right triangle, "NO" if not so.
Constraints
* 1 β€ length of the side β€ 1,000
* N β€ 1,000
Input
Input consists of several data sets. In the first line, the number of data set, N is given. Then, N lines follow, each line corresponds to a data set. A data set consists of three integers separated by a single space.
Output
For each data set, print "YES" or "NO".
Example
Input
3
4 3 5
4 3 6
8 8 8
Output
YES
NO
NO | instruction | 0 | 4,937 | 23 | 9,874 |
"Correct Solution:
```
line = int(input())
for i in range(line):
a,b,c = sorted([int(i) for i in input().split(' ')])
if a**2 + b**2 == c**2:
print('YES')
else:
print('NO')
``` | output | 1 | 4,937 | 23 | 9,875 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which judges wheather given length of three side form a right triangle. Print "YES" if the given sides (integers) form a right triangle, "NO" if not so.
Constraints
* 1 β€ length of the side β€ 1,000
* N β€ 1,000
Input
Input consists of several data sets. In the first line, the number of data set, N is given. Then, N lines follow, each line corresponds to a data set. A data set consists of three integers separated by a single space.
Output
For each data set, print "YES" or "NO".
Example
Input
3
4 3 5
4 3 6
8 8 8
Output
YES
NO
NO | instruction | 0 | 4,938 | 23 | 9,876 |
"Correct Solution:
```
for _ in range(int(input())):
x = list(sorted(map(int, input().split())))
print("YES" if x[0]**2 + x[1]**2 == x[2]**2 else "NO")
``` | output | 1 | 4,938 | 23 | 9,877 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Write a program which judges wheather given length of three side form a right triangle. Print "YES" if the given sides (integers) form a right triangle, "NO" if not so.
Constraints
* 1 β€ length of the side β€ 1,000
* N β€ 1,000
Input
Input consists of several data sets. In the first line, the number of data set, N is given. Then, N lines follow, each line corresponds to a data set. A data set consists of three integers separated by a single space.
Output
For each data set, print "YES" or "NO".
Example
Input
3
4 3 5
4 3 6
8 8 8
Output
YES
NO
NO
Submitted Solution:
```
N = int(input())
for i in range(N):
a,b,c = map(int,input().split())
if a**2 == b**2+c**2 or b**2 == a**2+c**2 or c**2 == a**2+b**2:
print('YES')
else:
print('NO')
``` | instruction | 0 | 4,939 | 23 | 9,878 |
Yes | output | 1 | 4,939 | 23 | 9,879 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Write a program which judges wheather given length of three side form a right triangle. Print "YES" if the given sides (integers) form a right triangle, "NO" if not so.
Constraints
* 1 β€ length of the side β€ 1,000
* N β€ 1,000
Input
Input consists of several data sets. In the first line, the number of data set, N is given. Then, N lines follow, each line corresponds to a data set. A data set consists of three integers separated by a single space.
Output
For each data set, print "YES" or "NO".
Example
Input
3
4 3 5
4 3 6
8 8 8
Output
YES
NO
NO
Submitted Solution:
```
[print("YES" if y[0] + y[1] == y[2] else "NO") for y in [sorted([int(x)**2 for x in input().split()]) for _ in range(int(input()))]]
``` | instruction | 0 | 4,940 | 23 | 9,880 |
Yes | output | 1 | 4,940 | 23 | 9,881 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Write a program which judges wheather given length of three side form a right triangle. Print "YES" if the given sides (integers) form a right triangle, "NO" if not so.
Constraints
* 1 β€ length of the side β€ 1,000
* N β€ 1,000
Input
Input consists of several data sets. In the first line, the number of data set, N is given. Then, N lines follow, each line corresponds to a data set. A data set consists of three integers separated by a single space.
Output
For each data set, print "YES" or "NO".
Example
Input
3
4 3 5
4 3 6
8 8 8
Output
YES
NO
NO
Submitted Solution:
```
def main():
n = int(input())
if n <= 0:
return None
li = [input() for _ in range(n)]
li = sorted(li)
for x in li:
tmp = x.split(" ")
for i in range(len(tmp)):
tmp[i] = int(tmp[i])
tmp = sorted(tmp)
a,b,c = tmp[0],tmp[1],tmp[2]
if (a**2 + b**2) == c**2:
print("YES")
else:
print("NO")
return None
if __name__ == '__main__':
main()
``` | instruction | 0 | 4,944 | 23 | 9,888 |
No | output | 1 | 4,944 | 23 | 9,889 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Write a program which judges wheather given length of three side form a right triangle. Print "YES" if the given sides (integers) form a right triangle, "NO" if not so.
Constraints
* 1 β€ length of the side β€ 1,000
* N β€ 1,000
Input
Input consists of several data sets. In the first line, the number of data set, N is given. Then, N lines follow, each line corresponds to a data set. A data set consists of three integers separated by a single space.
Output
For each data set, print "YES" or "NO".
Example
Input
3
4 3 5
4 3 6
8 8 8
Output
YES
NO
NO
Submitted Solution:
```
cnt = int(input())
values = []
for i in range(cnt):
values.append([int(x) for x in input().split()])
for x, y, z in values:
if int(z ** 2) == int(x ** 2) + int(y ** 2):
print('YES')
else:
print('NO')
``` | instruction | 0 | 4,945 | 23 | 9,890 |
No | output | 1 | 4,945 | 23 | 9,891 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Write a program which judges wheather given length of three side form a right triangle. Print "YES" if the given sides (integers) form a right triangle, "NO" if not so.
Constraints
* 1 β€ length of the side β€ 1,000
* N β€ 1,000
Input
Input consists of several data sets. In the first line, the number of data set, N is given. Then, N lines follow, each line corresponds to a data set. A data set consists of three integers separated by a single space.
Output
For each data set, print "YES" or "NO".
Example
Input
3
4 3 5
4 3 6
8 8 8
Output
YES
NO
NO
Submitted Solution:
```
n = int(input())
for i in range(n):
tri = input()
tri_list = tri.split()
tri_list.sort()
a = int(tri_list[2]) ** 2
b = int(tri_list[0]) ** 2 + int(tri_list[1]) ** 2
if a == b:
print("YES")
else:
print("NO")
``` | instruction | 0 | 4,946 | 23 | 9,892 |
No | output | 1 | 4,946 | 23 | 9,893 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a β b), that are either each other's immediate neighbors in the circle, or there is number c, such that a and Ρ are immediate neighbors, and b and c are immediate neighbors. As you can easily deduce, in the end Vasya drew 2Β·n arcs.
For example, if the numbers are written in the circle in the order 1, 2, 3, 4, 5 (in the clockwise direction), then the arcs will join pairs of integers (1, 2), (2, 3), (3, 4), (4, 5), (5, 1), (1, 3), (2, 4), (3, 5), (4, 1) and (5, 2).
Much time has passed ever since, the numbers we wiped off the blackboard long ago, but recently Vasya has found a piece of paper with 2Β·n written pairs of integers that were joined with the arcs on the board. Vasya asks you to find the order of numbers in the circle by these pairs.
Input
The first line of the input contains a single integer n (5 β€ n β€ 105) that shows, how many numbers were written on the board. Next 2Β·n lines contain pairs of integers ai, bi (1 β€ ai, bi β€ n, ai β bi) β the numbers that were connected by the arcs.
It is guaranteed that no pair of integers, connected by a arc, occurs in the input more than once. The pairs of numbers and the numbers in the pairs are given in the arbitrary order.
Output
If Vasya made a mistake somewhere and there isn't any way to place numbers from 1 to n on the circle according to the statement, then print a single number "-1" (without the quotes). Otherwise, print any suitable sequence of n distinct integers from 1 to n.
If there are multiple solutions, you are allowed to print any of them. Specifically, it doesn't matter which number you write first to describe the sequence of the order. It also doesn't matter whether you write out the numbers in the clockwise or counter-clockwise direction.
Examples
Input
5
1 2
2 3
3 4
4 5
5 1
1 3
2 4
3 5
4 1
5 2
Output
1 2 3 4 5
Input
6
5 6
4 3
5 3
2 4
6 1
3 1
6 2
2 5
1 4
3 6
1 2
4 5
Output
1 2 4 5 3 6
Submitted Solution:
```
#!/usr/local/bin/python3
from __future__ import print_function
import sys
DEBUG = '-d' in sys.argv
def debug(*args, **kwargs):
if DEBUG:
print(*args, file=sys.stderr, **kwargs)
return None
n = int(input())
cnt = [0] * (n+1)
edge = []
for i in range (0, n + 1):
edge.append(set())
for i in range(0, 2 * n):
s, t = map(int, input().split())
edge[s].add(t)
edge[t].add(s)
cnt[s] += 1
cnt[t] += 1
c4 = 0
for i in range(1, n+1):
if cnt[i] == 4:
c4 += 1
if c4 != n:
print(-1)
else:
def go(i, res, mark):
res.append(i)
mark[i] = False
if len(res) == n:
print(' '.join([str(x) for x in res]))
raise StopIteration
for e in edge[i]:
if e != i and mark[e] and res[-1] in edge[e]:
go(e, res, mark)
return
try:
for v2 in edge[1]:
for v3 in edge[1]:
if v2 in edge[v3]:
mark = [True] * (n + 1)
mark[1] = False
mark[v2] = False
go(v3, [1, v2], mark)
print(-1)
except StopIteration:
pass
``` | instruction | 0 | 5,303 | 23 | 10,606 |
No | output | 1 | 5,303 | 23 | 10,607 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a β b), that are either each other's immediate neighbors in the circle, or there is number c, such that a and Ρ are immediate neighbors, and b and c are immediate neighbors. As you can easily deduce, in the end Vasya drew 2Β·n arcs.
For example, if the numbers are written in the circle in the order 1, 2, 3, 4, 5 (in the clockwise direction), then the arcs will join pairs of integers (1, 2), (2, 3), (3, 4), (4, 5), (5, 1), (1, 3), (2, 4), (3, 5), (4, 1) and (5, 2).
Much time has passed ever since, the numbers we wiped off the blackboard long ago, but recently Vasya has found a piece of paper with 2Β·n written pairs of integers that were joined with the arcs on the board. Vasya asks you to find the order of numbers in the circle by these pairs.
Input
The first line of the input contains a single integer n (5 β€ n β€ 105) that shows, how many numbers were written on the board. Next 2Β·n lines contain pairs of integers ai, bi (1 β€ ai, bi β€ n, ai β bi) β the numbers that were connected by the arcs.
It is guaranteed that no pair of integers, connected by a arc, occurs in the input more than once. The pairs of numbers and the numbers in the pairs are given in the arbitrary order.
Output
If Vasya made a mistake somewhere and there isn't any way to place numbers from 1 to n on the circle according to the statement, then print a single number "-1" (without the quotes). Otherwise, print any suitable sequence of n distinct integers from 1 to n.
If there are multiple solutions, you are allowed to print any of them. Specifically, it doesn't matter which number you write first to describe the sequence of the order. It also doesn't matter whether you write out the numbers in the clockwise or counter-clockwise direction.
Examples
Input
5
1 2
2 3
3 4
4 5
5 1
1 3
2 4
3 5
4 1
5 2
Output
1 2 3 4 5
Input
6
5 6
4 3
5 3
2 4
6 1
3 1
6 2
2 5
1 4
3 6
1 2
4 5
Output
1 2 4 5 3 6
Submitted Solution:
```
input=__import__('sys').stdin.readline
n=int(input())
if n==5:exit(print(1,2,3,4,5))
ans=[1]
g=[set()for _ in range(n+1)]
vis=[1]*(n+1)
for _ in range(n*2):a,b=map(int,input().split());g[a].add(b);g[b].add(a)
for _ in range(n-1):
for i in g[ans[-1]]:
c=g[ans[-1]]&g[i]
if len(c)==2and not(_ and ans[-2]not in c)and vis[i]:ans.append(i);vis[i]=0;break
if len(ans)==n:print(*ans)
else:print(-1)
``` | instruction | 0 | 5,304 | 23 | 10,608 |
No | output | 1 | 5,304 | 23 | 10,609 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a β b), that are either each other's immediate neighbors in the circle, or there is number c, such that a and Ρ are immediate neighbors, and b and c are immediate neighbors. As you can easily deduce, in the end Vasya drew 2Β·n arcs.
For example, if the numbers are written in the circle in the order 1, 2, 3, 4, 5 (in the clockwise direction), then the arcs will join pairs of integers (1, 2), (2, 3), (3, 4), (4, 5), (5, 1), (1, 3), (2, 4), (3, 5), (4, 1) and (5, 2).
Much time has passed ever since, the numbers we wiped off the blackboard long ago, but recently Vasya has found a piece of paper with 2Β·n written pairs of integers that were joined with the arcs on the board. Vasya asks you to find the order of numbers in the circle by these pairs.
Input
The first line of the input contains a single integer n (5 β€ n β€ 105) that shows, how many numbers were written on the board. Next 2Β·n lines contain pairs of integers ai, bi (1 β€ ai, bi β€ n, ai β bi) β the numbers that were connected by the arcs.
It is guaranteed that no pair of integers, connected by a arc, occurs in the input more than once. The pairs of numbers and the numbers in the pairs are given in the arbitrary order.
Output
If Vasya made a mistake somewhere and there isn't any way to place numbers from 1 to n on the circle according to the statement, then print a single number "-1" (without the quotes). Otherwise, print any suitable sequence of n distinct integers from 1 to n.
If there are multiple solutions, you are allowed to print any of them. Specifically, it doesn't matter which number you write first to describe the sequence of the order. It also doesn't matter whether you write out the numbers in the clockwise or counter-clockwise direction.
Examples
Input
5
1 2
2 3
3 4
4 5
5 1
1 3
2 4
3 5
4 1
5 2
Output
1 2 3 4 5
Input
6
5 6
4 3
5 3
2 4
6 1
3 1
6 2
2 5
1 4
3 6
1 2
4 5
Output
1 2 4 5 3 6
Submitted Solution:
```
from sys import stdin, stdout, stderr
import sys
inints=lambda: [int(x) for x in stdin.readline().split()]
fastwrite=lambda s: stdout.write( str(s) + "\n" )
fasterr=lambda s: stderr.write( str(s) + "\n" )
irange=lambda x,y: range(x, y+1)
####
def adj(x):
d=[0]*(n+1)
for i in g[x]:
for j in g[i]:
if j in g[x] and j not in result:
d[j]+=1
return d.index(max(d))
fasterr("please input")
n,=inints()
g=[ [] for i in range(n+1) ]
result=[0]*n
for i in range(2*n):
a,b=inints()
g[a].append(b)
g[b].append(a)
if n==5:
for i in irange(1,5):
stdout.write(str(i)+" ")
sys.exit()
elif n==6:
disconnected=0
for i in irange(2,6):
if i not in g[1]:
disconnected=i
break
r=[i for i in irange(1,6)]
x=r.index(disconnected)
r[3],r[x]=r[x],r[3]
if r[1] not in g[r[2]]:
r[2],r[4]=r[4],r[2]
for i in r:
stdout.write(str(i)+" ")
sys.exit()
for i in range(n):
result[i]=adj( 1 if i==0 else result[i-1] )
for i in result:
stdout.write(str(i)+" ")
``` | instruction | 0 | 5,305 | 23 | 10,610 |
No | output | 1 | 5,305 | 23 | 10,611 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a β b), that are either each other's immediate neighbors in the circle, or there is number c, such that a and Ρ are immediate neighbors, and b and c are immediate neighbors. As you can easily deduce, in the end Vasya drew 2Β·n arcs.
For example, if the numbers are written in the circle in the order 1, 2, 3, 4, 5 (in the clockwise direction), then the arcs will join pairs of integers (1, 2), (2, 3), (3, 4), (4, 5), (5, 1), (1, 3), (2, 4), (3, 5), (4, 1) and (5, 2).
Much time has passed ever since, the numbers we wiped off the blackboard long ago, but recently Vasya has found a piece of paper with 2Β·n written pairs of integers that were joined with the arcs on the board. Vasya asks you to find the order of numbers in the circle by these pairs.
Input
The first line of the input contains a single integer n (5 β€ n β€ 105) that shows, how many numbers were written on the board. Next 2Β·n lines contain pairs of integers ai, bi (1 β€ ai, bi β€ n, ai β bi) β the numbers that were connected by the arcs.
It is guaranteed that no pair of integers, connected by a arc, occurs in the input more than once. The pairs of numbers and the numbers in the pairs are given in the arbitrary order.
Output
If Vasya made a mistake somewhere and there isn't any way to place numbers from 1 to n on the circle according to the statement, then print a single number "-1" (without the quotes). Otherwise, print any suitable sequence of n distinct integers from 1 to n.
If there are multiple solutions, you are allowed to print any of them. Specifically, it doesn't matter which number you write first to describe the sequence of the order. It also doesn't matter whether you write out the numbers in the clockwise or counter-clockwise direction.
Examples
Input
5
1 2
2 3
3 4
4 5
5 1
1 3
2 4
3 5
4 1
5 2
Output
1 2 3 4 5
Input
6
5 6
4 3
5 3
2 4
6 1
3 1
6 2
2 5
1 4
3 6
1 2
4 5
Output
1 2 4 5 3 6
Submitted Solution:
```
n = int(input())
e = {x + 1: [] for x in range(n)}
for _ in range(n * 2):
s, r = list(map(int, input().split()))
e[s] += [r]
e[r] += [s]
variants = [[1]]
for _ in range(n - 1):
newVariants = []
for mas in variants:
lastE = mas[len(mas) - 1]
l = e[lastE][0]
r = e[lastE][1]
mas1 = mas
mas2 = mas
if not (l in mas1):
mas1 = mas + [l]
if not (r in mas2):
mas2 = mas + [r]
newVariants += [mas1]
newVariants += [mas2]
l1 = e[lastE][2]
r2 = e[lastE][3]
mas3 = mas
mas4 = mas
if not (l1 in mas3):
mas3 = mas + [l1]
if not (r2 in mas4):
mas6 = mas + [r2]
newVariants += [mas3]
newVariants += [mas4]
variants = newVariants
res = []
for mas in variants:
lastE = mas[len(mas) - 1]
if len(mas) == n and (1 in e[lastE]):
res = mas
if len(res) == n:
print(" ".join(str(x) for x in res))
else:
print(-1)
``` | instruction | 0 | 5,306 | 23 | 10,612 |
No | output | 1 | 5,306 | 23 | 10,613 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework.
The teacher gave Seryozha the coordinates of n distinct points on the abscissa axis and asked to consecutively connect them by semi-circus in a certain order: first connect the first point with the second one, then connect the second point with the third one, then the third one with the fourth one and so on to the n-th point. Two points with coordinates (x1, 0) and (x2, 0) should be connected by a semi-circle that passes above the abscissa axis with the diameter that coincides with the segment between points. Seryozha needs to find out if the line on the picture intersects itself. For clarifications, see the picture Seryozha showed to Dima (the left picture has self-intersections, the right picture doesn't have any).
<image>
Seryozha is not a small boy, so the coordinates of the points can be rather large. Help Dima cope with the problem.
Input
The first line contains a single integer n (1 β€ n β€ 103). The second line contains n distinct integers x1, x2, ..., xn ( - 106 β€ xi β€ 106) β the i-th point has coordinates (xi, 0). The points are not necessarily sorted by their x coordinate.
Output
In the single line print "yes" (without the quotes), if the line has self-intersections. Otherwise, print "no" (without the quotes).
Examples
Input
4
0 10 5 15
Output
yes
Input
4
0 15 5 10
Output
no
Note
The first test from the statement is on the picture to the left, the second test is on the picture to the right. | instruction | 0 | 5,355 | 23 | 10,710 |
Tags: brute force, implementation
Correct Solution:
```
n = int(input())
seq = list(map(int, input().split()))
if n == 1:
print("no")
exit(0)
pairs = []
cur = [-1, seq[0]]
fail = False
for i in range(1, len(seq)):
cur[0], cur[1] = cur[1], seq[i]
if cur[1] < cur[0]:
pairs.append([cur[1], cur[0]])
else:
pairs.append(cur[:])
#print(pairs)
for x1, x2 in pairs:
if not fail:
for x3, x4 in pairs:
if (x1 != x3 or x2 != x4) and (x1 < x3 < x2 < x4 or x3 < x1 < x4 < x2):
fail = True
break
else:
break
if fail:
print("yes")
else:
print("no")
``` | output | 1 | 5,355 | 23 | 10,711 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework.
The teacher gave Seryozha the coordinates of n distinct points on the abscissa axis and asked to consecutively connect them by semi-circus in a certain order: first connect the first point with the second one, then connect the second point with the third one, then the third one with the fourth one and so on to the n-th point. Two points with coordinates (x1, 0) and (x2, 0) should be connected by a semi-circle that passes above the abscissa axis with the diameter that coincides with the segment between points. Seryozha needs to find out if the line on the picture intersects itself. For clarifications, see the picture Seryozha showed to Dima (the left picture has self-intersections, the right picture doesn't have any).
<image>
Seryozha is not a small boy, so the coordinates of the points can be rather large. Help Dima cope with the problem.
Input
The first line contains a single integer n (1 β€ n β€ 103). The second line contains n distinct integers x1, x2, ..., xn ( - 106 β€ xi β€ 106) β the i-th point has coordinates (xi, 0). The points are not necessarily sorted by their x coordinate.
Output
In the single line print "yes" (without the quotes), if the line has self-intersections. Otherwise, print "no" (without the quotes).
Examples
Input
4
0 10 5 15
Output
yes
Input
4
0 15 5 10
Output
no
Note
The first test from the statement is on the picture to the left, the second test is on the picture to the right. | instruction | 0 | 5,356 | 23 | 10,712 |
Tags: brute force, implementation
Correct Solution:
```
n = int(input())
Min = -1e10
Max = 1e10
ans = "no"
def f(x, y):
return x[0] < y[0] < x[1] < y[1] or \
y[0] < x[0] < y[1] < x[1]
xs = list(map(int, input().split()))
for i in range(1, len(xs) - 1):
for j in range(0, i):
if f([min(xs[i:i+2]), max(xs[i:i+2])], [min(xs[j:j+2]), max(xs[j:j+2])]):
ans = "yes"
break
print(ans)
``` | output | 1 | 5,356 | 23 | 10,713 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework.
The teacher gave Seryozha the coordinates of n distinct points on the abscissa axis and asked to consecutively connect them by semi-circus in a certain order: first connect the first point with the second one, then connect the second point with the third one, then the third one with the fourth one and so on to the n-th point. Two points with coordinates (x1, 0) and (x2, 0) should be connected by a semi-circle that passes above the abscissa axis with the diameter that coincides with the segment between points. Seryozha needs to find out if the line on the picture intersects itself. For clarifications, see the picture Seryozha showed to Dima (the left picture has self-intersections, the right picture doesn't have any).
<image>
Seryozha is not a small boy, so the coordinates of the points can be rather large. Help Dima cope with the problem.
Input
The first line contains a single integer n (1 β€ n β€ 103). The second line contains n distinct integers x1, x2, ..., xn ( - 106 β€ xi β€ 106) β the i-th point has coordinates (xi, 0). The points are not necessarily sorted by their x coordinate.
Output
In the single line print "yes" (without the quotes), if the line has self-intersections. Otherwise, print "no" (without the quotes).
Examples
Input
4
0 10 5 15
Output
yes
Input
4
0 15 5 10
Output
no
Note
The first test from the statement is on the picture to the left, the second test is on the picture to the right. | instruction | 0 | 5,357 | 23 | 10,714 |
Tags: brute force, implementation
Correct Solution:
```
n,l=int(input()),list(map(int,input().split()))
for i in range(n-1):
for j in range(n-1):
x=sorted([l[i],l[i+1]])+sorted([l[j],l[j+1]])
if x[0]<x[2]<x[1]<x[3]:
exit(print('yes'))
print('no')
``` | output | 1 | 5,357 | 23 | 10,715 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework.
The teacher gave Seryozha the coordinates of n distinct points on the abscissa axis and asked to consecutively connect them by semi-circus in a certain order: first connect the first point with the second one, then connect the second point with the third one, then the third one with the fourth one and so on to the n-th point. Two points with coordinates (x1, 0) and (x2, 0) should be connected by a semi-circle that passes above the abscissa axis with the diameter that coincides with the segment between points. Seryozha needs to find out if the line on the picture intersects itself. For clarifications, see the picture Seryozha showed to Dima (the left picture has self-intersections, the right picture doesn't have any).
<image>
Seryozha is not a small boy, so the coordinates of the points can be rather large. Help Dima cope with the problem.
Input
The first line contains a single integer n (1 β€ n β€ 103). The second line contains n distinct integers x1, x2, ..., xn ( - 106 β€ xi β€ 106) β the i-th point has coordinates (xi, 0). The points are not necessarily sorted by their x coordinate.
Output
In the single line print "yes" (without the quotes), if the line has self-intersections. Otherwise, print "no" (without the quotes).
Examples
Input
4
0 10 5 15
Output
yes
Input
4
0 15 5 10
Output
no
Note
The first test from the statement is on the picture to the left, the second test is on the picture to the right. | instruction | 0 | 5,358 | 23 | 10,716 |
Tags: brute force, implementation
Correct Solution:
```
def self_intersect(points:list):
for i in range(len(points)):
check_point = points[i]
for j in range(len(points)):
if i != j:
check_point2 = points[j]
if check_point[0] < check_point2[0] < check_point[1] < check_point2[1]:
return True
if check_point2[0] < check_point[0] < check_point2[1] < check_point[1]:
return True
return False
n = int(input())
points = list(map(int,input().split(' ')))
semi_circles = []
for i in range(0,len(points)-1):
if points[i] < points[i+1]:
semi_circles.append([points[i],points[i+1]])
else:
semi_circles.append([points[i+1],points[i]])
if self_intersect(semi_circles):
print("yes")
else:
print("no")
``` | output | 1 | 5,358 | 23 | 10,717 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework.
The teacher gave Seryozha the coordinates of n distinct points on the abscissa axis and asked to consecutively connect them by semi-circus in a certain order: first connect the first point with the second one, then connect the second point with the third one, then the third one with the fourth one and so on to the n-th point. Two points with coordinates (x1, 0) and (x2, 0) should be connected by a semi-circle that passes above the abscissa axis with the diameter that coincides with the segment between points. Seryozha needs to find out if the line on the picture intersects itself. For clarifications, see the picture Seryozha showed to Dima (the left picture has self-intersections, the right picture doesn't have any).
<image>
Seryozha is not a small boy, so the coordinates of the points can be rather large. Help Dima cope with the problem.
Input
The first line contains a single integer n (1 β€ n β€ 103). The second line contains n distinct integers x1, x2, ..., xn ( - 106 β€ xi β€ 106) β the i-th point has coordinates (xi, 0). The points are not necessarily sorted by their x coordinate.
Output
In the single line print "yes" (without the quotes), if the line has self-intersections. Otherwise, print "no" (without the quotes).
Examples
Input
4
0 10 5 15
Output
yes
Input
4
0 15 5 10
Output
no
Note
The first test from the statement is on the picture to the left, the second test is on the picture to the right. | instruction | 0 | 5,359 | 23 | 10,718 |
Tags: brute force, implementation
Correct Solution:
```
n = int(input())
arr = list(map(int, input().split()))
flag = 0
for i in range(n-1):
for j in range(i+1,n-1):
a,b = min(arr[i],arr[i+1]),max(arr[i],arr[i+1])
c,d = min(arr[j],arr[j+1]),max(arr[j],arr[j+1])
if a<c<b<d or c<a<d<b:
flag=1
break
if flag==1:
break
if flag==0:
print("no")
else:
print("yes")
``` | output | 1 | 5,359 | 23 | 10,719 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework.
The teacher gave Seryozha the coordinates of n distinct points on the abscissa axis and asked to consecutively connect them by semi-circus in a certain order: first connect the first point with the second one, then connect the second point with the third one, then the third one with the fourth one and so on to the n-th point. Two points with coordinates (x1, 0) and (x2, 0) should be connected by a semi-circle that passes above the abscissa axis with the diameter that coincides with the segment between points. Seryozha needs to find out if the line on the picture intersects itself. For clarifications, see the picture Seryozha showed to Dima (the left picture has self-intersections, the right picture doesn't have any).
<image>
Seryozha is not a small boy, so the coordinates of the points can be rather large. Help Dima cope with the problem.
Input
The first line contains a single integer n (1 β€ n β€ 103). The second line contains n distinct integers x1, x2, ..., xn ( - 106 β€ xi β€ 106) β the i-th point has coordinates (xi, 0). The points are not necessarily sorted by their x coordinate.
Output
In the single line print "yes" (without the quotes), if the line has self-intersections. Otherwise, print "no" (without the quotes).
Examples
Input
4
0 10 5 15
Output
yes
Input
4
0 15 5 10
Output
no
Note
The first test from the statement is on the picture to the left, the second test is on the picture to the right. | instruction | 0 | 5,360 | 23 | 10,720 |
Tags: brute force, implementation
Correct Solution:
```
def intersect(p1,p2):
if (p2[0] < p1[1] and p2[0] > p1[0] and p2[1] > p1[1]) or (p2[1] < p1[1] and p2[1] > p1[0] and p2[0] < p1[0]):
return True
return False
def check(points):
for x in range(len(points)):
for i in range(x + 1,len(points)):
if intersect(points[x],points[i]): return "yes"
return "no"
n = int(input())
temp_in = [int(x) for x in input().split(' ')]
points = []
for x in range(n - 1):
points.append((min(temp_in[x],temp_in[x + 1]),max(temp_in[x],temp_in[x + 1])))
#print(points)
print(check(points)) #chyba przypadek z tym ze wspolrzedne pozniej sa mniejsze i wtedy warunek nie wchodzi na przeciecie
'''
2
0 15 13 20
ans: yes
semicircles will intersect with each other in one case:
begininning of the second one will be earlier than ending of the first.
and there will be no subcircle (circle which is included in the one above)
brute force O(N^2+N / 2)
'''
``` | output | 1 | 5,360 | 23 | 10,721 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework.
The teacher gave Seryozha the coordinates of n distinct points on the abscissa axis and asked to consecutively connect them by semi-circus in a certain order: first connect the first point with the second one, then connect the second point with the third one, then the third one with the fourth one and so on to the n-th point. Two points with coordinates (x1, 0) and (x2, 0) should be connected by a semi-circle that passes above the abscissa axis with the diameter that coincides with the segment between points. Seryozha needs to find out if the line on the picture intersects itself. For clarifications, see the picture Seryozha showed to Dima (the left picture has self-intersections, the right picture doesn't have any).
<image>
Seryozha is not a small boy, so the coordinates of the points can be rather large. Help Dima cope with the problem.
Input
The first line contains a single integer n (1 β€ n β€ 103). The second line contains n distinct integers x1, x2, ..., xn ( - 106 β€ xi β€ 106) β the i-th point has coordinates (xi, 0). The points are not necessarily sorted by their x coordinate.
Output
In the single line print "yes" (without the quotes), if the line has self-intersections. Otherwise, print "no" (without the quotes).
Examples
Input
4
0 10 5 15
Output
yes
Input
4
0 15 5 10
Output
no
Note
The first test from the statement is on the picture to the left, the second test is on the picture to the right. | instruction | 0 | 5,361 | 23 | 10,722 |
Tags: brute force, implementation
Correct Solution:
```
#http://codeforces.com/problemset/problem/358/A
#not accepted
n = eval(input())
points = [(int)(i) for i in input().split()]
poles = []
'''
left = 0
right = 0
prevDir = '-'
currentDir = '-'
'''
def is_intersect(points):
if(n <= 2):
return False;
global poles
poles.append([points[0],points[1]])
for i in range(2,n):
prevPoint = points[i-1]
currentPoint = points[i]
for pole in poles:
_min = min(pole[0],pole[1])
_max = max(pole[0],pole[1])
if (prevPoint in range(_min+1,_max) and\
currentPoint not in range(_min,_max+1)) or\
(currentPoint in range(_min+1,_max) and\
prevPoint not in range(_min,_max+1)):
return True
poles.append([prevPoint,currentPoint]);
return False
'''
global right
global left
global prevDir
global currentDir
left = min(points[0],points[1])
right = max(points[0],points[1])
prevDir = points[1] > points[0] if 'right' else 'left'
currentDir = '-'
for i in range(2,n):
prevPoint = points[i-1]
currentPoint = points[i]
currentDir = currentPoint > prevPoint if 'right' else 'left'
if prevDir == currentDir:
if currentDir == 'left':
right = prevPoint;
left = currentPoint;
elif currentDir == 'right':
right = currentPoint
left = prevPoint
else:
pass
prevDir = currentDir
return False
'''
if is_intersect(points):
print('yes')
else:
print('no')
``` | output | 1 | 5,361 | 23 | 10,723 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework.
The teacher gave Seryozha the coordinates of n distinct points on the abscissa axis and asked to consecutively connect them by semi-circus in a certain order: first connect the first point with the second one, then connect the second point with the third one, then the third one with the fourth one and so on to the n-th point. Two points with coordinates (x1, 0) and (x2, 0) should be connected by a semi-circle that passes above the abscissa axis with the diameter that coincides with the segment between points. Seryozha needs to find out if the line on the picture intersects itself. For clarifications, see the picture Seryozha showed to Dima (the left picture has self-intersections, the right picture doesn't have any).
<image>
Seryozha is not a small boy, so the coordinates of the points can be rather large. Help Dima cope with the problem.
Input
The first line contains a single integer n (1 β€ n β€ 103). The second line contains n distinct integers x1, x2, ..., xn ( - 106 β€ xi β€ 106) β the i-th point has coordinates (xi, 0). The points are not necessarily sorted by their x coordinate.
Output
In the single line print "yes" (without the quotes), if the line has self-intersections. Otherwise, print "no" (without the quotes).
Examples
Input
4
0 10 5 15
Output
yes
Input
4
0 15 5 10
Output
no
Note
The first test from the statement is on the picture to the left, the second test is on the picture to the right. | instruction | 0 | 5,362 | 23 | 10,724 |
Tags: brute force, implementation
Correct Solution:
```
n = int(input())
x = [int(i) for i in input().split()]
if (n < 3):
print ('no')
else:
ans = 'no'
for i in range(3, n):
prev = x[i - 1]
num = x[i]
for j in range(i - 2):
num1 = min(x[j], x[j + 1])
num2 = max(x[j], x[j + 1])
if (prev < num1 or prev > num2) and (num > num1 and num < num2):
ans = 'yes'
break
elif ((num < num1 or num > num2) and (prev > num1 and prev < num2)):
ans = 'yes'
break
print (ans)
``` | output | 1 | 5,362 | 23 | 10,725 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework.
The teacher gave Seryozha the coordinates of n distinct points on the abscissa axis and asked to consecutively connect them by semi-circus in a certain order: first connect the first point with the second one, then connect the second point with the third one, then the third one with the fourth one and so on to the n-th point. Two points with coordinates (x1, 0) and (x2, 0) should be connected by a semi-circle that passes above the abscissa axis with the diameter that coincides with the segment between points. Seryozha needs to find out if the line on the picture intersects itself. For clarifications, see the picture Seryozha showed to Dima (the left picture has self-intersections, the right picture doesn't have any).
<image>
Seryozha is not a small boy, so the coordinates of the points can be rather large. Help Dima cope with the problem.
Input
The first line contains a single integer n (1 β€ n β€ 103). The second line contains n distinct integers x1, x2, ..., xn ( - 106 β€ xi β€ 106) β the i-th point has coordinates (xi, 0). The points are not necessarily sorted by their x coordinate.
Output
In the single line print "yes" (without the quotes), if the line has self-intersections. Otherwise, print "no" (without the quotes).
Examples
Input
4
0 10 5 15
Output
yes
Input
4
0 15 5 10
Output
no
Note
The first test from the statement is on the picture to the left, the second test is on the picture to the right.
Submitted Solution:
```
n=int(input())
l=list(map(int,input().split()))
maxx=l[0]
minn=l[0]
for i in range(0,n-1):
if l[i+1]>l[i]:
if l[i]>minn and l[i]<maxx and l[i+1]>maxx:
print("yes")
exit()
elif l[i]<minn and l[i+1]>minn and l[i+1]<maxx :
print("yes")
exit()
else:
if l[i]>maxx:
maxx=l[i]
if l[i]<minn:
minn=l[i]
elif l[i+1]<l[i]:
if l[i+1]>minn and l[i+1]<maxx and l[i]>maxx:
print("yes")
exit()
elif l[i+1]<minn and l[i]>minn and l[i]<maxx:
print("yes")
exit()
else:
if l[i]>maxx:
maxx=l[i]
if l[i]<minn:
minn=l[i]
print("no")
``` | instruction | 0 | 5,363 | 23 | 10,726 |
Yes | output | 1 | 5,363 | 23 | 10,727 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework.
The teacher gave Seryozha the coordinates of n distinct points on the abscissa axis and asked to consecutively connect them by semi-circus in a certain order: first connect the first point with the second one, then connect the second point with the third one, then the third one with the fourth one and so on to the n-th point. Two points with coordinates (x1, 0) and (x2, 0) should be connected by a semi-circle that passes above the abscissa axis with the diameter that coincides with the segment between points. Seryozha needs to find out if the line on the picture intersects itself. For clarifications, see the picture Seryozha showed to Dima (the left picture has self-intersections, the right picture doesn't have any).
<image>
Seryozha is not a small boy, so the coordinates of the points can be rather large. Help Dima cope with the problem.
Input
The first line contains a single integer n (1 β€ n β€ 103). The second line contains n distinct integers x1, x2, ..., xn ( - 106 β€ xi β€ 106) β the i-th point has coordinates (xi, 0). The points are not necessarily sorted by their x coordinate.
Output
In the single line print "yes" (without the quotes), if the line has self-intersections. Otherwise, print "no" (without the quotes).
Examples
Input
4
0 10 5 15
Output
yes
Input
4
0 15 5 10
Output
no
Note
The first test from the statement is on the picture to the left, the second test is on the picture to the right.
Submitted Solution:
```
'''
Created on Oct 31, 2013
@author: Ismael
'''
def main():
input()
l = list(map(int,input().split()))
#l = [0,10,5,15]
#l = [0,15,5,10]
if(len(l)<=3):
print("no")
return
xMin = min(l[0],l[1])
xMax = max(l[0],l[1])
for i in range(2,len(l)-1):
if(l[i]<=xMin or l[i]>=xMax):#3eme ext, next point must be outside [xMin,xMax]
if(l[i+1]>xMin and l[i+1]<xMax):
print("yes")
return
elif(l[i]>=xMin and l[i]<=xMax):#3eme int, next point must be inside [xMin,xMax]
if(l[i+1]<xMin or l[i+1]>xMax):
print("yes")
return
min123 = min(xMin,l[i])
max123 = max(xMax,l[i])
if(l[i+1]<min123 or l[i+1]>max123):
xMin = min123
xMax = max123
else:
elems = [l[i+1],xMin,xMax,l[i]]
elems.sort()
ind4 = elems.index(l[i+1])
xMin = elems[ind4-1]
xMax = elems[ind4+1]
print("no")
main()
``` | instruction | 0 | 5,364 | 23 | 10,728 |
Yes | output | 1 | 5,364 | 23 | 10,729 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework.
The teacher gave Seryozha the coordinates of n distinct points on the abscissa axis and asked to consecutively connect them by semi-circus in a certain order: first connect the first point with the second one, then connect the second point with the third one, then the third one with the fourth one and so on to the n-th point. Two points with coordinates (x1, 0) and (x2, 0) should be connected by a semi-circle that passes above the abscissa axis with the diameter that coincides with the segment between points. Seryozha needs to find out if the line on the picture intersects itself. For clarifications, see the picture Seryozha showed to Dima (the left picture has self-intersections, the right picture doesn't have any).
<image>
Seryozha is not a small boy, so the coordinates of the points can be rather large. Help Dima cope with the problem.
Input
The first line contains a single integer n (1 β€ n β€ 103). The second line contains n distinct integers x1, x2, ..., xn ( - 106 β€ xi β€ 106) β the i-th point has coordinates (xi, 0). The points are not necessarily sorted by their x coordinate.
Output
In the single line print "yes" (without the quotes), if the line has self-intersections. Otherwise, print "no" (without the quotes).
Examples
Input
4
0 10 5 15
Output
yes
Input
4
0 15 5 10
Output
no
Note
The first test from the statement is on the picture to the left, the second test is on the picture to the right.
Submitted Solution:
```
n = int(input())
a = [int(y) for y in input().split()]
flag = 0
for i in range(len(a)-2):
for j in range(i, 0, -1):
r = min(a[j], a[j-1])
s = max(a[j], a[j-1])
if (a[i+2] > r and a[i+2] < s) and (a[i+1] > s or a[i+1] < r):
flag += 1
break
elif (a[i+1] > r and a[i+1] < s) and (a[i+2] > s or a[i+2] < r):
flag += 1
break
if(flag == 0):
print("no")
else:
print("yes")
``` | instruction | 0 | 5,365 | 23 | 10,730 |
Yes | output | 1 | 5,365 | 23 | 10,731 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework.
The teacher gave Seryozha the coordinates of n distinct points on the abscissa axis and asked to consecutively connect them by semi-circus in a certain order: first connect the first point with the second one, then connect the second point with the third one, then the third one with the fourth one and so on to the n-th point. Two points with coordinates (x1, 0) and (x2, 0) should be connected by a semi-circle that passes above the abscissa axis with the diameter that coincides with the segment between points. Seryozha needs to find out if the line on the picture intersects itself. For clarifications, see the picture Seryozha showed to Dima (the left picture has self-intersections, the right picture doesn't have any).
<image>
Seryozha is not a small boy, so the coordinates of the points can be rather large. Help Dima cope with the problem.
Input
The first line contains a single integer n (1 β€ n β€ 103). The second line contains n distinct integers x1, x2, ..., xn ( - 106 β€ xi β€ 106) β the i-th point has coordinates (xi, 0). The points are not necessarily sorted by their x coordinate.
Output
In the single line print "yes" (without the quotes), if the line has self-intersections. Otherwise, print "no" (without the quotes).
Examples
Input
4
0 10 5 15
Output
yes
Input
4
0 15 5 10
Output
no
Note
The first test from the statement is on the picture to the left, the second test is on the picture to the right.
Submitted Solution:
```
def take_input(s): #for integer inputs
if s == 1: return int(input())
return map(int, input().split())
n = take_input(1)
if n == 1: print("no"); exit()
a = list(take_input(n))
flag = 0
for i in range(1,n-1):
for j in range(i):
init_1 = min(a[i],a[i+1]); fin_1 = max(a[i],a[i+1])
init_2 = min(a[j],a[j+1]); fin_2 = max(a[j],a[j+1])
if ((init_1 > init_2 and init_1 < fin_2 and fin_1 > fin_2) or (init_1 < init_2 and fin_1 > init_2 and fin_1<fin_2)) and flag == 0:
print("yes")
flag = 1
break
if flag == 0:
print("no")
``` | instruction | 0 | 5,366 | 23 | 10,732 |
Yes | output | 1 | 5,366 | 23 | 10,733 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework.
The teacher gave Seryozha the coordinates of n distinct points on the abscissa axis and asked to consecutively connect them by semi-circus in a certain order: first connect the first point with the second one, then connect the second point with the third one, then the third one with the fourth one and so on to the n-th point. Two points with coordinates (x1, 0) and (x2, 0) should be connected by a semi-circle that passes above the abscissa axis with the diameter that coincides with the segment between points. Seryozha needs to find out if the line on the picture intersects itself. For clarifications, see the picture Seryozha showed to Dima (the left picture has self-intersections, the right picture doesn't have any).
<image>
Seryozha is not a small boy, so the coordinates of the points can be rather large. Help Dima cope with the problem.
Input
The first line contains a single integer n (1 β€ n β€ 103). The second line contains n distinct integers x1, x2, ..., xn ( - 106 β€ xi β€ 106) β the i-th point has coordinates (xi, 0). The points are not necessarily sorted by their x coordinate.
Output
In the single line print "yes" (without the quotes), if the line has self-intersections. Otherwise, print "no" (without the quotes).
Examples
Input
4
0 10 5 15
Output
yes
Input
4
0 15 5 10
Output
no
Note
The first test from the statement is on the picture to the left, the second test is on the picture to the right.
Submitted Solution:
```
n = int(input().strip())
points = list(map(int, input().strip().split()))
val = True
for i in range(n - 1):
if points[i] > points[i+1]:
if points[i] < max(points[i+1:]):
val = False
break
if val:
print("no")
else:
print("yes")
``` | instruction | 0 | 5,367 | 23 | 10,734 |
No | output | 1 | 5,367 | 23 | 10,735 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework.
The teacher gave Seryozha the coordinates of n distinct points on the abscissa axis and asked to consecutively connect them by semi-circus in a certain order: first connect the first point with the second one, then connect the second point with the third one, then the third one with the fourth one and so on to the n-th point. Two points with coordinates (x1, 0) and (x2, 0) should be connected by a semi-circle that passes above the abscissa axis with the diameter that coincides with the segment between points. Seryozha needs to find out if the line on the picture intersects itself. For clarifications, see the picture Seryozha showed to Dima (the left picture has self-intersections, the right picture doesn't have any).
<image>
Seryozha is not a small boy, so the coordinates of the points can be rather large. Help Dima cope with the problem.
Input
The first line contains a single integer n (1 β€ n β€ 103). The second line contains n distinct integers x1, x2, ..., xn ( - 106 β€ xi β€ 106) β the i-th point has coordinates (xi, 0). The points are not necessarily sorted by their x coordinate.
Output
In the single line print "yes" (without the quotes), if the line has self-intersections. Otherwise, print "no" (without the quotes).
Examples
Input
4
0 10 5 15
Output
yes
Input
4
0 15 5 10
Output
no
Note
The first test from the statement is on the picture to the left, the second test is on the picture to the right.
Submitted Solution:
```
n = int(input())
pos = [int(k) for k in input().split()]
sigue = True
if len(pos)>2:
for i in range(len(pos)-2):
x1 = pos[i]
x2 = pos[i+1]
for k in range(i+2,len(pos)-1):
x3 = pos[k]
x4 = pos[k+1]
if x1<x3<x2<x4 or x3<x1<x4<x2 or x1<x4<x2<x3 or x4<x1<x3<x2:
print("yes")
sigue = False
break
if not sigue:
break
if sigue:
print("no")
``` | instruction | 0 | 5,368 | 23 | 10,736 |
No | output | 1 | 5,368 | 23 | 10,737 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework.
The teacher gave Seryozha the coordinates of n distinct points on the abscissa axis and asked to consecutively connect them by semi-circus in a certain order: first connect the first point with the second one, then connect the second point with the third one, then the third one with the fourth one and so on to the n-th point. Two points with coordinates (x1, 0) and (x2, 0) should be connected by a semi-circle that passes above the abscissa axis with the diameter that coincides with the segment between points. Seryozha needs to find out if the line on the picture intersects itself. For clarifications, see the picture Seryozha showed to Dima (the left picture has self-intersections, the right picture doesn't have any).
<image>
Seryozha is not a small boy, so the coordinates of the points can be rather large. Help Dima cope with the problem.
Input
The first line contains a single integer n (1 β€ n β€ 103). The second line contains n distinct integers x1, x2, ..., xn ( - 106 β€ xi β€ 106) β the i-th point has coordinates (xi, 0). The points are not necessarily sorted by their x coordinate.
Output
In the single line print "yes" (without the quotes), if the line has self-intersections. Otherwise, print "no" (without the quotes).
Examples
Input
4
0 10 5 15
Output
yes
Input
4
0 15 5 10
Output
no
Note
The first test from the statement is on the picture to the left, the second test is on the picture to the right.
Submitted Solution:
```
import sys
import math
import itertools
import collections
def getdict(n):
d = {}
if type(n) is list or type(n) is str:
for i in n:
if i in d:
d[i] += 1
else:
d[i] = 1
else:
for i in range(n):
t = ii()
if t in d:
d[t] += 1
else:
d[t] = 1
return d
def divs(n, start=1):
r = []
for i in range(start, int(math.sqrt(n) + 1)):
if (n % i == 0):
if (n / i == i):
r.append(i)
else:
r.extend([i, n // i])
return r
def cdiv(n, k): return n // k + (n % k != 0)
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return list(map(int, input().split()))
def lcm(a, b): return abs(a*b) // math.gcd(a, b)
def wr(arr): return '\n'.join(map(str, arr))
def revn(n): return int(str(n)[::-1])
def prime(n):
if n == 2: return True
if n % 2 == 0 or n <= 1: return False
sqr = int(math.sqrt(n)) + 1
for d in range(3, sqr, 2):
if n % d == 0: return False
return True
n = ii()
x = li()
if n < 4:
print('yes')
else:
mnx = min(x)
mxx = max(x)
if x[0] == mnx and x[1] == mxx:
lp, rp = mnx, mxx
for i in range(2, n):
if i % 2 == 0:
if lp < x[i] and x[i] < rp:
lp = x[i]
else:
exit(print('yes'))
else:
if lp < x[i] and x[i] < rp:
rp = x[i]
else:
exit(print('yes'))
elif x[0] == mxx and x[1] == mnx:
lp, rp = mnx, mxx
for i in range(2, n):
if i % 2 == 0:
if lp < x[i] and x[i] < rp:
rp = x[i]
else:
exit(print('yes'))
else:
if lp < x[i] and x[i] < rp:
lp = x[i]
else:
exit(print('yes'))
elif x[1] < x[0]:
lp, rp = x[1], x[0]
for i in range(2, n):
if i % 2 == 0:
if rp < x[i]:
rp = x[i]
else:
exit(print('no'))
else:
if x[i] < lp:
rp = x[i]
else:
exit(print('yes'))
elif x[0] < x[1]:
lp, rp = x[0], x[1]
for i in range(2, n):
if i % 2 == 0:
if x[i] < lp:
lp = x[i]
else:
exit(print('yes'))
else:
if rp < x[i]:
rp = x[i]
else:
exit(print('yes'))
print('no')
``` | instruction | 0 | 5,369 | 23 | 10,738 |
No | output | 1 | 5,369 | 23 | 10,739 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework.
The teacher gave Seryozha the coordinates of n distinct points on the abscissa axis and asked to consecutively connect them by semi-circus in a certain order: first connect the first point with the second one, then connect the second point with the third one, then the third one with the fourth one and so on to the n-th point. Two points with coordinates (x1, 0) and (x2, 0) should be connected by a semi-circle that passes above the abscissa axis with the diameter that coincides with the segment between points. Seryozha needs to find out if the line on the picture intersects itself. For clarifications, see the picture Seryozha showed to Dima (the left picture has self-intersections, the right picture doesn't have any).
<image>
Seryozha is not a small boy, so the coordinates of the points can be rather large. Help Dima cope with the problem.
Input
The first line contains a single integer n (1 β€ n β€ 103). The second line contains n distinct integers x1, x2, ..., xn ( - 106 β€ xi β€ 106) β the i-th point has coordinates (xi, 0). The points are not necessarily sorted by their x coordinate.
Output
In the single line print "yes" (without the quotes), if the line has self-intersections. Otherwise, print "no" (without the quotes).
Examples
Input
4
0 10 5 15
Output
yes
Input
4
0 15 5 10
Output
no
Note
The first test from the statement is on the picture to the left, the second test is on the picture to the right.
Submitted Solution:
```
n=int(input())
x = list(map(int, input().split()))
c=0
d=0
if(n<=3):
d+=1
else:
for i in range(n-3):
if(x[i]<x[i+2]<x[i+1]<x[i+3] or x[i+2]<x[i]<x[i+3]<x[i+1]):
c+=1
else:
d+=1
if(c>0):
print("yes")
else:
print("no")
``` | instruction | 0 | 5,370 | 23 | 10,740 |
No | output | 1 | 5,370 | 23 | 10,741 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Petya is preparing for the first contact with aliens. He knows that alien spaceships have shapes of non-degenerate triangles and there will be exactly 4 ships. Landing platform for a ship can be made of 3 special columns located at some points of a Cartesian plane such that these 3 points form a triangle equal to the ship with respect to rotations, translations (parallel shifts along some vector) and reflections (symmetries along the edges). The ships can overlap after the landing.
Each column can be used to land more than one ship, for example, if there are two equal ships, we don't need to build 6 columns to land both ships, 3 will be enough. Petya wants to know what minimum number of columns will be enough to land all ships.
Input
Each of 4 lines will contain 6 integers x1 y1 x2 y2 x3 y3 (0 β€ x1, y1, x2, y2, x3, y3 β€ 20), representing 3 points that describe the shape of each of 4 ships. It is guaranteed that 3 points in each line will represent a non-degenerate triangle.
Output
First line should contain minimum number of columns enough to land all spaceships.
Examples
Input
0 0 1 0 1 2
0 0 0 2 2 2
0 0 3 0 1 2
0 0 3 0 2 2
Output
4
Input
0 0 0 1 1 1
0 0 0 2 2 2
0 0 0 5 5 5
0 0 0 17 17 17
Output
9
Note
In the first test case columns can be put in these points: (0, 0), (1, 0), (3, 0), (1, 2). Note that the second ship can land using last 3 columns.
In the second test case following points can be chosen: (0, 0), (0, 1), (1, 0), (0, 2), (2, 0), (0, 5), (5, 0), (0, 17), (17, 0). It is impossible to use less than 9 columns.
Submitted Solution:
```
a=input()
if a=='0 0 1 0 1 2':
print(4)
elif a=='0 0 0 1 1 1':
print(9)
else:
print(8)
``` | instruction | 0 | 5,478 | 23 | 10,956 |
No | output | 1 | 5,478 | 23 | 10,957 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Petya is preparing for the first contact with aliens. He knows that alien spaceships have shapes of non-degenerate triangles and there will be exactly 4 ships. Landing platform for a ship can be made of 3 special columns located at some points of a Cartesian plane such that these 3 points form a triangle equal to the ship with respect to rotations, translations (parallel shifts along some vector) and reflections (symmetries along the edges). The ships can overlap after the landing.
Each column can be used to land more than one ship, for example, if there are two equal ships, we don't need to build 6 columns to land both ships, 3 will be enough. Petya wants to know what minimum number of columns will be enough to land all ships.
Input
Each of 4 lines will contain 6 integers x1 y1 x2 y2 x3 y3 (0 β€ x1, y1, x2, y2, x3, y3 β€ 20), representing 3 points that describe the shape of each of 4 ships. It is guaranteed that 3 points in each line will represent a non-degenerate triangle.
Output
First line should contain minimum number of columns enough to land all spaceships.
Examples
Input
0 0 1 0 1 2
0 0 0 2 2 2
0 0 3 0 1 2
0 0 3 0 2 2
Output
4
Input
0 0 0 1 1 1
0 0 0 2 2 2
0 0 0 5 5 5
0 0 0 17 17 17
Output
9
Note
In the first test case columns can be put in these points: (0, 0), (1, 0), (3, 0), (1, 2). Note that the second ship can land using last 3 columns.
In the second test case following points can be chosen: (0, 0), (0, 1), (1, 0), (0, 2), (2, 0), (0, 5), (5, 0), (0, 17), (17, 0). It is impossible to use less than 9 columns.
Submitted Solution:
```
#I'm in lov
``` | instruction | 0 | 5,479 | 23 | 10,958 |
No | output | 1 | 5,479 | 23 | 10,959 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Petya is preparing for the first contact with aliens. He knows that alien spaceships have shapes of non-degenerate triangles and there will be exactly 4 ships. Landing platform for a ship can be made of 3 special columns located at some points of a Cartesian plane such that these 3 points form a triangle equal to the ship with respect to rotations, translations (parallel shifts along some vector) and reflections (symmetries along the edges). The ships can overlap after the landing.
Each column can be used to land more than one ship, for example, if there are two equal ships, we don't need to build 6 columns to land both ships, 3 will be enough. Petya wants to know what minimum number of columns will be enough to land all ships.
Input
Each of 4 lines will contain 6 integers x1 y1 x2 y2 x3 y3 (0 β€ x1, y1, x2, y2, x3, y3 β€ 20), representing 3 points that describe the shape of each of 4 ships. It is guaranteed that 3 points in each line will represent a non-degenerate triangle.
Output
First line should contain minimum number of columns enough to land all spaceships.
Examples
Input
0 0 1 0 1 2
0 0 0 2 2 2
0 0 3 0 1 2
0 0 3 0 2 2
Output
4
Input
0 0 0 1 1 1
0 0 0 2 2 2
0 0 0 5 5 5
0 0 0 17 17 17
Output
9
Note
In the first test case columns can be put in these points: (0, 0), (1, 0), (3, 0), (1, 2). Note that the second ship can land using last 3 columns.
In the second test case following points can be chosen: (0, 0), (0, 1), (1, 0), (0, 2), (2, 0), (0, 5), (5, 0), (0, 17), (17, 0). It is impossible to use less than 9 columns.
Submitted Solution:
```
a=input()
if a=='0 0 1 0 1 2':
print(4)
elif a=='0 0 0 1 1 1':
print(9)
elif a=='3 8 7 4 2 7':
print(7)
else:
print(8)
``` | instruction | 0 | 5,480 | 23 | 10,960 |
No | output | 1 | 5,480 | 23 | 10,961 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Petya is preparing for the first contact with aliens. He knows that alien spaceships have shapes of non-degenerate triangles and there will be exactly 4 ships. Landing platform for a ship can be made of 3 special columns located at some points of a Cartesian plane such that these 3 points form a triangle equal to the ship with respect to rotations, translations (parallel shifts along some vector) and reflections (symmetries along the edges). The ships can overlap after the landing.
Each column can be used to land more than one ship, for example, if there are two equal ships, we don't need to build 6 columns to land both ships, 3 will be enough. Petya wants to know what minimum number of columns will be enough to land all ships.
Input
Each of 4 lines will contain 6 integers x1 y1 x2 y2 x3 y3 (0 β€ x1, y1, x2, y2, x3, y3 β€ 20), representing 3 points that describe the shape of each of 4 ships. It is guaranteed that 3 points in each line will represent a non-degenerate triangle.
Output
First line should contain minimum number of columns enough to land all spaceships.
Examples
Input
0 0 1 0 1 2
0 0 0 2 2 2
0 0 3 0 1 2
0 0 3 0 2 2
Output
4
Input
0 0 0 1 1 1
0 0 0 2 2 2
0 0 0 5 5 5
0 0 0 17 17 17
Output
9
Note
In the first test case columns can be put in these points: (0, 0), (1, 0), (3, 0), (1, 2). Note that the second ship can land using last 3 columns.
In the second test case following points can be chosen: (0, 0), (0, 1), (1, 0), (0, 2), (2, 0), (0, 5), (5, 0), (0, 17), (17, 0). It is impossible to use less than 9 columns.
Submitted Solution:
```
#Hit my plug, that's my cholo (mi amigo)
i = input()+input()+input()+input()
if i == '0 0 1 0 1 20 0 0 2 2 20 0 3 0 1 20 0 3 0 2 2':
print(4)
if i == '0 0 0 1 1 10 0 0 2 2 20 0 0 5 5 50 0 0 17 17 17':
print(9)
if i == '3 8 7 4 2 77 9 3 1 9 80 2 4 8 6 50 9 0 0 6 1':
print(7)
if i == '3 8 9 3 4 46 0 6 6 1 84 9 6 3 7 88 2 9 1 3 5':
print(7)
if i == '1 7 4 0 9 48 8 2 4 5 51 7 1 1 5 27 6 1 4 2 3':
print(7)
if i == '20 8 13 19 17 1612 0 19 20 14 513 6 7 8 13 1418 18 9 9 17 6':
print(7)
``` | instruction | 0 | 5,481 | 23 | 10,962 |
No | output | 1 | 5,481 | 23 | 10,963 |
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,482 | 23 | 10,964 |
Tags: greedy, math
Correct Solution:
```
def get_next(T):
[a,b,c] = sorted(T)
return [b,c,b+c-1]
def main():
y,x = [int(s) for s in input().split()]
T = [x,x,x]
i = 0
while max(T) < y:
T = get_next(T)
i += 1
print(2+i)
main()
``` | output | 1 | 5,482 | 23 | 10,965 |
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,483 | 23 | 10,966 |
Tags: greedy, math
Correct Solution:
```
import math
x, y = map(int, input().split())
res = 0
now = [y, y, y]
while min(now) < x:
res += 1
ind = now.index(min(now))
o1, o2 = (ind + 1) % 3, (ind + 2) % 3
now[ind] = now[o1] + now[o2] - 1
print(res)
``` | output | 1 | 5,483 | 23 | 10,967 |
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,484 | 23 | 10,968 |
Tags: greedy, math
Correct Solution:
```
# (a[0], a[1], a[2]) => (y, y, y)
def triangle(a, y, prt=False):
if min(a) >= y:
return 0
elif a[1] + a[2] - 1 >= y:
return triangle([a[1], a[2], y], y) + 1
else:
return triangle([a[1], a[2], a[1] + a[2] - 1], y) + 1
def main():
x, y = list(map(int, input().split(' ')))
print(triangle([y, y, y], x))
if __name__ == '__main__':
main()
``` | output | 1 | 5,484 | 23 | 10,969 |
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,485 | 23 | 10,970 |
Tags: greedy, math
Correct Solution:
```
b,a=map(int,input().split())
t=0
s=[a,a,a]
while min(s)<b:
x=min(s)
if s[0]==x:
s[0]=min(s[1]+s[2]-1,b)
elif s[1]==x:
s[1]=min(s[0]+s[2]-1,b)
else:
s[2]=min(s[0]+s[1]-1,b)
t+=1
print(t)
``` | output | 1 | 5,485 | 23 | 10,971 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.