message stringlengths 2 44.5k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 276 109k | cluster float64 23 23 | __index_level_0__ int64 552 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You might have remembered Theatre square from the [problem 1A](https://codeforces.com/problemset/problem/1/A). Now it's finally getting repaved.
The square still has a rectangular shape of n × m meters. However, the picture is about to get more complicated now. Let a_{i,j} be the j-th square in the i-th row of the pavement.
You are given the picture of the squares:
* if a_{i,j} = "*", then the j-th square in the i-th row should be black;
* if a_{i,j} = ".", then the j-th square in the i-th row should be white.
The black squares are paved already. You have to pave the white squares. There are two options for pavement tiles:
* 1 × 1 tiles — each tile costs x burles and covers exactly 1 square;
* 1 × 2 tiles — each tile costs y burles and covers exactly 2 adjacent squares of the same row. Note that you are not allowed to rotate these tiles or cut them into 1 × 1 tiles.
You should cover all the white squares, no two tiles should overlap and no black squares should be covered by tiles.
What is the smallest total price of the tiles needed to cover all the white squares?
Input
The first line contains a single integer t (1 ≤ t ≤ 500) — the number of testcases. Then the description of t testcases follow.
The first line of each testcase contains four integers n, m, x and y (1 ≤ n ≤ 100; 1 ≤ m ≤ 1000; 1 ≤ x, y ≤ 1000) — the size of the Theatre square, the price of the 1 × 1 tile and the price of the 1 × 2 tile.
Each of the next n lines contains m characters. The j-th character in the i-th line is a_{i,j}. If a_{i,j} = "*", then the j-th square in the i-th row should be black, and if a_{i,j} = ".", then the j-th square in the i-th row should be white.
It's guaranteed that the sum of n × m over all testcases doesn't exceed 10^5.
Output
For each testcase print a single integer — the smallest total price of the tiles needed to cover all the white squares in burles.
Example
Input
4
1 1 10 1
.
1 2 10 1
..
2 1 10 1
.
.
3 3 3 7
..*
*..
.*.
Output
10
1
20
18
Note
In the first testcase you are required to use a single 1 × 1 tile, even though 1 × 2 tile is cheaper. So the total price is 10 burles.
In the second testcase you can either use two 1 × 1 tiles and spend 20 burles or use a single 1 × 2 tile and spend 1 burle. The second option is cheaper, thus the answer is 1.
The third testcase shows that you can't rotate 1 × 2 tiles. You still have to use two 1 × 1 tiles for the total price of 20.
In the fourth testcase the cheapest way is to use 1 × 1 tiles everywhere. The total cost is 6 ⋅ 3 = 18.
Submitted Solution:
```
for ad in range(int(input())):
n,m,x,y=list(map(int, input().split()))
l=[];a=[]
for i in range(n):
v=list(input())
l.append(v)
a+=v
if 2*x<=y:
print(x*(a.count(".")))
else:
c=0
for i in l:
j=0
while j<m-1:
if i[j]==".":
if i[j+1] == i[j]:
c+=y
else:
c+=x
j+=2
al=2
else:
j+=1
al=1
if j==m and al==1:
if i[-1]==".":
c+=x
if m==1:
if i[0] == ".":
c+=x
print(c)
``` | instruction | 0 | 35,350 | 23 | 70,700 |
No | output | 1 | 35,350 | 23 | 70,701 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You might have remembered Theatre square from the [problem 1A](https://codeforces.com/problemset/problem/1/A). Now it's finally getting repaved.
The square still has a rectangular shape of n × m meters. However, the picture is about to get more complicated now. Let a_{i,j} be the j-th square in the i-th row of the pavement.
You are given the picture of the squares:
* if a_{i,j} = "*", then the j-th square in the i-th row should be black;
* if a_{i,j} = ".", then the j-th square in the i-th row should be white.
The black squares are paved already. You have to pave the white squares. There are two options for pavement tiles:
* 1 × 1 tiles — each tile costs x burles and covers exactly 1 square;
* 1 × 2 tiles — each tile costs y burles and covers exactly 2 adjacent squares of the same row. Note that you are not allowed to rotate these tiles or cut them into 1 × 1 tiles.
You should cover all the white squares, no two tiles should overlap and no black squares should be covered by tiles.
What is the smallest total price of the tiles needed to cover all the white squares?
Input
The first line contains a single integer t (1 ≤ t ≤ 500) — the number of testcases. Then the description of t testcases follow.
The first line of each testcase contains four integers n, m, x and y (1 ≤ n ≤ 100; 1 ≤ m ≤ 1000; 1 ≤ x, y ≤ 1000) — the size of the Theatre square, the price of the 1 × 1 tile and the price of the 1 × 2 tile.
Each of the next n lines contains m characters. The j-th character in the i-th line is a_{i,j}. If a_{i,j} = "*", then the j-th square in the i-th row should be black, and if a_{i,j} = ".", then the j-th square in the i-th row should be white.
It's guaranteed that the sum of n × m over all testcases doesn't exceed 10^5.
Output
For each testcase print a single integer — the smallest total price of the tiles needed to cover all the white squares in burles.
Example
Input
4
1 1 10 1
.
1 2 10 1
..
2 1 10 1
.
.
3 3 3 7
..*
*..
.*.
Output
10
1
20
18
Note
In the first testcase you are required to use a single 1 × 1 tile, even though 1 × 2 tile is cheaper. So the total price is 10 burles.
In the second testcase you can either use two 1 × 1 tiles and spend 20 burles or use a single 1 × 2 tile and spend 1 burle. The second option is cheaper, thus the answer is 1.
The third testcase shows that you can't rotate 1 × 2 tiles. You still have to use two 1 × 1 tiles for the total price of 20.
In the fourth testcase the cheapest way is to use 1 × 1 tiles everywhere. The total cost is 6 ⋅ 3 = 18.
Submitted Solution:
```
from sys import stdout,stdin
for testcases in range(int(stdin.readline())):
rows,col,ones,twos=map(int,stdin.readline().split())
twos=min(ones*2,twos)
total=0
for i in range(rows):
string=input()
tiles=string.count(".")
total+= twos*(tiles//2) + ones*(tiles%2)
stdout.write(str(total)+"\n")
``` | instruction | 0 | 35,351 | 23 | 70,702 |
No | output | 1 | 35,351 | 23 | 70,703 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You might have remembered Theatre square from the [problem 1A](https://codeforces.com/problemset/problem/1/A). Now it's finally getting repaved.
The square still has a rectangular shape of n × m meters. However, the picture is about to get more complicated now. Let a_{i,j} be the j-th square in the i-th row of the pavement.
You are given the picture of the squares:
* if a_{i,j} = "*", then the j-th square in the i-th row should be black;
* if a_{i,j} = ".", then the j-th square in the i-th row should be white.
The black squares are paved already. You have to pave the white squares. There are two options for pavement tiles:
* 1 × 1 tiles — each tile costs x burles and covers exactly 1 square;
* 1 × 2 tiles — each tile costs y burles and covers exactly 2 adjacent squares of the same row. Note that you are not allowed to rotate these tiles or cut them into 1 × 1 tiles.
You should cover all the white squares, no two tiles should overlap and no black squares should be covered by tiles.
What is the smallest total price of the tiles needed to cover all the white squares?
Input
The first line contains a single integer t (1 ≤ t ≤ 500) — the number of testcases. Then the description of t testcases follow.
The first line of each testcase contains four integers n, m, x and y (1 ≤ n ≤ 100; 1 ≤ m ≤ 1000; 1 ≤ x, y ≤ 1000) — the size of the Theatre square, the price of the 1 × 1 tile and the price of the 1 × 2 tile.
Each of the next n lines contains m characters. The j-th character in the i-th line is a_{i,j}. If a_{i,j} = "*", then the j-th square in the i-th row should be black, and if a_{i,j} = ".", then the j-th square in the i-th row should be white.
It's guaranteed that the sum of n × m over all testcases doesn't exceed 10^5.
Output
For each testcase print a single integer — the smallest total price of the tiles needed to cover all the white squares in burles.
Example
Input
4
1 1 10 1
.
1 2 10 1
..
2 1 10 1
.
.
3 3 3 7
..*
*..
.*.
Output
10
1
20
18
Note
In the first testcase you are required to use a single 1 × 1 tile, even though 1 × 2 tile is cheaper. So the total price is 10 burles.
In the second testcase you can either use two 1 × 1 tiles and spend 20 burles or use a single 1 × 2 tile and spend 1 burle. The second option is cheaper, thus the answer is 1.
The third testcase shows that you can't rotate 1 × 2 tiles. You still have to use two 1 × 1 tiles for the total price of 20.
In the fourth testcase the cheapest way is to use 1 × 1 tiles everywhere. The total cost is 6 ⋅ 3 = 18.
Submitted Solution:
```
import math
t=int(input())
for g in range(0,t):
nmxy=list(map(int,input().split()))
n=nmxy[0]
m=nmxy[1]
x=nmxy[2]
y=nmxy[3]
price=0
for i in range(0,n):
string=input()
j=0
while(j<m-1):
if(string[j]=="." and string[j+1]=="."):
j=j+1
if(2*x<y):
price+=2*x;
else:
price+=y;
elif(string[j]=="."):
price+=x
j=j+1
if(m>=2 and string[m-2]!="." and string[m-1]=="."):
price+=x
if(m==1):
if(string[0]=="."):
price+=x
print(price)
``` | instruction | 0 | 35,352 | 23 | 70,704 |
No | output | 1 | 35,352 | 23 | 70,705 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has found a piece of paper with a coordinate system written on it. There are n distinct squares drawn in this coordinate system. Let's number the squares with integers from 1 to n. It turned out that points with coordinates (0, 0) and (ai, ai) are the opposite corners of the i-th square.
Vasya wants to find such integer point (with integer coordinates) of the plane, that belongs to exactly k drawn squares. We'll say that a point belongs to a square, if the point is located either inside the square, or on its boundary.
Help Vasya find a point that would meet the described limits.
Input
The first line contains two space-separated integers n, k (1 ≤ n, k ≤ 50). The second line contains space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).
It is guaranteed that all given squares are distinct.
Output
In a single line print two space-separated integers x and y (0 ≤ x, y ≤ 109) — the coordinates of the point that belongs to exactly k squares. If there are multiple answers, you are allowed to print any of them.
If there is no answer, print "-1" (without the quotes).
Examples
Input
4 3
5 1 3 4
Output
2 1
Input
3 1
2 4 1
Output
4 0
Input
4 50
5 1 10 2
Output
-1 | instruction | 0 | 35,449 | 23 | 70,898 |
Tags: greedy, implementation, sortings
Correct Solution:
```
n, k = [int(x) for x in input().split()]
l = sorted([int(x) for x in input().split()])
i = n - 1
while i >= 0:
j = i
while j >= 0 and l[i] == l[j]:
j -= 1
i = j
if n - 1 - i == k:
print(l[i + 1], 0)
break
else:
print(-1)
``` | output | 1 | 35,449 | 23 | 70,899 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has found a piece of paper with a coordinate system written on it. There are n distinct squares drawn in this coordinate system. Let's number the squares with integers from 1 to n. It turned out that points with coordinates (0, 0) and (ai, ai) are the opposite corners of the i-th square.
Vasya wants to find such integer point (with integer coordinates) of the plane, that belongs to exactly k drawn squares. We'll say that a point belongs to a square, if the point is located either inside the square, or on its boundary.
Help Vasya find a point that would meet the described limits.
Input
The first line contains two space-separated integers n, k (1 ≤ n, k ≤ 50). The second line contains space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).
It is guaranteed that all given squares are distinct.
Output
In a single line print two space-separated integers x and y (0 ≤ x, y ≤ 109) — the coordinates of the point that belongs to exactly k squares. If there are multiple answers, you are allowed to print any of them.
If there is no answer, print "-1" (without the quotes).
Examples
Input
4 3
5 1 3 4
Output
2 1
Input
3 1
2 4 1
Output
4 0
Input
4 50
5 1 10 2
Output
-1 | instruction | 0 | 35,450 | 23 | 70,900 |
Tags: greedy, implementation, sortings
Correct Solution:
```
[n, k] = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
if n < k:
print(-1)
else:
a.sort(reverse = True)
try:
if a[k] == a[k - 1]:
print(-1)
else:
print(a[k - 1], a[k - 1])
except(IndexError):
print(0, 0)
``` | output | 1 | 35,450 | 23 | 70,901 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has found a piece of paper with a coordinate system written on it. There are n distinct squares drawn in this coordinate system. Let's number the squares with integers from 1 to n. It turned out that points with coordinates (0, 0) and (ai, ai) are the opposite corners of the i-th square.
Vasya wants to find such integer point (with integer coordinates) of the plane, that belongs to exactly k drawn squares. We'll say that a point belongs to a square, if the point is located either inside the square, or on its boundary.
Help Vasya find a point that would meet the described limits.
Input
The first line contains two space-separated integers n, k (1 ≤ n, k ≤ 50). The second line contains space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).
It is guaranteed that all given squares are distinct.
Output
In a single line print two space-separated integers x and y (0 ≤ x, y ≤ 109) — the coordinates of the point that belongs to exactly k squares. If there are multiple answers, you are allowed to print any of them.
If there is no answer, print "-1" (without the quotes).
Examples
Input
4 3
5 1 3 4
Output
2 1
Input
3 1
2 4 1
Output
4 0
Input
4 50
5 1 10 2
Output
-1 | instruction | 0 | 35,451 | 23 | 70,902 |
Tags: greedy, implementation, sortings
Correct Solution:
```
firstLine = list(map(int, input().split()))
squares = sorted(list(map(int, input().split())))
# inSquares = {}
# for i in range(squares[len(squares)-1]):
# for j in range(squares[len(squares)-1]):
# existsIn = 0
# for square in squares:
# if i<= square and j <= square:
# existsIn+=1
# inSquares[existsIn] = (i,j)
# print(inSquares)
# inSquares[firstLine[1]]
inSquares = 0
if firstLine[1] > len(squares):
print("-1")
else:
inSquares = len(squares) - firstLine[1]
print(str(squares[inSquares])+" 0")
``` | output | 1 | 35,451 | 23 | 70,903 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has found a piece of paper with a coordinate system written on it. There are n distinct squares drawn in this coordinate system. Let's number the squares with integers from 1 to n. It turned out that points with coordinates (0, 0) and (ai, ai) are the opposite corners of the i-th square.
Vasya wants to find such integer point (with integer coordinates) of the plane, that belongs to exactly k drawn squares. We'll say that a point belongs to a square, if the point is located either inside the square, or on its boundary.
Help Vasya find a point that would meet the described limits.
Input
The first line contains two space-separated integers n, k (1 ≤ n, k ≤ 50). The second line contains space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).
It is guaranteed that all given squares are distinct.
Output
In a single line print two space-separated integers x and y (0 ≤ x, y ≤ 109) — the coordinates of the point that belongs to exactly k squares. If there are multiple answers, you are allowed to print any of them.
If there is no answer, print "-1" (without the quotes).
Examples
Input
4 3
5 1 3 4
Output
2 1
Input
3 1
2 4 1
Output
4 0
Input
4 50
5 1 10 2
Output
-1 | instruction | 0 | 35,452 | 23 | 70,904 |
Tags: greedy, implementation, sortings
Correct Solution:
```
p=input().split()
a=int(p[0])
b=int(p[1])
q=input().split()
l=[]
i=0
while i<a:
l.append(int(q[i]))
i=i+1
l.sort()
if b>a:
print(-1)
else:
print(l[a-b],l[a-b])
``` | output | 1 | 35,452 | 23 | 70,905 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has found a piece of paper with a coordinate system written on it. There are n distinct squares drawn in this coordinate system. Let's number the squares with integers from 1 to n. It turned out that points with coordinates (0, 0) and (ai, ai) are the opposite corners of the i-th square.
Vasya wants to find such integer point (with integer coordinates) of the plane, that belongs to exactly k drawn squares. We'll say that a point belongs to a square, if the point is located either inside the square, or on its boundary.
Help Vasya find a point that would meet the described limits.
Input
The first line contains two space-separated integers n, k (1 ≤ n, k ≤ 50). The second line contains space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).
It is guaranteed that all given squares are distinct.
Output
In a single line print two space-separated integers x and y (0 ≤ x, y ≤ 109) — the coordinates of the point that belongs to exactly k squares. If there are multiple answers, you are allowed to print any of them.
If there is no answer, print "-1" (without the quotes).
Examples
Input
4 3
5 1 3 4
Output
2 1
Input
3 1
2 4 1
Output
4 0
Input
4 50
5 1 10 2
Output
-1 | instruction | 0 | 35,453 | 23 | 70,906 |
Tags: greedy, implementation, sortings
Correct Solution:
```
n,k = map(int,input().split())
arr = [int(x) for x in input().split()]
arr.sort(reverse=True)
if n>=k:
print(arr[k-1],arr[k-1])
else:
print(-1)
``` | output | 1 | 35,453 | 23 | 70,907 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has found a piece of paper with a coordinate system written on it. There are n distinct squares drawn in this coordinate system. Let's number the squares with integers from 1 to n. It turned out that points with coordinates (0, 0) and (ai, ai) are the opposite corners of the i-th square.
Vasya wants to find such integer point (with integer coordinates) of the plane, that belongs to exactly k drawn squares. We'll say that a point belongs to a square, if the point is located either inside the square, or on its boundary.
Help Vasya find a point that would meet the described limits.
Input
The first line contains two space-separated integers n, k (1 ≤ n, k ≤ 50). The second line contains space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).
It is guaranteed that all given squares are distinct.
Output
In a single line print two space-separated integers x and y (0 ≤ x, y ≤ 109) — the coordinates of the point that belongs to exactly k squares. If there are multiple answers, you are allowed to print any of them.
If there is no answer, print "-1" (without the quotes).
Examples
Input
4 3
5 1 3 4
Output
2 1
Input
3 1
2 4 1
Output
4 0
Input
4 50
5 1 10 2
Output
-1 | instruction | 0 | 35,454 | 23 | 70,908 |
Tags: greedy, implementation, sortings
Correct Solution:
```
n, k = map(int , input().split())
squares = list(map(int, input().split()))
if k<=n:
squares.sort()
co_ordinate = squares[n-k]
print(co_ordinate, 0)
else:
print(-1)
``` | output | 1 | 35,454 | 23 | 70,909 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has found a piece of paper with a coordinate system written on it. There are n distinct squares drawn in this coordinate system. Let's number the squares with integers from 1 to n. It turned out that points with coordinates (0, 0) and (ai, ai) are the opposite corners of the i-th square.
Vasya wants to find such integer point (with integer coordinates) of the plane, that belongs to exactly k drawn squares. We'll say that a point belongs to a square, if the point is located either inside the square, or on its boundary.
Help Vasya find a point that would meet the described limits.
Input
The first line contains two space-separated integers n, k (1 ≤ n, k ≤ 50). The second line contains space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).
It is guaranteed that all given squares are distinct.
Output
In a single line print two space-separated integers x and y (0 ≤ x, y ≤ 109) — the coordinates of the point that belongs to exactly k squares. If there are multiple answers, you are allowed to print any of them.
If there is no answer, print "-1" (without the quotes).
Examples
Input
4 3
5 1 3 4
Output
2 1
Input
3 1
2 4 1
Output
4 0
Input
4 50
5 1 10 2
Output
-1 | instruction | 0 | 35,455 | 23 | 70,910 |
Tags: greedy, implementation, sortings
Correct Solution:
```
# https://codeforces.com/problemset/problem/263/B
# 900
n, k = map(int, input().split())
s = list(map(int, input().split()))
s.sort()
if k > n:
print(-1)
else:
print(s[-k], s[-k])
``` | output | 1 | 35,455 | 23 | 70,911 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has found a piece of paper with a coordinate system written on it. There are n distinct squares drawn in this coordinate system. Let's number the squares with integers from 1 to n. It turned out that points with coordinates (0, 0) and (ai, ai) are the opposite corners of the i-th square.
Vasya wants to find such integer point (with integer coordinates) of the plane, that belongs to exactly k drawn squares. We'll say that a point belongs to a square, if the point is located either inside the square, or on its boundary.
Help Vasya find a point that would meet the described limits.
Input
The first line contains two space-separated integers n, k (1 ≤ n, k ≤ 50). The second line contains space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).
It is guaranteed that all given squares are distinct.
Output
In a single line print two space-separated integers x and y (0 ≤ x, y ≤ 109) — the coordinates of the point that belongs to exactly k squares. If there are multiple answers, you are allowed to print any of them.
If there is no answer, print "-1" (without the quotes).
Examples
Input
4 3
5 1 3 4
Output
2 1
Input
3 1
2 4 1
Output
4 0
Input
4 50
5 1 10 2
Output
-1 | instruction | 0 | 35,456 | 23 | 70,912 |
Tags: greedy, implementation, sortings
Correct Solution:
```
n, k = map(int, input().split())
a = list(map(int, input().split()))
if k > n:
print(-1)
else:
a.sort(reverse=True)
print("%d 0" % a[k-1])
``` | output | 1 | 35,456 | 23 | 70,913 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has found a piece of paper with a coordinate system written on it. There are n distinct squares drawn in this coordinate system. Let's number the squares with integers from 1 to n. It turned out that points with coordinates (0, 0) and (ai, ai) are the opposite corners of the i-th square.
Vasya wants to find such integer point (with integer coordinates) of the plane, that belongs to exactly k drawn squares. We'll say that a point belongs to a square, if the point is located either inside the square, or on its boundary.
Help Vasya find a point that would meet the described limits.
Input
The first line contains two space-separated integers n, k (1 ≤ n, k ≤ 50). The second line contains space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).
It is guaranteed that all given squares are distinct.
Output
In a single line print two space-separated integers x and y (0 ≤ x, y ≤ 109) — the coordinates of the point that belongs to exactly k squares. If there are multiple answers, you are allowed to print any of them.
If there is no answer, print "-1" (without the quotes).
Examples
Input
4 3
5 1 3 4
Output
2 1
Input
3 1
2 4 1
Output
4 0
Input
4 50
5 1 10 2
Output
-1
Submitted Solution:
```
import sys
my_file = sys.stdin
#my_file = open("input.txt", "r")
line = [int(i) for i in my_file.readline().strip("\n").split()]
n, k = line[0], line[1]
a = [int(i) for i in my_file.readline().split()]
a = sorted(a, reverse=True)
if k>n:
print('-1')
else:
print(a[k-1], 0)
``` | instruction | 0 | 35,457 | 23 | 70,914 |
Yes | output | 1 | 35,457 | 23 | 70,915 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has found a piece of paper with a coordinate system written on it. There are n distinct squares drawn in this coordinate system. Let's number the squares with integers from 1 to n. It turned out that points with coordinates (0, 0) and (ai, ai) are the opposite corners of the i-th square.
Vasya wants to find such integer point (with integer coordinates) of the plane, that belongs to exactly k drawn squares. We'll say that a point belongs to a square, if the point is located either inside the square, or on its boundary.
Help Vasya find a point that would meet the described limits.
Input
The first line contains two space-separated integers n, k (1 ≤ n, k ≤ 50). The second line contains space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).
It is guaranteed that all given squares are distinct.
Output
In a single line print two space-separated integers x and y (0 ≤ x, y ≤ 109) — the coordinates of the point that belongs to exactly k squares. If there are multiple answers, you are allowed to print any of them.
If there is no answer, print "-1" (without the quotes).
Examples
Input
4 3
5 1 3 4
Output
2 1
Input
3 1
2 4 1
Output
4 0
Input
4 50
5 1 10 2
Output
-1
Submitted Solution:
```
n, k = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=True)
if k > n:
print(-1)
exit()
if k == n:
print(0, 0)
exit()
if a[k] == a[k - 1]:
print(-1)
exit()
print(a[k - 1], a[k - 1])
``` | instruction | 0 | 35,458 | 23 | 70,916 |
Yes | output | 1 | 35,458 | 23 | 70,917 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has found a piece of paper with a coordinate system written on it. There are n distinct squares drawn in this coordinate system. Let's number the squares with integers from 1 to n. It turned out that points with coordinates (0, 0) and (ai, ai) are the opposite corners of the i-th square.
Vasya wants to find such integer point (with integer coordinates) of the plane, that belongs to exactly k drawn squares. We'll say that a point belongs to a square, if the point is located either inside the square, or on its boundary.
Help Vasya find a point that would meet the described limits.
Input
The first line contains two space-separated integers n, k (1 ≤ n, k ≤ 50). The second line contains space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).
It is guaranteed that all given squares are distinct.
Output
In a single line print two space-separated integers x and y (0 ≤ x, y ≤ 109) — the coordinates of the point that belongs to exactly k squares. If there are multiple answers, you are allowed to print any of them.
If there is no answer, print "-1" (without the quotes).
Examples
Input
4 3
5 1 3 4
Output
2 1
Input
3 1
2 4 1
Output
4 0
Input
4 50
5 1 10 2
Output
-1
Submitted Solution:
```
def input_nk():
line1=input()
n,k=line1.split()
n=int(n)
k=int(k)
line2 = input()
a = [int(x) for x in line2.split(" ")]
a.sort()
if (n-k)<0:
print(-1)
else:
print(a[n-k], a[n-k])
input_nk()
``` | instruction | 0 | 35,459 | 23 | 70,918 |
Yes | output | 1 | 35,459 | 23 | 70,919 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has found a piece of paper with a coordinate system written on it. There are n distinct squares drawn in this coordinate system. Let's number the squares with integers from 1 to n. It turned out that points with coordinates (0, 0) and (ai, ai) are the opposite corners of the i-th square.
Vasya wants to find such integer point (with integer coordinates) of the plane, that belongs to exactly k drawn squares. We'll say that a point belongs to a square, if the point is located either inside the square, or on its boundary.
Help Vasya find a point that would meet the described limits.
Input
The first line contains two space-separated integers n, k (1 ≤ n, k ≤ 50). The second line contains space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).
It is guaranteed that all given squares are distinct.
Output
In a single line print two space-separated integers x and y (0 ≤ x, y ≤ 109) — the coordinates of the point that belongs to exactly k squares. If there are multiple answers, you are allowed to print any of them.
If there is no answer, print "-1" (without the quotes).
Examples
Input
4 3
5 1 3 4
Output
2 1
Input
3 1
2 4 1
Output
4 0
Input
4 50
5 1 10 2
Output
-1
Submitted Solution:
```
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
if n < k:
print(-1)
else:
print(a[n - k], 0)
``` | instruction | 0 | 35,460 | 23 | 70,920 |
Yes | output | 1 | 35,460 | 23 | 70,921 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has found a piece of paper with a coordinate system written on it. There are n distinct squares drawn in this coordinate system. Let's number the squares with integers from 1 to n. It turned out that points with coordinates (0, 0) and (ai, ai) are the opposite corners of the i-th square.
Vasya wants to find such integer point (with integer coordinates) of the plane, that belongs to exactly k drawn squares. We'll say that a point belongs to a square, if the point is located either inside the square, or on its boundary.
Help Vasya find a point that would meet the described limits.
Input
The first line contains two space-separated integers n, k (1 ≤ n, k ≤ 50). The second line contains space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).
It is guaranteed that all given squares are distinct.
Output
In a single line print two space-separated integers x and y (0 ≤ x, y ≤ 109) — the coordinates of the point that belongs to exactly k squares. If there are multiple answers, you are allowed to print any of them.
If there is no answer, print "-1" (without the quotes).
Examples
Input
4 3
5 1 3 4
Output
2 1
Input
3 1
2 4 1
Output
4 0
Input
4 50
5 1 10 2
Output
-1
Submitted Solution:
```
R=lambda:map(int, input().split())
n, k = R()
arr = list(R())
if n < k:
print(-1)
else:
print(arr[-k], arr[-k])
``` | instruction | 0 | 35,461 | 23 | 70,922 |
No | output | 1 | 35,461 | 23 | 70,923 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has found a piece of paper with a coordinate system written on it. There are n distinct squares drawn in this coordinate system. Let's number the squares with integers from 1 to n. It turned out that points with coordinates (0, 0) and (ai, ai) are the opposite corners of the i-th square.
Vasya wants to find such integer point (with integer coordinates) of the plane, that belongs to exactly k drawn squares. We'll say that a point belongs to a square, if the point is located either inside the square, or on its boundary.
Help Vasya find a point that would meet the described limits.
Input
The first line contains two space-separated integers n, k (1 ≤ n, k ≤ 50). The second line contains space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).
It is guaranteed that all given squares are distinct.
Output
In a single line print two space-separated integers x and y (0 ≤ x, y ≤ 109) — the coordinates of the point that belongs to exactly k squares. If there are multiple answers, you are allowed to print any of them.
If there is no answer, print "-1" (without the quotes).
Examples
Input
4 3
5 1 3 4
Output
2 1
Input
3 1
2 4 1
Output
4 0
Input
4 50
5 1 10 2
Output
-1
Submitted Solution:
```
def main_function():
n, k = [int(i) for i in input().split(" ")]
a = sorted([int(i) for i in input().split(" ")])
if n < k:
return "-1"
return f"{a[k - 1]} {a[k - 1]}"
print(main_function())
``` | instruction | 0 | 35,462 | 23 | 70,924 |
No | output | 1 | 35,462 | 23 | 70,925 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has found a piece of paper with a coordinate system written on it. There are n distinct squares drawn in this coordinate system. Let's number the squares with integers from 1 to n. It turned out that points with coordinates (0, 0) and (ai, ai) are the opposite corners of the i-th square.
Vasya wants to find such integer point (with integer coordinates) of the plane, that belongs to exactly k drawn squares. We'll say that a point belongs to a square, if the point is located either inside the square, or on its boundary.
Help Vasya find a point that would meet the described limits.
Input
The first line contains two space-separated integers n, k (1 ≤ n, k ≤ 50). The second line contains space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).
It is guaranteed that all given squares are distinct.
Output
In a single line print two space-separated integers x and y (0 ≤ x, y ≤ 109) — the coordinates of the point that belongs to exactly k squares. If there are multiple answers, you are allowed to print any of them.
If there is no answer, print "-1" (without the quotes).
Examples
Input
4 3
5 1 3 4
Output
2 1
Input
3 1
2 4 1
Output
4 0
Input
4 50
5 1 10 2
Output
-1
Submitted Solution:
```
n, k = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
try:
if k > 1:
print(x[-k - 1] + 1, x[-k - 1] + 1)
else:
print(x[-k], x[-k])
except IndexError:
print(-1)
``` | instruction | 0 | 35,463 | 23 | 70,926 |
No | output | 1 | 35,463 | 23 | 70,927 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has found a piece of paper with a coordinate system written on it. There are n distinct squares drawn in this coordinate system. Let's number the squares with integers from 1 to n. It turned out that points with coordinates (0, 0) and (ai, ai) are the opposite corners of the i-th square.
Vasya wants to find such integer point (with integer coordinates) of the plane, that belongs to exactly k drawn squares. We'll say that a point belongs to a square, if the point is located either inside the square, or on its boundary.
Help Vasya find a point that would meet the described limits.
Input
The first line contains two space-separated integers n, k (1 ≤ n, k ≤ 50). The second line contains space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).
It is guaranteed that all given squares are distinct.
Output
In a single line print two space-separated integers x and y (0 ≤ x, y ≤ 109) — the coordinates of the point that belongs to exactly k squares. If there are multiple answers, you are allowed to print any of them.
If there is no answer, print "-1" (without the quotes).
Examples
Input
4 3
5 1 3 4
Output
2 1
Input
3 1
2 4 1
Output
4 0
Input
4 50
5 1 10 2
Output
-1
Submitted Solution:
```
import bisect
import sys
M , N = map(int,input().split())
squares = list(map(int,input().split()))
squares.sort(reverse=True)
if N == M:
print(M , "" , N)
sys.exit()
elif N > M :
print("-1")
sys.exit()
else:
z = squares[N]
b = squares[N-1] - squares[N]
print(b + z, "", z)
``` | instruction | 0 | 35,464 | 23 | 70,928 |
No | output | 1 | 35,464 | 23 | 70,929 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Wilbur is playing with a set of n points on the coordinate plane. All points have non-negative integer coordinates. Moreover, if some point (x, y) belongs to the set, then all points (x', y'), such that 0 ≤ x' ≤ x and 0 ≤ y' ≤ y also belong to this set.
Now Wilbur wants to number the points in the set he has, that is assign them distinct integer numbers from 1 to n. In order to make the numbering aesthetically pleasing, Wilbur imposes the condition that if some point (x, y) gets number i, then all (x',y') from the set, such that x' ≥ x and y' ≥ y must be assigned a number not less than i. For example, for a set of four points (0, 0), (0, 1), (1, 0) and (1, 1), there are two aesthetically pleasing numberings. One is 1, 2, 3, 4 and another one is 1, 3, 2, 4.
Wilbur's friend comes along and challenges Wilbur. For any point he defines it's special value as s(x, y) = y - x. Now he gives Wilbur some w1, w2,..., wn, and asks him to find an aesthetically pleasing numbering of the points in the set, such that the point that gets number i has it's special value equal to wi, that is s(xi, yi) = yi - xi = wi.
Now Wilbur asks you to help him with this challenge.
Input
The first line of the input consists of a single integer n (1 ≤ n ≤ 100 000) — the number of points in the set Wilbur is playing with.
Next follow n lines with points descriptions. Each line contains two integers x and y (0 ≤ x, y ≤ 100 000), that give one point in Wilbur's set. It's guaranteed that all points are distinct. Also, it is guaranteed that if some point (x, y) is present in the input, then all points (x', y'), such that 0 ≤ x' ≤ x and 0 ≤ y' ≤ y, are also present in the input.
The last line of the input contains n integers. The i-th of them is wi ( - 100 000 ≤ wi ≤ 100 000) — the required special value of the point that gets number i in any aesthetically pleasing numbering.
Output
If there exists an aesthetically pleasant numbering of points in the set, such that s(xi, yi) = yi - xi = wi, then print "YES" on the first line of the output. Otherwise, print "NO".
If a solution exists, proceed output with n lines. On the i-th of these lines print the point of the set that gets number i. If there are multiple solutions, print any of them.
Examples
Input
5
2 0
0 0
1 0
1 1
0 1
0 -1 -2 1 0
Output
YES
0 0
1 0
2 0
0 1
1 1
Input
3
1 0
0 0
2 0
0 1 2
Output
NO
Note
In the first sample, point (2, 0) gets number 3, point (0, 0) gets number one, point (1, 0) gets number 2, point (1, 1) gets number 5 and point (0, 1) gets number 4. One can easily check that this numbering is aesthetically pleasing and yi - xi = wi.
In the second sample, the special values of the points in the set are 0, - 1, and - 2 while the sequence that the friend gives to Wilbur is 0, 1, 2. Therefore, the answer does not exist. | instruction | 0 | 35,572 | 23 | 71,144 |
Tags: combinatorics, greedy, sortings
Correct Solution:
```
n = int(input())
p = sorted([tuple(map(int, input().split())) for _ in range(n)])
arr = list(map(int, input().split()))
w, r, pr = {}, {}, {}
for i, wi in enumerate(arr, 1):
if wi not in w:
w[wi] = []
w[wi].append(i)
def is_nbr(nb, i):
return 0 if pr.get(nb, 0) > i else 1
def check_nbrs(p, i):
n1 = (p[0] - 1, p[1])
n2 = (p[0], p[1] - 1)
n3 = (p[0] - 1, p[1] - 1)
return is_nbr(n1, i) and is_nbr(n2, i) and is_nbr(n3, i)
def solve():
for i in range(len(p)):
d = p[i][1] - p[i][0]
if d not in w:
return 0
q = w[d]
if not q:
return 0
ind = q.pop(0)
r[ind] = p[i]
pr[p[i]] = ind
if not check_nbrs(p[i], ind):
return 0
return 1
if solve() == 0:
print("NO")
else:
print("YES")
for k, v in sorted(r.items()):
print(v[0], v[1])
``` | output | 1 | 35,572 | 23 | 71,145 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Wilbur is playing with a set of n points on the coordinate plane. All points have non-negative integer coordinates. Moreover, if some point (x, y) belongs to the set, then all points (x', y'), such that 0 ≤ x' ≤ x and 0 ≤ y' ≤ y also belong to this set.
Now Wilbur wants to number the points in the set he has, that is assign them distinct integer numbers from 1 to n. In order to make the numbering aesthetically pleasing, Wilbur imposes the condition that if some point (x, y) gets number i, then all (x',y') from the set, such that x' ≥ x and y' ≥ y must be assigned a number not less than i. For example, for a set of four points (0, 0), (0, 1), (1, 0) and (1, 1), there are two aesthetically pleasing numberings. One is 1, 2, 3, 4 and another one is 1, 3, 2, 4.
Wilbur's friend comes along and challenges Wilbur. For any point he defines it's special value as s(x, y) = y - x. Now he gives Wilbur some w1, w2,..., wn, and asks him to find an aesthetically pleasing numbering of the points in the set, such that the point that gets number i has it's special value equal to wi, that is s(xi, yi) = yi - xi = wi.
Now Wilbur asks you to help him with this challenge.
Input
The first line of the input consists of a single integer n (1 ≤ n ≤ 100 000) — the number of points in the set Wilbur is playing with.
Next follow n lines with points descriptions. Each line contains two integers x and y (0 ≤ x, y ≤ 100 000), that give one point in Wilbur's set. It's guaranteed that all points are distinct. Also, it is guaranteed that if some point (x, y) is present in the input, then all points (x', y'), such that 0 ≤ x' ≤ x and 0 ≤ y' ≤ y, are also present in the input.
The last line of the input contains n integers. The i-th of them is wi ( - 100 000 ≤ wi ≤ 100 000) — the required special value of the point that gets number i in any aesthetically pleasing numbering.
Output
If there exists an aesthetically pleasant numbering of points in the set, such that s(xi, yi) = yi - xi = wi, then print "YES" on the first line of the output. Otherwise, print "NO".
If a solution exists, proceed output with n lines. On the i-th of these lines print the point of the set that gets number i. If there are multiple solutions, print any of them.
Examples
Input
5
2 0
0 0
1 0
1 1
0 1
0 -1 -2 1 0
Output
YES
0 0
1 0
2 0
0 1
1 1
Input
3
1 0
0 0
2 0
0 1 2
Output
NO
Note
In the first sample, point (2, 0) gets number 3, point (0, 0) gets number one, point (1, 0) gets number 2, point (1, 1) gets number 5 and point (0, 1) gets number 4. One can easily check that this numbering is aesthetically pleasing and yi - xi = wi.
In the second sample, the special values of the points in the set are 0, - 1, and - 2 while the sequence that the friend gives to Wilbur is 0, 1, 2. Therefore, the answer does not exist. | instruction | 0 | 35,573 | 23 | 71,146 |
Tags: combinatorics, greedy, sortings
Correct Solution:
```
n = int(input())
R = lambda : map(int, input().split())
p = []
w = {}
r = {}
pr = {}
from collections import deque
for _ in range(n):
x,y = R()
p.append((x,y))
p = sorted(p)
for i,wi in enumerate(list(R()),1):
if wi not in w:
w[wi] = deque()
w[wi].append(i)
def solve(p,w,r):
for i in range(len(p)):
d = p[i][1]-p[i][0]
if d in w:
q = w[d]
if len(q) > 0:
ind = q.popleft()
r[ind] = p[i]
pr[p[i]] = ind
if not check_neighbours(p[i],ind,pr):
return 0
else:
return 0
else:
return 0
return 1
def check_neighbours(p,ind,pr):
n1 = (p[0]-1,p[1])
n2 = (p[0],p[1]-1)
n3 = (p[0]-1,p[1]-1)
return (check_neighbour(n1,ind,pr) and check_neighbour(n2,ind,pr) and check_neighbour(n3,ind,pr))
def check_neighbour(nb,ind,pr):
if nb in pr:
if pr[nb] > ind:
return 0
return 1
if solve(p,w,r) == 0:
print("NO")
else:
print("YES")
for k,v in sorted(r.items()):
print(v[0], v[1])
``` | output | 1 | 35,573 | 23 | 71,147 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Wilbur is playing with a set of n points on the coordinate plane. All points have non-negative integer coordinates. Moreover, if some point (x, y) belongs to the set, then all points (x', y'), such that 0 ≤ x' ≤ x and 0 ≤ y' ≤ y also belong to this set.
Now Wilbur wants to number the points in the set he has, that is assign them distinct integer numbers from 1 to n. In order to make the numbering aesthetically pleasing, Wilbur imposes the condition that if some point (x, y) gets number i, then all (x',y') from the set, such that x' ≥ x and y' ≥ y must be assigned a number not less than i. For example, for a set of four points (0, 0), (0, 1), (1, 0) and (1, 1), there are two aesthetically pleasing numberings. One is 1, 2, 3, 4 and another one is 1, 3, 2, 4.
Wilbur's friend comes along and challenges Wilbur. For any point he defines it's special value as s(x, y) = y - x. Now he gives Wilbur some w1, w2,..., wn, and asks him to find an aesthetically pleasing numbering of the points in the set, such that the point that gets number i has it's special value equal to wi, that is s(xi, yi) = yi - xi = wi.
Now Wilbur asks you to help him with this challenge.
Input
The first line of the input consists of a single integer n (1 ≤ n ≤ 100 000) — the number of points in the set Wilbur is playing with.
Next follow n lines with points descriptions. Each line contains two integers x and y (0 ≤ x, y ≤ 100 000), that give one point in Wilbur's set. It's guaranteed that all points are distinct. Also, it is guaranteed that if some point (x, y) is present in the input, then all points (x', y'), such that 0 ≤ x' ≤ x and 0 ≤ y' ≤ y, are also present in the input.
The last line of the input contains n integers. The i-th of them is wi ( - 100 000 ≤ wi ≤ 100 000) — the required special value of the point that gets number i in any aesthetically pleasing numbering.
Output
If there exists an aesthetically pleasant numbering of points in the set, such that s(xi, yi) = yi - xi = wi, then print "YES" on the first line of the output. Otherwise, print "NO".
If a solution exists, proceed output with n lines. On the i-th of these lines print the point of the set that gets number i. If there are multiple solutions, print any of them.
Examples
Input
5
2 0
0 0
1 0
1 1
0 1
0 -1 -2 1 0
Output
YES
0 0
1 0
2 0
0 1
1 1
Input
3
1 0
0 0
2 0
0 1 2
Output
NO
Note
In the first sample, point (2, 0) gets number 3, point (0, 0) gets number one, point (1, 0) gets number 2, point (1, 1) gets number 5 and point (0, 1) gets number 4. One can easily check that this numbering is aesthetically pleasing and yi - xi = wi.
In the second sample, the special values of the points in the set are 0, - 1, and - 2 while the sequence that the friend gives to Wilbur is 0, 1, 2. Therefore, the answer does not exist. | instruction | 0 | 35,574 | 23 | 71,148 |
Tags: combinatorics, greedy, sortings
Correct Solution:
```
def main():
n = int(input())
diag = [0] * 200005
use = [0] * 200005
for i in range(n):
x, y = [int(i) for i in input().split(' ')]
c = y - x
if c > 0:
diag[c] = max(x+1, diag[c])
else:
diag[c] = max(y+1, diag[c])
table = set()
for i in range(100005):
table.add((-1, i))
table.add((i, -1))
result = []
for v in [int(i) for i in input().split(' ')]:
# print(v)
if v > 0:
x = use[v]
y = x + v
else:
y = use[v]
x = y - v
# print(x, y, use[v], diag[v], use[v] > diag[v], (x-1, y) not in table, (x, y-1) not in table)
use[v] += 1
if use[v] > diag[v]:
print ('NO')
return
if (x-1, y) not in table or (x, y-1) not in table:
print ('NO')
return
table.add((x, y))
result.append((x, y))
print('YES')
for v in result:
print(v[0], v[1])
main()
``` | output | 1 | 35,574 | 23 | 71,149 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Wilbur is playing with a set of n points on the coordinate plane. All points have non-negative integer coordinates. Moreover, if some point (x, y) belongs to the set, then all points (x', y'), such that 0 ≤ x' ≤ x and 0 ≤ y' ≤ y also belong to this set.
Now Wilbur wants to number the points in the set he has, that is assign them distinct integer numbers from 1 to n. In order to make the numbering aesthetically pleasing, Wilbur imposes the condition that if some point (x, y) gets number i, then all (x',y') from the set, such that x' ≥ x and y' ≥ y must be assigned a number not less than i. For example, for a set of four points (0, 0), (0, 1), (1, 0) and (1, 1), there are two aesthetically pleasing numberings. One is 1, 2, 3, 4 and another one is 1, 3, 2, 4.
Wilbur's friend comes along and challenges Wilbur. For any point he defines it's special value as s(x, y) = y - x. Now he gives Wilbur some w1, w2,..., wn, and asks him to find an aesthetically pleasing numbering of the points in the set, such that the point that gets number i has it's special value equal to wi, that is s(xi, yi) = yi - xi = wi.
Now Wilbur asks you to help him with this challenge.
Input
The first line of the input consists of a single integer n (1 ≤ n ≤ 100 000) — the number of points in the set Wilbur is playing with.
Next follow n lines with points descriptions. Each line contains two integers x and y (0 ≤ x, y ≤ 100 000), that give one point in Wilbur's set. It's guaranteed that all points are distinct. Also, it is guaranteed that if some point (x, y) is present in the input, then all points (x', y'), such that 0 ≤ x' ≤ x and 0 ≤ y' ≤ y, are also present in the input.
The last line of the input contains n integers. The i-th of them is wi ( - 100 000 ≤ wi ≤ 100 000) — the required special value of the point that gets number i in any aesthetically pleasing numbering.
Output
If there exists an aesthetically pleasant numbering of points in the set, such that s(xi, yi) = yi - xi = wi, then print "YES" on the first line of the output. Otherwise, print "NO".
If a solution exists, proceed output with n lines. On the i-th of these lines print the point of the set that gets number i. If there are multiple solutions, print any of them.
Examples
Input
5
2 0
0 0
1 0
1 1
0 1
0 -1 -2 1 0
Output
YES
0 0
1 0
2 0
0 1
1 1
Input
3
1 0
0 0
2 0
0 1 2
Output
NO
Note
In the first sample, point (2, 0) gets number 3, point (0, 0) gets number one, point (1, 0) gets number 2, point (1, 1) gets number 5 and point (0, 1) gets number 4. One can easily check that this numbering is aesthetically pleasing and yi - xi = wi.
In the second sample, the special values of the points in the set are 0, - 1, and - 2 while the sequence that the friend gives to Wilbur is 0, 1, 2. Therefore, the answer does not exist. | instruction | 0 | 35,575 | 23 | 71,150 |
Tags: combinatorics, greedy, sortings
Correct Solution:
```
from collections import deque
dp={}
for i in range(int(input())):
x,y = map(int, input().split())
if y-x in dp:
dp[y-x].append((x,y))
else:
dp[y-x]=[(x,y)]
for i in dp:
dp[i].sort()
dp[i]=deque(dp[i])
w=list(map(int, input().split()))
ans=[0]*len(w)
flag=1
for i in range(len(w)):
if not w[i] in dp or not len(dp[w[i]]):
flag=0
break
ans[i]=dp[w[i]].popleft()
if not flag:
print("NO")
else:
for i in range(1,len(ans)):
if ans[i][0]<=ans[i-1][0] and ans[i][1]<=ans[i-1][1]:
flag=0
if not flag:
print("NO")
else:
print("YES")
for i in ans:
print(i[0], i[1])
# Made By Mostafa_Khaled
``` | output | 1 | 35,575 | 23 | 71,151 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Wilbur is playing with a set of n points on the coordinate plane. All points have non-negative integer coordinates. Moreover, if some point (x, y) belongs to the set, then all points (x', y'), such that 0 ≤ x' ≤ x and 0 ≤ y' ≤ y also belong to this set.
Now Wilbur wants to number the points in the set he has, that is assign them distinct integer numbers from 1 to n. In order to make the numbering aesthetically pleasing, Wilbur imposes the condition that if some point (x, y) gets number i, then all (x',y') from the set, such that x' ≥ x and y' ≥ y must be assigned a number not less than i. For example, for a set of four points (0, 0), (0, 1), (1, 0) and (1, 1), there are two aesthetically pleasing numberings. One is 1, 2, 3, 4 and another one is 1, 3, 2, 4.
Wilbur's friend comes along and challenges Wilbur. For any point he defines it's special value as s(x, y) = y - x. Now he gives Wilbur some w1, w2,..., wn, and asks him to find an aesthetically pleasing numbering of the points in the set, such that the point that gets number i has it's special value equal to wi, that is s(xi, yi) = yi - xi = wi.
Now Wilbur asks you to help him with this challenge.
Input
The first line of the input consists of a single integer n (1 ≤ n ≤ 100 000) — the number of points in the set Wilbur is playing with.
Next follow n lines with points descriptions. Each line contains two integers x and y (0 ≤ x, y ≤ 100 000), that give one point in Wilbur's set. It's guaranteed that all points are distinct. Also, it is guaranteed that if some point (x, y) is present in the input, then all points (x', y'), such that 0 ≤ x' ≤ x and 0 ≤ y' ≤ y, are also present in the input.
The last line of the input contains n integers. The i-th of them is wi ( - 100 000 ≤ wi ≤ 100 000) — the required special value of the point that gets number i in any aesthetically pleasing numbering.
Output
If there exists an aesthetically pleasant numbering of points in the set, such that s(xi, yi) = yi - xi = wi, then print "YES" on the first line of the output. Otherwise, print "NO".
If a solution exists, proceed output with n lines. On the i-th of these lines print the point of the set that gets number i. If there are multiple solutions, print any of them.
Examples
Input
5
2 0
0 0
1 0
1 1
0 1
0 -1 -2 1 0
Output
YES
0 0
1 0
2 0
0 1
1 1
Input
3
1 0
0 0
2 0
0 1 2
Output
NO
Note
In the first sample, point (2, 0) gets number 3, point (0, 0) gets number one, point (1, 0) gets number 2, point (1, 1) gets number 5 and point (0, 1) gets number 4. One can easily check that this numbering is aesthetically pleasing and yi - xi = wi.
In the second sample, the special values of the points in the set are 0, - 1, and - 2 while the sequence that the friend gives to Wilbur is 0, 1, 2. Therefore, the answer does not exist. | instruction | 0 | 35,576 | 23 | 71,152 |
Tags: combinatorics, greedy, sortings
Correct Solution:
```
n = int(input())
MAX = 100000
coord = [list() for i in range(2 * MAX + 1)]
for i in range(n):
x, y = map(int, input().split())
coord[y - x - MAX].append((x, y))
w = list(map(int, input().split()))
for i in range(2 * MAX + 1):
coord[i].sort()
ans = [(0, 0) for i in range(n)]
possible = True
last_x = [-1] * (MAX + 1)
last_y = [-1] * (MAX + 1)
for i in range(n):
if len(coord[w[i] - MAX]) > 0:
x = coord[w[i] - MAX][0][0]
y = coord[w[i] - MAX][0][1]
if last_x[y] == x - 1 and last_y[x] == y - 1:
last_x[y] += 1
last_y[x] += 1
ans[i] = x, y
coord[w[i] - MAX].pop(0)
else:
possible = False
break
else:
possible = False
break
if possible:
print("YES")
print("\n".join([" ".join(map(str, coords)) for coords in ans]))
else:
print("NO")
``` | output | 1 | 35,576 | 23 | 71,153 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Wilbur is playing with a set of n points on the coordinate plane. All points have non-negative integer coordinates. Moreover, if some point (x, y) belongs to the set, then all points (x', y'), such that 0 ≤ x' ≤ x and 0 ≤ y' ≤ y also belong to this set.
Now Wilbur wants to number the points in the set he has, that is assign them distinct integer numbers from 1 to n. In order to make the numbering aesthetically pleasing, Wilbur imposes the condition that if some point (x, y) gets number i, then all (x',y') from the set, such that x' ≥ x and y' ≥ y must be assigned a number not less than i. For example, for a set of four points (0, 0), (0, 1), (1, 0) and (1, 1), there are two aesthetically pleasing numberings. One is 1, 2, 3, 4 and another one is 1, 3, 2, 4.
Wilbur's friend comes along and challenges Wilbur. For any point he defines it's special value as s(x, y) = y - x. Now he gives Wilbur some w1, w2,..., wn, and asks him to find an aesthetically pleasing numbering of the points in the set, such that the point that gets number i has it's special value equal to wi, that is s(xi, yi) = yi - xi = wi.
Now Wilbur asks you to help him with this challenge.
Input
The first line of the input consists of a single integer n (1 ≤ n ≤ 100 000) — the number of points in the set Wilbur is playing with.
Next follow n lines with points descriptions. Each line contains two integers x and y (0 ≤ x, y ≤ 100 000), that give one point in Wilbur's set. It's guaranteed that all points are distinct. Also, it is guaranteed that if some point (x, y) is present in the input, then all points (x', y'), such that 0 ≤ x' ≤ x and 0 ≤ y' ≤ y, are also present in the input.
The last line of the input contains n integers. The i-th of them is wi ( - 100 000 ≤ wi ≤ 100 000) — the required special value of the point that gets number i in any aesthetically pleasing numbering.
Output
If there exists an aesthetically pleasant numbering of points in the set, such that s(xi, yi) = yi - xi = wi, then print "YES" on the first line of the output. Otherwise, print "NO".
If a solution exists, proceed output with n lines. On the i-th of these lines print the point of the set that gets number i. If there are multiple solutions, print any of them.
Examples
Input
5
2 0
0 0
1 0
1 1
0 1
0 -1 -2 1 0
Output
YES
0 0
1 0
2 0
0 1
1 1
Input
3
1 0
0 0
2 0
0 1 2
Output
NO
Note
In the first sample, point (2, 0) gets number 3, point (0, 0) gets number one, point (1, 0) gets number 2, point (1, 1) gets number 5 and point (0, 1) gets number 4. One can easily check that this numbering is aesthetically pleasing and yi - xi = wi.
In the second sample, the special values of the points in the set are 0, - 1, and - 2 while the sequence that the friend gives to Wilbur is 0, 1, 2. Therefore, the answer does not exist. | instruction | 0 | 35,577 | 23 | 71,154 |
Tags: combinatorics, greedy, sortings
Correct Solution:
```
read = lambda: map(int, input().split())
n = int(input())
Max = {}
for i in range(n):
x, y = read()
s = y - x
if s not in Max or y > Max[s]:
Max[s] = y
cur = {i: max(i, 0) for i in Max}
ans = []
def no():
print('NO')
exit()
for i in read():
if i not in cur: no()
y = cur[i]
f2 = y > Max[i]
f3 = i + 1 in cur and cur[i + 1] != y + 1
f4 = i - 1 in cur and cur[i - 1] != y
if f2 or f3 or f4: no()
ans.append('%d %d' % (y - i, y))
cur[i] = y + 1
print('YES\n' + '\n'.join(ans))
``` | output | 1 | 35,577 | 23 | 71,155 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Wilbur is playing with a set of n points on the coordinate plane. All points have non-negative integer coordinates. Moreover, if some point (x, y) belongs to the set, then all points (x', y'), such that 0 ≤ x' ≤ x and 0 ≤ y' ≤ y also belong to this set.
Now Wilbur wants to number the points in the set he has, that is assign them distinct integer numbers from 1 to n. In order to make the numbering aesthetically pleasing, Wilbur imposes the condition that if some point (x, y) gets number i, then all (x',y') from the set, such that x' ≥ x and y' ≥ y must be assigned a number not less than i. For example, for a set of four points (0, 0), (0, 1), (1, 0) and (1, 1), there are two aesthetically pleasing numberings. One is 1, 2, 3, 4 and another one is 1, 3, 2, 4.
Wilbur's friend comes along and challenges Wilbur. For any point he defines it's special value as s(x, y) = y - x. Now he gives Wilbur some w1, w2,..., wn, and asks him to find an aesthetically pleasing numbering of the points in the set, such that the point that gets number i has it's special value equal to wi, that is s(xi, yi) = yi - xi = wi.
Now Wilbur asks you to help him with this challenge.
Input
The first line of the input consists of a single integer n (1 ≤ n ≤ 100 000) — the number of points in the set Wilbur is playing with.
Next follow n lines with points descriptions. Each line contains two integers x and y (0 ≤ x, y ≤ 100 000), that give one point in Wilbur's set. It's guaranteed that all points are distinct. Also, it is guaranteed that if some point (x, y) is present in the input, then all points (x', y'), such that 0 ≤ x' ≤ x and 0 ≤ y' ≤ y, are also present in the input.
The last line of the input contains n integers. The i-th of them is wi ( - 100 000 ≤ wi ≤ 100 000) — the required special value of the point that gets number i in any aesthetically pleasing numbering.
Output
If there exists an aesthetically pleasant numbering of points in the set, such that s(xi, yi) = yi - xi = wi, then print "YES" on the first line of the output. Otherwise, print "NO".
If a solution exists, proceed output with n lines. On the i-th of these lines print the point of the set that gets number i. If there are multiple solutions, print any of them.
Examples
Input
5
2 0
0 0
1 0
1 1
0 1
0 -1 -2 1 0
Output
YES
0 0
1 0
2 0
0 1
1 1
Input
3
1 0
0 0
2 0
0 1 2
Output
NO
Note
In the first sample, point (2, 0) gets number 3, point (0, 0) gets number one, point (1, 0) gets number 2, point (1, 1) gets number 5 and point (0, 1) gets number 4. One can easily check that this numbering is aesthetically pleasing and yi - xi = wi.
In the second sample, the special values of the points in the set are 0, - 1, and - 2 while the sequence that the friend gives to Wilbur is 0, 1, 2. Therefore, the answer does not exist. | instruction | 0 | 35,578 | 23 | 71,156 |
Tags: combinatorics, greedy, sortings
Correct Solution:
```
def binsearch(lofpoints,l,r,w,arr):
if(l>r):
return "None"
mid=(l+r)//2
if(lofpoints[mid][0]==w and arr[mid]==1):
if(mid==0):
arr[mid]=0
return mid
elif(lofpoints[mid-1][0]!=w or arr[mid-1]==0):
arr[mid]=0
return mid
else:
return binsearch(lofpoints,l,mid-1,w,arr)
if(lofpoints[mid][0]==w and arr[mid]==0):
return binsearch(lofpoints,mid+1,r,w,arr)
if(lofpoints[mid][0]<w):
return binsearch(lofpoints,mid+1,r,w,arr)
if(lofpoints[mid][0]>w):
return binsearch(lofpoints,l,mid-1,w,arr)
n=int(input())
lofpoints=[]
for i in range(n):
l=input().split()
x=int(l[0])
y=int(l[1])
lofpoints.append((y-x,x,y))
lofpoints.sort()
w=input().split()
wi=[int(i) for i in w]
arr=[1 for i in range(n)]
lsol=[]
done=1
#print(lofpoints)
for i in range(n):
x=binsearch(lofpoints,0,n-1,wi[i],arr)
#print(x)
if(x=="None"):
done=0
break
elif(lsol==[]):
lsol.append((lofpoints[x][1],lofpoints[x][2]))
elif(lofpoints[x][1]<lsol[-1][0] and lofpoints[x][2]<lsol[-1][1]):
done=0
break
else:
lsol.append((lofpoints[x][1],lofpoints[x][2]))
#print(lsol)
if(done==1):
hashi=dict()
for i in range(n):
hashi[(lsol[i][0],lsol[i][1])]=i
for i in hashi:
x=i[0]
y=i[1]
t=hashi[i]
if((x,y+1) in hashi):
if(hashi[(x,y+1)]<t):
done=0
break
if((x+1,y) in hashi):
if(hashi[(x+1,y)]<t):
done=0
break
if(done==0):
print("NO")
else:
print("YES")
for i in lsol:
print(i[0],i[1])
else:
print("NO")
``` | output | 1 | 35,578 | 23 | 71,157 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Wilbur is playing with a set of n points on the coordinate plane. All points have non-negative integer coordinates. Moreover, if some point (x, y) belongs to the set, then all points (x', y'), such that 0 ≤ x' ≤ x and 0 ≤ y' ≤ y also belong to this set.
Now Wilbur wants to number the points in the set he has, that is assign them distinct integer numbers from 1 to n. In order to make the numbering aesthetically pleasing, Wilbur imposes the condition that if some point (x, y) gets number i, then all (x',y') from the set, such that x' ≥ x and y' ≥ y must be assigned a number not less than i. For example, for a set of four points (0, 0), (0, 1), (1, 0) and (1, 1), there are two aesthetically pleasing numberings. One is 1, 2, 3, 4 and another one is 1, 3, 2, 4.
Wilbur's friend comes along and challenges Wilbur. For any point he defines it's special value as s(x, y) = y - x. Now he gives Wilbur some w1, w2,..., wn, and asks him to find an aesthetically pleasing numbering of the points in the set, such that the point that gets number i has it's special value equal to wi, that is s(xi, yi) = yi - xi = wi.
Now Wilbur asks you to help him with this challenge.
Input
The first line of the input consists of a single integer n (1 ≤ n ≤ 100 000) — the number of points in the set Wilbur is playing with.
Next follow n lines with points descriptions. Each line contains two integers x and y (0 ≤ x, y ≤ 100 000), that give one point in Wilbur's set. It's guaranteed that all points are distinct. Also, it is guaranteed that if some point (x, y) is present in the input, then all points (x', y'), such that 0 ≤ x' ≤ x and 0 ≤ y' ≤ y, are also present in the input.
The last line of the input contains n integers. The i-th of them is wi ( - 100 000 ≤ wi ≤ 100 000) — the required special value of the point that gets number i in any aesthetically pleasing numbering.
Output
If there exists an aesthetically pleasant numbering of points in the set, such that s(xi, yi) = yi - xi = wi, then print "YES" on the first line of the output. Otherwise, print "NO".
If a solution exists, proceed output with n lines. On the i-th of these lines print the point of the set that gets number i. If there are multiple solutions, print any of them.
Examples
Input
5
2 0
0 0
1 0
1 1
0 1
0 -1 -2 1 0
Output
YES
0 0
1 0
2 0
0 1
1 1
Input
3
1 0
0 0
2 0
0 1 2
Output
NO
Note
In the first sample, point (2, 0) gets number 3, point (0, 0) gets number one, point (1, 0) gets number 2, point (1, 1) gets number 5 and point (0, 1) gets number 4. One can easily check that this numbering is aesthetically pleasing and yi - xi = wi.
In the second sample, the special values of the points in the set are 0, - 1, and - 2 while the sequence that the friend gives to Wilbur is 0, 1, 2. Therefore, the answer does not exist. | instruction | 0 | 35,579 | 23 | 71,158 |
Tags: combinatorics, greedy, sortings
Correct Solution:
```
from collections import defaultdict
from operator import itemgetter
n = int(input())
points = []
point_weights = defaultdict(list)
for _ in range(n):
x, y = tuple(map(int,input().split()))
points.append((x, y))
point_weights[y - x].append((x, y))
weights = list(map(int, input().split()))
points.sort(key=itemgetter(0, 1))
for w, p in point_weights.items():
point_weights[w] = sorted(p, key=itemgetter(0, 1), reverse=True)
ans = "YES"
ans_arr = []
for weight in weights:
if weight not in point_weights:
ans = "NO"
break
else:
if len(point_weights[weight]) == 0:
ans = "NO"
break
else:
ans_arr.append(point_weights[weight].pop())
for i in range(1, len(ans_arr)):
if ans_arr[i][0] <= ans_arr[i - 1][0] and ans_arr[i][1] <= ans_arr[i - 1][1]:
ans = "NO"
break
print(ans)
if ans == "YES":
for point in ans_arr:
print(*point)
``` | output | 1 | 35,579 | 23 | 71,159 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Wilbur is playing with a set of n points on the coordinate plane. All points have non-negative integer coordinates. Moreover, if some point (x, y) belongs to the set, then all points (x', y'), such that 0 ≤ x' ≤ x and 0 ≤ y' ≤ y also belong to this set.
Now Wilbur wants to number the points in the set he has, that is assign them distinct integer numbers from 1 to n. In order to make the numbering aesthetically pleasing, Wilbur imposes the condition that if some point (x, y) gets number i, then all (x',y') from the set, such that x' ≥ x and y' ≥ y must be assigned a number not less than i. For example, for a set of four points (0, 0), (0, 1), (1, 0) and (1, 1), there are two aesthetically pleasing numberings. One is 1, 2, 3, 4 and another one is 1, 3, 2, 4.
Wilbur's friend comes along and challenges Wilbur. For any point he defines it's special value as s(x, y) = y - x. Now he gives Wilbur some w1, w2,..., wn, and asks him to find an aesthetically pleasing numbering of the points in the set, such that the point that gets number i has it's special value equal to wi, that is s(xi, yi) = yi - xi = wi.
Now Wilbur asks you to help him with this challenge.
Input
The first line of the input consists of a single integer n (1 ≤ n ≤ 100 000) — the number of points in the set Wilbur is playing with.
Next follow n lines with points descriptions. Each line contains two integers x and y (0 ≤ x, y ≤ 100 000), that give one point in Wilbur's set. It's guaranteed that all points are distinct. Also, it is guaranteed that if some point (x, y) is present in the input, then all points (x', y'), such that 0 ≤ x' ≤ x and 0 ≤ y' ≤ y, are also present in the input.
The last line of the input contains n integers. The i-th of them is wi ( - 100 000 ≤ wi ≤ 100 000) — the required special value of the point that gets number i in any aesthetically pleasing numbering.
Output
If there exists an aesthetically pleasant numbering of points in the set, such that s(xi, yi) = yi - xi = wi, then print "YES" on the first line of the output. Otherwise, print "NO".
If a solution exists, proceed output with n lines. On the i-th of these lines print the point of the set that gets number i. If there are multiple solutions, print any of them.
Examples
Input
5
2 0
0 0
1 0
1 1
0 1
0 -1 -2 1 0
Output
YES
0 0
1 0
2 0
0 1
1 1
Input
3
1 0
0 0
2 0
0 1 2
Output
NO
Note
In the first sample, point (2, 0) gets number 3, point (0, 0) gets number one, point (1, 0) gets number 2, point (1, 1) gets number 5 and point (0, 1) gets number 4. One can easily check that this numbering is aesthetically pleasing and yi - xi = wi.
In the second sample, the special values of the points in the set are 0, - 1, and - 2 while the sequence that the friend gives to Wilbur is 0, 1, 2. Therefore, the answer does not exist.
Submitted Solution:
```
if __name__ == "__main__":
n = int( input() )
maxX = [-1]*100005
for _ in range(n):
px,py = [int(x) for x in input().split()]
maxX[py] = max( maxX[py] , px )
#print( maxX[:2] )
w = [int(x) for x in input().split()]
p = [-1]*100005
p[0] = 0
wdict = dict()
wdict[0] = (0,0)
res = []
for wi in w:
if wi in wdict:
px , py = wdict.pop(wi)
res.append( (px,py) )
if maxX[py] > px:
wdict[py-(px+1)] = (px+1,py)
p[py] += 1
if maxX[py+1] != -1 and p[py+1] == -1:
wdict[py+1] = (0,py+1)
p[py+1] += 1
else:
break
if len(res) == n:
print("YES")
for ares in res:
print(ares[0],ares[1])
else:
print("NO")
``` | instruction | 0 | 35,580 | 23 | 71,160 |
Yes | output | 1 | 35,580 | 23 | 71,161 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Wilbur is playing with a set of n points on the coordinate plane. All points have non-negative integer coordinates. Moreover, if some point (x, y) belongs to the set, then all points (x', y'), such that 0 ≤ x' ≤ x and 0 ≤ y' ≤ y also belong to this set.
Now Wilbur wants to number the points in the set he has, that is assign them distinct integer numbers from 1 to n. In order to make the numbering aesthetically pleasing, Wilbur imposes the condition that if some point (x, y) gets number i, then all (x',y') from the set, such that x' ≥ x and y' ≥ y must be assigned a number not less than i. For example, for a set of four points (0, 0), (0, 1), (1, 0) and (1, 1), there are two aesthetically pleasing numberings. One is 1, 2, 3, 4 and another one is 1, 3, 2, 4.
Wilbur's friend comes along and challenges Wilbur. For any point he defines it's special value as s(x, y) = y - x. Now he gives Wilbur some w1, w2,..., wn, and asks him to find an aesthetically pleasing numbering of the points in the set, such that the point that gets number i has it's special value equal to wi, that is s(xi, yi) = yi - xi = wi.
Now Wilbur asks you to help him with this challenge.
Input
The first line of the input consists of a single integer n (1 ≤ n ≤ 100 000) — the number of points in the set Wilbur is playing with.
Next follow n lines with points descriptions. Each line contains two integers x and y (0 ≤ x, y ≤ 100 000), that give one point in Wilbur's set. It's guaranteed that all points are distinct. Also, it is guaranteed that if some point (x, y) is present in the input, then all points (x', y'), such that 0 ≤ x' ≤ x and 0 ≤ y' ≤ y, are also present in the input.
The last line of the input contains n integers. The i-th of them is wi ( - 100 000 ≤ wi ≤ 100 000) — the required special value of the point that gets number i in any aesthetically pleasing numbering.
Output
If there exists an aesthetically pleasant numbering of points in the set, such that s(xi, yi) = yi - xi = wi, then print "YES" on the first line of the output. Otherwise, print "NO".
If a solution exists, proceed output with n lines. On the i-th of these lines print the point of the set that gets number i. If there are multiple solutions, print any of them.
Examples
Input
5
2 0
0 0
1 0
1 1
0 1
0 -1 -2 1 0
Output
YES
0 0
1 0
2 0
0 1
1 1
Input
3
1 0
0 0
2 0
0 1 2
Output
NO
Note
In the first sample, point (2, 0) gets number 3, point (0, 0) gets number one, point (1, 0) gets number 2, point (1, 1) gets number 5 and point (0, 1) gets number 4. One can easily check that this numbering is aesthetically pleasing and yi - xi = wi.
In the second sample, the special values of the points in the set are 0, - 1, and - 2 while the sequence that the friend gives to Wilbur is 0, 1, 2. Therefore, the answer does not exist.
Submitted Solution:
```
__author__ = 'mac'
from collections import Counter
def sortByDiag(elem):
return elem[0]*elem[0]+elem[1]*elem[1]
count = int(input())
points = {}
compList = []
for i in range(count):
x,y = [int(x) for x in input().strip().split(' ')]
w = y-x
compList.append(w)
if not w in points:
points[w] = []
points[w].append([x,y])
wArr = []
for x in input().strip().split(' '):
if (len(wArr) > 1 and int(x) == wArr[-1]) or (abs(int(x))>len(wArr)):
print('NO')
exit()
wArr.append(int(x))
c1 = Counter(wArr)
c2 = Counter(compList)
diff = c1-c2
if len(list(diff.elements())) != 0:
print('NO')
exit()
print('YES')
for e in points:
points[e] = sorted(points[e], key = sortByDiag)
for i in wArr:
temp = points[i].pop(0)
print(temp[0],temp[1])
``` | instruction | 0 | 35,581 | 23 | 71,162 |
Yes | output | 1 | 35,581 | 23 | 71,163 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Wilbur is playing with a set of n points on the coordinate plane. All points have non-negative integer coordinates. Moreover, if some point (x, y) belongs to the set, then all points (x', y'), such that 0 ≤ x' ≤ x and 0 ≤ y' ≤ y also belong to this set.
Now Wilbur wants to number the points in the set he has, that is assign them distinct integer numbers from 1 to n. In order to make the numbering aesthetically pleasing, Wilbur imposes the condition that if some point (x, y) gets number i, then all (x',y') from the set, such that x' ≥ x and y' ≥ y must be assigned a number not less than i. For example, for a set of four points (0, 0), (0, 1), (1, 0) and (1, 1), there are two aesthetically pleasing numberings. One is 1, 2, 3, 4 and another one is 1, 3, 2, 4.
Wilbur's friend comes along and challenges Wilbur. For any point he defines it's special value as s(x, y) = y - x. Now he gives Wilbur some w1, w2,..., wn, and asks him to find an aesthetically pleasing numbering of the points in the set, such that the point that gets number i has it's special value equal to wi, that is s(xi, yi) = yi - xi = wi.
Now Wilbur asks you to help him with this challenge.
Input
The first line of the input consists of a single integer n (1 ≤ n ≤ 100 000) — the number of points in the set Wilbur is playing with.
Next follow n lines with points descriptions. Each line contains two integers x and y (0 ≤ x, y ≤ 100 000), that give one point in Wilbur's set. It's guaranteed that all points are distinct. Also, it is guaranteed that if some point (x, y) is present in the input, then all points (x', y'), such that 0 ≤ x' ≤ x and 0 ≤ y' ≤ y, are also present in the input.
The last line of the input contains n integers. The i-th of them is wi ( - 100 000 ≤ wi ≤ 100 000) — the required special value of the point that gets number i in any aesthetically pleasing numbering.
Output
If there exists an aesthetically pleasant numbering of points in the set, such that s(xi, yi) = yi - xi = wi, then print "YES" on the first line of the output. Otherwise, print "NO".
If a solution exists, proceed output with n lines. On the i-th of these lines print the point of the set that gets number i. If there are multiple solutions, print any of them.
Examples
Input
5
2 0
0 0
1 0
1 1
0 1
0 -1 -2 1 0
Output
YES
0 0
1 0
2 0
0 1
1 1
Input
3
1 0
0 0
2 0
0 1 2
Output
NO
Note
In the first sample, point (2, 0) gets number 3, point (0, 0) gets number one, point (1, 0) gets number 2, point (1, 1) gets number 5 and point (0, 1) gets number 4. One can easily check that this numbering is aesthetically pleasing and yi - xi = wi.
In the second sample, the special values of the points in the set are 0, - 1, and - 2 while the sequence that the friend gives to Wilbur is 0, 1, 2. Therefore, the answer does not exist.
Submitted Solution:
```
n = int(input())
max_y = {}
for i in range(n):
x, y = map(int, input().split())
key = y - x
if key not in max_y or y > max_y[key]:
max_y[key] = y
curr_y = { key: max(key, 0) for key in max_y }
result = []
def fail():
print('NO')
import sys; sys.exit()
for key in map(int, input().split()):
if key not in curr_y:
fail()
y = curr_y[key]
if y > max_y[key]:
fail()
if key + 1 in curr_y and curr_y[key + 1] != y + 1:
fail()
if key - 1 in curr_y and curr_y[key - 1] != y:
fail()
result.append('%d %d' % (y - key, y))
curr_y[key] = y + 1
print('YES')
print('\n'.join(result))
``` | instruction | 0 | 35,582 | 23 | 71,164 |
Yes | output | 1 | 35,582 | 23 | 71,165 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Wilbur is playing with a set of n points on the coordinate plane. All points have non-negative integer coordinates. Moreover, if some point (x, y) belongs to the set, then all points (x', y'), such that 0 ≤ x' ≤ x and 0 ≤ y' ≤ y also belong to this set.
Now Wilbur wants to number the points in the set he has, that is assign them distinct integer numbers from 1 to n. In order to make the numbering aesthetically pleasing, Wilbur imposes the condition that if some point (x, y) gets number i, then all (x',y') from the set, such that x' ≥ x and y' ≥ y must be assigned a number not less than i. For example, for a set of four points (0, 0), (0, 1), (1, 0) and (1, 1), there are two aesthetically pleasing numberings. One is 1, 2, 3, 4 and another one is 1, 3, 2, 4.
Wilbur's friend comes along and challenges Wilbur. For any point he defines it's special value as s(x, y) = y - x. Now he gives Wilbur some w1, w2,..., wn, and asks him to find an aesthetically pleasing numbering of the points in the set, such that the point that gets number i has it's special value equal to wi, that is s(xi, yi) = yi - xi = wi.
Now Wilbur asks you to help him with this challenge.
Input
The first line of the input consists of a single integer n (1 ≤ n ≤ 100 000) — the number of points in the set Wilbur is playing with.
Next follow n lines with points descriptions. Each line contains two integers x and y (0 ≤ x, y ≤ 100 000), that give one point in Wilbur's set. It's guaranteed that all points are distinct. Also, it is guaranteed that if some point (x, y) is present in the input, then all points (x', y'), such that 0 ≤ x' ≤ x and 0 ≤ y' ≤ y, are also present in the input.
The last line of the input contains n integers. The i-th of them is wi ( - 100 000 ≤ wi ≤ 100 000) — the required special value of the point that gets number i in any aesthetically pleasing numbering.
Output
If there exists an aesthetically pleasant numbering of points in the set, such that s(xi, yi) = yi - xi = wi, then print "YES" on the first line of the output. Otherwise, print "NO".
If a solution exists, proceed output with n lines. On the i-th of these lines print the point of the set that gets number i. If there are multiple solutions, print any of them.
Examples
Input
5
2 0
0 0
1 0
1 1
0 1
0 -1 -2 1 0
Output
YES
0 0
1 0
2 0
0 1
1 1
Input
3
1 0
0 0
2 0
0 1 2
Output
NO
Note
In the first sample, point (2, 0) gets number 3, point (0, 0) gets number one, point (1, 0) gets number 2, point (1, 1) gets number 5 and point (0, 1) gets number 4. One can easily check that this numbering is aesthetically pleasing and yi - xi = wi.
In the second sample, the special values of the points in the set are 0, - 1, and - 2 while the sequence that the friend gives to Wilbur is 0, 1, 2. Therefore, the answer does not exist.
Submitted Solution:
```
n = int(input().rstrip())
l = set()
for i in range(n):
l.add(tuple(map(int, input().rstrip().split())))
w = list(map(int, input().rstrip().split()))
d = {0: (0, 0)}
s = ""
visited = set()
visited.add((0, 0))
for k in w:
if d.get(k, None) is None:
print("NO")
exit(0)
p = d[k]
del d[k]
s += "{} {}\n".format(*p)
if p[1] == 0 and (p[0] + 1, p[1]) in l:
visited.add((p[0] + 1, p[1]))
d[-p[0] - 1] = (p[0] + 1, 0)
else:
if (p[0] + 1, p[1] - 1) in visited and (p[0]+1, p[1]) in l:
visited.add((p[0] + 1, p[1]))
d[p[1] - p[0] - 1] = (p[0] + 1, p[1])
if p[0] == 0 and (0, p[1] + 1) in l:
d[p[1] + 1] = (0, p[1] + 1)
visited.add((0, p[1] + 1))
else:
if (p[0] - 1, p[1] + 1) in visited and (p[0], p[1] + 1) in l:
visited.add((p[0], p[1] + 1))
d[p[1]-p[0] + 1] = (p[0], p[1] + 1)
print("YES")
print(s,end="")
``` | instruction | 0 | 35,583 | 23 | 71,166 |
Yes | output | 1 | 35,583 | 23 | 71,167 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Wilbur is playing with a set of n points on the coordinate plane. All points have non-negative integer coordinates. Moreover, if some point (x, y) belongs to the set, then all points (x', y'), such that 0 ≤ x' ≤ x and 0 ≤ y' ≤ y also belong to this set.
Now Wilbur wants to number the points in the set he has, that is assign them distinct integer numbers from 1 to n. In order to make the numbering aesthetically pleasing, Wilbur imposes the condition that if some point (x, y) gets number i, then all (x',y') from the set, such that x' ≥ x and y' ≥ y must be assigned a number not less than i. For example, for a set of four points (0, 0), (0, 1), (1, 0) and (1, 1), there are two aesthetically pleasing numberings. One is 1, 2, 3, 4 and another one is 1, 3, 2, 4.
Wilbur's friend comes along and challenges Wilbur. For any point he defines it's special value as s(x, y) = y - x. Now he gives Wilbur some w1, w2,..., wn, and asks him to find an aesthetically pleasing numbering of the points in the set, such that the point that gets number i has it's special value equal to wi, that is s(xi, yi) = yi - xi = wi.
Now Wilbur asks you to help him with this challenge.
Input
The first line of the input consists of a single integer n (1 ≤ n ≤ 100 000) — the number of points in the set Wilbur is playing with.
Next follow n lines with points descriptions. Each line contains two integers x and y (0 ≤ x, y ≤ 100 000), that give one point in Wilbur's set. It's guaranteed that all points are distinct. Also, it is guaranteed that if some point (x, y) is present in the input, then all points (x', y'), such that 0 ≤ x' ≤ x and 0 ≤ y' ≤ y, are also present in the input.
The last line of the input contains n integers. The i-th of them is wi ( - 100 000 ≤ wi ≤ 100 000) — the required special value of the point that gets number i in any aesthetically pleasing numbering.
Output
If there exists an aesthetically pleasant numbering of points in the set, such that s(xi, yi) = yi - xi = wi, then print "YES" on the first line of the output. Otherwise, print "NO".
If a solution exists, proceed output with n lines. On the i-th of these lines print the point of the set that gets number i. If there are multiple solutions, print any of them.
Examples
Input
5
2 0
0 0
1 0
1 1
0 1
0 -1 -2 1 0
Output
YES
0 0
1 0
2 0
0 1
1 1
Input
3
1 0
0 0
2 0
0 1 2
Output
NO
Note
In the first sample, point (2, 0) gets number 3, point (0, 0) gets number one, point (1, 0) gets number 2, point (1, 1) gets number 5 and point (0, 1) gets number 4. One can easily check that this numbering is aesthetically pleasing and yi - xi = wi.
In the second sample, the special values of the points in the set are 0, - 1, and - 2 while the sequence that the friend gives to Wilbur is 0, 1, 2. Therefore, the answer does not exist.
Submitted Solution:
```
from collections import deque
dp={}
for i in range(int(input())):
x,y = map(int, input().split())
if y-x in dp:
dp[y-x].append((x,y))
else:
dp[y-x]=[(x,y)]
for i in dp:
dp[i].sort()
dp[i]=deque(dp[i])
w=list(map(int, input().split()))
ans=[0]*len(w)
flag=1
for i in range(len(w)):
if not w[i] in dp or not len(dp[w[i]]):
flag=0
break
ans[i]=dp[w[i]].popleft()
#~ for i in range(len(ans)):
#~ if ans[i]
if flag:
print("YES")
for i in ans:
print(i[0], i[1])
else:
print("NO")
``` | instruction | 0 | 35,584 | 23 | 71,168 |
No | output | 1 | 35,584 | 23 | 71,169 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Wilbur is playing with a set of n points on the coordinate plane. All points have non-negative integer coordinates. Moreover, if some point (x, y) belongs to the set, then all points (x', y'), such that 0 ≤ x' ≤ x and 0 ≤ y' ≤ y also belong to this set.
Now Wilbur wants to number the points in the set he has, that is assign them distinct integer numbers from 1 to n. In order to make the numbering aesthetically pleasing, Wilbur imposes the condition that if some point (x, y) gets number i, then all (x',y') from the set, such that x' ≥ x and y' ≥ y must be assigned a number not less than i. For example, for a set of four points (0, 0), (0, 1), (1, 0) and (1, 1), there are two aesthetically pleasing numberings. One is 1, 2, 3, 4 and another one is 1, 3, 2, 4.
Wilbur's friend comes along and challenges Wilbur. For any point he defines it's special value as s(x, y) = y - x. Now he gives Wilbur some w1, w2,..., wn, and asks him to find an aesthetically pleasing numbering of the points in the set, such that the point that gets number i has it's special value equal to wi, that is s(xi, yi) = yi - xi = wi.
Now Wilbur asks you to help him with this challenge.
Input
The first line of the input consists of a single integer n (1 ≤ n ≤ 100 000) — the number of points in the set Wilbur is playing with.
Next follow n lines with points descriptions. Each line contains two integers x and y (0 ≤ x, y ≤ 100 000), that give one point in Wilbur's set. It's guaranteed that all points are distinct. Also, it is guaranteed that if some point (x, y) is present in the input, then all points (x', y'), such that 0 ≤ x' ≤ x and 0 ≤ y' ≤ y, are also present in the input.
The last line of the input contains n integers. The i-th of them is wi ( - 100 000 ≤ wi ≤ 100 000) — the required special value of the point that gets number i in any aesthetically pleasing numbering.
Output
If there exists an aesthetically pleasant numbering of points in the set, such that s(xi, yi) = yi - xi = wi, then print "YES" on the first line of the output. Otherwise, print "NO".
If a solution exists, proceed output with n lines. On the i-th of these lines print the point of the set that gets number i. If there are multiple solutions, print any of them.
Examples
Input
5
2 0
0 0
1 0
1 1
0 1
0 -1 -2 1 0
Output
YES
0 0
1 0
2 0
0 1
1 1
Input
3
1 0
0 0
2 0
0 1 2
Output
NO
Note
In the first sample, point (2, 0) gets number 3, point (0, 0) gets number one, point (1, 0) gets number 2, point (1, 1) gets number 5 and point (0, 1) gets number 4. One can easily check that this numbering is aesthetically pleasing and yi - xi = wi.
In the second sample, the special values of the points in the set are 0, - 1, and - 2 while the sequence that the friend gives to Wilbur is 0, 1, 2. Therefore, the answer does not exist.
Submitted Solution:
```
__author__ = 'mac'
from collections import Counter
def sortByDiag(elem):
return elem[0]*elem[0]+elem[1]*elem[1]
count = int(input())
points = {}
compList = []
for i in range(count):
x,y = [int(x) for x in input().strip().split(' ')]
w = y-x
compList.append(w)
if not w in points:
points[w] = []
points[w].append([x,y])
wArr = []
for x in input().strip().split(' '):
if (len(wArr) > 1 and int(x) == wArr[-1]) or (abs(int(x)-1)>len(wArr)):
print('NO')
exit()
wArr.append(int(x))
c1 = Counter(wArr)
c2 = Counter(compList)
diff = c1-c2
if len(list(diff.elements())) != 0:
print('NO')
exit()
print('YES')
for e in points:
points[e] = sorted(points[e], key = sortByDiag)
for i in wArr:
temp = points[i].pop(0)
print(temp[0],temp[1])
``` | instruction | 0 | 35,585 | 23 | 71,170 |
No | output | 1 | 35,585 | 23 | 71,171 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Wilbur is playing with a set of n points on the coordinate plane. All points have non-negative integer coordinates. Moreover, if some point (x, y) belongs to the set, then all points (x', y'), such that 0 ≤ x' ≤ x and 0 ≤ y' ≤ y also belong to this set.
Now Wilbur wants to number the points in the set he has, that is assign them distinct integer numbers from 1 to n. In order to make the numbering aesthetically pleasing, Wilbur imposes the condition that if some point (x, y) gets number i, then all (x',y') from the set, such that x' ≥ x and y' ≥ y must be assigned a number not less than i. For example, for a set of four points (0, 0), (0, 1), (1, 0) and (1, 1), there are two aesthetically pleasing numberings. One is 1, 2, 3, 4 and another one is 1, 3, 2, 4.
Wilbur's friend comes along and challenges Wilbur. For any point he defines it's special value as s(x, y) = y - x. Now he gives Wilbur some w1, w2,..., wn, and asks him to find an aesthetically pleasing numbering of the points in the set, such that the point that gets number i has it's special value equal to wi, that is s(xi, yi) = yi - xi = wi.
Now Wilbur asks you to help him with this challenge.
Input
The first line of the input consists of a single integer n (1 ≤ n ≤ 100 000) — the number of points in the set Wilbur is playing with.
Next follow n lines with points descriptions. Each line contains two integers x and y (0 ≤ x, y ≤ 100 000), that give one point in Wilbur's set. It's guaranteed that all points are distinct. Also, it is guaranteed that if some point (x, y) is present in the input, then all points (x', y'), such that 0 ≤ x' ≤ x and 0 ≤ y' ≤ y, are also present in the input.
The last line of the input contains n integers. The i-th of them is wi ( - 100 000 ≤ wi ≤ 100 000) — the required special value of the point that gets number i in any aesthetically pleasing numbering.
Output
If there exists an aesthetically pleasant numbering of points in the set, such that s(xi, yi) = yi - xi = wi, then print "YES" on the first line of the output. Otherwise, print "NO".
If a solution exists, proceed output with n lines. On the i-th of these lines print the point of the set that gets number i. If there are multiple solutions, print any of them.
Examples
Input
5
2 0
0 0
1 0
1 1
0 1
0 -1 -2 1 0
Output
YES
0 0
1 0
2 0
0 1
1 1
Input
3
1 0
0 0
2 0
0 1 2
Output
NO
Note
In the first sample, point (2, 0) gets number 3, point (0, 0) gets number one, point (1, 0) gets number 2, point (1, 1) gets number 5 and point (0, 1) gets number 4. One can easily check that this numbering is aesthetically pleasing and yi - xi = wi.
In the second sample, the special values of the points in the set are 0, - 1, and - 2 while the sequence that the friend gives to Wilbur is 0, 1, 2. Therefore, the answer does not exist.
Submitted Solution:
```
debug = False
# debug = True
s = lambda x, y: y - x
points = dict()
w = []
if debug:
with open("input.txt", "r") as inp:
num_points = int(inp.readline())
for i in range(num_points):
x, y = [int(a) for a in inp.readline().split(' ')]
key = s(x, y)
if not key in points:
points[key] = []
points[key].append([x, y])
print(points)
w = [int(a) for a in inp.readline().split(' ')]
print(w)
else:
num_points = int(input())
for i in range(num_points):
x, y = [int(a) for a in input().split(' ')]
key = s(x, y)
if not key in points:
points[key] = []
points[key].append([x, y])
w = [int(a) for a in input().split(' ')]
for k in points:
points[k] = sorted(points[k], key =lambda p: (p[0]+1)*(p[1]+1))
# points[k] = sorted(points[k], key =lambda p: p[0])
if debug:
print(points)
answer = True
answer_arr = []
for wi in w:
if not wi in points:
answer = False
break
answer_arr.append(points[wi].pop(0))
print("YES" if answer else "NO", end='\n')
if answer:
for el in answer_arr:
print(el[0], el[1], sep=' ', end='\n')
``` | instruction | 0 | 35,586 | 23 | 71,172 |
No | output | 1 | 35,586 | 23 | 71,173 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Wilbur is playing with a set of n points on the coordinate plane. All points have non-negative integer coordinates. Moreover, if some point (x, y) belongs to the set, then all points (x', y'), such that 0 ≤ x' ≤ x and 0 ≤ y' ≤ y also belong to this set.
Now Wilbur wants to number the points in the set he has, that is assign them distinct integer numbers from 1 to n. In order to make the numbering aesthetically pleasing, Wilbur imposes the condition that if some point (x, y) gets number i, then all (x',y') from the set, such that x' ≥ x and y' ≥ y must be assigned a number not less than i. For example, for a set of four points (0, 0), (0, 1), (1, 0) and (1, 1), there are two aesthetically pleasing numberings. One is 1, 2, 3, 4 and another one is 1, 3, 2, 4.
Wilbur's friend comes along and challenges Wilbur. For any point he defines it's special value as s(x, y) = y - x. Now he gives Wilbur some w1, w2,..., wn, and asks him to find an aesthetically pleasing numbering of the points in the set, such that the point that gets number i has it's special value equal to wi, that is s(xi, yi) = yi - xi = wi.
Now Wilbur asks you to help him with this challenge.
Input
The first line of the input consists of a single integer n (1 ≤ n ≤ 100 000) — the number of points in the set Wilbur is playing with.
Next follow n lines with points descriptions. Each line contains two integers x and y (0 ≤ x, y ≤ 100 000), that give one point in Wilbur's set. It's guaranteed that all points are distinct. Also, it is guaranteed that if some point (x, y) is present in the input, then all points (x', y'), such that 0 ≤ x' ≤ x and 0 ≤ y' ≤ y, are also present in the input.
The last line of the input contains n integers. The i-th of them is wi ( - 100 000 ≤ wi ≤ 100 000) — the required special value of the point that gets number i in any aesthetically pleasing numbering.
Output
If there exists an aesthetically pleasant numbering of points in the set, such that s(xi, yi) = yi - xi = wi, then print "YES" on the first line of the output. Otherwise, print "NO".
If a solution exists, proceed output with n lines. On the i-th of these lines print the point of the set that gets number i. If there are multiple solutions, print any of them.
Examples
Input
5
2 0
0 0
1 0
1 1
0 1
0 -1 -2 1 0
Output
YES
0 0
1 0
2 0
0 1
1 1
Input
3
1 0
0 0
2 0
0 1 2
Output
NO
Note
In the first sample, point (2, 0) gets number 3, point (0, 0) gets number one, point (1, 0) gets number 2, point (1, 1) gets number 5 and point (0, 1) gets number 4. One can easily check that this numbering is aesthetically pleasing and yi - xi = wi.
In the second sample, the special values of the points in the set are 0, - 1, and - 2 while the sequence that the friend gives to Wilbur is 0, 1, 2. Therefore, the answer does not exist.
Submitted Solution:
```
n = int(input())
a = []
b = []
res = []
ind = -1
for i in range(n):
a.append(tuple(map(int, input().split())))
def cmp(block):
a = min(*block), max(*block)
return a
a.sort(key = cmp)
for i in range(n):
w = a[i][1] - a[i][0]
if i == 0 or (a[i][0] > a[i-1][0] and a[i][1] > a[i-1][1]):
b.append({})
ind += 1
if w not in b[ind]:
b[ind][w] = set()
b[ind][w].add(a[i])
W = list(map(int, input().split()))
ind = 0
f = 0
for i in range(n):
k = W[i]
if len(b[ind]) == 0:
ind += 1
if k in b[ind]:
res.append(b[ind][k].pop())
if len(b[ind][k]) == 0:
b[ind].pop(k)
else:
f = 1
break
if f == 1:
print("NO")
else:
print("YES")
for i in res:
print(i[0], i[1])
``` | instruction | 0 | 35,587 | 23 | 71,174 |
No | output | 1 | 35,587 | 23 | 71,175 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi wants to print a document with N pages double-sided, where two pages of data can be printed on one sheet of paper.
At least how many sheets of paper does he need?
Constraints
* N is an integer.
* 1 \leq N \leq 100
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Examples
Input
5
Output
3
Input
2
Output
1
Input
100
Output
50
Submitted Solution:
```
from copy import deepcopy
N, M, K = map(int, input().split())
FRIENDS = [list(map(int, input().split())) for _ in range(M)]
BLOCKS = [list(map(int, input().split())) for _ in range(K)]
def search(i, friends):
copied_friends = deepcopy(friends)
res = []
for a, b in friends:
if a == i:
copied_friends.remove([a, b])
res.append(b)
if b == i:
copied_friends.remove([a, b])
res.append(a)
return res, copied_friends
def find(i, j, friends):
for a, b in friends:
if a == i and b == j:
return True
if b == i and a == j:
return True
return False
def dfs(i, friends):
if len(friends) == 0:
return [i]
targets, new_friends = search(i, friends)
for t in targets:
if targets.count(t) <= 1:
targets += dfs(t, new_friends)
return targets
results = []
for i in range(1, N+1):
targets = list(set(dfs(i, FRIENDS)))
targets = filter(lambda x: not find(x, i, FRIENDS), targets)
targets = filter(lambda x: not find(x, i, BLOCKS), targets)
results.append(len(list(targets)))
print(" ".join(map(str, results)))
``` | instruction | 0 | 35,773 | 23 | 71,546 |
No | output | 1 | 35,773 | 23 | 71,547 |
Provide a correct Python 3 solution for this coding contest problem.
Given are N points on the circumference of a circle centered at (0,0) in an xy-plane. The coordinates of the i-th point are (\cos(\frac{2\pi T_i}{L}),\sin(\frac{2\pi T_i}{L})).
Three distinct points will be chosen uniformly at random from these N points. Find the expected x- and y-coordinates of the center of the circle inscribed in the triangle formed by the chosen points.
Constraints
* 3 \leq N \leq 3000
* N \leq L \leq 10^9
* 0 \leq T_i \leq L-1
* T_i<T_{i+1}
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N L
T_1
:
T_N
Output
Print the expected x- and y-coordinates of the center of the circle inscribed in the triangle formed by the chosen points. Your output will be considered correct when the absolute or relative error is at most 10^{-9}.
Examples
Input
3 4
0
1
3
Output
0.414213562373095 -0.000000000000000
Input
4 8
1
3
5
6
Output
-0.229401949926902 -0.153281482438188
Input
10 100
2
11
35
42
54
69
89
91
93
99
Output
0.352886583546338 -0.109065017701873 | instruction | 0 | 35,777 | 23 | 71,554 |
"Correct Solution:
```
from math import sqrt, sin, cos, pi
import time
def main():
N,L = map(int, input().split())
t = [int(input()) for i in range(N)]
#N,L = 3000, 3000
#t = [int(i) for i in range(N)]
comb = N * (N-1) * (N-2) / 6
ans_X, ans_Y = 0, 0
for i in range(N-1):
for j in range(i+1,N):
theta = pi * (t[j] + t[i]) / L
I_X = cos(theta) * (N - 2*(j-i))
I_Y = sin(theta) * (N - 2*(j-i))
ans_X += I_X / comb
ans_Y += I_Y / comb
#print(ans_X, ans_Y)
print(ans_X, ans_Y)
if __name__ == "__main__":
#start = time.time()
main()
#elapsed_time = time.time() - start
#rint ("elapsed_time:{0}".format(elapsed_time) + "[sec]")
``` | output | 1 | 35,777 | 23 | 71,555 |
Provide a correct Python 3 solution for this coding contest problem.
Given are N points on the circumference of a circle centered at (0,0) in an xy-plane. The coordinates of the i-th point are (\cos(\frac{2\pi T_i}{L}),\sin(\frac{2\pi T_i}{L})).
Three distinct points will be chosen uniformly at random from these N points. Find the expected x- and y-coordinates of the center of the circle inscribed in the triangle formed by the chosen points.
Constraints
* 3 \leq N \leq 3000
* N \leq L \leq 10^9
* 0 \leq T_i \leq L-1
* T_i<T_{i+1}
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N L
T_1
:
T_N
Output
Print the expected x- and y-coordinates of the center of the circle inscribed in the triangle formed by the chosen points. Your output will be considered correct when the absolute or relative error is at most 10^{-9}.
Examples
Input
3 4
0
1
3
Output
0.414213562373095 -0.000000000000000
Input
4 8
1
3
5
6
Output
-0.229401949926902 -0.153281482438188
Input
10 100
2
11
35
42
54
69
89
91
93
99
Output
0.352886583546338 -0.109065017701873 | instruction | 0 | 35,778 | 23 | 71,556 |
"Correct Solution:
```
#解説読んだ
import math
N, L = list(map(int, input().split()))
T = [int(input()) for _ in range(N)]
K = N * (N - 1) * (N - 2) / 3 / 2
x, y = 0, 0
for i in range(N - 1):
for j in range(i + 1, N):
a = (T[i] + T[j]) / 2
b = a + L / 2
t = j - i - 1
k = N - 2 - t
x += k * math.cos(2 * math.pi * a / L) / K
x += t * math.cos(2 * math.pi * b / L) / K
y += k * math.sin(2 * math.pi * a / L) / K
y += t * math.sin(2 * math.pi * b / L) / K
print(x, y)
``` | output | 1 | 35,778 | 23 | 71,557 |
Provide a correct Python 3 solution for this coding contest problem.
Given are N points on the circumference of a circle centered at (0,0) in an xy-plane. The coordinates of the i-th point are (\cos(\frac{2\pi T_i}{L}),\sin(\frac{2\pi T_i}{L})).
Three distinct points will be chosen uniformly at random from these N points. Find the expected x- and y-coordinates of the center of the circle inscribed in the triangle formed by the chosen points.
Constraints
* 3 \leq N \leq 3000
* N \leq L \leq 10^9
* 0 \leq T_i \leq L-1
* T_i<T_{i+1}
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N L
T_1
:
T_N
Output
Print the expected x- and y-coordinates of the center of the circle inscribed in the triangle formed by the chosen points. Your output will be considered correct when the absolute or relative error is at most 10^{-9}.
Examples
Input
3 4
0
1
3
Output
0.414213562373095 -0.000000000000000
Input
4 8
1
3
5
6
Output
-0.229401949926902 -0.153281482438188
Input
10 100
2
11
35
42
54
69
89
91
93
99
Output
0.352886583546338 -0.109065017701873 | instruction | 0 | 35,779 | 23 | 71,558 |
"Correct Solution:
```
from math import cos, sin, pi
from itertools import combinations
N, L = map(int, input().split())
T = [int(input()) for _ in range(N)]
PI2oL = 2*pi/L
csum, ssum = 0, 0
count = 0
for i, j in combinations(range(N), 2):
count += 1
mid1, num2 = (T[i] + T[j]) / 2, j - i - 1
mid2, num1 = (mid1 + L/2) % L, N - num2 - 2
csum += cos(PI2oL*mid1) * num1 + cos(PI2oL*mid2) * num2
ssum += sin(PI2oL*mid1) * num1 + sin(PI2oL*mid2) * num2
print(csum/count/(N-2)*3, ssum/count/(N-2)*3)
``` | output | 1 | 35,779 | 23 | 71,559 |
Provide a correct Python 3 solution for this coding contest problem.
Given are N points on the circumference of a circle centered at (0,0) in an xy-plane. The coordinates of the i-th point are (\cos(\frac{2\pi T_i}{L}),\sin(\frac{2\pi T_i}{L})).
Three distinct points will be chosen uniformly at random from these N points. Find the expected x- and y-coordinates of the center of the circle inscribed in the triangle formed by the chosen points.
Constraints
* 3 \leq N \leq 3000
* N \leq L \leq 10^9
* 0 \leq T_i \leq L-1
* T_i<T_{i+1}
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N L
T_1
:
T_N
Output
Print the expected x- and y-coordinates of the center of the circle inscribed in the triangle formed by the chosen points. Your output will be considered correct when the absolute or relative error is at most 10^{-9}.
Examples
Input
3 4
0
1
3
Output
0.414213562373095 -0.000000000000000
Input
4 8
1
3
5
6
Output
-0.229401949926902 -0.153281482438188
Input
10 100
2
11
35
42
54
69
89
91
93
99
Output
0.352886583546338 -0.109065017701873 | instruction | 0 | 35,780 | 23 | 71,560 |
"Correct Solution:
```
import math
N,L=map(int,input().split())
T=[int(input()) for i in range(N)]
X=0
Y=0
for i in range(N):
for j in range(i+1,N):
angle=math.pi*(T[j]+T[i])/L
#print(math.cos(angle),math.sin(angle))
X+=math.cos(angle)*(N-2-(j-i-1)*2)
Y+=math.sin(angle)*(N-2-(j-i-1)*2)
A=(N*(N-1)*(N-2))//6
print(X/A,Y/A)
``` | output | 1 | 35,780 | 23 | 71,561 |
Provide a correct Python 3 solution for this coding contest problem.
Given are N points on the circumference of a circle centered at (0,0) in an xy-plane. The coordinates of the i-th point are (\cos(\frac{2\pi T_i}{L}),\sin(\frac{2\pi T_i}{L})).
Three distinct points will be chosen uniformly at random from these N points. Find the expected x- and y-coordinates of the center of the circle inscribed in the triangle formed by the chosen points.
Constraints
* 3 \leq N \leq 3000
* N \leq L \leq 10^9
* 0 \leq T_i \leq L-1
* T_i<T_{i+1}
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N L
T_1
:
T_N
Output
Print the expected x- and y-coordinates of the center of the circle inscribed in the triangle formed by the chosen points. Your output will be considered correct when the absolute or relative error is at most 10^{-9}.
Examples
Input
3 4
0
1
3
Output
0.414213562373095 -0.000000000000000
Input
4 8
1
3
5
6
Output
-0.229401949926902 -0.153281482438188
Input
10 100
2
11
35
42
54
69
89
91
93
99
Output
0.352886583546338 -0.109065017701873 | instruction | 0 | 35,781 | 23 | 71,562 |
"Correct Solution:
```
import math
pi = math.acos(-1)
N, L = map(int, input().split())
NN = N * (N-1) * (N-2) // 6
T = [int(input()) for _ in range(N)]
print(sum([sum([math.cos((T[i]+T[j])*pi/L) * (N+2*(i-j)) for j in range(i+1, N)]) for i in range(N)])/NN, sum([sum([math.sin((T[i]+T[j])*pi/L) * (N+2*(i-j)) for j in range(i+1, N)]) for i in range(N)])/NN)
``` | output | 1 | 35,781 | 23 | 71,563 |
Provide a correct Python 3 solution for this coding contest problem.
Given are N points on the circumference of a circle centered at (0,0) in an xy-plane. The coordinates of the i-th point are (\cos(\frac{2\pi T_i}{L}),\sin(\frac{2\pi T_i}{L})).
Three distinct points will be chosen uniformly at random from these N points. Find the expected x- and y-coordinates of the center of the circle inscribed in the triangle formed by the chosen points.
Constraints
* 3 \leq N \leq 3000
* N \leq L \leq 10^9
* 0 \leq T_i \leq L-1
* T_i<T_{i+1}
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N L
T_1
:
T_N
Output
Print the expected x- and y-coordinates of the center of the circle inscribed in the triangle formed by the chosen points. Your output will be considered correct when the absolute or relative error is at most 10^{-9}.
Examples
Input
3 4
0
1
3
Output
0.414213562373095 -0.000000000000000
Input
4 8
1
3
5
6
Output
-0.229401949926902 -0.153281482438188
Input
10 100
2
11
35
42
54
69
89
91
93
99
Output
0.352886583546338 -0.109065017701873 | instruction | 0 | 35,782 | 23 | 71,564 |
"Correct Solution:
```
from math import sin, cos, pi
N, L = map(int, input().split())
NN = N * (N-1) * (N-2) // 6
T = [int(input())*pi/L for _ in range(N)]
print(sum([sum([cos((T[i]+T[j])) * (N+2*(i-j)) for j in range(i+1, N)]) for i in range(N)])/NN, sum([sum([sin((T[i]+T[j])) * (N+2*(i-j)) for j in range(i+1, N)]) for i in range(N)])/NN)
``` | output | 1 | 35,782 | 23 | 71,565 |
Provide a correct Python 3 solution for this coding contest problem.
Given are N points on the circumference of a circle centered at (0,0) in an xy-plane. The coordinates of the i-th point are (\cos(\frac{2\pi T_i}{L}),\sin(\frac{2\pi T_i}{L})).
Three distinct points will be chosen uniformly at random from these N points. Find the expected x- and y-coordinates of the center of the circle inscribed in the triangle formed by the chosen points.
Constraints
* 3 \leq N \leq 3000
* N \leq L \leq 10^9
* 0 \leq T_i \leq L-1
* T_i<T_{i+1}
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N L
T_1
:
T_N
Output
Print the expected x- and y-coordinates of the center of the circle inscribed in the triangle formed by the chosen points. Your output will be considered correct when the absolute or relative error is at most 10^{-9}.
Examples
Input
3 4
0
1
3
Output
0.414213562373095 -0.000000000000000
Input
4 8
1
3
5
6
Output
-0.229401949926902 -0.153281482438188
Input
10 100
2
11
35
42
54
69
89
91
93
99
Output
0.352886583546338 -0.109065017701873 | instruction | 0 | 35,783 | 23 | 71,566 |
"Correct Solution:
```
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
n,L=map(int,input().split())
T=[int(input()) for _ in range(n)]
s=0
from math import pi
from cmath import rect
for j in range(n):
for i in range(j): # 0<=i<j<=n-1
s+=-rect(1,(T[i]+T[j])*pi/L)*(j-i-1) # Ti<T<Tj なるTの個数はj-i-1
s+= rect(1,(T[i]+T[j])*pi/L)*(n-(j-i+1)) # T<Ti, Tj<T なるTの個数はn-(j-i+1)
s/=n*(n-1)*(n-2)/6
print(s.real,s.imag)
resolve()
``` | output | 1 | 35,783 | 23 | 71,567 |
Provide a correct Python 3 solution for this coding contest problem.
Given are N points on the circumference of a circle centered at (0,0) in an xy-plane. The coordinates of the i-th point are (\cos(\frac{2\pi T_i}{L}),\sin(\frac{2\pi T_i}{L})).
Three distinct points will be chosen uniformly at random from these N points. Find the expected x- and y-coordinates of the center of the circle inscribed in the triangle formed by the chosen points.
Constraints
* 3 \leq N \leq 3000
* N \leq L \leq 10^9
* 0 \leq T_i \leq L-1
* T_i<T_{i+1}
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N L
T_1
:
T_N
Output
Print the expected x- and y-coordinates of the center of the circle inscribed in the triangle formed by the chosen points. Your output will be considered correct when the absolute or relative error is at most 10^{-9}.
Examples
Input
3 4
0
1
3
Output
0.414213562373095 -0.000000000000000
Input
4 8
1
3
5
6
Output
-0.229401949926902 -0.153281482438188
Input
10 100
2
11
35
42
54
69
89
91
93
99
Output
0.352886583546338 -0.109065017701873 | instruction | 0 | 35,784 | 23 | 71,568 |
"Correct Solution:
```
#解説読んだ
import math
N, L = list(map(int, input().split()))
T = [int(input()) for _ in range(N)]
x, y = 0, 0
for i in range(N - 1):
for j in range(i + 1, N):
a = (T[i] + T[j]) / 2
b = a + L / 2
t = j - i - 1
k = N - 2 - t
x += k * math.cos(2 * math.pi * a / L)
x += t * math.cos(2 * math.pi * b / L)
y += k * math.sin(2 * math.pi * a / L)
y += t * math.sin(2 * math.pi * b / L)
x /= N * (N - 1) * (N - 2) / 3 / 2
y /= N * (N - 1) * (N - 2) / 3 / 2
print(x, y)
``` | output | 1 | 35,784 | 23 | 71,569 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given are N points on the circumference of a circle centered at (0,0) in an xy-plane. The coordinates of the i-th point are (\cos(\frac{2\pi T_i}{L}),\sin(\frac{2\pi T_i}{L})).
Three distinct points will be chosen uniformly at random from these N points. Find the expected x- and y-coordinates of the center of the circle inscribed in the triangle formed by the chosen points.
Constraints
* 3 \leq N \leq 3000
* N \leq L \leq 10^9
* 0 \leq T_i \leq L-1
* T_i<T_{i+1}
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N L
T_1
:
T_N
Output
Print the expected x- and y-coordinates of the center of the circle inscribed in the triangle formed by the chosen points. Your output will be considered correct when the absolute or relative error is at most 10^{-9}.
Examples
Input
3 4
0
1
3
Output
0.414213562373095 -0.000000000000000
Input
4 8
1
3
5
6
Output
-0.229401949926902 -0.153281482438188
Input
10 100
2
11
35
42
54
69
89
91
93
99
Output
0.352886583546338 -0.109065017701873
Submitted Solution:
```
from math import sin,cos,pi
N,L=map(int,input().split())
S=N*(N-1)*(N-2)/6
T=[int(input())*pi/L for _ in range(N)]
print(sum([sum([cos((T[i]+T[j]))*(N+2*(i-j))for j in range(i+1, N)])for i in range(N)])/S,sum([sum([sin((T[i]+T[j]))*(N+2*(i-j))for j in range(i+1,N)])for i in range(N)])/S)
``` | instruction | 0 | 35,785 | 23 | 71,570 |
Yes | output | 1 | 35,785 | 23 | 71,571 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given are N points on the circumference of a circle centered at (0,0) in an xy-plane. The coordinates of the i-th point are (\cos(\frac{2\pi T_i}{L}),\sin(\frac{2\pi T_i}{L})).
Three distinct points will be chosen uniformly at random from these N points. Find the expected x- and y-coordinates of the center of the circle inscribed in the triangle formed by the chosen points.
Constraints
* 3 \leq N \leq 3000
* N \leq L \leq 10^9
* 0 \leq T_i \leq L-1
* T_i<T_{i+1}
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N L
T_1
:
T_N
Output
Print the expected x- and y-coordinates of the center of the circle inscribed in the triangle formed by the chosen points. Your output will be considered correct when the absolute or relative error is at most 10^{-9}.
Examples
Input
3 4
0
1
3
Output
0.414213562373095 -0.000000000000000
Input
4 8
1
3
5
6
Output
-0.229401949926902 -0.153281482438188
Input
10 100
2
11
35
42
54
69
89
91
93
99
Output
0.352886583546338 -0.109065017701873
Submitted Solution:
```
#!/usr/bin/env python3
from math import cos, sin, pi
n, L = map(int, input().split())
t = [int(input()) for _ in range(n)]
ans = [0, 0]
for i in range(n):
for j in range(i + 1, n):
k = (n - 1 - j + i) - (j - i - 1)
ans[0] += cos(pi * (t[i] + t[j]) / L) * k
ans[1] += sin(pi * (t[i] + t[j]) / L) * k
for i in range(2):
ans[i] /= n * (n - 1) * (n - 2) / 6
print(*ans, sep=' ')
``` | instruction | 0 | 35,786 | 23 | 71,572 |
Yes | output | 1 | 35,786 | 23 | 71,573 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given are N points on the circumference of a circle centered at (0,0) in an xy-plane. The coordinates of the i-th point are (\cos(\frac{2\pi T_i}{L}),\sin(\frac{2\pi T_i}{L})).
Three distinct points will be chosen uniformly at random from these N points. Find the expected x- and y-coordinates of the center of the circle inscribed in the triangle formed by the chosen points.
Constraints
* 3 \leq N \leq 3000
* N \leq L \leq 10^9
* 0 \leq T_i \leq L-1
* T_i<T_{i+1}
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N L
T_1
:
T_N
Output
Print the expected x- and y-coordinates of the center of the circle inscribed in the triangle formed by the chosen points. Your output will be considered correct when the absolute or relative error is at most 10^{-9}.
Examples
Input
3 4
0
1
3
Output
0.414213562373095 -0.000000000000000
Input
4 8
1
3
5
6
Output
-0.229401949926902 -0.153281482438188
Input
10 100
2
11
35
42
54
69
89
91
93
99
Output
0.352886583546338 -0.109065017701873
Submitted Solution:
```
import sys
from math import *
from itertools import *
input = sys.stdin.readline
N, L = list(map(int,input().split()))
T = [int(input().strip()) for i in range(N)]
T.sort()
pairN = factorial(N)/(factorial(N-2)*factorial(2))
tripleN = factorial(N)/(factorial(N-3)*factorial(3))
ans = [0,0]
for i0, i1 in combinations(range(N),2):
t0, t1 = T[i0], T[i1]
tn = (t0+t1)/2
to = tn+(L/2.0)
cn = (cos(2.0*pi*tn/L),sin(2.0*pi*tn/L))
co = (cos(2.0*pi*to/L),sin(2.0*pi*to/L))
onum = (i1-i0)-1
nnum = N-2-onum
ans[0] += (cn[0]*nnum + co[0]*onum)/tripleN
ans[1] += (cn[1]*nnum + co[1]*onum)/tripleN
print(" ".join(map(str,ans)))
``` | instruction | 0 | 35,787 | 23 | 71,574 |
Yes | output | 1 | 35,787 | 23 | 71,575 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given are N points on the circumference of a circle centered at (0,0) in an xy-plane. The coordinates of the i-th point are (\cos(\frac{2\pi T_i}{L}),\sin(\frac{2\pi T_i}{L})).
Three distinct points will be chosen uniformly at random from these N points. Find the expected x- and y-coordinates of the center of the circle inscribed in the triangle formed by the chosen points.
Constraints
* 3 \leq N \leq 3000
* N \leq L \leq 10^9
* 0 \leq T_i \leq L-1
* T_i<T_{i+1}
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N L
T_1
:
T_N
Output
Print the expected x- and y-coordinates of the center of the circle inscribed in the triangle formed by the chosen points. Your output will be considered correct when the absolute or relative error is at most 10^{-9}.
Examples
Input
3 4
0
1
3
Output
0.414213562373095 -0.000000000000000
Input
4 8
1
3
5
6
Output
-0.229401949926902 -0.153281482438188
Input
10 100
2
11
35
42
54
69
89
91
93
99
Output
0.352886583546338 -0.109065017701873
Submitted Solution:
```
import math
N,L=map(int,input().split())
T=[int(input()) for i in range(N)]
ANSX=ANSY=0
for i in range(N-1):
for j in range(i+1,N):
ANSX+=math.cos((T[i]+T[j])*math.pi/L)*(N-(j-i+1))
ANSY+=math.sin((T[i]+T[j])*math.pi/L)*(N-(j-i+1))
ANSX+=math.cos((T[i]+T[j])*math.pi/L+math.pi)*(j-i-1)
ANSY+=math.sin((T[i]+T[j])*math.pi/L+math.pi)*(j-i-1)
print(ANSX/(N*(N-1)*(N-2)//6),ANSY/(N*(N-1)*(N-2)//6))
``` | instruction | 0 | 35,788 | 23 | 71,576 |
Yes | output | 1 | 35,788 | 23 | 71,577 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given are N points on the circumference of a circle centered at (0,0) in an xy-plane. The coordinates of the i-th point are (\cos(\frac{2\pi T_i}{L}),\sin(\frac{2\pi T_i}{L})).
Three distinct points will be chosen uniformly at random from these N points. Find the expected x- and y-coordinates of the center of the circle inscribed in the triangle formed by the chosen points.
Constraints
* 3 \leq N \leq 3000
* N \leq L \leq 10^9
* 0 \leq T_i \leq L-1
* T_i<T_{i+1}
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N L
T_1
:
T_N
Output
Print the expected x- and y-coordinates of the center of the circle inscribed in the triangle formed by the chosen points. Your output will be considered correct when the absolute or relative error is at most 10^{-9}.
Examples
Input
3 4
0
1
3
Output
0.414213562373095 -0.000000000000000
Input
4 8
1
3
5
6
Output
-0.229401949926902 -0.153281482438188
Input
10 100
2
11
35
42
54
69
89
91
93
99
Output
0.352886583546338 -0.109065017701873
Submitted Solution:
```
import math
import time
start = time.time()
N, L = map(int, input().split())
nodes = []
for i in range(N):
nodes.append(float(input()))
def calc_naishin(a, b, c):
a_x, a_y = a
b_x, b_y = b
c_x, c_y = c
A = math.sqrt((b_x-c_x)**2 + (b_y-c_y)**2)
B = math.sqrt((c_x-a_x)**2 + (c_y-a_y)**2)
C = math.sqrt((a_x-b_x)**2 + (a_y-b_y)**2)
n_x = (A*a_x + B*b_x + C*c_x) / (A + B + C)
n_y = (A*a_y + B*b_y + C*c_y) / (A + B + C)
return n_x, n_y
counter = 0
sum_x = 0.0
sum_y = 0.0
"""
for i in range(len(nodes) - 2):
for j in range(i+1, len(nodes) - 1):
for k in range(j+1, len(nodes)):
a = ((math.cos((2*math.pi*nodes[i])/L)), math.sin((2*math.pi*nodes[i])/L))
b = ((math.cos((2*math.pi*nodes[j])/L)), math.sin((2*math.pi*nodes[j])/L))
c = ((math.cos((2*math.pi*nodes[k])/L)), math.sin((2*math.pi*nodes[k])/L))
n_x, n_y = calc_naishin(a, b, c)
sum_x += n_x
sum_y += n_y
counter += 1
"""
for i in range(len(nodes) - 2):
for j in range(i+1, len(nodes) - 1):
for k in range(j+1, len(nodes)):
T_i, T_j, T_k = nodes[i], nodes[j], nodes[k]
a = ((math.cos((2*math.pi*T_i)/L)), math.sin((2*math.pi*T_i)/L))
b = ((math.cos((2*math.pi*T_j)/L)), math.sin((2*math.pi*T_j)/L))
c = ((math.cos((2*math.pi*T_k)/L)), math.sin((2*math.pi*T_k)/L))
n_x, n_y = calc_naishin(a, b, c)
sum_x += n_x
sum_y += n_y
counter += 1
print(sum_x/counter, sum_y/counter)
print(time.time() - start)
``` | instruction | 0 | 35,789 | 23 | 71,578 |
No | output | 1 | 35,789 | 23 | 71,579 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given are N points on the circumference of a circle centered at (0,0) in an xy-plane. The coordinates of the i-th point are (\cos(\frac{2\pi T_i}{L}),\sin(\frac{2\pi T_i}{L})).
Three distinct points will be chosen uniformly at random from these N points. Find the expected x- and y-coordinates of the center of the circle inscribed in the triangle formed by the chosen points.
Constraints
* 3 \leq N \leq 3000
* N \leq L \leq 10^9
* 0 \leq T_i \leq L-1
* T_i<T_{i+1}
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N L
T_1
:
T_N
Output
Print the expected x- and y-coordinates of the center of the circle inscribed in the triangle formed by the chosen points. Your output will be considered correct when the absolute or relative error is at most 10^{-9}.
Examples
Input
3 4
0
1
3
Output
0.414213562373095 -0.000000000000000
Input
4 8
1
3
5
6
Output
-0.229401949926902 -0.153281482438188
Input
10 100
2
11
35
42
54
69
89
91
93
99
Output
0.352886583546338 -0.109065017701873
Submitted Solution:
```
import math
import time
import numpy as np
N, L = map(int, input().split())
nodes = []
for i in range(N):
nodes.append(int(input()))
start = time.time()
def calc_naishin(a, b, c):
a_x, a_y = a
b_x, b_y = b
c_x, c_y = c
A = math.sqrt((b_x-c_x)**2 + (b_y-c_y)**2)
B = math.sqrt((c_x-a_x)**2 + (c_y-a_y)**2)
C = math.sqrt((a_x-b_x)**2 + (a_y-b_y)**2)
n_x = (A*a_x + B*b_x + C*c_x) / (A + B + C)
n_y = (A*a_y + B*b_y + C*c_y) / (A + B + C)
return n_x, n_y
counter = 0
sum_x = 0.0
sum_y = 0.0
x = np.array([i for i in range(L)])
cos_x = np.cos(2*math.pi*x/L)
sin_x = np.sin(2*math.pi*x/L)
"""
for i in range(len(nodes) - 2):
for j in range(i+1, len(nodes) - 1):
for k in range(j+1, len(nodes)):
a = ((math.cos((2*math.pi*nodes[i])/L)), math.sin((2*math.pi*nodes[i])/L))
b = ((math.cos((2*math.pi*nodes[j])/L)), math.sin((2*math.pi*nodes[j])/L))
c = ((math.cos((2*math.pi*nodes[k])/L)), math.sin((2*math.pi*nodes[k])/L))
n_x, n_y = calc_naishin(a, b, c)
print(n_x, n_y)
sum_x += n_x
sum_y += n_y
counter += 1
"""
for i, T_i in enumerate(nodes[:-2]):
for j, T_j in enumerate(nodes[i+1:-1], start=i+1):
for k, T_k in enumerate(nodes[j+1:], start=j+1):
a = (cos_x[T_i], sin_x[T_i])
b = (cos_x[T_j], sin_x[T_j])
c = (cos_x[T_k], sin_x[T_k])
n_x, n_y = calc_naishin(a, b, c)
#print(n_x, n_y)
sum_x += n_x
sum_y += n_y
counter += 1
print(sum_x/counter, sum_y/counter)
#print(time.time() - start)
``` | instruction | 0 | 35,790 | 23 | 71,580 |
No | output | 1 | 35,790 | 23 | 71,581 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.