message stringlengths 2 44.5k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 276 109k | cluster float64 23 23 | __index_level_0__ int64 552 217k |
|---|---|---|---|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n points on a line with their coordinates xi. Find the point x so the sum of distances to the given points is minimal.
Input
The first line contains integer n (1 β€ n β€ 3Β·105) β the number of points on the line.
The second line contains n integers xi ( - 109 β€ xi β€ 109) β the coordinates of the given n points.
Output
Print the only integer x β the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
Example
Input
4
1 2 3 4
Output
2 | instruction | 0 | 20,768 | 23 | 41,536 |
Tags: brute force, sortings
Correct Solution:
```
count = int(input())
nums = sorted([int(num) for num in input().split()])
print(nums[(count - 1) // 2])
``` | output | 1 | 20,768 | 23 | 41,537 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n points on a line with their coordinates xi. Find the point x so the sum of distances to the given points is minimal.
Input
The first line contains integer n (1 β€ n β€ 3Β·105) β the number of points on the line.
The second line contains n integers xi ( - 109 β€ xi β€ 109) β the coordinates of the given n points.
Output
Print the only integer x β the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
Example
Input
4
1 2 3 4
Output
2 | instruction | 0 | 20,769 | 23 | 41,538 |
Tags: brute force, sortings
Correct Solution:
```
import sys
from statistics import median
from math import floor
sys.stdin.readline()
numbers = sorted(int(a) for a in sys.stdin.readline().split())
print(numbers[floor((len(numbers) - 1) / 2)])
``` | output | 1 | 20,769 | 23 | 41,539 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n points on a line with their coordinates xi. Find the point x so the sum of distances to the given points is minimal.
Input
The first line contains integer n (1 β€ n β€ 3Β·105) β the number of points on the line.
The second line contains n integers xi ( - 109 β€ xi β€ 109) β the coordinates of the given n points.
Output
Print the only integer x β the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
Example
Input
4
1 2 3 4
Output
2 | instruction | 0 | 20,770 | 23 | 41,540 |
Tags: brute force, sortings
Correct Solution:
```
n=int(input())
a=list(map(int, input().split()))
a.sort()
k=0
r=0
for i in range(1,n):
k=k+abs((a[i]-a[0]))
if n%2==1:
print(a[n//2])
else:
for j in range(n):
r=r+abs(a[n//2-1]-a[j])
for i in range(n):
k=k+abs(a[n//2]-a[i])
if r<=k:
print(a[n//2-1])
else:
print(a[n//2])
``` | output | 1 | 20,770 | 23 | 41,541 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n points on a line with their coordinates xi. Find the point x so the sum of distances to the given points is minimal.
Input
The first line contains integer n (1 β€ n β€ 3Β·105) β the number of points on the line.
The second line contains n integers xi ( - 109 β€ xi β€ 109) β the coordinates of the given n points.
Output
Print the only integer x β the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
Example
Input
4
1 2 3 4
Output
2 | instruction | 0 | 20,771 | 23 | 41,542 |
Tags: brute force, sortings
Correct Solution:
```
n=int(input())
li=list(map(int, input().split()))
li.sort()
print(li[(n-1)//2])
``` | output | 1 | 20,771 | 23 | 41,543 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n points on a line with their coordinates xi. Find the point x so the sum of distances to the given points is minimal.
Input
The first line contains integer n (1 β€ n β€ 3Β·105) β the number of points on the line.
The second line contains n integers xi ( - 109 β€ xi β€ 109) β the coordinates of the given n points.
Output
Print the only integer x β the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
Example
Input
4
1 2 3 4
Output
2 | instruction | 0 | 20,772 | 23 | 41,544 |
Tags: brute force, sortings
Correct Solution:
```
'''
You are given n points on a line with their coordinates x_i.
Find the point x so the sum of distances to the given points is minimal.
Input
The first line contains integer n (1ββ€βnββ€β3Β·105)
β the number of points on the line.
The second line contains n integers x[i] (β-β109ββ€βx[i]ββ€β109)
β the coordinates of the given n points.
Output
Print the only integer x β the position of the optimal point on the line.
If there are several optimal points print the position of the
leftmost one. It is guaranteed that the answer is always the integer.
'''
import io
import sys
import time
import random
#~ start = time.clock()
#~ test ='''4
#~ 1 2'''
#~ sys.stdin = io.StringIO(test)
n = int(input())
x = [int(x) for x in input().split()]
x.sort()
if len(x)%2==0:
print( x[ (len(x)-1)//2 ] )
else:
print( x[ len(x)//2 ] )
#~ dur = time.clock()-start
#~ print("Time:",dur)
``` | output | 1 | 20,772 | 23 | 41,545 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n points on a line with their coordinates xi. Find the point x so the sum of distances to the given points is minimal.
Input
The first line contains integer n (1 β€ n β€ 3Β·105) β the number of points on the line.
The second line contains n integers xi ( - 109 β€ xi β€ 109) β the coordinates of the given n points.
Output
Print the only integer x β the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
Example
Input
4
1 2 3 4
Output
2 | instruction | 0 | 20,773 | 23 | 41,546 |
Tags: brute force, sortings
Correct Solution:
```
n, x = int(input()), sorted(list(map(int, input().split())))
print(x[(n - 1) // 2])
``` | output | 1 | 20,773 | 23 | 41,547 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given n points on a line with their coordinates xi. Find the point x so the sum of distances to the given points is minimal.
Input
The first line contains integer n (1 β€ n β€ 3Β·105) β the number of points on the line.
The second line contains n integers xi ( - 109 β€ xi β€ 109) β the coordinates of the given n points.
Output
Print the only integer x β the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
Example
Input
4
1 2 3 4
Output
2
Submitted Solution:
```
n=int(input())
a=list(map(int,input().split()))
a.sort()
if n%2==0:
print(a[int(n/2)-1])
else:
print(a[int((n-1)/2)])
``` | instruction | 0 | 20,774 | 23 | 41,548 |
Yes | output | 1 | 20,774 | 23 | 41,549 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given n points on a line with their coordinates xi. Find the point x so the sum of distances to the given points is minimal.
Input
The first line contains integer n (1 β€ n β€ 3Β·105) β the number of points on the line.
The second line contains n integers xi ( - 109 β€ xi β€ 109) β the coordinates of the given n points.
Output
Print the only integer x β the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
Example
Input
4
1 2 3 4
Output
2
Submitted Solution:
```
if __name__ == '__main__':
n = int(input())
nums = list(map(int, input().split()))
nums.sort()
if n % 2 == 0:
ans = n // 2 - 1
else:
ans = n // 2
print(nums[ans])
``` | instruction | 0 | 20,775 | 23 | 41,550 |
Yes | output | 1 | 20,775 | 23 | 41,551 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given n points on a line with their coordinates xi. Find the point x so the sum of distances to the given points is minimal.
Input
The first line contains integer n (1 β€ n β€ 3Β·105) β the number of points on the line.
The second line contains n integers xi ( - 109 β€ xi β€ 109) β the coordinates of the given n points.
Output
Print the only integer x β the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
Example
Input
4
1 2 3 4
Output
2
Submitted Solution:
```
def good(mid):
s=0
for i in a:
s+=abs(mid-i)
if s<=old:
s=old
return 1
else:
return -1
n=int(input())
a=list(map(int,input().split()))
l=1
r=10**6
old=max(a)-min(a)
while l < r:
mid = l + (r - l) // 2
temp = good(mid)
if temp:
r = mid
else:
l = mid + 1
print(l+1)
``` | instruction | 0 | 20,778 | 23 | 41,556 |
No | output | 1 | 20,778 | 23 | 41,557 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given n points on a line with their coordinates xi. Find the point x so the sum of distances to the given points is minimal.
Input
The first line contains integer n (1 β€ n β€ 3Β·105) β the number of points on the line.
The second line contains n integers xi ( - 109 β€ xi β€ 109) β the coordinates of the given n points.
Output
Print the only integer x β the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
Example
Input
4
1 2 3 4
Output
2
Submitted Solution:
```
from statistics import median
def left(n):
if n >= 0:
return int(n)
return int(n) - 1
n = int(input())
x = list(map(int,input().split()))
print(left(median(x)))
``` | instruction | 0 | 20,779 | 23 | 41,558 |
No | output | 1 | 20,779 | 23 | 41,559 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given n points on a line with their coordinates xi. Find the point x so the sum of distances to the given points is minimal.
Input
The first line contains integer n (1 β€ n β€ 3Β·105) β the number of points on the line.
The second line contains n integers xi ( - 109 β€ xi β€ 109) β the coordinates of the given n points.
Output
Print the only integer x β the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
Example
Input
4
1 2 3 4
Output
2
Submitted Solution:
```
n = int(input())
xi = list(map(int,input().split()))
num = sum(xi)/n
num2 = int(num)
if num - num2 > 0.5:
print(num2+1)
else:
print(num2)
``` | instruction | 0 | 20,780 | 23 | 41,560 |
No | output | 1 | 20,780 | 23 | 41,561 |
Provide tags and a correct Python 3 solution for this coding contest problem.
PolandBall has such a convex polygon with n veritces that no three of its diagonals intersect at the same point. PolandBall decided to improve it and draw some red segments.
He chose a number k such that gcd(n, k) = 1. Vertices of the polygon are numbered from 1 to n in a clockwise way. PolandBall repeats the following process n times, starting from the vertex 1:
Assume you've ended last operation in vertex x (consider x = 1 if it is the first operation). Draw a new segment from vertex x to k-th next vertex in clockwise direction. This is a vertex x + k or x + k - n depending on which of these is a valid index of polygon's vertex.
Your task is to calculate number of polygon's sections after each drawing. A section is a clear area inside the polygon bounded with drawn diagonals or the polygon's sides.
Input
There are only two numbers in the input: n and k (5 β€ n β€ 106, 2 β€ k β€ n - 2, gcd(n, k) = 1).
Output
You should print n values separated by spaces. The i-th value should represent number of polygon's sections after drawing first i lines.
Examples
Input
5 2
Output
2 3 5 8 11
Input
10 3
Output
2 3 4 6 9 12 16 21 26 31
Note
The greatest common divisor (gcd) of two integers a and b is the largest positive integer that divides both a and b without a remainder.
For the first sample testcase, you should output "2 3 5 8 11". Pictures below correspond to situations after drawing lines.
<image> <image> <image> <image> <image> <image> | instruction | 0 | 20,798 | 23 | 41,596 |
Tags: data structures
Correct Solution:
```
n, k = map(int, input().split())
if n // 2 < k:
k = n - k
i = 1
count = 1
ans = [1]
for _ in range(n):
i += k
if i > n + 1:
count += 1
ans.append(ans[-1] + count)
count += 1
i -= n
else:
ans.append(ans[-1] + count)
print(*ans[1:])
``` | output | 1 | 20,798 | 23 | 41,597 |
Provide tags and a correct Python 3 solution for this coding contest problem.
PolandBall has such a convex polygon with n veritces that no three of its diagonals intersect at the same point. PolandBall decided to improve it and draw some red segments.
He chose a number k such that gcd(n, k) = 1. Vertices of the polygon are numbered from 1 to n in a clockwise way. PolandBall repeats the following process n times, starting from the vertex 1:
Assume you've ended last operation in vertex x (consider x = 1 if it is the first operation). Draw a new segment from vertex x to k-th next vertex in clockwise direction. This is a vertex x + k or x + k - n depending on which of these is a valid index of polygon's vertex.
Your task is to calculate number of polygon's sections after each drawing. A section is a clear area inside the polygon bounded with drawn diagonals or the polygon's sides.
Input
There are only two numbers in the input: n and k (5 β€ n β€ 106, 2 β€ k β€ n - 2, gcd(n, k) = 1).
Output
You should print n values separated by spaces. The i-th value should represent number of polygon's sections after drawing first i lines.
Examples
Input
5 2
Output
2 3 5 8 11
Input
10 3
Output
2 3 4 6 9 12 16 21 26 31
Note
The greatest common divisor (gcd) of two integers a and b is the largest positive integer that divides both a and b without a remainder.
For the first sample testcase, you should output "2 3 5 8 11". Pictures below correspond to situations after drawing lines.
<image> <image> <image> <image> <image> <image> | instruction | 0 | 20,799 | 23 | 41,598 |
Tags: data structures
Correct Solution:
```
def euclid(a, b): ##return [m, n] with am + bn = gcd(a, b)
if b == 0:
return [1, 0]
if b > a:
l = euclid(b, a)
l.reverse()
return l
else:
quo = a // b
rem = a % b
l = euclid(b, rem)
m = l[0]
n = l[1]
return [n, m - n * quo]
s = input().split()
n = int(s[0])
k = int(s[1])
if 2 * k > n:
k = n - k
a = [0 for i in range(n)]
t = 0
inv = euclid(n, k)[1] % n
for i in range(k - 1):
t = ((i + 1) * inv) % n
a[t] += 1
a[n - t] += 1
for r in range(2):
a[0] += 1
for i in range(1, n):
a[i] += a[i - 1]
##for i in range(n):
## print(a[i])
print("\n".join(str(a[i]) for i in range(n)))
``` | output | 1 | 20,799 | 23 | 41,599 |
Provide tags and a correct Python 3 solution for this coding contest problem.
PolandBall has such a convex polygon with n veritces that no three of its diagonals intersect at the same point. PolandBall decided to improve it and draw some red segments.
He chose a number k such that gcd(n, k) = 1. Vertices of the polygon are numbered from 1 to n in a clockwise way. PolandBall repeats the following process n times, starting from the vertex 1:
Assume you've ended last operation in vertex x (consider x = 1 if it is the first operation). Draw a new segment from vertex x to k-th next vertex in clockwise direction. This is a vertex x + k or x + k - n depending on which of these is a valid index of polygon's vertex.
Your task is to calculate number of polygon's sections after each drawing. A section is a clear area inside the polygon bounded with drawn diagonals or the polygon's sides.
Input
There are only two numbers in the input: n and k (5 β€ n β€ 106, 2 β€ k β€ n - 2, gcd(n, k) = 1).
Output
You should print n values separated by spaces. The i-th value should represent number of polygon's sections after drawing first i lines.
Examples
Input
5 2
Output
2 3 5 8 11
Input
10 3
Output
2 3 4 6 9 12 16 21 26 31
Note
The greatest common divisor (gcd) of two integers a and b is the largest positive integer that divides both a and b without a remainder.
For the first sample testcase, you should output "2 3 5 8 11". Pictures below correspond to situations after drawing lines.
<image> <image> <image> <image> <image> <image> | instruction | 0 | 20,800 | 23 | 41,600 |
Tags: data structures
Correct Solution:
```
import sys
inf = (1 << 31) - 1
def solve():
n, k = map(int, input().split())
if k > n - k:
k = n - k
bit = BinaryIndexedTree([0]*n)
s = 0
res = 1
ans = []
for i in range(n):
t = (s + k) % n
if s < t:
res += bit.get_sum(t) - bit.get_sum(s + 1) + 1
ans.append(res)
else:
res += bit.get_sum(n) - bit.get_sum(s + 1)
res += bit.get_sum(t) + 1
ans.append(res)
bit.add(s, 1)
bit.add(t, 1)
s = t
print(*ans)
class BinaryIndexedTree:
''' 1-origin Binary Indexed Tree '''
def __init__(self, a):
self.n = len(a)
self.bit = [0]*(self.n + 1)
for i in range(1, self.n + 1):
self.bit[i] += a[i - 1]
if i + (i & (-i)) <= self.n:
self.bit[i + (i & (-i))] += self.bit[i]
def add(self, i, x):
''' a_i += x '''
i += 1 # 0-origin -> 1-origin
while i <= self.n:
self.bit[i] += x
i += i & (-i)
def get_sum(self, r):
''' sum(a[0 .. r)) '''
res = 0
while r > 0:
res += self.bit[r]
r -= r & (-r)
return res
if __name__ == '__main__':
solve()
``` | output | 1 | 20,800 | 23 | 41,601 |
Provide tags and a correct Python 3 solution for this coding contest problem.
PolandBall has such a convex polygon with n veritces that no three of its diagonals intersect at the same point. PolandBall decided to improve it and draw some red segments.
He chose a number k such that gcd(n, k) = 1. Vertices of the polygon are numbered from 1 to n in a clockwise way. PolandBall repeats the following process n times, starting from the vertex 1:
Assume you've ended last operation in vertex x (consider x = 1 if it is the first operation). Draw a new segment from vertex x to k-th next vertex in clockwise direction. This is a vertex x + k or x + k - n depending on which of these is a valid index of polygon's vertex.
Your task is to calculate number of polygon's sections after each drawing. A section is a clear area inside the polygon bounded with drawn diagonals or the polygon's sides.
Input
There are only two numbers in the input: n and k (5 β€ n β€ 106, 2 β€ k β€ n - 2, gcd(n, k) = 1).
Output
You should print n values separated by spaces. The i-th value should represent number of polygon's sections after drawing first i lines.
Examples
Input
5 2
Output
2 3 5 8 11
Input
10 3
Output
2 3 4 6 9 12 16 21 26 31
Note
The greatest common divisor (gcd) of two integers a and b is the largest positive integer that divides both a and b without a remainder.
For the first sample testcase, you should output "2 3 5 8 11". Pictures below correspond to situations after drawing lines.
<image> <image> <image> <image> <image> <image> | instruction | 0 | 20,801 | 23 | 41,602 |
Tags: data structures
Correct Solution:
```
n, k = map(int, input().split())
if k << 1 > n: k = n - k
s = 1
for i in range(n):
s += 1 + i * k // n + (i * k + k - 1) // n
print(s)
``` | output | 1 | 20,801 | 23 | 41,603 |
Provide tags and a correct Python 3 solution for this coding contest problem.
PolandBall has such a convex polygon with n veritces that no three of its diagonals intersect at the same point. PolandBall decided to improve it and draw some red segments.
He chose a number k such that gcd(n, k) = 1. Vertices of the polygon are numbered from 1 to n in a clockwise way. PolandBall repeats the following process n times, starting from the vertex 1:
Assume you've ended last operation in vertex x (consider x = 1 if it is the first operation). Draw a new segment from vertex x to k-th next vertex in clockwise direction. This is a vertex x + k or x + k - n depending on which of these is a valid index of polygon's vertex.
Your task is to calculate number of polygon's sections after each drawing. A section is a clear area inside the polygon bounded with drawn diagonals or the polygon's sides.
Input
There are only two numbers in the input: n and k (5 β€ n β€ 106, 2 β€ k β€ n - 2, gcd(n, k) = 1).
Output
You should print n values separated by spaces. The i-th value should represent number of polygon's sections after drawing first i lines.
Examples
Input
5 2
Output
2 3 5 8 11
Input
10 3
Output
2 3 4 6 9 12 16 21 26 31
Note
The greatest common divisor (gcd) of two integers a and b is the largest positive integer that divides both a and b without a remainder.
For the first sample testcase, you should output "2 3 5 8 11". Pictures below correspond to situations after drawing lines.
<image> <image> <image> <image> <image> <image> | instruction | 0 | 20,802 | 23 | 41,604 |
Tags: data structures
Correct Solution:
```
# input = raw_input
# range = xrange
class Fen:
def __init__(self, n):
self.value = [0] * n
def get(self, fro, to):
return self.get1(to) - self.get1(fro - 1)
def get1(self, to):
to = min(to, len(self.value))
result = 0
while to >= 0:
result += self.value[to]
to = (to & (to + 1)) - 1
return result
def add(self, at, value):
while at < len(self.value):
self.value[at] += value
at = at | (at + 1)
def solve():
n, k = map(int, input().split())
k = min(k, n - k)
count = [0] * n
res = [None] * n
ans = 1
cur = 0
fen = Fen(n)
for iteration in range(n):
nxt = (cur + k) % n
here = 0
if cur < nxt:
here = fen.get(cur + 1, nxt - 1)
else:
here = fen.get(0, nxt - 1) + fen.get(cur + 1, n - 1)
fen.add(cur, 1)
fen.add(nxt, 1)
cur = nxt
ans += here + 1
res[iteration] = ans
print(" ".join(map(str, res)))
solve()
``` | output | 1 | 20,802 | 23 | 41,605 |
Provide tags and a correct Python 3 solution for this coding contest problem.
PolandBall has such a convex polygon with n veritces that no three of its diagonals intersect at the same point. PolandBall decided to improve it and draw some red segments.
He chose a number k such that gcd(n, k) = 1. Vertices of the polygon are numbered from 1 to n in a clockwise way. PolandBall repeats the following process n times, starting from the vertex 1:
Assume you've ended last operation in vertex x (consider x = 1 if it is the first operation). Draw a new segment from vertex x to k-th next vertex in clockwise direction. This is a vertex x + k or x + k - n depending on which of these is a valid index of polygon's vertex.
Your task is to calculate number of polygon's sections after each drawing. A section is a clear area inside the polygon bounded with drawn diagonals or the polygon's sides.
Input
There are only two numbers in the input: n and k (5 β€ n β€ 106, 2 β€ k β€ n - 2, gcd(n, k) = 1).
Output
You should print n values separated by spaces. The i-th value should represent number of polygon's sections after drawing first i lines.
Examples
Input
5 2
Output
2 3 5 8 11
Input
10 3
Output
2 3 4 6 9 12 16 21 26 31
Note
The greatest common divisor (gcd) of two integers a and b is the largest positive integer that divides both a and b without a remainder.
For the first sample testcase, you should output "2 3 5 8 11". Pictures below correspond to situations after drawing lines.
<image> <image> <image> <image> <image> <image> | instruction | 0 | 20,803 | 23 | 41,606 |
Tags: data structures
Correct Solution:
```
#------------------------template--------------------------#
import os
import sys
# from math import *
from collections import *
# from fractions import *
# from heapq import*
from bisect import *
from io import BytesIO, IOBase
def vsInput():
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
ALPHA='abcdefghijklmnopqrstuvwxyz'
M=998244353
EPS=1e-6
def Ceil(a,b): return a//b+int(a%b>0)
def value():return tuple(map(int,input().split()))
def array():return [int(i) for i in input().split()]
def Int():return int(input())
def Str():return input()
def arrayS():return [i for i in input().split()]
#-------------------------code---------------------------#
# vsInput()
n,k = value()
C = [0]*n
k = min(k,n-k)
ans = 1
cur = 1
steps = 0
single = 1
series = []
while(steps<n):
while(cur <= n):
cur += k
steps += 1
ans += single
series.append(ans)
ans+=1
series[-1]+=1
single+=2
cur = cur%n
series[-1]-=1
print(*series)
``` | output | 1 | 20,803 | 23 | 41,607 |
Provide tags and a correct Python 3 solution for this coding contest problem.
PolandBall has such a convex polygon with n veritces that no three of its diagonals intersect at the same point. PolandBall decided to improve it and draw some red segments.
He chose a number k such that gcd(n, k) = 1. Vertices of the polygon are numbered from 1 to n in a clockwise way. PolandBall repeats the following process n times, starting from the vertex 1:
Assume you've ended last operation in vertex x (consider x = 1 if it is the first operation). Draw a new segment from vertex x to k-th next vertex in clockwise direction. This is a vertex x + k or x + k - n depending on which of these is a valid index of polygon's vertex.
Your task is to calculate number of polygon's sections after each drawing. A section is a clear area inside the polygon bounded with drawn diagonals or the polygon's sides.
Input
There are only two numbers in the input: n and k (5 β€ n β€ 106, 2 β€ k β€ n - 2, gcd(n, k) = 1).
Output
You should print n values separated by spaces. The i-th value should represent number of polygon's sections after drawing first i lines.
Examples
Input
5 2
Output
2 3 5 8 11
Input
10 3
Output
2 3 4 6 9 12 16 21 26 31
Note
The greatest common divisor (gcd) of two integers a and b is the largest positive integer that divides both a and b without a remainder.
For the first sample testcase, you should output "2 3 5 8 11". Pictures below correspond to situations after drawing lines.
<image> <image> <image> <image> <image> <image> | instruction | 0 | 20,804 | 23 | 41,608 |
Tags: data structures
Correct Solution:
```
import sys
inf = (1 << 31) - 1
def solve():
n, k = map(int, input().split())
if k > n - k:
k = n - k
s = 0
res = 1
a = 1
ans = [0]*n
for i in range(n):
t = (s + k) % n
if t < s and t > 0:
res += a + 1
a += 2
else:
res += a
ans[i] = res
s = t
print(*ans)
if __name__ == '__main__':
solve()
``` | output | 1 | 20,804 | 23 | 41,609 |
Provide tags and a correct Python 3 solution for this coding contest problem.
PolandBall has such a convex polygon with n veritces that no three of its diagonals intersect at the same point. PolandBall decided to improve it and draw some red segments.
He chose a number k such that gcd(n, k) = 1. Vertices of the polygon are numbered from 1 to n in a clockwise way. PolandBall repeats the following process n times, starting from the vertex 1:
Assume you've ended last operation in vertex x (consider x = 1 if it is the first operation). Draw a new segment from vertex x to k-th next vertex in clockwise direction. This is a vertex x + k or x + k - n depending on which of these is a valid index of polygon's vertex.
Your task is to calculate number of polygon's sections after each drawing. A section is a clear area inside the polygon bounded with drawn diagonals or the polygon's sides.
Input
There are only two numbers in the input: n and k (5 β€ n β€ 106, 2 β€ k β€ n - 2, gcd(n, k) = 1).
Output
You should print n values separated by spaces. The i-th value should represent number of polygon's sections after drawing first i lines.
Examples
Input
5 2
Output
2 3 5 8 11
Input
10 3
Output
2 3 4 6 9 12 16 21 26 31
Note
The greatest common divisor (gcd) of two integers a and b is the largest positive integer that divides both a and b without a remainder.
For the first sample testcase, you should output "2 3 5 8 11". Pictures below correspond to situations after drawing lines.
<image> <image> <image> <image> <image> <image> | instruction | 0 | 20,805 | 23 | 41,610 |
Tags: data structures
Correct Solution:
```
if __name__ == "__main__":
n,k = list(map(int, input().strip().split()))
if k > n//2:
k = n - k
intersection = n * [0]
count = 1
done = False
i=0
result = []
for i in range(1,n+1):
nn = (i*k) // n
j = (i*k)%n
if j < k:
count += (2*nn )
else:
count += (2*nn +1)
result.append(count)
result[-1] -= 1
print(" ".join([str(r) for r in result]))
``` | output | 1 | 20,805 | 23 | 41,611 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
PolandBall has such a convex polygon with n veritces that no three of its diagonals intersect at the same point. PolandBall decided to improve it and draw some red segments.
He chose a number k such that gcd(n, k) = 1. Vertices of the polygon are numbered from 1 to n in a clockwise way. PolandBall repeats the following process n times, starting from the vertex 1:
Assume you've ended last operation in vertex x (consider x = 1 if it is the first operation). Draw a new segment from vertex x to k-th next vertex in clockwise direction. This is a vertex x + k or x + k - n depending on which of these is a valid index of polygon's vertex.
Your task is to calculate number of polygon's sections after each drawing. A section is a clear area inside the polygon bounded with drawn diagonals or the polygon's sides.
Input
There are only two numbers in the input: n and k (5 β€ n β€ 106, 2 β€ k β€ n - 2, gcd(n, k) = 1).
Output
You should print n values separated by spaces. The i-th value should represent number of polygon's sections after drawing first i lines.
Examples
Input
5 2
Output
2 3 5 8 11
Input
10 3
Output
2 3 4 6 9 12 16 21 26 31
Note
The greatest common divisor (gcd) of two integers a and b is the largest positive integer that divides both a and b without a remainder.
For the first sample testcase, you should output "2 3 5 8 11". Pictures below correspond to situations after drawing lines.
<image> <image> <image> <image> <image> <image>
Submitted Solution:
```
n, m = [int(i) for i in input().split()]
if m > n//2:
m = n-m
ans = [1]
count = 0
c = 1
for i in range(n):
count+=m
if count>n:
c+=1
count-=n
ans.append(ans[-1] +c)
c+=1
else:
ans.append(ans[-1] +c)
ans = ans[1:]
print(*ans)
``` | instruction | 0 | 20,806 | 23 | 41,612 |
Yes | output | 1 | 20,806 | 23 | 41,613 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
PolandBall has such a convex polygon with n veritces that no three of its diagonals intersect at the same point. PolandBall decided to improve it and draw some red segments.
He chose a number k such that gcd(n, k) = 1. Vertices of the polygon are numbered from 1 to n in a clockwise way. PolandBall repeats the following process n times, starting from the vertex 1:
Assume you've ended last operation in vertex x (consider x = 1 if it is the first operation). Draw a new segment from vertex x to k-th next vertex in clockwise direction. This is a vertex x + k or x + k - n depending on which of these is a valid index of polygon's vertex.
Your task is to calculate number of polygon's sections after each drawing. A section is a clear area inside the polygon bounded with drawn diagonals or the polygon's sides.
Input
There are only two numbers in the input: n and k (5 β€ n β€ 106, 2 β€ k β€ n - 2, gcd(n, k) = 1).
Output
You should print n values separated by spaces. The i-th value should represent number of polygon's sections after drawing first i lines.
Examples
Input
5 2
Output
2 3 5 8 11
Input
10 3
Output
2 3 4 6 9 12 16 21 26 31
Note
The greatest common divisor (gcd) of two integers a and b is the largest positive integer that divides both a and b without a remainder.
For the first sample testcase, you should output "2 3 5 8 11". Pictures below correspond to situations after drawing lines.
<image> <image> <image> <image> <image> <image>
Submitted Solution:
```
l=input().split()
n=int(l[0])
k=int(l[1])
curr=0
ans=1
if(k>n//2):
k=n-k
for i in range(n):
curr+=k
if(i==n-1):
ans=ans+2*(curr//n)-1
elif(curr%n<k):
ans=ans+2*((curr)//n)
else:
ans=ans+2*((curr)//n)+1
print(ans,end=" ")
``` | instruction | 0 | 20,807 | 23 | 41,614 |
Yes | output | 1 | 20,807 | 23 | 41,615 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
PolandBall has such a convex polygon with n veritces that no three of its diagonals intersect at the same point. PolandBall decided to improve it and draw some red segments.
He chose a number k such that gcd(n, k) = 1. Vertices of the polygon are numbered from 1 to n in a clockwise way. PolandBall repeats the following process n times, starting from the vertex 1:
Assume you've ended last operation in vertex x (consider x = 1 if it is the first operation). Draw a new segment from vertex x to k-th next vertex in clockwise direction. This is a vertex x + k or x + k - n depending on which of these is a valid index of polygon's vertex.
Your task is to calculate number of polygon's sections after each drawing. A section is a clear area inside the polygon bounded with drawn diagonals or the polygon's sides.
Input
There are only two numbers in the input: n and k (5 β€ n β€ 106, 2 β€ k β€ n - 2, gcd(n, k) = 1).
Output
You should print n values separated by spaces. The i-th value should represent number of polygon's sections after drawing first i lines.
Examples
Input
5 2
Output
2 3 5 8 11
Input
10 3
Output
2 3 4 6 9 12 16 21 26 31
Note
The greatest common divisor (gcd) of two integers a and b is the largest positive integer that divides both a and b without a remainder.
For the first sample testcase, you should output "2 3 5 8 11". Pictures below correspond to situations after drawing lines.
<image> <image> <image> <image> <image> <image>
Submitted Solution:
```
n, k = map(int, input().split())
res = 1
diags = 0
ii = 0
for i in range(n):
to = (ii + k) % n
cur = 0
cur += diags
if diags == 0:
cur += 1
if i == n - 1:
cur -= 1
diags += 1
# print("cur is " + str(cur) + " " + str(i));
res += cur
ii = to
print(res, end=" ")
``` | instruction | 0 | 20,808 | 23 | 41,616 |
No | output | 1 | 20,808 | 23 | 41,617 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
PolandBall has such a convex polygon with n veritces that no three of its diagonals intersect at the same point. PolandBall decided to improve it and draw some red segments.
He chose a number k such that gcd(n, k) = 1. Vertices of the polygon are numbered from 1 to n in a clockwise way. PolandBall repeats the following process n times, starting from the vertex 1:
Assume you've ended last operation in vertex x (consider x = 1 if it is the first operation). Draw a new segment from vertex x to k-th next vertex in clockwise direction. This is a vertex x + k or x + k - n depending on which of these is a valid index of polygon's vertex.
Your task is to calculate number of polygon's sections after each drawing. A section is a clear area inside the polygon bounded with drawn diagonals or the polygon's sides.
Input
There are only two numbers in the input: n and k (5 β€ n β€ 106, 2 β€ k β€ n - 2, gcd(n, k) = 1).
Output
You should print n values separated by spaces. The i-th value should represent number of polygon's sections after drawing first i lines.
Examples
Input
5 2
Output
2 3 5 8 11
Input
10 3
Output
2 3 4 6 9 12 16 21 26 31
Note
The greatest common divisor (gcd) of two integers a and b is the largest positive integer that divides both a and b without a remainder.
For the first sample testcase, you should output "2 3 5 8 11". Pictures below correspond to situations after drawing lines.
<image> <image> <image> <image> <image> <image>
Submitted Solution:
```
#n = int(input())
n, m = map(int, input().split())
#s = input()
#c = list(map(int, input().split()))
k = 1
x = 1
l = 1
if n // 2 >= m:
for i in range(n - 1):
x = (x - 1) % n + 1
x += m
if x > n:
k += 2
l -= 1
l += k
print(l, end = ' ')
else:
print(l + k)
else:
k = -1
l = 2
for i in range(n - 1):
if i == m:
k += 1
k += 1
l += k
print(l, end = ' ')
print(l + m)
``` | instruction | 0 | 20,809 | 23 | 41,618 |
No | output | 1 | 20,809 | 23 | 41,619 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
PolandBall has such a convex polygon with n veritces that no three of its diagonals intersect at the same point. PolandBall decided to improve it and draw some red segments.
He chose a number k such that gcd(n, k) = 1. Vertices of the polygon are numbered from 1 to n in a clockwise way. PolandBall repeats the following process n times, starting from the vertex 1:
Assume you've ended last operation in vertex x (consider x = 1 if it is the first operation). Draw a new segment from vertex x to k-th next vertex in clockwise direction. This is a vertex x + k or x + k - n depending on which of these is a valid index of polygon's vertex.
Your task is to calculate number of polygon's sections after each drawing. A section is a clear area inside the polygon bounded with drawn diagonals or the polygon's sides.
Input
There are only two numbers in the input: n and k (5 β€ n β€ 106, 2 β€ k β€ n - 2, gcd(n, k) = 1).
Output
You should print n values separated by spaces. The i-th value should represent number of polygon's sections after drawing first i lines.
Examples
Input
5 2
Output
2 3 5 8 11
Input
10 3
Output
2 3 4 6 9 12 16 21 26 31
Note
The greatest common divisor (gcd) of two integers a and b is the largest positive integer that divides both a and b without a remainder.
For the first sample testcase, you should output "2 3 5 8 11". Pictures below correspond to situations after drawing lines.
<image> <image> <image> <image> <image> <image>
Submitted Solution:
```
#n = int(input())
n, m = map(int, input().split())
#s = input()
#c = list(map(int, input().split()))
k = 1
x = 1
l = 1
if n // 2 >= m:
for i in range(n - 1):
x = (x - 1) % n + 1
x += m
if x > n:
k += 2
l -= 1
l += k
print(l, end = ' ')
else:
print(l + k)
else:
k = -1
l = 2
for i in range(n - 1):
if i == m - 1:
k -= 1
k += 1
l += k
print(l, end = ' ')
print(l + m + 4)
``` | instruction | 0 | 20,810 | 23 | 41,620 |
No | output | 1 | 20,810 | 23 | 41,621 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
PolandBall has such a convex polygon with n veritces that no three of its diagonals intersect at the same point. PolandBall decided to improve it and draw some red segments.
He chose a number k such that gcd(n, k) = 1. Vertices of the polygon are numbered from 1 to n in a clockwise way. PolandBall repeats the following process n times, starting from the vertex 1:
Assume you've ended last operation in vertex x (consider x = 1 if it is the first operation). Draw a new segment from vertex x to k-th next vertex in clockwise direction. This is a vertex x + k or x + k - n depending on which of these is a valid index of polygon's vertex.
Your task is to calculate number of polygon's sections after each drawing. A section is a clear area inside the polygon bounded with drawn diagonals or the polygon's sides.
Input
There are only two numbers in the input: n and k (5 β€ n β€ 106, 2 β€ k β€ n - 2, gcd(n, k) = 1).
Output
You should print n values separated by spaces. The i-th value should represent number of polygon's sections after drawing first i lines.
Examples
Input
5 2
Output
2 3 5 8 11
Input
10 3
Output
2 3 4 6 9 12 16 21 26 31
Note
The greatest common divisor (gcd) of two integers a and b is the largest positive integer that divides both a and b without a remainder.
For the first sample testcase, you should output "2 3 5 8 11". Pictures below correspond to situations after drawing lines.
<image> <image> <image> <image> <image> <image>
Submitted Solution:
```
n, k = map(int, input().split())
cur = 0
parts = 1
cycles = 0
for step in range(n):
parts += 1 + 2 * cycles
if (cur + k) > n:
parts += 1
cycles += 1
cur = (cur + k) % n
print(parts, end = ' ')
print()
``` | instruction | 0 | 20,811 | 23 | 41,622 |
No | output | 1 | 20,811 | 23 | 41,623 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a set of n vectors on a plane. For each vector you are allowed to multiply any of its coordinates by -1. Thus, each vector vi = (xi, yi) can be transformed into one of the following four vectors:
* vi1 = (xi, yi),
* vi2 = ( - xi, yi),
* vi3 = (xi, - yi),
* vi4 = ( - xi, - yi).
You should find two vectors from the set and determine which of their coordinates should be multiplied by -1 so that the absolute value of the sum of the resulting vectors was minimally possible. More formally, you should choose two vectors vi, vj (1 β€ i, j β€ n, i β j) and two numbers k1, k2 (1 β€ k1, k2 β€ 4), so that the value of the expression |vik1 + vjk2| were minimum.
Input
The first line contains a single integer n (2 β€ n β€ 105). Then n lines contain vectors as pairs of integers "xi yi" ( - 10000 β€ xi, yi β€ 10000), one pair per line.
Output
Print on the first line four space-separated numbers "i k1 j k2" β the answer to the problem. If there are several variants the absolute value of whose sums is minimum, you can print any of them.
Examples
Input
5
-7 -3
9 0
-8 6
7 -8
4 -5
Output
3 2 4 2
Input
5
3 2
-4 7
-6 0
-8 4
5 1
Output
3 4 5 4
Note
A sum of two vectors v = (xv, yv) and u = (xu, yu) is vector s = v + u = (xv + xu, yv + yu).
An absolute value of vector v = (x, y) is number <image>.
In the second sample there are several valid answers, such as:
(3 1 4 2), (3 1 4 4), (3 4 4 1), (3 4 4 3), (4 1 3 2), (4 1 3 4), (4 2 3 1).
Submitted Solution:
```
dx = [1,-1,1,-1]
dy = [1,1,-1,-1]
def conv(x,y,idx):
d = (1e18-x)**2 + (1e18-y)**2
ret = []
for i in range(4):
ret.append((d,x*dx[i],y*dy[i],i+1,idx))
return ret
inpt = open("input.txt","r")
otpt = open("output.txt","w")
p = []
n = int(inpt.readline())
for i in range(n):
inp = inpt.readline().split()
trt = conv(int(inp[0]),int(inp[1]),i+1)
p.extend(trt)
p.sort()
mn = 1e40
ans1 = (0,0,0,0,0)
ans2 = (0,0,0,0,0)
for i in range(len(p)):
cnt =0
for j in range(i+1,len(p)):
if cnt>100:
break
cnt = cnt + 1
if p[i][4]== p[j][4]:
continue
d = (p[i][1] - p[j][1])**2 + (p[i][2] - p[j][2])**2
if d < mn :
mn = d
ans1 = p[i]
ans2 = p[j]
otpt.write(str(ans1[4])+" ")
otpt.write(str(ans1[3])+" ")
otpt.write(str(ans2[4])+" ")
otpt.write(str(ans2[3])+"\n")
inpt.close()
otpt.close()
``` | instruction | 0 | 21,277 | 23 | 42,554 |
No | output | 1 | 21,277 | 23 | 42,555 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a set of n vectors on a plane. For each vector you are allowed to multiply any of its coordinates by -1. Thus, each vector vi = (xi, yi) can be transformed into one of the following four vectors:
* vi1 = (xi, yi),
* vi2 = ( - xi, yi),
* vi3 = (xi, - yi),
* vi4 = ( - xi, - yi).
You should find two vectors from the set and determine which of their coordinates should be multiplied by -1 so that the absolute value of the sum of the resulting vectors was minimally possible. More formally, you should choose two vectors vi, vj (1 β€ i, j β€ n, i β j) and two numbers k1, k2 (1 β€ k1, k2 β€ 4), so that the value of the expression |vik1 + vjk2| were minimum.
Input
The first line contains a single integer n (2 β€ n β€ 105). Then n lines contain vectors as pairs of integers "xi yi" ( - 10000 β€ xi, yi β€ 10000), one pair per line.
Output
Print on the first line four space-separated numbers "i k1 j k2" β the answer to the problem. If there are several variants the absolute value of whose sums is minimum, you can print any of them.
Examples
Input
5
-7 -3
9 0
-8 6
7 -8
4 -5
Output
3 2 4 2
Input
5
3 2
-4 7
-6 0
-8 4
5 1
Output
3 4 5 4
Note
A sum of two vectors v = (xv, yv) and u = (xu, yu) is vector s = v + u = (xv + xu, yv + yu).
An absolute value of vector v = (x, y) is number <image>.
In the second sample there are several valid answers, such as:
(3 1 4 2), (3 1 4 4), (3 4 4 1), (3 4 4 3), (4 1 3 2), (4 1 3 4), (4 2 3 1).
Submitted Solution:
```
print("ok")
``` | instruction | 0 | 21,278 | 23 | 42,556 |
No | output | 1 | 21,278 | 23 | 42,557 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a set of n vectors on a plane. For each vector you are allowed to multiply any of its coordinates by -1. Thus, each vector vi = (xi, yi) can be transformed into one of the following four vectors:
* vi1 = (xi, yi),
* vi2 = ( - xi, yi),
* vi3 = (xi, - yi),
* vi4 = ( - xi, - yi).
You should find two vectors from the set and determine which of their coordinates should be multiplied by -1 so that the absolute value of the sum of the resulting vectors was minimally possible. More formally, you should choose two vectors vi, vj (1 β€ i, j β€ n, i β j) and two numbers k1, k2 (1 β€ k1, k2 β€ 4), so that the value of the expression |vik1 + vjk2| were minimum.
Input
The first line contains a single integer n (2 β€ n β€ 105). Then n lines contain vectors as pairs of integers "xi yi" ( - 10000 β€ xi, yi β€ 10000), one pair per line.
Output
Print on the first line four space-separated numbers "i k1 j k2" β the answer to the problem. If there are several variants the absolute value of whose sums is minimum, you can print any of them.
Examples
Input
5
-7 -3
9 0
-8 6
7 -8
4 -5
Output
3 2 4 2
Input
5
3 2
-4 7
-6 0
-8 4
5 1
Output
3 4 5 4
Note
A sum of two vectors v = (xv, yv) and u = (xu, yu) is vector s = v + u = (xv + xu, yv + yu).
An absolute value of vector v = (x, y) is number <image>.
In the second sample there are several valid answers, such as:
(3 1 4 2), (3 1 4 4), (3 4 4 1), (3 4 4 3), (4 1 3 2), (4 1 3 4), (4 2 3 1).
Submitted Solution:
```
# Author nitish420 ------------------------------------------
from math import sqrt
class Point:
def __init__(self,x,y):
self.x=x
self.y=y
def main():
inp=open("input.txt","r")
opt=open("output.txt","w")
n=int(inp.readline())
dd=dict()
points=[]
global ansdist,anspoints
anspoints=[]
ansdist=float('inf')
for i in range(n):
a,b=map(int,inp.readline().split())
if a<0 and b<0:
a=abs(a)
b=abs(b)
dd[(a,b)]=[4]
elif a<0:
a=abs(a)
dd[(a,b)]=[2]
elif b<0:
b=abs(b)
dd[(a,b)]=[3]
else:
dd[(a,b)]=[1]
dd[(a,b)].append(i)
points.append(Point(a,b))
points.sort(key=lambda p:p.x)
ypoints=points.copy()
ypoints.sort(key=lambda p:p.y)
def sqdist(p,q):
global ansdist,anspoints
val=(p.x-q.x)**2+(p.y-q.y)**2
val=sqrt(val)
if val<ansdist:
ansdist=val
anspoints=[p,q]
return val
def midStripClosest(pnts,sz,d):
val=d
for i in range(sz):
j=i+1
while j<sz and pnts[j].y-pnts[i].y<val:
val=sqdist(pnts[i],pnts[j])
j+=1
return val
def bruteForce(l,r):
val=float('inf')
for i in range(l,r+1):
for j in range(i+1,r+1):
dst=sqdist(points[i],points[j])
if dst<val:
val=dst
return val
def cloasestUtil(l,r):
nn=r-l+1
if nn<=3:
return bruteForce(l,r)
mid=l+(r-l)//2
dl=cloasestUtil(l,mid)
dr=cloasestUtil(mid,r)
d=min(dl,dr)
midpoints=[]
ymidpoints=[]
for i in range(l,r):
if abs(points[i].x-points[mid].x)<d:
midpoints.append(points[i])
if abs(ypoints[i].x-points[mid].x)<d:
ymidpoints.append(ypoints[i])
midpoints.sort(key=lambda p:p.y)
min_a=min(d,midStripClosest(midpoints,len(midpoints),d))
min_b=min(d,midStripClosest(ymidpoints,len(ymidpoints),d))
return min(min_a,min_b)
cloasestUtil(0,n-1)
zzz=int()
kkk=dd[(anspoints[1].x,anspoints[1].y)][0]
if kkk==1:
zzz=4
elif kkk==2:
zzz=3
elif kkk==3:
zzz=2
else:
zzz=1
opt.write(str(dd[(anspoints[0].x,anspoints[0].y)][1]+1)+" ")
opt.write(str(dd[(anspoints[0].x,anspoints[0].y)][0])+" ")
opt.write(str(dd[(anspoints[1].x,anspoints[1].y)][1]+1)+" ")
opt.write(str(zzz)+"\n")
inp.close()
opt.close()
main()
``` | instruction | 0 | 21,279 | 23 | 42,558 |
No | output | 1 | 21,279 | 23 | 42,559 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a set of n vectors on a plane. For each vector you are allowed to multiply any of its coordinates by -1. Thus, each vector vi = (xi, yi) can be transformed into one of the following four vectors:
* vi1 = (xi, yi),
* vi2 = ( - xi, yi),
* vi3 = (xi, - yi),
* vi4 = ( - xi, - yi).
You should find two vectors from the set and determine which of their coordinates should be multiplied by -1 so that the absolute value of the sum of the resulting vectors was minimally possible. More formally, you should choose two vectors vi, vj (1 β€ i, j β€ n, i β j) and two numbers k1, k2 (1 β€ k1, k2 β€ 4), so that the value of the expression |vik1 + vjk2| were minimum.
Input
The first line contains a single integer n (2 β€ n β€ 105). Then n lines contain vectors as pairs of integers "xi yi" ( - 10000 β€ xi, yi β€ 10000), one pair per line.
Output
Print on the first line four space-separated numbers "i k1 j k2" β the answer to the problem. If there are several variants the absolute value of whose sums is minimum, you can print any of them.
Examples
Input
5
-7 -3
9 0
-8 6
7 -8
4 -5
Output
3 2 4 2
Input
5
3 2
-4 7
-6 0
-8 4
5 1
Output
3 4 5 4
Note
A sum of two vectors v = (xv, yv) and u = (xu, yu) is vector s = v + u = (xv + xu, yv + yu).
An absolute value of vector v = (x, y) is number <image>.
In the second sample there are several valid answers, such as:
(3 1 4 2), (3 1 4 4), (3 4 4 1), (3 4 4 3), (4 1 3 2), (4 1 3 4), (4 2 3 1).
Submitted Solution:
```
dx = [1,-1,1,-1]
dy = [1,1,-1,-1]
mx = int(1e28)
def conv(x,y,idx):
d = int((mx-x)**2 + (mx-y)**2)
ret = []
for i in range(4):
ret.append((-d,x*dx[i],y*dy[i],i+1,idx))
return ret
inpt = open("input.txt","r")
otpt = open("output.txt","w")
p = []
n = int(inpt.readline())
for i in range(n):
inp = inpt.readline().split()
trt = conv(int(inp[0]),int(inp[1]),i+1)
p.extend(trt)
p.sort()
mn = 1e40
ans1 = (0,0,0,0,0)
ans2 = (0,0,0,0,0)
for i in range(len(p)):
cnt =0
for j in range(i+1,len(p)):
if cnt>100:
break
cnt = cnt + 1
if p[i][4]== p[j][4]:
continue
d = (p[i][1] - p[j][1])**2 + (p[i][2] - p[j][2])**2
if d < mn :
mn = d
ans1 = p[i]
ans2 = p[j]
fuck = ans2[3]
fuck = (4-fuck)%4+1
otpt.write(str(ans1[4])+" ")
otpt.write(str(ans1[3])+" ")
otpt.write(str(ans2[4])+" ")
otpt.write(str(fuck)+"\n")
inpt.close()
otpt.close()
``` | instruction | 0 | 21,280 | 23 | 42,560 |
No | output | 1 | 21,280 | 23 | 42,561 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Petya learns how to write. The teacher gave pupils the task to write the letter A on the sheet of paper. It is required to check whether Petya really had written the letter A.
You are given three segments on the plane. They form the letter A if the following conditions hold:
* Two segments have common endpoint (lets call these segments first and second), while the third segment connects two points on the different segments.
* The angle between the first and the second segments is greater than 0 and do not exceed 90 degrees.
* The third segment divides each of the first two segments in proportion not less than 1 / 4 (i.e. the ratio of the length of the shortest part to the length of the longest part is not less than 1 / 4).
Input
The first line contains one integer t (1 β€ t β€ 10000) β the number of test cases to solve. Each case consists of three lines. Each of these three lines contains four space-separated integers β coordinates of the endpoints of one of the segments. All coordinates do not exceed 108 by absolute value. All segments have positive length.
Output
Output one line for each test case. Print Β«YESΒ» (without quotes), if the segments form the letter A and Β«NOΒ» otherwise.
Examples
Input
3
4 4 6 0
4 1 5 2
4 0 4 4
0 0 0 6
0 6 2 -4
1 1 0 1
0 0 0 5
0 5 2 -1
1 2 0 1
Output
YES
NO
YES | instruction | 0 | 21,379 | 23 | 42,758 |
Tags: geometry, implementation
Correct Solution:
```
""" A : Determine if three line segments form A """
def cross(vecA, vecB):
return vecA[0] * vecB[1] - vecA[1] * vecB[0]
def dot(vecA, vecB):
return vecA[0] * vecB[0] + vecA[1] * vecB[1]
def angle(lineA, lineB):
x1, y1 = (lineA[0][0] - lineA[1][0], lineA[0][1] - lineA[1][1])
x2, y2 = (lineB[0][0] - lineB[1][0], lineB[0][1] - lineB[1][1])
d1 = (x1 ** 2 + y1 ** 2) ** 0.5
d2 = (x2 ** 2 + y2 ** 2) ** 0.5
return (x1 * x2 + y1 * y2) / (d1*d2)
def div_ratio(line, point):
# Simple way to approximately check if the point lies on the line
mx, my = point
(a, b), (c, d) = line
if not (min(a, c) <= mx <= max(a, c) and min(b, d) <= my <= max(b, d)):
return -1
# Again make sure the point lies on the line
vecA = (a - mx, b - my)
vecB = (a - c, b - d)
if cross(vecA, vecB) != 0:
return -1
# Finally compute the ratio
if c == a and d == b: return -1
if d != b:
ratio = (my - b) / (d - b)
if a != c:
ratio = (mx - a) / (c - a)
if ratio < 0.2 or ratio > 0.8:
ratio = -1
return ratio
def isA(lines):
""" Given three line segments check if they form A of not"""
# Find the two slanted line segments
k, l = -1, -1
lines_found = False
for i in range(3):
if lines_found: break
temp = set(lines[i])
for j in range(i + 1, 3):
# Check which of the two points is the common point
if lines[j][0] in temp:
common = lines[j][0]
k, l = i, j
lines_found = True
break
if not lines_found and lines[j][1] in temp:
common = lines[j][1]
k, l = i, j
lines_found = True
break
if not lines_found: return False
# Process the lines
lineA = lines[k]
if lineA[0] != common:
lineA = [lineA[1], lineA[0]]
lineB = lines[l]
if lineB[0] != common:
lineB = [lineB[1], lineB[0]]
# Check the angle between two lines. Must be greater than 0 and less than 90
degree = angle(lineA, lineB)
# print("Degree ", degree)
if degree < 0 or degree >= 1: return False
# The third is the line connecting two slanted line segments
divider = lines[3 - k - l]
# If first point of divider does not divide (or lie on) either of the line segments, it does not form A
thresh = 0.2 # Converted 1/4 to 1/5 in another metric
r1 = div_ratio(lineA, divider[0])
if r1 == -1:
r2 = div_ratio(lineB, divider[0]) # div[0] lies on lineB
if r2 == -1: return False
r1 = div_ratio(lineA, divider[1]) # div[1] lies on lineA
if r1 == -1: return False
else:
r2 = div_ratio(lineB, divider[1])
if r2 == -1: return False
# For everything else
return True
def CF14C():
N = int(input())
result = []
for _ in range(N):
lines = []
for _ in range(3):
a, b, c, d = map(int, input().split())
lines.append(((a, b), (c, d)))
res = isA(lines)
result.append("YES" if res else "NO")
return result
res = CF14C()
print("\n".join(res))
``` | output | 1 | 21,379 | 23 | 42,759 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Petya learns how to write. The teacher gave pupils the task to write the letter A on the sheet of paper. It is required to check whether Petya really had written the letter A.
You are given three segments on the plane. They form the letter A if the following conditions hold:
* Two segments have common endpoint (lets call these segments first and second), while the third segment connects two points on the different segments.
* The angle between the first and the second segments is greater than 0 and do not exceed 90 degrees.
* The third segment divides each of the first two segments in proportion not less than 1 / 4 (i.e. the ratio of the length of the shortest part to the length of the longest part is not less than 1 / 4).
Input
The first line contains one integer t (1 β€ t β€ 10000) β the number of test cases to solve. Each case consists of three lines. Each of these three lines contains four space-separated integers β coordinates of the endpoints of one of the segments. All coordinates do not exceed 108 by absolute value. All segments have positive length.
Output
Output one line for each test case. Print Β«YESΒ» (without quotes), if the segments form the letter A and Β«NOΒ» otherwise.
Examples
Input
3
4 4 6 0
4 1 5 2
4 0 4 4
0 0 0 6
0 6 2 -4
1 1 0 1
0 0 0 5
0 5 2 -1
1 2 0 1
Output
YES
NO
YES | instruction | 0 | 21,381 | 23 | 42,762 |
Tags: geometry, implementation
Correct Solution:
```
import sys
input = sys.stdin.buffer.readline
def dot(a,b):
return a[0]*b[0] + a[1]*b[1]
for _ in range(int(input())):
points = [list(map(int,input().split())) for i in range(3)]
points = [[points[i][:2],points[i][2:]] for i in range(3)]
diff = [[[points[i][ti^1][k] - points[i][ti][k] for k in range(2)] for ti in range(2)] for i in range(3)]
worked = 0
for i in range(3):
for j in range(3):
if i != j:
for ti in range(2):
for tj in range(2):
if points[i][ti] == points[j][tj]: # common endpoint
if 0 <= dot(diff[i][ti], diff[j][tj]) and \
dot(diff[i][ti], diff[j][tj])**2 < (diff[i][ti][0]**2 + diff[i][ti][1]**2)*(diff[j][tj][0]**2 + diff[j][tj][1]**2): # (0-90] degrees
#print(i,ti,j,tj)
# k = the other line
k = (i+1)%3
if k == j:
k = (k+1)%3
# check that 3rd seg has 1 point in common and 1/4 ratio
check = [i,j]
work_both = 1
for a in check:
work = 0
for tk in range(2):
if (points[k][tk][0] - points[a][0][0]) * diff[a][0][1] == \
(points[k][tk][1] - points[a][0][1]) * diff[a][0][0]\
and min(points[a][0][0],points[a][1][0]) <= points[k][tk][0] <= max(points[a][0][0],points[a][1][0]): # on line
delta_x = []
for ta in range(2):
delta_x.append(abs(points[a][ta][0]-points[k][tk][0]))
if delta_x == [0,0]: # edge case of vertical line
delta_x = []
for ta in range(2):
delta_x.append(abs(points[a][ta][1] - points[k][tk][1]))
delta_x.sort()
if 4*delta_x[0] >= delta_x[1]: # >= 1/4 ratio
#print(delta_x)
work = 1
if not work:
work_both = 0
if work_both:
worked = 1
if worked:
print("YES")
else:
print("NO")
``` | output | 1 | 21,381 | 23 | 42,763 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Petya learns how to write. The teacher gave pupils the task to write the letter A on the sheet of paper. It is required to check whether Petya really had written the letter A.
You are given three segments on the plane. They form the letter A if the following conditions hold:
* Two segments have common endpoint (lets call these segments first and second), while the third segment connects two points on the different segments.
* The angle between the first and the second segments is greater than 0 and do not exceed 90 degrees.
* The third segment divides each of the first two segments in proportion not less than 1 / 4 (i.e. the ratio of the length of the shortest part to the length of the longest part is not less than 1 / 4).
Input
The first line contains one integer t (1 β€ t β€ 10000) β the number of test cases to solve. Each case consists of three lines. Each of these three lines contains four space-separated integers β coordinates of the endpoints of one of the segments. All coordinates do not exceed 108 by absolute value. All segments have positive length.
Output
Output one line for each test case. Print Β«YESΒ» (without quotes), if the segments form the letter A and Β«NOΒ» otherwise.
Examples
Input
3
4 4 6 0
4 1 5 2
4 0 4 4
0 0 0 6
0 6 2 -4
1 1 0 1
0 0 0 5
0 5 2 -1
1 2 0 1
Output
YES
NO
YES | instruction | 0 | 21,382 | 23 | 42,764 |
Tags: geometry, implementation
Correct Solution:
```
#13B - Letter A
import math
r = lambda: map(int,input().split())
#Function to check if the lines cross
def cross(a, b):
return a[0] * b[1] - a[1] * b[0]
def dot(a, b):
return a[0] * b[0] + a[1] * b[1]
# def l(v):
# return math.hypot(*v)
def on_line(a, b):
return dot(a, b) > 0 and cross(a, b) == 0 and abs(b[0]) <= abs(5 * a[0]) <= abs(4 * b[0]) and abs(b[1]) <= abs(5 * a[1]) <= abs(4 * b[1])
def is_A(a, b, c):
a, b = set(a), set(b)
if len(a & b) != 1:
return False
p1, = a & b
p2, p3 = a ^ b
v1 = (p2[0] - p1[0], p2[1] - p1[1])
v2 = (p3[0] - p1[0], p3[1] - p1[1])
if dot(v1, v2) < 0 or abs(cross(v1, v2)) == 0:
return False
v3 = (c[0][0] - p1[0], c[0][1] - p1[1])
v4 = (c[1][0] - p1[0], c[1][1] - p1[1])
return (on_line(v3, v1) and on_line(v4, v2)) or (on_line(v3, v2) and on_line(v4, v1))
for i in range(int(input())):
xa1, ya1, xa2, ya2 = r()
xb1, yb1, xb2, yb2 = r()
xc1, yc1, xc2, yc2 = r()
a, b, c = [(xa1, ya1), (xa2, ya2)], [(xb1, yb1), (xb2, yb2)], [(xc1, yc1), (xc2, yc2)]
print ("YES" if is_A(a, b, c) or is_A(a, c, b) or is_A(b, c, a) else "NO")
``` | output | 1 | 21,382 | 23 | 42,765 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Petya learns how to write. The teacher gave pupils the task to write the letter A on the sheet of paper. It is required to check whether Petya really had written the letter A.
You are given three segments on the plane. They form the letter A if the following conditions hold:
* Two segments have common endpoint (lets call these segments first and second), while the third segment connects two points on the different segments.
* The angle between the first and the second segments is greater than 0 and do not exceed 90 degrees.
* The third segment divides each of the first two segments in proportion not less than 1 / 4 (i.e. the ratio of the length of the shortest part to the length of the longest part is not less than 1 / 4).
Input
The first line contains one integer t (1 β€ t β€ 10000) β the number of test cases to solve. Each case consists of three lines. Each of these three lines contains four space-separated integers β coordinates of the endpoints of one of the segments. All coordinates do not exceed 108 by absolute value. All segments have positive length.
Output
Output one line for each test case. Print Β«YESΒ» (without quotes), if the segments form the letter A and Β«NOΒ» otherwise.
Examples
Input
3
4 4 6 0
4 1 5 2
4 0 4 4
0 0 0 6
0 6 2 -4
1 1 0 1
0 0 0 5
0 5 2 -1
1 2 0 1
Output
YES
NO
YES | instruction | 0 | 21,384 | 23 | 42,768 |
Tags: geometry, implementation
Correct Solution:
```
import random
from math import sqrt as s
def dist(x1, y1, x2, y2):
return s((x2 - x1) ** 2 + (y2 - y1) ** 2)
def is_dot_on_line(c1, c2, dot):
A = c1[1] - c2[1]
B = c2[0] - c1[0]
C = c1[0] * c2[1] - c2[0] * c1[1]
maxx, minx = max(c1[0], c2[0]), min(c1[0], c2[0])
maxy, miny = max(c1[1], c2[1]), min(c1[1], c2[1])
res = A * dot[0] + B * dot[1] + C
if res == 0 and minx <= dot[0] <= maxx and miny <= dot[1] <= maxy:
return True
return False
def cosangle(x1, y1, x2, y2):
return x1 * x2 + y1 * y2
def same(k11, k12, k21, k22, k31, k32):
if k11 == k21 or k11 == k22 or k12 == k21 or k12 == k22:
return 0, 1, 2
if k11 == k31 or k11 == k32 or k12 == k31 or k12 == k32:
return 0, 2, 1
if k21 == k31 or k21 == k32 or k22 == k31 or k22 == k32:
return 1, 2, 0
return False
def is_a(c1, c2, c3, debug=-1):
al = [c1, c2, c3]
lines = same(*c1, *c2, *c3)
if not lines:
return False
c1, c2, c3 = al[lines[0]], al[lines[1]], al[lines[2]]
if c1[0] == c2[1]:
c2[0], c2[1] = c2[1], c2[0]
if c1[1] == c2[0]:
c1[0], c1[1] = c1[1], c1[0]
if not (is_dot_on_line(c1[0], c1[1], c3[0]) and is_dot_on_line(c2[0], c2[1], c3[1])):
if not (is_dot_on_line(c1[0], c1[1], c3[1]) and is_dot_on_line(c2[0], c2[1], c3[0])):
return False
c3[0], c3[1] = c3[1], c3[0]
cosa = cosangle(c1[0][0] - c1[1][0],
c1[0][1] - c1[1][1],
c2[0][0] - c2[1][0],
c2[0][1] - c2[1][1])
if cosa < 0:
return False
l1 = dist(*c1[0], *c3[0]), dist(*c1[1], *c3[0])
l2 = dist(*c2[0], *c3[1]), dist(*c2[1], *c3[1])
if min(l1) / max(l1) < 1/4 or min(l2) / max(l2) < 1/4:
return False
return True
n = int(input())
for i in range(n):
c1 = list(map(int, input().split()))
c2 = list(map(int, input().split()))
c3 = list(map(int, input().split()))
if is_a([c1[:2], c1[2:]], [c2[:2], c2[2:]], [c3[:2], c3[2:]], debug=i):
print("YES")
else:
print("NO")
``` | output | 1 | 21,384 | 23 | 42,769 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Petya learns how to write. The teacher gave pupils the task to write the letter A on the sheet of paper. It is required to check whether Petya really had written the letter A.
You are given three segments on the plane. They form the letter A if the following conditions hold:
* Two segments have common endpoint (lets call these segments first and second), while the third segment connects two points on the different segments.
* The angle between the first and the second segments is greater than 0 and do not exceed 90 degrees.
* The third segment divides each of the first two segments in proportion not less than 1 / 4 (i.e. the ratio of the length of the shortest part to the length of the longest part is not less than 1 / 4).
Input
The first line contains one integer t (1 β€ t β€ 10000) β the number of test cases to solve. Each case consists of three lines. Each of these three lines contains four space-separated integers β coordinates of the endpoints of one of the segments. All coordinates do not exceed 108 by absolute value. All segments have positive length.
Output
Output one line for each test case. Print Β«YESΒ» (without quotes), if the segments form the letter A and Β«NOΒ» otherwise.
Examples
Input
3
4 4 6 0
4 1 5 2
4 0 4 4
0 0 0 6
0 6 2 -4
1 1 0 1
0 0 0 5
0 5 2 -1
1 2 0 1
Output
YES
NO
YES
Submitted Solution:
```
def distance(a, b, c, d):
return (d - b) ** 2 + (c - a) ** 2
def slope(x1, y1, x2, y2):
if x1 != x2: return (y2 - y1) / (x2 - x1)
return float('inf')
def div_ratio(line, point):
mx, my = point
(a, b), (c, d) = line
if slope(a, b, mx, my) != slope(c, d, mx, my):
return -1
d1 = distance(a, b, mx, my)
d2 = distance(c, d, mx, my)
if d1 < d2:
ratio = d1 / d2
else:
ratio = d2 / d1
return ratio
def isA(lines):
""" Given three line segments check if they form A of not"""
# Find the two slanted line segments
k, l = -1, -1
lines_found = False
for i in range(3):
temp = set(lines[i])
for j in range(i + 1, 3):
# Check which of the two points is the common point
if lines[j][0] in temp:
common = lines[j][0]
k, l = i, j
lines_found = True
break
if lines[j][1] in temp:
common = lines[j][1]
k, l = i, j
lines_found = True
break
else:
return False # Cause no common point was found
if lines_found: break
# Process the lines
lineA = lines[k]
if lineA[0] != common:
lineA = [lineA[1], lineA[0]]
lineB = lines[l]
if lineB[0] != common:
lineB = [lineB[1], lineB[0]]
# The third is the line connecting two slanted line segments
divider = lines[3 - k - l]
# If first point of divider does not divide (or lie on) either of the line segments, it does not form A
thresh = 0.0625 # 0.25 * 0.25 = 0.0625
r1 = div_ratio(lineA, divider[0])
if r1 != -1 and r1 < thresh:
return False
elif r1 == -1:
r2 = div_ratio(lineB, divider[0]) # div[0] lies on lineB
if r2 < thresh: return False
r3 = div_ratio(lineA, divider[1]) # div[1] lies on lineA
if r3 < thresh: return False
elif r1 >= thresh:
r2 = div_ratio(lineB, divider[1])
if r2 < thresh: return False
# For everything else
return True
def CF14C():
N = int(input())
result = []
for _ in range(N):
lines = []
for _ in range(3):
a, b, c, d = map(int, input().split())
lines.append(((a, b), (c, d)))
res = isA(lines)
result.append("YES" if res else "NO")
return result
res = CF14C()
print("\n".join(res))
``` | instruction | 0 | 21,385 | 23 | 42,770 |
No | output | 1 | 21,385 | 23 | 42,771 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Petya learns how to write. The teacher gave pupils the task to write the letter A on the sheet of paper. It is required to check whether Petya really had written the letter A.
You are given three segments on the plane. They form the letter A if the following conditions hold:
* Two segments have common endpoint (lets call these segments first and second), while the third segment connects two points on the different segments.
* The angle between the first and the second segments is greater than 0 and do not exceed 90 degrees.
* The third segment divides each of the first two segments in proportion not less than 1 / 4 (i.e. the ratio of the length of the shortest part to the length of the longest part is not less than 1 / 4).
Input
The first line contains one integer t (1 β€ t β€ 10000) β the number of test cases to solve. Each case consists of three lines. Each of these three lines contains four space-separated integers β coordinates of the endpoints of one of the segments. All coordinates do not exceed 108 by absolute value. All segments have positive length.
Output
Output one line for each test case. Print Β«YESΒ» (without quotes), if the segments form the letter A and Β«NOΒ» otherwise.
Examples
Input
3
4 4 6 0
4 1 5 2
4 0 4 4
0 0 0 6
0 6 2 -4
1 1 0 1
0 0 0 5
0 5 2 -1
1 2 0 1
Output
YES
NO
YES
Submitted Solution:
```
""" A : Determine if three line segments form A """
def cross(vecA, vecB):
return vecA[0] * vecB[1] - vecA[1] * vecB[0]
def dot(vecA, vecB):
return vecA[0] * vecB[0] + vecA[1] * vecB[1]
def slope(x1, y1, x2, y2):
if x1 != x2: return (y2 - y1) / (x2 - x1)
return float('inf')
def div_ratio(line, point):
# Simple way to approximately check if the point lies on the line
mx, my = point
(a, b), (c, d) = line
print("Min check nai pass vayena")
if not (min(a, c) <= mx <= max(a, c) and min(b, d) <= my <= max(b, d)):
return -1
# Again make sure the point lies on the line
vecA = (a - mx, b - my)
vecB = (a - c, b - d)
if cross(vecA, vecB) != 0:
print("Area 0")
return -1
# Finally compute the ratio
if c == a and d == b: return -1
if d != b:
ratio = (my - b) / (d - b)
if a != c:
ratio = (mx - a) / (c - a)
if ratio < 0.2 or ratio > 0.8:
ratio = -1
print("LPR : ", line, point, ratio)
return ratio
def isA(lines):
""" Given three line segments check if they form A of not"""
# Find the two slanted line segments
k, l = -1, -1
lines_found = False
for i in range(3):
temp = set(lines[i])
for j in range(i + 1, 3):
# Check which of the two points is the common point
if lines[j][0] in temp:
common = lines[j][0]
k, l = i, j
lines_found = True
break
if lines[j][1] in temp:
common = lines[j][1]
k, l = i, j
lines_found = True
break
else:
# print("No common point found")
return False # Cause no common point was found
if lines_found: break
# Process the lines
lineA = lines[k]
if lineA[0] != common:
lineA = [lineA[1], lineA[0]]
lineB = lines[l]
if lineB[0] != common:
lineB = [lineB[1], lineB[0]]
# The third is the line connecting two slanted line segments
divider = lines[3 - k - l]
# If first point of divider does not divide (or lie on) either of the line segments, it does not form A
thresh = 0.0625 # 0.25 * 0.25 = 0.0625
thresh = 0.2
r1 = div_ratio(lineA, divider[0])
if r1 == -1:
r2 = div_ratio(lineB, divider[0]) # div[0] lies on lineB
if r2 == -1: return False
r1 = div_ratio(lineA, divider[1]) # div[1] lies on lineA
if r1 == -1: return False
else:
r2 = div_ratio(lineB, divider[1])
if r2 == -1: return False
# For everything else
return True
def CF14C():
N = int(input())
result = []
for _ in range(N):
lines = []
for _ in range(3):
a, b, c, d = map(int, input().split())
lines.append(((a, b), (c, d)))
res = isA(lines)
result.append("YES" if res else "NO")
return result
res = CF14C()
print("\n".join(res))
``` | instruction | 0 | 21,386 | 23 | 42,772 |
No | output | 1 | 21,386 | 23 | 42,773 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Petya learns how to write. The teacher gave pupils the task to write the letter A on the sheet of paper. It is required to check whether Petya really had written the letter A.
You are given three segments on the plane. They form the letter A if the following conditions hold:
* Two segments have common endpoint (lets call these segments first and second), while the third segment connects two points on the different segments.
* The angle between the first and the second segments is greater than 0 and do not exceed 90 degrees.
* The third segment divides each of the first two segments in proportion not less than 1 / 4 (i.e. the ratio of the length of the shortest part to the length of the longest part is not less than 1 / 4).
Input
The first line contains one integer t (1 β€ t β€ 10000) β the number of test cases to solve. Each case consists of three lines. Each of these three lines contains four space-separated integers β coordinates of the endpoints of one of the segments. All coordinates do not exceed 108 by absolute value. All segments have positive length.
Output
Output one line for each test case. Print Β«YESΒ» (without quotes), if the segments form the letter A and Β«NOΒ» otherwise.
Examples
Input
3
4 4 6 0
4 1 5 2
4 0 4 4
0 0 0 6
0 6 2 -4
1 1 0 1
0 0 0 5
0 5 2 -1
1 2 0 1
Output
YES
NO
YES
Submitted Solution:
```
import random
from math import sqrt as s
def dist(x1, y1, x2, y2):
return s((x2 - x1) ** 2 + (y2 - y1) ** 2)
def is_dot_on_line(c1, c2, dot):
if dist(*c1, *dot) + dist(*dot, *c2) - dist(*c1, *c2) <= 0.00000001:
return True
return False
def cosangle(x1, y1, x2, y2):
return x1 * x2 + y1 * y2
def same(k11, k12, k21, k22, k31, k32):
if k11 == k21 or k11 == k22 or k12 == k21 or k12 == k22:
return 0, 1, 2
if k11 == k31 or k11 == k32 or k12 == k31 or k12 == k32:
return 0, 2, 1
if k21 == k31 or k21 == k32 or k22 == k31 or k22 == k32:
return 1, 2, 0
return False
def is_a(c1, c2, c3, debug=-1):
al = [c1, c2, c3]
lines = same(*c1, *c2, *c3)
if not lines:
return False
c1, c2, c3 = al[lines[0]], al[lines[1]], al[lines[2]]
if c1[0] == c2[1]:
c2[0], c2[1] = c2[1], c2[0]
if c1[1] == c2[0]:
c1[0], c1[1] = c1[1], c1[0]
if not (is_dot_on_line(c1[0], c1[1], c3[0]) and is_dot_on_line(c2[0], c2[1], c3[1])):
if not (is_dot_on_line(c1[0], c1[1], c3[1]) and is_dot_on_line(c2[0], c2[1], c3[0])):
return False
c3[0], c3[1] = c3[1], c3[0]
cosa = cosangle(c1[0][0] - c1[1][0],
c1[0][1] - c1[1][1],
c2[0][0] - c2[1][0],
c2[0][1] - c2[1][1])
if cosa < 0:
return False
l1 = dist(*c1[0], *c3[0]), dist(*c1[1], *c3[0])
l2 = dist(*c2[0], *c3[1]), dist(*c2[1], *c3[1])
if min(l1) / max(l1) < 1/4 or min(l2) / max(l2) < 1/4:
return False
return True
n = int(input())
for i in range(n):
c1 = list(map(int, input().split()))
c2 = list(map(int, input().split()))
c3 = list(map(int, input().split()))
if is_a([c1[:2], c1[2:]], [c2[:2], c2[2:]], [c3[:2], c3[2:]], debug=i):
print("YES")
else:
print("NO")
``` | instruction | 0 | 21,387 | 23 | 42,774 |
No | output | 1 | 21,387 | 23 | 42,775 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Petya learns how to write. The teacher gave pupils the task to write the letter A on the sheet of paper. It is required to check whether Petya really had written the letter A.
You are given three segments on the plane. They form the letter A if the following conditions hold:
* Two segments have common endpoint (lets call these segments first and second), while the third segment connects two points on the different segments.
* The angle between the first and the second segments is greater than 0 and do not exceed 90 degrees.
* The third segment divides each of the first two segments in proportion not less than 1 / 4 (i.e. the ratio of the length of the shortest part to the length of the longest part is not less than 1 / 4).
Input
The first line contains one integer t (1 β€ t β€ 10000) β the number of test cases to solve. Each case consists of three lines. Each of these three lines contains four space-separated integers β coordinates of the endpoints of one of the segments. All coordinates do not exceed 108 by absolute value. All segments have positive length.
Output
Output one line for each test case. Print Β«YESΒ» (without quotes), if the segments form the letter A and Β«NOΒ» otherwise.
Examples
Input
3
4 4 6 0
4 1 5 2
4 0 4 4
0 0 0 6
0 6 2 -4
1 1 0 1
0 0 0 5
0 5 2 -1
1 2 0 1
Output
YES
NO
YES
Submitted Solution:
```
import random
from math import sqrt as s
def dist(x1, y1, x2, y2):
return s((x2 - x1) ** 2 + (y2 - y1) ** 2)
def is_dot_on_line(c1, c2, dot):
if dist(*c1, *dot) + dist(*dot, *c2) == dist(*c1, *c2):
return True
return False
def cosangle(x1, y1, x2, y2):
return x1 * x2 + y1 * y2
def same(k11, k12, k21, k22, k31, k32):
if k11 == k21 or k11 == k22 or k12 == k21 or k12 == k22:
return 0, 1, 2
if k11 == k31 or k11 == k32 or k12 == k31 or k12 == k32:
return 0, 2, 1
if k21 == k31 or k21 == k32 or k22 == k31 or k22 == k32:
return 1, 2, 0
return False
def is_a(c1, c2, c3, debug=-1):
al = [c1, c2, c3]
lines = same(*c1, *c2, *c3)
if not lines:
return False
c1, c2, c3 = al[lines[0]], al[lines[1]], al[lines[2]]
if c1[0] == c2[1]:
c2[0], c2[1] = c2[1], c2[0]
if c1[1] == c2[0]:
c1[0], c1[1] = c1[1], c1[0]
if not (is_dot_on_line(c1[0], c1[1], c3[0]) and is_dot_on_line(c2[0], c2[1], c3[1])):
if not (is_dot_on_line(c1[0], c1[1], c3[1]) and is_dot_on_line(c2[0], c2[1], c3[0])):
if i == 57:
print(c1, c2, c3, "NOT ON LINE")
return False
c3[0], c3[1] = c3[1], c3[0]
cosa = cosangle(c1[0][0] - c1[1][0],
c1[0][1] - c1[1][1],
c2[0][0] - c2[1][0],
c2[0][1] - c2[1][1])
if cosa < 0:
return False
l1 = dist(*c1[0], *c3[0]), dist(*c1[1], *c3[0])
l2 = dist(*c2[0], *c3[1]), dist(*c2[1], *c3[1])
if min(l1) / max(l1) < 1/4 or min(l2) / max(l2) < 1/4:
return False
return True
n = int(input())
for i in range(n):
c1 = list(map(int, input().split()))
c2 = list(map(int, input().split()))
c3 = list(map(int, input().split()))
if is_a([c1[:2], c1[2:]], [c2[:2], c2[2:]], [c3[:2], c3[2:]], debug=i):
print("YES")
else:
print("NO")
``` | instruction | 0 | 21,388 | 23 | 42,776 |
No | output | 1 | 21,388 | 23 | 42,777 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a rectangular grid of lattice points from (0, 0) to (n, m) inclusive. You have to choose exactly 4 different points to build a polyline possibly with self-intersections and self-touching. This polyline should be as long as possible.
A polyline defined by points p1, p2, p3, p4 consists of the line segments p1 p2, p2 p3, p3 p4, and its length is the sum of the lengths of the individual line segments.
Input
The only line of the input contains two integers n and m (0 β€ n, m β€ 1000). It is guaranteed that grid contains at least 4 different points.
Output
Print 4 lines with two integers per line separated by space β coordinates of points p1, p2, p3, p4 in order which represent the longest possible polyline.
Judge program compares your answer and jury's answer with 10 - 6 precision.
Examples
Input
1 1
Output
1 1
0 0
1 0
0 1
Input
0 10
Output
0 1
0 10
0 0
0 9 | instruction | 0 | 21,554 | 23 | 43,108 |
Tags: brute force, constructive algorithms, geometry, trees
Correct Solution:
```
n , m = map(int,input().split())
if n == 0 :
print (0, 1)
print (0, m)
print (0, 0)
print (0, m - 1)
elif m == 0 :
print (1, 0)
print (n, 0)
print (0, 0)
print (n - 1, 0)
elif m >= n :
if 2 * (m ** 2 + (n - 1) ** 2) ** 0.5 >= m + (m ** 2 + n ** 2) ** 0.5 :
print (1, 0)
print (n, m)
print (0, 0)
print (n - 1, m)
else :
print (n, m)
print (0, 0)
print (0, m)
print (n, 0)
else :
if 2 * ((m - 1) ** 2 + n ** 2) ** 0.5 >= n + (m ** 2 + n ** 2) ** 0.5 :
print (0, 1)
print (n, m)
print (0, 0)
print (n, m - 1)
else :
print (n, m)
print (0, 0)
print (n, 0)
print (0, m)
``` | output | 1 | 21,554 | 23 | 43,109 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a rectangular grid of lattice points from (0, 0) to (n, m) inclusive. You have to choose exactly 4 different points to build a polyline possibly with self-intersections and self-touching. This polyline should be as long as possible.
A polyline defined by points p1, p2, p3, p4 consists of the line segments p1 p2, p2 p3, p3 p4, and its length is the sum of the lengths of the individual line segments.
Input
The only line of the input contains two integers n and m (0 β€ n, m β€ 1000). It is guaranteed that grid contains at least 4 different points.
Output
Print 4 lines with two integers per line separated by space β coordinates of points p1, p2, p3, p4 in order which represent the longest possible polyline.
Judge program compares your answer and jury's answer with 10 - 6 precision.
Examples
Input
1 1
Output
1 1
0 0
1 0
0 1
Input
0 10
Output
0 1
0 10
0 0
0 9 | instruction | 0 | 21,555 | 23 | 43,110 |
Tags: brute force, constructive algorithms, geometry, trees
Correct Solution:
```
def dist(x1, y1, x2, y2):
return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
def ddist(a):
res = 0.0
for i in range(3):
res += dist(a[i][0], a[i][1], a[i + 1][0], a[i + 1][1])
return res;
n, m = map(int, input().split())
if (n == 0):
print("0 1")
print("0", m)
print(0, 0)
print(0, m - 1)
elif (m == 0):
print(1, 0)
print(n, 0)
print(0, 0)
print(n - 1, 0)
else:
aa = [[[n - 1, m], [0, 0], [n, m], [1, 0]], [[0, 1], [n, m], [0, 0], [n, m - 1]], [[0, 0], [n, m], [0, m], [n, 0]], [[n, m], [0, 0], [0, m], [n, 0]]]
a = max(aa, key = ddist)
for i in a:
print(i[0], i[1])
``` | output | 1 | 21,555 | 23 | 43,111 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a rectangular grid of lattice points from (0, 0) to (n, m) inclusive. You have to choose exactly 4 different points to build a polyline possibly with self-intersections and self-touching. This polyline should be as long as possible.
A polyline defined by points p1, p2, p3, p4 consists of the line segments p1 p2, p2 p3, p3 p4, and its length is the sum of the lengths of the individual line segments.
Input
The only line of the input contains two integers n and m (0 β€ n, m β€ 1000). It is guaranteed that grid contains at least 4 different points.
Output
Print 4 lines with two integers per line separated by space β coordinates of points p1, p2, p3, p4 in order which represent the longest possible polyline.
Judge program compares your answer and jury's answer with 10 - 6 precision.
Examples
Input
1 1
Output
1 1
0 0
1 0
0 1
Input
0 10
Output
0 1
0 10
0 0
0 9 | instruction | 0 | 21,556 | 23 | 43,112 |
Tags: brute force, constructive algorithms, geometry, trees
Correct Solution:
```
import math
n, m = map(int, input().split())
def check(a):
return 0 <= a[0] <= n and 0 <= a[1] <= m
def dist(a, b):
if not check(a) or not check(b):
return -1324345543
return math.hypot(0.0 + a[0] - b[0], a[1] - b[1] + 0.0)
points = [(0, 0), (n, m), (0, 1), (1, 0), (0, m), (n, 0), (n, 1), (m, 1), (n - 1, m - 1), (n - 2, m - 1), (0, m - 1),
(n - 1, 0),
(n - 2, 0), (n - 1, m - 2), (1, 1), (2, 2), (n - 2, m - 2), (2, 1), (1, 2),
(0, 0), (0, 1), (1, 0), (1, 1), (0, m), (0, m - 1), (0, m - 2), (1, m), (2, m),
(n, 0), (n, 1), (n, 2), (n - 1, 0), (n - 1, 1), (n - 2, 1)]
points = list(set([q if check(q) else (0, 0) for q in points]))
ans = 0
anns = []
for a in points:
for b in points:
for c in points:
for d in points:
if(len({a,b,c,d}))==4:
les = dist(a, b) + dist(b, c) + dist(c, d)
if les > ans:
ans = les
anns = [a, b, c, d]
for i in anns:
print(*i)
``` | output | 1 | 21,556 | 23 | 43,113 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a rectangular grid of lattice points from (0, 0) to (n, m) inclusive. You have to choose exactly 4 different points to build a polyline possibly with self-intersections and self-touching. This polyline should be as long as possible.
A polyline defined by points p1, p2, p3, p4 consists of the line segments p1 p2, p2 p3, p3 p4, and its length is the sum of the lengths of the individual line segments.
Input
The only line of the input contains two integers n and m (0 β€ n, m β€ 1000). It is guaranteed that grid contains at least 4 different points.
Output
Print 4 lines with two integers per line separated by space β coordinates of points p1, p2, p3, p4 in order which represent the longest possible polyline.
Judge program compares your answer and jury's answer with 10 - 6 precision.
Examples
Input
1 1
Output
1 1
0 0
1 0
0 1
Input
0 10
Output
0 1
0 10
0 0
0 9 | instruction | 0 | 21,557 | 23 | 43,114 |
Tags: brute force, constructive algorithms, geometry, trees
Correct Solution:
```
import math
a,b=map(int,input().split(' '))
if a==0:
print(0,' ',1)
print(0,' ',b)
print(0,' ',0)
print(0,' ',b-1)
elif b==0:
print(1,' ',0)
print(a,' ',0)
print(0,' ',0)
print(a-1,' ',0)
elif a>=b:
if math.sqrt(a**2+b**2)+a>2*math.sqrt(a**2+(b-1)**2):
print(0,' ',0)
print(a,' ',b)
print(0,' ',b)
print(a,' ',0)
else:
print(0,' ',1)
print(a,' ',b)
print(0,' ',0)
print(a,' ',b-1)
else:
if math.sqrt(a**2+b**2)+b>2*math.sqrt((a-1)**2+b**2):
print(0,' ',0)
print(a,' ',b)
print(a,' ',0)
print(0,' ',b)
else:
print(1,' ',0)
print(a,' ',b)
print(0,' ',0)
print(a-1,' ',b)
``` | output | 1 | 21,557 | 23 | 43,115 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a rectangular grid of lattice points from (0, 0) to (n, m) inclusive. You have to choose exactly 4 different points to build a polyline possibly with self-intersections and self-touching. This polyline should be as long as possible.
A polyline defined by points p1, p2, p3, p4 consists of the line segments p1 p2, p2 p3, p3 p4, and its length is the sum of the lengths of the individual line segments.
Input
The only line of the input contains two integers n and m (0 β€ n, m β€ 1000). It is guaranteed that grid contains at least 4 different points.
Output
Print 4 lines with two integers per line separated by space β coordinates of points p1, p2, p3, p4 in order which represent the longest possible polyline.
Judge program compares your answer and jury's answer with 10 - 6 precision.
Examples
Input
1 1
Output
1 1
0 0
1 0
0 1
Input
0 10
Output
0 1
0 10
0 0
0 9 | instruction | 0 | 21,558 | 23 | 43,116 |
Tags: brute force, constructive algorithms, geometry, trees
Correct Solution:
```
n, m = map(int, input().split())
A = set((i, j) for i in range(2) for j in range(2) if i <= n and j <= m)
A |= set((n - i, m - j) for i in range(2) for j in range(2) if i <= n and j <= m)
A |= set((i, m - j) for i in range(2) for j in range(2) if i <= n and j <= m)
A |= set((n - i, j) for i in range(2) for j in range(2) if i <= n and j <= m)
def dist2(a, b):
return (a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2
ans = sorted((dist2(p1, p2) + dist2(p2, p3) + dist2(p3, p4), p1, p2, p3, p4) for p1 in A for p2 in A for p3 in A for p4 in A if len(set([p1, p2, p3, p4])) == 4)[-1][1:5]
print('\n'.join(str(p[0]) + ' ' + str(p[1]) for p in ans))
``` | output | 1 | 21,558 | 23 | 43,117 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a rectangular grid of lattice points from (0, 0) to (n, m) inclusive. You have to choose exactly 4 different points to build a polyline possibly with self-intersections and self-touching. This polyline should be as long as possible.
A polyline defined by points p1, p2, p3, p4 consists of the line segments p1 p2, p2 p3, p3 p4, and its length is the sum of the lengths of the individual line segments.
Input
The only line of the input contains two integers n and m (0 β€ n, m β€ 1000). It is guaranteed that grid contains at least 4 different points.
Output
Print 4 lines with two integers per line separated by space β coordinates of points p1, p2, p3, p4 in order which represent the longest possible polyline.
Judge program compares your answer and jury's answer with 10 - 6 precision.
Examples
Input
1 1
Output
1 1
0 0
1 0
0 1
Input
0 10
Output
0 1
0 10
0 0
0 9 | instruction | 0 | 21,559 | 23 | 43,118 |
Tags: brute force, constructive algorithms, geometry, trees
Correct Solution:
```
def main():
a=input().split()
for i in range(len(a)):
a[i]=int(a[i])
m=a[1]
n=a[0]
if n==0:
c1={(0, 0), (0, 1), (0, m-1), (0, m)}
elif m==0:
c1={(0, 0), (1, 0), (n-1, 0), (n, 0)}
else:
c1={(0, 0), (0, 1), (1, 0), (1, 1), (0, m-1), (0, m), (1, m-1), (1, m), (n-1, m-1), (n-1, m), (n, m-1), (n, m), (n-1, 0), (n, 0), (n-1, 1), (n, 1)}
maximum=0
for i in c1:
for j in c1-{i}:
for k in c1-{i, j}:
for l in c1-{i, j, k}:
maximum=max(polyline(i, j, k, l), maximum)
for i in c1:
for j in c1-{i}:
for k in c1-{i, j}:
for l in c1-{i, j, k}:
if maximum==polyline(i, j, k, l):
print(l[0], l[1])
print(k[0], k[1])
print(j[0], j[1])
print(i[0], i[1])
return
def dis(i, j):
return ((i[0]-j[0])**2+(i[1]-j[1])**2)**(0.5)
def polyline(i, j, k, l):
return dis(i, j)+dis(j, k)+dis(k, l)
main()
``` | output | 1 | 21,559 | 23 | 43,119 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a rectangular grid of lattice points from (0, 0) to (n, m) inclusive. You have to choose exactly 4 different points to build a polyline possibly with self-intersections and self-touching. This polyline should be as long as possible.
A polyline defined by points p1, p2, p3, p4 consists of the line segments p1 p2, p2 p3, p3 p4, and its length is the sum of the lengths of the individual line segments.
Input
The only line of the input contains two integers n and m (0 β€ n, m β€ 1000). It is guaranteed that grid contains at least 4 different points.
Output
Print 4 lines with two integers per line separated by space β coordinates of points p1, p2, p3, p4 in order which represent the longest possible polyline.
Judge program compares your answer and jury's answer with 10 - 6 precision.
Examples
Input
1 1
Output
1 1
0 0
1 0
0 1
Input
0 10
Output
0 1
0 10
0 0
0 9 | instruction | 0 | 21,560 | 23 | 43,120 |
Tags: brute force, constructive algorithms, geometry, trees
Correct Solution:
```
from math import *
def d(p1x,p1y,p2x,p2y,p3x,p3y,p4x,p4y):
if len(set([(p1x,p1y),(p2x,p2y),(p3x,p3y),(p4x,p4y)])) != 4:
return (0,0)
dis = sqrt((p2x-p1x)*(p2x-p1x) + (p2y-p1y)*(p2y-p1y)) + \
sqrt((p3x-p2x)*(p3x-p2x) + (p3y-p2y)*(p3y-p2y)) + \
sqrt((p4x-p3x)*(p4x-p3x) + (p4y-p3y)*(p4y-p3y))
return (dis,(p1x,p1y,p2x,p2y,p3x,p3y,p4x,p4y))
def bf():
l = []
for p1x in range(0,n+1):
for p1y in range(0,m+1):
for p2x in range(0,n+1):
for p2y in range(0,m+1):
for p3x in range(0,n+1):
for p3y in range(0,m+1):
for p4x in range(0,n+1):
for p4y in range(0,m+1):
if len(set([(p1x,p1y),(p2x,p2y),(p3x,p3y),(p4x,p4y)])) == 4:
l.append(d(p1x,p1y,p2x,p2y,p3x,p3y,p4x,p4y))
print(list(reversed(sorted(l)))[0])
n,m = list(map(int,input().split()))
#bf()
if m==0:
print("%d %d\n%d %d\n%d %d\n%d %d\n"%(1,0,n,m,0,0,n-1,m))
elif n==0:
print("%d %d\n%d %d\n%d %d\n%d %d\n"%(0,1,n,m,0,0,n,m-1))
else:
l = []
l.append(d(n-1,m,0,0,n,m,0,1))
l.append(d(n,m-1,0,0,n,m,1,0))
l.append(d(1,0,n,m,0,0,n-1,m))
l.append(d(0,1,n,m,0,0,n,m-1))
l.append(d(0,0,n,m,0,1,n-1,m))
l.append(d(0,0,n,m,1,0,n,m-1))
l.append(d(0,0,n,m,n,0,0,m))
l.append(d(0,0,n,m,0,m,n,0))
a = list(reversed(sorted(l)))[0]
#print(a)
a = a[1]
for i in range(4):
print(a[i*2],a[i*2+1])
``` | output | 1 | 21,560 | 23 | 43,121 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a rectangular grid of lattice points from (0, 0) to (n, m) inclusive. You have to choose exactly 4 different points to build a polyline possibly with self-intersections and self-touching. This polyline should be as long as possible.
A polyline defined by points p1, p2, p3, p4 consists of the line segments p1 p2, p2 p3, p3 p4, and its length is the sum of the lengths of the individual line segments.
Input
The only line of the input contains two integers n and m (0 β€ n, m β€ 1000). It is guaranteed that grid contains at least 4 different points.
Output
Print 4 lines with two integers per line separated by space β coordinates of points p1, p2, p3, p4 in order which represent the longest possible polyline.
Judge program compares your answer and jury's answer with 10 - 6 precision.
Examples
Input
1 1
Output
1 1
0 0
1 0
0 1
Input
0 10
Output
0 1
0 10
0 0
0 9 | instruction | 0 | 21,561 | 23 | 43,122 |
Tags: brute force, constructive algorithms, geometry, trees
Correct Solution:
```
def dist(v):
ans = 0
for i in range(4):
for j in range(4):
if i != j and v[i] == v[j]:
return 0
for i in range(3):
ans += (v[i][0] - v[i + 1][0]) ** 2 + (v[i][1] - v[i + 1][1]) ** 2
return ans
now = [0] * 4
n, m = map(int, input().split())
best = 0
if n == 0:
print(0, 1)
print(0, m)
print(0, 0)
print(0, m - 1)
elif m == 0:
print(1, 0)
print(n, 0)
print(0, 0)
print(n - 1, 0)
else:
v = [[(0, 0), (n, m), (0, m), (n, 0)],
[(0, 0), (n, m), (n, 0), (0, m)],
[(0, 0), (n, m), (0, 1), (n, m - 1)],
[(0, 0), (n, m), (1, 0), (n - 1, m)],
[(0, 0), (n, m), (0, 1), (n - 1, m)],
[(0, 0), (n, m), (1, 0), (n, m - 1)],
[(0, 1), (n, m), (0, 0), (n, m - 1)],
[(1, 0), (n, m), (0, 0), (n - 1, m)],
[(0, 1), (n, m), (0, 0), (n - 1, m)],
[(1, 0), (n, m), (0, 0), (n, m - 1)],
[(0, 1), (n, m - 1), (0, 0), (n, m)],
[(1, 0), (n - 1, m), (0, 0), (n, m)],
[(0, 1), (n - 1, m), (0, 0), (n, m)],
[(1, 0), (n, m - 1), (0, 0), (n, m)],
[(0, 1), (n, m - 1), (1, 0), (n, m)],
[(1, 0), (n - 1, m), (0, 1), (n, m)],
[(0, 1), (n - 1, m), (1, 0), (n, m)],
[(1, 0), (n, m - 1), (0, 1), (n, m)],
[(0, 1), (n, m - 1), (1, 0), (n - 1, m)],
[(1, 0), (n - 1, m), (0, 1), (n, m - 1)],
[(0, 1), (n - 1, m), (1, 0), (n, m - 1)],
[(1, 0), (n, m - 1), (0, 1), (n - 1, m)],
[(0, 0), (n, m - 1), (0, 1), (n, m)],
[(0, 0), (n - 1, m), (1, 0), (n, m)],
[(0, 0), (n - 1, m), (0, 1), (n, m)],
[(0, 0), (n, m - 1), (1, 0), (n, m)]]
for i in range(len(v)):
now = dist(v[i])
if now > best:
best = now
ans = i
for i in range(4):
print(v[ans][i][0], v[ans][i][1])
``` | output | 1 | 21,561 | 23 | 43,123 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a rectangular grid of lattice points from (0, 0) to (n, m) inclusive. You have to choose exactly 4 different points to build a polyline possibly with self-intersections and self-touching. This polyline should be as long as possible.
A polyline defined by points p1, p2, p3, p4 consists of the line segments p1 p2, p2 p3, p3 p4, and its length is the sum of the lengths of the individual line segments.
Input
The only line of the input contains two integers n and m (0 β€ n, m β€ 1000). It is guaranteed that grid contains at least 4 different points.
Output
Print 4 lines with two integers per line separated by space β coordinates of points p1, p2, p3, p4 in order which represent the longest possible polyline.
Judge program compares your answer and jury's answer with 10 - 6 precision.
Examples
Input
1 1
Output
1 1
0 0
1 0
0 1
Input
0 10
Output
0 1
0 10
0 0
0 9
Submitted Solution:
```
from math import *
def main():
n, m = [int(x) for x in input().split()]
if n == 0:
print(0, 1)
print(0, m)
print(0, 0)
print(0, m-1)
elif m == 0:
print(1, 0)
print(n, 0)
print(0, 0)
print(n-1, 0)
else:
r1 = 2*sqrt(n*n + m*m) + max(n, m)
r2 = 2*sqrt((n - 1)*(n - 1) + m*m) + sqrt(n*n + m*m)
r3 = 2*sqrt((m - 1)*(m - 1) + n*n) + sqrt(n*n + m*m)
if r3 > max(r1, r2):
print(n, 1)
print(0, m)
print(n, 0)
print(0, m-1)
elif r2 > r1:
print(n-1, m)
print(0, 0)
print(n, m)
print(1, 0)
else:
# r1
print(0, 0)
print(n, m)
if n < m: # take longest route
print(n, 0)
print(0, m)
else:
print(0, m)
print(n, 0)
main()
``` | instruction | 0 | 21,562 | 23 | 43,124 |
Yes | output | 1 | 21,562 | 23 | 43,125 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a rectangular grid of lattice points from (0, 0) to (n, m) inclusive. You have to choose exactly 4 different points to build a polyline possibly with self-intersections and self-touching. This polyline should be as long as possible.
A polyline defined by points p1, p2, p3, p4 consists of the line segments p1 p2, p2 p3, p3 p4, and its length is the sum of the lengths of the individual line segments.
Input
The only line of the input contains two integers n and m (0 β€ n, m β€ 1000). It is guaranteed that grid contains at least 4 different points.
Output
Print 4 lines with two integers per line separated by space β coordinates of points p1, p2, p3, p4 in order which represent the longest possible polyline.
Judge program compares your answer and jury's answer with 10 - 6 precision.
Examples
Input
1 1
Output
1 1
0 0
1 0
0 1
Input
0 10
Output
0 1
0 10
0 0
0 9
Submitted Solution:
```
n,m=map(int,input().split())
if(m==0):
print(1,0)
print(n,0)
print(0,0)
print(n-1,0)
elif(n==0):
print(0,1)
print(0,m)
print(0,0)
print(0,m-1)
elif(n==1 and m==1):
print(1,1)
print(0,0)
print(1,0)
print(0,1)
elif(n==1):
print(0,0)
print(1,m)
print(1,0)
print(0,m)
elif(m==1):
print(0,0)
print(n,1)
print(0,1)
print(n,0)
else:
if(n<m):
a=pow(n**2+m**2,1/2)*2+max(n,m)
b=pow((n-1)**2+m**2,1/2)*2+pow(m**2+n**2,1/2)
if(b>a):
print(1,0)
print(n,m)
print(0,0)
print(n-1,m)
else:
print(0,0)
print(n,m)
print(n,0)
print(0,m)
else:
a=pow(n**2+m**2,1/2)*2+max(n,m)
b=pow((m-1)**2+n**2,1/2)*2+pow(m**2+n**2,1/2)
if(b>a):
print(0,1)
print(n,m)
print(0,0)
print(n,m-1)
else:
print(0,0)
print(n,m)
print(0,m)
print(n,0)
``` | instruction | 0 | 21,563 | 23 | 43,126 |
Yes | output | 1 | 21,563 | 23 | 43,127 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a rectangular grid of lattice points from (0, 0) to (n, m) inclusive. You have to choose exactly 4 different points to build a polyline possibly with self-intersections and self-touching. This polyline should be as long as possible.
A polyline defined by points p1, p2, p3, p4 consists of the line segments p1 p2, p2 p3, p3 p4, and its length is the sum of the lengths of the individual line segments.
Input
The only line of the input contains two integers n and m (0 β€ n, m β€ 1000). It is guaranteed that grid contains at least 4 different points.
Output
Print 4 lines with two integers per line separated by space β coordinates of points p1, p2, p3, p4 in order which represent the longest possible polyline.
Judge program compares your answer and jury's answer with 10 - 6 precision.
Examples
Input
1 1
Output
1 1
0 0
1 0
0 1
Input
0 10
Output
0 1
0 10
0 0
0 9
Submitted Solution:
```
n,m=map(int,input().split())
v=set()
R=0,1
def f(a,b):
if 0<=a<=n and 0<=b<=m:v.add((a,b))
g=lambda x:sum((x[0][i]-x[1][i])**2 for i in R)**.5+g(x[1:])if len(x)>1else 0
r=[[0,0]]*4
for i in R:
for j in R:f(i,j);f(n-i,m-j);f(i,m-j);f(n-i,j)
for a in v:
for b in v:
for c in v:
for d in v:
if len(set([a,b,c,d]))==4 and g(r)<g([a,b,c,d]):r=a,b,c,d
for a,b in r:print(a,b)
``` | instruction | 0 | 21,564 | 23 | 43,128 |
Yes | output | 1 | 21,564 | 23 | 43,129 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a rectangular grid of lattice points from (0, 0) to (n, m) inclusive. You have to choose exactly 4 different points to build a polyline possibly with self-intersections and self-touching. This polyline should be as long as possible.
A polyline defined by points p1, p2, p3, p4 consists of the line segments p1 p2, p2 p3, p3 p4, and its length is the sum of the lengths of the individual line segments.
Input
The only line of the input contains two integers n and m (0 β€ n, m β€ 1000). It is guaranteed that grid contains at least 4 different points.
Output
Print 4 lines with two integers per line separated by space β coordinates of points p1, p2, p3, p4 in order which represent the longest possible polyline.
Judge program compares your answer and jury's answer with 10 - 6 precision.
Examples
Input
1 1
Output
1 1
0 0
1 0
0 1
Input
0 10
Output
0 1
0 10
0 0
0 9
Submitted Solution:
```
inp = input().split()
x = int(inp[0])
y = int(inp[1])
def distance(points):
d = 0
for i in range(len(points) - 1):
p1 = points[i]
p2 = points[i + 1]
d += ((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2) ** 0.5
return d
res = None
poss = []
if x != 0 and y != 0:
poss.append([(0,1), (x, y), (0, 0), (x, y-1)])
poss.append([(1,0), (x, y), (0, 0), (x - 1, y)])
poss.append([(0,0), (x, y), (x, 0), (0, y)])
poss.append([(0,0), (x, y), (0, y), (x, 0)])
d1 = distance(poss[0])
d2 = distance(poss[1])
d3 = distance(poss[2])
d4 = distance(poss[3])
if d1 >= d2 and d1 >= d3 and d1 >= d4:
res = poss[0]
elif d2 >= d1 and d2 >= d3 and d2 >= d4:
res = poss[1]
elif d3 >= d1 and d3 >= d2 and d3 >= d4:
res = poss[2]
else:
res = poss[3]
elif x == 0 and y != 0:
res = [(0, 1), (0,y), (0,0), (0, y - 1)]
elif x != 0 and y == 0:
res = [(1, 0), (x,0), (0,0), (x - 1,0)]
else:
res = [(0,0),(0,0),(0,0),(0,0)]
for i in res:
print(i[0], i[1])
``` | instruction | 0 | 21,565 | 23 | 43,130 |
Yes | output | 1 | 21,565 | 23 | 43,131 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a rectangular grid of lattice points from (0, 0) to (n, m) inclusive. You have to choose exactly 4 different points to build a polyline possibly with self-intersections and self-touching. This polyline should be as long as possible.
A polyline defined by points p1, p2, p3, p4 consists of the line segments p1 p2, p2 p3, p3 p4, and its length is the sum of the lengths of the individual line segments.
Input
The only line of the input contains two integers n and m (0 β€ n, m β€ 1000). It is guaranteed that grid contains at least 4 different points.
Output
Print 4 lines with two integers per line separated by space β coordinates of points p1, p2, p3, p4 in order which represent the longest possible polyline.
Judge program compares your answer and jury's answer with 10 - 6 precision.
Examples
Input
1 1
Output
1 1
0 0
1 0
0 1
Input
0 10
Output
0 1
0 10
0 0
0 9
Submitted Solution:
```
a,b=map(int,input().split(' '))
if a==0:
print(0,' ',1)
print(0,' ',b)
print(0,' ',0)
print(0,' ',b-1)
elif b==0:
print(1,' ',0)
print(a,' ',0)
print(0,' ',0)
print(a-1,' ',0)
elif a>=b:
print(0,' ',0)
print(a,' ',b)
print(0,' ',b)
print(a,' ',0)
else:
print(0,' ',0)
print(a,' ',b)
print(a,' ',0)
print(0,' ',b)
``` | instruction | 0 | 21,566 | 23 | 43,132 |
No | output | 1 | 21,566 | 23 | 43,133 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.