message stringlengths 2 20.1k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 1.95k 109k | cluster float64 17 17 | __index_level_0__ int64 3.91k 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
N students from JOI High School are lined up in a row from east to west. The i-th student from the western end of the column is student i. Each student has a bib with one integer. Initially, the integer Ai is written on the number of student i.
There are M batons, and the batons are numbered from 1 to M. For k = 1, 2, ..., M, perform the following operations. The operation related to baton k (2 ≤ k ≤ M) is performed after the operation related to baton k -1 is completed.
1. The teacher gives the baton k to student 1.
2. Students who receive the baton pass the baton according to the following rules.
* Rule: Suppose student i receives the baton k.
* 1 ≤ i ≤ N-1: When the remainder of the integer of the number of student i divided by k is greater than the remainder of the integer of the number of student i + 1 divided by k, student i and student i + 1 exchanges the number, and student i passes the baton to student i + 1. Otherwise, student i passes the baton to student i + 1 without changing the bib.
* When i = N: Student N passes the baton to the teacher.
3. When the teacher receives the baton k from student N, the operation related to the baton k is finished.
Given the integer and the number of batons M that were originally written in the student number, write a program to find the integer of each student's number after the teacher receives the baton M from student N.
input
The input consists of 1 + N lines.
The integers N and M (1 ≤ N ≤ 100, 1 ≤ M ≤ 100) are written on the first line, separated by blanks, and represent the number of students and the number of batons, respectively.
The integer Ai (1 ≤ Ai ≤ 1000) is written on the i-th line (1 ≤ i ≤ N) of the following N lines, and represents the integer Ai first written on the number of student i.
output
The output consists of N lines. On line i (1 ≤ i ≤ N), output the integer of the number of student i after the teacher receives the baton M from student N.
Input / output example
Input example 1
6 4
3
2
8
3
1
Five
Output example 1
2
3
1
8
Five
3
Input example 2
10 6
1
2
3
Four
Five
6
7
8
9
Ten
Output example 2
6
1
2
3
Ten
Four
8
7
9
Five
Input / output example 1 has 6 students. Initially, the student numbers are 3, 2, 8, 3, 1, and 5, in that order. There are four batons.
* At the end of the operation related to baton 1, the student numbers are 3, 2, 8, 3, 1, and 5, respectively.
* At the end of the operation related to baton 2, the student numbers are 2, 8, 3, 3, 1, and 5, respectively.
* At the end of the operation related to baton 3, the student numbers are 2, 3, 3, 1, 8, and 5, respectively.
* At the end of the operation related to baton 4, the student numbers are 2, 3, 1, 8, 5, and 3 in order.
Creative Commons License
Information Olympics Japan Committee work "15th Japan Information Olympics JOI 2015/2016 Qualifying Competition Tasks"
Example
Input
6 4
3
2
8
3
1
5
Output
2
3
1
8
5
3
Submitted Solution:
```
n,k = map(int,input().split())
d={}
for i in range(n):
d[i+1] = int(input())
for i in range(n):
j = i+1
if j == n:
break
if d[i]%k > d[i+1]%k:
t = d[i]
d[i] = d[i+1]
d[i+1] = t
for i in range(n):
print(d[i+1])
``` | instruction | 0 | 48,739 | 17 | 97,478 |
No | output | 1 | 48,739 | 17 | 97,479 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
N students from JOI High School are lined up in a row from east to west. The i-th student from the western end of the column is student i. Each student has a bib with one integer. Initially, the integer Ai is written on the number of student i.
There are M batons, and the batons are numbered from 1 to M. For k = 1, 2, ..., M, perform the following operations. The operation related to baton k (2 ≤ k ≤ M) is performed after the operation related to baton k -1 is completed.
1. The teacher gives the baton k to student 1.
2. Students who receive the baton pass the baton according to the following rules.
* Rule: Suppose student i receives the baton k.
* 1 ≤ i ≤ N-1: When the remainder of the integer of the number of student i divided by k is greater than the remainder of the integer of the number of student i + 1 divided by k, student i and student i + 1 exchanges the number, and student i passes the baton to student i + 1. Otherwise, student i passes the baton to student i + 1 without changing the bib.
* When i = N: Student N passes the baton to the teacher.
3. When the teacher receives the baton k from student N, the operation related to the baton k is finished.
Given the integer and the number of batons M that were originally written in the student number, write a program to find the integer of each student's number after the teacher receives the baton M from student N.
input
The input consists of 1 + N lines.
The integers N and M (1 ≤ N ≤ 100, 1 ≤ M ≤ 100) are written on the first line, separated by blanks, and represent the number of students and the number of batons, respectively.
The integer Ai (1 ≤ Ai ≤ 1000) is written on the i-th line (1 ≤ i ≤ N) of the following N lines, and represents the integer Ai first written on the number of student i.
output
The output consists of N lines. On line i (1 ≤ i ≤ N), output the integer of the number of student i after the teacher receives the baton M from student N.
Input / output example
Input example 1
6 4
3
2
8
3
1
Five
Output example 1
2
3
1
8
Five
3
Input example 2
10 6
1
2
3
Four
Five
6
7
8
9
Ten
Output example 2
6
1
2
3
Ten
Four
8
7
9
Five
Input / output example 1 has 6 students. Initially, the student numbers are 3, 2, 8, 3, 1, and 5, in that order. There are four batons.
* At the end of the operation related to baton 1, the student numbers are 3, 2, 8, 3, 1, and 5, respectively.
* At the end of the operation related to baton 2, the student numbers are 2, 8, 3, 3, 1, and 5, respectively.
* At the end of the operation related to baton 3, the student numbers are 2, 3, 3, 1, 8, and 5, respectively.
* At the end of the operation related to baton 4, the student numbers are 2, 3, 1, 8, 5, and 3 in order.
Creative Commons License
Information Olympics Japan Committee work "15th Japan Information Olympics JOI 2015/2016 Qualifying Competition Tasks"
Example
Input
6 4
3
2
8
3
1
5
Output
2
3
1
8
5
3
Submitted Solution:
```
n,m = map(int,input().split())
d={}
for i in range(n):
d[i+1] = int(input())
print(2 in d)
for l in range(m):
k = l+1
for j in range(n):
i = j+1
if i == n:
break
if d[i]%k > d[i+1]%k:
t = d[i]
d[i] = d[i+1]
d[i+1] = t
for i in range(n):
print(d[i+1])
``` | instruction | 0 | 48,740 | 17 | 97,480 |
No | output | 1 | 48,740 | 17 | 97,481 |
Provide tags and a correct Python 3 solution for this coding contest problem.
At the beginning of the school year Berland State University starts two city school programming groups, for beginners and for intermediate coders. The children were tested in order to sort them into groups. According to the results, each student got some score from 1 to m points. We know that c1 schoolchildren got 1 point, c2 children got 2 points, ..., cm children got m points. Now you need to set the passing rate k (integer from 1 to m): all schoolchildren who got less than k points go to the beginner group and those who get at strictly least k points go to the intermediate group. We know that if the size of a group is more than y, then the university won't find a room for them. We also know that if a group has less than x schoolchildren, then it is too small and there's no point in having classes with it. So, you need to split all schoolchildren into two groups so that the size of each group was from x to y, inclusive.
Help the university pick the passing rate in a way that meets these requirements.
Input
The first line contains integer m (2 ≤ m ≤ 100). The second line contains m integers c1, c2, ..., cm, separated by single spaces (0 ≤ ci ≤ 100). The third line contains two space-separated integers x and y (1 ≤ x ≤ y ≤ 10000). At least one ci is greater than 0.
Output
If it is impossible to pick a passing rate in a way that makes the size of each resulting groups at least x and at most y, print 0. Otherwise, print an integer from 1 to m — the passing rate you'd like to suggest. If there are multiple possible answers, print any of them.
Examples
Input
5
3 4 3 2 1
6 8
Output
3
Input
5
0 3 3 4 2
3 10
Output
4
Input
2
2 5
3 6
Output
0
Note
In the first sample the beginner group has 7 students, the intermediate group has 6 of them.
In the second sample another correct answer is 3. | instruction | 0 | 49,160 | 17 | 98,320 |
Tags: brute force, greedy, implementation
Correct Solution:
```
m = int(input())
c = list(map(int, input().rstrip().split()))
x, y = map(int, input().rstrip().split())
s = sum(c)
low = 0
high = s
for i in range(m):
low += c[i]
high -= c[i]
if low >= x and high <= y and low <= y and high >= x:
print(i + 2)
break
else:
print(0)
``` | output | 1 | 49,160 | 17 | 98,321 |
Provide tags and a correct Python 3 solution for this coding contest problem.
At the beginning of the school year Berland State University starts two city school programming groups, for beginners and for intermediate coders. The children were tested in order to sort them into groups. According to the results, each student got some score from 1 to m points. We know that c1 schoolchildren got 1 point, c2 children got 2 points, ..., cm children got m points. Now you need to set the passing rate k (integer from 1 to m): all schoolchildren who got less than k points go to the beginner group and those who get at strictly least k points go to the intermediate group. We know that if the size of a group is more than y, then the university won't find a room for them. We also know that if a group has less than x schoolchildren, then it is too small and there's no point in having classes with it. So, you need to split all schoolchildren into two groups so that the size of each group was from x to y, inclusive.
Help the university pick the passing rate in a way that meets these requirements.
Input
The first line contains integer m (2 ≤ m ≤ 100). The second line contains m integers c1, c2, ..., cm, separated by single spaces (0 ≤ ci ≤ 100). The third line contains two space-separated integers x and y (1 ≤ x ≤ y ≤ 10000). At least one ci is greater than 0.
Output
If it is impossible to pick a passing rate in a way that makes the size of each resulting groups at least x and at most y, print 0. Otherwise, print an integer from 1 to m — the passing rate you'd like to suggest. If there are multiple possible answers, print any of them.
Examples
Input
5
3 4 3 2 1
6 8
Output
3
Input
5
0 3 3 4 2
3 10
Output
4
Input
2
2 5
3 6
Output
0
Note
In the first sample the beginner group has 7 students, the intermediate group has 6 of them.
In the second sample another correct answer is 3. | instruction | 0 | 49,161 | 17 | 98,322 |
Tags: brute force, greedy, implementation
Correct Solution:
```
m = int(input())
c = list(map(int, input().split()))
x, y = map(int, input().split())
s = sum(c)
x, y = max(x, s - y), min(y, s - x)
i, q = 0, 0
while i < m and q < x:
q += c[i]
i += 1
print(0 if q > y else i + 1)
``` | output | 1 | 49,161 | 17 | 98,323 |
Provide tags and a correct Python 3 solution for this coding contest problem.
At the beginning of the school year Berland State University starts two city school programming groups, for beginners and for intermediate coders. The children were tested in order to sort them into groups. According to the results, each student got some score from 1 to m points. We know that c1 schoolchildren got 1 point, c2 children got 2 points, ..., cm children got m points. Now you need to set the passing rate k (integer from 1 to m): all schoolchildren who got less than k points go to the beginner group and those who get at strictly least k points go to the intermediate group. We know that if the size of a group is more than y, then the university won't find a room for them. We also know that if a group has less than x schoolchildren, then it is too small and there's no point in having classes with it. So, you need to split all schoolchildren into two groups so that the size of each group was from x to y, inclusive.
Help the university pick the passing rate in a way that meets these requirements.
Input
The first line contains integer m (2 ≤ m ≤ 100). The second line contains m integers c1, c2, ..., cm, separated by single spaces (0 ≤ ci ≤ 100). The third line contains two space-separated integers x and y (1 ≤ x ≤ y ≤ 10000). At least one ci is greater than 0.
Output
If it is impossible to pick a passing rate in a way that makes the size of each resulting groups at least x and at most y, print 0. Otherwise, print an integer from 1 to m — the passing rate you'd like to suggest. If there are multiple possible answers, print any of them.
Examples
Input
5
3 4 3 2 1
6 8
Output
3
Input
5
0 3 3 4 2
3 10
Output
4
Input
2
2 5
3 6
Output
0
Note
In the first sample the beginner group has 7 students, the intermediate group has 6 of them.
In the second sample another correct answer is 3. | instruction | 0 | 49,162 | 17 | 98,324 |
Tags: brute force, greedy, implementation
Correct Solution:
```
m = int(input())
c = list(map(int,input().split()))
x, y = map(int,input().split())
for i in range(m):
sb = sum(c[:-i-1])
si = sum(c[-i-1:])
if x <= sb <= y:
if x <= si <= y:
print(m-i)
break
else:
print(0)
``` | output | 1 | 49,162 | 17 | 98,325 |
Provide tags and a correct Python 3 solution for this coding contest problem.
At the beginning of the school year Berland State University starts two city school programming groups, for beginners and for intermediate coders. The children were tested in order to sort them into groups. According to the results, each student got some score from 1 to m points. We know that c1 schoolchildren got 1 point, c2 children got 2 points, ..., cm children got m points. Now you need to set the passing rate k (integer from 1 to m): all schoolchildren who got less than k points go to the beginner group and those who get at strictly least k points go to the intermediate group. We know that if the size of a group is more than y, then the university won't find a room for them. We also know that if a group has less than x schoolchildren, then it is too small and there's no point in having classes with it. So, you need to split all schoolchildren into two groups so that the size of each group was from x to y, inclusive.
Help the university pick the passing rate in a way that meets these requirements.
Input
The first line contains integer m (2 ≤ m ≤ 100). The second line contains m integers c1, c2, ..., cm, separated by single spaces (0 ≤ ci ≤ 100). The third line contains two space-separated integers x and y (1 ≤ x ≤ y ≤ 10000). At least one ci is greater than 0.
Output
If it is impossible to pick a passing rate in a way that makes the size of each resulting groups at least x and at most y, print 0. Otherwise, print an integer from 1 to m — the passing rate you'd like to suggest. If there are multiple possible answers, print any of them.
Examples
Input
5
3 4 3 2 1
6 8
Output
3
Input
5
0 3 3 4 2
3 10
Output
4
Input
2
2 5
3 6
Output
0
Note
In the first sample the beginner group has 7 students, the intermediate group has 6 of them.
In the second sample another correct answer is 3. | instruction | 0 | 49,163 | 17 | 98,326 |
Tags: brute force, greedy, implementation
Correct Solution:
```
m = int(input())
c = [int(x) for x in input().split()]
x, y = (int(x) for x in input().split())
cur = 0
tot = sum(c)
for i, ci in enumerate(c):
cur += ci
if cur >= x and cur <= y and tot - cur >= x and tot - cur <= y:
print(i + 2)
exit()
print(0)
``` | output | 1 | 49,163 | 17 | 98,327 |
Provide tags and a correct Python 3 solution for this coding contest problem.
At the beginning of the school year Berland State University starts two city school programming groups, for beginners and for intermediate coders. The children were tested in order to sort them into groups. According to the results, each student got some score from 1 to m points. We know that c1 schoolchildren got 1 point, c2 children got 2 points, ..., cm children got m points. Now you need to set the passing rate k (integer from 1 to m): all schoolchildren who got less than k points go to the beginner group and those who get at strictly least k points go to the intermediate group. We know that if the size of a group is more than y, then the university won't find a room for them. We also know that if a group has less than x schoolchildren, then it is too small and there's no point in having classes with it. So, you need to split all schoolchildren into two groups so that the size of each group was from x to y, inclusive.
Help the university pick the passing rate in a way that meets these requirements.
Input
The first line contains integer m (2 ≤ m ≤ 100). The second line contains m integers c1, c2, ..., cm, separated by single spaces (0 ≤ ci ≤ 100). The third line contains two space-separated integers x and y (1 ≤ x ≤ y ≤ 10000). At least one ci is greater than 0.
Output
If it is impossible to pick a passing rate in a way that makes the size of each resulting groups at least x and at most y, print 0. Otherwise, print an integer from 1 to m — the passing rate you'd like to suggest. If there are multiple possible answers, print any of them.
Examples
Input
5
3 4 3 2 1
6 8
Output
3
Input
5
0 3 3 4 2
3 10
Output
4
Input
2
2 5
3 6
Output
0
Note
In the first sample the beginner group has 7 students, the intermediate group has 6 of them.
In the second sample another correct answer is 3. | instruction | 0 | 49,164 | 17 | 98,328 |
Tags: brute force, greedy, implementation
Correct Solution:
```
def readln():
return tuple(map(int, input().split()))
m, = readln()
c = readln()
x, y = readln()
for k in range(1, m):
if x <= sum(c[:k]) <= y and x <= sum(c[k:]) <= y:
print(k + 1)
break
else:
print(0)
``` | output | 1 | 49,164 | 17 | 98,329 |
Provide tags and a correct Python 3 solution for this coding contest problem.
At the beginning of the school year Berland State University starts two city school programming groups, for beginners and for intermediate coders. The children were tested in order to sort them into groups. According to the results, each student got some score from 1 to m points. We know that c1 schoolchildren got 1 point, c2 children got 2 points, ..., cm children got m points. Now you need to set the passing rate k (integer from 1 to m): all schoolchildren who got less than k points go to the beginner group and those who get at strictly least k points go to the intermediate group. We know that if the size of a group is more than y, then the university won't find a room for them. We also know that if a group has less than x schoolchildren, then it is too small and there's no point in having classes with it. So, you need to split all schoolchildren into two groups so that the size of each group was from x to y, inclusive.
Help the university pick the passing rate in a way that meets these requirements.
Input
The first line contains integer m (2 ≤ m ≤ 100). The second line contains m integers c1, c2, ..., cm, separated by single spaces (0 ≤ ci ≤ 100). The third line contains two space-separated integers x and y (1 ≤ x ≤ y ≤ 10000). At least one ci is greater than 0.
Output
If it is impossible to pick a passing rate in a way that makes the size of each resulting groups at least x and at most y, print 0. Otherwise, print an integer from 1 to m — the passing rate you'd like to suggest. If there are multiple possible answers, print any of them.
Examples
Input
5
3 4 3 2 1
6 8
Output
3
Input
5
0 3 3 4 2
3 10
Output
4
Input
2
2 5
3 6
Output
0
Note
In the first sample the beginner group has 7 students, the intermediate group has 6 of them.
In the second sample another correct answer is 3. | instruction | 0 | 49,165 | 17 | 98,330 |
Tags: brute force, greedy, implementation
Correct Solution:
```
n=int(input())
marks=[int(i) for i in input().split()]
x,y=map(int,input().split())
sm=0
f=0
tot=sum(marks)
for i in range(n):
sm+=marks[i]
if sm>=x:
store=sm
rem=tot-sm
if rem>=x and rem<=y and sm<=y:
print(i+2)
exit()
if store>y:
continue
if store<=y:
if rem>=x and rem<=y:
print(i+2)
exit()
else:
pass
if not f:
print(f)
``` | output | 1 | 49,165 | 17 | 98,331 |
Provide tags and a correct Python 3 solution for this coding contest problem.
At the beginning of the school year Berland State University starts two city school programming groups, for beginners and for intermediate coders. The children were tested in order to sort them into groups. According to the results, each student got some score from 1 to m points. We know that c1 schoolchildren got 1 point, c2 children got 2 points, ..., cm children got m points. Now you need to set the passing rate k (integer from 1 to m): all schoolchildren who got less than k points go to the beginner group and those who get at strictly least k points go to the intermediate group. We know that if the size of a group is more than y, then the university won't find a room for them. We also know that if a group has less than x schoolchildren, then it is too small and there's no point in having classes with it. So, you need to split all schoolchildren into two groups so that the size of each group was from x to y, inclusive.
Help the university pick the passing rate in a way that meets these requirements.
Input
The first line contains integer m (2 ≤ m ≤ 100). The second line contains m integers c1, c2, ..., cm, separated by single spaces (0 ≤ ci ≤ 100). The third line contains two space-separated integers x and y (1 ≤ x ≤ y ≤ 10000). At least one ci is greater than 0.
Output
If it is impossible to pick a passing rate in a way that makes the size of each resulting groups at least x and at most y, print 0. Otherwise, print an integer from 1 to m — the passing rate you'd like to suggest. If there are multiple possible answers, print any of them.
Examples
Input
5
3 4 3 2 1
6 8
Output
3
Input
5
0 3 3 4 2
3 10
Output
4
Input
2
2 5
3 6
Output
0
Note
In the first sample the beginner group has 7 students, the intermediate group has 6 of them.
In the second sample another correct answer is 3. | instruction | 0 | 49,166 | 17 | 98,332 |
Tags: brute force, greedy, implementation
Correct Solution:
```
# -*- coding: utf-8 -*-
'''
======================================================================
* File Name : group.py
* Purpose :
* Creation Date : 15-10-2013
* Last Modified :
* Created By : Mario Ćesić
======================================================================
'''
import sys
# input
m = sys.stdin.readline().rstrip()
list_m = sys.stdin.readline().rstrip().split(' ')
list_m = [int(x) for x in list_m]
[x, y] = sys.stdin.readline().rstrip().split(' ')
x, y = int(x), int(y)
found = False
for i in range(len(list_m)):
sum_beginner = sum(list_m[:i])
sum_intermediate = sum(list_m[i:])
if sum_beginner >= x and sum_beginner <= y and sum_intermediate >=x and sum_intermediate <= y:
print(i + 1)
found = True
break
if not found:
print(0)
``` | output | 1 | 49,166 | 17 | 98,333 |
Provide tags and a correct Python 3 solution for this coding contest problem.
At the beginning of the school year Berland State University starts two city school programming groups, for beginners and for intermediate coders. The children were tested in order to sort them into groups. According to the results, each student got some score from 1 to m points. We know that c1 schoolchildren got 1 point, c2 children got 2 points, ..., cm children got m points. Now you need to set the passing rate k (integer from 1 to m): all schoolchildren who got less than k points go to the beginner group and those who get at strictly least k points go to the intermediate group. We know that if the size of a group is more than y, then the university won't find a room for them. We also know that if a group has less than x schoolchildren, then it is too small and there's no point in having classes with it. So, you need to split all schoolchildren into two groups so that the size of each group was from x to y, inclusive.
Help the university pick the passing rate in a way that meets these requirements.
Input
The first line contains integer m (2 ≤ m ≤ 100). The second line contains m integers c1, c2, ..., cm, separated by single spaces (0 ≤ ci ≤ 100). The third line contains two space-separated integers x and y (1 ≤ x ≤ y ≤ 10000). At least one ci is greater than 0.
Output
If it is impossible to pick a passing rate in a way that makes the size of each resulting groups at least x and at most y, print 0. Otherwise, print an integer from 1 to m — the passing rate you'd like to suggest. If there are multiple possible answers, print any of them.
Examples
Input
5
3 4 3 2 1
6 8
Output
3
Input
5
0 3 3 4 2
3 10
Output
4
Input
2
2 5
3 6
Output
0
Note
In the first sample the beginner group has 7 students, the intermediate group has 6 of them.
In the second sample another correct answer is 3. | instruction | 0 | 49,167 | 17 | 98,334 |
Tags: brute force, greedy, implementation
Correct Solution:
```
m = int(input())
c = list(map(int, input().split()))
x, y = map(int, input().split())
for i in range(m):
# print(sum(c[:i+1]), sum(c[i+1:]))
if x <= sum(c[:i+1]) <= y and x <= sum(c[i+1:]) <= y:
print(i+2)
exit(0)
print(0)
``` | output | 1 | 49,167 | 17 | 98,335 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
At the beginning of the school year Berland State University starts two city school programming groups, for beginners and for intermediate coders. The children were tested in order to sort them into groups. According to the results, each student got some score from 1 to m points. We know that c1 schoolchildren got 1 point, c2 children got 2 points, ..., cm children got m points. Now you need to set the passing rate k (integer from 1 to m): all schoolchildren who got less than k points go to the beginner group and those who get at strictly least k points go to the intermediate group. We know that if the size of a group is more than y, then the university won't find a room for them. We also know that if a group has less than x schoolchildren, then it is too small and there's no point in having classes with it. So, you need to split all schoolchildren into two groups so that the size of each group was from x to y, inclusive.
Help the university pick the passing rate in a way that meets these requirements.
Input
The first line contains integer m (2 ≤ m ≤ 100). The second line contains m integers c1, c2, ..., cm, separated by single spaces (0 ≤ ci ≤ 100). The third line contains two space-separated integers x and y (1 ≤ x ≤ y ≤ 10000). At least one ci is greater than 0.
Output
If it is impossible to pick a passing rate in a way that makes the size of each resulting groups at least x and at most y, print 0. Otherwise, print an integer from 1 to m — the passing rate you'd like to suggest. If there are multiple possible answers, print any of them.
Examples
Input
5
3 4 3 2 1
6 8
Output
3
Input
5
0 3 3 4 2
3 10
Output
4
Input
2
2 5
3 6
Output
0
Note
In the first sample the beginner group has 7 students, the intermediate group has 6 of them.
In the second sample another correct answer is 3.
Submitted Solution:
```
m = int(input())
c = list(map(int, input().split()))
inputting = list(map(int, input().split()))
x = inputting[0]
y = inputting[1]
array = []
for i in range(m):
for j in range(c[i]):
array.append(i+1)
for i in range(1, m+1):
xing = len([j for j in array if j < i])
ying = len([j for j in array if j >= i])
if xing >= x and xing <= y and ying <= y and ying >= x:
print(i)
exit()
print(0)
``` | instruction | 0 | 49,168 | 17 | 98,336 |
Yes | output | 1 | 49,168 | 17 | 98,337 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
At the beginning of the school year Berland State University starts two city school programming groups, for beginners and for intermediate coders. The children were tested in order to sort them into groups. According to the results, each student got some score from 1 to m points. We know that c1 schoolchildren got 1 point, c2 children got 2 points, ..., cm children got m points. Now you need to set the passing rate k (integer from 1 to m): all schoolchildren who got less than k points go to the beginner group and those who get at strictly least k points go to the intermediate group. We know that if the size of a group is more than y, then the university won't find a room for them. We also know that if a group has less than x schoolchildren, then it is too small and there's no point in having classes with it. So, you need to split all schoolchildren into two groups so that the size of each group was from x to y, inclusive.
Help the university pick the passing rate in a way that meets these requirements.
Input
The first line contains integer m (2 ≤ m ≤ 100). The second line contains m integers c1, c2, ..., cm, separated by single spaces (0 ≤ ci ≤ 100). The third line contains two space-separated integers x and y (1 ≤ x ≤ y ≤ 10000). At least one ci is greater than 0.
Output
If it is impossible to pick a passing rate in a way that makes the size of each resulting groups at least x and at most y, print 0. Otherwise, print an integer from 1 to m — the passing rate you'd like to suggest. If there are multiple possible answers, print any of them.
Examples
Input
5
3 4 3 2 1
6 8
Output
3
Input
5
0 3 3 4 2
3 10
Output
4
Input
2
2 5
3 6
Output
0
Note
In the first sample the beginner group has 7 students, the intermediate group has 6 of them.
In the second sample another correct answer is 3.
Submitted Solution:
```
n=int(input())
a=list(map(int,input().split()))
x,y=map(int,input().split())
s=0
for i in a:
s+=i
s1=s
for i in range(len(a)):
if (s1-a[i])>=x and (s1-a[i])<=y and (s-s1+a[i])>=x and s-s1+a[i]<=y:
print(i+2)
exit(0)
s1-=a[i]
print(0)
``` | instruction | 0 | 49,169 | 17 | 98,338 |
Yes | output | 1 | 49,169 | 17 | 98,339 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
At the beginning of the school year Berland State University starts two city school programming groups, for beginners and for intermediate coders. The children were tested in order to sort them into groups. According to the results, each student got some score from 1 to m points. We know that c1 schoolchildren got 1 point, c2 children got 2 points, ..., cm children got m points. Now you need to set the passing rate k (integer from 1 to m): all schoolchildren who got less than k points go to the beginner group and those who get at strictly least k points go to the intermediate group. We know that if the size of a group is more than y, then the university won't find a room for them. We also know that if a group has less than x schoolchildren, then it is too small and there's no point in having classes with it. So, you need to split all schoolchildren into two groups so that the size of each group was from x to y, inclusive.
Help the university pick the passing rate in a way that meets these requirements.
Input
The first line contains integer m (2 ≤ m ≤ 100). The second line contains m integers c1, c2, ..., cm, separated by single spaces (0 ≤ ci ≤ 100). The third line contains two space-separated integers x and y (1 ≤ x ≤ y ≤ 10000). At least one ci is greater than 0.
Output
If it is impossible to pick a passing rate in a way that makes the size of each resulting groups at least x and at most y, print 0. Otherwise, print an integer from 1 to m — the passing rate you'd like to suggest. If there are multiple possible answers, print any of them.
Examples
Input
5
3 4 3 2 1
6 8
Output
3
Input
5
0 3 3 4 2
3 10
Output
4
Input
2
2 5
3 6
Output
0
Note
In the first sample the beginner group has 7 students, the intermediate group has 6 of them.
In the second sample another correct answer is 3.
Submitted Solution:
```
m = int(input())
students = list(map(int, input().split()))
x, y = map(int, input().split())
for i in range(0,m):
left = sum(students[:i])
right = sum(students[i:])
if left>=x and left<=y and right>=x and right<=y:
print(i+1)
exit()
print(0)
``` | instruction | 0 | 49,170 | 17 | 98,340 |
Yes | output | 1 | 49,170 | 17 | 98,341 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
At the beginning of the school year Berland State University starts two city school programming groups, for beginners and for intermediate coders. The children were tested in order to sort them into groups. According to the results, each student got some score from 1 to m points. We know that c1 schoolchildren got 1 point, c2 children got 2 points, ..., cm children got m points. Now you need to set the passing rate k (integer from 1 to m): all schoolchildren who got less than k points go to the beginner group and those who get at strictly least k points go to the intermediate group. We know that if the size of a group is more than y, then the university won't find a room for them. We also know that if a group has less than x schoolchildren, then it is too small and there's no point in having classes with it. So, you need to split all schoolchildren into two groups so that the size of each group was from x to y, inclusive.
Help the university pick the passing rate in a way that meets these requirements.
Input
The first line contains integer m (2 ≤ m ≤ 100). The second line contains m integers c1, c2, ..., cm, separated by single spaces (0 ≤ ci ≤ 100). The third line contains two space-separated integers x and y (1 ≤ x ≤ y ≤ 10000). At least one ci is greater than 0.
Output
If it is impossible to pick a passing rate in a way that makes the size of each resulting groups at least x and at most y, print 0. Otherwise, print an integer from 1 to m — the passing rate you'd like to suggest. If there are multiple possible answers, print any of them.
Examples
Input
5
3 4 3 2 1
6 8
Output
3
Input
5
0 3 3 4 2
3 10
Output
4
Input
2
2 5
3 6
Output
0
Note
In the first sample the beginner group has 7 students, the intermediate group has 6 of them.
In the second sample another correct answer is 3.
Submitted Solution:
```
# import math
# import collections
# from itertools import permutations
# from itertools import combinations
# import sys
# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')
'''def is_prime(n):
j=2
while j*j<=n:
if n%j==0:
return 0
j+=1
return 1'''
'''def gcd(x, y):
while(y):
x, y = y, x % y
return x'''
'''fact=[]
def factors(n) :
i = 1
while i <= math.sqrt(n):
if (n % i == 0) :
if (n / i == i) :
fact.append(i)
else :
fact.append(i)
fact.append(n//i)
i = i + 1'''
def prob():
n = int(input())
# s=input()
l = [int(x) for x in input().split()]
a,b = list(map(int , input().split()))
k = sum(l)
s=0
for i in range(n):
s += l[i]
r = k-s
# print(r,s)
if a<=s<=b and a<=r<=b:
print(i+2)
return
print(0)
t=1
# t=int(input())
for _ in range(0,t):
prob()
``` | instruction | 0 | 49,171 | 17 | 98,342 |
Yes | output | 1 | 49,171 | 17 | 98,343 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
At the beginning of the school year Berland State University starts two city school programming groups, for beginners and for intermediate coders. The children were tested in order to sort them into groups. According to the results, each student got some score from 1 to m points. We know that c1 schoolchildren got 1 point, c2 children got 2 points, ..., cm children got m points. Now you need to set the passing rate k (integer from 1 to m): all schoolchildren who got less than k points go to the beginner group and those who get at strictly least k points go to the intermediate group. We know that if the size of a group is more than y, then the university won't find a room for them. We also know that if a group has less than x schoolchildren, then it is too small and there's no point in having classes with it. So, you need to split all schoolchildren into two groups so that the size of each group was from x to y, inclusive.
Help the university pick the passing rate in a way that meets these requirements.
Input
The first line contains integer m (2 ≤ m ≤ 100). The second line contains m integers c1, c2, ..., cm, separated by single spaces (0 ≤ ci ≤ 100). The third line contains two space-separated integers x and y (1 ≤ x ≤ y ≤ 10000). At least one ci is greater than 0.
Output
If it is impossible to pick a passing rate in a way that makes the size of each resulting groups at least x and at most y, print 0. Otherwise, print an integer from 1 to m — the passing rate you'd like to suggest. If there are multiple possible answers, print any of them.
Examples
Input
5
3 4 3 2 1
6 8
Output
3
Input
5
0 3 3 4 2
3 10
Output
4
Input
2
2 5
3 6
Output
0
Note
In the first sample the beginner group has 7 students, the intermediate group has 6 of them.
In the second sample another correct answer is 3.
Submitted Solution:
```
n=int(input())
marks=[int(i) for i in input().split()]
x,y=map(int,input().split())
sm=0
f=0
tot=sum(marks)
for i in range(n):
sm+=marks[i]
if sm>=x:
store=sm
rem=tot-sm
if rem>=x and rem<=y:
print(i+2)
exit()
if store>y:
continue
if store<=y:
if rem>=x and rem<=y:
print(i+2)
exit()
else:
pass
if not f:
print(f)
``` | instruction | 0 | 49,172 | 17 | 98,344 |
No | output | 1 | 49,172 | 17 | 98,345 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
At the beginning of the school year Berland State University starts two city school programming groups, for beginners and for intermediate coders. The children were tested in order to sort them into groups. According to the results, each student got some score from 1 to m points. We know that c1 schoolchildren got 1 point, c2 children got 2 points, ..., cm children got m points. Now you need to set the passing rate k (integer from 1 to m): all schoolchildren who got less than k points go to the beginner group and those who get at strictly least k points go to the intermediate group. We know that if the size of a group is more than y, then the university won't find a room for them. We also know that if a group has less than x schoolchildren, then it is too small and there's no point in having classes with it. So, you need to split all schoolchildren into two groups so that the size of each group was from x to y, inclusive.
Help the university pick the passing rate in a way that meets these requirements.
Input
The first line contains integer m (2 ≤ m ≤ 100). The second line contains m integers c1, c2, ..., cm, separated by single spaces (0 ≤ ci ≤ 100). The third line contains two space-separated integers x and y (1 ≤ x ≤ y ≤ 10000). At least one ci is greater than 0.
Output
If it is impossible to pick a passing rate in a way that makes the size of each resulting groups at least x and at most y, print 0. Otherwise, print an integer from 1 to m — the passing rate you'd like to suggest. If there are multiple possible answers, print any of them.
Examples
Input
5
3 4 3 2 1
6 8
Output
3
Input
5
0 3 3 4 2
3 10
Output
4
Input
2
2 5
3 6
Output
0
Note
In the first sample the beginner group has 7 students, the intermediate group has 6 of them.
In the second sample another correct answer is 3.
Submitted Solution:
```
if __name__=='__main__':
N = int(input())
arr = input().split(' ')
L = []
for a in arr:
L.append(int(a))
arr = input().split(' ')
x = int(arr[0])
y = int(arr[1])
cs = 0
cL = []
for a in L:
cs+=a
cL.append(cs)
ans = 0
for i in range(len(L)):
if max(cL[i],cs-cL[i])<=y and min(cL[i],cs-cL[i])>=x:
ans = i+1
break
print(ans)
``` | instruction | 0 | 49,173 | 17 | 98,346 |
No | output | 1 | 49,173 | 17 | 98,347 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
At the beginning of the school year Berland State University starts two city school programming groups, for beginners and for intermediate coders. The children were tested in order to sort them into groups. According to the results, each student got some score from 1 to m points. We know that c1 schoolchildren got 1 point, c2 children got 2 points, ..., cm children got m points. Now you need to set the passing rate k (integer from 1 to m): all schoolchildren who got less than k points go to the beginner group and those who get at strictly least k points go to the intermediate group. We know that if the size of a group is more than y, then the university won't find a room for them. We also know that if a group has less than x schoolchildren, then it is too small and there's no point in having classes with it. So, you need to split all schoolchildren into two groups so that the size of each group was from x to y, inclusive.
Help the university pick the passing rate in a way that meets these requirements.
Input
The first line contains integer m (2 ≤ m ≤ 100). The second line contains m integers c1, c2, ..., cm, separated by single spaces (0 ≤ ci ≤ 100). The third line contains two space-separated integers x and y (1 ≤ x ≤ y ≤ 10000). At least one ci is greater than 0.
Output
If it is impossible to pick a passing rate in a way that makes the size of each resulting groups at least x and at most y, print 0. Otherwise, print an integer from 1 to m — the passing rate you'd like to suggest. If there are multiple possible answers, print any of them.
Examples
Input
5
3 4 3 2 1
6 8
Output
3
Input
5
0 3 3 4 2
3 10
Output
4
Input
2
2 5
3 6
Output
0
Note
In the first sample the beginner group has 7 students, the intermediate group has 6 of them.
In the second sample another correct answer is 3.
Submitted Solution:
```
from typing import SupportsFloat
m = int (input())
tot = 0
c = list(map(int ,input().split(' ')))
x, y= map(int, input().split())
for i in range(m):
tot += c[i]
currsum = 0
f = False
for i in range(m):
currsum += c[i]
print (currsum)
if (currsum >= x and currsum <= y) and ((tot - currsum) >= x and (tot - currsum <= y)):
print (i + 2)
f = True
break
if f == False:
print (0)
``` | instruction | 0 | 49,174 | 17 | 98,348 |
No | output | 1 | 49,174 | 17 | 98,349 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
At the beginning of the school year Berland State University starts two city school programming groups, for beginners and for intermediate coders. The children were tested in order to sort them into groups. According to the results, each student got some score from 1 to m points. We know that c1 schoolchildren got 1 point, c2 children got 2 points, ..., cm children got m points. Now you need to set the passing rate k (integer from 1 to m): all schoolchildren who got less than k points go to the beginner group and those who get at strictly least k points go to the intermediate group. We know that if the size of a group is more than y, then the university won't find a room for them. We also know that if a group has less than x schoolchildren, then it is too small and there's no point in having classes with it. So, you need to split all schoolchildren into two groups so that the size of each group was from x to y, inclusive.
Help the university pick the passing rate in a way that meets these requirements.
Input
The first line contains integer m (2 ≤ m ≤ 100). The second line contains m integers c1, c2, ..., cm, separated by single spaces (0 ≤ ci ≤ 100). The third line contains two space-separated integers x and y (1 ≤ x ≤ y ≤ 10000). At least one ci is greater than 0.
Output
If it is impossible to pick a passing rate in a way that makes the size of each resulting groups at least x and at most y, print 0. Otherwise, print an integer from 1 to m — the passing rate you'd like to suggest. If there are multiple possible answers, print any of them.
Examples
Input
5
3 4 3 2 1
6 8
Output
3
Input
5
0 3 3 4 2
3 10
Output
4
Input
2
2 5
3 6
Output
0
Note
In the first sample the beginner group has 7 students, the intermediate group has 6 of them.
In the second sample another correct answer is 3.
Submitted Solution:
```
m = int(input())
yes = 0
a = [int(s) for s in input().split()]
d, c = [int(s) for s in input().split()]
def l_find(LIST, elem):
for i in range(len(LIST)):
if LIST[i] == elem:
return i
return -1
for i in range(m):
s1 = sum(a[:i])
s2 = sum(a[i:])
if s1 in range(d, c + 1) and s2 in range(d, c + 1):
print(i + 1)
yes = 1
print(0 if yes == 0 else '')
``` | instruction | 0 | 49,175 | 17 | 98,350 |
No | output | 1 | 49,175 | 17 | 98,351 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long jumps, and Valery has lost his favorite ruler!
However, there is no reason for disappointment, as Valery has found another ruler, its length is l centimeters. The ruler already has n marks, with which he can make measurements. We assume that the marks are numbered from 1 to n in the order they appear from the beginning of the ruler to its end. The first point coincides with the beginning of the ruler and represents the origin. The last mark coincides with the end of the ruler, at distance l from the origin. This ruler can be repesented by an increasing sequence a1, a2, ..., an, where ai denotes the distance of the i-th mark from the origin (a1 = 0, an = l).
Valery believes that with a ruler he can measure the distance of d centimeters, if there is a pair of integers i and j (1 ≤ i ≤ j ≤ n), such that the distance between the i-th and the j-th mark is exactly equal to d (in other words, aj - ai = d).
Under the rules, the girls should be able to jump at least x centimeters, and the boys should be able to jump at least y (x < y) centimeters. To test the children's abilities, Valery needs a ruler to measure each of the distances x and y.
Your task is to determine what is the minimum number of additional marks you need to add on the ruler so that they can be used to measure the distances x and y. Valery can add the marks at any integer non-negative distance from the origin not exceeding the length of the ruler.
Input
The first line contains four positive space-separated integers n, l, x, y (2 ≤ n ≤ 105, 2 ≤ l ≤ 109, 1 ≤ x < y ≤ l) — the number of marks, the length of the ruler and the jump norms for girls and boys, correspondingly.
The second line contains a sequence of n integers a1, a2, ..., an (0 = a1 < a2 < ... < an = l), where ai shows the distance from the i-th mark to the origin.
Output
In the first line print a single non-negative integer v — the minimum number of marks that you need to add on the ruler.
In the second line print v space-separated integers p1, p2, ..., pv (0 ≤ pi ≤ l). Number pi means that the i-th mark should be at the distance of pi centimeters from the origin. Print the marks in any order. If there are multiple solutions, print any of them.
Examples
Input
3 250 185 230
0 185 250
Output
1
230
Input
4 250 185 230
0 20 185 250
Output
0
Input
2 300 185 230
0 300
Output
2
185 230
Note
In the first sample it is impossible to initially measure the distance of 230 centimeters. For that it is enough to add a 20 centimeter mark or a 230 centimeter mark.
In the second sample you already can use the ruler to measure the distances of 185 and 230 centimeters, so you don't have to add new marks.
In the third sample the ruler only contains the initial and the final marks. We will need to add two marks to be able to test the children's skills. | instruction | 0 | 50,005 | 17 | 100,010 |
Tags: binary search, greedy, implementation
Correct Solution:
```
from collections import defaultdict
n,l,x,y = map(int,input().split())
arr = [int(x) for x in input().split()]
d = defaultdict(bool)
for i in arr:
d[i] = True
# check if already available
xs = False
ys = False
for i,v in enumerate(arr):
if(d[v+x] or d[v-x]):
xs = True
if(d[v-y] or d[v+y]):
ys = True
if(xs and ys):
print(0)
elif(xs):
print(1)
print(y)
elif(ys):
print(1)
print(x)
else:
# Try to add only one mark
done = False
a1,a2 = 0,0
for i, v in enumerate(arr):
plusY = v + y
if(0<=plusY<=l):
if(d[plusY-x]):
a1,a2 = plusY,plusY-x
done = True
break
if(d[plusY+x]):
a1,a2 = plusY,plusY+x
done = True
break
negY = v - y
if(0<=negY<=l):
if(d[negY-x]):
a1,a2 = negY,negY-x
done = True
break
if(d[negY+x]):
a1,a2 = negY,negY+x
done = True
break
plusX = v + x
if(0<=plusX<=l):
if(d[plusX-y]):
a1,a2 = plusX,plusX-y
done = True
break
if(d[plusX+y]):
a1,a2 = plusX,plusX+y
done = True
break
negX = v - x
if(0<=negX<=l):
if(d[negX-y]):
a1,a2 = negX,negX-y
done = True
break
if(d[negX+y]):
a1,a2 = negX,negX+y
done = True
break
if(done):
print(1)
print(a1)
else:
print(2)
print(x,y)
``` | output | 1 | 50,005 | 17 | 100,011 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long jumps, and Valery has lost his favorite ruler!
However, there is no reason for disappointment, as Valery has found another ruler, its length is l centimeters. The ruler already has n marks, with which he can make measurements. We assume that the marks are numbered from 1 to n in the order they appear from the beginning of the ruler to its end. The first point coincides with the beginning of the ruler and represents the origin. The last mark coincides with the end of the ruler, at distance l from the origin. This ruler can be repesented by an increasing sequence a1, a2, ..., an, where ai denotes the distance of the i-th mark from the origin (a1 = 0, an = l).
Valery believes that with a ruler he can measure the distance of d centimeters, if there is a pair of integers i and j (1 ≤ i ≤ j ≤ n), such that the distance between the i-th and the j-th mark is exactly equal to d (in other words, aj - ai = d).
Under the rules, the girls should be able to jump at least x centimeters, and the boys should be able to jump at least y (x < y) centimeters. To test the children's abilities, Valery needs a ruler to measure each of the distances x and y.
Your task is to determine what is the minimum number of additional marks you need to add on the ruler so that they can be used to measure the distances x and y. Valery can add the marks at any integer non-negative distance from the origin not exceeding the length of the ruler.
Input
The first line contains four positive space-separated integers n, l, x, y (2 ≤ n ≤ 105, 2 ≤ l ≤ 109, 1 ≤ x < y ≤ l) — the number of marks, the length of the ruler and the jump norms for girls and boys, correspondingly.
The second line contains a sequence of n integers a1, a2, ..., an (0 = a1 < a2 < ... < an = l), where ai shows the distance from the i-th mark to the origin.
Output
In the first line print a single non-negative integer v — the minimum number of marks that you need to add on the ruler.
In the second line print v space-separated integers p1, p2, ..., pv (0 ≤ pi ≤ l). Number pi means that the i-th mark should be at the distance of pi centimeters from the origin. Print the marks in any order. If there are multiple solutions, print any of them.
Examples
Input
3 250 185 230
0 185 250
Output
1
230
Input
4 250 185 230
0 20 185 250
Output
0
Input
2 300 185 230
0 300
Output
2
185 230
Note
In the first sample it is impossible to initially measure the distance of 230 centimeters. For that it is enough to add a 20 centimeter mark or a 230 centimeter mark.
In the second sample you already can use the ruler to measure the distances of 185 and 230 centimeters, so you don't have to add new marks.
In the third sample the ruler only contains the initial and the final marks. We will need to add two marks to be able to test the children's skills. | instruction | 0 | 50,006 | 17 | 100,012 |
Tags: binary search, greedy, implementation
Correct Solution:
```
# -*- coding: utf-8 -*-
import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
from typing import List
"""
created by shhuan at 2020/1/13 20:48
"""
def solve(N, L, X, Y, A):
vs = set(A)
mx = any([a+X in vs for a in A])
my = any([a+Y in vs for a in A])
if mx and my:
print(0)
elif mx:
print(1)
print(Y)
elif my:
print(1)
print(X)
else:
# try to add 1 mark
for a in vs:
for b, c in [(a + X, Y), (a + Y, X), (a - X, Y), (a - Y, X)]:
if 0 <= b <= L:
if (b + c <= L and b + c in vs) or (b - c >= 0 and b - c in vs):
print(1)
print(b)
return
# add 2 marks
print(2)
print('{} {}'.format(X, Y))
N, L, X, Y = map(int, input().split())
A = [int(x) for x in input().split()]
solve(N, L, X, Y, A)
``` | output | 1 | 50,006 | 17 | 100,013 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long jumps, and Valery has lost his favorite ruler!
However, there is no reason for disappointment, as Valery has found another ruler, its length is l centimeters. The ruler already has n marks, with which he can make measurements. We assume that the marks are numbered from 1 to n in the order they appear from the beginning of the ruler to its end. The first point coincides with the beginning of the ruler and represents the origin. The last mark coincides with the end of the ruler, at distance l from the origin. This ruler can be repesented by an increasing sequence a1, a2, ..., an, where ai denotes the distance of the i-th mark from the origin (a1 = 0, an = l).
Valery believes that with a ruler he can measure the distance of d centimeters, if there is a pair of integers i and j (1 ≤ i ≤ j ≤ n), such that the distance between the i-th and the j-th mark is exactly equal to d (in other words, aj - ai = d).
Under the rules, the girls should be able to jump at least x centimeters, and the boys should be able to jump at least y (x < y) centimeters. To test the children's abilities, Valery needs a ruler to measure each of the distances x and y.
Your task is to determine what is the minimum number of additional marks you need to add on the ruler so that they can be used to measure the distances x and y. Valery can add the marks at any integer non-negative distance from the origin not exceeding the length of the ruler.
Input
The first line contains four positive space-separated integers n, l, x, y (2 ≤ n ≤ 105, 2 ≤ l ≤ 109, 1 ≤ x < y ≤ l) — the number of marks, the length of the ruler and the jump norms for girls and boys, correspondingly.
The second line contains a sequence of n integers a1, a2, ..., an (0 = a1 < a2 < ... < an = l), where ai shows the distance from the i-th mark to the origin.
Output
In the first line print a single non-negative integer v — the minimum number of marks that you need to add on the ruler.
In the second line print v space-separated integers p1, p2, ..., pv (0 ≤ pi ≤ l). Number pi means that the i-th mark should be at the distance of pi centimeters from the origin. Print the marks in any order. If there are multiple solutions, print any of them.
Examples
Input
3 250 185 230
0 185 250
Output
1
230
Input
4 250 185 230
0 20 185 250
Output
0
Input
2 300 185 230
0 300
Output
2
185 230
Note
In the first sample it is impossible to initially measure the distance of 230 centimeters. For that it is enough to add a 20 centimeter mark or a 230 centimeter mark.
In the second sample you already can use the ruler to measure the distances of 185 and 230 centimeters, so you don't have to add new marks.
In the third sample the ruler only contains the initial and the final marks. We will need to add two marks to be able to test the children's skills. | instruction | 0 | 50,007 | 17 | 100,014 |
Tags: binary search, greedy, implementation
Correct Solution:
```
n, l, x, y = map(int, input().split())
a = set(map(int, input().split()))
ok1 = ok2 = ok3 = False
for c in a:
if c + x in a:
ok1 = True
if c + y in a:
ok2 = True
if c - x > 0 and c - x + y in a:
ok3 = True
mark = c - x
if c + x < l and c + x - y in a:
ok3 = True
mark = c + x
if c + x + y in a:
ok3 = True
mark = c + x
if c - x - y in a:
ok3 = True
mark = c - x
if ok1 and ok2:
print(0)
elif (not ok1) and (not ok2):
if ok3:
print(1)
print(mark)
else:
print(2)
print(x, y)
else:
print(1)
print(y if ok1 else x)
``` | output | 1 | 50,007 | 17 | 100,015 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long jumps, and Valery has lost his favorite ruler!
However, there is no reason for disappointment, as Valery has found another ruler, its length is l centimeters. The ruler already has n marks, with which he can make measurements. We assume that the marks are numbered from 1 to n in the order they appear from the beginning of the ruler to its end. The first point coincides with the beginning of the ruler and represents the origin. The last mark coincides with the end of the ruler, at distance l from the origin. This ruler can be repesented by an increasing sequence a1, a2, ..., an, where ai denotes the distance of the i-th mark from the origin (a1 = 0, an = l).
Valery believes that with a ruler he can measure the distance of d centimeters, if there is a pair of integers i and j (1 ≤ i ≤ j ≤ n), such that the distance between the i-th and the j-th mark is exactly equal to d (in other words, aj - ai = d).
Under the rules, the girls should be able to jump at least x centimeters, and the boys should be able to jump at least y (x < y) centimeters. To test the children's abilities, Valery needs a ruler to measure each of the distances x and y.
Your task is to determine what is the minimum number of additional marks you need to add on the ruler so that they can be used to measure the distances x and y. Valery can add the marks at any integer non-negative distance from the origin not exceeding the length of the ruler.
Input
The first line contains four positive space-separated integers n, l, x, y (2 ≤ n ≤ 105, 2 ≤ l ≤ 109, 1 ≤ x < y ≤ l) — the number of marks, the length of the ruler and the jump norms for girls and boys, correspondingly.
The second line contains a sequence of n integers a1, a2, ..., an (0 = a1 < a2 < ... < an = l), where ai shows the distance from the i-th mark to the origin.
Output
In the first line print a single non-negative integer v — the minimum number of marks that you need to add on the ruler.
In the second line print v space-separated integers p1, p2, ..., pv (0 ≤ pi ≤ l). Number pi means that the i-th mark should be at the distance of pi centimeters from the origin. Print the marks in any order. If there are multiple solutions, print any of them.
Examples
Input
3 250 185 230
0 185 250
Output
1
230
Input
4 250 185 230
0 20 185 250
Output
0
Input
2 300 185 230
0 300
Output
2
185 230
Note
In the first sample it is impossible to initially measure the distance of 230 centimeters. For that it is enough to add a 20 centimeter mark or a 230 centimeter mark.
In the second sample you already can use the ruler to measure the distances of 185 and 230 centimeters, so you don't have to add new marks.
In the third sample the ruler only contains the initial and the final marks. We will need to add two marks to be able to test the children's skills. | instruction | 0 | 50,008 | 17 | 100,016 |
Tags: binary search, greedy, implementation
Correct Solution:
```
__author__ = "zabidon"
n, l, x, y = map(int, input().split())
data = set(map(int, input().split()))
old_x = any(i + x in data for i in data)
old_y = any(i + y in data for i in data)
if old_x and old_y:
#all
print(0)
elif old_x:
#one
print(1)
print(y)
elif old_y:
#one
print(1)
print(x)
else:
found = False
for i in data:
if i + x + y in data:
found = True
print(1)
print(i + x)
elif i + x - y in data:
# because x<y
# i + x - y mean exist one mark
if 0 <= i + x <= l:
found = True
print(1)
print(i + x)
if not found and 0 <= i - y <= l:
found = True
print(1)
print(i - y)
if found:
break
if not found:
print(2)
print(x, y)
``` | output | 1 | 50,008 | 17 | 100,017 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long jumps, and Valery has lost his favorite ruler!
However, there is no reason for disappointment, as Valery has found another ruler, its length is l centimeters. The ruler already has n marks, with which he can make measurements. We assume that the marks are numbered from 1 to n in the order they appear from the beginning of the ruler to its end. The first point coincides with the beginning of the ruler and represents the origin. The last mark coincides with the end of the ruler, at distance l from the origin. This ruler can be repesented by an increasing sequence a1, a2, ..., an, where ai denotes the distance of the i-th mark from the origin (a1 = 0, an = l).
Valery believes that with a ruler he can measure the distance of d centimeters, if there is a pair of integers i and j (1 ≤ i ≤ j ≤ n), such that the distance between the i-th and the j-th mark is exactly equal to d (in other words, aj - ai = d).
Under the rules, the girls should be able to jump at least x centimeters, and the boys should be able to jump at least y (x < y) centimeters. To test the children's abilities, Valery needs a ruler to measure each of the distances x and y.
Your task is to determine what is the minimum number of additional marks you need to add on the ruler so that they can be used to measure the distances x and y. Valery can add the marks at any integer non-negative distance from the origin not exceeding the length of the ruler.
Input
The first line contains four positive space-separated integers n, l, x, y (2 ≤ n ≤ 105, 2 ≤ l ≤ 109, 1 ≤ x < y ≤ l) — the number of marks, the length of the ruler and the jump norms for girls and boys, correspondingly.
The second line contains a sequence of n integers a1, a2, ..., an (0 = a1 < a2 < ... < an = l), where ai shows the distance from the i-th mark to the origin.
Output
In the first line print a single non-negative integer v — the minimum number of marks that you need to add on the ruler.
In the second line print v space-separated integers p1, p2, ..., pv (0 ≤ pi ≤ l). Number pi means that the i-th mark should be at the distance of pi centimeters from the origin. Print the marks in any order. If there are multiple solutions, print any of them.
Examples
Input
3 250 185 230
0 185 250
Output
1
230
Input
4 250 185 230
0 20 185 250
Output
0
Input
2 300 185 230
0 300
Output
2
185 230
Note
In the first sample it is impossible to initially measure the distance of 230 centimeters. For that it is enough to add a 20 centimeter mark or a 230 centimeter mark.
In the second sample you already can use the ruler to measure the distances of 185 and 230 centimeters, so you don't have to add new marks.
In the third sample the ruler only contains the initial and the final marks. We will need to add two marks to be able to test the children's skills. | instruction | 0 | 50,009 | 17 | 100,018 |
Tags: binary search, greedy, implementation
Correct Solution:
```
from collections import defaultdict
class LongJumps():
def __init__(self, n, l, x, y, a):
self.n, self.l, self.x, self.y, self.a = n,l,x,y,a
def get_markers(self):
st = defaultdict(set)
req_pts = [self.x,self.y]
exist_check = defaultdict(bool)
value_check = defaultdict(bool)
for v in self.a:
exist_check[v] = True
for v in self.a:
for i in range(len(req_pts)):
if v - req_pts[i] >= 0:
st[v - req_pts[i]].add(i)
if exist_check[v - req_pts[i]]:
value_check[i] = True
if v + req_pts[i] <= l:
st[v+req_pts[i]].add(i)
if exist_check[v + req_pts[i]]:
value_check[i] = True
if value_check[0] and value_check[1]:
print(0)
return
sol_status = 2
status1_marker = None
for v in st:
if len(st[v]) == 2:
sol_status = 1
status1_marker = v
elif len(st[v]) == 1:
if exist_check[v]:
sol_status = 1
status1_marker = req_pts[1-st[v].pop()]
if sol_status == 1:
print(1)
print(status1_marker)
return
else:
print(2)
print(x, y)
n, l, x, y = list(map(int,input().strip(' ').split(' ')))
a = list(map(int,input().strip(' ').split(' ')))
lj = LongJumps(n,l,x,y,a)
lj.get_markers()
``` | output | 1 | 50,009 | 17 | 100,019 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long jumps, and Valery has lost his favorite ruler!
However, there is no reason for disappointment, as Valery has found another ruler, its length is l centimeters. The ruler already has n marks, with which he can make measurements. We assume that the marks are numbered from 1 to n in the order they appear from the beginning of the ruler to its end. The first point coincides with the beginning of the ruler and represents the origin. The last mark coincides with the end of the ruler, at distance l from the origin. This ruler can be repesented by an increasing sequence a1, a2, ..., an, where ai denotes the distance of the i-th mark from the origin (a1 = 0, an = l).
Valery believes that with a ruler he can measure the distance of d centimeters, if there is a pair of integers i and j (1 ≤ i ≤ j ≤ n), such that the distance between the i-th and the j-th mark is exactly equal to d (in other words, aj - ai = d).
Under the rules, the girls should be able to jump at least x centimeters, and the boys should be able to jump at least y (x < y) centimeters. To test the children's abilities, Valery needs a ruler to measure each of the distances x and y.
Your task is to determine what is the minimum number of additional marks you need to add on the ruler so that they can be used to measure the distances x and y. Valery can add the marks at any integer non-negative distance from the origin not exceeding the length of the ruler.
Input
The first line contains four positive space-separated integers n, l, x, y (2 ≤ n ≤ 105, 2 ≤ l ≤ 109, 1 ≤ x < y ≤ l) — the number of marks, the length of the ruler and the jump norms for girls and boys, correspondingly.
The second line contains a sequence of n integers a1, a2, ..., an (0 = a1 < a2 < ... < an = l), where ai shows the distance from the i-th mark to the origin.
Output
In the first line print a single non-negative integer v — the minimum number of marks that you need to add on the ruler.
In the second line print v space-separated integers p1, p2, ..., pv (0 ≤ pi ≤ l). Number pi means that the i-th mark should be at the distance of pi centimeters from the origin. Print the marks in any order. If there are multiple solutions, print any of them.
Examples
Input
3 250 185 230
0 185 250
Output
1
230
Input
4 250 185 230
0 20 185 250
Output
0
Input
2 300 185 230
0 300
Output
2
185 230
Note
In the first sample it is impossible to initially measure the distance of 230 centimeters. For that it is enough to add a 20 centimeter mark or a 230 centimeter mark.
In the second sample you already can use the ruler to measure the distances of 185 and 230 centimeters, so you don't have to add new marks.
In the third sample the ruler only contains the initial and the final marks. We will need to add two marks to be able to test the children's skills. | instruction | 0 | 50,010 | 17 | 100,020 |
Tags: binary search, greedy, implementation
Correct Solution:
```
if __name__ == "__main__":
n, l, x, y = list(map(int, input().split()))
v = list(map(int, input().split()))
s = set(v)
cx = 0
for i in range(n):
if v[i]+x in s:
cx = 1
break
cy = 0
for i in range(n):
if v[i]+y in s:
cy = 1
break
count = 0
ans = []
if cx==0:
count += 1
ans.append(x)
if cy==0:
count += 1
ans.append(y)
if count==2:
for i in range(n):
if (v[i]+x+y in s):
count = 1
ans = [v[i]+x]
break
if count==2:
for i in range(n):
if (v[i]+x-y in s):
if v[i]+x<=l:
count = 1
ans = [v[i]+x]
break
elif v[i]-y>=0:
count = 1
ans = [v[i]-y]
break
print(count)
if count!=0:
print(*ans)
``` | output | 1 | 50,010 | 17 | 100,021 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long jumps, and Valery has lost his favorite ruler!
However, there is no reason for disappointment, as Valery has found another ruler, its length is l centimeters. The ruler already has n marks, with which he can make measurements. We assume that the marks are numbered from 1 to n in the order they appear from the beginning of the ruler to its end. The first point coincides with the beginning of the ruler and represents the origin. The last mark coincides with the end of the ruler, at distance l from the origin. This ruler can be repesented by an increasing sequence a1, a2, ..., an, where ai denotes the distance of the i-th mark from the origin (a1 = 0, an = l).
Valery believes that with a ruler he can measure the distance of d centimeters, if there is a pair of integers i and j (1 ≤ i ≤ j ≤ n), such that the distance between the i-th and the j-th mark is exactly equal to d (in other words, aj - ai = d).
Under the rules, the girls should be able to jump at least x centimeters, and the boys should be able to jump at least y (x < y) centimeters. To test the children's abilities, Valery needs a ruler to measure each of the distances x and y.
Your task is to determine what is the minimum number of additional marks you need to add on the ruler so that they can be used to measure the distances x and y. Valery can add the marks at any integer non-negative distance from the origin not exceeding the length of the ruler.
Input
The first line contains four positive space-separated integers n, l, x, y (2 ≤ n ≤ 105, 2 ≤ l ≤ 109, 1 ≤ x < y ≤ l) — the number of marks, the length of the ruler and the jump norms for girls and boys, correspondingly.
The second line contains a sequence of n integers a1, a2, ..., an (0 = a1 < a2 < ... < an = l), where ai shows the distance from the i-th mark to the origin.
Output
In the first line print a single non-negative integer v — the minimum number of marks that you need to add on the ruler.
In the second line print v space-separated integers p1, p2, ..., pv (0 ≤ pi ≤ l). Number pi means that the i-th mark should be at the distance of pi centimeters from the origin. Print the marks in any order. If there are multiple solutions, print any of them.
Examples
Input
3 250 185 230
0 185 250
Output
1
230
Input
4 250 185 230
0 20 185 250
Output
0
Input
2 300 185 230
0 300
Output
2
185 230
Note
In the first sample it is impossible to initially measure the distance of 230 centimeters. For that it is enough to add a 20 centimeter mark or a 230 centimeter mark.
In the second sample you already can use the ruler to measure the distances of 185 and 230 centimeters, so you don't have to add new marks.
In the third sample the ruler only contains the initial and the final marks. We will need to add two marks to be able to test the children's skills. | instruction | 0 | 50,011 | 17 | 100,022 |
Tags: binary search, greedy, implementation
Correct Solution:
```
n,l,x,y=map(int,input().split(" "))
li=list(map(int,input().split(" ",n)[:n]))
li.sort()
dic={}
a1,a2=0,0
ans=2
x1=x
y1=y
xi=-1
yi=-1
for i in li:
dic[i]=1
for i in range(n):
if li[i]-x>=0:
if li[i]-x in dic:
a1=1
xi=i
if li[i]+x<=l:
if li[i]+x in dic:
a1=1
xi=i
if li[i]-y>=0:
if li[i]-y in dic:
a2=1
yi=i
if li[i]+y<=l:
if li[i]+y in dic:
a2=1
yi=i
if a1==1 and a2==1:
print(0)
elif a1==1:
if li[xi]-x>=0:
if li[xi]-x in dic:
if li[xi]-x+y<=l and li[xi]-x+y in dic:
a2=1
if li[xi]-x-y>=0 and li[xi]-x-y in dic:
a2=1
if li[xi]+x<=l:
if li[xi]+x in dic:
if li[xi]+x+y<=l and li[xi]+x+y in dic:
a2=1
if li[xi]+x-y>=0 and li[xi]+x-y in dic:
a2=1
if a2==1:
print(0)
else:
print(1)
print(y)
elif a2==1:
if li[yi]-y>=0:
if li[yi]-y in dic:
if li[yi]-y+x<=l and li[yi]-y+x in dic:
a1=1
if li[yi]-y-x>=0 and li[yi]-y-x in dic:
a1=1
if li[yi]+y<=l:
if li[yi]+x in dic:
if li[yi]+y+x<=l and li[yi]+y+x in dic:
a1=1
if li[yi]+y-x>=0 and li[yi]+y-x in dic:
a1=1
if a1==1:
print(0)
else:
print(1)
print(x)
else:
for i in range(n):
if li[i]-x>=0:
a1=1
xi=i
if li[xi]-x+y<=l and li[xi]-x+y in dic:
a2=1
if li[xi]-x-y>=0 and li[xi]-x-y in dic:
a2=1
if a2==1:
print(1)
print(li[i]-x)
break
else:
a1=0
if li[i]+x<=l:
a1=1
xi=i
if li[xi]+x+y<=l and li[xi]+x+y in dic:
a2=1
if li[xi]+x-y>=0 and li[xi]+x-y in dic:
a2=1
if a2==1:
print(1)
print(li[i]+x)
break
else:
a1=0
if li[i]-y>=0:
a2=1
yi=i
if li[yi]-y+x<=l and li[yi]-y+x in dic:
a1=1
if li[yi]-y-x>=0 and li[yi]-y-x in dic:
a1=1
if a1==1:
print(1)
print(li[i]-y)
break
else:
a2=0
if li[i]+y<=l:
a2=1
yi=i
if li[yi]+y+x<=l and li[yi]+y+x in dic:
a1=1
if li[yi]+y-x>=0 and li[yi]+y-x in dic:
a1=1
if a1==1:
print(1)
print(li[i]+y)
break
else:
a2=0
if a1==0 and a2==0:
print(2)
print(x,y)
``` | output | 1 | 50,011 | 17 | 100,023 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long jumps, and Valery has lost his favorite ruler!
However, there is no reason for disappointment, as Valery has found another ruler, its length is l centimeters. The ruler already has n marks, with which he can make measurements. We assume that the marks are numbered from 1 to n in the order they appear from the beginning of the ruler to its end. The first point coincides with the beginning of the ruler and represents the origin. The last mark coincides with the end of the ruler, at distance l from the origin. This ruler can be repesented by an increasing sequence a1, a2, ..., an, where ai denotes the distance of the i-th mark from the origin (a1 = 0, an = l).
Valery believes that with a ruler he can measure the distance of d centimeters, if there is a pair of integers i and j (1 ≤ i ≤ j ≤ n), such that the distance between the i-th and the j-th mark is exactly equal to d (in other words, aj - ai = d).
Under the rules, the girls should be able to jump at least x centimeters, and the boys should be able to jump at least y (x < y) centimeters. To test the children's abilities, Valery needs a ruler to measure each of the distances x and y.
Your task is to determine what is the minimum number of additional marks you need to add on the ruler so that they can be used to measure the distances x and y. Valery can add the marks at any integer non-negative distance from the origin not exceeding the length of the ruler.
Input
The first line contains four positive space-separated integers n, l, x, y (2 ≤ n ≤ 105, 2 ≤ l ≤ 109, 1 ≤ x < y ≤ l) — the number of marks, the length of the ruler and the jump norms for girls and boys, correspondingly.
The second line contains a sequence of n integers a1, a2, ..., an (0 = a1 < a2 < ... < an = l), where ai shows the distance from the i-th mark to the origin.
Output
In the first line print a single non-negative integer v — the minimum number of marks that you need to add on the ruler.
In the second line print v space-separated integers p1, p2, ..., pv (0 ≤ pi ≤ l). Number pi means that the i-th mark should be at the distance of pi centimeters from the origin. Print the marks in any order. If there are multiple solutions, print any of them.
Examples
Input
3 250 185 230
0 185 250
Output
1
230
Input
4 250 185 230
0 20 185 250
Output
0
Input
2 300 185 230
0 300
Output
2
185 230
Note
In the first sample it is impossible to initially measure the distance of 230 centimeters. For that it is enough to add a 20 centimeter mark or a 230 centimeter mark.
In the second sample you already can use the ruler to measure the distances of 185 and 230 centimeters, so you don't have to add new marks.
In the third sample the ruler only contains the initial and the final marks. We will need to add two marks to be able to test the children's skills. | instruction | 0 | 50,012 | 17 | 100,024 |
Tags: binary search, greedy, implementation
Correct Solution:
```
from collections import defaultdict as dc
def serch(a,b,x,y):
for i in range(1,n):
if (b[a[i]-x-y]):
return a[i]-y
if b[a[i]-(y-x)] and a[i]+x<=l:
return a[i]+x
if b[a[i]+(y-x)] and a[i]-x>=0:
return a[i]-x
return 0
n,l,x,y=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
b=dc(int)
b=dc(lambda :0,b)
k1=0
k2=0
for i in range(n):
b[a[i]]=1
if b[a[i]-x]==1:
k1=1
if b[a[i]-y]==1:
k2=1
if k1==1 and k2==1:
print(0)
elif k1==0 and k2==0:
z=serch(a,b,x,y)
if z!=0:
print(1)
print(z)
else:
print(2)
print(x,y)
elif k1==0:
print(1)
print(x)
else:
print(1)
print(y)
``` | output | 1 | 50,012 | 17 | 100,025 |
Provide tags and a correct Python 2 solution for this coding contest problem.
Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long jumps, and Valery has lost his favorite ruler!
However, there is no reason for disappointment, as Valery has found another ruler, its length is l centimeters. The ruler already has n marks, with which he can make measurements. We assume that the marks are numbered from 1 to n in the order they appear from the beginning of the ruler to its end. The first point coincides with the beginning of the ruler and represents the origin. The last mark coincides with the end of the ruler, at distance l from the origin. This ruler can be repesented by an increasing sequence a1, a2, ..., an, where ai denotes the distance of the i-th mark from the origin (a1 = 0, an = l).
Valery believes that with a ruler he can measure the distance of d centimeters, if there is a pair of integers i and j (1 ≤ i ≤ j ≤ n), such that the distance between the i-th and the j-th mark is exactly equal to d (in other words, aj - ai = d).
Under the rules, the girls should be able to jump at least x centimeters, and the boys should be able to jump at least y (x < y) centimeters. To test the children's abilities, Valery needs a ruler to measure each of the distances x and y.
Your task is to determine what is the minimum number of additional marks you need to add on the ruler so that they can be used to measure the distances x and y. Valery can add the marks at any integer non-negative distance from the origin not exceeding the length of the ruler.
Input
The first line contains four positive space-separated integers n, l, x, y (2 ≤ n ≤ 105, 2 ≤ l ≤ 109, 1 ≤ x < y ≤ l) — the number of marks, the length of the ruler and the jump norms for girls and boys, correspondingly.
The second line contains a sequence of n integers a1, a2, ..., an (0 = a1 < a2 < ... < an = l), where ai shows the distance from the i-th mark to the origin.
Output
In the first line print a single non-negative integer v — the minimum number of marks that you need to add on the ruler.
In the second line print v space-separated integers p1, p2, ..., pv (0 ≤ pi ≤ l). Number pi means that the i-th mark should be at the distance of pi centimeters from the origin. Print the marks in any order. If there are multiple solutions, print any of them.
Examples
Input
3 250 185 230
0 185 250
Output
1
230
Input
4 250 185 230
0 20 185 250
Output
0
Input
2 300 185 230
0 300
Output
2
185 230
Note
In the first sample it is impossible to initially measure the distance of 230 centimeters. For that it is enough to add a 20 centimeter mark or a 230 centimeter mark.
In the second sample you already can use the ruler to measure the distances of 185 and 230 centimeters, so you don't have to add new marks.
In the third sample the ruler only contains the initial and the final marks. We will need to add two marks to be able to test the children's skills. | instruction | 0 | 50,013 | 17 | 100,026 |
Tags: binary search, greedy, implementation
Correct Solution:
```
from sys import stdin, stdout
from collections import Counter, defaultdict
from itertools import permutations, combinations
raw_input = stdin.readline
pr = stdout.write
def in_arr():
return map(int,raw_input().split())
def pr_num(n):
stdout.write(str(n)+'\n')
def pr_arr(arr):
for i in arr:
stdout.write(str(i)+' ')
stdout.write('\n')
range = xrange # not for python 3.0+
# main code
n,l1,x,y=in_arr()
l=in_arr()
d=Counter(l)
f1=0
f2=0
for i in range(n):
if d[l[i]+x]:
f1=1
if d[l[i]+y]:
f2=1
if f1 and f2:
print 0
elif f1 or f2:
print 1
if f2:
print x
else:
print y
else:
f=0
for i in range(n):
if l[i]+x<=l1 and ( d[l[i]+x+y] or d[l[i]+x-y]):
print 1
#print 'a'
print l[i]+x
exit()
break
if l[i]-x>=0 and (d[l[i]+y-x] or d[l[i]-y-x]):
print 1
print l[i]-x
exit()
print 2
print x,y
``` | output | 1 | 50,013 | 17 | 100,027 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long jumps, and Valery has lost his favorite ruler!
However, there is no reason for disappointment, as Valery has found another ruler, its length is l centimeters. The ruler already has n marks, with which he can make measurements. We assume that the marks are numbered from 1 to n in the order they appear from the beginning of the ruler to its end. The first point coincides with the beginning of the ruler and represents the origin. The last mark coincides with the end of the ruler, at distance l from the origin. This ruler can be repesented by an increasing sequence a1, a2, ..., an, where ai denotes the distance of the i-th mark from the origin (a1 = 0, an = l).
Valery believes that with a ruler he can measure the distance of d centimeters, if there is a pair of integers i and j (1 ≤ i ≤ j ≤ n), such that the distance between the i-th and the j-th mark is exactly equal to d (in other words, aj - ai = d).
Under the rules, the girls should be able to jump at least x centimeters, and the boys should be able to jump at least y (x < y) centimeters. To test the children's abilities, Valery needs a ruler to measure each of the distances x and y.
Your task is to determine what is the minimum number of additional marks you need to add on the ruler so that they can be used to measure the distances x and y. Valery can add the marks at any integer non-negative distance from the origin not exceeding the length of the ruler.
Input
The first line contains four positive space-separated integers n, l, x, y (2 ≤ n ≤ 105, 2 ≤ l ≤ 109, 1 ≤ x < y ≤ l) — the number of marks, the length of the ruler and the jump norms for girls and boys, correspondingly.
The second line contains a sequence of n integers a1, a2, ..., an (0 = a1 < a2 < ... < an = l), where ai shows the distance from the i-th mark to the origin.
Output
In the first line print a single non-negative integer v — the minimum number of marks that you need to add on the ruler.
In the second line print v space-separated integers p1, p2, ..., pv (0 ≤ pi ≤ l). Number pi means that the i-th mark should be at the distance of pi centimeters from the origin. Print the marks in any order. If there are multiple solutions, print any of them.
Examples
Input
3 250 185 230
0 185 250
Output
1
230
Input
4 250 185 230
0 20 185 250
Output
0
Input
2 300 185 230
0 300
Output
2
185 230
Note
In the first sample it is impossible to initially measure the distance of 230 centimeters. For that it is enough to add a 20 centimeter mark or a 230 centimeter mark.
In the second sample you already can use the ruler to measure the distances of 185 and 230 centimeters, so you don't have to add new marks.
In the third sample the ruler only contains the initial and the final marks. We will need to add two marks to be able to test the children's skills.
Submitted Solution:
```
a = input().split(' ')
b = input().split(' ')
n=int(a[1])
x=int(a[2])
y=int(a[3])
xcan=False
ycan=False
xycan=False
xymoar=False
cool=0
cool2=0
s=set()
for element in b:
s.add(int(element))
for c in s:
if c+x in s:
xcan=True
if c+y in s:
ycan=True
if c+x+y in s:
xycan = True
cool=c
if c+y-x in s:
if c+y>n:
if c-x<0:
pass
else:
cool2 = c-x
xymoar=True
else:
xymoar = True
cool2 = c+y
if xcan:
if ycan:
break
if xcan==True:
if ycan==True:
result=0
marks=[]
else:
result = 1
marks=[y]
else:
if ycan == True:
result = 1
marks=[x]
else:
if xycan == True:
result=1
marks=[cool+x]
elif xymoar == True:
result=1
marks=[cool2]
else:
result=2
marks=[x,y]
print(result)
for i in range(len(marks)):
print(marks[i], end=' ')
``` | instruction | 0 | 50,014 | 17 | 100,028 |
Yes | output | 1 | 50,014 | 17 | 100,029 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long jumps, and Valery has lost his favorite ruler!
However, there is no reason for disappointment, as Valery has found another ruler, its length is l centimeters. The ruler already has n marks, with which he can make measurements. We assume that the marks are numbered from 1 to n in the order they appear from the beginning of the ruler to its end. The first point coincides with the beginning of the ruler and represents the origin. The last mark coincides with the end of the ruler, at distance l from the origin. This ruler can be repesented by an increasing sequence a1, a2, ..., an, where ai denotes the distance of the i-th mark from the origin (a1 = 0, an = l).
Valery believes that with a ruler he can measure the distance of d centimeters, if there is a pair of integers i and j (1 ≤ i ≤ j ≤ n), such that the distance between the i-th and the j-th mark is exactly equal to d (in other words, aj - ai = d).
Under the rules, the girls should be able to jump at least x centimeters, and the boys should be able to jump at least y (x < y) centimeters. To test the children's abilities, Valery needs a ruler to measure each of the distances x and y.
Your task is to determine what is the minimum number of additional marks you need to add on the ruler so that they can be used to measure the distances x and y. Valery can add the marks at any integer non-negative distance from the origin not exceeding the length of the ruler.
Input
The first line contains four positive space-separated integers n, l, x, y (2 ≤ n ≤ 105, 2 ≤ l ≤ 109, 1 ≤ x < y ≤ l) — the number of marks, the length of the ruler and the jump norms for girls and boys, correspondingly.
The second line contains a sequence of n integers a1, a2, ..., an (0 = a1 < a2 < ... < an = l), where ai shows the distance from the i-th mark to the origin.
Output
In the first line print a single non-negative integer v — the minimum number of marks that you need to add on the ruler.
In the second line print v space-separated integers p1, p2, ..., pv (0 ≤ pi ≤ l). Number pi means that the i-th mark should be at the distance of pi centimeters from the origin. Print the marks in any order. If there are multiple solutions, print any of them.
Examples
Input
3 250 185 230
0 185 250
Output
1
230
Input
4 250 185 230
0 20 185 250
Output
0
Input
2 300 185 230
0 300
Output
2
185 230
Note
In the first sample it is impossible to initially measure the distance of 230 centimeters. For that it is enough to add a 20 centimeter mark or a 230 centimeter mark.
In the second sample you already can use the ruler to measure the distances of 185 and 230 centimeters, so you don't have to add new marks.
In the third sample the ruler only contains the initial and the final marks. We will need to add two marks to be able to test the children's skills.
Submitted Solution:
```
def main():
import sys
tokens = [int(i) for i in sys.stdin.read().split()]
tokens.reverse()
n, l, x, y = [tokens.pop() for i in range(4)]
marks = set(tokens)
x_index = y_index = sum_index = sub_index1 = sub_index2 = -1
for i in marks:
if i + x in marks:
x_index = y
if i + y in marks:
y_index = x
if i + x + y in marks:
sum_index = i + x
if i + y - x in marks and i - x >= 0:
sub_index1 = i - x
if i + y - x in marks and i + y <= l:
sub_index2 = i + y
if x_index != -1 and y_index != -1:
print(0)
else:
for i in (x_index, y_index, sum_index, sub_index1, sub_index2):
if i != -1:
print(1)
print(i)
break
else:
print(2)
print(x, y)
main()
``` | instruction | 0 | 50,015 | 17 | 100,030 |
Yes | output | 1 | 50,015 | 17 | 100,031 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long jumps, and Valery has lost his favorite ruler!
However, there is no reason for disappointment, as Valery has found another ruler, its length is l centimeters. The ruler already has n marks, with which he can make measurements. We assume that the marks are numbered from 1 to n in the order they appear from the beginning of the ruler to its end. The first point coincides with the beginning of the ruler and represents the origin. The last mark coincides with the end of the ruler, at distance l from the origin. This ruler can be repesented by an increasing sequence a1, a2, ..., an, where ai denotes the distance of the i-th mark from the origin (a1 = 0, an = l).
Valery believes that with a ruler he can measure the distance of d centimeters, if there is a pair of integers i and j (1 ≤ i ≤ j ≤ n), such that the distance between the i-th and the j-th mark is exactly equal to d (in other words, aj - ai = d).
Under the rules, the girls should be able to jump at least x centimeters, and the boys should be able to jump at least y (x < y) centimeters. To test the children's abilities, Valery needs a ruler to measure each of the distances x and y.
Your task is to determine what is the minimum number of additional marks you need to add on the ruler so that they can be used to measure the distances x and y. Valery can add the marks at any integer non-negative distance from the origin not exceeding the length of the ruler.
Input
The first line contains four positive space-separated integers n, l, x, y (2 ≤ n ≤ 105, 2 ≤ l ≤ 109, 1 ≤ x < y ≤ l) — the number of marks, the length of the ruler and the jump norms for girls and boys, correspondingly.
The second line contains a sequence of n integers a1, a2, ..., an (0 = a1 < a2 < ... < an = l), where ai shows the distance from the i-th mark to the origin.
Output
In the first line print a single non-negative integer v — the minimum number of marks that you need to add on the ruler.
In the second line print v space-separated integers p1, p2, ..., pv (0 ≤ pi ≤ l). Number pi means that the i-th mark should be at the distance of pi centimeters from the origin. Print the marks in any order. If there are multiple solutions, print any of them.
Examples
Input
3 250 185 230
0 185 250
Output
1
230
Input
4 250 185 230
0 20 185 250
Output
0
Input
2 300 185 230
0 300
Output
2
185 230
Note
In the first sample it is impossible to initially measure the distance of 230 centimeters. For that it is enough to add a 20 centimeter mark or a 230 centimeter mark.
In the second sample you already can use the ruler to measure the distances of 185 and 230 centimeters, so you don't have to add new marks.
In the third sample the ruler only contains the initial and the final marks. We will need to add two marks to be able to test the children's skills.
Submitted Solution:
```
R = lambda: map(int, input().split())
n, l, x, y = R()
arr = set(R())
x_good, y_good = False, False
for m in arr:
if m + x in arr or m - x in arr:
x_good = True
break
for m in arr:
if m + y in arr or m - y in arr:
y_good = True
break
if x_good and y_good:
print(0)
exit()
elif x_good:
print(1)
print(y)
exit()
elif y_good:
print(1)
print(x)
exit()
else:
for m in arr:
if m + x <= l and (m + x + y in arr or m + x - y in arr):
print(1)
print(m + x)
exit()
if m - x >= 0 and (m - x + y in arr or m - x - y in arr):
print(1)
print(m - x)
exit()
if m + y <= l and (m + y + x in arr or m + y - x in arr):
print(1)
print(m + y)
exit()
if m - y >= 0 and (m - y + x in arr or m - y - x in arr):
print(1)
print(m - y)
exit()
print(2)
print(x, y)
``` | instruction | 0 | 50,016 | 17 | 100,032 |
Yes | output | 1 | 50,016 | 17 | 100,033 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long jumps, and Valery has lost his favorite ruler!
However, there is no reason for disappointment, as Valery has found another ruler, its length is l centimeters. The ruler already has n marks, with which he can make measurements. We assume that the marks are numbered from 1 to n in the order they appear from the beginning of the ruler to its end. The first point coincides with the beginning of the ruler and represents the origin. The last mark coincides with the end of the ruler, at distance l from the origin. This ruler can be repesented by an increasing sequence a1, a2, ..., an, where ai denotes the distance of the i-th mark from the origin (a1 = 0, an = l).
Valery believes that with a ruler he can measure the distance of d centimeters, if there is a pair of integers i and j (1 ≤ i ≤ j ≤ n), such that the distance between the i-th and the j-th mark is exactly equal to d (in other words, aj - ai = d).
Under the rules, the girls should be able to jump at least x centimeters, and the boys should be able to jump at least y (x < y) centimeters. To test the children's abilities, Valery needs a ruler to measure each of the distances x and y.
Your task is to determine what is the minimum number of additional marks you need to add on the ruler so that they can be used to measure the distances x and y. Valery can add the marks at any integer non-negative distance from the origin not exceeding the length of the ruler.
Input
The first line contains four positive space-separated integers n, l, x, y (2 ≤ n ≤ 105, 2 ≤ l ≤ 109, 1 ≤ x < y ≤ l) — the number of marks, the length of the ruler and the jump norms for girls and boys, correspondingly.
The second line contains a sequence of n integers a1, a2, ..., an (0 = a1 < a2 < ... < an = l), where ai shows the distance from the i-th mark to the origin.
Output
In the first line print a single non-negative integer v — the minimum number of marks that you need to add on the ruler.
In the second line print v space-separated integers p1, p2, ..., pv (0 ≤ pi ≤ l). Number pi means that the i-th mark should be at the distance of pi centimeters from the origin. Print the marks in any order. If there are multiple solutions, print any of them.
Examples
Input
3 250 185 230
0 185 250
Output
1
230
Input
4 250 185 230
0 20 185 250
Output
0
Input
2 300 185 230
0 300
Output
2
185 230
Note
In the first sample it is impossible to initially measure the distance of 230 centimeters. For that it is enough to add a 20 centimeter mark or a 230 centimeter mark.
In the second sample you already can use the ruler to measure the distances of 185 and 230 centimeters, so you don't have to add new marks.
In the third sample the ruler only contains the initial and the final marks. We will need to add two marks to be able to test the children's skills.
Submitted Solution:
```
def main():
import sys
tokens = [int(i) for i in sys.stdin.read().split()]
tokens.reverse()
n, l, x, y = [tokens.pop() for i in range(4)]
marks = set(tokens)
flag_x = flag_y = False
index = -1
for i in marks:
if i + x in marks:
flag_x = True
index = y
if i + y in marks:
flag_y = True
index = x
if i + x + y in marks:
index = i + x
if i + y - x in marks and i - x >= 0:
index = i - x
if i + y - x in marks and i + y <= l:
index = i + y
if flag_x and flag_y:
print(0)
elif index != -1:
print(1)
print(index)
else:
print(2)
print(x, y)
main()
``` | instruction | 0 | 50,017 | 17 | 100,034 |
Yes | output | 1 | 50,017 | 17 | 100,035 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long jumps, and Valery has lost his favorite ruler!
However, there is no reason for disappointment, as Valery has found another ruler, its length is l centimeters. The ruler already has n marks, with which he can make measurements. We assume that the marks are numbered from 1 to n in the order they appear from the beginning of the ruler to its end. The first point coincides with the beginning of the ruler and represents the origin. The last mark coincides with the end of the ruler, at distance l from the origin. This ruler can be repesented by an increasing sequence a1, a2, ..., an, where ai denotes the distance of the i-th mark from the origin (a1 = 0, an = l).
Valery believes that with a ruler he can measure the distance of d centimeters, if there is a pair of integers i and j (1 ≤ i ≤ j ≤ n), such that the distance between the i-th and the j-th mark is exactly equal to d (in other words, aj - ai = d).
Under the rules, the girls should be able to jump at least x centimeters, and the boys should be able to jump at least y (x < y) centimeters. To test the children's abilities, Valery needs a ruler to measure each of the distances x and y.
Your task is to determine what is the minimum number of additional marks you need to add on the ruler so that they can be used to measure the distances x and y. Valery can add the marks at any integer non-negative distance from the origin not exceeding the length of the ruler.
Input
The first line contains four positive space-separated integers n, l, x, y (2 ≤ n ≤ 105, 2 ≤ l ≤ 109, 1 ≤ x < y ≤ l) — the number of marks, the length of the ruler and the jump norms for girls and boys, correspondingly.
The second line contains a sequence of n integers a1, a2, ..., an (0 = a1 < a2 < ... < an = l), where ai shows the distance from the i-th mark to the origin.
Output
In the first line print a single non-negative integer v — the minimum number of marks that you need to add on the ruler.
In the second line print v space-separated integers p1, p2, ..., pv (0 ≤ pi ≤ l). Number pi means that the i-th mark should be at the distance of pi centimeters from the origin. Print the marks in any order. If there are multiple solutions, print any of them.
Examples
Input
3 250 185 230
0 185 250
Output
1
230
Input
4 250 185 230
0 20 185 250
Output
0
Input
2 300 185 230
0 300
Output
2
185 230
Note
In the first sample it is impossible to initially measure the distance of 230 centimeters. For that it is enough to add a 20 centimeter mark or a 230 centimeter mark.
In the second sample you already can use the ruler to measure the distances of 185 and 230 centimeters, so you don't have to add new marks.
In the third sample the ruler only contains the initial and the final marks. We will need to add two marks to be able to test the children's skills.
Submitted Solution:
```
import sys
first = sys.stdin.readline().split(" ")
n = int(first[0])
l = int(first[1])
x = int(first[2])
y = int(first[3])
second = sys.stdin.readline().split(" ")
have_dict = {}
need_dict_x = {}
need_dict_y = {}
for val in second:
have_dict[val] = 1
val = int(val)
need_dict_x[str(val - x)] = 1
need_dict_x[str(val+x)] = 1
need_dict_y[str(val - y)] = 1
need_dict_y[str(val + y)] = 1
need_x = 1
need_y = 1
something = 1
for val in have_dict.keys():
try:
need_dict_x[val]
need_x = 0
except:
something += 1
try:
need_dict_y[val]
need_y = 0
except:
something -= 1
need_vals = []
if need_x == 1 and need_y == 1:
for val in need_dict_x.keys():
try:
need_dict_y[val]
print(1)
print(val)
sys.exit()
except:
continue
print(2)
print(str(x) + " "+str(y))
else:
print(need_x+need_y)
if need_x == 1:
print(x)
elif need_y == 1:
print(y)
``` | instruction | 0 | 50,018 | 17 | 100,036 |
No | output | 1 | 50,018 | 17 | 100,037 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long jumps, and Valery has lost his favorite ruler!
However, there is no reason for disappointment, as Valery has found another ruler, its length is l centimeters. The ruler already has n marks, with which he can make measurements. We assume that the marks are numbered from 1 to n in the order they appear from the beginning of the ruler to its end. The first point coincides with the beginning of the ruler and represents the origin. The last mark coincides with the end of the ruler, at distance l from the origin. This ruler can be repesented by an increasing sequence a1, a2, ..., an, where ai denotes the distance of the i-th mark from the origin (a1 = 0, an = l).
Valery believes that with a ruler he can measure the distance of d centimeters, if there is a pair of integers i and j (1 ≤ i ≤ j ≤ n), such that the distance between the i-th and the j-th mark is exactly equal to d (in other words, aj - ai = d).
Under the rules, the girls should be able to jump at least x centimeters, and the boys should be able to jump at least y (x < y) centimeters. To test the children's abilities, Valery needs a ruler to measure each of the distances x and y.
Your task is to determine what is the minimum number of additional marks you need to add on the ruler so that they can be used to measure the distances x and y. Valery can add the marks at any integer non-negative distance from the origin not exceeding the length of the ruler.
Input
The first line contains four positive space-separated integers n, l, x, y (2 ≤ n ≤ 105, 2 ≤ l ≤ 109, 1 ≤ x < y ≤ l) — the number of marks, the length of the ruler and the jump norms for girls and boys, correspondingly.
The second line contains a sequence of n integers a1, a2, ..., an (0 = a1 < a2 < ... < an = l), where ai shows the distance from the i-th mark to the origin.
Output
In the first line print a single non-negative integer v — the minimum number of marks that you need to add on the ruler.
In the second line print v space-separated integers p1, p2, ..., pv (0 ≤ pi ≤ l). Number pi means that the i-th mark should be at the distance of pi centimeters from the origin. Print the marks in any order. If there are multiple solutions, print any of them.
Examples
Input
3 250 185 230
0 185 250
Output
1
230
Input
4 250 185 230
0 20 185 250
Output
0
Input
2 300 185 230
0 300
Output
2
185 230
Note
In the first sample it is impossible to initially measure the distance of 230 centimeters. For that it is enough to add a 20 centimeter mark or a 230 centimeter mark.
In the second sample you already can use the ruler to measure the distances of 185 and 230 centimeters, so you don't have to add new marks.
In the third sample the ruler only contains the initial and the final marks. We will need to add two marks to be able to test the children's skills.
Submitted Solution:
```
a = input().split(' ')
b = input().split(' ')
x=int(a[2])
y=int(a[3])
xcan=False
ycan=False
xycan=False
xymoar=False
cool=0
cool2=0
s=set()
for element in b:
s.add(int(element))
for c in s:
if c+x in s:
xcan=True
if c+y in s:
ycan=True
if c+x+y in s:
xycan = True
cool=c
if c+y-x in s:
if c+y>len(s):
pass
elif c-x<0:
pass
else:
xymoar = True
cool2 = c
if xcan:
if ycan:
break
if xcan==True:
if ycan==True:
result=0
marks=[]
else:
result = 1
marks=[y]
else:
if ycan == True:
result = 1
marks=[x]
else:
if xycan == True:
result=1
marks=[cool+x]
elif xymoar == True:
result=1
if cool2+y>len(s):
marks = [cool2-x]
else:
marks=[cool2+y]
else:
result=2
marks=[x,y]
print(result)
for i in range(len(marks)):
print(marks[i], end=' ')
``` | instruction | 0 | 50,019 | 17 | 100,038 |
No | output | 1 | 50,019 | 17 | 100,039 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long jumps, and Valery has lost his favorite ruler!
However, there is no reason for disappointment, as Valery has found another ruler, its length is l centimeters. The ruler already has n marks, with which he can make measurements. We assume that the marks are numbered from 1 to n in the order they appear from the beginning of the ruler to its end. The first point coincides with the beginning of the ruler and represents the origin. The last mark coincides with the end of the ruler, at distance l from the origin. This ruler can be repesented by an increasing sequence a1, a2, ..., an, where ai denotes the distance of the i-th mark from the origin (a1 = 0, an = l).
Valery believes that with a ruler he can measure the distance of d centimeters, if there is a pair of integers i and j (1 ≤ i ≤ j ≤ n), such that the distance between the i-th and the j-th mark is exactly equal to d (in other words, aj - ai = d).
Under the rules, the girls should be able to jump at least x centimeters, and the boys should be able to jump at least y (x < y) centimeters. To test the children's abilities, Valery needs a ruler to measure each of the distances x and y.
Your task is to determine what is the minimum number of additional marks you need to add on the ruler so that they can be used to measure the distances x and y. Valery can add the marks at any integer non-negative distance from the origin not exceeding the length of the ruler.
Input
The first line contains four positive space-separated integers n, l, x, y (2 ≤ n ≤ 105, 2 ≤ l ≤ 109, 1 ≤ x < y ≤ l) — the number of marks, the length of the ruler and the jump norms for girls and boys, correspondingly.
The second line contains a sequence of n integers a1, a2, ..., an (0 = a1 < a2 < ... < an = l), where ai shows the distance from the i-th mark to the origin.
Output
In the first line print a single non-negative integer v — the minimum number of marks that you need to add on the ruler.
In the second line print v space-separated integers p1, p2, ..., pv (0 ≤ pi ≤ l). Number pi means that the i-th mark should be at the distance of pi centimeters from the origin. Print the marks in any order. If there are multiple solutions, print any of them.
Examples
Input
3 250 185 230
0 185 250
Output
1
230
Input
4 250 185 230
0 20 185 250
Output
0
Input
2 300 185 230
0 300
Output
2
185 230
Note
In the first sample it is impossible to initially measure the distance of 230 centimeters. For that it is enough to add a 20 centimeter mark or a 230 centimeter mark.
In the second sample you already can use the ruler to measure the distances of 185 and 230 centimeters, so you don't have to add new marks.
In the third sample the ruler only contains the initial and the final marks. We will need to add two marks to be able to test the children's skills.
Submitted Solution:
```
def main():
from bisect import bisect_left
n, l, x, y = map(int, input().split())
aa, res = list(map(int, input().split())), set()
for z in x, y:
for a in aa:
a += z
if a > l:
break
b = aa[bisect_left(aa, a)]
if b <= a:
if b == a:
res.add(z)
break
if res:
res = [z for z in (x, y) if z not in res]
else:
a, z, t, res = 0, y - x, y + x, [x, y]
for b in aa:
if b - a == z:
if a - x > 0:
res = [a - x]
elif b + x < l:
res = [b + x]
elif b == t:
res = [x]
break
a = b
print(len(res))
if res:
print(*res)
if __name__ == '__main__':
main()
``` | instruction | 0 | 50,020 | 17 | 100,040 |
No | output | 1 | 50,020 | 17 | 100,041 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long jumps, and Valery has lost his favorite ruler!
However, there is no reason for disappointment, as Valery has found another ruler, its length is l centimeters. The ruler already has n marks, with which he can make measurements. We assume that the marks are numbered from 1 to n in the order they appear from the beginning of the ruler to its end. The first point coincides with the beginning of the ruler and represents the origin. The last mark coincides with the end of the ruler, at distance l from the origin. This ruler can be repesented by an increasing sequence a1, a2, ..., an, where ai denotes the distance of the i-th mark from the origin (a1 = 0, an = l).
Valery believes that with a ruler he can measure the distance of d centimeters, if there is a pair of integers i and j (1 ≤ i ≤ j ≤ n), such that the distance between the i-th and the j-th mark is exactly equal to d (in other words, aj - ai = d).
Under the rules, the girls should be able to jump at least x centimeters, and the boys should be able to jump at least y (x < y) centimeters. To test the children's abilities, Valery needs a ruler to measure each of the distances x and y.
Your task is to determine what is the minimum number of additional marks you need to add on the ruler so that they can be used to measure the distances x and y. Valery can add the marks at any integer non-negative distance from the origin not exceeding the length of the ruler.
Input
The first line contains four positive space-separated integers n, l, x, y (2 ≤ n ≤ 105, 2 ≤ l ≤ 109, 1 ≤ x < y ≤ l) — the number of marks, the length of the ruler and the jump norms for girls and boys, correspondingly.
The second line contains a sequence of n integers a1, a2, ..., an (0 = a1 < a2 < ... < an = l), where ai shows the distance from the i-th mark to the origin.
Output
In the first line print a single non-negative integer v — the minimum number of marks that you need to add on the ruler.
In the second line print v space-separated integers p1, p2, ..., pv (0 ≤ pi ≤ l). Number pi means that the i-th mark should be at the distance of pi centimeters from the origin. Print the marks in any order. If there are multiple solutions, print any of them.
Examples
Input
3 250 185 230
0 185 250
Output
1
230
Input
4 250 185 230
0 20 185 250
Output
0
Input
2 300 185 230
0 300
Output
2
185 230
Note
In the first sample it is impossible to initially measure the distance of 230 centimeters. For that it is enough to add a 20 centimeter mark or a 230 centimeter mark.
In the second sample you already can use the ruler to measure the distances of 185 and 230 centimeters, so you don't have to add new marks.
In the third sample the ruler only contains the initial and the final marks. We will need to add two marks to be able to test the children's skills.
Submitted Solution:
```
# import sys, io, os
# input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def solve(n,l,x,y,a):
s=set()
fx,fy,fxy=False,False,False
vxy=-1
for v in a:
if v-x in s:
fx=True
if v-y in s:
fy=True
if v-x-y in s:
fxy=True
vxy=v
s.add(v)
if fx and fy:
print(0)
elif fx:
print(1)
print(y)
elif fy:
print(1)
print(x)
elif fxy:
print(1)
print(vxy-y)
else:
print(2)
print(x,y)
n,l,x,y=map(int,input().split())
a=list(map(int,input().split()))
solve(n,l,x,y,a)
``` | instruction | 0 | 50,021 | 17 | 100,042 |
No | output | 1 | 50,021 | 17 | 100,043 |
Provide a correct Python 3 solution for this coding contest problem.
N players will participate in a tennis tournament. We will call them Player 1, Player 2, \ldots, Player N.
The tournament is round-robin format, and there will be N(N-1)/2 matches in total. Is it possible to schedule these matches so that all of the following conditions are satisfied? If the answer is yes, also find the minimum number of days required.
* Each player plays at most one matches in a day.
* Each player i (1 \leq i \leq N) plays one match against Player A_{i, 1}, A_{i, 2}, \ldots, A_{i, N-1} in this order.
Constraints
* 3 \leq N \leq 1000
* 1 \leq A_{i, j} \leq N
* A_{i, j} \neq i
* A_{i, 1}, A_{i, 2}, \ldots, A_{i, N-1} are all different.
Input
Input is given from Standard Input in the following format:
N
A_{1, 1} A_{1, 2} \ldots A_{1, N-1}
A_{2, 1} A_{2, 2} \ldots A_{2, N-1}
:
A_{N, 1} A_{N, 2} \ldots A_{N, N-1}
Output
If it is possible to schedule all the matches so that all of the conditions are satisfied, print the minimum number of days required; if it is impossible, print `-1`.
Examples
Input
3
2 3
1 3
1 2
Output
3
Input
4
2 3 4
1 3 4
4 1 2
3 1 2
Output
4
Input
3
2 3
3 1
1 2
Output
-1 | instruction | 0 | 50,300 | 17 | 100,600 |
"Correct Solution:
```
n=int(input());l=[list(map(int,input().split()))for i in[0]*n];a=[0]*n;d=1;k=n*(n-1)
while sum(a)<k and d<9999:
L=[0]*n;y=0;d+=1
for i in range(n):
if a[i]<n-1:
x=l[i][a[i]]-1
if l[x][a[x]]-1==i and L[x]+L[i]<1:
a[i]+=1;a[x]+=1;L[i]=L[x]=y=1
d*=y;print([k//2,d-1][d<9999])
``` | output | 1 | 50,300 | 17 | 100,601 |
Provide a correct Python 3 solution for this coding contest problem.
N players will participate in a tennis tournament. We will call them Player 1, Player 2, \ldots, Player N.
The tournament is round-robin format, and there will be N(N-1)/2 matches in total. Is it possible to schedule these matches so that all of the following conditions are satisfied? If the answer is yes, also find the minimum number of days required.
* Each player plays at most one matches in a day.
* Each player i (1 \leq i \leq N) plays one match against Player A_{i, 1}, A_{i, 2}, \ldots, A_{i, N-1} in this order.
Constraints
* 3 \leq N \leq 1000
* 1 \leq A_{i, j} \leq N
* A_{i, j} \neq i
* A_{i, 1}, A_{i, 2}, \ldots, A_{i, N-1} are all different.
Input
Input is given from Standard Input in the following format:
N
A_{1, 1} A_{1, 2} \ldots A_{1, N-1}
A_{2, 1} A_{2, 2} \ldots A_{2, N-1}
:
A_{N, 1} A_{N, 2} \ldots A_{N, N-1}
Output
If it is possible to schedule all the matches so that all of the conditions are satisfied, print the minimum number of days required; if it is impossible, print `-1`.
Examples
Input
3
2 3
1 3
1 2
Output
3
Input
4
2 3 4
1 3 4
4 1 2
3 1 2
Output
4
Input
3
2 3
3 1
1 2
Output
-1 | instruction | 0 | 50,301 | 17 | 100,602 |
"Correct Solution:
```
import sys
sys.setrecursionlimit(10**7)
def dfs(now):
res=day[now]
if vis[now]:
if res==-1:return -1
else:return res
res=1
vis[now]=1
for to in d[now]:
r=dfs(to)
if r==-1:return -1
res=max(res,r+1)
day[now]=res
return res
n=int(input())
v=0
si=[[0]*n for _ in range(n)]
for i in range(n):
for j in range(i+1,n):
si[i][j]=v
v+=1
d=[[] for _ in range(v)]
s=[]
for i in range(n):
a=list(map(int,input().split()))
if i<a[0]-1:b=si[i][a[0]-1]
else:b=si[a[0]-1][i]
for j in a[1:]:
j-=1
if i<j:
d[b]+=[si[i][j]]
b=si[i][j]
else:
d[b]+=[si[j][i]]
b=si[j][i]
vis=[0]*v
day=[-1]*v
ans=0
for i in range(v):
di=dfs(i)
if di==-1:
print(-1)
exit()
ans=max(ans,di)
print(ans)
``` | output | 1 | 50,301 | 17 | 100,603 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
N players will participate in a tennis tournament. We will call them Player 1, Player 2, \ldots, Player N.
The tournament is round-robin format, and there will be N(N-1)/2 matches in total. Is it possible to schedule these matches so that all of the following conditions are satisfied? If the answer is yes, also find the minimum number of days required.
* Each player plays at most one matches in a day.
* Each player i (1 \leq i \leq N) plays one match against Player A_{i, 1}, A_{i, 2}, \ldots, A_{i, N-1} in this order.
Constraints
* 3 \leq N \leq 1000
* 1 \leq A_{i, j} \leq N
* A_{i, j} \neq i
* A_{i, 1}, A_{i, 2}, \ldots, A_{i, N-1} are all different.
Input
Input is given from Standard Input in the following format:
N
A_{1, 1} A_{1, 2} \ldots A_{1, N-1}
A_{2, 1} A_{2, 2} \ldots A_{2, N-1}
:
A_{N, 1} A_{N, 2} \ldots A_{N, N-1}
Output
If it is possible to schedule all the matches so that all of the conditions are satisfied, print the minimum number of days required; if it is impossible, print `-1`.
Examples
Input
3
2 3
1 3
1 2
Output
3
Input
4
2 3 4
1 3 4
4 1 2
3 1 2
Output
4
Input
3
2 3
3 1
1 2
Output
-1
Submitted Solution:
```
import sys, time
def input():
return sys.stdin.readline()[:-1]
n = int(input())
a = [list(map(int, input().split()))[::-1] for _ in range(n)]
#print(*a, sep="\n")
opponent = [-1 for _ in range(n)]
match = 0
day = 0
start_time = time.time()
while match < n*(n-1)//2:
approved = False
for i in range(n):
if a[i] != [] and opponent[i] == -1:
opponent[i] = a[i].pop()-1
#print(opponent)
for i in range(n):
if opponent[i] != -1 and opponent[opponent[i]] == i:
approved = True
match += 1
opponent[opponent[i]] = -1
opponent[i] = -1
#print(opponent)
if not approved:
print(-1)
sys.exit()
now = time.time()
#print(start_time, now, now - start_time)
if now-start_time > 1.6:
print(n*(n-1)//2)
sys.exit()
day += 1
print(day)
``` | instruction | 0 | 50,305 | 17 | 100,610 |
Yes | output | 1 | 50,305 | 17 | 100,611 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
N players will participate in a tennis tournament. We will call them Player 1, Player 2, \ldots, Player N.
The tournament is round-robin format, and there will be N(N-1)/2 matches in total. Is it possible to schedule these matches so that all of the following conditions are satisfied? If the answer is yes, also find the minimum number of days required.
* Each player plays at most one matches in a day.
* Each player i (1 \leq i \leq N) plays one match against Player A_{i, 1}, A_{i, 2}, \ldots, A_{i, N-1} in this order.
Constraints
* 3 \leq N \leq 1000
* 1 \leq A_{i, j} \leq N
* A_{i, j} \neq i
* A_{i, 1}, A_{i, 2}, \ldots, A_{i, N-1} are all different.
Input
Input is given from Standard Input in the following format:
N
A_{1, 1} A_{1, 2} \ldots A_{1, N-1}
A_{2, 1} A_{2, 2} \ldots A_{2, N-1}
:
A_{N, 1} A_{N, 2} \ldots A_{N, N-1}
Output
If it is possible to schedule all the matches so that all of the conditions are satisfied, print the minimum number of days required; if it is impossible, print `-1`.
Examples
Input
3
2 3
1 3
1 2
Output
3
Input
4
2 3 4
1 3 4
4 1 2
3 1 2
Output
4
Input
3
2 3
3 1
1 2
Output
-1
Submitted Solution:
```
n=int(input());a=[0]*n;l=[list(map(int,input().split()))for i in a];d=1;k=n*~-n
while sum(a)<k and d<1e4:
L=[1]*n;y=0;d+=1
for i in range(n):
if-~a[i]-n:
x=l[i][a[i]]-1
if l[x][a[x]]*L[x]*L[i]==i+1:a[i]+=1;a[x]+=1;L[i]=L[x]=0;y=1
print([k//2,d*y-1][d*y<1e4])
``` | instruction | 0 | 50,306 | 17 | 100,612 |
Yes | output | 1 | 50,306 | 17 | 100,613 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
N players will participate in a tennis tournament. We will call them Player 1, Player 2, \ldots, Player N.
The tournament is round-robin format, and there will be N(N-1)/2 matches in total. Is it possible to schedule these matches so that all of the following conditions are satisfied? If the answer is yes, also find the minimum number of days required.
* Each player plays at most one matches in a day.
* Each player i (1 \leq i \leq N) plays one match against Player A_{i, 1}, A_{i, 2}, \ldots, A_{i, N-1} in this order.
Constraints
* 3 \leq N \leq 1000
* 1 \leq A_{i, j} \leq N
* A_{i, j} \neq i
* A_{i, 1}, A_{i, 2}, \ldots, A_{i, N-1} are all different.
Input
Input is given from Standard Input in the following format:
N
A_{1, 1} A_{1, 2} \ldots A_{1, N-1}
A_{2, 1} A_{2, 2} \ldots A_{2, N-1}
:
A_{N, 1} A_{N, 2} \ldots A_{N, N-1}
Output
If it is possible to schedule all the matches so that all of the conditions are satisfied, print the minimum number of days required; if it is impossible, print `-1`.
Examples
Input
3
2 3
1 3
1 2
Output
3
Input
4
2 3 4
1 3 4
4 1 2
3 1 2
Output
4
Input
3
2 3
3 1
1 2
Output
-1
Submitted Solution:
```
import sys
from collections import deque
n = int(input())
matches = [[a - 1 for a in map(int, line.split())] for line in sys.stdin]
q = deque(range(n))
depth = [0] * n
waiting = [-1] * n
while q:
a = q.popleft()
b = matches[a].pop()
if waiting[b] == a:
depth[a] = depth[b] = max(depth[a], depth[b]) + 1
if matches[a]:
q.append(a)
if matches[b]:
q.append(b)
else:
waiting[a] = b
if any(matches):
print(-1)
else:
print(max(depth))
``` | instruction | 0 | 50,307 | 17 | 100,614 |
Yes | output | 1 | 50,307 | 17 | 100,615 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
N players will participate in a tennis tournament. We will call them Player 1, Player 2, \ldots, Player N.
The tournament is round-robin format, and there will be N(N-1)/2 matches in total. Is it possible to schedule these matches so that all of the following conditions are satisfied? If the answer is yes, also find the minimum number of days required.
* Each player plays at most one matches in a day.
* Each player i (1 \leq i \leq N) plays one match against Player A_{i, 1}, A_{i, 2}, \ldots, A_{i, N-1} in this order.
Constraints
* 3 \leq N \leq 1000
* 1 \leq A_{i, j} \leq N
* A_{i, j} \neq i
* A_{i, 1}, A_{i, 2}, \ldots, A_{i, N-1} are all different.
Input
Input is given from Standard Input in the following format:
N
A_{1, 1} A_{1, 2} \ldots A_{1, N-1}
A_{2, 1} A_{2, 2} \ldots A_{2, N-1}
:
A_{N, 1} A_{N, 2} \ldots A_{N, N-1}
Output
If it is possible to schedule all the matches so that all of the conditions are satisfied, print the minimum number of days required; if it is impossible, print `-1`.
Examples
Input
3
2 3
1 3
1 2
Output
3
Input
4
2 3 4
1 3 4
4 1 2
3 1 2
Output
4
Input
3
2 3
3 1
1 2
Output
-1
Submitted Solution:
```
n = int(input())
a = []
for _ in range(n+1):
a.append([-1])
for i in range(n):
inp = list(map(int, input().split()))
for j in range(n-2, -1, -1):
a[i+1].append(inp[j])
matched = [i for i in range(1, n+1)]
finish = 0
days = 0
while True:
used = set()
while matched != []:
i = matched.pop()
p = a[i][-1]
if p != -1 and a[p][-1] == i and (i not in used) and (p not in used) :
a[i].pop()
a[p].pop()
used.add(i)
used.add(p)
if a[i][-1] == -1:
finish += 1
if a[p][-1] == -1:
finish += 1
days += 1
matched = list(used)
if len(used) == 0:
days = -1
break
elif finish == n:
break
print(days)
``` | instruction | 0 | 50,308 | 17 | 100,616 |
Yes | output | 1 | 50,308 | 17 | 100,617 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
N players will participate in a tennis tournament. We will call them Player 1, Player 2, \ldots, Player N.
The tournament is round-robin format, and there will be N(N-1)/2 matches in total. Is it possible to schedule these matches so that all of the following conditions are satisfied? If the answer is yes, also find the minimum number of days required.
* Each player plays at most one matches in a day.
* Each player i (1 \leq i \leq N) plays one match against Player A_{i, 1}, A_{i, 2}, \ldots, A_{i, N-1} in this order.
Constraints
* 3 \leq N \leq 1000
* 1 \leq A_{i, j} \leq N
* A_{i, j} \neq i
* A_{i, 1}, A_{i, 2}, \ldots, A_{i, N-1} are all different.
Input
Input is given from Standard Input in the following format:
N
A_{1, 1} A_{1, 2} \ldots A_{1, N-1}
A_{2, 1} A_{2, 2} \ldots A_{2, N-1}
:
A_{N, 1} A_{N, 2} \ldots A_{N, N-1}
Output
If it is possible to schedule all the matches so that all of the conditions are satisfied, print the minimum number of days required; if it is impossible, print `-1`.
Examples
Input
3
2 3
1 3
1 2
Output
3
Input
4
2 3 4
1 3 4
4 1 2
3 1 2
Output
4
Input
3
2 3
3 1
1 2
Output
-1
Submitted Solution:
```
#E
from collections import deque
n = int(input())
matches = [list(a -1 for a in map(int,input().split()))
for _ in range(N)]
q = deque(range(n))
depth = [0] * n
waiting = [-1] * n
while q:
a = q.popleft()
ma = matches[a]
if not ma:
continue
# gyaku kara kanngaeteru
b = ma.pop()
if waiting[b] == a:
depth[a] = depth[b] = max(depth[a],depth[b]) +1
q.append(a)
q.append(b)
else:
waiting[a] = b
if any(matches):
print(-1)
else:
print(max(depth))
``` | instruction | 0 | 50,309 | 17 | 100,618 |
No | output | 1 | 50,309 | 17 | 100,619 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
N players will participate in a tennis tournament. We will call them Player 1, Player 2, \ldots, Player N.
The tournament is round-robin format, and there will be N(N-1)/2 matches in total. Is it possible to schedule these matches so that all of the following conditions are satisfied? If the answer is yes, also find the minimum number of days required.
* Each player plays at most one matches in a day.
* Each player i (1 \leq i \leq N) plays one match against Player A_{i, 1}, A_{i, 2}, \ldots, A_{i, N-1} in this order.
Constraints
* 3 \leq N \leq 1000
* 1 \leq A_{i, j} \leq N
* A_{i, j} \neq i
* A_{i, 1}, A_{i, 2}, \ldots, A_{i, N-1} are all different.
Input
Input is given from Standard Input in the following format:
N
A_{1, 1} A_{1, 2} \ldots A_{1, N-1}
A_{2, 1} A_{2, 2} \ldots A_{2, N-1}
:
A_{N, 1} A_{N, 2} \ldots A_{N, N-1}
Output
If it is possible to schedule all the matches so that all of the conditions are satisfied, print the minimum number of days required; if it is impossible, print `-1`.
Examples
Input
3
2 3
1 3
1 2
Output
3
Input
4
2 3 4
1 3 4
4 1 2
3 1 2
Output
4
Input
3
2 3
3 1
1 2
Output
-1
Submitted Solution:
```
#16:07
n = int(input())
raw = []
for _ in range(n):
raw.append(list(map(lambda x: int(x)-1, input().split())))
cnt = [0 for _ in range(n)]
now = [i for i in range(n)]
ans = 0
while now:
ans += 1
last = now
now = []
tmp = [0 for _ in range(n)]
for x in last:
if cnt[x] < n-1:
y = raw[x][cnt[x]]
if tmp[x] == tmp[y] == 0 and x == raw[y][cnt[y]]:
cnt[x] += 1
cnt[y] += 1
tmp[x] = 1
tmp[y] = 1
now.append(x)
now.append(y)
#print(now)
if cnt == [n-1 for _ in range(n)]:
print(ans-1)
else:
print(-1)
``` | instruction | 0 | 50,310 | 17 | 100,620 |
No | output | 1 | 50,310 | 17 | 100,621 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
N players will participate in a tennis tournament. We will call them Player 1, Player 2, \ldots, Player N.
The tournament is round-robin format, and there will be N(N-1)/2 matches in total. Is it possible to schedule these matches so that all of the following conditions are satisfied? If the answer is yes, also find the minimum number of days required.
* Each player plays at most one matches in a day.
* Each player i (1 \leq i \leq N) plays one match against Player A_{i, 1}, A_{i, 2}, \ldots, A_{i, N-1} in this order.
Constraints
* 3 \leq N \leq 1000
* 1 \leq A_{i, j} \leq N
* A_{i, j} \neq i
* A_{i, 1}, A_{i, 2}, \ldots, A_{i, N-1} are all different.
Input
Input is given from Standard Input in the following format:
N
A_{1, 1} A_{1, 2} \ldots A_{1, N-1}
A_{2, 1} A_{2, 2} \ldots A_{2, N-1}
:
A_{N, 1} A_{N, 2} \ldots A_{N, N-1}
Output
If it is possible to schedule all the matches so that all of the conditions are satisfied, print the minimum number of days required; if it is impossible, print `-1`.
Examples
Input
3
2 3
1 3
1 2
Output
3
Input
4
2 3 4
1 3 4
4 1 2
3 1 2
Output
4
Input
3
2 3
3 1
1 2
Output
-1
Submitted Solution:
```
def examA():
N = I()
ans = 0
print(ans)
return
def examB():
ans = 0
print(ans)
return
def examC():
ans = 0
print(ans)
return
def examD():
ans = 0
print(ans)
return
def examE():
N = I()
node = N*(N-1)//2
V = [[]for _ in range(node)]
A = [LI() for _ in range(N)]
D = defaultdict(int)
cur = 0
for i in range(N):
for j in range(i+1,N):
D[(i,j)] = cur
D[(j,i)] = cur
cur += 1
for i in range(N):
a = A[i]
for j in range(N-2):
fr = D[(i,a[j]-1)]
to = D[(i,a[j+1]-1)]
#print(fr,to)
V[fr].append(to)
visited = [False] * node
calculated = [False] * node
dp = [1] * node
# https://mhiro216.hatenablog.com/entry/2019/09/08/142414
def dfs(v):
if visited[v]:
if not calculated[v]:
return -1 # 計算が終わっていない頂点を2度訪れるのはループがあるということ
return dp[v]
visited[v] = True
for u in V[v]: # 全ての辺をなめる
res = dfs(u)
if res == -1: return -1 # ループがあれば-1を返す
dp[v] = max(dp[v], res + 1)
calculated[v] = True
return dp[v]
ans = 0
for i in range(node):
res = dfs(i)
if res == -1:
print('-1') # ループがあれば-1を返す(問題文の指示)
return
elif ans<res:
ans = res
print(ans)
return
def examF():
ans = 0
print(ans)
return
import sys,copy,bisect,itertools,heapq,math,random
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]
sys.setrecursionlimit(10**6)
if __name__ == '__main__':
examE()
"""
"""
``` | instruction | 0 | 50,311 | 17 | 100,622 |
No | output | 1 | 50,311 | 17 | 100,623 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
N players will participate in a tennis tournament. We will call them Player 1, Player 2, \ldots, Player N.
The tournament is round-robin format, and there will be N(N-1)/2 matches in total. Is it possible to schedule these matches so that all of the following conditions are satisfied? If the answer is yes, also find the minimum number of days required.
* Each player plays at most one matches in a day.
* Each player i (1 \leq i \leq N) plays one match against Player A_{i, 1}, A_{i, 2}, \ldots, A_{i, N-1} in this order.
Constraints
* 3 \leq N \leq 1000
* 1 \leq A_{i, j} \leq N
* A_{i, j} \neq i
* A_{i, 1}, A_{i, 2}, \ldots, A_{i, N-1} are all different.
Input
Input is given from Standard Input in the following format:
N
A_{1, 1} A_{1, 2} \ldots A_{1, N-1}
A_{2, 1} A_{2, 2} \ldots A_{2, N-1}
:
A_{N, 1} A_{N, 2} \ldots A_{N, N-1}
Output
If it is possible to schedule all the matches so that all of the conditions are satisfied, print the minimum number of days required; if it is impossible, print `-1`.
Examples
Input
3
2 3
1 3
1 2
Output
3
Input
4
2 3 4
1 3 4
4 1 2
3 1 2
Output
4
Input
3
2 3
3 1
1 2
Output
-1
Submitted Solution:
```
N = int(input())
import sys
input = sys.stdin.readline
A = [None] * N
for i in range(N):
a = list(map(int, input().split()))
A[i] = a
import itertools
def f():
IDX = [0] * N
day = 0
end = 0
for _ in itertools.cycle([None]):
NEXT_IDX = IDX[:]
flag = True
for player, i in enumerate(IDX):
#print(player, i)
if i > N-2:
continue
#print(player, i)
enemy = A[player][i]
if A[enemy-1][IDX[enemy-1]] == player+1:
NEXT_IDX[player] += 1
flag = False
#print(player, NEXT_IDX)
if NEXT_IDX[player] == N-1:
end += 1
if flag:
#print(end, NEXT_IDX)
return(-1)
day += 1
if end == N:
return day
IDX = NEXT_IDX[:]
print(f())
``` | instruction | 0 | 50,312 | 17 | 100,624 |
No | output | 1 | 50,312 | 17 | 100,625 |
Provide a correct Python 3 solution for this coding contest problem.
<image>
The International Clown and Pierrot Competition (ICPC), is one of the most distinguished and also the most popular events on earth in the show business.
One of the unique features of this contest is the great number of judges that sometimes counts up to one hundred. The number of judges may differ from one contestant to another, because judges with any relationship whatsoever with a specific contestant are temporarily excluded for scoring his/her performance.
Basically, scores given to a contestant's performance by the judges are averaged to decide his/her score. To avoid letting judges with eccentric viewpoints too much influence the score, the highest and the lowest scores are set aside in this calculation. If the same highest score is marked by two or more judges, only one of them is ignored. The same is with the lowest score. The average, which may contain fractions, are truncated down to obtain final score as an integer.
You are asked to write a program that computes the scores of performances, given the scores of all the judges, to speed up the event to be suited for a TV program.
Input
The input consists of a number of datasets, each corresponding to a contestant's performance. There are no more than 20 datasets in the input.
A dataset begins with a line with an integer n, the number of judges participated in scoring the performance (3 ≤ n ≤ 100). Each of the n lines following it has an integral score s (0 ≤ s ≤ 1000) marked by a judge. No other characters except for digits to express these numbers are in the input. Judges' names are kept secret.
The end of the input is indicated by a line with a single zero in it.
Output
For each dataset, a line containing a single decimal integer indicating the score for the corresponding performance should be output. No other characters should be on the output line.
Example
Input
3
1000
342
0
5
2
2
9
11
932
5
300
1000
0
200
400
8
353
242
402
274
283
132
402
523
0
Output
342
7
300
326 | instruction | 0 | 50,439 | 17 | 100,878 |
"Correct Solution:
```
while True:
n = int(input())
if n == 0:
break
s = [int(input()) for i in range(n)]
s.sort()
score = sum(s) - s[0] - s[-1]
print(score // (n - 2))
``` | output | 1 | 50,439 | 17 | 100,879 |
Provide a correct Python 3 solution for this coding contest problem.
<image>
The International Clown and Pierrot Competition (ICPC), is one of the most distinguished and also the most popular events on earth in the show business.
One of the unique features of this contest is the great number of judges that sometimes counts up to one hundred. The number of judges may differ from one contestant to another, because judges with any relationship whatsoever with a specific contestant are temporarily excluded for scoring his/her performance.
Basically, scores given to a contestant's performance by the judges are averaged to decide his/her score. To avoid letting judges with eccentric viewpoints too much influence the score, the highest and the lowest scores are set aside in this calculation. If the same highest score is marked by two or more judges, only one of them is ignored. The same is with the lowest score. The average, which may contain fractions, are truncated down to obtain final score as an integer.
You are asked to write a program that computes the scores of performances, given the scores of all the judges, to speed up the event to be suited for a TV program.
Input
The input consists of a number of datasets, each corresponding to a contestant's performance. There are no more than 20 datasets in the input.
A dataset begins with a line with an integer n, the number of judges participated in scoring the performance (3 ≤ n ≤ 100). Each of the n lines following it has an integral score s (0 ≤ s ≤ 1000) marked by a judge. No other characters except for digits to express these numbers are in the input. Judges' names are kept secret.
The end of the input is indicated by a line with a single zero in it.
Output
For each dataset, a line containing a single decimal integer indicating the score for the corresponding performance should be output. No other characters should be on the output line.
Example
Input
3
1000
342
0
5
2
2
9
11
932
5
300
1000
0
200
400
8
353
242
402
274
283
132
402
523
0
Output
342
7
300
326 | instruction | 0 | 50,440 | 17 | 100,880 |
"Correct Solution:
```
list2=[]
while True:
try:
N=int(input())
list1=[int(input()) for _ in range(N)]
list2.append(int((sum(list1)-max(list1)-min(list1))/(N-2)))
except:
break
for tmp in list2:
print(tmp)
``` | output | 1 | 50,440 | 17 | 100,881 |
Provide a correct Python 3 solution for this coding contest problem.
<image>
The International Clown and Pierrot Competition (ICPC), is one of the most distinguished and also the most popular events on earth in the show business.
One of the unique features of this contest is the great number of judges that sometimes counts up to one hundred. The number of judges may differ from one contestant to another, because judges with any relationship whatsoever with a specific contestant are temporarily excluded for scoring his/her performance.
Basically, scores given to a contestant's performance by the judges are averaged to decide his/her score. To avoid letting judges with eccentric viewpoints too much influence the score, the highest and the lowest scores are set aside in this calculation. If the same highest score is marked by two or more judges, only one of them is ignored. The same is with the lowest score. The average, which may contain fractions, are truncated down to obtain final score as an integer.
You are asked to write a program that computes the scores of performances, given the scores of all the judges, to speed up the event to be suited for a TV program.
Input
The input consists of a number of datasets, each corresponding to a contestant's performance. There are no more than 20 datasets in the input.
A dataset begins with a line with an integer n, the number of judges participated in scoring the performance (3 ≤ n ≤ 100). Each of the n lines following it has an integral score s (0 ≤ s ≤ 1000) marked by a judge. No other characters except for digits to express these numbers are in the input. Judges' names are kept secret.
The end of the input is indicated by a line with a single zero in it.
Output
For each dataset, a line containing a single decimal integer indicating the score for the corresponding performance should be output. No other characters should be on the output line.
Example
Input
3
1000
342
0
5
2
2
9
11
932
5
300
1000
0
200
400
8
353
242
402
274
283
132
402
523
0
Output
342
7
300
326 | instruction | 0 | 50,441 | 17 | 100,882 |
"Correct Solution:
```
while 1:
n=int(input())
if n==0:break
print((sum(sorted([int(input()) for _ in range(n)])[1:-1]))//(n-2))
``` | output | 1 | 50,441 | 17 | 100,883 |
Provide a correct Python 3 solution for this coding contest problem.
<image>
The International Clown and Pierrot Competition (ICPC), is one of the most distinguished and also the most popular events on earth in the show business.
One of the unique features of this contest is the great number of judges that sometimes counts up to one hundred. The number of judges may differ from one contestant to another, because judges with any relationship whatsoever with a specific contestant are temporarily excluded for scoring his/her performance.
Basically, scores given to a contestant's performance by the judges are averaged to decide his/her score. To avoid letting judges with eccentric viewpoints too much influence the score, the highest and the lowest scores are set aside in this calculation. If the same highest score is marked by two or more judges, only one of them is ignored. The same is with the lowest score. The average, which may contain fractions, are truncated down to obtain final score as an integer.
You are asked to write a program that computes the scores of performances, given the scores of all the judges, to speed up the event to be suited for a TV program.
Input
The input consists of a number of datasets, each corresponding to a contestant's performance. There are no more than 20 datasets in the input.
A dataset begins with a line with an integer n, the number of judges participated in scoring the performance (3 ≤ n ≤ 100). Each of the n lines following it has an integral score s (0 ≤ s ≤ 1000) marked by a judge. No other characters except for digits to express these numbers are in the input. Judges' names are kept secret.
The end of the input is indicated by a line with a single zero in it.
Output
For each dataset, a line containing a single decimal integer indicating the score for the corresponding performance should be output. No other characters should be on the output line.
Example
Input
3
1000
342
0
5
2
2
9
11
932
5
300
1000
0
200
400
8
353
242
402
274
283
132
402
523
0
Output
342
7
300
326 | instruction | 0 | 50,442 | 17 | 100,884 |
"Correct Solution:
```
while True:
n = int(input())
if n == 0:
break
i = [int(input()) for i in range(n)]
print((sum(i) - min(i) - max(i)) // (n - 2))
``` | output | 1 | 50,442 | 17 | 100,885 |
Provide a correct Python 3 solution for this coding contest problem.
<image>
The International Clown and Pierrot Competition (ICPC), is one of the most distinguished and also the most popular events on earth in the show business.
One of the unique features of this contest is the great number of judges that sometimes counts up to one hundred. The number of judges may differ from one contestant to another, because judges with any relationship whatsoever with a specific contestant are temporarily excluded for scoring his/her performance.
Basically, scores given to a contestant's performance by the judges are averaged to decide his/her score. To avoid letting judges with eccentric viewpoints too much influence the score, the highest and the lowest scores are set aside in this calculation. If the same highest score is marked by two or more judges, only one of them is ignored. The same is with the lowest score. The average, which may contain fractions, are truncated down to obtain final score as an integer.
You are asked to write a program that computes the scores of performances, given the scores of all the judges, to speed up the event to be suited for a TV program.
Input
The input consists of a number of datasets, each corresponding to a contestant's performance. There are no more than 20 datasets in the input.
A dataset begins with a line with an integer n, the number of judges participated in scoring the performance (3 ≤ n ≤ 100). Each of the n lines following it has an integral score s (0 ≤ s ≤ 1000) marked by a judge. No other characters except for digits to express these numbers are in the input. Judges' names are kept secret.
The end of the input is indicated by a line with a single zero in it.
Output
For each dataset, a line containing a single decimal integer indicating the score for the corresponding performance should be output. No other characters should be on the output line.
Example
Input
3
1000
342
0
5
2
2
9
11
932
5
300
1000
0
200
400
8
353
242
402
274
283
132
402
523
0
Output
342
7
300
326 | instruction | 0 | 50,443 | 17 | 100,886 |
"Correct Solution:
```
while True:
n = int(input())
if n < 3:
break
print(sum(sorted([int(input()) for i in range(n)])[1:-1]) // (n - 2))
``` | output | 1 | 50,443 | 17 | 100,887 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.