message stringlengths 2 22.7k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 145 109k | cluster float64 9 9 | __index_level_0__ int64 290 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Gleb ordered pizza home. When the courier delivered the pizza, he was very upset, because several pieces of sausage lay on the crust, and he does not really like the crust.
The pizza is a circle of radius r and center at the origin. Pizza consists of the main part β circle of radius r - d with center at the origin, and crust around the main part of the width d. Pieces of sausage are also circles. The radius of the i -th piece of the sausage is ri, and the center is given as a pair (xi, yi).
Gleb asks you to help determine the number of pieces of sausage caught on the crust. A piece of sausage got on the crust, if it completely lies on the crust.
Input
First string contains two integer numbers r and d (0 β€ d < r β€ 500) β the radius of pizza and the width of crust.
Next line contains one integer number n β the number of pieces of sausage (1 β€ n β€ 105).
Each of next n lines contains three integer numbers xi, yi and ri ( - 500 β€ xi, yi β€ 500, 0 β€ ri β€ 500), where xi and yi are coordinates of the center of i-th peace of sausage, ri β radius of i-th peace of sausage.
Output
Output the number of pieces of sausage that lay on the crust.
Examples
Input
8 4
7
7 8 1
-7 3 2
0 2 1
0 -2 2
-3 -3 1
0 6 2
5 3 1
Output
2
Input
10 8
4
0 0 9
0 0 10
1 0 1
1 0 2
Output
0
Note
Below is a picture explaining the first example. Circles of green color denote pieces of sausage lying on the crust.
<image>
Submitted Solution:
```
r,d=map(int,input().split());c=0
for _ in range(int(input())):
x,y,r1=map(int,input().split())
dst=(x**2+y**2)**0.5
if dst>=r-d and dst<=r:
if dst+r1<=r and dst-r1>=r-d: c+=1
print(c)
``` | instruction | 0 | 53,581 | 9 | 107,162 |
Yes | output | 1 | 53,581 | 9 | 107,163 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Gleb ordered pizza home. When the courier delivered the pizza, he was very upset, because several pieces of sausage lay on the crust, and he does not really like the crust.
The pizza is a circle of radius r and center at the origin. Pizza consists of the main part β circle of radius r - d with center at the origin, and crust around the main part of the width d. Pieces of sausage are also circles. The radius of the i -th piece of the sausage is ri, and the center is given as a pair (xi, yi).
Gleb asks you to help determine the number of pieces of sausage caught on the crust. A piece of sausage got on the crust, if it completely lies on the crust.
Input
First string contains two integer numbers r and d (0 β€ d < r β€ 500) β the radius of pizza and the width of crust.
Next line contains one integer number n β the number of pieces of sausage (1 β€ n β€ 105).
Each of next n lines contains three integer numbers xi, yi and ri ( - 500 β€ xi, yi β€ 500, 0 β€ ri β€ 500), where xi and yi are coordinates of the center of i-th peace of sausage, ri β radius of i-th peace of sausage.
Output
Output the number of pieces of sausage that lay on the crust.
Examples
Input
8 4
7
7 8 1
-7 3 2
0 2 1
0 -2 2
-3 -3 1
0 6 2
5 3 1
Output
2
Input
10 8
4
0 0 9
0 0 10
1 0 1
1 0 2
Output
0
Note
Below is a picture explaining the first example. Circles of green color denote pieces of sausage lying on the crust.
<image>
Submitted Solution:
```
import math
r, d = map(int,input().split())
cnt = 0
for _ in range(int(input())):
x, y, r1 = map(int,input().split())
if math.sqrt(x**2+y**2)+r1<=r and math.sqrt(x**2+y**2)-r1>=r-d:
cnt += 1
print(cnt)
``` | instruction | 0 | 53,582 | 9 | 107,164 |
Yes | output | 1 | 53,582 | 9 | 107,165 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Gleb ordered pizza home. When the courier delivered the pizza, he was very upset, because several pieces of sausage lay on the crust, and he does not really like the crust.
The pizza is a circle of radius r and center at the origin. Pizza consists of the main part β circle of radius r - d with center at the origin, and crust around the main part of the width d. Pieces of sausage are also circles. The radius of the i -th piece of the sausage is ri, and the center is given as a pair (xi, yi).
Gleb asks you to help determine the number of pieces of sausage caught on the crust. A piece of sausage got on the crust, if it completely lies on the crust.
Input
First string contains two integer numbers r and d (0 β€ d < r β€ 500) β the radius of pizza and the width of crust.
Next line contains one integer number n β the number of pieces of sausage (1 β€ n β€ 105).
Each of next n lines contains three integer numbers xi, yi and ri ( - 500 β€ xi, yi β€ 500, 0 β€ ri β€ 500), where xi and yi are coordinates of the center of i-th peace of sausage, ri β radius of i-th peace of sausage.
Output
Output the number of pieces of sausage that lay on the crust.
Examples
Input
8 4
7
7 8 1
-7 3 2
0 2 1
0 -2 2
-3 -3 1
0 6 2
5 3 1
Output
2
Input
10 8
4
0 0 9
0 0 10
1 0 1
1 0 2
Output
0
Note
Below is a picture explaining the first example. Circles of green color denote pieces of sausage lying on the crust.
<image>
Submitted Solution:
```
r,di=map(int,input().split())
cnt=0
for i in range(int(input())):
x,y,z=map(int,input().split())
mx=max(abs(x),abs(y))
a=mx+z
b=mx-z
#print(a,b)
if di<=a<=r and di<=b<=r: cnt+=1
print(cnt)
``` | instruction | 0 | 53,583 | 9 | 107,166 |
No | output | 1 | 53,583 | 9 | 107,167 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Gleb ordered pizza home. When the courier delivered the pizza, he was very upset, because several pieces of sausage lay on the crust, and he does not really like the crust.
The pizza is a circle of radius r and center at the origin. Pizza consists of the main part β circle of radius r - d with center at the origin, and crust around the main part of the width d. Pieces of sausage are also circles. The radius of the i -th piece of the sausage is ri, and the center is given as a pair (xi, yi).
Gleb asks you to help determine the number of pieces of sausage caught on the crust. A piece of sausage got on the crust, if it completely lies on the crust.
Input
First string contains two integer numbers r and d (0 β€ d < r β€ 500) β the radius of pizza and the width of crust.
Next line contains one integer number n β the number of pieces of sausage (1 β€ n β€ 105).
Each of next n lines contains three integer numbers xi, yi and ri ( - 500 β€ xi, yi β€ 500, 0 β€ ri β€ 500), where xi and yi are coordinates of the center of i-th peace of sausage, ri β radius of i-th peace of sausage.
Output
Output the number of pieces of sausage that lay on the crust.
Examples
Input
8 4
7
7 8 1
-7 3 2
0 2 1
0 -2 2
-3 -3 1
0 6 2
5 3 1
Output
2
Input
10 8
4
0 0 9
0 0 10
1 0 1
1 0 2
Output
0
Note
Below is a picture explaining the first example. Circles of green color denote pieces of sausage lying on the crust.
<image>
Submitted Solution:
```
from math import sqrt
def dist(x1,x2,y1,y2):
return sqrt( (x2 - x1)**2 + (y2 - y1)**2 )
r,d = map(int,input().split())
n = int(input())
res = 0
for i in range(n):
x,y,c = map(int,input().split())
if dist(x,y,0,0)-c>=r-d:
res+=1
print(res)
``` | instruction | 0 | 53,584 | 9 | 107,168 |
No | output | 1 | 53,584 | 9 | 107,169 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Gleb ordered pizza home. When the courier delivered the pizza, he was very upset, because several pieces of sausage lay on the crust, and he does not really like the crust.
The pizza is a circle of radius r and center at the origin. Pizza consists of the main part β circle of radius r - d with center at the origin, and crust around the main part of the width d. Pieces of sausage are also circles. The radius of the i -th piece of the sausage is ri, and the center is given as a pair (xi, yi).
Gleb asks you to help determine the number of pieces of sausage caught on the crust. A piece of sausage got on the crust, if it completely lies on the crust.
Input
First string contains two integer numbers r and d (0 β€ d < r β€ 500) β the radius of pizza and the width of crust.
Next line contains one integer number n β the number of pieces of sausage (1 β€ n β€ 105).
Each of next n lines contains three integer numbers xi, yi and ri ( - 500 β€ xi, yi β€ 500, 0 β€ ri β€ 500), where xi and yi are coordinates of the center of i-th peace of sausage, ri β radius of i-th peace of sausage.
Output
Output the number of pieces of sausage that lay on the crust.
Examples
Input
8 4
7
7 8 1
-7 3 2
0 2 1
0 -2 2
-3 -3 1
0 6 2
5 3 1
Output
2
Input
10 8
4
0 0 9
0 0 10
1 0 1
1 0 2
Output
0
Note
Below is a picture explaining the first example. Circles of green color denote pieces of sausage lying on the crust.
<image>
Submitted Solution:
```
r,d=list(map(int,input().split()))
n=int(input())
a=[]
for _ in range(n):
x,y,z=list(map(int,input().split()))
x=(x**2+y**2)**0.5
x=x-z
a.append(x)
y=0
for i in a:
if i>(r-d):
y+=1
print(y)
``` | instruction | 0 | 53,585 | 9 | 107,170 |
No | output | 1 | 53,585 | 9 | 107,171 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Gleb ordered pizza home. When the courier delivered the pizza, he was very upset, because several pieces of sausage lay on the crust, and he does not really like the crust.
The pizza is a circle of radius r and center at the origin. Pizza consists of the main part β circle of radius r - d with center at the origin, and crust around the main part of the width d. Pieces of sausage are also circles. The radius of the i -th piece of the sausage is ri, and the center is given as a pair (xi, yi).
Gleb asks you to help determine the number of pieces of sausage caught on the crust. A piece of sausage got on the crust, if it completely lies on the crust.
Input
First string contains two integer numbers r and d (0 β€ d < r β€ 500) β the radius of pizza and the width of crust.
Next line contains one integer number n β the number of pieces of sausage (1 β€ n β€ 105).
Each of next n lines contains three integer numbers xi, yi and ri ( - 500 β€ xi, yi β€ 500, 0 β€ ri β€ 500), where xi and yi are coordinates of the center of i-th peace of sausage, ri β radius of i-th peace of sausage.
Output
Output the number of pieces of sausage that lay on the crust.
Examples
Input
8 4
7
7 8 1
-7 3 2
0 2 1
0 -2 2
-3 -3 1
0 6 2
5 3 1
Output
2
Input
10 8
4
0 0 9
0 0 10
1 0 1
1 0 2
Output
0
Note
Below is a picture explaining the first example. Circles of green color denote pieces of sausage lying on the crust.
<image>
Submitted Solution:
```
r, d = map(int, input().split())
n = int(input())
ans = 0
for i in range(n):
xi, yi, ri = map(int, input().split())
if (xi**2+yi**2>(r-d)**2 and xi ** 2 + (yi + ri) ** 2 >= (r - d) ** 2 and (xi + ri) ** 2 + yi ** 2 >= (r - d) ** 2 and xi ** 2 + (yi - ri) ** 2 >= (r - d) ** 2 and (xi - ri) ** 2 + yi ** 2 >= (r - d) ** 2) and ( xi**2+yi**2<r**2 and xi ** 2 + (yi + ri) ** 2 <= r ** 2 and (xi + ri) ** 2 + yi ** 2 <= r ** 2 and xi ** 2 + (yi - ri) ** 2 <= r ** 2 and (xi - ri) ** 2 + yi ** 2 <= r ** 2):
ans += 1
print(ans)
``` | instruction | 0 | 53,586 | 9 | 107,172 |
No | output | 1 | 53,586 | 9 | 107,173 |
Provide a correct Python 3 solution for this coding contest problem.
Jou and Yae are a good couple. Jou is collecting prizes for capsule toy vending machines (Gachapon), and even when they go out together, when they find Gachapon, they seem to get so hot that they try it several times. Yae was just looking at Jou, who looked happy, but decided to give him a Gachapon prize for his upcoming birthday present. Yae wasn't very interested in Gachapon itself, but hopefully he would like a match with Jou.
For Gachapon that Yae wants to try, one prize will be given in one challenge. You can see how many types of prizes there are, including those that are out of stock, and how many of each prize remains. However, I don't know which prize will be given in one challenge. Therefore, regardless of the order in which the prizes are given, create a program that outputs the minimum number of challenges required for Yae to get two of the same prizes.
input
The input consists of multiple datasets. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format:
N
k1 k2 ... kN
Each dataset has two lines, and the first line is given the integer N (1 β€ N β€ 10000), which indicates how many types of prizes there are. The next line is given the integer ki (0 β€ ki β€ 10000), which indicates how many prizes are left.
The number of datasets does not exceed 100.
output
For each dataset, the minimum number of challenges required to get two identical prizes is output. However, if it is not possible, NA is output.
Example
Input
2
3 2
3
0 1 1
1
1000
0
Output
3
NA
2 | instruction | 0 | 53,836 | 9 | 107,672 |
"Correct Solution:
```
# AOJ 0279: A Pair of Prizes
# Python3 2018.6.25 bal4u
while True:
n = int(input())
if n == 0: break
k = list(map(int, input().split()))
one, many = 0, 0
for i in k:
if i == 1: one += 1
elif i > 1: many += 1
print(one+many+1 if many > 0 else "NA")
``` | output | 1 | 53,836 | 9 | 107,673 |
Provide a correct Python 3 solution for this coding contest problem.
Jou and Yae are a good couple. Jou is collecting prizes for capsule toy vending machines (Gachapon), and even when they go out together, when they find Gachapon, they seem to get so hot that they try it several times. Yae was just looking at Jou, who looked happy, but decided to give him a Gachapon prize for his upcoming birthday present. Yae wasn't very interested in Gachapon itself, but hopefully he would like a match with Jou.
For Gachapon that Yae wants to try, one prize will be given in one challenge. You can see how many types of prizes there are, including those that are out of stock, and how many of each prize remains. However, I don't know which prize will be given in one challenge. Therefore, regardless of the order in which the prizes are given, create a program that outputs the minimum number of challenges required for Yae to get two of the same prizes.
input
The input consists of multiple datasets. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format:
N
k1 k2 ... kN
Each dataset has two lines, and the first line is given the integer N (1 β€ N β€ 10000), which indicates how many types of prizes there are. The next line is given the integer ki (0 β€ ki β€ 10000), which indicates how many prizes are left.
The number of datasets does not exceed 100.
output
For each dataset, the minimum number of challenges required to get two identical prizes is output. However, if it is not possible, NA is output.
Example
Input
2
3 2
3
0 1 1
1
1000
0
Output
3
NA
2 | instruction | 0 | 53,837 | 9 | 107,674 |
"Correct Solution:
```
while input()!="0":
a=list(map(int,input().split()))
print("NA" if max(a)<2 else sum(1 for x in a if x)+1)
``` | output | 1 | 53,837 | 9 | 107,675 |
Provide a correct Python 3 solution for this coding contest problem.
Jou and Yae are a good couple. Jou is collecting prizes for capsule toy vending machines (Gachapon), and even when they go out together, when they find Gachapon, they seem to get so hot that they try it several times. Yae was just looking at Jou, who looked happy, but decided to give him a Gachapon prize for his upcoming birthday present. Yae wasn't very interested in Gachapon itself, but hopefully he would like a match with Jou.
For Gachapon that Yae wants to try, one prize will be given in one challenge. You can see how many types of prizes there are, including those that are out of stock, and how many of each prize remains. However, I don't know which prize will be given in one challenge. Therefore, regardless of the order in which the prizes are given, create a program that outputs the minimum number of challenges required for Yae to get two of the same prizes.
input
The input consists of multiple datasets. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format:
N
k1 k2 ... kN
Each dataset has two lines, and the first line is given the integer N (1 β€ N β€ 10000), which indicates how many types of prizes there are. The next line is given the integer ki (0 β€ ki β€ 10000), which indicates how many prizes are left.
The number of datasets does not exceed 100.
output
For each dataset, the minimum number of challenges required to get two identical prizes is output. However, if it is not possible, NA is output.
Example
Input
2
3 2
3
0 1 1
1
1000
0
Output
3
NA
2 | instruction | 0 | 53,838 | 9 | 107,676 |
"Correct Solution:
```
while 1:
n=int(input())
count=1
if n==0:break
k=list(map(int,input().split()))
k.sort(reverse=True)
if k[0]<2:print("NA")
else:
for i in k:
if i!=0:count+=1
print(count)
``` | output | 1 | 53,838 | 9 | 107,677 |
Provide a correct Python 3 solution for this coding contest problem.
Jou and Yae are a good couple. Jou is collecting prizes for capsule toy vending machines (Gachapon), and even when they go out together, when they find Gachapon, they seem to get so hot that they try it several times. Yae was just looking at Jou, who looked happy, but decided to give him a Gachapon prize for his upcoming birthday present. Yae wasn't very interested in Gachapon itself, but hopefully he would like a match with Jou.
For Gachapon that Yae wants to try, one prize will be given in one challenge. You can see how many types of prizes there are, including those that are out of stock, and how many of each prize remains. However, I don't know which prize will be given in one challenge. Therefore, regardless of the order in which the prizes are given, create a program that outputs the minimum number of challenges required for Yae to get two of the same prizes.
input
The input consists of multiple datasets. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format:
N
k1 k2 ... kN
Each dataset has two lines, and the first line is given the integer N (1 β€ N β€ 10000), which indicates how many types of prizes there are. The next line is given the integer ki (0 β€ ki β€ 10000), which indicates how many prizes are left.
The number of datasets does not exceed 100.
output
For each dataset, the minimum number of challenges required to get two identical prizes is output. However, if it is not possible, NA is output.
Example
Input
2
3 2
3
0 1 1
1
1000
0
Output
3
NA
2 | instruction | 0 | 53,839 | 9 | 107,678 |
"Correct Solution:
```
while 1:
n = int(input())
if n == 0:break
p = list(map(int,input().split()))
if max(p) < 2:
print("NA")
continue
print(n - p.count(0) + 1)
``` | output | 1 | 53,839 | 9 | 107,679 |
Provide a correct Python 3 solution for this coding contest problem.
Jou and Yae are a good couple. Jou is collecting prizes for capsule toy vending machines (Gachapon), and even when they go out together, when they find Gachapon, they seem to get so hot that they try it several times. Yae was just looking at Jou, who looked happy, but decided to give him a Gachapon prize for his upcoming birthday present. Yae wasn't very interested in Gachapon itself, but hopefully he would like a match with Jou.
For Gachapon that Yae wants to try, one prize will be given in one challenge. You can see how many types of prizes there are, including those that are out of stock, and how many of each prize remains. However, I don't know which prize will be given in one challenge. Therefore, regardless of the order in which the prizes are given, create a program that outputs the minimum number of challenges required for Yae to get two of the same prizes.
input
The input consists of multiple datasets. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format:
N
k1 k2 ... kN
Each dataset has two lines, and the first line is given the integer N (1 β€ N β€ 10000), which indicates how many types of prizes there are. The next line is given the integer ki (0 β€ ki β€ 10000), which indicates how many prizes are left.
The number of datasets does not exceed 100.
output
For each dataset, the minimum number of challenges required to get two identical prizes is output. However, if it is not possible, NA is output.
Example
Input
2
3 2
3
0 1 1
1
1000
0
Output
3
NA
2 | instruction | 0 | 53,840 | 9 | 107,680 |
"Correct Solution:
```
while ( True ):
n = int(input())
if n == 0 : break
ki = list(map(int, input().split()))
less1Cnt = 0
zeroCnt = 0
for k in ki:
if k <= 1 : less1Cnt += 1
if k == 0 : zeroCnt += 1
if n == less1Cnt : print("NA")
else : print(n - zeroCnt + 1)
``` | output | 1 | 53,840 | 9 | 107,681 |
Provide a correct Python 3 solution for this coding contest problem.
Jou and Yae are a good couple. Jou is collecting prizes for capsule toy vending machines (Gachapon), and even when they go out together, when they find Gachapon, they seem to get so hot that they try it several times. Yae was just looking at Jou, who looked happy, but decided to give him a Gachapon prize for his upcoming birthday present. Yae wasn't very interested in Gachapon itself, but hopefully he would like a match with Jou.
For Gachapon that Yae wants to try, one prize will be given in one challenge. You can see how many types of prizes there are, including those that are out of stock, and how many of each prize remains. However, I don't know which prize will be given in one challenge. Therefore, regardless of the order in which the prizes are given, create a program that outputs the minimum number of challenges required for Yae to get two of the same prizes.
input
The input consists of multiple datasets. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format:
N
k1 k2 ... kN
Each dataset has two lines, and the first line is given the integer N (1 β€ N β€ 10000), which indicates how many types of prizes there are. The next line is given the integer ki (0 β€ ki β€ 10000), which indicates how many prizes are left.
The number of datasets does not exceed 100.
output
For each dataset, the minimum number of challenges required to get two identical prizes is output. However, if it is not possible, NA is output.
Example
Input
2
3 2
3
0 1 1
1
1000
0
Output
3
NA
2 | instruction | 0 | 53,841 | 9 | 107,682 |
"Correct Solution:
```
while 1:
n = int(input())
if n == 0:break
k = [x for x in map(int,input().split()) if x >0]
k2 = [x for x in k if x > 1]
if len(k2) > 0:
print(len(k)+1)
else:
print('NA')
``` | output | 1 | 53,841 | 9 | 107,683 |
Provide a correct Python 3 solution for this coding contest problem.
Jou and Yae are a good couple. Jou is collecting prizes for capsule toy vending machines (Gachapon), and even when they go out together, when they find Gachapon, they seem to get so hot that they try it several times. Yae was just looking at Jou, who looked happy, but decided to give him a Gachapon prize for his upcoming birthday present. Yae wasn't very interested in Gachapon itself, but hopefully he would like a match with Jou.
For Gachapon that Yae wants to try, one prize will be given in one challenge. You can see how many types of prizes there are, including those that are out of stock, and how many of each prize remains. However, I don't know which prize will be given in one challenge. Therefore, regardless of the order in which the prizes are given, create a program that outputs the minimum number of challenges required for Yae to get two of the same prizes.
input
The input consists of multiple datasets. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format:
N
k1 k2 ... kN
Each dataset has two lines, and the first line is given the integer N (1 β€ N β€ 10000), which indicates how many types of prizes there are. The next line is given the integer ki (0 β€ ki β€ 10000), which indicates how many prizes are left.
The number of datasets does not exceed 100.
output
For each dataset, the minimum number of challenges required to get two identical prizes is output. However, if it is not possible, NA is output.
Example
Input
2
3 2
3
0 1 1
1
1000
0
Output
3
NA
2 | instruction | 0 | 53,842 | 9 | 107,684 |
"Correct Solution:
```
while True:
n = int(input())
if n ==0:
break
k = list(map(int, input().split()))
if n == 1:
print(2)
elif k.count(0) + k.count(1) == n:
print("NA")
else:
print(n - k.count(0) + 1)
``` | output | 1 | 53,842 | 9 | 107,685 |
Provide a correct Python 3 solution for this coding contest problem.
Jou and Yae are a good couple. Jou is collecting prizes for capsule toy vending machines (Gachapon), and even when they go out together, when they find Gachapon, they seem to get so hot that they try it several times. Yae was just looking at Jou, who looked happy, but decided to give him a Gachapon prize for his upcoming birthday present. Yae wasn't very interested in Gachapon itself, but hopefully he would like a match with Jou.
For Gachapon that Yae wants to try, one prize will be given in one challenge. You can see how many types of prizes there are, including those that are out of stock, and how many of each prize remains. However, I don't know which prize will be given in one challenge. Therefore, regardless of the order in which the prizes are given, create a program that outputs the minimum number of challenges required for Yae to get two of the same prizes.
input
The input consists of multiple datasets. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format:
N
k1 k2 ... kN
Each dataset has two lines, and the first line is given the integer N (1 β€ N β€ 10000), which indicates how many types of prizes there are. The next line is given the integer ki (0 β€ ki β€ 10000), which indicates how many prizes are left.
The number of datasets does not exceed 100.
output
For each dataset, the minimum number of challenges required to get two identical prizes is output. However, if it is not possible, NA is output.
Example
Input
2
3 2
3
0 1 1
1
1000
0
Output
3
NA
2 | instruction | 0 | 53,843 | 9 | 107,686 |
"Correct Solution:
```
while 1:
n=int(input())
if n==0: break
a=list(map(int,input().split()))
if max(a)<2:
print("NA")
continue
print(len([x for x in a if x>0])+1)
``` | output | 1 | 53,843 | 9 | 107,687 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Jou and Yae are a good couple. Jou is collecting prizes for capsule toy vending machines (Gachapon), and even when they go out together, when they find Gachapon, they seem to get so hot that they try it several times. Yae was just looking at Jou, who looked happy, but decided to give him a Gachapon prize for his upcoming birthday present. Yae wasn't very interested in Gachapon itself, but hopefully he would like a match with Jou.
For Gachapon that Yae wants to try, one prize will be given in one challenge. You can see how many types of prizes there are, including those that are out of stock, and how many of each prize remains. However, I don't know which prize will be given in one challenge. Therefore, regardless of the order in which the prizes are given, create a program that outputs the minimum number of challenges required for Yae to get two of the same prizes.
input
The input consists of multiple datasets. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format:
N
k1 k2 ... kN
Each dataset has two lines, and the first line is given the integer N (1 β€ N β€ 10000), which indicates how many types of prizes there are. The next line is given the integer ki (0 β€ ki β€ 10000), which indicates how many prizes are left.
The number of datasets does not exceed 100.
output
For each dataset, the minimum number of challenges required to get two identical prizes is output. However, if it is not possible, NA is output.
Example
Input
2
3 2
3
0 1 1
1
1000
0
Output
3
NA
2
Submitted Solution:
```
# coding: utf-8
# Your code here!
while True:
N = int(input())
if N == 0:
break
nums = [int(i) for i in input().split()]
maxNum = 0
cnt = 0
for i in range(N):
if nums[i] > 0:
cnt = cnt + 1
maxNum = max(nums[i], maxNum)
if maxNum < 2:
print("NA")
else:
print(cnt + 1)
``` | instruction | 0 | 53,845 | 9 | 107,690 |
Yes | output | 1 | 53,845 | 9 | 107,691 |
Provide a correct Python 3 solution for this coding contest problem.
problem
JOI Pizza sells pizza home delivery along the d-meter-long ring road that runs through the city center.
JOI Pizza has n stores S1, ..., Sn on the loop line. The head office is S1. The distance from S1 to Si when moving the loop line clockwise is set to di meters. D2 , ..., dn is an integer greater than or equal to 1 and less than or equal to d -1. D2, ..., dn are all different. Bake and deliver pizza at the shortest store.
The location of the delivery destination is represented by an integer k that is greater than or equal to 0 and less than or equal to d -1. This means that the distance from the head office S1 to the delivery destination in the clockwise direction is k meters. Pizza delivery is done along the loop line and no other road is allowed. However, the loop line may move clockwise or counterclockwise.
For example, if the location of the store and the location of the delivery destination are as shown in the figure below (this example corresponds to Example 1 of "I / O example").
<image>
The store closest to the delivery destination 1 is S2, so the delivery is from store S2. At this time, the distance traveled from the store is 1. Also, the store closest to delivery destination 2 is S1 (main store), so store S1 (main store). ) To deliver to home. At this time, the distance traveled from the store is 2.
Total length of the loop line d, Number of JOI pizza stores n, Number of orders m, N --1 integer representing a location other than the main store d2, ..., dn, Integer k1, .. representing the location of the delivery destination Given ., km, create a program to find the sum of all orders for each order by the distance traveled during delivery (ie, the distance from the nearest store to the delivery destination).
input
The input consists of multiple datasets. Each dataset is given in the following format.
The first line is a positive integer d (2 β€ d β€ 1000000000 = 109) that represents the total length of the loop line, the second line is a positive integer n (2 β€ n β€ 100000) that represents the number of stores, and the third line is A positive integer m (1 β€ m β€ 10000) is written to represent the number of orders. The n --1 lines after the 4th line are integers d2, d3, ..., dn that represent the location of stores other than the main store. (1 β€ di β€ d -1) is written in this order, and the integers k1, k2, ..., km (0 β€ ki β€ d) representing the delivery destination location are in the m lines after the n + 3rd line. --1) are written in this order.
Of the scoring data, for 40% of the points, n β€ 10000 is satisfied. For 40% of the points, the total distance traveled and the value of d are both 1000000 or less. In the scoring data, the total distance traveled is 1000000000 = 109 or less.
When d is 0, it indicates the end of input. The number of data sets does not exceed 10.
output
For each data set, one integer representing the total distance traveled during delivery is output on one line.
Examples
Input
8
3
2
3
1
4
6
20
4
4
12
8
16
7
7
11
8
0
Output
3
3
Input
None
Output
None | instruction | 0 | 53,849 | 9 | 107,698 |
"Correct Solution:
```
read = map(int, open(0).readlines()).__next__
ans = []
while 1:
D = read()
if D == 0:
break
N = read()
M = read()
P = [read() for i in range(N-1)]
P.append(0); P.append(D)
Q = [read() for i in range(M)]
P.sort(); Q.sort()
it = iter(P).__next__
prv = 0; nxt = it(); idx = 0
res = 0
for q in Q:
while nxt <= q:
prv = nxt; nxt = it()
res += min(q - prv, nxt - q)
ans.append("%d\n" % res)
open(1, 'w').writelines(ans)
``` | output | 1 | 53,849 | 9 | 107,699 |
Provide a correct Python 3 solution for this coding contest problem.
problem
JOI Pizza sells pizza home delivery along the d-meter-long ring road that runs through the city center.
JOI Pizza has n stores S1, ..., Sn on the loop line. The head office is S1. The distance from S1 to Si when moving the loop line clockwise is set to di meters. D2 , ..., dn is an integer greater than or equal to 1 and less than or equal to d -1. D2, ..., dn are all different. Bake and deliver pizza at the shortest store.
The location of the delivery destination is represented by an integer k that is greater than or equal to 0 and less than or equal to d -1. This means that the distance from the head office S1 to the delivery destination in the clockwise direction is k meters. Pizza delivery is done along the loop line and no other road is allowed. However, the loop line may move clockwise or counterclockwise.
For example, if the location of the store and the location of the delivery destination are as shown in the figure below (this example corresponds to Example 1 of "I / O example").
<image>
The store closest to the delivery destination 1 is S2, so the delivery is from store S2. At this time, the distance traveled from the store is 1. Also, the store closest to delivery destination 2 is S1 (main store), so store S1 (main store). ) To deliver to home. At this time, the distance traveled from the store is 2.
Total length of the loop line d, Number of JOI pizza stores n, Number of orders m, N --1 integer representing a location other than the main store d2, ..., dn, Integer k1, .. representing the location of the delivery destination Given ., km, create a program to find the sum of all orders for each order by the distance traveled during delivery (ie, the distance from the nearest store to the delivery destination).
input
The input consists of multiple datasets. Each dataset is given in the following format.
The first line is a positive integer d (2 β€ d β€ 1000000000 = 109) that represents the total length of the loop line, the second line is a positive integer n (2 β€ n β€ 100000) that represents the number of stores, and the third line is A positive integer m (1 β€ m β€ 10000) is written to represent the number of orders. The n --1 lines after the 4th line are integers d2, d3, ..., dn that represent the location of stores other than the main store. (1 β€ di β€ d -1) is written in this order, and the integers k1, k2, ..., km (0 β€ ki β€ d) representing the delivery destination location are in the m lines after the n + 3rd line. --1) are written in this order.
Of the scoring data, for 40% of the points, n β€ 10000 is satisfied. For 40% of the points, the total distance traveled and the value of d are both 1000000 or less. In the scoring data, the total distance traveled is 1000000000 = 109 or less.
When d is 0, it indicates the end of input. The number of data sets does not exceed 10.
output
For each data set, one integer representing the total distance traveled during delivery is output on one line.
Examples
Input
8
3
2
3
1
4
6
20
4
4
12
8
16
7
7
11
8
0
Output
3
3
Input
None
Output
None | instruction | 0 | 53,850 | 9 | 107,700 |
"Correct Solution:
```
import bisect
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
def solve():
d = int(input())
if d == 0:
return False
n = int(input())
m = int(input())
stores = [int(input()) for _ in range(n-1)]
stores = [0]+sorted(stores)+[d]
ret = 0
for _ in range(m):
dest = int(input())
l = bisect.bisect_right(stores, dest)
dist = min(stores[l]-dest, dest-stores[l-1])
ret += dist
return ret
ans = []
while True:
a = solve()
if a:
ans.append(a)
else:
break
print("\n".join(map(str, ans)))
``` | output | 1 | 53,850 | 9 | 107,701 |
Provide a correct Python 3 solution for this coding contest problem.
problem
JOI Pizza sells pizza home delivery along the d-meter-long ring road that runs through the city center.
JOI Pizza has n stores S1, ..., Sn on the loop line. The head office is S1. The distance from S1 to Si when moving the loop line clockwise is set to di meters. D2 , ..., dn is an integer greater than or equal to 1 and less than or equal to d -1. D2, ..., dn are all different. Bake and deliver pizza at the shortest store.
The location of the delivery destination is represented by an integer k that is greater than or equal to 0 and less than or equal to d -1. This means that the distance from the head office S1 to the delivery destination in the clockwise direction is k meters. Pizza delivery is done along the loop line and no other road is allowed. However, the loop line may move clockwise or counterclockwise.
For example, if the location of the store and the location of the delivery destination are as shown in the figure below (this example corresponds to Example 1 of "I / O example").
<image>
The store closest to the delivery destination 1 is S2, so the delivery is from store S2. At this time, the distance traveled from the store is 1. Also, the store closest to delivery destination 2 is S1 (main store), so store S1 (main store). ) To deliver to home. At this time, the distance traveled from the store is 2.
Total length of the loop line d, Number of JOI pizza stores n, Number of orders m, N --1 integer representing a location other than the main store d2, ..., dn, Integer k1, .. representing the location of the delivery destination Given ., km, create a program to find the sum of all orders for each order by the distance traveled during delivery (ie, the distance from the nearest store to the delivery destination).
input
The input consists of multiple datasets. Each dataset is given in the following format.
The first line is a positive integer d (2 β€ d β€ 1000000000 = 109) that represents the total length of the loop line, the second line is a positive integer n (2 β€ n β€ 100000) that represents the number of stores, and the third line is A positive integer m (1 β€ m β€ 10000) is written to represent the number of orders. The n --1 lines after the 4th line are integers d2, d3, ..., dn that represent the location of stores other than the main store. (1 β€ di β€ d -1) is written in this order, and the integers k1, k2, ..., km (0 β€ ki β€ d) representing the delivery destination location are in the m lines after the n + 3rd line. --1) are written in this order.
Of the scoring data, for 40% of the points, n β€ 10000 is satisfied. For 40% of the points, the total distance traveled and the value of d are both 1000000 or less. In the scoring data, the total distance traveled is 1000000000 = 109 or less.
When d is 0, it indicates the end of input. The number of data sets does not exceed 10.
output
For each data set, one integer representing the total distance traveled during delivery is output on one line.
Examples
Input
8
3
2
3
1
4
6
20
4
4
12
8
16
7
7
11
8
0
Output
3
3
Input
None
Output
None | instruction | 0 | 53,851 | 9 | 107,702 |
"Correct Solution:
```
import bisect
while True:
len_d = int(input())
if len_d == 0: break
n = int(input())
m = int(input())
d = [0]
k = []
for i in range(1, n):
d.append(int(input()))
for i in range(m):
k.append(int(input()))
d.sort()
c = [len_d for i in range(m)]
ans = 0
for i in range(m):
if k[i] == 0: continue
t = bisect.bisect_left(d, k[i])
if t == n:
ans += min(len_d-k[i], k[i]-d[n-1])
else:
ans += min(k[i]-d[t-1], d[t]-k[i])
print(ans)
``` | output | 1 | 53,851 | 9 | 107,703 |
Provide a correct Python 3 solution for this coding contest problem.
problem
JOI Pizza sells pizza home delivery along the d-meter-long ring road that runs through the city center.
JOI Pizza has n stores S1, ..., Sn on the loop line. The head office is S1. The distance from S1 to Si when moving the loop line clockwise is set to di meters. D2 , ..., dn is an integer greater than or equal to 1 and less than or equal to d -1. D2, ..., dn are all different. Bake and deliver pizza at the shortest store.
The location of the delivery destination is represented by an integer k that is greater than or equal to 0 and less than or equal to d -1. This means that the distance from the head office S1 to the delivery destination in the clockwise direction is k meters. Pizza delivery is done along the loop line and no other road is allowed. However, the loop line may move clockwise or counterclockwise.
For example, if the location of the store and the location of the delivery destination are as shown in the figure below (this example corresponds to Example 1 of "I / O example").
<image>
The store closest to the delivery destination 1 is S2, so the delivery is from store S2. At this time, the distance traveled from the store is 1. Also, the store closest to delivery destination 2 is S1 (main store), so store S1 (main store). ) To deliver to home. At this time, the distance traveled from the store is 2.
Total length of the loop line d, Number of JOI pizza stores n, Number of orders m, N --1 integer representing a location other than the main store d2, ..., dn, Integer k1, .. representing the location of the delivery destination Given ., km, create a program to find the sum of all orders for each order by the distance traveled during delivery (ie, the distance from the nearest store to the delivery destination).
input
The input consists of multiple datasets. Each dataset is given in the following format.
The first line is a positive integer d (2 β€ d β€ 1000000000 = 109) that represents the total length of the loop line, the second line is a positive integer n (2 β€ n β€ 100000) that represents the number of stores, and the third line is A positive integer m (1 β€ m β€ 10000) is written to represent the number of orders. The n --1 lines after the 4th line are integers d2, d3, ..., dn that represent the location of stores other than the main store. (1 β€ di β€ d -1) is written in this order, and the integers k1, k2, ..., km (0 β€ ki β€ d) representing the delivery destination location are in the m lines after the n + 3rd line. --1) are written in this order.
Of the scoring data, for 40% of the points, n β€ 10000 is satisfied. For 40% of the points, the total distance traveled and the value of d are both 1000000 or less. In the scoring data, the total distance traveled is 1000000000 = 109 or less.
When d is 0, it indicates the end of input. The number of data sets does not exceed 10.
output
For each data set, one integer representing the total distance traveled during delivery is output on one line.
Examples
Input
8
3
2
3
1
4
6
20
4
4
12
8
16
7
7
11
8
0
Output
3
3
Input
None
Output
None | instruction | 0 | 53,852 | 9 | 107,704 |
"Correct Solution:
```
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0539
"""
import sys
from sys import stdin
from bisect import bisect_right
input = stdin.readline
def main(args):
while True:
d = int(input()) # ??Β°??ΒΆ????????????
if d == 0:
break
n = int(input()) # ??Β¬????????????????????Β°
m = int(input()) # ??Β¨????????Β°
cw_pos = [int(input()) for _ in range(n-1)]
dests = [int(input()) for _ in range(m)]
cw_pos.append(0)
cw_pos.append(d)
cw_pos.sort()
ccw_pos = [d-x for x in cw_pos]
ccw_pos.sort()
total_distance = 0
for t in dests:
if t == 0:
continue
i = bisect_right(cw_pos, t)
a1 = min(t-cw_pos[i-1], cw_pos[i]-t)
j = bisect_right(ccw_pos, d-t)
a2 = min(d-t-ccw_pos[j-1], ccw_pos[j]-(d-t))
ans = min(a1, a2)
total_distance += ans
print(total_distance)
if __name__ == '__main__':
main(sys.argv[1:])
``` | output | 1 | 53,852 | 9 | 107,705 |
Provide a correct Python 3 solution for this coding contest problem.
problem
JOI Pizza sells pizza home delivery along the d-meter-long ring road that runs through the city center.
JOI Pizza has n stores S1, ..., Sn on the loop line. The head office is S1. The distance from S1 to Si when moving the loop line clockwise is set to di meters. D2 , ..., dn is an integer greater than or equal to 1 and less than or equal to d -1. D2, ..., dn are all different. Bake and deliver pizza at the shortest store.
The location of the delivery destination is represented by an integer k that is greater than or equal to 0 and less than or equal to d -1. This means that the distance from the head office S1 to the delivery destination in the clockwise direction is k meters. Pizza delivery is done along the loop line and no other road is allowed. However, the loop line may move clockwise or counterclockwise.
For example, if the location of the store and the location of the delivery destination are as shown in the figure below (this example corresponds to Example 1 of "I / O example").
<image>
The store closest to the delivery destination 1 is S2, so the delivery is from store S2. At this time, the distance traveled from the store is 1. Also, the store closest to delivery destination 2 is S1 (main store), so store S1 (main store). ) To deliver to home. At this time, the distance traveled from the store is 2.
Total length of the loop line d, Number of JOI pizza stores n, Number of orders m, N --1 integer representing a location other than the main store d2, ..., dn, Integer k1, .. representing the location of the delivery destination Given ., km, create a program to find the sum of all orders for each order by the distance traveled during delivery (ie, the distance from the nearest store to the delivery destination).
input
The input consists of multiple datasets. Each dataset is given in the following format.
The first line is a positive integer d (2 β€ d β€ 1000000000 = 109) that represents the total length of the loop line, the second line is a positive integer n (2 β€ n β€ 100000) that represents the number of stores, and the third line is A positive integer m (1 β€ m β€ 10000) is written to represent the number of orders. The n --1 lines after the 4th line are integers d2, d3, ..., dn that represent the location of stores other than the main store. (1 β€ di β€ d -1) is written in this order, and the integers k1, k2, ..., km (0 β€ ki β€ d) representing the delivery destination location are in the m lines after the n + 3rd line. --1) are written in this order.
Of the scoring data, for 40% of the points, n β€ 10000 is satisfied. For 40% of the points, the total distance traveled and the value of d are both 1000000 or less. In the scoring data, the total distance traveled is 1000000000 = 109 or less.
When d is 0, it indicates the end of input. The number of data sets does not exceed 10.
output
For each data set, one integer representing the total distance traveled during delivery is output on one line.
Examples
Input
8
3
2
3
1
4
6
20
4
4
12
8
16
7
7
11
8
0
Output
3
3
Input
None
Output
None | instruction | 0 | 53,853 | 9 | 107,706 |
"Correct Solution:
```
while True:
D = int(input())
if D==0: exit()
N = int(input())
M = int(input())
shops = [0]
for _ in range(N-1):
shops.append(int(input()))
shops.append(D)
shops.sort()
res = 0
for _ in range(M):
x = int(input())
ok,ng = -1,len(shops)
while abs(ok-ng)>1:
mid = (ok+ng)//2
if shops[mid] <= x:
ok = mid
else:
ng = mid
res += min(x-shops[ok], shops[ok+1]-x)
print(res)
``` | output | 1 | 53,853 | 9 | 107,707 |
Provide a correct Python 3 solution for this coding contest problem.
problem
JOI Pizza sells pizza home delivery along the d-meter-long ring road that runs through the city center.
JOI Pizza has n stores S1, ..., Sn on the loop line. The head office is S1. The distance from S1 to Si when moving the loop line clockwise is set to di meters. D2 , ..., dn is an integer greater than or equal to 1 and less than or equal to d -1. D2, ..., dn are all different. Bake and deliver pizza at the shortest store.
The location of the delivery destination is represented by an integer k that is greater than or equal to 0 and less than or equal to d -1. This means that the distance from the head office S1 to the delivery destination in the clockwise direction is k meters. Pizza delivery is done along the loop line and no other road is allowed. However, the loop line may move clockwise or counterclockwise.
For example, if the location of the store and the location of the delivery destination are as shown in the figure below (this example corresponds to Example 1 of "I / O example").
<image>
The store closest to the delivery destination 1 is S2, so the delivery is from store S2. At this time, the distance traveled from the store is 1. Also, the store closest to delivery destination 2 is S1 (main store), so store S1 (main store). ) To deliver to home. At this time, the distance traveled from the store is 2.
Total length of the loop line d, Number of JOI pizza stores n, Number of orders m, N --1 integer representing a location other than the main store d2, ..., dn, Integer k1, .. representing the location of the delivery destination Given ., km, create a program to find the sum of all orders for each order by the distance traveled during delivery (ie, the distance from the nearest store to the delivery destination).
input
The input consists of multiple datasets. Each dataset is given in the following format.
The first line is a positive integer d (2 β€ d β€ 1000000000 = 109) that represents the total length of the loop line, the second line is a positive integer n (2 β€ n β€ 100000) that represents the number of stores, and the third line is A positive integer m (1 β€ m β€ 10000) is written to represent the number of orders. The n --1 lines after the 4th line are integers d2, d3, ..., dn that represent the location of stores other than the main store. (1 β€ di β€ d -1) is written in this order, and the integers k1, k2, ..., km (0 β€ ki β€ d) representing the delivery destination location are in the m lines after the n + 3rd line. --1) are written in this order.
Of the scoring data, for 40% of the points, n β€ 10000 is satisfied. For 40% of the points, the total distance traveled and the value of d are both 1000000 or less. In the scoring data, the total distance traveled is 1000000000 = 109 or less.
When d is 0, it indicates the end of input. The number of data sets does not exceed 10.
output
For each data set, one integer representing the total distance traveled during delivery is output on one line.
Examples
Input
8
3
2
3
1
4
6
20
4
4
12
8
16
7
7
11
8
0
Output
3
3
Input
None
Output
None | instruction | 0 | 53,854 | 9 | 107,708 |
"Correct Solution:
```
import bisect
def main():
while True:
D=int(input())
if D==0:
break
n=int(input())
m=int(input())
d=list()
d.append(0)
for i in range(n-1):
d.append(int(input()))
d.append(D)
d.sort()
ans=0
for i in range(m):
k=int(input())
idx=bisect.bisect_left(d,k)
ans+=min(abs(d[idx]-k),abs(d[idx-1]-k))
print(ans)
if __name__=="__main__":
main()
``` | output | 1 | 53,854 | 9 | 107,709 |
Provide a correct Python 3 solution for this coding contest problem.
problem
JOI Pizza sells pizza home delivery along the d-meter-long ring road that runs through the city center.
JOI Pizza has n stores S1, ..., Sn on the loop line. The head office is S1. The distance from S1 to Si when moving the loop line clockwise is set to di meters. D2 , ..., dn is an integer greater than or equal to 1 and less than or equal to d -1. D2, ..., dn are all different. Bake and deliver pizza at the shortest store.
The location of the delivery destination is represented by an integer k that is greater than or equal to 0 and less than or equal to d -1. This means that the distance from the head office S1 to the delivery destination in the clockwise direction is k meters. Pizza delivery is done along the loop line and no other road is allowed. However, the loop line may move clockwise or counterclockwise.
For example, if the location of the store and the location of the delivery destination are as shown in the figure below (this example corresponds to Example 1 of "I / O example").
<image>
The store closest to the delivery destination 1 is S2, so the delivery is from store S2. At this time, the distance traveled from the store is 1. Also, the store closest to delivery destination 2 is S1 (main store), so store S1 (main store). ) To deliver to home. At this time, the distance traveled from the store is 2.
Total length of the loop line d, Number of JOI pizza stores n, Number of orders m, N --1 integer representing a location other than the main store d2, ..., dn, Integer k1, .. representing the location of the delivery destination Given ., km, create a program to find the sum of all orders for each order by the distance traveled during delivery (ie, the distance from the nearest store to the delivery destination).
input
The input consists of multiple datasets. Each dataset is given in the following format.
The first line is a positive integer d (2 β€ d β€ 1000000000 = 109) that represents the total length of the loop line, the second line is a positive integer n (2 β€ n β€ 100000) that represents the number of stores, and the third line is A positive integer m (1 β€ m β€ 10000) is written to represent the number of orders. The n --1 lines after the 4th line are integers d2, d3, ..., dn that represent the location of stores other than the main store. (1 β€ di β€ d -1) is written in this order, and the integers k1, k2, ..., km (0 β€ ki β€ d) representing the delivery destination location are in the m lines after the n + 3rd line. --1) are written in this order.
Of the scoring data, for 40% of the points, n β€ 10000 is satisfied. For 40% of the points, the total distance traveled and the value of d are both 1000000 or less. In the scoring data, the total distance traveled is 1000000000 = 109 or less.
When d is 0, it indicates the end of input. The number of data sets does not exceed 10.
output
For each data set, one integer representing the total distance traveled during delivery is output on one line.
Examples
Input
8
3
2
3
1
4
6
20
4
4
12
8
16
7
7
11
8
0
Output
3
3
Input
None
Output
None | instruction | 0 | 53,855 | 9 | 107,710 |
"Correct Solution:
```
from bisect import bisect_left
while True:
d = int(input())
if not d:
break
n = int(input())
m = int(input())
stores = {0, d}
for i in range(2, n + 1):
stores.add(int(input()))
sorted_stores = sorted(stores)
total_dist = 0
while m:
k = int(input())
i = bisect_left(sorted_stores, k)
if i:
l, r = sorted_stores[i - 1:i + 1]
total_dist += min(k - l, r - k)
m -= 1
print(total_dist)
``` | output | 1 | 53,855 | 9 | 107,711 |
Provide a correct Python 3 solution for this coding contest problem.
problem
JOI Pizza sells pizza home delivery along the d-meter-long ring road that runs through the city center.
JOI Pizza has n stores S1, ..., Sn on the loop line. The head office is S1. The distance from S1 to Si when moving the loop line clockwise is set to di meters. D2 , ..., dn is an integer greater than or equal to 1 and less than or equal to d -1. D2, ..., dn are all different. Bake and deliver pizza at the shortest store.
The location of the delivery destination is represented by an integer k that is greater than or equal to 0 and less than or equal to d -1. This means that the distance from the head office S1 to the delivery destination in the clockwise direction is k meters. Pizza delivery is done along the loop line and no other road is allowed. However, the loop line may move clockwise or counterclockwise.
For example, if the location of the store and the location of the delivery destination are as shown in the figure below (this example corresponds to Example 1 of "I / O example").
<image>
The store closest to the delivery destination 1 is S2, so the delivery is from store S2. At this time, the distance traveled from the store is 1. Also, the store closest to delivery destination 2 is S1 (main store), so store S1 (main store). ) To deliver to home. At this time, the distance traveled from the store is 2.
Total length of the loop line d, Number of JOI pizza stores n, Number of orders m, N --1 integer representing a location other than the main store d2, ..., dn, Integer k1, .. representing the location of the delivery destination Given ., km, create a program to find the sum of all orders for each order by the distance traveled during delivery (ie, the distance from the nearest store to the delivery destination).
input
The input consists of multiple datasets. Each dataset is given in the following format.
The first line is a positive integer d (2 β€ d β€ 1000000000 = 109) that represents the total length of the loop line, the second line is a positive integer n (2 β€ n β€ 100000) that represents the number of stores, and the third line is A positive integer m (1 β€ m β€ 10000) is written to represent the number of orders. The n --1 lines after the 4th line are integers d2, d3, ..., dn that represent the location of stores other than the main store. (1 β€ di β€ d -1) is written in this order, and the integers k1, k2, ..., km (0 β€ ki β€ d) representing the delivery destination location are in the m lines after the n + 3rd line. --1) are written in this order.
Of the scoring data, for 40% of the points, n β€ 10000 is satisfied. For 40% of the points, the total distance traveled and the value of d are both 1000000 or less. In the scoring data, the total distance traveled is 1000000000 = 109 or less.
When d is 0, it indicates the end of input. The number of data sets does not exceed 10.
output
For each data set, one integer representing the total distance traveled during delivery is output on one line.
Examples
Input
8
3
2
3
1
4
6
20
4
4
12
8
16
7
7
11
8
0
Output
3
3
Input
None
Output
None | instruction | 0 | 53,856 | 9 | 107,712 |
"Correct Solution:
```
import bisect
while True:
d = int(input())
if d==0: break
n = int(input())
m = int(input())
shops = [0]*n
for i in range(1,n):
shops[i] = int(input())
shops.sort()
shops.append(d)
d = 0
for i in range(m):
cus = int(input())
req = bisect.bisect(shops,cus)
d += min(abs(cus-shops[req-1]), abs(cus-shops[req]))
print(d)
``` | output | 1 | 53,856 | 9 | 107,713 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
JOI Pizza sells pizza home delivery along the d-meter-long ring road that runs through the city center.
JOI Pizza has n stores S1, ..., Sn on the loop line. The head office is S1. The distance from S1 to Si when moving the loop line clockwise is set to di meters. D2 , ..., dn is an integer greater than or equal to 1 and less than or equal to d -1. D2, ..., dn are all different. Bake and deliver pizza at the shortest store.
The location of the delivery destination is represented by an integer k that is greater than or equal to 0 and less than or equal to d -1. This means that the distance from the head office S1 to the delivery destination in the clockwise direction is k meters. Pizza delivery is done along the loop line and no other road is allowed. However, the loop line may move clockwise or counterclockwise.
For example, if the location of the store and the location of the delivery destination are as shown in the figure below (this example corresponds to Example 1 of "I / O example").
<image>
The store closest to the delivery destination 1 is S2, so the delivery is from store S2. At this time, the distance traveled from the store is 1. Also, the store closest to delivery destination 2 is S1 (main store), so store S1 (main store). ) To deliver to home. At this time, the distance traveled from the store is 2.
Total length of the loop line d, Number of JOI pizza stores n, Number of orders m, N --1 integer representing a location other than the main store d2, ..., dn, Integer k1, .. representing the location of the delivery destination Given ., km, create a program to find the sum of all orders for each order by the distance traveled during delivery (ie, the distance from the nearest store to the delivery destination).
input
The input consists of multiple datasets. Each dataset is given in the following format.
The first line is a positive integer d (2 β€ d β€ 1000000000 = 109) that represents the total length of the loop line, the second line is a positive integer n (2 β€ n β€ 100000) that represents the number of stores, and the third line is A positive integer m (1 β€ m β€ 10000) is written to represent the number of orders. The n --1 lines after the 4th line are integers d2, d3, ..., dn that represent the location of stores other than the main store. (1 β€ di β€ d -1) is written in this order, and the integers k1, k2, ..., km (0 β€ ki β€ d) representing the delivery destination location are in the m lines after the n + 3rd line. --1) are written in this order.
Of the scoring data, for 40% of the points, n β€ 10000 is satisfied. For 40% of the points, the total distance traveled and the value of d are both 1000000 or less. In the scoring data, the total distance traveled is 1000000000 = 109 or less.
When d is 0, it indicates the end of input. The number of data sets does not exceed 10.
output
For each data set, one integer representing the total distance traveled during delivery is output on one line.
Examples
Input
8
3
2
3
1
4
6
20
4
4
12
8
16
7
7
11
8
0
Output
3
3
Input
None
Output
None
Submitted Solution:
```
# AOJ 0539: Pizza
# Python3 2018.7.1 bal4u
import sys
from sys import stdin
input = stdin.readline
import bisect
while True:
d = int(input())
if d == 0: break
n, m = int(input()), int(input())
p = [0] + [int(input()) for i in range(n-1)] + [d]
p.sort()
ans = 0
for i in range(m):
k = int(input())
if k > 0:
t = bisect.bisect_left(p, k)
ans += min(k-p[t-1], p[t]-k)
print(ans)
``` | instruction | 0 | 53,857 | 9 | 107,714 |
Yes | output | 1 | 53,857 | 9 | 107,715 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
JOI Pizza sells pizza home delivery along the d-meter-long ring road that runs through the city center.
JOI Pizza has n stores S1, ..., Sn on the loop line. The head office is S1. The distance from S1 to Si when moving the loop line clockwise is set to di meters. D2 , ..., dn is an integer greater than or equal to 1 and less than or equal to d -1. D2, ..., dn are all different. Bake and deliver pizza at the shortest store.
The location of the delivery destination is represented by an integer k that is greater than or equal to 0 and less than or equal to d -1. This means that the distance from the head office S1 to the delivery destination in the clockwise direction is k meters. Pizza delivery is done along the loop line and no other road is allowed. However, the loop line may move clockwise or counterclockwise.
For example, if the location of the store and the location of the delivery destination are as shown in the figure below (this example corresponds to Example 1 of "I / O example").
<image>
The store closest to the delivery destination 1 is S2, so the delivery is from store S2. At this time, the distance traveled from the store is 1. Also, the store closest to delivery destination 2 is S1 (main store), so store S1 (main store). ) To deliver to home. At this time, the distance traveled from the store is 2.
Total length of the loop line d, Number of JOI pizza stores n, Number of orders m, N --1 integer representing a location other than the main store d2, ..., dn, Integer k1, .. representing the location of the delivery destination Given ., km, create a program to find the sum of all orders for each order by the distance traveled during delivery (ie, the distance from the nearest store to the delivery destination).
input
The input consists of multiple datasets. Each dataset is given in the following format.
The first line is a positive integer d (2 β€ d β€ 1000000000 = 109) that represents the total length of the loop line, the second line is a positive integer n (2 β€ n β€ 100000) that represents the number of stores, and the third line is A positive integer m (1 β€ m β€ 10000) is written to represent the number of orders. The n --1 lines after the 4th line are integers d2, d3, ..., dn that represent the location of stores other than the main store. (1 β€ di β€ d -1) is written in this order, and the integers k1, k2, ..., km (0 β€ ki β€ d) representing the delivery destination location are in the m lines after the n + 3rd line. --1) are written in this order.
Of the scoring data, for 40% of the points, n β€ 10000 is satisfied. For 40% of the points, the total distance traveled and the value of d are both 1000000 or less. In the scoring data, the total distance traveled is 1000000000 = 109 or less.
When d is 0, it indicates the end of input. The number of data sets does not exceed 10.
output
For each data set, one integer representing the total distance traveled during delivery is output on one line.
Examples
Input
8
3
2
3
1
4
6
20
4
4
12
8
16
7
7
11
8
0
Output
3
3
Input
None
Output
None
Submitted Solution:
```
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0539
AC
"""
import sys
from sys import stdin
from bisect import bisect_right
input = stdin.readline
def main(args):
while True:
d = int(input()) # ??Β°??ΒΆ????????????
if d == 0:
break
n = int(input()) # ??Β¬????????????????????Β°
m = int(input()) # ??Β¨????????Β°
cw_pos = [int(input()) for _ in range(n-1)]
dests = [int(input()) for _ in range(m)]
cw_pos.append(0) # ??Β¬????????????
cw_pos.append(d) # ??Β°??ΒΆ??????1??Β¨??????????????Β¬????????????(??????)
cw_pos.sort()
# ccw_pos = [d-x for x in cw_pos] # ??Β°??ΒΆ?????????????????Β£????????????????????????
# ccw_pos.sort()
total_distance = 0
for t in dests:
if t == 0: # ?????????????????????0?????\??Β£????????????bisect_right?????Β¨????????????????????Β§??????
continue
i = bisect_right(cw_pos, t) # ????Β¨?????????Β§??????????????????
a1 = min(t-cw_pos[i-1], cw_pos[i]-t) # ?????????????????????????????Β’
# j = bisect_right(ccw_pos, d-t) # ???????Β¨?????????Β§???????????Β¨?????????
# a2 = min(d-t-ccw_pos[j-1], ccw_pos[j]-(d-t))
# ans = min(a1, a2)
total_distance += a1 # ?????????????????????????????Β°OK
print(total_distance)
if __name__ == '__main__':
main(sys.argv[1:])
``` | instruction | 0 | 53,858 | 9 | 107,716 |
Yes | output | 1 | 53,858 | 9 | 107,717 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
JOI Pizza sells pizza home delivery along the d-meter-long ring road that runs through the city center.
JOI Pizza has n stores S1, ..., Sn on the loop line. The head office is S1. The distance from S1 to Si when moving the loop line clockwise is set to di meters. D2 , ..., dn is an integer greater than or equal to 1 and less than or equal to d -1. D2, ..., dn are all different. Bake and deliver pizza at the shortest store.
The location of the delivery destination is represented by an integer k that is greater than or equal to 0 and less than or equal to d -1. This means that the distance from the head office S1 to the delivery destination in the clockwise direction is k meters. Pizza delivery is done along the loop line and no other road is allowed. However, the loop line may move clockwise or counterclockwise.
For example, if the location of the store and the location of the delivery destination are as shown in the figure below (this example corresponds to Example 1 of "I / O example").
<image>
The store closest to the delivery destination 1 is S2, so the delivery is from store S2. At this time, the distance traveled from the store is 1. Also, the store closest to delivery destination 2 is S1 (main store), so store S1 (main store). ) To deliver to home. At this time, the distance traveled from the store is 2.
Total length of the loop line d, Number of JOI pizza stores n, Number of orders m, N --1 integer representing a location other than the main store d2, ..., dn, Integer k1, .. representing the location of the delivery destination Given ., km, create a program to find the sum of all orders for each order by the distance traveled during delivery (ie, the distance from the nearest store to the delivery destination).
input
The input consists of multiple datasets. Each dataset is given in the following format.
The first line is a positive integer d (2 β€ d β€ 1000000000 = 109) that represents the total length of the loop line, the second line is a positive integer n (2 β€ n β€ 100000) that represents the number of stores, and the third line is A positive integer m (1 β€ m β€ 10000) is written to represent the number of orders. The n --1 lines after the 4th line are integers d2, d3, ..., dn that represent the location of stores other than the main store. (1 β€ di β€ d -1) is written in this order, and the integers k1, k2, ..., km (0 β€ ki β€ d) representing the delivery destination location are in the m lines after the n + 3rd line. --1) are written in this order.
Of the scoring data, for 40% of the points, n β€ 10000 is satisfied. For 40% of the points, the total distance traveled and the value of d are both 1000000 or less. In the scoring data, the total distance traveled is 1000000000 = 109 or less.
When d is 0, it indicates the end of input. The number of data sets does not exceed 10.
output
For each data set, one integer representing the total distance traveled during delivery is output on one line.
Examples
Input
8
3
2
3
1
4
6
20
4
4
12
8
16
7
7
11
8
0
Output
3
3
Input
None
Output
None
Submitted Solution:
```
import sys
file_input = sys.stdin
d = int(file_input.readline())
import bisect
def calc_distance(destination):
p = bisect.bisect(shop, destination)
d1 = shop[p] - destination
d2 = destination - shop[p - 1]
return min(d1, d2)
while d:
n = int(file_input.readline())
m = int(file_input.readline())
shop = [int(file_input.readline()) for i in range(n - 1)]
shop.append(0)
shop.append(d)
shop.sort()
k = (int(file_input.readline()) for i in range(m))
ans = sum(map(calc_distance, k))
print(ans)
d = int(file_input.readline())
``` | instruction | 0 | 53,859 | 9 | 107,718 |
Yes | output | 1 | 53,859 | 9 | 107,719 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
JOI Pizza sells pizza home delivery along the d-meter-long ring road that runs through the city center.
JOI Pizza has n stores S1, ..., Sn on the loop line. The head office is S1. The distance from S1 to Si when moving the loop line clockwise is set to di meters. D2 , ..., dn is an integer greater than or equal to 1 and less than or equal to d -1. D2, ..., dn are all different. Bake and deliver pizza at the shortest store.
The location of the delivery destination is represented by an integer k that is greater than or equal to 0 and less than or equal to d -1. This means that the distance from the head office S1 to the delivery destination in the clockwise direction is k meters. Pizza delivery is done along the loop line and no other road is allowed. However, the loop line may move clockwise or counterclockwise.
For example, if the location of the store and the location of the delivery destination are as shown in the figure below (this example corresponds to Example 1 of "I / O example").
<image>
The store closest to the delivery destination 1 is S2, so the delivery is from store S2. At this time, the distance traveled from the store is 1. Also, the store closest to delivery destination 2 is S1 (main store), so store S1 (main store). ) To deliver to home. At this time, the distance traveled from the store is 2.
Total length of the loop line d, Number of JOI pizza stores n, Number of orders m, N --1 integer representing a location other than the main store d2, ..., dn, Integer k1, .. representing the location of the delivery destination Given ., km, create a program to find the sum of all orders for each order by the distance traveled during delivery (ie, the distance from the nearest store to the delivery destination).
input
The input consists of multiple datasets. Each dataset is given in the following format.
The first line is a positive integer d (2 β€ d β€ 1000000000 = 109) that represents the total length of the loop line, the second line is a positive integer n (2 β€ n β€ 100000) that represents the number of stores, and the third line is A positive integer m (1 β€ m β€ 10000) is written to represent the number of orders. The n --1 lines after the 4th line are integers d2, d3, ..., dn that represent the location of stores other than the main store. (1 β€ di β€ d -1) is written in this order, and the integers k1, k2, ..., km (0 β€ ki β€ d) representing the delivery destination location are in the m lines after the n + 3rd line. --1) are written in this order.
Of the scoring data, for 40% of the points, n β€ 10000 is satisfied. For 40% of the points, the total distance traveled and the value of d are both 1000000 or less. In the scoring data, the total distance traveled is 1000000000 = 109 or less.
When d is 0, it indicates the end of input. The number of data sets does not exceed 10.
output
For each data set, one integer representing the total distance traveled during delivery is output on one line.
Examples
Input
8
3
2
3
1
4
6
20
4
4
12
8
16
7
7
11
8
0
Output
3
3
Input
None
Output
None
Submitted Solution:
```
import bisect
def main():
while True:
d = int(input())
if d == 0:
break
n = int(input())
m = int(input())
s = [0] + [int(input()) for i in range(n - 1)] + [d]
s.sort()
print(sum(dist(s, int(input())) for i in range(m)))
def dist(s, o):
return min(o- s[bisect.bisect_right(s, o) - 1], s[bisect.bisect_left(s,o)] - o)
if __name__=="__main__":
main()
``` | instruction | 0 | 53,860 | 9 | 107,720 |
Yes | output | 1 | 53,860 | 9 | 107,721 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
JOI Pizza sells pizza home delivery along the d-meter-long ring road that runs through the city center.
JOI Pizza has n stores S1, ..., Sn on the loop line. The head office is S1. The distance from S1 to Si when moving the loop line clockwise is set to di meters. D2 , ..., dn is an integer greater than or equal to 1 and less than or equal to d -1. D2, ..., dn are all different. Bake and deliver pizza at the shortest store.
The location of the delivery destination is represented by an integer k that is greater than or equal to 0 and less than or equal to d -1. This means that the distance from the head office S1 to the delivery destination in the clockwise direction is k meters. Pizza delivery is done along the loop line and no other road is allowed. However, the loop line may move clockwise or counterclockwise.
For example, if the location of the store and the location of the delivery destination are as shown in the figure below (this example corresponds to Example 1 of "I / O example").
<image>
The store closest to the delivery destination 1 is S2, so the delivery is from store S2. At this time, the distance traveled from the store is 1. Also, the store closest to delivery destination 2 is S1 (main store), so store S1 (main store). ) To deliver to home. At this time, the distance traveled from the store is 2.
Total length of the loop line d, Number of JOI pizza stores n, Number of orders m, N --1 integer representing a location other than the main store d2, ..., dn, Integer k1, .. representing the location of the delivery destination Given ., km, create a program to find the sum of all orders for each order by the distance traveled during delivery (ie, the distance from the nearest store to the delivery destination).
input
The input consists of multiple datasets. Each dataset is given in the following format.
The first line is a positive integer d (2 β€ d β€ 1000000000 = 109) that represents the total length of the loop line, the second line is a positive integer n (2 β€ n β€ 100000) that represents the number of stores, and the third line is A positive integer m (1 β€ m β€ 10000) is written to represent the number of orders. The n --1 lines after the 4th line are integers d2, d3, ..., dn that represent the location of stores other than the main store. (1 β€ di β€ d -1) is written in this order, and the integers k1, k2, ..., km (0 β€ ki β€ d) representing the delivery destination location are in the m lines after the n + 3rd line. --1) are written in this order.
Of the scoring data, for 40% of the points, n β€ 10000 is satisfied. For 40% of the points, the total distance traveled and the value of d are both 1000000 or less. In the scoring data, the total distance traveled is 1000000000 = 109 or less.
When d is 0, it indicates the end of input. The number of data sets does not exceed 10.
output
For each data set, one integer representing the total distance traveled during delivery is output on one line.
Examples
Input
8
3
2
3
1
4
6
20
4
4
12
8
16
7
7
11
8
0
Output
3
3
Input
None
Output
None
Submitted Solution:
```
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0539
"""
import sys
from sys import stdin
from bisect import bisect_right
input = stdin.readline
def main(args):
while True:
d = int(input())
if d == 0:
break
n = int(input())
m = int(input())
cw_pos = [int(input()) for _ in range(n-1)]
dests = [int(input()) for _ in range(m)]
cw_pos.append(0)
cw_pos.append(d)
cw_pos.sort()
ccw_pos = [d-x for x in cw_pos]
ccw_pos.sort()
total_distance = 0
for t in dests:
i = bisect_right(cw_pos, t)
a1 = min(t-cw_pos[i-1], cw_pos[i]-t)
j = bisect_right(ccw_pos, d-t)
a2 = min(d-t-ccw_pos[j-1], ccw_pos[j]-(d-t))
ans = min(a1, a2)
total_distance += ans
print(total_distance)
if __name__ == '__main__':
main(sys.argv[1:])
``` | instruction | 0 | 53,861 | 9 | 107,722 |
No | output | 1 | 53,861 | 9 | 107,723 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
JOI Pizza sells pizza home delivery along the d-meter-long ring road that runs through the city center.
JOI Pizza has n stores S1, ..., Sn on the loop line. The head office is S1. The distance from S1 to Si when moving the loop line clockwise is set to di meters. D2 , ..., dn is an integer greater than or equal to 1 and less than or equal to d -1. D2, ..., dn are all different. Bake and deliver pizza at the shortest store.
The location of the delivery destination is represented by an integer k that is greater than or equal to 0 and less than or equal to d -1. This means that the distance from the head office S1 to the delivery destination in the clockwise direction is k meters. Pizza delivery is done along the loop line and no other road is allowed. However, the loop line may move clockwise or counterclockwise.
For example, if the location of the store and the location of the delivery destination are as shown in the figure below (this example corresponds to Example 1 of "I / O example").
<image>
The store closest to the delivery destination 1 is S2, so the delivery is from store S2. At this time, the distance traveled from the store is 1. Also, the store closest to delivery destination 2 is S1 (main store), so store S1 (main store). ) To deliver to home. At this time, the distance traveled from the store is 2.
Total length of the loop line d, Number of JOI pizza stores n, Number of orders m, N --1 integer representing a location other than the main store d2, ..., dn, Integer k1, .. representing the location of the delivery destination Given ., km, create a program to find the sum of all orders for each order by the distance traveled during delivery (ie, the distance from the nearest store to the delivery destination).
input
The input consists of multiple datasets. Each dataset is given in the following format.
The first line is a positive integer d (2 β€ d β€ 1000000000 = 109) that represents the total length of the loop line, the second line is a positive integer n (2 β€ n β€ 100000) that represents the number of stores, and the third line is A positive integer m (1 β€ m β€ 10000) is written to represent the number of orders. The n --1 lines after the 4th line are integers d2, d3, ..., dn that represent the location of stores other than the main store. (1 β€ di β€ d -1) is written in this order, and the integers k1, k2, ..., km (0 β€ ki β€ d) representing the delivery destination location are in the m lines after the n + 3rd line. --1) are written in this order.
Of the scoring data, for 40% of the points, n β€ 10000 is satisfied. For 40% of the points, the total distance traveled and the value of d are both 1000000 or less. In the scoring data, the total distance traveled is 1000000000 = 109 or less.
When d is 0, it indicates the end of input. The number of data sets does not exceed 10.
output
For each data set, one integer representing the total distance traveled during delivery is output on one line.
Examples
Input
8
3
2
3
1
4
6
20
4
4
12
8
16
7
7
11
8
0
Output
3
3
Input
None
Output
None
Submitted Solution:
```
from bisect import bisect_left as bs
def solve():
while True:
d = int(input())
if not d: break
n = int(input())
m = int(input())
d_lst = [int(input()) for _ in range(n - 1)]
d_lst.extend([0,d])
d_lst.sort()
ans = 0
for _ in range(m):
k = int(input())
ind = bs(d_lst,k)
ans += min(d_lst[ind] - k, k - d_lst[ind - 1])
print(ans)
solve()
``` | instruction | 0 | 53,862 | 9 | 107,724 |
No | output | 1 | 53,862 | 9 | 107,725 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
JOI Pizza sells pizza home delivery along the d-meter-long ring road that runs through the city center.
JOI Pizza has n stores S1, ..., Sn on the loop line. The head office is S1. The distance from S1 to Si when moving the loop line clockwise is set to di meters. D2 , ..., dn is an integer greater than or equal to 1 and less than or equal to d -1. D2, ..., dn are all different. Bake and deliver pizza at the shortest store.
The location of the delivery destination is represented by an integer k that is greater than or equal to 0 and less than or equal to d -1. This means that the distance from the head office S1 to the delivery destination in the clockwise direction is k meters. Pizza delivery is done along the loop line and no other road is allowed. However, the loop line may move clockwise or counterclockwise.
For example, if the location of the store and the location of the delivery destination are as shown in the figure below (this example corresponds to Example 1 of "I / O example").
<image>
The store closest to the delivery destination 1 is S2, so the delivery is from store S2. At this time, the distance traveled from the store is 1. Also, the store closest to delivery destination 2 is S1 (main store), so store S1 (main store). ) To deliver to home. At this time, the distance traveled from the store is 2.
Total length of the loop line d, Number of JOI pizza stores n, Number of orders m, N --1 integer representing a location other than the main store d2, ..., dn, Integer k1, .. representing the location of the delivery destination Given ., km, create a program to find the sum of all orders for each order by the distance traveled during delivery (ie, the distance from the nearest store to the delivery destination).
input
The input consists of multiple datasets. Each dataset is given in the following format.
The first line is a positive integer d (2 β€ d β€ 1000000000 = 109) that represents the total length of the loop line, the second line is a positive integer n (2 β€ n β€ 100000) that represents the number of stores, and the third line is A positive integer m (1 β€ m β€ 10000) is written to represent the number of orders. The n --1 lines after the 4th line are integers d2, d3, ..., dn that represent the location of stores other than the main store. (1 β€ di β€ d -1) is written in this order, and the integers k1, k2, ..., km (0 β€ ki β€ d) representing the delivery destination location are in the m lines after the n + 3rd line. --1) are written in this order.
Of the scoring data, for 40% of the points, n β€ 10000 is satisfied. For 40% of the points, the total distance traveled and the value of d are both 1000000 or less. In the scoring data, the total distance traveled is 1000000000 = 109 or less.
When d is 0, it indicates the end of input. The number of data sets does not exceed 10.
output
For each data set, one integer representing the total distance traveled during delivery is output on one line.
Examples
Input
8
3
2
3
1
4
6
20
4
4
12
8
16
7
7
11
8
0
Output
3
3
Input
None
Output
None
Submitted Solution:
```
while True:
d = input()
if d == 0:
break
n = input()
m = input()
dis = []
for i in range(n-1):
s = input()
dis.append(s)
dis.append(0)
k = []
for i in range(m):
s = input()
k.append(s)
ans = 0
for i in k:
mini = 1000000000
for j in dis:
a = i
b = j
if a < b:
a,b = b,a
dist = a - b
if dist > round(d/2):
dist = d - a + b
if dist < mini:
mini = dist
ans = ans + mini
print(ans)
``` | instruction | 0 | 53,863 | 9 | 107,726 |
No | output | 1 | 53,863 | 9 | 107,727 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
JOI Pizza sells pizza home delivery along the d-meter-long ring road that runs through the city center.
JOI Pizza has n stores S1, ..., Sn on the loop line. The head office is S1. The distance from S1 to Si when moving the loop line clockwise is set to di meters. D2 , ..., dn is an integer greater than or equal to 1 and less than or equal to d -1. D2, ..., dn are all different. Bake and deliver pizza at the shortest store.
The location of the delivery destination is represented by an integer k that is greater than or equal to 0 and less than or equal to d -1. This means that the distance from the head office S1 to the delivery destination in the clockwise direction is k meters. Pizza delivery is done along the loop line and no other road is allowed. However, the loop line may move clockwise or counterclockwise.
For example, if the location of the store and the location of the delivery destination are as shown in the figure below (this example corresponds to Example 1 of "I / O example").
<image>
The store closest to the delivery destination 1 is S2, so the delivery is from store S2. At this time, the distance traveled from the store is 1. Also, the store closest to delivery destination 2 is S1 (main store), so store S1 (main store). ) To deliver to home. At this time, the distance traveled from the store is 2.
Total length of the loop line d, Number of JOI pizza stores n, Number of orders m, N --1 integer representing a location other than the main store d2, ..., dn, Integer k1, .. representing the location of the delivery destination Given ., km, create a program to find the sum of all orders for each order by the distance traveled during delivery (ie, the distance from the nearest store to the delivery destination).
input
The input consists of multiple datasets. Each dataset is given in the following format.
The first line is a positive integer d (2 β€ d β€ 1000000000 = 109) that represents the total length of the loop line, the second line is a positive integer n (2 β€ n β€ 100000) that represents the number of stores, and the third line is A positive integer m (1 β€ m β€ 10000) is written to represent the number of orders. The n --1 lines after the 4th line are integers d2, d3, ..., dn that represent the location of stores other than the main store. (1 β€ di β€ d -1) is written in this order, and the integers k1, k2, ..., km (0 β€ ki β€ d) representing the delivery destination location are in the m lines after the n + 3rd line. --1) are written in this order.
Of the scoring data, for 40% of the points, n β€ 10000 is satisfied. For 40% of the points, the total distance traveled and the value of d are both 1000000 or less. In the scoring data, the total distance traveled is 1000000000 = 109 or less.
When d is 0, it indicates the end of input. The number of data sets does not exceed 10.
output
For each data set, one integer representing the total distance traveled during delivery is output on one line.
Examples
Input
8
3
2
3
1
4
6
20
4
4
12
8
16
7
7
11
8
0
Output
3
3
Input
None
Output
None
Submitted Solution:
```
import bisect
d = int(input())
n = int(input())
m = int(input())
shops = [0]*n
for i in range(1,n):
shops[i] = int(input())
shops.sort()
shops.append(d)
d = 0
for i in range(m):
cus = int(input())
req = bisect.bisect(shops,cus)
d += min(abs(cus-shops[req-1]), abs(cus-shops[req]))
print(d)
``` | instruction | 0 | 53,864 | 9 | 107,728 |
No | output | 1 | 53,864 | 9 | 107,729 |
Provide a correct Python 3 solution for this coding contest problem.
Turtle Shi-ta and turtle Be-ko decided to divide a chocolate. The shape of the chocolate is rectangle. The corners of the chocolate are put on (0,0), (w,0), (w,h) and (0,h). The chocolate has lines for cutting. They cut the chocolate only along some of these lines.
The lines are expressed as follows. There are m points on the line connected between (0,0) and (0,h), and between (w,0) and (w,h). Each i-th point, ordered by y value (i = 0 then y =0), is connected as cutting line. These lines do not share any point where 0 < x < w . They can share points where x = 0 or x = w . However, (0, li ) = (0,lj ) and (w,ri ) = (w,rj ) implies i = j . The following figure shows the example of the chocolate.
<image>
There are n special almonds, so delicious but high in calories on the chocolate. Almonds are circle but their radius is too small. You can ignore radius of almonds. The position of almond is expressed as (x,y) coordinate.
Two turtles are so selfish. Both of them have requirement for cutting.
Shi-ta's requirement is that the piece for her is continuous. It is possible for her that she cannot get any chocolate. Assume that the minimum index of the piece is i and the maximum is k . She must have all pieces between i and k . For example, chocolate piece 1,2,3 is continuous but 1,3 or 0,2,4 is not continuous.
Be-ko requires that the area of her chocolate is at least S . She is worry about her weight. So she wants the number of almond on her chocolate is as few as possible.
They doesn't want to make remainder of the chocolate because the chocolate is expensive.
Your task is to compute the minumum number of Beko's almonds if both of their requirment are satisfied.
Input
Input consists of multiple test cases.
Each dataset is given in the following format.
n m w h S
l0 r0
...
lm-1 rm-1
x0 y0
...
xn-1 yn-1
The last line contains five 0s. n is the number of almonds. m is the number of lines. w is the width of the chocolate. h is the height of the chocolate. S is the area that Be-ko wants to eat. Input is integer except xi yi.
Input satisfies following constraints.
1 β€ n β€ 30000
1 β€ m β€ 30000
1 β€ w β€ 200
1 β€ h β€ 1000000
0 β€ S β€ w*h
If i < j then li β€ lj and ri β€ rj and then i -th lines and j -th lines share at most 1 point. It is assured that lm-1 and rm-1 are h. xi yi is floating point number with ten digits. It is assured that they are inside of the chocolate. It is assured that the distance between points and any lines is at least 0.00001.
Output
You should output the minumum number of almonds for Be-ko.
Example
Input
2 3 10 10 50
3 3
6 6
10 10
4.0000000000 4.0000000000
7.0000000000 7.0000000000
2 3 10 10 70
3 3
6 6
10 10
4.0000000000 4.0000000000
7.0000000000 7.0000000000
2 3 10 10 30
3 3
6 6
10 10
4.0000000000 4.0000000000
7.0000000000 7.0000000000
2 3 10 10 40
3 3
6 6
10 10
4.0000000000 4.0000000000
7.0000000000 7.0000000000
2 3 10 10 100
3 3
6 6
10 10
4.0000000000 4.0000000000
7.0000000000 7.0000000000
0 0 0 0 0
Output
1
1
0
1
2 | instruction | 0 | 53,865 | 9 | 107,730 |
"Correct Solution:
```
# AOJ 1067 Cutting a Chocolate
# Python3 2018.7.10 bal4u
from bisect import bisect_left
while True:
n, m, w, h, S = map(int, input().split())
if n == 0: break
m, wh2 = m+1, 2*(w*h)
S = wh2-2*S
tbl, s = [[0,0,0,0]], [0]
for i in range(1, m):
l, r = map(int, input().split())
tbl.append([l, r, 0, r-l])
s.append((l+r)*w)
p = []
for i in range(n):
x, y = map(float, input().split())
p.append((x, y))
p.sort(key=lambda x:(x[1],x[0]))
j = 1
for i in range(n):
x, y = p[i]
while True:
y1 = tbl[j-1][3]*x/w + tbl[j-1][0]
y2 = tbl[j ][3]*x/w + tbl[j ][0]
if y1 < y:
if y < y2: break
j += 1
else: j -= 1
tbl[j][2] += 1
for i in range(1, m): tbl[i][2] += tbl[i-1][2]
if S == 0:
print(n)
continue
elif S == wh2:
print(0)
continue
j = bisect_left(s, S, 0, m)
if s[j] != S: j -= 1
ans, i = tbl[j][2], 1
while j+1 < m:
j += 1
while s[j]-s[i] > S: i += 1
ans = max(ans, tbl[j][2]-tbl[i][2])
print(n - ans)
``` | output | 1 | 53,865 | 9 | 107,731 |
Provide a correct Python 3 solution for this coding contest problem.
Turtle Shi-ta and turtle Be-ko decided to divide a chocolate. The shape of the chocolate is rectangle. The corners of the chocolate are put on (0,0), (w,0), (w,h) and (0,h). The chocolate has lines for cutting. They cut the chocolate only along some of these lines.
The lines are expressed as follows. There are m points on the line connected between (0,0) and (0,h), and between (w,0) and (w,h). Each i-th point, ordered by y value (i = 0 then y =0), is connected as cutting line. These lines do not share any point where 0 < x < w . They can share points where x = 0 or x = w . However, (0, li ) = (0,lj ) and (w,ri ) = (w,rj ) implies i = j . The following figure shows the example of the chocolate.
<image>
There are n special almonds, so delicious but high in calories on the chocolate. Almonds are circle but their radius is too small. You can ignore radius of almonds. The position of almond is expressed as (x,y) coordinate.
Two turtles are so selfish. Both of them have requirement for cutting.
Shi-ta's requirement is that the piece for her is continuous. It is possible for her that she cannot get any chocolate. Assume that the minimum index of the piece is i and the maximum is k . She must have all pieces between i and k . For example, chocolate piece 1,2,3 is continuous but 1,3 or 0,2,4 is not continuous.
Be-ko requires that the area of her chocolate is at least S . She is worry about her weight. So she wants the number of almond on her chocolate is as few as possible.
They doesn't want to make remainder of the chocolate because the chocolate is expensive.
Your task is to compute the minumum number of Beko's almonds if both of their requirment are satisfied.
Input
Input consists of multiple test cases.
Each dataset is given in the following format.
n m w h S
l0 r0
...
lm-1 rm-1
x0 y0
...
xn-1 yn-1
The last line contains five 0s. n is the number of almonds. m is the number of lines. w is the width of the chocolate. h is the height of the chocolate. S is the area that Be-ko wants to eat. Input is integer except xi yi.
Input satisfies following constraints.
1 β€ n β€ 30000
1 β€ m β€ 30000
1 β€ w β€ 200
1 β€ h β€ 1000000
0 β€ S β€ w*h
If i < j then li β€ lj and ri β€ rj and then i -th lines and j -th lines share at most 1 point. It is assured that lm-1 and rm-1 are h. xi yi is floating point number with ten digits. It is assured that they are inside of the chocolate. It is assured that the distance between points and any lines is at least 0.00001.
Output
You should output the minumum number of almonds for Be-ko.
Example
Input
2 3 10 10 50
3 3
6 6
10 10
4.0000000000 4.0000000000
7.0000000000 7.0000000000
2 3 10 10 70
3 3
6 6
10 10
4.0000000000 4.0000000000
7.0000000000 7.0000000000
2 3 10 10 30
3 3
6 6
10 10
4.0000000000 4.0000000000
7.0000000000 7.0000000000
2 3 10 10 40
3 3
6 6
10 10
4.0000000000 4.0000000000
7.0000000000 7.0000000000
2 3 10 10 100
3 3
6 6
10 10
4.0000000000 4.0000000000
7.0000000000 7.0000000000
0 0 0 0 0
Output
1
1
0
1
2 | instruction | 0 | 53,866 | 9 | 107,732 |
"Correct Solution:
```
# AOJ 1067 Cutting a Chocolate
# Python3 2018.7.10 bal4u
from bisect import bisect_left
while True:
n, m, w, h, S = map(int, input().split())
if n == 0: break
m, wh2 = m+1, 2*(w*h)
S = wh2-2*S
tbl, s = [[0,0,0]], [0]
for i in range(1, m):
l, r = map(int, input().split())
tbl.append([l, r, r-l])
s.append((l+r)*w)
p = []
for i in range(n):
x, y = map(float, input().split())
p.append((y, x))
if S == 0:
print(n)
continue
elif S == wh2:
print(0)
continue
p.sort()
j, a = 1, [0]*m
for i in range(n):
y, x = p[i]
while True:
y1 = tbl[j-1][2]*x/w + tbl[j-1][0]
y2 = tbl[j ][2]*x/w + tbl[j ][0]
if y1 < y:
if y < y2: break
j += 1
else: j -= 1
a[j] += 1
for i in range(1, m): a[i] += a[i-1]
j = bisect_left(s, S, 0, m)
if s[j] != S: j -= 1
ans, i = a[j], 1
while j+1 < m:
j += 1
while s[j]-s[i] > S: i += 1
ans = max(ans, a[j]-a[i])
print(n - ans)
``` | output | 1 | 53,866 | 9 | 107,733 |
Provide a correct Python 3 solution for this coding contest problem.
Chokudai loves eating so much. However, his doctor Akensho told him that he was overweight, so he finally decided to lose his weight.
Chokudai made a slimming plan of a $D$-day cycle. It is represented by $D$ integers $w_0, ..., w_{D-1}$. His weight is $S$ on the 0-th day of the plan and he aims to reduce it to $T$ ($S > T$). If his weight on the $i$-th day of the plan is $x$, it will be $x + w_{i\%D}$ on the $(i+1)$-th day. Note that $i\%D$ is the remainder obtained by dividing $i$ by $D$. If his weight successfully gets less than or equal to $T$, he will stop slimming immediately.
If his slimming plan takes too many days or even does not end forever, he should reconsider it.
Determine whether it ends or not, and report how many days it takes if it ends.
Input
The input consists of a single test case formatted as follows.
$S$ $T$ $D$
$w_0 ... w_{D-1}$
The first line consists of three integers $S$, $T$, $D$ ($1 \leq S, T, D \leq 100,000, S > T$). The second line consists of $D$ integers $w_0, ..., w_{D-1}$ ($-100,000 \leq w_i \leq 100,000$ for each $i$).
Output
If Chokudai's slimming plan ends on the $d$-th day, print $d$ in one line. If it never ends, print $-1$.
Examples
Input
65 60 3
-2 3 -4
Output
4
Input
65 60 3
-2 10 -3
Output
-1
Input
100000 1 1
-1
Output
99999
Input
60 59 1
-123
Output
1 | instruction | 0 | 53,893 | 9 | 107,786 |
"Correct Solution:
```
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
def solve():
s,t,d = LI()
w = LI()
W = -sum(w)
if W <= 0:
for i in range(d):
s += w[i]
if s <= t:
print(i+1)
return
print(-1)
else:
S = [s]
for i in range(d):
S.append(S[-1]+w[i])
if S[-1] <= t:
print(i+1)
return
m = min(S)
for j in range(d+1):
if S[j] == m:
break
s = S[j]
w = w[j:]+w[:j]
k = (s-t)//W
s -= k*W
if s <= t:
print(k*d+j)
return
for i in range(d):
s += w[i]
if s <= t:
print(k*d+i+1+j)
return
return
#Solve
if __name__ == "__main__":
solve()
``` | output | 1 | 53,893 | 9 | 107,787 |
Provide a correct Python 3 solution for this coding contest problem.
Chokudai loves eating so much. However, his doctor Akensho told him that he was overweight, so he finally decided to lose his weight.
Chokudai made a slimming plan of a $D$-day cycle. It is represented by $D$ integers $w_0, ..., w_{D-1}$. His weight is $S$ on the 0-th day of the plan and he aims to reduce it to $T$ ($S > T$). If his weight on the $i$-th day of the plan is $x$, it will be $x + w_{i\%D}$ on the $(i+1)$-th day. Note that $i\%D$ is the remainder obtained by dividing $i$ by $D$. If his weight successfully gets less than or equal to $T$, he will stop slimming immediately.
If his slimming plan takes too many days or even does not end forever, he should reconsider it.
Determine whether it ends or not, and report how many days it takes if it ends.
Input
The input consists of a single test case formatted as follows.
$S$ $T$ $D$
$w_0 ... w_{D-1}$
The first line consists of three integers $S$, $T$, $D$ ($1 \leq S, T, D \leq 100,000, S > T$). The second line consists of $D$ integers $w_0, ..., w_{D-1}$ ($-100,000 \leq w_i \leq 100,000$ for each $i$).
Output
If Chokudai's slimming plan ends on the $d$-th day, print $d$ in one line. If it never ends, print $-1$.
Examples
Input
65 60 3
-2 3 -4
Output
4
Input
65 60 3
-2 10 -3
Output
-1
Input
100000 1 1
-1
Output
99999
Input
60 59 1
-123
Output
1 | instruction | 0 | 53,895 | 9 | 107,790 |
"Correct Solution:
```
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')
#A
def A():
s, t, d = LI()
w = LI()
sumw = sum(w)
sb = s
mins = s
for i in range(d):
sb += w[i]
mins = min(mins, sb)
if sb <= t:
print(i + 1)
return
if sumw >= 0:
print(-1)
else:
ans = ((mins - t) // abs(sumw)) * d
#print(ans, s, d, t, sumw)
s += ans // d * sumw
i = 0
while 1:
if s <= t:
print(ans + i)
return
s += w[i%d]
i += 1
print(ans+i+1)
return
#B
def B():
return
#C
def C():
return
#D
def D():
return
#E
def E():
return
#F
def F():
return
#G
def G():
return
#H
def H():
return
#Solve
if __name__ == '__main__':
A()
``` | output | 1 | 53,895 | 9 | 107,791 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places.
Munhattan consists of n streets and m avenues. There is exactly one restaurant on the intersection of each street and avenue. The streets are numbered with integers from 1 to n and the avenues are numbered with integers from 1 to m. The cost of dinner in the restaurant at the intersection of the i-th street and the j-th avenue is cij.
Jack and Emma decide to choose the restaurant in the following way. Firstly Emma chooses the street to dinner and then Jack chooses the avenue. Emma and Jack makes their choice optimally: Emma wants to maximize the cost of the dinner, Jack wants to minimize it. Emma takes into account that Jack wants to minimize the cost of the dinner. Find the cost of the dinner for the couple in love.
Input
The first line contains two integers n, m (1 β€ n, m β€ 100) β the number of streets and avenues in Munhattan.
Each of the next n lines contains m integers cij (1 β€ cij β€ 109) β the cost of the dinner in the restaurant on the intersection of the i-th street and the j-th avenue.
Output
Print the only integer a β the cost of the dinner for Jack and Emma.
Examples
Input
3 4
4 1 3 5
2 2 2 2
5 4 5 1
Output
2
Input
3 3
1 2 3
2 3 1
3 1 2
Output
1
Note
In the first example if Emma chooses the first or the third streets Jack can choose an avenue with the cost of the dinner 1. So she chooses the second street and Jack chooses any avenue. The cost of the dinner is 2.
In the second example regardless of Emma's choice Jack can choose a restaurant with the cost of the dinner 1. | instruction | 0 | 54,392 | 9 | 108,784 |
Tags: games, greedy
Correct Solution:
```
from sys import stdin
n, m = map(int, stdin.readline().split())
print(max([min(list(map(int, stdin.readline().split()))) for i in range(n)]))
``` | output | 1 | 54,392 | 9 | 108,785 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places.
Munhattan consists of n streets and m avenues. There is exactly one restaurant on the intersection of each street and avenue. The streets are numbered with integers from 1 to n and the avenues are numbered with integers from 1 to m. The cost of dinner in the restaurant at the intersection of the i-th street and the j-th avenue is cij.
Jack and Emma decide to choose the restaurant in the following way. Firstly Emma chooses the street to dinner and then Jack chooses the avenue. Emma and Jack makes their choice optimally: Emma wants to maximize the cost of the dinner, Jack wants to minimize it. Emma takes into account that Jack wants to minimize the cost of the dinner. Find the cost of the dinner for the couple in love.
Input
The first line contains two integers n, m (1 β€ n, m β€ 100) β the number of streets and avenues in Munhattan.
Each of the next n lines contains m integers cij (1 β€ cij β€ 109) β the cost of the dinner in the restaurant on the intersection of the i-th street and the j-th avenue.
Output
Print the only integer a β the cost of the dinner for Jack and Emma.
Examples
Input
3 4
4 1 3 5
2 2 2 2
5 4 5 1
Output
2
Input
3 3
1 2 3
2 3 1
3 1 2
Output
1
Note
In the first example if Emma chooses the first or the third streets Jack can choose an avenue with the cost of the dinner 1. So she chooses the second street and Jack chooses any avenue. The cost of the dinner is 2.
In the second example regardless of Emma's choice Jack can choose a restaurant with the cost of the dinner 1. | instruction | 0 | 54,393 | 9 | 108,786 |
Tags: games, greedy
Correct Solution:
```
row , col =map(int , input().split())
array = [[0 for i in range(col)] for j in range(row)]
for i in range(row):
s= input()
c = 0
for j in s.split():
array[i][c] = (int(j))
c+=1
largest = min(array[0])
for i in range(row):
if min(array[i]) > largest:
largest = min(array[i])
print(largest)
``` | output | 1 | 54,393 | 9 | 108,787 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places.
Munhattan consists of n streets and m avenues. There is exactly one restaurant on the intersection of each street and avenue. The streets are numbered with integers from 1 to n and the avenues are numbered with integers from 1 to m. The cost of dinner in the restaurant at the intersection of the i-th street and the j-th avenue is cij.
Jack and Emma decide to choose the restaurant in the following way. Firstly Emma chooses the street to dinner and then Jack chooses the avenue. Emma and Jack makes their choice optimally: Emma wants to maximize the cost of the dinner, Jack wants to minimize it. Emma takes into account that Jack wants to minimize the cost of the dinner. Find the cost of the dinner for the couple in love.
Input
The first line contains two integers n, m (1 β€ n, m β€ 100) β the number of streets and avenues in Munhattan.
Each of the next n lines contains m integers cij (1 β€ cij β€ 109) β the cost of the dinner in the restaurant on the intersection of the i-th street and the j-th avenue.
Output
Print the only integer a β the cost of the dinner for Jack and Emma.
Examples
Input
3 4
4 1 3 5
2 2 2 2
5 4 5 1
Output
2
Input
3 3
1 2 3
2 3 1
3 1 2
Output
1
Note
In the first example if Emma chooses the first or the third streets Jack can choose an avenue with the cost of the dinner 1. So she chooses the second street and Jack chooses any avenue. The cost of the dinner is 2.
In the second example regardless of Emma's choice Jack can choose a restaurant with the cost of the dinner 1. | instruction | 0 | 54,394 | 9 | 108,788 |
Tags: games, greedy
Correct Solution:
```
from copy import copy
n,m = map(int,input().split())
minval = 0
maxval = []
for i in range(n):
l = list(map(int,input().split()))
xx = min(l)
if xx > minval:
minval =xx
maxval = copy(l)
print(min(maxval))
``` | output | 1 | 54,394 | 9 | 108,789 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places.
Munhattan consists of n streets and m avenues. There is exactly one restaurant on the intersection of each street and avenue. The streets are numbered with integers from 1 to n and the avenues are numbered with integers from 1 to m. The cost of dinner in the restaurant at the intersection of the i-th street and the j-th avenue is cij.
Jack and Emma decide to choose the restaurant in the following way. Firstly Emma chooses the street to dinner and then Jack chooses the avenue. Emma and Jack makes their choice optimally: Emma wants to maximize the cost of the dinner, Jack wants to minimize it. Emma takes into account that Jack wants to minimize the cost of the dinner. Find the cost of the dinner for the couple in love.
Input
The first line contains two integers n, m (1 β€ n, m β€ 100) β the number of streets and avenues in Munhattan.
Each of the next n lines contains m integers cij (1 β€ cij β€ 109) β the cost of the dinner in the restaurant on the intersection of the i-th street and the j-th avenue.
Output
Print the only integer a β the cost of the dinner for Jack and Emma.
Examples
Input
3 4
4 1 3 5
2 2 2 2
5 4 5 1
Output
2
Input
3 3
1 2 3
2 3 1
3 1 2
Output
1
Note
In the first example if Emma chooses the first or the third streets Jack can choose an avenue with the cost of the dinner 1. So she chooses the second street and Jack chooses any avenue. The cost of the dinner is 2.
In the second example regardless of Emma's choice Jack can choose a restaurant with the cost of the dinner 1. | instruction | 0 | 54,395 | 9 | 108,790 |
Tags: games, greedy
Correct Solution:
```
n,m = list(map(int, input().strip().split()))
M = 0
for i in range(n):
a = list(map(int, input().strip().split()))
m = min(a)
M = max(m, M)
print(M)
``` | output | 1 | 54,395 | 9 | 108,791 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places.
Munhattan consists of n streets and m avenues. There is exactly one restaurant on the intersection of each street and avenue. The streets are numbered with integers from 1 to n and the avenues are numbered with integers from 1 to m. The cost of dinner in the restaurant at the intersection of the i-th street and the j-th avenue is cij.
Jack and Emma decide to choose the restaurant in the following way. Firstly Emma chooses the street to dinner and then Jack chooses the avenue. Emma and Jack makes their choice optimally: Emma wants to maximize the cost of the dinner, Jack wants to minimize it. Emma takes into account that Jack wants to minimize the cost of the dinner. Find the cost of the dinner for the couple in love.
Input
The first line contains two integers n, m (1 β€ n, m β€ 100) β the number of streets and avenues in Munhattan.
Each of the next n lines contains m integers cij (1 β€ cij β€ 109) β the cost of the dinner in the restaurant on the intersection of the i-th street and the j-th avenue.
Output
Print the only integer a β the cost of the dinner for Jack and Emma.
Examples
Input
3 4
4 1 3 5
2 2 2 2
5 4 5 1
Output
2
Input
3 3
1 2 3
2 3 1
3 1 2
Output
1
Note
In the first example if Emma chooses the first or the third streets Jack can choose an avenue with the cost of the dinner 1. So she chooses the second street and Jack chooses any avenue. The cost of the dinner is 2.
In the second example regardless of Emma's choice Jack can choose a restaurant with the cost of the dinner 1. | instruction | 0 | 54,396 | 9 | 108,792 |
Tags: games, greedy
Correct Solution:
```
n, m = [int(x) for x in input().split(' ')]
c = [[int(x) for x in input().split(' ')] for i in range(n)]
ans = max([min(x) for x in c])
print(ans)
``` | output | 1 | 54,396 | 9 | 108,793 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places.
Munhattan consists of n streets and m avenues. There is exactly one restaurant on the intersection of each street and avenue. The streets are numbered with integers from 1 to n and the avenues are numbered with integers from 1 to m. The cost of dinner in the restaurant at the intersection of the i-th street and the j-th avenue is cij.
Jack and Emma decide to choose the restaurant in the following way. Firstly Emma chooses the street to dinner and then Jack chooses the avenue. Emma and Jack makes their choice optimally: Emma wants to maximize the cost of the dinner, Jack wants to minimize it. Emma takes into account that Jack wants to minimize the cost of the dinner. Find the cost of the dinner for the couple in love.
Input
The first line contains two integers n, m (1 β€ n, m β€ 100) β the number of streets and avenues in Munhattan.
Each of the next n lines contains m integers cij (1 β€ cij β€ 109) β the cost of the dinner in the restaurant on the intersection of the i-th street and the j-th avenue.
Output
Print the only integer a β the cost of the dinner for Jack and Emma.
Examples
Input
3 4
4 1 3 5
2 2 2 2
5 4 5 1
Output
2
Input
3 3
1 2 3
2 3 1
3 1 2
Output
1
Note
In the first example if Emma chooses the first or the third streets Jack can choose an avenue with the cost of the dinner 1. So she chooses the second street and Jack chooses any avenue. The cost of the dinner is 2.
In the second example regardless of Emma's choice Jack can choose a restaurant with the cost of the dinner 1. | instruction | 0 | 54,397 | 9 | 108,794 |
Tags: games, greedy
Correct Solution:
```
n, m = map(int, input().split())
a = []
b = []
for i in range(n):
a.append(list(map(int,input().split())))
b.append(min(a[i]))
print(max(b))
``` | output | 1 | 54,397 | 9 | 108,795 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places.
Munhattan consists of n streets and m avenues. There is exactly one restaurant on the intersection of each street and avenue. The streets are numbered with integers from 1 to n and the avenues are numbered with integers from 1 to m. The cost of dinner in the restaurant at the intersection of the i-th street and the j-th avenue is cij.
Jack and Emma decide to choose the restaurant in the following way. Firstly Emma chooses the street to dinner and then Jack chooses the avenue. Emma and Jack makes their choice optimally: Emma wants to maximize the cost of the dinner, Jack wants to minimize it. Emma takes into account that Jack wants to minimize the cost of the dinner. Find the cost of the dinner for the couple in love.
Input
The first line contains two integers n, m (1 β€ n, m β€ 100) β the number of streets and avenues in Munhattan.
Each of the next n lines contains m integers cij (1 β€ cij β€ 109) β the cost of the dinner in the restaurant on the intersection of the i-th street and the j-th avenue.
Output
Print the only integer a β the cost of the dinner for Jack and Emma.
Examples
Input
3 4
4 1 3 5
2 2 2 2
5 4 5 1
Output
2
Input
3 3
1 2 3
2 3 1
3 1 2
Output
1
Note
In the first example if Emma chooses the first or the third streets Jack can choose an avenue with the cost of the dinner 1. So she chooses the second street and Jack chooses any avenue. The cost of the dinner is 2.
In the second example regardless of Emma's choice Jack can choose a restaurant with the cost of the dinner 1. | instruction | 0 | 54,398 | 9 | 108,796 |
Tags: games, greedy
Correct Solution:
```
__author__ = 'abdujabbor'
n, m = [int(x) for x in input().split()]
a = [[0]*m]*n
p = [0] * n
for i in range(n):
a[i] = sorted([int(x) for x in input().split()])
p[i] = min(a[i])
print(max(p))
``` | output | 1 | 54,398 | 9 | 108,797 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places.
Munhattan consists of n streets and m avenues. There is exactly one restaurant on the intersection of each street and avenue. The streets are numbered with integers from 1 to n and the avenues are numbered with integers from 1 to m. The cost of dinner in the restaurant at the intersection of the i-th street and the j-th avenue is cij.
Jack and Emma decide to choose the restaurant in the following way. Firstly Emma chooses the street to dinner and then Jack chooses the avenue. Emma and Jack makes their choice optimally: Emma wants to maximize the cost of the dinner, Jack wants to minimize it. Emma takes into account that Jack wants to minimize the cost of the dinner. Find the cost of the dinner for the couple in love.
Input
The first line contains two integers n, m (1 β€ n, m β€ 100) β the number of streets and avenues in Munhattan.
Each of the next n lines contains m integers cij (1 β€ cij β€ 109) β the cost of the dinner in the restaurant on the intersection of the i-th street and the j-th avenue.
Output
Print the only integer a β the cost of the dinner for Jack and Emma.
Examples
Input
3 4
4 1 3 5
2 2 2 2
5 4 5 1
Output
2
Input
3 3
1 2 3
2 3 1
3 1 2
Output
1
Note
In the first example if Emma chooses the first or the third streets Jack can choose an avenue with the cost of the dinner 1. So she chooses the second street and Jack chooses any avenue. The cost of the dinner is 2.
In the second example regardless of Emma's choice Jack can choose a restaurant with the cost of the dinner 1. | instruction | 0 | 54,399 | 9 | 108,798 |
Tags: games, greedy
Correct Solution:
```
n, m = (int(i) for i in input().split())
masha = {}
pasha = {}
max = 0
vybor = 0
for i in range(1, n+1):
street = [int(i) for i in input().split()]
mininstreet = min(street)
pasha.update({i:mininstreet})
if max <= mininstreet:
max = mininstreet
vybor = i
print(pasha[vybor])
``` | output | 1 | 54,399 | 9 | 108,799 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places.
Munhattan consists of n streets and m avenues. There is exactly one restaurant on the intersection of each street and avenue. The streets are numbered with integers from 1 to n and the avenues are numbered with integers from 1 to m. The cost of dinner in the restaurant at the intersection of the i-th street and the j-th avenue is cij.
Jack and Emma decide to choose the restaurant in the following way. Firstly Emma chooses the street to dinner and then Jack chooses the avenue. Emma and Jack makes their choice optimally: Emma wants to maximize the cost of the dinner, Jack wants to minimize it. Emma takes into account that Jack wants to minimize the cost of the dinner. Find the cost of the dinner for the couple in love.
Input
The first line contains two integers n, m (1 β€ n, m β€ 100) β the number of streets and avenues in Munhattan.
Each of the next n lines contains m integers cij (1 β€ cij β€ 109) β the cost of the dinner in the restaurant on the intersection of the i-th street and the j-th avenue.
Output
Print the only integer a β the cost of the dinner for Jack and Emma.
Examples
Input
3 4
4 1 3 5
2 2 2 2
5 4 5 1
Output
2
Input
3 3
1 2 3
2 3 1
3 1 2
Output
1
Note
In the first example if Emma chooses the first or the third streets Jack can choose an avenue with the cost of the dinner 1. So she chooses the second street and Jack chooses any avenue. The cost of the dinner is 2.
In the second example regardless of Emma's choice Jack can choose a restaurant with the cost of the dinner 1.
Submitted Solution:
```
elso = input()
elso = elso.split()
n = int(elso[0])
m = int(elso[1])
lista = []
for _ in range(n):
sor = input()
sor = sor.split()
sor = list(map(lambda x: int(x), sor))
lista.append(sor)
lista = list(map(lambda x: min(x), lista)) #minimumok
print(max(lista))
``` | instruction | 0 | 54,400 | 9 | 108,800 |
Yes | output | 1 | 54,400 | 9 | 108,801 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places.
Munhattan consists of n streets and m avenues. There is exactly one restaurant on the intersection of each street and avenue. The streets are numbered with integers from 1 to n and the avenues are numbered with integers from 1 to m. The cost of dinner in the restaurant at the intersection of the i-th street and the j-th avenue is cij.
Jack and Emma decide to choose the restaurant in the following way. Firstly Emma chooses the street to dinner and then Jack chooses the avenue. Emma and Jack makes their choice optimally: Emma wants to maximize the cost of the dinner, Jack wants to minimize it. Emma takes into account that Jack wants to minimize the cost of the dinner. Find the cost of the dinner for the couple in love.
Input
The first line contains two integers n, m (1 β€ n, m β€ 100) β the number of streets and avenues in Munhattan.
Each of the next n lines contains m integers cij (1 β€ cij β€ 109) β the cost of the dinner in the restaurant on the intersection of the i-th street and the j-th avenue.
Output
Print the only integer a β the cost of the dinner for Jack and Emma.
Examples
Input
3 4
4 1 3 5
2 2 2 2
5 4 5 1
Output
2
Input
3 3
1 2 3
2 3 1
3 1 2
Output
1
Note
In the first example if Emma chooses the first or the third streets Jack can choose an avenue with the cost of the dinner 1. So she chooses the second street and Jack chooses any avenue. The cost of the dinner is 2.
In the second example regardless of Emma's choice Jack can choose a restaurant with the cost of the dinner 1.
Submitted Solution:
```
li = list(map(int, input().split(" ")))
n = li[0]
m = li[1]
ans = 0
for i in range(n) :
li = list(map(int, input().split(" ")))
ans = max(ans, min(li))
print(ans)
``` | instruction | 0 | 54,401 | 9 | 108,802 |
Yes | output | 1 | 54,401 | 9 | 108,803 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places.
Munhattan consists of n streets and m avenues. There is exactly one restaurant on the intersection of each street and avenue. The streets are numbered with integers from 1 to n and the avenues are numbered with integers from 1 to m. The cost of dinner in the restaurant at the intersection of the i-th street and the j-th avenue is cij.
Jack and Emma decide to choose the restaurant in the following way. Firstly Emma chooses the street to dinner and then Jack chooses the avenue. Emma and Jack makes their choice optimally: Emma wants to maximize the cost of the dinner, Jack wants to minimize it. Emma takes into account that Jack wants to minimize the cost of the dinner. Find the cost of the dinner for the couple in love.
Input
The first line contains two integers n, m (1 β€ n, m β€ 100) β the number of streets and avenues in Munhattan.
Each of the next n lines contains m integers cij (1 β€ cij β€ 109) β the cost of the dinner in the restaurant on the intersection of the i-th street and the j-th avenue.
Output
Print the only integer a β the cost of the dinner for Jack and Emma.
Examples
Input
3 4
4 1 3 5
2 2 2 2
5 4 5 1
Output
2
Input
3 3
1 2 3
2 3 1
3 1 2
Output
1
Note
In the first example if Emma chooses the first or the third streets Jack can choose an avenue with the cost of the dinner 1. So she chooses the second street and Jack chooses any avenue. The cost of the dinner is 2.
In the second example regardless of Emma's choice Jack can choose a restaurant with the cost of the dinner 1.
Submitted Solution:
```
N, M = map(int, input().split())
res = 0
for _ in range(N):
res = max(res, min(map(int, input().split())))
print(res)
``` | instruction | 0 | 54,402 | 9 | 108,804 |
Yes | output | 1 | 54,402 | 9 | 108,805 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places.
Munhattan consists of n streets and m avenues. There is exactly one restaurant on the intersection of each street and avenue. The streets are numbered with integers from 1 to n and the avenues are numbered with integers from 1 to m. The cost of dinner in the restaurant at the intersection of the i-th street and the j-th avenue is cij.
Jack and Emma decide to choose the restaurant in the following way. Firstly Emma chooses the street to dinner and then Jack chooses the avenue. Emma and Jack makes their choice optimally: Emma wants to maximize the cost of the dinner, Jack wants to minimize it. Emma takes into account that Jack wants to minimize the cost of the dinner. Find the cost of the dinner for the couple in love.
Input
The first line contains two integers n, m (1 β€ n, m β€ 100) β the number of streets and avenues in Munhattan.
Each of the next n lines contains m integers cij (1 β€ cij β€ 109) β the cost of the dinner in the restaurant on the intersection of the i-th street and the j-th avenue.
Output
Print the only integer a β the cost of the dinner for Jack and Emma.
Examples
Input
3 4
4 1 3 5
2 2 2 2
5 4 5 1
Output
2
Input
3 3
1 2 3
2 3 1
3 1 2
Output
1
Note
In the first example if Emma chooses the first or the third streets Jack can choose an avenue with the cost of the dinner 1. So she chooses the second street and Jack chooses any avenue. The cost of the dinner is 2.
In the second example regardless of Emma's choice Jack can choose a restaurant with the cost of the dinner 1.
Submitted Solution:
```
n,m=list(map(int,input().split()))
cmi=0
ans=-10000000
for i in range(n):
l=list(map(int,input().split()))
cmi=min(l)
ans=max(ans,cmi)
print(ans)
``` | instruction | 0 | 54,403 | 9 | 108,806 |
Yes | output | 1 | 54,403 | 9 | 108,807 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places.
Munhattan consists of n streets and m avenues. There is exactly one restaurant on the intersection of each street and avenue. The streets are numbered with integers from 1 to n and the avenues are numbered with integers from 1 to m. The cost of dinner in the restaurant at the intersection of the i-th street and the j-th avenue is cij.
Jack and Emma decide to choose the restaurant in the following way. Firstly Emma chooses the street to dinner and then Jack chooses the avenue. Emma and Jack makes their choice optimally: Emma wants to maximize the cost of the dinner, Jack wants to minimize it. Emma takes into account that Jack wants to minimize the cost of the dinner. Find the cost of the dinner for the couple in love.
Input
The first line contains two integers n, m (1 β€ n, m β€ 100) β the number of streets and avenues in Munhattan.
Each of the next n lines contains m integers cij (1 β€ cij β€ 109) β the cost of the dinner in the restaurant on the intersection of the i-th street and the j-th avenue.
Output
Print the only integer a β the cost of the dinner for Jack and Emma.
Examples
Input
3 4
4 1 3 5
2 2 2 2
5 4 5 1
Output
2
Input
3 3
1 2 3
2 3 1
3 1 2
Output
1
Note
In the first example if Emma chooses the first or the third streets Jack can choose an avenue with the cost of the dinner 1. So she chooses the second street and Jack chooses any avenue. The cost of the dinner is 2.
In the second example regardless of Emma's choice Jack can choose a restaurant with the cost of the dinner 1.
Submitted Solution:
```
n,m=map(int,input().split())
mn=0
for i in range(n):
mas=list(map(int,input().split()))
if mn<max(mn,min(mas)):
mn=min(mas)
ans=i+1
print(ans)
``` | instruction | 0 | 54,404 | 9 | 108,808 |
No | output | 1 | 54,404 | 9 | 108,809 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places.
Munhattan consists of n streets and m avenues. There is exactly one restaurant on the intersection of each street and avenue. The streets are numbered with integers from 1 to n and the avenues are numbered with integers from 1 to m. The cost of dinner in the restaurant at the intersection of the i-th street and the j-th avenue is cij.
Jack and Emma decide to choose the restaurant in the following way. Firstly Emma chooses the street to dinner and then Jack chooses the avenue. Emma and Jack makes their choice optimally: Emma wants to maximize the cost of the dinner, Jack wants to minimize it. Emma takes into account that Jack wants to minimize the cost of the dinner. Find the cost of the dinner for the couple in love.
Input
The first line contains two integers n, m (1 β€ n, m β€ 100) β the number of streets and avenues in Munhattan.
Each of the next n lines contains m integers cij (1 β€ cij β€ 109) β the cost of the dinner in the restaurant on the intersection of the i-th street and the j-th avenue.
Output
Print the only integer a β the cost of the dinner for Jack and Emma.
Examples
Input
3 4
4 1 3 5
2 2 2 2
5 4 5 1
Output
2
Input
3 3
1 2 3
2 3 1
3 1 2
Output
1
Note
In the first example if Emma chooses the first or the third streets Jack can choose an avenue with the cost of the dinner 1. So she chooses the second street and Jack chooses any avenue. The cost of the dinner is 2.
In the second example regardless of Emma's choice Jack can choose a restaurant with the cost of the dinner 1.
Submitted Solution:
```
n,m=map(int,input().split())
a=[]
min1=1000000001
max1=0
for i in range(n):
a.append(input().split())
for j in range(m):
if int(a[i][j])>max1:
max1=int(a[i][j])
if int(a[i][j])<min1:
min1=int(a[i][j])
min2=1000000001
n1=0
for i in range(n):
for j in range(m):
if int(a[i][j])==min1:
n1+=1
elif int(a[i][j])<min2:
min2=int(a[i][j])
if m==1:
print(max1)
elif n1==n:
print(min1)
else:
print(min2)
``` | instruction | 0 | 54,405 | 9 | 108,810 |
No | output | 1 | 54,405 | 9 | 108,811 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places.
Munhattan consists of n streets and m avenues. There is exactly one restaurant on the intersection of each street and avenue. The streets are numbered with integers from 1 to n and the avenues are numbered with integers from 1 to m. The cost of dinner in the restaurant at the intersection of the i-th street and the j-th avenue is cij.
Jack and Emma decide to choose the restaurant in the following way. Firstly Emma chooses the street to dinner and then Jack chooses the avenue. Emma and Jack makes their choice optimally: Emma wants to maximize the cost of the dinner, Jack wants to minimize it. Emma takes into account that Jack wants to minimize the cost of the dinner. Find the cost of the dinner for the couple in love.
Input
The first line contains two integers n, m (1 β€ n, m β€ 100) β the number of streets and avenues in Munhattan.
Each of the next n lines contains m integers cij (1 β€ cij β€ 109) β the cost of the dinner in the restaurant on the intersection of the i-th street and the j-th avenue.
Output
Print the only integer a β the cost of the dinner for Jack and Emma.
Examples
Input
3 4
4 1 3 5
2 2 2 2
5 4 5 1
Output
2
Input
3 3
1 2 3
2 3 1
3 1 2
Output
1
Note
In the first example if Emma chooses the first or the third streets Jack can choose an avenue with the cost of the dinner 1. So she chooses the second street and Jack chooses any avenue. The cost of the dinner is 2.
In the second example regardless of Emma's choice Jack can choose a restaurant with the cost of the dinner 1.
Submitted Solution:
```
n , m = map(int , input().split())
l=[]
costly = 0
for i in range(n):
temp = list(map(int , input().split()))
t = [max(temp), min(temp)]
x = max(temp)
costly = max(x , costly)
l.append(t)
ans = costly
if m!=1:
for i in l:
if costly not in i:
ans = min(ans , min(i))
if ans == costly:
ans = min(l[0])
else:
ans = costly
print(ans)
``` | instruction | 0 | 54,406 | 9 | 108,812 |
No | output | 1 | 54,406 | 9 | 108,813 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.