text stringlengths 1.02k 43.5k | conversation_id int64 853 107k | embedding list | cluster int64 24 24 |
|---|---|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
Hooray! Polycarp turned n years old! The Technocup Team sincerely congratulates Polycarp!
Polycarp celebrated all of his n birthdays: from the 1-th to the n-th. At the moment, he is wondering: how many times he turned beautiful number of years?
According to Polycarp, a positive integer is beautiful if it consists of only one digit repeated one or more times. For example, the following numbers are beautiful: 1, 77, 777, 44 and 999999. The following numbers are not beautiful: 12, 11110, 6969 and 987654321.
Of course, Polycarpus uses the decimal numeral system (i.e. radix is 10).
Help Polycarpus to find the number of numbers from 1 to n (inclusive) that are beautiful.
Input
The first line contains an integer t (1 β€ t β€ 10^4) β the number of test cases in the input. Then t test cases follow.
Each test case consists of one line, which contains a positive integer n (1 β€ n β€ 10^9) β how many years Polycarp has turned.
Output
Print t integers β the answers to the given test cases in the order they are written in the test. Each answer is an integer: the number of beautiful years between 1 and n, inclusive.
Example
Input
6
18
1
9
100500
33
1000000000
Output
10
1
9
45
12
81
Note
In the first test case of the example beautiful years are 1, 2, 3, 4, 5, 6, 7, 8, 9 and 11.
Tags: implementation
Correct Solution:
```
from collections import defaultdict, deque
from itertools import permutations
from sys import stdin,stdout
from bisect import bisect_left, bisect_right
from copy import deepcopy
import os,sys
int_input=lambda : int(stdin.readline())
string_input=lambda : stdin.readline()
multi_int_input =lambda : map(int, stdin.readline().split())
multi_input = lambda : stdin.readline().split()
list_input=lambda : list(map(int,stdin.readline().split()))
string_list_input=lambda: list(string_input())
MOD = pow(10,9)+7
# stdin = open(os.path.join(sys.path[0],'input.in'),'r')
# sys.stdout = open(os.path.join(sys.path[0],'output2.in'),'w')
test = int_input()
arr = [9,18,27,36,45,54,63,72,81]
for _ in range(test):
n = int_input()
if n<=9:
print(n)
else:
string_no = str(n)
length_no = len(string_no)
first_digit = int(string_no[0])
maximum = str(first_digit)*length_no
maximum = int(maximum)
if maximum<=n:
print(arr[length_no-2]+first_digit)
else:
print(arr[length_no-2]+(first_digit-1))
```
| 60,774 | [
0.53564453125,
0.08709716796875,
0.092529296875,
0.01898193359375,
-0.45947265625,
-0.2197265625,
-0.06243896484375,
-0.0721435546875,
0.271484375,
0.40576171875,
0.65966796875,
-0.42236328125,
0.14306640625,
-0.623046875,
-0.36572265625,
-0.1214599609375,
-0.395263671875,
-0.30395... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Hooray! Polycarp turned n years old! The Technocup Team sincerely congratulates Polycarp!
Polycarp celebrated all of his n birthdays: from the 1-th to the n-th. At the moment, he is wondering: how many times he turned beautiful number of years?
According to Polycarp, a positive integer is beautiful if it consists of only one digit repeated one or more times. For example, the following numbers are beautiful: 1, 77, 777, 44 and 999999. The following numbers are not beautiful: 12, 11110, 6969 and 987654321.
Of course, Polycarpus uses the decimal numeral system (i.e. radix is 10).
Help Polycarpus to find the number of numbers from 1 to n (inclusive) that are beautiful.
Input
The first line contains an integer t (1 β€ t β€ 10^4) β the number of test cases in the input. Then t test cases follow.
Each test case consists of one line, which contains a positive integer n (1 β€ n β€ 10^9) β how many years Polycarp has turned.
Output
Print t integers β the answers to the given test cases in the order they are written in the test. Each answer is an integer: the number of beautiful years between 1 and n, inclusive.
Example
Input
6
18
1
9
100500
33
1000000000
Output
10
1
9
45
12
81
Note
In the first test case of the example beautiful years are 1, 2, 3, 4, 5, 6, 7, 8, 9 and 11.
Tags: implementation
Correct Solution:
```
n = int(input())
for a in range(n):
x = input()
l = int(len(x))
count = 9*(l-1)
x = int(x)
count += x//((10**l-1)//9)
print(count)
```
| 60,775 | [
0.59130859375,
0.033447265625,
0.04827880859375,
0.02850341796875,
-0.404296875,
-0.2841796875,
0.0090179443359375,
-0.034088134765625,
0.31396484375,
0.3486328125,
0.62939453125,
-0.331787109375,
0.1514892578125,
-0.64208984375,
-0.33544921875,
-0.1236572265625,
-0.401123046875,
-... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Hooray! Polycarp turned n years old! The Technocup Team sincerely congratulates Polycarp!
Polycarp celebrated all of his n birthdays: from the 1-th to the n-th. At the moment, he is wondering: how many times he turned beautiful number of years?
According to Polycarp, a positive integer is beautiful if it consists of only one digit repeated one or more times. For example, the following numbers are beautiful: 1, 77, 777, 44 and 999999. The following numbers are not beautiful: 12, 11110, 6969 and 987654321.
Of course, Polycarpus uses the decimal numeral system (i.e. radix is 10).
Help Polycarpus to find the number of numbers from 1 to n (inclusive) that are beautiful.
Input
The first line contains an integer t (1 β€ t β€ 10^4) β the number of test cases in the input. Then t test cases follow.
Each test case consists of one line, which contains a positive integer n (1 β€ n β€ 10^9) β how many years Polycarp has turned.
Output
Print t integers β the answers to the given test cases in the order they are written in the test. Each answer is an integer: the number of beautiful years between 1 and n, inclusive.
Example
Input
6
18
1
9
100500
33
1000000000
Output
10
1
9
45
12
81
Note
In the first test case of the example beautiful years are 1, 2, 3, 4, 5, 6, 7, 8, 9 and 11.
Tags: implementation
Correct Solution:
```
from math import *
def r1(t):
return t(input())
def r2(t):
return [t(i) for i in input().split()]
for _ in range(r1(int)):
n = r1(int)
ans = 0
for i in range(1, 10):
cn = i
while cn <= n:
ans += 1
cn = cn*10 + i
print(int(ans))
```
| 60,776 | [
0.576171875,
0.0225677490234375,
0.050872802734375,
-0.0036411285400390625,
-0.359130859375,
-0.2447509765625,
-0.0190887451171875,
-0.06585693359375,
0.309326171875,
0.36328125,
0.65283203125,
-0.3916015625,
0.1295166015625,
-0.5810546875,
-0.314453125,
-0.1107177734375,
-0.42822265... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Hooray! Polycarp turned n years old! The Technocup Team sincerely congratulates Polycarp!
Polycarp celebrated all of his n birthdays: from the 1-th to the n-th. At the moment, he is wondering: how many times he turned beautiful number of years?
According to Polycarp, a positive integer is beautiful if it consists of only one digit repeated one or more times. For example, the following numbers are beautiful: 1, 77, 777, 44 and 999999. The following numbers are not beautiful: 12, 11110, 6969 and 987654321.
Of course, Polycarpus uses the decimal numeral system (i.e. radix is 10).
Help Polycarpus to find the number of numbers from 1 to n (inclusive) that are beautiful.
Input
The first line contains an integer t (1 β€ t β€ 10^4) β the number of test cases in the input. Then t test cases follow.
Each test case consists of one line, which contains a positive integer n (1 β€ n β€ 10^9) β how many years Polycarp has turned.
Output
Print t integers β the answers to the given test cases in the order they are written in the test. Each answer is an integer: the number of beautiful years between 1 and n, inclusive.
Example
Input
6
18
1
9
100500
33
1000000000
Output
10
1
9
45
12
81
Note
In the first test case of the example beautiful years are 1, 2, 3, 4, 5, 6, 7, 8, 9 and 11.
Submitted Solution:
```
t=int(input())
for _ in range(t):
n=int(input())
k=len(str(n))
k1=""
for i in range(k):
k1+="1"
c=9*(k-1)
k1=int(k1)
k2=k1
while((k1)<=n):
(k1)=(k1)+(k2)
c+=1
print(c)
```
Yes
| 60,777 | [
0.5625,
0.035797119140625,
0.027069091796875,
0.0157012939453125,
-0.498046875,
-0.178955078125,
-0.03338623046875,
0.055755615234375,
0.223876953125,
0.3857421875,
0.5810546875,
-0.290283203125,
0.142822265625,
-0.6318359375,
-0.306640625,
-0.1226806640625,
-0.384765625,
-0.351074... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Hooray! Polycarp turned n years old! The Technocup Team sincerely congratulates Polycarp!
Polycarp celebrated all of his n birthdays: from the 1-th to the n-th. At the moment, he is wondering: how many times he turned beautiful number of years?
According to Polycarp, a positive integer is beautiful if it consists of only one digit repeated one or more times. For example, the following numbers are beautiful: 1, 77, 777, 44 and 999999. The following numbers are not beautiful: 12, 11110, 6969 and 987654321.
Of course, Polycarpus uses the decimal numeral system (i.e. radix is 10).
Help Polycarpus to find the number of numbers from 1 to n (inclusive) that are beautiful.
Input
The first line contains an integer t (1 β€ t β€ 10^4) β the number of test cases in the input. Then t test cases follow.
Each test case consists of one line, which contains a positive integer n (1 β€ n β€ 10^9) β how many years Polycarp has turned.
Output
Print t integers β the answers to the given test cases in the order they are written in the test. Each answer is an integer: the number of beautiful years between 1 and n, inclusive.
Example
Input
6
18
1
9
100500
33
1000000000
Output
10
1
9
45
12
81
Note
In the first test case of the example beautiful years are 1, 2, 3, 4, 5, 6, 7, 8, 9 and 11.
Submitted Solution:
```
t=int(input())
for i in range(t):
n=(input())
s=n[0]*len(n)
k=(len(n)-1)*9
k+=(int(n[0])-1)
if int(n)>=int(s):
k+=1
print(k)
```
Yes
| 60,778 | [
0.556640625,
0.047882080078125,
0.02154541015625,
0.0221099853515625,
-0.4873046875,
-0.155517578125,
-0.044952392578125,
0.07501220703125,
0.24755859375,
0.379150390625,
0.59521484375,
-0.245361328125,
0.1475830078125,
-0.6494140625,
-0.301513671875,
-0.12225341796875,
-0.3776855468... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Hooray! Polycarp turned n years old! The Technocup Team sincerely congratulates Polycarp!
Polycarp celebrated all of his n birthdays: from the 1-th to the n-th. At the moment, he is wondering: how many times he turned beautiful number of years?
According to Polycarp, a positive integer is beautiful if it consists of only one digit repeated one or more times. For example, the following numbers are beautiful: 1, 77, 777, 44 and 999999. The following numbers are not beautiful: 12, 11110, 6969 and 987654321.
Of course, Polycarpus uses the decimal numeral system (i.e. radix is 10).
Help Polycarpus to find the number of numbers from 1 to n (inclusive) that are beautiful.
Input
The first line contains an integer t (1 β€ t β€ 10^4) β the number of test cases in the input. Then t test cases follow.
Each test case consists of one line, which contains a positive integer n (1 β€ n β€ 10^9) β how many years Polycarp has turned.
Output
Print t integers β the answers to the given test cases in the order they are written in the test. Each answer is an integer: the number of beautiful years between 1 and n, inclusive.
Example
Input
6
18
1
9
100500
33
1000000000
Output
10
1
9
45
12
81
Note
In the first test case of the example beautiful years are 1, 2, 3, 4, 5, 6, 7, 8, 9 and 11.
Submitted Solution:
```
t = int(input())
for i in range(t):
n = int(input())
L = len(str(n))
ans = (L - 1) * 9
for j in range(1,10):
if n >= int(str(j) * L):
ans += 1
print(ans)
```
Yes
| 60,779 | [
0.5703125,
0.02325439453125,
0.038177490234375,
0.01212310791015625,
-0.49609375,
-0.1434326171875,
-0.0263824462890625,
0.059967041015625,
0.267578125,
0.375732421875,
0.60205078125,
-0.25537109375,
0.13134765625,
-0.650390625,
-0.314697265625,
-0.1263427734375,
-0.370361328125,
-... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Hooray! Polycarp turned n years old! The Technocup Team sincerely congratulates Polycarp!
Polycarp celebrated all of his n birthdays: from the 1-th to the n-th. At the moment, he is wondering: how many times he turned beautiful number of years?
According to Polycarp, a positive integer is beautiful if it consists of only one digit repeated one or more times. For example, the following numbers are beautiful: 1, 77, 777, 44 and 999999. The following numbers are not beautiful: 12, 11110, 6969 and 987654321.
Of course, Polycarpus uses the decimal numeral system (i.e. radix is 10).
Help Polycarpus to find the number of numbers from 1 to n (inclusive) that are beautiful.
Input
The first line contains an integer t (1 β€ t β€ 10^4) β the number of test cases in the input. Then t test cases follow.
Each test case consists of one line, which contains a positive integer n (1 β€ n β€ 10^9) β how many years Polycarp has turned.
Output
Print t integers β the answers to the given test cases in the order they are written in the test. Each answer is an integer: the number of beautiful years between 1 and n, inclusive.
Example
Input
6
18
1
9
100500
33
1000000000
Output
10
1
9
45
12
81
Note
In the first test case of the example beautiful years are 1, 2, 3, 4, 5, 6, 7, 8, 9 and 11.
Submitted Solution:
```
t = int(input(''))
for v in range(t):
n = input('')
l = len(n)
ans = 9*(l-1)
s = int(n[0])
if(l == 1):
print(s)
else:
i = 1
res = True
while(i < l):
if(int(n[i]) > s):
res = True
break
elif(int(n[i]) < s):
res = False
break
else:
i = i+1
if(res):
print(ans + s)
else:
print(ans + s-1)
```
Yes
| 60,780 | [
0.5517578125,
0.046966552734375,
0.05255126953125,
0.0033740997314453125,
-0.456298828125,
-0.1422119140625,
-0.015838623046875,
0.05560302734375,
0.251953125,
0.3818359375,
0.6005859375,
-0.288330078125,
0.1572265625,
-0.63525390625,
-0.30615234375,
-0.1536865234375,
-0.39599609375,... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Hooray! Polycarp turned n years old! The Technocup Team sincerely congratulates Polycarp!
Polycarp celebrated all of his n birthdays: from the 1-th to the n-th. At the moment, he is wondering: how many times he turned beautiful number of years?
According to Polycarp, a positive integer is beautiful if it consists of only one digit repeated one or more times. For example, the following numbers are beautiful: 1, 77, 777, 44 and 999999. The following numbers are not beautiful: 12, 11110, 6969 and 987654321.
Of course, Polycarpus uses the decimal numeral system (i.e. radix is 10).
Help Polycarpus to find the number of numbers from 1 to n (inclusive) that are beautiful.
Input
The first line contains an integer t (1 β€ t β€ 10^4) β the number of test cases in the input. Then t test cases follow.
Each test case consists of one line, which contains a positive integer n (1 β€ n β€ 10^9) β how many years Polycarp has turned.
Output
Print t integers β the answers to the given test cases in the order they are written in the test. Each answer is an integer: the number of beautiful years between 1 and n, inclusive.
Example
Input
6
18
1
9
100500
33
1000000000
Output
10
1
9
45
12
81
Note
In the first test case of the example beautiful years are 1, 2, 3, 4, 5, 6, 7, 8, 9 and 11.
Submitted Solution:
```
t=int(input())
for i in range(t):
n=input()
y=list(n)
x=len(y)
a=(x-1)*9
for i in range(1,9):
if(int(str(i)*x)<=int(n)):
a=a+1
print(a)
```
No
| 60,781 | [
0.55859375,
0.03424072265625,
0.025299072265625,
0.0294189453125,
-0.4873046875,
-0.1495361328125,
-0.0279388427734375,
0.0789794921875,
0.262451171875,
0.384033203125,
0.60888671875,
-0.246337890625,
0.15283203125,
-0.65087890625,
-0.307861328125,
-0.13916015625,
-0.376708984375,
... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Hooray! Polycarp turned n years old! The Technocup Team sincerely congratulates Polycarp!
Polycarp celebrated all of his n birthdays: from the 1-th to the n-th. At the moment, he is wondering: how many times he turned beautiful number of years?
According to Polycarp, a positive integer is beautiful if it consists of only one digit repeated one or more times. For example, the following numbers are beautiful: 1, 77, 777, 44 and 999999. The following numbers are not beautiful: 12, 11110, 6969 and 987654321.
Of course, Polycarpus uses the decimal numeral system (i.e. radix is 10).
Help Polycarpus to find the number of numbers from 1 to n (inclusive) that are beautiful.
Input
The first line contains an integer t (1 β€ t β€ 10^4) β the number of test cases in the input. Then t test cases follow.
Each test case consists of one line, which contains a positive integer n (1 β€ n β€ 10^9) β how many years Polycarp has turned.
Output
Print t integers β the answers to the given test cases in the order they are written in the test. Each answer is an integer: the number of beautiful years between 1 and n, inclusive.
Example
Input
6
18
1
9
100500
33
1000000000
Output
10
1
9
45
12
81
Note
In the first test case of the example beautiful years are 1, 2, 3, 4, 5, 6, 7, 8, 9 and 11.
Submitted Solution:
```
for i in range(int(input())):
n=input()
l=len(n)
k=1
for i in n:
if int(i)<int(n[0]):
k=0
break
s=9*(l-1)+int(n[0])-1
if k==1:
s+=1
print(s)
```
No
| 60,782 | [
0.5576171875,
0.03704833984375,
0.026947021484375,
0.04290771484375,
-0.499267578125,
-0.1748046875,
-0.035247802734375,
0.07012939453125,
0.2354736328125,
0.408935546875,
0.60693359375,
-0.26220703125,
0.143310546875,
-0.64501953125,
-0.308349609375,
-0.1190185546875,
-0.3876953125,... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Hooray! Polycarp turned n years old! The Technocup Team sincerely congratulates Polycarp!
Polycarp celebrated all of his n birthdays: from the 1-th to the n-th. At the moment, he is wondering: how many times he turned beautiful number of years?
According to Polycarp, a positive integer is beautiful if it consists of only one digit repeated one or more times. For example, the following numbers are beautiful: 1, 77, 777, 44 and 999999. The following numbers are not beautiful: 12, 11110, 6969 and 987654321.
Of course, Polycarpus uses the decimal numeral system (i.e. radix is 10).
Help Polycarpus to find the number of numbers from 1 to n (inclusive) that are beautiful.
Input
The first line contains an integer t (1 β€ t β€ 10^4) β the number of test cases in the input. Then t test cases follow.
Each test case consists of one line, which contains a positive integer n (1 β€ n β€ 10^9) β how many years Polycarp has turned.
Output
Print t integers β the answers to the given test cases in the order they are written in the test. Each answer is an integer: the number of beautiful years between 1 and n, inclusive.
Example
Input
6
18
1
9
100500
33
1000000000
Output
10
1
9
45
12
81
Note
In the first test case of the example beautiful years are 1, 2, 3, 4, 5, 6, 7, 8, 9 and 11.
Submitted Solution:
```
# -*- coding: utf-8 -*-
"""
Created on Sun Oct 25 01:44:59 2020
@author: Dark Soul
"""
for _ in range(int(input(''))):
s=list(input(''))
l=len(s)
s.sort()
if l==0:
l=1
print(9*(l-1)+(int(s[0])==int(s[l-1]))*int(s[0]))
```
No
| 60,783 | [
0.5732421875,
0.01102447509765625,
0.0087738037109375,
0.0726318359375,
-0.44384765625,
-0.1636962890625,
-0.0243988037109375,
0.0712890625,
0.249755859375,
0.412353515625,
0.64990234375,
-0.275146484375,
0.1646728515625,
-0.57470703125,
-0.309326171875,
-0.1214599609375,
-0.38183593... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Hooray! Polycarp turned n years old! The Technocup Team sincerely congratulates Polycarp!
Polycarp celebrated all of his n birthdays: from the 1-th to the n-th. At the moment, he is wondering: how many times he turned beautiful number of years?
According to Polycarp, a positive integer is beautiful if it consists of only one digit repeated one or more times. For example, the following numbers are beautiful: 1, 77, 777, 44 and 999999. The following numbers are not beautiful: 12, 11110, 6969 and 987654321.
Of course, Polycarpus uses the decimal numeral system (i.e. radix is 10).
Help Polycarpus to find the number of numbers from 1 to n (inclusive) that are beautiful.
Input
The first line contains an integer t (1 β€ t β€ 10^4) β the number of test cases in the input. Then t test cases follow.
Each test case consists of one line, which contains a positive integer n (1 β€ n β€ 10^9) β how many years Polycarp has turned.
Output
Print t integers β the answers to the given test cases in the order they are written in the test. Each answer is an integer: the number of beautiful years between 1 and n, inclusive.
Example
Input
6
18
1
9
100500
33
1000000000
Output
10
1
9
45
12
81
Note
In the first test case of the example beautiful years are 1, 2, 3, 4, 5, 6, 7, 8, 9 and 11.
Submitted Solution:
```
# -*- coding: utf-8 -*-
"""
Created on Sun Oct 25 01:44:59 2020
@author: Dark Soul
"""
for _ in range(int(input(''))):
s=list(input(''))
l=len(s)
if l==1:
print(int(s[0]))
continue
ans=9*(l-1)
ans+=int(s[0])-1
s.sort()
if s[0]==s[l-1]:
ans+=1
print(ans)
```
No
| 60,784 | [
0.57421875,
0.016998291015625,
0.00904083251953125,
0.0604248046875,
-0.4501953125,
-0.14453125,
-0.014739990234375,
0.07757568359375,
0.262451171875,
0.3974609375,
0.63720703125,
-0.2900390625,
0.1591796875,
-0.57568359375,
-0.310791015625,
-0.12164306640625,
-0.369384765625,
-0.3... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The map of Bertown can be represented as a set of n intersections, numbered from 1 to n and connected by m one-way roads. It is possible to move along the roads from any intersection to any other intersection. The length of some path from one intersection to another is the number of roads that one has to traverse along the path. The shortest path from one intersection v to another intersection u is the path that starts in v, ends in u and has the minimum length among all such paths.
Polycarp lives near the intersection s and works in a building near the intersection t. Every day he gets from s to t by car. Today he has chosen the following path to his workplace: p_1, p_2, ..., p_k, where p_1 = s, p_k = t, and all other elements of this sequence are the intermediate intersections, listed in the order Polycarp arrived at them. Polycarp never arrived at the same intersection twice, so all elements of this sequence are pairwise distinct. Note that you know Polycarp's path beforehand (it is fixed), and it is not necessarily one of the shortest paths from s to t.
Polycarp's car has a complex navigation system installed in it. Let's describe how it works. When Polycarp starts his journey at the intersection s, the system chooses some shortest path from s to t and shows it to Polycarp. Let's denote the next intersection in the chosen path as v. If Polycarp chooses to drive along the road from s to v, then the navigator shows him the same shortest path (obviously, starting from v as soon as he arrives at this intersection). However, if Polycarp chooses to drive to another intersection w instead, the navigator rebuilds the path: as soon as Polycarp arrives at w, the navigation system chooses some shortest path from w to t and shows it to Polycarp. The same process continues until Polycarp arrives at t: if Polycarp moves along the road recommended by the system, it maintains the shortest path it has already built; but if Polycarp chooses some other path, the system rebuilds the path by the same rules.
Here is an example. Suppose the map of Bertown looks as follows, and Polycarp drives along the path [1, 2, 3, 4] (s = 1, t = 4):
Check the picture by the link [http://tk.codeforces.com/a.png](//tk.codeforces.com/a.png)
1. When Polycarp starts at 1, the system chooses some shortest path from 1 to 4. There is only one such path, it is [1, 5, 4];
2. Polycarp chooses to drive to 2, which is not along the path chosen by the system. When Polycarp arrives at 2, the navigator rebuilds the path by choosing some shortest path from 2 to 4, for example, [2, 6, 4] (note that it could choose [2, 3, 4]);
3. Polycarp chooses to drive to 3, which is not along the path chosen by the system. When Polycarp arrives at 3, the navigator rebuilds the path by choosing the only shortest path from 3 to 4, which is [3, 4];
4. Polycarp arrives at 4 along the road chosen by the navigator, so the system does not have to rebuild anything.
Overall, we get 2 rebuilds in this scenario. Note that if the system chose [2, 3, 4] instead of [2, 6, 4] during the second step, there would be only 1 rebuild (since Polycarp goes along the path, so the system maintains the path [3, 4] during the third step).
The example shows us that the number of rebuilds can differ even if the map of Bertown and the path chosen by Polycarp stays the same. Given this information (the map and Polycarp's path), can you determine the minimum and the maximum number of rebuilds that could have happened during the journey?
Input
The first line contains two integers n and m (2 β€ n β€ m β€ 2 β
10^5) β the number of intersections and one-way roads in Bertown, respectively.
Then m lines follow, each describing a road. Each line contains two integers u and v (1 β€ u, v β€ n, u β v) denoting a road from intersection u to intersection v. All roads in Bertown are pairwise distinct, which means that each ordered pair (u, v) appears at most once in these m lines (but if there is a road (u, v), the road (v, u) can also appear).
The following line contains one integer k (2 β€ k β€ n) β the number of intersections in Polycarp's path from home to his workplace.
The last line contains k integers p_1, p_2, ..., p_k (1 β€ p_i β€ n, all these integers are pairwise distinct) β the intersections along Polycarp's path in the order he arrived at them. p_1 is the intersection where Polycarp lives (s = p_1), and p_k is the intersection where Polycarp's workplace is situated (t = p_k). It is guaranteed that for every i β [1, k - 1] the road from p_i to p_{i + 1} exists, so the path goes along the roads of Bertown.
Output
Print two integers: the minimum and the maximum number of rebuilds that could have happened during the journey.
Examples
Input
6 9
1 5
5 4
1 2
2 3
3 4
4 1
2 6
6 4
4 2
4
1 2 3 4
Output
1 2
Input
7 7
1 2
2 3
3 4
4 5
5 6
6 7
7 1
7
1 2 3 4 5 6 7
Output
0 0
Input
8 13
8 7
8 6
7 5
7 4
6 5
6 4
5 3
5 2
4 3
4 2
3 1
2 1
1 8
5
8 7 5 2 1
Output
0 3
Tags: dfs and similar, graphs, shortest paths
Correct Solution:
```
from collections import defaultdict, deque
from sys import stdin
input = stdin.readline
if __name__ == '__main__':
n, m = map(int, input().split())
err = [tuple(map(int, input().split())) for _ in range(m)]
k = int(input())
prr = list(map(int, input().split()))
# Save reversed paths because we need BFS from t
dct = defaultdict(lambda: [])
for u, v in err:
dct[v].append(u)
# BFS from t
lim = 10 ** 6
cdct = defaultdict(lambda: (lim, 0))
r = prr[-1]
viz = {r}
q = deque(viz)
cdct[r] = (0, 1)
while q:
r = q.popleft()
d = cdct[r][0]
for c in dct[r]:
if c not in viz:
q.append(c)
viz.add(c)
cd, cp = cdct[c]
if d + 1 <= cd:
cdct[c] = d + 1, cp + 1
# For every step check if this has decreased distance
# if it did, min += 0
# otherwise min += 1
# For max:
# If there is more than one way -> Assume he has chosen the alternate way
# which makes max += 1
# however, if he actually chooses a path which is not optimal
# that has to be considered
# so we can decrease 1 if last p had more than one way
d = cdct[prr[0]][0] + 1
mn = 0
mx = 0
for i, p in enumerate(prr):
cd = cdct[p]
imn = int(cd[0] >= d)
mn += imn
d = cd[0]
if imn and cdct[prr[i - 1]][1] == 1:
mx += 1
mx += int(cd[1] > 1)
print(mn, mx)
```
| 60,785 | [
0.1834716796875,
0.39599609375,
0.0008940696716308594,
-0.07891845703125,
-0.0501708984375,
0.07489013671875,
-0.53564453125,
0.016571044921875,
0.2548828125,
0.9677734375,
1.0224609375,
-0.1876220703125,
0.11834716796875,
-0.87255859375,
-0.4052734375,
0.144775390625,
-0.62353515625... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The map of Bertown can be represented as a set of n intersections, numbered from 1 to n and connected by m one-way roads. It is possible to move along the roads from any intersection to any other intersection. The length of some path from one intersection to another is the number of roads that one has to traverse along the path. The shortest path from one intersection v to another intersection u is the path that starts in v, ends in u and has the minimum length among all such paths.
Polycarp lives near the intersection s and works in a building near the intersection t. Every day he gets from s to t by car. Today he has chosen the following path to his workplace: p_1, p_2, ..., p_k, where p_1 = s, p_k = t, and all other elements of this sequence are the intermediate intersections, listed in the order Polycarp arrived at them. Polycarp never arrived at the same intersection twice, so all elements of this sequence are pairwise distinct. Note that you know Polycarp's path beforehand (it is fixed), and it is not necessarily one of the shortest paths from s to t.
Polycarp's car has a complex navigation system installed in it. Let's describe how it works. When Polycarp starts his journey at the intersection s, the system chooses some shortest path from s to t and shows it to Polycarp. Let's denote the next intersection in the chosen path as v. If Polycarp chooses to drive along the road from s to v, then the navigator shows him the same shortest path (obviously, starting from v as soon as he arrives at this intersection). However, if Polycarp chooses to drive to another intersection w instead, the navigator rebuilds the path: as soon as Polycarp arrives at w, the navigation system chooses some shortest path from w to t and shows it to Polycarp. The same process continues until Polycarp arrives at t: if Polycarp moves along the road recommended by the system, it maintains the shortest path it has already built; but if Polycarp chooses some other path, the system rebuilds the path by the same rules.
Here is an example. Suppose the map of Bertown looks as follows, and Polycarp drives along the path [1, 2, 3, 4] (s = 1, t = 4):
Check the picture by the link [http://tk.codeforces.com/a.png](//tk.codeforces.com/a.png)
1. When Polycarp starts at 1, the system chooses some shortest path from 1 to 4. There is only one such path, it is [1, 5, 4];
2. Polycarp chooses to drive to 2, which is not along the path chosen by the system. When Polycarp arrives at 2, the navigator rebuilds the path by choosing some shortest path from 2 to 4, for example, [2, 6, 4] (note that it could choose [2, 3, 4]);
3. Polycarp chooses to drive to 3, which is not along the path chosen by the system. When Polycarp arrives at 3, the navigator rebuilds the path by choosing the only shortest path from 3 to 4, which is [3, 4];
4. Polycarp arrives at 4 along the road chosen by the navigator, so the system does not have to rebuild anything.
Overall, we get 2 rebuilds in this scenario. Note that if the system chose [2, 3, 4] instead of [2, 6, 4] during the second step, there would be only 1 rebuild (since Polycarp goes along the path, so the system maintains the path [3, 4] during the third step).
The example shows us that the number of rebuilds can differ even if the map of Bertown and the path chosen by Polycarp stays the same. Given this information (the map and Polycarp's path), can you determine the minimum and the maximum number of rebuilds that could have happened during the journey?
Input
The first line contains two integers n and m (2 β€ n β€ m β€ 2 β
10^5) β the number of intersections and one-way roads in Bertown, respectively.
Then m lines follow, each describing a road. Each line contains two integers u and v (1 β€ u, v β€ n, u β v) denoting a road from intersection u to intersection v. All roads in Bertown are pairwise distinct, which means that each ordered pair (u, v) appears at most once in these m lines (but if there is a road (u, v), the road (v, u) can also appear).
The following line contains one integer k (2 β€ k β€ n) β the number of intersections in Polycarp's path from home to his workplace.
The last line contains k integers p_1, p_2, ..., p_k (1 β€ p_i β€ n, all these integers are pairwise distinct) β the intersections along Polycarp's path in the order he arrived at them. p_1 is the intersection where Polycarp lives (s = p_1), and p_k is the intersection where Polycarp's workplace is situated (t = p_k). It is guaranteed that for every i β [1, k - 1] the road from p_i to p_{i + 1} exists, so the path goes along the roads of Bertown.
Output
Print two integers: the minimum and the maximum number of rebuilds that could have happened during the journey.
Examples
Input
6 9
1 5
5 4
1 2
2 3
3 4
4 1
2 6
6 4
4 2
4
1 2 3 4
Output
1 2
Input
7 7
1 2
2 3
3 4
4 5
5 6
6 7
7 1
7
1 2 3 4 5 6 7
Output
0 0
Input
8 13
8 7
8 6
7 5
7 4
6 5
6 4
5 3
5 2
4 3
4 2
3 1
2 1
1 8
5
8 7 5 2 1
Output
0 3
Tags: dfs and similar, graphs, shortest paths
Correct Solution:
```
n, m = map(int, input().split())
Q = [[]for _ in range(n)]
for _ in range(m):
u, v = map(int, input().split())
u -= 1
v -= 1
Q[v].append(u)
k = int(input())
p = [int(T) - 1 for T in input().split()]
W = [-1] * n
E = [0] * n
q = [(p[-1], 0)]
for u, d in q:
if W[u] < 0:
W[u] = d
d += 1
for v in Q[u]:
q.append((v, d))
elif W[u] == d:
E[u] += 1
R = S = 0
for i in range(1, k):
u, v = p[i - 1], p[i]
if W[u] <= W[v]:
R += 1
S += 1
elif E[u]:
S += 1
print(R, S)
```
| 60,786 | [
0.1834716796875,
0.39599609375,
0.0008940696716308594,
-0.07891845703125,
-0.0501708984375,
0.07489013671875,
-0.53564453125,
0.016571044921875,
0.2548828125,
0.9677734375,
1.0224609375,
-0.1876220703125,
0.11834716796875,
-0.87255859375,
-0.4052734375,
0.144775390625,
-0.62353515625... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The map of Bertown can be represented as a set of n intersections, numbered from 1 to n and connected by m one-way roads. It is possible to move along the roads from any intersection to any other intersection. The length of some path from one intersection to another is the number of roads that one has to traverse along the path. The shortest path from one intersection v to another intersection u is the path that starts in v, ends in u and has the minimum length among all such paths.
Polycarp lives near the intersection s and works in a building near the intersection t. Every day he gets from s to t by car. Today he has chosen the following path to his workplace: p_1, p_2, ..., p_k, where p_1 = s, p_k = t, and all other elements of this sequence are the intermediate intersections, listed in the order Polycarp arrived at them. Polycarp never arrived at the same intersection twice, so all elements of this sequence are pairwise distinct. Note that you know Polycarp's path beforehand (it is fixed), and it is not necessarily one of the shortest paths from s to t.
Polycarp's car has a complex navigation system installed in it. Let's describe how it works. When Polycarp starts his journey at the intersection s, the system chooses some shortest path from s to t and shows it to Polycarp. Let's denote the next intersection in the chosen path as v. If Polycarp chooses to drive along the road from s to v, then the navigator shows him the same shortest path (obviously, starting from v as soon as he arrives at this intersection). However, if Polycarp chooses to drive to another intersection w instead, the navigator rebuilds the path: as soon as Polycarp arrives at w, the navigation system chooses some shortest path from w to t and shows it to Polycarp. The same process continues until Polycarp arrives at t: if Polycarp moves along the road recommended by the system, it maintains the shortest path it has already built; but if Polycarp chooses some other path, the system rebuilds the path by the same rules.
Here is an example. Suppose the map of Bertown looks as follows, and Polycarp drives along the path [1, 2, 3, 4] (s = 1, t = 4):
Check the picture by the link [http://tk.codeforces.com/a.png](//tk.codeforces.com/a.png)
1. When Polycarp starts at 1, the system chooses some shortest path from 1 to 4. There is only one such path, it is [1, 5, 4];
2. Polycarp chooses to drive to 2, which is not along the path chosen by the system. When Polycarp arrives at 2, the navigator rebuilds the path by choosing some shortest path from 2 to 4, for example, [2, 6, 4] (note that it could choose [2, 3, 4]);
3. Polycarp chooses to drive to 3, which is not along the path chosen by the system. When Polycarp arrives at 3, the navigator rebuilds the path by choosing the only shortest path from 3 to 4, which is [3, 4];
4. Polycarp arrives at 4 along the road chosen by the navigator, so the system does not have to rebuild anything.
Overall, we get 2 rebuilds in this scenario. Note that if the system chose [2, 3, 4] instead of [2, 6, 4] during the second step, there would be only 1 rebuild (since Polycarp goes along the path, so the system maintains the path [3, 4] during the third step).
The example shows us that the number of rebuilds can differ even if the map of Bertown and the path chosen by Polycarp stays the same. Given this information (the map and Polycarp's path), can you determine the minimum and the maximum number of rebuilds that could have happened during the journey?
Input
The first line contains two integers n and m (2 β€ n β€ m β€ 2 β
10^5) β the number of intersections and one-way roads in Bertown, respectively.
Then m lines follow, each describing a road. Each line contains two integers u and v (1 β€ u, v β€ n, u β v) denoting a road from intersection u to intersection v. All roads in Bertown are pairwise distinct, which means that each ordered pair (u, v) appears at most once in these m lines (but if there is a road (u, v), the road (v, u) can also appear).
The following line contains one integer k (2 β€ k β€ n) β the number of intersections in Polycarp's path from home to his workplace.
The last line contains k integers p_1, p_2, ..., p_k (1 β€ p_i β€ n, all these integers are pairwise distinct) β the intersections along Polycarp's path in the order he arrived at them. p_1 is the intersection where Polycarp lives (s = p_1), and p_k is the intersection where Polycarp's workplace is situated (t = p_k). It is guaranteed that for every i β [1, k - 1] the road from p_i to p_{i + 1} exists, so the path goes along the roads of Bertown.
Output
Print two integers: the minimum and the maximum number of rebuilds that could have happened during the journey.
Examples
Input
6 9
1 5
5 4
1 2
2 3
3 4
4 1
2 6
6 4
4 2
4
1 2 3 4
Output
1 2
Input
7 7
1 2
2 3
3 4
4 5
5 6
6 7
7 1
7
1 2 3 4 5 6 7
Output
0 0
Input
8 13
8 7
8 6
7 5
7 4
6 5
6 4
5 3
5 2
4 3
4 2
3 1
2 1
1 8
5
8 7 5 2 1
Output
0 3
Tags: dfs and similar, graphs, shortest paths
Correct Solution:
```
# from debug import debug
inf = int(1e10)
n, m = map(int, input().split())
trans = [[] for i in range(n)]
graph = [[] for i in range(n)]
for i in range(m):
a,b = map(int, input().split())
trans[b-1].append(a-1)
graph[a-1].append(b-1)
k = int(input())
lis = [x-1 for x in map(int, input().split())]
s, d = lis[0], lis[-1]
v = [0]*n
dis = [inf]*n
v[d] = 1
dis[d] = 0
q = [d]
while q:
node = q.pop(0)
for i in trans[node]:
if not v[i] and dis[i] > dis[node]+1:
dis[i] = dis[node] + 1
q.append(i)
reb, ad = 0, 0
prev = s
for i in range(1, k-1):
if dis[lis[i]] + 1 > dis[prev]:
reb+=1
for j in graph[prev]:
if j != lis[i] and dis[j] + 1 == dis[prev]:
ad+=1
break
prev = lis[i]
print(reb, ad)
```
| 60,787 | [
0.1834716796875,
0.39599609375,
0.0008940696716308594,
-0.07891845703125,
-0.0501708984375,
0.07489013671875,
-0.53564453125,
0.016571044921875,
0.2548828125,
0.9677734375,
1.0224609375,
-0.1876220703125,
0.11834716796875,
-0.87255859375,
-0.4052734375,
0.144775390625,
-0.62353515625... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The map of Bertown can be represented as a set of n intersections, numbered from 1 to n and connected by m one-way roads. It is possible to move along the roads from any intersection to any other intersection. The length of some path from one intersection to another is the number of roads that one has to traverse along the path. The shortest path from one intersection v to another intersection u is the path that starts in v, ends in u and has the minimum length among all such paths.
Polycarp lives near the intersection s and works in a building near the intersection t. Every day he gets from s to t by car. Today he has chosen the following path to his workplace: p_1, p_2, ..., p_k, where p_1 = s, p_k = t, and all other elements of this sequence are the intermediate intersections, listed in the order Polycarp arrived at them. Polycarp never arrived at the same intersection twice, so all elements of this sequence are pairwise distinct. Note that you know Polycarp's path beforehand (it is fixed), and it is not necessarily one of the shortest paths from s to t.
Polycarp's car has a complex navigation system installed in it. Let's describe how it works. When Polycarp starts his journey at the intersection s, the system chooses some shortest path from s to t and shows it to Polycarp. Let's denote the next intersection in the chosen path as v. If Polycarp chooses to drive along the road from s to v, then the navigator shows him the same shortest path (obviously, starting from v as soon as he arrives at this intersection). However, if Polycarp chooses to drive to another intersection w instead, the navigator rebuilds the path: as soon as Polycarp arrives at w, the navigation system chooses some shortest path from w to t and shows it to Polycarp. The same process continues until Polycarp arrives at t: if Polycarp moves along the road recommended by the system, it maintains the shortest path it has already built; but if Polycarp chooses some other path, the system rebuilds the path by the same rules.
Here is an example. Suppose the map of Bertown looks as follows, and Polycarp drives along the path [1, 2, 3, 4] (s = 1, t = 4):
Check the picture by the link [http://tk.codeforces.com/a.png](//tk.codeforces.com/a.png)
1. When Polycarp starts at 1, the system chooses some shortest path from 1 to 4. There is only one such path, it is [1, 5, 4];
2. Polycarp chooses to drive to 2, which is not along the path chosen by the system. When Polycarp arrives at 2, the navigator rebuilds the path by choosing some shortest path from 2 to 4, for example, [2, 6, 4] (note that it could choose [2, 3, 4]);
3. Polycarp chooses to drive to 3, which is not along the path chosen by the system. When Polycarp arrives at 3, the navigator rebuilds the path by choosing the only shortest path from 3 to 4, which is [3, 4];
4. Polycarp arrives at 4 along the road chosen by the navigator, so the system does not have to rebuild anything.
Overall, we get 2 rebuilds in this scenario. Note that if the system chose [2, 3, 4] instead of [2, 6, 4] during the second step, there would be only 1 rebuild (since Polycarp goes along the path, so the system maintains the path [3, 4] during the third step).
The example shows us that the number of rebuilds can differ even if the map of Bertown and the path chosen by Polycarp stays the same. Given this information (the map and Polycarp's path), can you determine the minimum and the maximum number of rebuilds that could have happened during the journey?
Input
The first line contains two integers n and m (2 β€ n β€ m β€ 2 β
10^5) β the number of intersections and one-way roads in Bertown, respectively.
Then m lines follow, each describing a road. Each line contains two integers u and v (1 β€ u, v β€ n, u β v) denoting a road from intersection u to intersection v. All roads in Bertown are pairwise distinct, which means that each ordered pair (u, v) appears at most once in these m lines (but if there is a road (u, v), the road (v, u) can also appear).
The following line contains one integer k (2 β€ k β€ n) β the number of intersections in Polycarp's path from home to his workplace.
The last line contains k integers p_1, p_2, ..., p_k (1 β€ p_i β€ n, all these integers are pairwise distinct) β the intersections along Polycarp's path in the order he arrived at them. p_1 is the intersection where Polycarp lives (s = p_1), and p_k is the intersection where Polycarp's workplace is situated (t = p_k). It is guaranteed that for every i β [1, k - 1] the road from p_i to p_{i + 1} exists, so the path goes along the roads of Bertown.
Output
Print two integers: the minimum and the maximum number of rebuilds that could have happened during the journey.
Examples
Input
6 9
1 5
5 4
1 2
2 3
3 4
4 1
2 6
6 4
4 2
4
1 2 3 4
Output
1 2
Input
7 7
1 2
2 3
3 4
4 5
5 6
6 7
7 1
7
1 2 3 4 5 6 7
Output
0 0
Input
8 13
8 7
8 6
7 5
7 4
6 5
6 4
5 3
5 2
4 3
4 2
3 1
2 1
1 8
5
8 7 5 2 1
Output
0 3
Tags: dfs and similar, graphs, shortest paths
Correct Solution:
```
from collections import deque
from sys import stdin
nV, nE = map(int, stdin.readline().split())
g = [[] for _ in range(nV + 1)]
rev = [[] for _ in range(nV + 1)]
for _ in range(nE):
u, v = map(int, stdin.readline().split())
g[u].append(v)
rev[v].append(u)
k = int(stdin.readline())
path = list(map(int, stdin.readline().split()))
def bfs(s, g):
UNDEF = -1
dist = [UNDEF] * (nV + 1)
dist[s] = 0
q = deque([s])
while q:
v = q.pop()
for to in g[v]:
if dist[to] == UNDEF:
dist[to] = 1 + dist[v]
q.appendleft(to)
return dist
dist = bfs(path[-1], rev)
mn = mx = 0
prev = None
for v in path:
if prev and dist[v] > dist[prev] - 1:
mn += 1
mx += 1
if prev and dist[v] == dist[prev] - 1:
for to in g[prev]:
if to != v and dist[to] == dist[v]:
mx += 1
break
prev = v
print('%d %d' % (mn, mx))
```
| 60,788 | [
0.1834716796875,
0.39599609375,
0.0008940696716308594,
-0.07891845703125,
-0.0501708984375,
0.07489013671875,
-0.53564453125,
0.016571044921875,
0.2548828125,
0.9677734375,
1.0224609375,
-0.1876220703125,
0.11834716796875,
-0.87255859375,
-0.4052734375,
0.144775390625,
-0.62353515625... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The map of Bertown can be represented as a set of n intersections, numbered from 1 to n and connected by m one-way roads. It is possible to move along the roads from any intersection to any other intersection. The length of some path from one intersection to another is the number of roads that one has to traverse along the path. The shortest path from one intersection v to another intersection u is the path that starts in v, ends in u and has the minimum length among all such paths.
Polycarp lives near the intersection s and works in a building near the intersection t. Every day he gets from s to t by car. Today he has chosen the following path to his workplace: p_1, p_2, ..., p_k, where p_1 = s, p_k = t, and all other elements of this sequence are the intermediate intersections, listed in the order Polycarp arrived at them. Polycarp never arrived at the same intersection twice, so all elements of this sequence are pairwise distinct. Note that you know Polycarp's path beforehand (it is fixed), and it is not necessarily one of the shortest paths from s to t.
Polycarp's car has a complex navigation system installed in it. Let's describe how it works. When Polycarp starts his journey at the intersection s, the system chooses some shortest path from s to t and shows it to Polycarp. Let's denote the next intersection in the chosen path as v. If Polycarp chooses to drive along the road from s to v, then the navigator shows him the same shortest path (obviously, starting from v as soon as he arrives at this intersection). However, if Polycarp chooses to drive to another intersection w instead, the navigator rebuilds the path: as soon as Polycarp arrives at w, the navigation system chooses some shortest path from w to t and shows it to Polycarp. The same process continues until Polycarp arrives at t: if Polycarp moves along the road recommended by the system, it maintains the shortest path it has already built; but if Polycarp chooses some other path, the system rebuilds the path by the same rules.
Here is an example. Suppose the map of Bertown looks as follows, and Polycarp drives along the path [1, 2, 3, 4] (s = 1, t = 4):
Check the picture by the link [http://tk.codeforces.com/a.png](//tk.codeforces.com/a.png)
1. When Polycarp starts at 1, the system chooses some shortest path from 1 to 4. There is only one such path, it is [1, 5, 4];
2. Polycarp chooses to drive to 2, which is not along the path chosen by the system. When Polycarp arrives at 2, the navigator rebuilds the path by choosing some shortest path from 2 to 4, for example, [2, 6, 4] (note that it could choose [2, 3, 4]);
3. Polycarp chooses to drive to 3, which is not along the path chosen by the system. When Polycarp arrives at 3, the navigator rebuilds the path by choosing the only shortest path from 3 to 4, which is [3, 4];
4. Polycarp arrives at 4 along the road chosen by the navigator, so the system does not have to rebuild anything.
Overall, we get 2 rebuilds in this scenario. Note that if the system chose [2, 3, 4] instead of [2, 6, 4] during the second step, there would be only 1 rebuild (since Polycarp goes along the path, so the system maintains the path [3, 4] during the third step).
The example shows us that the number of rebuilds can differ even if the map of Bertown and the path chosen by Polycarp stays the same. Given this information (the map and Polycarp's path), can you determine the minimum and the maximum number of rebuilds that could have happened during the journey?
Input
The first line contains two integers n and m (2 β€ n β€ m β€ 2 β
10^5) β the number of intersections and one-way roads in Bertown, respectively.
Then m lines follow, each describing a road. Each line contains two integers u and v (1 β€ u, v β€ n, u β v) denoting a road from intersection u to intersection v. All roads in Bertown are pairwise distinct, which means that each ordered pair (u, v) appears at most once in these m lines (but if there is a road (u, v), the road (v, u) can also appear).
The following line contains one integer k (2 β€ k β€ n) β the number of intersections in Polycarp's path from home to his workplace.
The last line contains k integers p_1, p_2, ..., p_k (1 β€ p_i β€ n, all these integers are pairwise distinct) β the intersections along Polycarp's path in the order he arrived at them. p_1 is the intersection where Polycarp lives (s = p_1), and p_k is the intersection where Polycarp's workplace is situated (t = p_k). It is guaranteed that for every i β [1, k - 1] the road from p_i to p_{i + 1} exists, so the path goes along the roads of Bertown.
Output
Print two integers: the minimum and the maximum number of rebuilds that could have happened during the journey.
Examples
Input
6 9
1 5
5 4
1 2
2 3
3 4
4 1
2 6
6 4
4 2
4
1 2 3 4
Output
1 2
Input
7 7
1 2
2 3
3 4
4 5
5 6
6 7
7 1
7
1 2 3 4 5 6 7
Output
0 0
Input
8 13
8 7
8 6
7 5
7 4
6 5
6 4
5 3
5 2
4 3
4 2
3 1
2 1
1 8
5
8 7 5 2 1
Output
0 3
Tags: dfs and similar, graphs, shortest paths
Correct Solution:
```
# Legends Always Come Up with Solution
# Author: Manvir Singh
import os
import sys
from io import BytesIO, IOBase
from collections import deque
def bfs(tree,s):
n=len(tree)
h=[0]*(n+1)
v=[0]*(n+1)
q=deque()
q.append((s,0))
v[s]=1
while q:
c,p=q.popleft()
h[c]=h[p]+1
for i in tree[c]:
if not v[i]:
q.append((i,c))
v[i]=1
return h
def main():
n,m=map(int,input().split())
tree=[[] for _ in range(n+1)]
tree1=[[] for _ in range(n+1)]
for _ in range(m):
x,y=map(int,input().split())
tree[x].append(y)
tree1[y].append(x)
k=int(input())
a=list(map(int,input().split()))
h,mi,ma=bfs(tree1,a[-1]),0,0
for i in range(k-1):
if h[a[i+1]]>h[a[i]]-1:
mi,ma=mi+1,ma+1
else:
f=0
for j in tree[a[i]]:
if h[j]==h[a[i]]-1 and j!=a[i+1]:
f=1
break
ma+=f
print(mi,ma)
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
if __name__ == "__main__":
main()
```
| 60,789 | [
0.1834716796875,
0.39599609375,
0.0008940696716308594,
-0.07891845703125,
-0.0501708984375,
0.07489013671875,
-0.53564453125,
0.016571044921875,
0.2548828125,
0.9677734375,
1.0224609375,
-0.1876220703125,
0.11834716796875,
-0.87255859375,
-0.4052734375,
0.144775390625,
-0.62353515625... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The map of Bertown can be represented as a set of n intersections, numbered from 1 to n and connected by m one-way roads. It is possible to move along the roads from any intersection to any other intersection. The length of some path from one intersection to another is the number of roads that one has to traverse along the path. The shortest path from one intersection v to another intersection u is the path that starts in v, ends in u and has the minimum length among all such paths.
Polycarp lives near the intersection s and works in a building near the intersection t. Every day he gets from s to t by car. Today he has chosen the following path to his workplace: p_1, p_2, ..., p_k, where p_1 = s, p_k = t, and all other elements of this sequence are the intermediate intersections, listed in the order Polycarp arrived at them. Polycarp never arrived at the same intersection twice, so all elements of this sequence are pairwise distinct. Note that you know Polycarp's path beforehand (it is fixed), and it is not necessarily one of the shortest paths from s to t.
Polycarp's car has a complex navigation system installed in it. Let's describe how it works. When Polycarp starts his journey at the intersection s, the system chooses some shortest path from s to t and shows it to Polycarp. Let's denote the next intersection in the chosen path as v. If Polycarp chooses to drive along the road from s to v, then the navigator shows him the same shortest path (obviously, starting from v as soon as he arrives at this intersection). However, if Polycarp chooses to drive to another intersection w instead, the navigator rebuilds the path: as soon as Polycarp arrives at w, the navigation system chooses some shortest path from w to t and shows it to Polycarp. The same process continues until Polycarp arrives at t: if Polycarp moves along the road recommended by the system, it maintains the shortest path it has already built; but if Polycarp chooses some other path, the system rebuilds the path by the same rules.
Here is an example. Suppose the map of Bertown looks as follows, and Polycarp drives along the path [1, 2, 3, 4] (s = 1, t = 4):
Check the picture by the link [http://tk.codeforces.com/a.png](//tk.codeforces.com/a.png)
1. When Polycarp starts at 1, the system chooses some shortest path from 1 to 4. There is only one such path, it is [1, 5, 4];
2. Polycarp chooses to drive to 2, which is not along the path chosen by the system. When Polycarp arrives at 2, the navigator rebuilds the path by choosing some shortest path from 2 to 4, for example, [2, 6, 4] (note that it could choose [2, 3, 4]);
3. Polycarp chooses to drive to 3, which is not along the path chosen by the system. When Polycarp arrives at 3, the navigator rebuilds the path by choosing the only shortest path from 3 to 4, which is [3, 4];
4. Polycarp arrives at 4 along the road chosen by the navigator, so the system does not have to rebuild anything.
Overall, we get 2 rebuilds in this scenario. Note that if the system chose [2, 3, 4] instead of [2, 6, 4] during the second step, there would be only 1 rebuild (since Polycarp goes along the path, so the system maintains the path [3, 4] during the third step).
The example shows us that the number of rebuilds can differ even if the map of Bertown and the path chosen by Polycarp stays the same. Given this information (the map and Polycarp's path), can you determine the minimum and the maximum number of rebuilds that could have happened during the journey?
Input
The first line contains two integers n and m (2 β€ n β€ m β€ 2 β
10^5) β the number of intersections and one-way roads in Bertown, respectively.
Then m lines follow, each describing a road. Each line contains two integers u and v (1 β€ u, v β€ n, u β v) denoting a road from intersection u to intersection v. All roads in Bertown are pairwise distinct, which means that each ordered pair (u, v) appears at most once in these m lines (but if there is a road (u, v), the road (v, u) can also appear).
The following line contains one integer k (2 β€ k β€ n) β the number of intersections in Polycarp's path from home to his workplace.
The last line contains k integers p_1, p_2, ..., p_k (1 β€ p_i β€ n, all these integers are pairwise distinct) β the intersections along Polycarp's path in the order he arrived at them. p_1 is the intersection where Polycarp lives (s = p_1), and p_k is the intersection where Polycarp's workplace is situated (t = p_k). It is guaranteed that for every i β [1, k - 1] the road from p_i to p_{i + 1} exists, so the path goes along the roads of Bertown.
Output
Print two integers: the minimum and the maximum number of rebuilds that could have happened during the journey.
Examples
Input
6 9
1 5
5 4
1 2
2 3
3 4
4 1
2 6
6 4
4 2
4
1 2 3 4
Output
1 2
Input
7 7
1 2
2 3
3 4
4 5
5 6
6 7
7 1
7
1 2 3 4 5 6 7
Output
0 0
Input
8 13
8 7
8 6
7 5
7 4
6 5
6 4
5 3
5 2
4 3
4 2
3 1
2 1
1 8
5
8 7 5 2 1
Output
0 3
Tags: dfs and similar, graphs, shortest paths
Correct Solution:
```
import sys
n, m = list(map(int, sys.stdin.readline().strip().split()))
N = [[] for i in range (0, n+1)]
N2 = [[] for i in range (0, n+1)]
for i in range (0, m):
u, v = list(map(int, sys.stdin.readline().strip().split()))
N[u].append(v)
N2[v].append(u)
D = [n+10] * (n+1)
k = int(sys.stdin.readline().strip())
p = list(map(int, sys.stdin.readline().strip().split()))
D[p[k-1]] = 0
L = [p[k-1]]
i = 0
while i < len(L):
u = L[i]
for v in N2[u]:
if D[v] > D[u] + 1:
D[v] = D[u] + 1
L.append(v)
i = i + 1
m = 0
M = 0
for i in range (0, k-1):
q = p[i]
r = p[i+1]
if D[q] != 1 + D[r]:
m = m + 1
M = M + 1
c = 0
for v in N[q]:
if D[v] + 1 == D[q]:
c = c + 1
if c != 1 and D[q] == 1 + D[r]:
M = M + 1
print(m, M)
```
| 60,790 | [
0.1834716796875,
0.39599609375,
0.0008940696716308594,
-0.07891845703125,
-0.0501708984375,
0.07489013671875,
-0.53564453125,
0.016571044921875,
0.2548828125,
0.9677734375,
1.0224609375,
-0.1876220703125,
0.11834716796875,
-0.87255859375,
-0.4052734375,
0.144775390625,
-0.62353515625... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The map of Bertown can be represented as a set of n intersections, numbered from 1 to n and connected by m one-way roads. It is possible to move along the roads from any intersection to any other intersection. The length of some path from one intersection to another is the number of roads that one has to traverse along the path. The shortest path from one intersection v to another intersection u is the path that starts in v, ends in u and has the minimum length among all such paths.
Polycarp lives near the intersection s and works in a building near the intersection t. Every day he gets from s to t by car. Today he has chosen the following path to his workplace: p_1, p_2, ..., p_k, where p_1 = s, p_k = t, and all other elements of this sequence are the intermediate intersections, listed in the order Polycarp arrived at them. Polycarp never arrived at the same intersection twice, so all elements of this sequence are pairwise distinct. Note that you know Polycarp's path beforehand (it is fixed), and it is not necessarily one of the shortest paths from s to t.
Polycarp's car has a complex navigation system installed in it. Let's describe how it works. When Polycarp starts his journey at the intersection s, the system chooses some shortest path from s to t and shows it to Polycarp. Let's denote the next intersection in the chosen path as v. If Polycarp chooses to drive along the road from s to v, then the navigator shows him the same shortest path (obviously, starting from v as soon as he arrives at this intersection). However, if Polycarp chooses to drive to another intersection w instead, the navigator rebuilds the path: as soon as Polycarp arrives at w, the navigation system chooses some shortest path from w to t and shows it to Polycarp. The same process continues until Polycarp arrives at t: if Polycarp moves along the road recommended by the system, it maintains the shortest path it has already built; but if Polycarp chooses some other path, the system rebuilds the path by the same rules.
Here is an example. Suppose the map of Bertown looks as follows, and Polycarp drives along the path [1, 2, 3, 4] (s = 1, t = 4):
Check the picture by the link [http://tk.codeforces.com/a.png](//tk.codeforces.com/a.png)
1. When Polycarp starts at 1, the system chooses some shortest path from 1 to 4. There is only one such path, it is [1, 5, 4];
2. Polycarp chooses to drive to 2, which is not along the path chosen by the system. When Polycarp arrives at 2, the navigator rebuilds the path by choosing some shortest path from 2 to 4, for example, [2, 6, 4] (note that it could choose [2, 3, 4]);
3. Polycarp chooses to drive to 3, which is not along the path chosen by the system. When Polycarp arrives at 3, the navigator rebuilds the path by choosing the only shortest path from 3 to 4, which is [3, 4];
4. Polycarp arrives at 4 along the road chosen by the navigator, so the system does not have to rebuild anything.
Overall, we get 2 rebuilds in this scenario. Note that if the system chose [2, 3, 4] instead of [2, 6, 4] during the second step, there would be only 1 rebuild (since Polycarp goes along the path, so the system maintains the path [3, 4] during the third step).
The example shows us that the number of rebuilds can differ even if the map of Bertown and the path chosen by Polycarp stays the same. Given this information (the map and Polycarp's path), can you determine the minimum and the maximum number of rebuilds that could have happened during the journey?
Input
The first line contains two integers n and m (2 β€ n β€ m β€ 2 β
10^5) β the number of intersections and one-way roads in Bertown, respectively.
Then m lines follow, each describing a road. Each line contains two integers u and v (1 β€ u, v β€ n, u β v) denoting a road from intersection u to intersection v. All roads in Bertown are pairwise distinct, which means that each ordered pair (u, v) appears at most once in these m lines (but if there is a road (u, v), the road (v, u) can also appear).
The following line contains one integer k (2 β€ k β€ n) β the number of intersections in Polycarp's path from home to his workplace.
The last line contains k integers p_1, p_2, ..., p_k (1 β€ p_i β€ n, all these integers are pairwise distinct) β the intersections along Polycarp's path in the order he arrived at them. p_1 is the intersection where Polycarp lives (s = p_1), and p_k is the intersection where Polycarp's workplace is situated (t = p_k). It is guaranteed that for every i β [1, k - 1] the road from p_i to p_{i + 1} exists, so the path goes along the roads of Bertown.
Output
Print two integers: the minimum and the maximum number of rebuilds that could have happened during the journey.
Examples
Input
6 9
1 5
5 4
1 2
2 3
3 4
4 1
2 6
6 4
4 2
4
1 2 3 4
Output
1 2
Input
7 7
1 2
2 3
3 4
4 5
5 6
6 7
7 1
7
1 2 3 4 5 6 7
Output
0 0
Input
8 13
8 7
8 6
7 5
7 4
6 5
6 4
5 3
5 2
4 3
4 2
3 1
2 1
1 8
5
8 7 5 2 1
Output
0 3
Tags: dfs and similar, graphs, shortest paths
Correct Solution:
```
from types import GeneratorType
INF = 1e10
def bootstrap(f, stack=[]):
def wrappedfunc(*args, **kwargs):
if stack:
return f(*args, **kwargs)
else:
to = f(*args, **kwargs)
while True:
if type(to) is GeneratorType:
stack.append(to)
to = next(to)
else:
stack.pop()
if not stack:
break
to = stack[-1].send(to)
return to
return wrappedfunc
class Graph:
def __init__(self, V):
self.V = V
self.adj = [[] for i in range(V)]
def addEdge(self, v, w):
self.adj[v].append(w)
import sys
input = sys.stdin.readline
n, m = list(map(int, input().split()))
G = Graph(n)
G_transpose = Graph(n)
for _ in range(m):
u, v = list(map(int, input().split()))
G.addEdge(u - 1, v - 1)
G_transpose.addEdge(v - 1, u - 1)
minimums = [0 for _ in range(n)]
mini = [0 for _ in range(n)]
from collections import deque
def BFS_SP(graph, start):
explored = set()
queue = deque([start])
dz = set()
while queue:
node = queue.popleft()
if node not in explored:
neighbours = graph.adj[node]
# print(neighbours)
# print(sd)
for neighbour in neighbours:
if neighbour not in dz:
sd[neighbour] = sd[node] + 1
minimums[neighbour] = sd[node] + 1
mini[neighbour] = 1
dz.add(neighbour)
queue.append(neighbour)
else:
# print(node,neighbour,sd[node],minimums[neighbour])
if sd[node] + 1 == minimums[neighbour]:
mini[neighbour] += 1
explored.add(node)
k = int(input())
path = list(map(int, input().split()))
sd = [INF for _ in range(n)]
sd[path[-1] - 1] = 0
BFS_SP(G_transpose, path[-1] - 1)
ans_min = 0
ans_max = 0
# print(distances,child_distances_from_goal)
# print(path)
for i in range(0, len(path) - 1):
# print(i)
next_dist = sd[path[i + 1] - 1]
# print(all_distances)
if sd[path[i] - 1] == sd[path[i + 1] - 1] + 1:
if mini[path[i] - 1] > 1:
ans_max += 1
else:
ans_min += 1
ans_max += 1
# print(ans_min, ans_max)
print(ans_min - 1, ans_max - 1)
#
```
| 60,791 | [
0.1834716796875,
0.39599609375,
0.0008940696716308594,
-0.07891845703125,
-0.0501708984375,
0.07489013671875,
-0.53564453125,
0.016571044921875,
0.2548828125,
0.9677734375,
1.0224609375,
-0.1876220703125,
0.11834716796875,
-0.87255859375,
-0.4052734375,
0.144775390625,
-0.62353515625... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The map of Bertown can be represented as a set of n intersections, numbered from 1 to n and connected by m one-way roads. It is possible to move along the roads from any intersection to any other intersection. The length of some path from one intersection to another is the number of roads that one has to traverse along the path. The shortest path from one intersection v to another intersection u is the path that starts in v, ends in u and has the minimum length among all such paths.
Polycarp lives near the intersection s and works in a building near the intersection t. Every day he gets from s to t by car. Today he has chosen the following path to his workplace: p_1, p_2, ..., p_k, where p_1 = s, p_k = t, and all other elements of this sequence are the intermediate intersections, listed in the order Polycarp arrived at them. Polycarp never arrived at the same intersection twice, so all elements of this sequence are pairwise distinct. Note that you know Polycarp's path beforehand (it is fixed), and it is not necessarily one of the shortest paths from s to t.
Polycarp's car has a complex navigation system installed in it. Let's describe how it works. When Polycarp starts his journey at the intersection s, the system chooses some shortest path from s to t and shows it to Polycarp. Let's denote the next intersection in the chosen path as v. If Polycarp chooses to drive along the road from s to v, then the navigator shows him the same shortest path (obviously, starting from v as soon as he arrives at this intersection). However, if Polycarp chooses to drive to another intersection w instead, the navigator rebuilds the path: as soon as Polycarp arrives at w, the navigation system chooses some shortest path from w to t and shows it to Polycarp. The same process continues until Polycarp arrives at t: if Polycarp moves along the road recommended by the system, it maintains the shortest path it has already built; but if Polycarp chooses some other path, the system rebuilds the path by the same rules.
Here is an example. Suppose the map of Bertown looks as follows, and Polycarp drives along the path [1, 2, 3, 4] (s = 1, t = 4):
Check the picture by the link [http://tk.codeforces.com/a.png](//tk.codeforces.com/a.png)
1. When Polycarp starts at 1, the system chooses some shortest path from 1 to 4. There is only one such path, it is [1, 5, 4];
2. Polycarp chooses to drive to 2, which is not along the path chosen by the system. When Polycarp arrives at 2, the navigator rebuilds the path by choosing some shortest path from 2 to 4, for example, [2, 6, 4] (note that it could choose [2, 3, 4]);
3. Polycarp chooses to drive to 3, which is not along the path chosen by the system. When Polycarp arrives at 3, the navigator rebuilds the path by choosing the only shortest path from 3 to 4, which is [3, 4];
4. Polycarp arrives at 4 along the road chosen by the navigator, so the system does not have to rebuild anything.
Overall, we get 2 rebuilds in this scenario. Note that if the system chose [2, 3, 4] instead of [2, 6, 4] during the second step, there would be only 1 rebuild (since Polycarp goes along the path, so the system maintains the path [3, 4] during the third step).
The example shows us that the number of rebuilds can differ even if the map of Bertown and the path chosen by Polycarp stays the same. Given this information (the map and Polycarp's path), can you determine the minimum and the maximum number of rebuilds that could have happened during the journey?
Input
The first line contains two integers n and m (2 β€ n β€ m β€ 2 β
10^5) β the number of intersections and one-way roads in Bertown, respectively.
Then m lines follow, each describing a road. Each line contains two integers u and v (1 β€ u, v β€ n, u β v) denoting a road from intersection u to intersection v. All roads in Bertown are pairwise distinct, which means that each ordered pair (u, v) appears at most once in these m lines (but if there is a road (u, v), the road (v, u) can also appear).
The following line contains one integer k (2 β€ k β€ n) β the number of intersections in Polycarp's path from home to his workplace.
The last line contains k integers p_1, p_2, ..., p_k (1 β€ p_i β€ n, all these integers are pairwise distinct) β the intersections along Polycarp's path in the order he arrived at them. p_1 is the intersection where Polycarp lives (s = p_1), and p_k is the intersection where Polycarp's workplace is situated (t = p_k). It is guaranteed that for every i β [1, k - 1] the road from p_i to p_{i + 1} exists, so the path goes along the roads of Bertown.
Output
Print two integers: the minimum and the maximum number of rebuilds that could have happened during the journey.
Examples
Input
6 9
1 5
5 4
1 2
2 3
3 4
4 1
2 6
6 4
4 2
4
1 2 3 4
Output
1 2
Input
7 7
1 2
2 3
3 4
4 5
5 6
6 7
7 1
7
1 2 3 4 5 6 7
Output
0 0
Input
8 13
8 7
8 6
7 5
7 4
6 5
6 4
5 3
5 2
4 3
4 2
3 1
2 1
1 8
5
8 7 5 2 1
Output
0 3
Tags: dfs and similar, graphs, shortest paths
Correct Solution:
```
import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
from heapq import heappop, heappush
def multi_dijkstra(G, starts):
n = len(G)
dist = [float("inf")]*n
visited = set()
heap = []
for i in starts:
heap.append((0, i))
while heap and len(visited) != n:
d, cur = heappop(heap)
if cur in visited:
continue
visited.add(cur)
dist[cur] = d
for to in G[cur]:
if to not in visited:
heappush(heap, (d+1, to))
return dist
n,m = map(int, input().split())
G = [[] for i in range(n)]
Gr = [[] for i in range(n)]
for i in range(m):
a,b = map(int, input().split())
a,b = a-1,b-1
Gr[a].append(b)
G[b].append(a)
k = int(input())
p = list(map(int, input().split()))
p = [i-1 for i in p]
s,t = p[0], p[-1]
dist = multi_dijkstra(G, [t])
mi = ma = 0
cur = s
for i in range(1, k-1):
nxt = p[i]
d = dist[cur]
f = False
dists = [dist[to] for to in Gr[cur]]
d_min = min(dists)
if dist[nxt] != d_min:
mi += 1
ma += 1
else:
if dists.count(d_min) > 1:
ma += 1
cur = nxt
print(mi, ma)
```
| 60,792 | [
0.1834716796875,
0.39599609375,
0.0008940696716308594,
-0.07891845703125,
-0.0501708984375,
0.07489013671875,
-0.53564453125,
0.016571044921875,
0.2548828125,
0.9677734375,
1.0224609375,
-0.1876220703125,
0.11834716796875,
-0.87255859375,
-0.4052734375,
0.144775390625,
-0.62353515625... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The map of Bertown can be represented as a set of n intersections, numbered from 1 to n and connected by m one-way roads. It is possible to move along the roads from any intersection to any other intersection. The length of some path from one intersection to another is the number of roads that one has to traverse along the path. The shortest path from one intersection v to another intersection u is the path that starts in v, ends in u and has the minimum length among all such paths.
Polycarp lives near the intersection s and works in a building near the intersection t. Every day he gets from s to t by car. Today he has chosen the following path to his workplace: p_1, p_2, ..., p_k, where p_1 = s, p_k = t, and all other elements of this sequence are the intermediate intersections, listed in the order Polycarp arrived at them. Polycarp never arrived at the same intersection twice, so all elements of this sequence are pairwise distinct. Note that you know Polycarp's path beforehand (it is fixed), and it is not necessarily one of the shortest paths from s to t.
Polycarp's car has a complex navigation system installed in it. Let's describe how it works. When Polycarp starts his journey at the intersection s, the system chooses some shortest path from s to t and shows it to Polycarp. Let's denote the next intersection in the chosen path as v. If Polycarp chooses to drive along the road from s to v, then the navigator shows him the same shortest path (obviously, starting from v as soon as he arrives at this intersection). However, if Polycarp chooses to drive to another intersection w instead, the navigator rebuilds the path: as soon as Polycarp arrives at w, the navigation system chooses some shortest path from w to t and shows it to Polycarp. The same process continues until Polycarp arrives at t: if Polycarp moves along the road recommended by the system, it maintains the shortest path it has already built; but if Polycarp chooses some other path, the system rebuilds the path by the same rules.
Here is an example. Suppose the map of Bertown looks as follows, and Polycarp drives along the path [1, 2, 3, 4] (s = 1, t = 4):
Check the picture by the link [http://tk.codeforces.com/a.png](//tk.codeforces.com/a.png)
1. When Polycarp starts at 1, the system chooses some shortest path from 1 to 4. There is only one such path, it is [1, 5, 4];
2. Polycarp chooses to drive to 2, which is not along the path chosen by the system. When Polycarp arrives at 2, the navigator rebuilds the path by choosing some shortest path from 2 to 4, for example, [2, 6, 4] (note that it could choose [2, 3, 4]);
3. Polycarp chooses to drive to 3, which is not along the path chosen by the system. When Polycarp arrives at 3, the navigator rebuilds the path by choosing the only shortest path from 3 to 4, which is [3, 4];
4. Polycarp arrives at 4 along the road chosen by the navigator, so the system does not have to rebuild anything.
Overall, we get 2 rebuilds in this scenario. Note that if the system chose [2, 3, 4] instead of [2, 6, 4] during the second step, there would be only 1 rebuild (since Polycarp goes along the path, so the system maintains the path [3, 4] during the third step).
The example shows us that the number of rebuilds can differ even if the map of Bertown and the path chosen by Polycarp stays the same. Given this information (the map and Polycarp's path), can you determine the minimum and the maximum number of rebuilds that could have happened during the journey?
Input
The first line contains two integers n and m (2 β€ n β€ m β€ 2 β
10^5) β the number of intersections and one-way roads in Bertown, respectively.
Then m lines follow, each describing a road. Each line contains two integers u and v (1 β€ u, v β€ n, u β v) denoting a road from intersection u to intersection v. All roads in Bertown are pairwise distinct, which means that each ordered pair (u, v) appears at most once in these m lines (but if there is a road (u, v), the road (v, u) can also appear).
The following line contains one integer k (2 β€ k β€ n) β the number of intersections in Polycarp's path from home to his workplace.
The last line contains k integers p_1, p_2, ..., p_k (1 β€ p_i β€ n, all these integers are pairwise distinct) β the intersections along Polycarp's path in the order he arrived at them. p_1 is the intersection where Polycarp lives (s = p_1), and p_k is the intersection where Polycarp's workplace is situated (t = p_k). It is guaranteed that for every i β [1, k - 1] the road from p_i to p_{i + 1} exists, so the path goes along the roads of Bertown.
Output
Print two integers: the minimum and the maximum number of rebuilds that could have happened during the journey.
Examples
Input
6 9
1 5
5 4
1 2
2 3
3 4
4 1
2 6
6 4
4 2
4
1 2 3 4
Output
1 2
Input
7 7
1 2
2 3
3 4
4 5
5 6
6 7
7 1
7
1 2 3 4 5 6 7
Output
0 0
Input
8 13
8 7
8 6
7 5
7 4
6 5
6 4
5 3
5 2
4 3
4 2
3 1
2 1
1 8
5
8 7 5 2 1
Output
0 3
Submitted Solution:
```
from collections import defaultdict, deque
n, m = map(int, input().split())
e = defaultdict(list)
for _ in range(m):
a, b = map(int, input().split())
e[b].append(a)
plen, path = int(input()), list(map(int, input().split()))
tg = path[-1]
pathfrom = defaultdict(set)
pathsz = defaultdict(int)
q = deque([(tg, tg, 1)])
while q:
frm, to, sz = q.popleft()
if pathsz[to] == 0:
pathsz[to] = sz
pathfrom[to].add(frm)
for u in e[to]:
q.append((to, u, sz+1))
elif pathsz[to] == sz:
pathfrom[to].add(frm)
mn, mx = 0, 0
for i in range(plen-1):
u, v = path[i], path[i+1]
if v in pathfrom[u]:
if len(pathfrom[u]) > 1:
mx += 1
else:
mn += 1; mx += 1
print(mn, mx)
```
Yes
| 60,793 | [
0.2081298828125,
0.3828125,
-0.0384521484375,
-0.06658935546875,
-0.04461669921875,
0.11614990234375,
-0.5634765625,
0.070556640625,
0.2783203125,
0.9794921875,
0.9951171875,
-0.1278076171875,
0.1580810546875,
-0.80615234375,
-0.467041015625,
0.118896484375,
-0.60302734375,
-0.3737... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The map of Bertown can be represented as a set of n intersections, numbered from 1 to n and connected by m one-way roads. It is possible to move along the roads from any intersection to any other intersection. The length of some path from one intersection to another is the number of roads that one has to traverse along the path. The shortest path from one intersection v to another intersection u is the path that starts in v, ends in u and has the minimum length among all such paths.
Polycarp lives near the intersection s and works in a building near the intersection t. Every day he gets from s to t by car. Today he has chosen the following path to his workplace: p_1, p_2, ..., p_k, where p_1 = s, p_k = t, and all other elements of this sequence are the intermediate intersections, listed in the order Polycarp arrived at them. Polycarp never arrived at the same intersection twice, so all elements of this sequence are pairwise distinct. Note that you know Polycarp's path beforehand (it is fixed), and it is not necessarily one of the shortest paths from s to t.
Polycarp's car has a complex navigation system installed in it. Let's describe how it works. When Polycarp starts his journey at the intersection s, the system chooses some shortest path from s to t and shows it to Polycarp. Let's denote the next intersection in the chosen path as v. If Polycarp chooses to drive along the road from s to v, then the navigator shows him the same shortest path (obviously, starting from v as soon as he arrives at this intersection). However, if Polycarp chooses to drive to another intersection w instead, the navigator rebuilds the path: as soon as Polycarp arrives at w, the navigation system chooses some shortest path from w to t and shows it to Polycarp. The same process continues until Polycarp arrives at t: if Polycarp moves along the road recommended by the system, it maintains the shortest path it has already built; but if Polycarp chooses some other path, the system rebuilds the path by the same rules.
Here is an example. Suppose the map of Bertown looks as follows, and Polycarp drives along the path [1, 2, 3, 4] (s = 1, t = 4):
Check the picture by the link [http://tk.codeforces.com/a.png](//tk.codeforces.com/a.png)
1. When Polycarp starts at 1, the system chooses some shortest path from 1 to 4. There is only one such path, it is [1, 5, 4];
2. Polycarp chooses to drive to 2, which is not along the path chosen by the system. When Polycarp arrives at 2, the navigator rebuilds the path by choosing some shortest path from 2 to 4, for example, [2, 6, 4] (note that it could choose [2, 3, 4]);
3. Polycarp chooses to drive to 3, which is not along the path chosen by the system. When Polycarp arrives at 3, the navigator rebuilds the path by choosing the only shortest path from 3 to 4, which is [3, 4];
4. Polycarp arrives at 4 along the road chosen by the navigator, so the system does not have to rebuild anything.
Overall, we get 2 rebuilds in this scenario. Note that if the system chose [2, 3, 4] instead of [2, 6, 4] during the second step, there would be only 1 rebuild (since Polycarp goes along the path, so the system maintains the path [3, 4] during the third step).
The example shows us that the number of rebuilds can differ even if the map of Bertown and the path chosen by Polycarp stays the same. Given this information (the map and Polycarp's path), can you determine the minimum and the maximum number of rebuilds that could have happened during the journey?
Input
The first line contains two integers n and m (2 β€ n β€ m β€ 2 β
10^5) β the number of intersections and one-way roads in Bertown, respectively.
Then m lines follow, each describing a road. Each line contains two integers u and v (1 β€ u, v β€ n, u β v) denoting a road from intersection u to intersection v. All roads in Bertown are pairwise distinct, which means that each ordered pair (u, v) appears at most once in these m lines (but if there is a road (u, v), the road (v, u) can also appear).
The following line contains one integer k (2 β€ k β€ n) β the number of intersections in Polycarp's path from home to his workplace.
The last line contains k integers p_1, p_2, ..., p_k (1 β€ p_i β€ n, all these integers are pairwise distinct) β the intersections along Polycarp's path in the order he arrived at them. p_1 is the intersection where Polycarp lives (s = p_1), and p_k is the intersection where Polycarp's workplace is situated (t = p_k). It is guaranteed that for every i β [1, k - 1] the road from p_i to p_{i + 1} exists, so the path goes along the roads of Bertown.
Output
Print two integers: the minimum and the maximum number of rebuilds that could have happened during the journey.
Examples
Input
6 9
1 5
5 4
1 2
2 3
3 4
4 1
2 6
6 4
4 2
4
1 2 3 4
Output
1 2
Input
7 7
1 2
2 3
3 4
4 5
5 6
6 7
7 1
7
1 2 3 4 5 6 7
Output
0 0
Input
8 13
8 7
8 6
7 5
7 4
6 5
6 4
5 3
5 2
4 3
4 2
3 1
2 1
1 8
5
8 7 5 2 1
Output
0 3
Submitted Solution:
```
from collections import deque
from collections import defaultdict
no_nodes, e = list(map(int, input().strip().split()))
edges = []
for _ in range(e):
u, v = list(map(int, input().strip().split()))
edges.append((u, v))
k = int(input().strip())
given_path = list(map(int, input().strip().split()))
dest = given_path[-1]
class BFS_Graph:
def __init__(self, no_nodes):
self.graph = defaultdict(list)
self.no_nodes = no_nodes+1
def add_edge(self, u, v):
self.graph[u].append(v)
def add_edges_from_list(self, edges):
for edge in edges:
self.add_edge(edge[1], edge[0])
def BFS(self, source, destination=-1):
visited = [False]*self.no_nodes
pred = [-1]*self.no_nodes
dist = [float("inf")]*self.no_nodes
visited[source] = True
dist[source] = 0
queue = deque()
queue.append(source)
while queue:
u = queue.popleft()
if u == destination:
break
for i in self.graph[u]:
if visited[i] == False:
visited[i] = True
dist[i] = dist[u] + 1
pred[i] = [u]
queue.append(i)
else:
if dist[i] == dist[u] + 1:
pred[i].append(u)
return pred, dist
g = BFS_Graph(no_nodes)
g.add_edges_from_list(edges)
pred, dist = g.BFS(dest)
# print(pred)
# print(dist)
definite = []
possible = []
for i in range(1,k-1):
pre_node = given_path[i-1]
current_node = given_path[i]
if dist[current_node]>=dist[pre_node]:
definite.append(current_node)
else:
if len(pred[pre_node])>1:
possible.append(current_node)
# print(definite)
# print(possible)
max_val = len(definite) +len(possible)
min_val = len(definite)
print(min_val,max_val)
```
Yes
| 60,794 | [
0.2081298828125,
0.3828125,
-0.0384521484375,
-0.06658935546875,
-0.04461669921875,
0.11614990234375,
-0.5634765625,
0.070556640625,
0.2783203125,
0.9794921875,
0.9951171875,
-0.1278076171875,
0.1580810546875,
-0.80615234375,
-0.467041015625,
0.118896484375,
-0.60302734375,
-0.3737... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The map of Bertown can be represented as a set of n intersections, numbered from 1 to n and connected by m one-way roads. It is possible to move along the roads from any intersection to any other intersection. The length of some path from one intersection to another is the number of roads that one has to traverse along the path. The shortest path from one intersection v to another intersection u is the path that starts in v, ends in u and has the minimum length among all such paths.
Polycarp lives near the intersection s and works in a building near the intersection t. Every day he gets from s to t by car. Today he has chosen the following path to his workplace: p_1, p_2, ..., p_k, where p_1 = s, p_k = t, and all other elements of this sequence are the intermediate intersections, listed in the order Polycarp arrived at them. Polycarp never arrived at the same intersection twice, so all elements of this sequence are pairwise distinct. Note that you know Polycarp's path beforehand (it is fixed), and it is not necessarily one of the shortest paths from s to t.
Polycarp's car has a complex navigation system installed in it. Let's describe how it works. When Polycarp starts his journey at the intersection s, the system chooses some shortest path from s to t and shows it to Polycarp. Let's denote the next intersection in the chosen path as v. If Polycarp chooses to drive along the road from s to v, then the navigator shows him the same shortest path (obviously, starting from v as soon as he arrives at this intersection). However, if Polycarp chooses to drive to another intersection w instead, the navigator rebuilds the path: as soon as Polycarp arrives at w, the navigation system chooses some shortest path from w to t and shows it to Polycarp. The same process continues until Polycarp arrives at t: if Polycarp moves along the road recommended by the system, it maintains the shortest path it has already built; but if Polycarp chooses some other path, the system rebuilds the path by the same rules.
Here is an example. Suppose the map of Bertown looks as follows, and Polycarp drives along the path [1, 2, 3, 4] (s = 1, t = 4):
Check the picture by the link [http://tk.codeforces.com/a.png](//tk.codeforces.com/a.png)
1. When Polycarp starts at 1, the system chooses some shortest path from 1 to 4. There is only one such path, it is [1, 5, 4];
2. Polycarp chooses to drive to 2, which is not along the path chosen by the system. When Polycarp arrives at 2, the navigator rebuilds the path by choosing some shortest path from 2 to 4, for example, [2, 6, 4] (note that it could choose [2, 3, 4]);
3. Polycarp chooses to drive to 3, which is not along the path chosen by the system. When Polycarp arrives at 3, the navigator rebuilds the path by choosing the only shortest path from 3 to 4, which is [3, 4];
4. Polycarp arrives at 4 along the road chosen by the navigator, so the system does not have to rebuild anything.
Overall, we get 2 rebuilds in this scenario. Note that if the system chose [2, 3, 4] instead of [2, 6, 4] during the second step, there would be only 1 rebuild (since Polycarp goes along the path, so the system maintains the path [3, 4] during the third step).
The example shows us that the number of rebuilds can differ even if the map of Bertown and the path chosen by Polycarp stays the same. Given this information (the map and Polycarp's path), can you determine the minimum and the maximum number of rebuilds that could have happened during the journey?
Input
The first line contains two integers n and m (2 β€ n β€ m β€ 2 β
10^5) β the number of intersections and one-way roads in Bertown, respectively.
Then m lines follow, each describing a road. Each line contains two integers u and v (1 β€ u, v β€ n, u β v) denoting a road from intersection u to intersection v. All roads in Bertown are pairwise distinct, which means that each ordered pair (u, v) appears at most once in these m lines (but if there is a road (u, v), the road (v, u) can also appear).
The following line contains one integer k (2 β€ k β€ n) β the number of intersections in Polycarp's path from home to his workplace.
The last line contains k integers p_1, p_2, ..., p_k (1 β€ p_i β€ n, all these integers are pairwise distinct) β the intersections along Polycarp's path in the order he arrived at them. p_1 is the intersection where Polycarp lives (s = p_1), and p_k is the intersection where Polycarp's workplace is situated (t = p_k). It is guaranteed that for every i β [1, k - 1] the road from p_i to p_{i + 1} exists, so the path goes along the roads of Bertown.
Output
Print two integers: the minimum and the maximum number of rebuilds that could have happened during the journey.
Examples
Input
6 9
1 5
5 4
1 2
2 3
3 4
4 1
2 6
6 4
4 2
4
1 2 3 4
Output
1 2
Input
7 7
1 2
2 3
3 4
4 5
5 6
6 7
7 1
7
1 2 3 4 5 6 7
Output
0 0
Input
8 13
8 7
8 6
7 5
7 4
6 5
6 4
5 3
5 2
4 3
4 2
3 1
2 1
1 8
5
8 7 5 2 1
Output
0 3
Submitted Solution:
```
from sys import stdin, stdout
import math
n,m = map(int,stdin.readline().rstrip().split(' '))
roads = [[] for _ in range(n)]
roadsTo = [[] for _ in range(n)]
for _ in range(m):
u,v = map(int,stdin.readline().rstrip().split(' '))
u-=1
v-=1
roads[v].append(u)
roadsTo[u].append(v)
k = int(stdin.readline().rstrip())
p = list(map(int,stdin.readline().rstrip().split(' ')))
p = [i-1 for i in p]
visited = set([p[k-1]])
lastBatch = set([p[k-1]])
minLen = [0]*n
while len(visited)<n:
batch = set()
for i in lastBatch:
for j in roads[i]:
if j not in visited:
visited.add(j)
minLen[j] = minLen[i]+1
batch.add(j)
lastBatch = batch
minChg = 0
maxChg = 0
for i in range(len(p)-1):
nextUp = minLen[p[i+1]]
otherQuickest = min([minLen[j] for j in roadsTo[p[i]] if j!=p[i+1]]+[999999])
if otherQuickest<nextUp:
minChg+=1
maxChg+=1
elif otherQuickest==nextUp:
maxChg+=1
print(str(minChg)+' '+str(maxChg))
```
Yes
| 60,795 | [
0.2081298828125,
0.3828125,
-0.0384521484375,
-0.06658935546875,
-0.04461669921875,
0.11614990234375,
-0.5634765625,
0.070556640625,
0.2783203125,
0.9794921875,
0.9951171875,
-0.1278076171875,
0.1580810546875,
-0.80615234375,
-0.467041015625,
0.118896484375,
-0.60302734375,
-0.3737... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The map of Bertown can be represented as a set of n intersections, numbered from 1 to n and connected by m one-way roads. It is possible to move along the roads from any intersection to any other intersection. The length of some path from one intersection to another is the number of roads that one has to traverse along the path. The shortest path from one intersection v to another intersection u is the path that starts in v, ends in u and has the minimum length among all such paths.
Polycarp lives near the intersection s and works in a building near the intersection t. Every day he gets from s to t by car. Today he has chosen the following path to his workplace: p_1, p_2, ..., p_k, where p_1 = s, p_k = t, and all other elements of this sequence are the intermediate intersections, listed in the order Polycarp arrived at them. Polycarp never arrived at the same intersection twice, so all elements of this sequence are pairwise distinct. Note that you know Polycarp's path beforehand (it is fixed), and it is not necessarily one of the shortest paths from s to t.
Polycarp's car has a complex navigation system installed in it. Let's describe how it works. When Polycarp starts his journey at the intersection s, the system chooses some shortest path from s to t and shows it to Polycarp. Let's denote the next intersection in the chosen path as v. If Polycarp chooses to drive along the road from s to v, then the navigator shows him the same shortest path (obviously, starting from v as soon as he arrives at this intersection). However, if Polycarp chooses to drive to another intersection w instead, the navigator rebuilds the path: as soon as Polycarp arrives at w, the navigation system chooses some shortest path from w to t and shows it to Polycarp. The same process continues until Polycarp arrives at t: if Polycarp moves along the road recommended by the system, it maintains the shortest path it has already built; but if Polycarp chooses some other path, the system rebuilds the path by the same rules.
Here is an example. Suppose the map of Bertown looks as follows, and Polycarp drives along the path [1, 2, 3, 4] (s = 1, t = 4):
Check the picture by the link [http://tk.codeforces.com/a.png](//tk.codeforces.com/a.png)
1. When Polycarp starts at 1, the system chooses some shortest path from 1 to 4. There is only one such path, it is [1, 5, 4];
2. Polycarp chooses to drive to 2, which is not along the path chosen by the system. When Polycarp arrives at 2, the navigator rebuilds the path by choosing some shortest path from 2 to 4, for example, [2, 6, 4] (note that it could choose [2, 3, 4]);
3. Polycarp chooses to drive to 3, which is not along the path chosen by the system. When Polycarp arrives at 3, the navigator rebuilds the path by choosing the only shortest path from 3 to 4, which is [3, 4];
4. Polycarp arrives at 4 along the road chosen by the navigator, so the system does not have to rebuild anything.
Overall, we get 2 rebuilds in this scenario. Note that if the system chose [2, 3, 4] instead of [2, 6, 4] during the second step, there would be only 1 rebuild (since Polycarp goes along the path, so the system maintains the path [3, 4] during the third step).
The example shows us that the number of rebuilds can differ even if the map of Bertown and the path chosen by Polycarp stays the same. Given this information (the map and Polycarp's path), can you determine the minimum and the maximum number of rebuilds that could have happened during the journey?
Input
The first line contains two integers n and m (2 β€ n β€ m β€ 2 β
10^5) β the number of intersections and one-way roads in Bertown, respectively.
Then m lines follow, each describing a road. Each line contains two integers u and v (1 β€ u, v β€ n, u β v) denoting a road from intersection u to intersection v. All roads in Bertown are pairwise distinct, which means that each ordered pair (u, v) appears at most once in these m lines (but if there is a road (u, v), the road (v, u) can also appear).
The following line contains one integer k (2 β€ k β€ n) β the number of intersections in Polycarp's path from home to his workplace.
The last line contains k integers p_1, p_2, ..., p_k (1 β€ p_i β€ n, all these integers are pairwise distinct) β the intersections along Polycarp's path in the order he arrived at them. p_1 is the intersection where Polycarp lives (s = p_1), and p_k is the intersection where Polycarp's workplace is situated (t = p_k). It is guaranteed that for every i β [1, k - 1] the road from p_i to p_{i + 1} exists, so the path goes along the roads of Bertown.
Output
Print two integers: the minimum and the maximum number of rebuilds that could have happened during the journey.
Examples
Input
6 9
1 5
5 4
1 2
2 3
3 4
4 1
2 6
6 4
4 2
4
1 2 3 4
Output
1 2
Input
7 7
1 2
2 3
3 4
4 5
5 6
6 7
7 1
7
1 2 3 4 5 6 7
Output
0 0
Input
8 13
8 7
8 6
7 5
7 4
6 5
6 4
5 3
5 2
4 3
4 2
3 1
2 1
1 8
5
8 7 5 2 1
Output
0 3
Submitted Solution:
```
from collections import deque
n,m = map(int,input().split())
g = [list() for _ in range(n)]
for _ in range(m):
u,v = map(int,input().split())
u,v = u-1,v-1
g[v].append(u)
k = int(input())
path = list(map(int,input().split()))
for i in range(k):
path[i] -= 1
q = deque([])
q.append(path[-1])
dist = [-1]*(n)
isv = [-1]*(n)
dist[q[0]] = 0
while q:
top = q.popleft()
for i in g[top]:
if dist[i] == -1:
q.append(i)
dist[i] = dist[top]+1
isv[i] = 1
elif dist[i] == dist[top]+1:
isv[i]+=1
mn,mx = 0,0
for i in range(1,k):
# if the difference between current and previous not 1
# means that it is not the optimal path
# hence the ans += 1
if dist[path[i-1]]-1 != dist[path[i]]:
mn+=1
mx += 1
elif isv[path[i-1]] != -1 and isv[path[i-1]]>1:
mx += 1
print(mn,mx)
```
Yes
| 60,796 | [
0.2081298828125,
0.3828125,
-0.0384521484375,
-0.06658935546875,
-0.04461669921875,
0.11614990234375,
-0.5634765625,
0.070556640625,
0.2783203125,
0.9794921875,
0.9951171875,
-0.1278076171875,
0.1580810546875,
-0.80615234375,
-0.467041015625,
0.118896484375,
-0.60302734375,
-0.3737... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The map of Bertown can be represented as a set of n intersections, numbered from 1 to n and connected by m one-way roads. It is possible to move along the roads from any intersection to any other intersection. The length of some path from one intersection to another is the number of roads that one has to traverse along the path. The shortest path from one intersection v to another intersection u is the path that starts in v, ends in u and has the minimum length among all such paths.
Polycarp lives near the intersection s and works in a building near the intersection t. Every day he gets from s to t by car. Today he has chosen the following path to his workplace: p_1, p_2, ..., p_k, where p_1 = s, p_k = t, and all other elements of this sequence are the intermediate intersections, listed in the order Polycarp arrived at them. Polycarp never arrived at the same intersection twice, so all elements of this sequence are pairwise distinct. Note that you know Polycarp's path beforehand (it is fixed), and it is not necessarily one of the shortest paths from s to t.
Polycarp's car has a complex navigation system installed in it. Let's describe how it works. When Polycarp starts his journey at the intersection s, the system chooses some shortest path from s to t and shows it to Polycarp. Let's denote the next intersection in the chosen path as v. If Polycarp chooses to drive along the road from s to v, then the navigator shows him the same shortest path (obviously, starting from v as soon as he arrives at this intersection). However, if Polycarp chooses to drive to another intersection w instead, the navigator rebuilds the path: as soon as Polycarp arrives at w, the navigation system chooses some shortest path from w to t and shows it to Polycarp. The same process continues until Polycarp arrives at t: if Polycarp moves along the road recommended by the system, it maintains the shortest path it has already built; but if Polycarp chooses some other path, the system rebuilds the path by the same rules.
Here is an example. Suppose the map of Bertown looks as follows, and Polycarp drives along the path [1, 2, 3, 4] (s = 1, t = 4):
Check the picture by the link [http://tk.codeforces.com/a.png](//tk.codeforces.com/a.png)
1. When Polycarp starts at 1, the system chooses some shortest path from 1 to 4. There is only one such path, it is [1, 5, 4];
2. Polycarp chooses to drive to 2, which is not along the path chosen by the system. When Polycarp arrives at 2, the navigator rebuilds the path by choosing some shortest path from 2 to 4, for example, [2, 6, 4] (note that it could choose [2, 3, 4]);
3. Polycarp chooses to drive to 3, which is not along the path chosen by the system. When Polycarp arrives at 3, the navigator rebuilds the path by choosing the only shortest path from 3 to 4, which is [3, 4];
4. Polycarp arrives at 4 along the road chosen by the navigator, so the system does not have to rebuild anything.
Overall, we get 2 rebuilds in this scenario. Note that if the system chose [2, 3, 4] instead of [2, 6, 4] during the second step, there would be only 1 rebuild (since Polycarp goes along the path, so the system maintains the path [3, 4] during the third step).
The example shows us that the number of rebuilds can differ even if the map of Bertown and the path chosen by Polycarp stays the same. Given this information (the map and Polycarp's path), can you determine the minimum and the maximum number of rebuilds that could have happened during the journey?
Input
The first line contains two integers n and m (2 β€ n β€ m β€ 2 β
10^5) β the number of intersections and one-way roads in Bertown, respectively.
Then m lines follow, each describing a road. Each line contains two integers u and v (1 β€ u, v β€ n, u β v) denoting a road from intersection u to intersection v. All roads in Bertown are pairwise distinct, which means that each ordered pair (u, v) appears at most once in these m lines (but if there is a road (u, v), the road (v, u) can also appear).
The following line contains one integer k (2 β€ k β€ n) β the number of intersections in Polycarp's path from home to his workplace.
The last line contains k integers p_1, p_2, ..., p_k (1 β€ p_i β€ n, all these integers are pairwise distinct) β the intersections along Polycarp's path in the order he arrived at them. p_1 is the intersection where Polycarp lives (s = p_1), and p_k is the intersection where Polycarp's workplace is situated (t = p_k). It is guaranteed that for every i β [1, k - 1] the road from p_i to p_{i + 1} exists, so the path goes along the roads of Bertown.
Output
Print two integers: the minimum and the maximum number of rebuilds that could have happened during the journey.
Examples
Input
6 9
1 5
5 4
1 2
2 3
3 4
4 1
2 6
6 4
4 2
4
1 2 3 4
Output
1 2
Input
7 7
1 2
2 3
3 4
4 5
5 6
6 7
7 1
7
1 2 3 4 5 6 7
Output
0 0
Input
8 13
8 7
8 6
7 5
7 4
6 5
6 4
5 3
5 2
4 3
4 2
3 1
2 1
1 8
5
8 7 5 2 1
Output
0 3
Submitted Solution:
```
from math import *
n, m = map(int, input().split())
g = {}
for i in range(n):
g[i] = set()
for i in range(m):
a, b = map(int, input().split())
g[b-1].add(a-1)
k = int(input())
p = [int(i) - 1 for i in input().split()]
te = []
for i in range(n):
te.append([10**9, 0])
def dfs(v, d):
for u in g[v]:
if d < te[u][0]:
te[u][0] = d
te[u][1] = 1
elif d == te[u][0]:
te[u][1] += 1
else:
return
dfs(u, d + 1)
dfs(p[-1], 1)
ans1 = 0
ans2 = 0
for i in range(0, k - 1):
v = p[i]
dist, cnt = te[v]
if dist < k - i - 1:
ans1 += 1
ans2 += 1
elif cnt > 1:
ans2 += 1
print(ans1, ans2)
```
No
| 60,797 | [
0.2081298828125,
0.3828125,
-0.0384521484375,
-0.06658935546875,
-0.04461669921875,
0.11614990234375,
-0.5634765625,
0.070556640625,
0.2783203125,
0.9794921875,
0.9951171875,
-0.1278076171875,
0.1580810546875,
-0.80615234375,
-0.467041015625,
0.118896484375,
-0.60302734375,
-0.3737... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The map of Bertown can be represented as a set of n intersections, numbered from 1 to n and connected by m one-way roads. It is possible to move along the roads from any intersection to any other intersection. The length of some path from one intersection to another is the number of roads that one has to traverse along the path. The shortest path from one intersection v to another intersection u is the path that starts in v, ends in u and has the minimum length among all such paths.
Polycarp lives near the intersection s and works in a building near the intersection t. Every day he gets from s to t by car. Today he has chosen the following path to his workplace: p_1, p_2, ..., p_k, where p_1 = s, p_k = t, and all other elements of this sequence are the intermediate intersections, listed in the order Polycarp arrived at them. Polycarp never arrived at the same intersection twice, so all elements of this sequence are pairwise distinct. Note that you know Polycarp's path beforehand (it is fixed), and it is not necessarily one of the shortest paths from s to t.
Polycarp's car has a complex navigation system installed in it. Let's describe how it works. When Polycarp starts his journey at the intersection s, the system chooses some shortest path from s to t and shows it to Polycarp. Let's denote the next intersection in the chosen path as v. If Polycarp chooses to drive along the road from s to v, then the navigator shows him the same shortest path (obviously, starting from v as soon as he arrives at this intersection). However, if Polycarp chooses to drive to another intersection w instead, the navigator rebuilds the path: as soon as Polycarp arrives at w, the navigation system chooses some shortest path from w to t and shows it to Polycarp. The same process continues until Polycarp arrives at t: if Polycarp moves along the road recommended by the system, it maintains the shortest path it has already built; but if Polycarp chooses some other path, the system rebuilds the path by the same rules.
Here is an example. Suppose the map of Bertown looks as follows, and Polycarp drives along the path [1, 2, 3, 4] (s = 1, t = 4):
Check the picture by the link [http://tk.codeforces.com/a.png](//tk.codeforces.com/a.png)
1. When Polycarp starts at 1, the system chooses some shortest path from 1 to 4. There is only one such path, it is [1, 5, 4];
2. Polycarp chooses to drive to 2, which is not along the path chosen by the system. When Polycarp arrives at 2, the navigator rebuilds the path by choosing some shortest path from 2 to 4, for example, [2, 6, 4] (note that it could choose [2, 3, 4]);
3. Polycarp chooses to drive to 3, which is not along the path chosen by the system. When Polycarp arrives at 3, the navigator rebuilds the path by choosing the only shortest path from 3 to 4, which is [3, 4];
4. Polycarp arrives at 4 along the road chosen by the navigator, so the system does not have to rebuild anything.
Overall, we get 2 rebuilds in this scenario. Note that if the system chose [2, 3, 4] instead of [2, 6, 4] during the second step, there would be only 1 rebuild (since Polycarp goes along the path, so the system maintains the path [3, 4] during the third step).
The example shows us that the number of rebuilds can differ even if the map of Bertown and the path chosen by Polycarp stays the same. Given this information (the map and Polycarp's path), can you determine the minimum and the maximum number of rebuilds that could have happened during the journey?
Input
The first line contains two integers n and m (2 β€ n β€ m β€ 2 β
10^5) β the number of intersections and one-way roads in Bertown, respectively.
Then m lines follow, each describing a road. Each line contains two integers u and v (1 β€ u, v β€ n, u β v) denoting a road from intersection u to intersection v. All roads in Bertown are pairwise distinct, which means that each ordered pair (u, v) appears at most once in these m lines (but if there is a road (u, v), the road (v, u) can also appear).
The following line contains one integer k (2 β€ k β€ n) β the number of intersections in Polycarp's path from home to his workplace.
The last line contains k integers p_1, p_2, ..., p_k (1 β€ p_i β€ n, all these integers are pairwise distinct) β the intersections along Polycarp's path in the order he arrived at them. p_1 is the intersection where Polycarp lives (s = p_1), and p_k is the intersection where Polycarp's workplace is situated (t = p_k). It is guaranteed that for every i β [1, k - 1] the road from p_i to p_{i + 1} exists, so the path goes along the roads of Bertown.
Output
Print two integers: the minimum and the maximum number of rebuilds that could have happened during the journey.
Examples
Input
6 9
1 5
5 4
1 2
2 3
3 4
4 1
2 6
6 4
4 2
4
1 2 3 4
Output
1 2
Input
7 7
1 2
2 3
3 4
4 5
5 6
6 7
7 1
7
1 2 3 4 5 6 7
Output
0 0
Input
8 13
8 7
8 6
7 5
7 4
6 5
6 4
5 3
5 2
4 3
4 2
3 1
2 1
1 8
5
8 7 5 2 1
Output
0 3
Submitted Solution:
```
def bfs(graph, node, end):
visited = []
queue = []
visited.append(node)
queue.append(node)
nodes_dist = [-1]*len(graph)
nodes_routes = [0]*len(graph)
nodes_dist[node] = 0
while queue:
s = queue.pop(0)
for neighbour in graph[s]:
if neighbour not in visited:
visited.append(neighbour)
queue.append(neighbour)
nodes_dist[neighbour] = nodes_dist[s] + 1
if nodes_dist[s] + 1 == nodes_dist[neighbour]:
nodes_routes[neighbour] += 1
return nodes_dist[end], nodes_routes[end]
n, m = [int(s) for s in input().split(' ')]
N = [set() for _ in range(n+1)]
for i in range(m):
u, v = [int(s) for s in input().split(' ')]
N[u].add(v)
k = int(input())
p = [int(s) for s in input().split(' ')]
min_re = 0
max_re = 0
for i in range(k-1):
next_node = p[i+1]
best_next_nodes = set()
dist, routes = bfs(N, p[i], p[-1])
for neighbour in N[p[i]]:
neighbour_dist, _ = bfs(N, neighbour, p[-1])
if neighbour_dist + 1 == dist:
best_next_nodes.add(neighbour)
if next_node not in best_next_nodes:
min_re += 1
max_re += 1
elif routes > 1:
max_re += 1
print(min_re, max_re)
```
No
| 60,798 | [
0.2081298828125,
0.3828125,
-0.0384521484375,
-0.06658935546875,
-0.04461669921875,
0.11614990234375,
-0.5634765625,
0.070556640625,
0.2783203125,
0.9794921875,
0.9951171875,
-0.1278076171875,
0.1580810546875,
-0.80615234375,
-0.467041015625,
0.118896484375,
-0.60302734375,
-0.3737... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The map of Bertown can be represented as a set of n intersections, numbered from 1 to n and connected by m one-way roads. It is possible to move along the roads from any intersection to any other intersection. The length of some path from one intersection to another is the number of roads that one has to traverse along the path. The shortest path from one intersection v to another intersection u is the path that starts in v, ends in u and has the minimum length among all such paths.
Polycarp lives near the intersection s and works in a building near the intersection t. Every day he gets from s to t by car. Today he has chosen the following path to his workplace: p_1, p_2, ..., p_k, where p_1 = s, p_k = t, and all other elements of this sequence are the intermediate intersections, listed in the order Polycarp arrived at them. Polycarp never arrived at the same intersection twice, so all elements of this sequence are pairwise distinct. Note that you know Polycarp's path beforehand (it is fixed), and it is not necessarily one of the shortest paths from s to t.
Polycarp's car has a complex navigation system installed in it. Let's describe how it works. When Polycarp starts his journey at the intersection s, the system chooses some shortest path from s to t and shows it to Polycarp. Let's denote the next intersection in the chosen path as v. If Polycarp chooses to drive along the road from s to v, then the navigator shows him the same shortest path (obviously, starting from v as soon as he arrives at this intersection). However, if Polycarp chooses to drive to another intersection w instead, the navigator rebuilds the path: as soon as Polycarp arrives at w, the navigation system chooses some shortest path from w to t and shows it to Polycarp. The same process continues until Polycarp arrives at t: if Polycarp moves along the road recommended by the system, it maintains the shortest path it has already built; but if Polycarp chooses some other path, the system rebuilds the path by the same rules.
Here is an example. Suppose the map of Bertown looks as follows, and Polycarp drives along the path [1, 2, 3, 4] (s = 1, t = 4):
Check the picture by the link [http://tk.codeforces.com/a.png](//tk.codeforces.com/a.png)
1. When Polycarp starts at 1, the system chooses some shortest path from 1 to 4. There is only one such path, it is [1, 5, 4];
2. Polycarp chooses to drive to 2, which is not along the path chosen by the system. When Polycarp arrives at 2, the navigator rebuilds the path by choosing some shortest path from 2 to 4, for example, [2, 6, 4] (note that it could choose [2, 3, 4]);
3. Polycarp chooses to drive to 3, which is not along the path chosen by the system. When Polycarp arrives at 3, the navigator rebuilds the path by choosing the only shortest path from 3 to 4, which is [3, 4];
4. Polycarp arrives at 4 along the road chosen by the navigator, so the system does not have to rebuild anything.
Overall, we get 2 rebuilds in this scenario. Note that if the system chose [2, 3, 4] instead of [2, 6, 4] during the second step, there would be only 1 rebuild (since Polycarp goes along the path, so the system maintains the path [3, 4] during the third step).
The example shows us that the number of rebuilds can differ even if the map of Bertown and the path chosen by Polycarp stays the same. Given this information (the map and Polycarp's path), can you determine the minimum and the maximum number of rebuilds that could have happened during the journey?
Input
The first line contains two integers n and m (2 β€ n β€ m β€ 2 β
10^5) β the number of intersections and one-way roads in Bertown, respectively.
Then m lines follow, each describing a road. Each line contains two integers u and v (1 β€ u, v β€ n, u β v) denoting a road from intersection u to intersection v. All roads in Bertown are pairwise distinct, which means that each ordered pair (u, v) appears at most once in these m lines (but if there is a road (u, v), the road (v, u) can also appear).
The following line contains one integer k (2 β€ k β€ n) β the number of intersections in Polycarp's path from home to his workplace.
The last line contains k integers p_1, p_2, ..., p_k (1 β€ p_i β€ n, all these integers are pairwise distinct) β the intersections along Polycarp's path in the order he arrived at them. p_1 is the intersection where Polycarp lives (s = p_1), and p_k is the intersection where Polycarp's workplace is situated (t = p_k). It is guaranteed that for every i β [1, k - 1] the road from p_i to p_{i + 1} exists, so the path goes along the roads of Bertown.
Output
Print two integers: the minimum and the maximum number of rebuilds that could have happened during the journey.
Examples
Input
6 9
1 5
5 4
1 2
2 3
3 4
4 1
2 6
6 4
4 2
4
1 2 3 4
Output
1 2
Input
7 7
1 2
2 3
3 4
4 5
5 6
6 7
7 1
7
1 2 3 4 5 6 7
Output
0 0
Input
8 13
8 7
8 6
7 5
7 4
6 5
6 4
5 3
5 2
4 3
4 2
3 1
2 1
1 8
5
8 7 5 2 1
Output
0 3
Submitted Solution:
```
import sys
def bfs(g,src,d,found):
q=[src]
d[src]=0
while q:
rmv=q.pop(0)
for child in g[rmv]:
if d[child]!=-1:
d[child]=d[rmv]+1
q.append(child)
found[child]=1
elif d[child]==d[rmv]+1:
found[child]+=1
n,m=map(int,sys.stdin.readline().split())
g=[]
gt=[]
for i in range(n):
g.append(list())
gt.append(list())
for _ in range(m):
u,v=map(int,sys.stdin.readline().split())
u-=1
v-=1
g[u].append(v)
gt[v].append(u)
k=int(sys.stdin.readline())
p=list(map(int,sys.stdin.readline().split()))
for i in range(len(p)):
p[i]-=1
d=[-1]*(n)
found={}
bfs(gt,p[-1],d,found)
#print(d)
mn=0
mx=0
for i in range(1,k):
if d[p[i-1]]-1!=d[p[i]]:
mn+=1
mx+=1
if found.get(p[i-1])!=None and found[p[i-1]]>1:
mx+=1
print(mn,mx)
```
No
| 60,799 | [
0.2081298828125,
0.3828125,
-0.0384521484375,
-0.06658935546875,
-0.04461669921875,
0.11614990234375,
-0.5634765625,
0.070556640625,
0.2783203125,
0.9794921875,
0.9951171875,
-0.1278076171875,
0.1580810546875,
-0.80615234375,
-0.467041015625,
0.118896484375,
-0.60302734375,
-0.3737... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The map of Bertown can be represented as a set of n intersections, numbered from 1 to n and connected by m one-way roads. It is possible to move along the roads from any intersection to any other intersection. The length of some path from one intersection to another is the number of roads that one has to traverse along the path. The shortest path from one intersection v to another intersection u is the path that starts in v, ends in u and has the minimum length among all such paths.
Polycarp lives near the intersection s and works in a building near the intersection t. Every day he gets from s to t by car. Today he has chosen the following path to his workplace: p_1, p_2, ..., p_k, where p_1 = s, p_k = t, and all other elements of this sequence are the intermediate intersections, listed in the order Polycarp arrived at them. Polycarp never arrived at the same intersection twice, so all elements of this sequence are pairwise distinct. Note that you know Polycarp's path beforehand (it is fixed), and it is not necessarily one of the shortest paths from s to t.
Polycarp's car has a complex navigation system installed in it. Let's describe how it works. When Polycarp starts his journey at the intersection s, the system chooses some shortest path from s to t and shows it to Polycarp. Let's denote the next intersection in the chosen path as v. If Polycarp chooses to drive along the road from s to v, then the navigator shows him the same shortest path (obviously, starting from v as soon as he arrives at this intersection). However, if Polycarp chooses to drive to another intersection w instead, the navigator rebuilds the path: as soon as Polycarp arrives at w, the navigation system chooses some shortest path from w to t and shows it to Polycarp. The same process continues until Polycarp arrives at t: if Polycarp moves along the road recommended by the system, it maintains the shortest path it has already built; but if Polycarp chooses some other path, the system rebuilds the path by the same rules.
Here is an example. Suppose the map of Bertown looks as follows, and Polycarp drives along the path [1, 2, 3, 4] (s = 1, t = 4):
Check the picture by the link [http://tk.codeforces.com/a.png](//tk.codeforces.com/a.png)
1. When Polycarp starts at 1, the system chooses some shortest path from 1 to 4. There is only one such path, it is [1, 5, 4];
2. Polycarp chooses to drive to 2, which is not along the path chosen by the system. When Polycarp arrives at 2, the navigator rebuilds the path by choosing some shortest path from 2 to 4, for example, [2, 6, 4] (note that it could choose [2, 3, 4]);
3. Polycarp chooses to drive to 3, which is not along the path chosen by the system. When Polycarp arrives at 3, the navigator rebuilds the path by choosing the only shortest path from 3 to 4, which is [3, 4];
4. Polycarp arrives at 4 along the road chosen by the navigator, so the system does not have to rebuild anything.
Overall, we get 2 rebuilds in this scenario. Note that if the system chose [2, 3, 4] instead of [2, 6, 4] during the second step, there would be only 1 rebuild (since Polycarp goes along the path, so the system maintains the path [3, 4] during the third step).
The example shows us that the number of rebuilds can differ even if the map of Bertown and the path chosen by Polycarp stays the same. Given this information (the map and Polycarp's path), can you determine the minimum and the maximum number of rebuilds that could have happened during the journey?
Input
The first line contains two integers n and m (2 β€ n β€ m β€ 2 β
10^5) β the number of intersections and one-way roads in Bertown, respectively.
Then m lines follow, each describing a road. Each line contains two integers u and v (1 β€ u, v β€ n, u β v) denoting a road from intersection u to intersection v. All roads in Bertown are pairwise distinct, which means that each ordered pair (u, v) appears at most once in these m lines (but if there is a road (u, v), the road (v, u) can also appear).
The following line contains one integer k (2 β€ k β€ n) β the number of intersections in Polycarp's path from home to his workplace.
The last line contains k integers p_1, p_2, ..., p_k (1 β€ p_i β€ n, all these integers are pairwise distinct) β the intersections along Polycarp's path in the order he arrived at them. p_1 is the intersection where Polycarp lives (s = p_1), and p_k is the intersection where Polycarp's workplace is situated (t = p_k). It is guaranteed that for every i β [1, k - 1] the road from p_i to p_{i + 1} exists, so the path goes along the roads of Bertown.
Output
Print two integers: the minimum and the maximum number of rebuilds that could have happened during the journey.
Examples
Input
6 9
1 5
5 4
1 2
2 3
3 4
4 1
2 6
6 4
4 2
4
1 2 3 4
Output
1 2
Input
7 7
1 2
2 3
3 4
4 5
5 6
6 7
7 1
7
1 2 3 4 5 6 7
Output
0 0
Input
8 13
8 7
8 6
7 5
7 4
6 5
6 4
5 3
5 2
4 3
4 2
3 1
2 1
1 8
5
8 7 5 2 1
Output
0 3
Submitted Solution:
```
n,m=map(int,input().split())
adj,uvs=[],[]
for i in range(m):
uvs.append([int(a) for a in input().split()])
k=int(input())
ks=[int(a) for a in input().split()]
uvs.sort()
ls,vis=[],[]
for i in range(n+1):
adj.append([])
ls.append(0)
vis.append(False)
for a in uvs:
adj[a[0]].append(a[1])
q=[]
mn,mx=0,0
for ii in range(len(ks[:-1])):
a1=ks[ii]
an=[]
best=10**100
for iii in range(len(adj[a1])):
a=adj[a1][iii]
ctr=0
if a!=ks[-1]:
dis=10**100
visited,distance=[],[]
for i in range(n+1):
visited.append(False)
distance.append(0)
q.append(a)
visited[a]=True
while len(q)>0:
s = q[0]
q.pop(0)
for u in adj[s]:
if (visited[u]):
break
visited[u] = True
distance[u] = distance[s]+1
if u==ks[-1]:
break
an.append(s)
if u!=ks[-1]:
q.append(u)
if distance[u]==best:
an.append(a)
if distance[u]>best:
pass
if best>distance[u]:
an=[]
best=min(distance[u],best)
an.append(a)
if ks[ii+1] in an:
if len(an)!=1:
mx+=1
else:
mn+=1
mx+=1
print(mn,mx)
```
No
| 60,800 | [
0.2081298828125,
0.3828125,
-0.0384521484375,
-0.06658935546875,
-0.04461669921875,
0.11614990234375,
-0.5634765625,
0.070556640625,
0.2783203125,
0.9794921875,
0.9951171875,
-0.1278076171875,
0.1580810546875,
-0.80615234375,
-0.467041015625,
0.118896484375,
-0.60302734375,
-0.3737... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A group of n merry programmers celebrate Robert Floyd's birthday. Polucarpus has got an honourable task of pouring Ber-Cola to everybody. Pouring the same amount of Ber-Cola to everybody is really important. In other words, the drink's volume in each of the n mugs must be the same.
Polycarpus has already began the process and he partially emptied the Ber-Cola bottle. Now the first mug has a1 milliliters of the drink, the second one has a2 milliliters and so on. The bottle has b milliliters left and Polycarpus plans to pour them into the mugs so that the main equation was fulfilled.
Write a program that would determine what volume of the drink Polycarpus needs to add into each mug to ensure that the following two conditions were fulfilled simultaneously:
* there were b milliliters poured in total. That is, the bottle need to be emptied;
* after the process is over, the volumes of the drink in the mugs should be equal.
Input
The first line contains a pair of integers n, b (2 β€ n β€ 100, 1 β€ b β€ 100), where n is the total number of friends in the group and b is the current volume of drink in the bottle. The second line contains a sequence of integers a1, a2, ..., an (0 β€ ai β€ 100), where ai is the current volume of drink in the i-th mug.
Output
Print a single number "-1" (without the quotes), if there is no solution. Otherwise, print n float numbers c1, c2, ..., cn, where ci is the volume of the drink to add in the i-th mug. Print the numbers with no less than 6 digits after the decimal point, print each ci on a single line. Polycarpus proved that if a solution exists then it is unique.
Russian locale is installed by default on the testing computer. Make sure that your solution use the point to separate the integer part of a real number from the decimal, not a comma.
Examples
Input
5 50
1 2 3 4 5
Output
12.000000
11.000000
10.000000
9.000000
8.000000
Input
2 2
1 100
Output
-1
Tags: math
Correct Solution:
```
def f(l1,al):
n,b = l1
c = (sum(al) + b)/n
if max(al)>c:
return [-1]
return [c-a for a in al]
l1 = list(map(int,input().split()))
l2 = list(map(int,input().split()))
[print(r) for r in f(l1,l2)]
```
| 60,937 | [
0.28271484375,
0.11273193359375,
0.556640625,
0.347412109375,
-0.441162109375,
-0.48291015625,
-0.1434326171875,
0.39453125,
0.04559326171875,
0.63134765625,
0.70751953125,
-0.040557861328125,
0.0909423828125,
-0.59521484375,
-0.5791015625,
0.370849609375,
-0.5185546875,
-0.7622070... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A group of n merry programmers celebrate Robert Floyd's birthday. Polucarpus has got an honourable task of pouring Ber-Cola to everybody. Pouring the same amount of Ber-Cola to everybody is really important. In other words, the drink's volume in each of the n mugs must be the same.
Polycarpus has already began the process and he partially emptied the Ber-Cola bottle. Now the first mug has a1 milliliters of the drink, the second one has a2 milliliters and so on. The bottle has b milliliters left and Polycarpus plans to pour them into the mugs so that the main equation was fulfilled.
Write a program that would determine what volume of the drink Polycarpus needs to add into each mug to ensure that the following two conditions were fulfilled simultaneously:
* there were b milliliters poured in total. That is, the bottle need to be emptied;
* after the process is over, the volumes of the drink in the mugs should be equal.
Input
The first line contains a pair of integers n, b (2 β€ n β€ 100, 1 β€ b β€ 100), where n is the total number of friends in the group and b is the current volume of drink in the bottle. The second line contains a sequence of integers a1, a2, ..., an (0 β€ ai β€ 100), where ai is the current volume of drink in the i-th mug.
Output
Print a single number "-1" (without the quotes), if there is no solution. Otherwise, print n float numbers c1, c2, ..., cn, where ci is the volume of the drink to add in the i-th mug. Print the numbers with no less than 6 digits after the decimal point, print each ci on a single line. Polycarpus proved that if a solution exists then it is unique.
Russian locale is installed by default on the testing computer. Make sure that your solution use the point to separate the integer part of a real number from the decimal, not a comma.
Examples
Input
5 50
1 2 3 4 5
Output
12.000000
11.000000
10.000000
9.000000
8.000000
Input
2 2
1 100
Output
-1
Tags: math
Correct Solution:
```
n,b=map(int,input().split())
d=list(map(int,input().split()))
l1=[]
mx=max(d)
for item in d:
l1.append(mx-item)
b-=(mx-item)
if b<0:
print(-1)
else:
for i in range(len(l1)):
l1[i]+=(b/n)
for item in l1:
print(format(item,'.6f'))
```
| 60,938 | [
0.271728515625,
0.1348876953125,
0.53759765625,
0.363037109375,
-0.438232421875,
-0.488037109375,
-0.1536865234375,
0.408203125,
0.0355224609375,
0.64501953125,
0.72314453125,
-0.015655517578125,
0.087646484375,
-0.64892578125,
-0.56298828125,
0.36181640625,
-0.50927734375,
-0.7446... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A group of n merry programmers celebrate Robert Floyd's birthday. Polucarpus has got an honourable task of pouring Ber-Cola to everybody. Pouring the same amount of Ber-Cola to everybody is really important. In other words, the drink's volume in each of the n mugs must be the same.
Polycarpus has already began the process and he partially emptied the Ber-Cola bottle. Now the first mug has a1 milliliters of the drink, the second one has a2 milliliters and so on. The bottle has b milliliters left and Polycarpus plans to pour them into the mugs so that the main equation was fulfilled.
Write a program that would determine what volume of the drink Polycarpus needs to add into each mug to ensure that the following two conditions were fulfilled simultaneously:
* there were b milliliters poured in total. That is, the bottle need to be emptied;
* after the process is over, the volumes of the drink in the mugs should be equal.
Input
The first line contains a pair of integers n, b (2 β€ n β€ 100, 1 β€ b β€ 100), where n is the total number of friends in the group and b is the current volume of drink in the bottle. The second line contains a sequence of integers a1, a2, ..., an (0 β€ ai β€ 100), where ai is the current volume of drink in the i-th mug.
Output
Print a single number "-1" (without the quotes), if there is no solution. Otherwise, print n float numbers c1, c2, ..., cn, where ci is the volume of the drink to add in the i-th mug. Print the numbers with no less than 6 digits after the decimal point, print each ci on a single line. Polycarpus proved that if a solution exists then it is unique.
Russian locale is installed by default on the testing computer. Make sure that your solution use the point to separate the integer part of a real number from the decimal, not a comma.
Examples
Input
5 50
1 2 3 4 5
Output
12.000000
11.000000
10.000000
9.000000
8.000000
Input
2 2
1 100
Output
-1
Tags: math
Correct Solution:
```
I = lambda: map(int, input().split())
n, b = I()
A = list(I())
x = (b+sum(A)) / n
if x < max(A):
print(-1)
else:
print(*(x-a for a in A), sep='\n')
```
| 60,939 | [
0.2646484375,
0.158447265625,
0.53369140625,
0.376953125,
-0.432373046875,
-0.475341796875,
-0.1708984375,
0.414306640625,
0.0340576171875,
0.6396484375,
0.72021484375,
-0.027984619140625,
0.07000732421875,
-0.646484375,
-0.57470703125,
0.351806640625,
-0.5009765625,
-0.73291015625... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A group of n merry programmers celebrate Robert Floyd's birthday. Polucarpus has got an honourable task of pouring Ber-Cola to everybody. Pouring the same amount of Ber-Cola to everybody is really important. In other words, the drink's volume in each of the n mugs must be the same.
Polycarpus has already began the process and he partially emptied the Ber-Cola bottle. Now the first mug has a1 milliliters of the drink, the second one has a2 milliliters and so on. The bottle has b milliliters left and Polycarpus plans to pour them into the mugs so that the main equation was fulfilled.
Write a program that would determine what volume of the drink Polycarpus needs to add into each mug to ensure that the following two conditions were fulfilled simultaneously:
* there were b milliliters poured in total. That is, the bottle need to be emptied;
* after the process is over, the volumes of the drink in the mugs should be equal.
Input
The first line contains a pair of integers n, b (2 β€ n β€ 100, 1 β€ b β€ 100), where n is the total number of friends in the group and b is the current volume of drink in the bottle. The second line contains a sequence of integers a1, a2, ..., an (0 β€ ai β€ 100), where ai is the current volume of drink in the i-th mug.
Output
Print a single number "-1" (without the quotes), if there is no solution. Otherwise, print n float numbers c1, c2, ..., cn, where ci is the volume of the drink to add in the i-th mug. Print the numbers with no less than 6 digits after the decimal point, print each ci on a single line. Polycarpus proved that if a solution exists then it is unique.
Russian locale is installed by default on the testing computer. Make sure that your solution use the point to separate the integer part of a real number from the decimal, not a comma.
Examples
Input
5 50
1 2 3 4 5
Output
12.000000
11.000000
10.000000
9.000000
8.000000
Input
2 2
1 100
Output
-1
Tags: math
Correct Solution:
```
n,m=map(int,input().split())
a=list(map(int,input().split()))
s=0
for j in range(n):
s=s+a[j]
s=s+m
e=s/n
t=0
for i in range(n):
if e-a[i]>=0:
a[i]=e-a[i]
else:
print(-1)
t=1
break
if t==0:
print(*a,sep="\n")
```
| 60,940 | [
0.273193359375,
0.1361083984375,
0.53662109375,
0.364013671875,
-0.4375,
-0.4873046875,
-0.152587890625,
0.40576171875,
0.0380859375,
0.64306640625,
0.724609375,
-0.015533447265625,
0.0888671875,
-0.64892578125,
-0.56591796875,
0.361328125,
-0.50634765625,
-0.74658203125,
-0.4670... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A group of n merry programmers celebrate Robert Floyd's birthday. Polucarpus has got an honourable task of pouring Ber-Cola to everybody. Pouring the same amount of Ber-Cola to everybody is really important. In other words, the drink's volume in each of the n mugs must be the same.
Polycarpus has already began the process and he partially emptied the Ber-Cola bottle. Now the first mug has a1 milliliters of the drink, the second one has a2 milliliters and so on. The bottle has b milliliters left and Polycarpus plans to pour them into the mugs so that the main equation was fulfilled.
Write a program that would determine what volume of the drink Polycarpus needs to add into each mug to ensure that the following two conditions were fulfilled simultaneously:
* there were b milliliters poured in total. That is, the bottle need to be emptied;
* after the process is over, the volumes of the drink in the mugs should be equal.
Input
The first line contains a pair of integers n, b (2 β€ n β€ 100, 1 β€ b β€ 100), where n is the total number of friends in the group and b is the current volume of drink in the bottle. The second line contains a sequence of integers a1, a2, ..., an (0 β€ ai β€ 100), where ai is the current volume of drink in the i-th mug.
Output
Print a single number "-1" (without the quotes), if there is no solution. Otherwise, print n float numbers c1, c2, ..., cn, where ci is the volume of the drink to add in the i-th mug. Print the numbers with no less than 6 digits after the decimal point, print each ci on a single line. Polycarpus proved that if a solution exists then it is unique.
Russian locale is installed by default on the testing computer. Make sure that your solution use the point to separate the integer part of a real number from the decimal, not a comma.
Examples
Input
5 50
1 2 3 4 5
Output
12.000000
11.000000
10.000000
9.000000
8.000000
Input
2 2
1 100
Output
-1
Tags: math
Correct Solution:
```
n, b = map(int, input().split())
a = [int(i) for i in input().split()]
d = [(b + sum(a)) / len(a) - i for i in a]
print(-1) if any(i for i in d if i < 0) else [print(i) for i in d]
```
| 60,941 | [
0.271728515625,
0.1348876953125,
0.53759765625,
0.363037109375,
-0.438232421875,
-0.488037109375,
-0.1536865234375,
0.408203125,
0.0355224609375,
0.64501953125,
0.72314453125,
-0.015655517578125,
0.087646484375,
-0.64892578125,
-0.56298828125,
0.36181640625,
-0.50927734375,
-0.7446... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A group of n merry programmers celebrate Robert Floyd's birthday. Polucarpus has got an honourable task of pouring Ber-Cola to everybody. Pouring the same amount of Ber-Cola to everybody is really important. In other words, the drink's volume in each of the n mugs must be the same.
Polycarpus has already began the process and he partially emptied the Ber-Cola bottle. Now the first mug has a1 milliliters of the drink, the second one has a2 milliliters and so on. The bottle has b milliliters left and Polycarpus plans to pour them into the mugs so that the main equation was fulfilled.
Write a program that would determine what volume of the drink Polycarpus needs to add into each mug to ensure that the following two conditions were fulfilled simultaneously:
* there were b milliliters poured in total. That is, the bottle need to be emptied;
* after the process is over, the volumes of the drink in the mugs should be equal.
Input
The first line contains a pair of integers n, b (2 β€ n β€ 100, 1 β€ b β€ 100), where n is the total number of friends in the group and b is the current volume of drink in the bottle. The second line contains a sequence of integers a1, a2, ..., an (0 β€ ai β€ 100), where ai is the current volume of drink in the i-th mug.
Output
Print a single number "-1" (without the quotes), if there is no solution. Otherwise, print n float numbers c1, c2, ..., cn, where ci is the volume of the drink to add in the i-th mug. Print the numbers with no less than 6 digits after the decimal point, print each ci on a single line. Polycarpus proved that if a solution exists then it is unique.
Russian locale is installed by default on the testing computer. Make sure that your solution use the point to separate the integer part of a real number from the decimal, not a comma.
Examples
Input
5 50
1 2 3 4 5
Output
12.000000
11.000000
10.000000
9.000000
8.000000
Input
2 2
1 100
Output
-1
Tags: math
Correct Solution:
```
x=[int(i) for i in input().split()]
n=x[0]
y=[int(i) for i in input().split()]
if x[1]<max(y)*n-sum(y):
print(-1)
raise SystemExit
for i in range(n):
s=x[1]/n-y[i]++sum(y)/n
print('%.6f'% s)
```
| 60,942 | [
0.271240234375,
0.1248779296875,
0.5439453125,
0.35791015625,
-0.44140625,
-0.487060546875,
-0.1494140625,
0.393798828125,
0.054107666015625,
0.62939453125,
0.72265625,
-0.032867431640625,
0.07183837890625,
-0.63037109375,
-0.5849609375,
0.36328125,
-0.5166015625,
-0.75341796875,
... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A group of n merry programmers celebrate Robert Floyd's birthday. Polucarpus has got an honourable task of pouring Ber-Cola to everybody. Pouring the same amount of Ber-Cola to everybody is really important. In other words, the drink's volume in each of the n mugs must be the same.
Polycarpus has already began the process and he partially emptied the Ber-Cola bottle. Now the first mug has a1 milliliters of the drink, the second one has a2 milliliters and so on. The bottle has b milliliters left and Polycarpus plans to pour them into the mugs so that the main equation was fulfilled.
Write a program that would determine what volume of the drink Polycarpus needs to add into each mug to ensure that the following two conditions were fulfilled simultaneously:
* there were b milliliters poured in total. That is, the bottle need to be emptied;
* after the process is over, the volumes of the drink in the mugs should be equal.
Input
The first line contains a pair of integers n, b (2 β€ n β€ 100, 1 β€ b β€ 100), where n is the total number of friends in the group and b is the current volume of drink in the bottle. The second line contains a sequence of integers a1, a2, ..., an (0 β€ ai β€ 100), where ai is the current volume of drink in the i-th mug.
Output
Print a single number "-1" (without the quotes), if there is no solution. Otherwise, print n float numbers c1, c2, ..., cn, where ci is the volume of the drink to add in the i-th mug. Print the numbers with no less than 6 digits after the decimal point, print each ci on a single line. Polycarpus proved that if a solution exists then it is unique.
Russian locale is installed by default on the testing computer. Make sure that your solution use the point to separate the integer part of a real number from the decimal, not a comma.
Examples
Input
5 50
1 2 3 4 5
Output
12.000000
11.000000
10.000000
9.000000
8.000000
Input
2 2
1 100
Output
-1
Tags: math
Correct Solution:
```
n, b = map(int, input().split())
t = list(map(int, input().split()))
s, d = sum(t), max(t)
b -= d * n - s
if b < 0: print(-1)
else:
d += b / n
for i in range(n): t[i] = str(d - t[i])
print('\n'.join(t))
```
| 60,943 | [
0.271728515625,
0.1348876953125,
0.53759765625,
0.363037109375,
-0.438232421875,
-0.488037109375,
-0.1536865234375,
0.408203125,
0.0355224609375,
0.64501953125,
0.72314453125,
-0.015655517578125,
0.087646484375,
-0.64892578125,
-0.56298828125,
0.36181640625,
-0.50927734375,
-0.7446... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A group of n merry programmers celebrate Robert Floyd's birthday. Polucarpus has got an honourable task of pouring Ber-Cola to everybody. Pouring the same amount of Ber-Cola to everybody is really important. In other words, the drink's volume in each of the n mugs must be the same.
Polycarpus has already began the process and he partially emptied the Ber-Cola bottle. Now the first mug has a1 milliliters of the drink, the second one has a2 milliliters and so on. The bottle has b milliliters left and Polycarpus plans to pour them into the mugs so that the main equation was fulfilled.
Write a program that would determine what volume of the drink Polycarpus needs to add into each mug to ensure that the following two conditions were fulfilled simultaneously:
* there were b milliliters poured in total. That is, the bottle need to be emptied;
* after the process is over, the volumes of the drink in the mugs should be equal.
Input
The first line contains a pair of integers n, b (2 β€ n β€ 100, 1 β€ b β€ 100), where n is the total number of friends in the group and b is the current volume of drink in the bottle. The second line contains a sequence of integers a1, a2, ..., an (0 β€ ai β€ 100), where ai is the current volume of drink in the i-th mug.
Output
Print a single number "-1" (without the quotes), if there is no solution. Otherwise, print n float numbers c1, c2, ..., cn, where ci is the volume of the drink to add in the i-th mug. Print the numbers with no less than 6 digits after the decimal point, print each ci on a single line. Polycarpus proved that if a solution exists then it is unique.
Russian locale is installed by default on the testing computer. Make sure that your solution use the point to separate the integer part of a real number from the decimal, not a comma.
Examples
Input
5 50
1 2 3 4 5
Output
12.000000
11.000000
10.000000
9.000000
8.000000
Input
2 2
1 100
Output
-1
Tags: math
Correct Solution:
```
n, b = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
sumN = 0
for i in range(n):
sumN += a[i]
ans = (sumN + b) / n
if ans - max(a) < 0:
print(-1)
exit(0)
for i in range(n):
print(ans - a[i])
```
| 60,944 | [
0.275390625,
0.1214599609375,
0.552734375,
0.389404296875,
-0.43798828125,
-0.484375,
-0.135498046875,
0.397216796875,
0.042755126953125,
0.63330078125,
0.732421875,
-0.02813720703125,
0.068359375,
-0.62939453125,
-0.59326171875,
0.37060546875,
-0.505859375,
-0.74609375,
-0.46972... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A group of n merry programmers celebrate Robert Floyd's birthday. Polucarpus has got an honourable task of pouring Ber-Cola to everybody. Pouring the same amount of Ber-Cola to everybody is really important. In other words, the drink's volume in each of the n mugs must be the same.
Polycarpus has already began the process and he partially emptied the Ber-Cola bottle. Now the first mug has a1 milliliters of the drink, the second one has a2 milliliters and so on. The bottle has b milliliters left and Polycarpus plans to pour them into the mugs so that the main equation was fulfilled.
Write a program that would determine what volume of the drink Polycarpus needs to add into each mug to ensure that the following two conditions were fulfilled simultaneously:
* there were b milliliters poured in total. That is, the bottle need to be emptied;
* after the process is over, the volumes of the drink in the mugs should be equal.
Input
The first line contains a pair of integers n, b (2 β€ n β€ 100, 1 β€ b β€ 100), where n is the total number of friends in the group and b is the current volume of drink in the bottle. The second line contains a sequence of integers a1, a2, ..., an (0 β€ ai β€ 100), where ai is the current volume of drink in the i-th mug.
Output
Print a single number "-1" (without the quotes), if there is no solution. Otherwise, print n float numbers c1, c2, ..., cn, where ci is the volume of the drink to add in the i-th mug. Print the numbers with no less than 6 digits after the decimal point, print each ci on a single line. Polycarpus proved that if a solution exists then it is unique.
Russian locale is installed by default on the testing computer. Make sure that your solution use the point to separate the integer part of a real number from the decimal, not a comma.
Examples
Input
5 50
1 2 3 4 5
Output
12.000000
11.000000
10.000000
9.000000
8.000000
Input
2 2
1 100
Output
-1
Submitted Solution:
```
I=lambda:map(int,input().split())
P=print
n,b=I()
a=list(I())
x=(b+sum(a))/n
if any(i>x for i in a):P(-1)
else:[P(x-i)for i in a]
```
Yes
| 60,945 | [
0.275634765625,
0.193359375,
0.5390625,
0.2388916015625,
-0.5185546875,
-0.347900390625,
-0.2354736328125,
0.460205078125,
-0.0035991668701171875,
0.61669921875,
0.70947265625,
-0.06341552734375,
0.0113525390625,
-0.56640625,
-0.5498046875,
0.2265625,
-0.4912109375,
-0.71142578125,... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A group of n merry programmers celebrate Robert Floyd's birthday. Polucarpus has got an honourable task of pouring Ber-Cola to everybody. Pouring the same amount of Ber-Cola to everybody is really important. In other words, the drink's volume in each of the n mugs must be the same.
Polycarpus has already began the process and he partially emptied the Ber-Cola bottle. Now the first mug has a1 milliliters of the drink, the second one has a2 milliliters and so on. The bottle has b milliliters left and Polycarpus plans to pour them into the mugs so that the main equation was fulfilled.
Write a program that would determine what volume of the drink Polycarpus needs to add into each mug to ensure that the following two conditions were fulfilled simultaneously:
* there were b milliliters poured in total. That is, the bottle need to be emptied;
* after the process is over, the volumes of the drink in the mugs should be equal.
Input
The first line contains a pair of integers n, b (2 β€ n β€ 100, 1 β€ b β€ 100), where n is the total number of friends in the group and b is the current volume of drink in the bottle. The second line contains a sequence of integers a1, a2, ..., an (0 β€ ai β€ 100), where ai is the current volume of drink in the i-th mug.
Output
Print a single number "-1" (without the quotes), if there is no solution. Otherwise, print n float numbers c1, c2, ..., cn, where ci is the volume of the drink to add in the i-th mug. Print the numbers with no less than 6 digits after the decimal point, print each ci on a single line. Polycarpus proved that if a solution exists then it is unique.
Russian locale is installed by default on the testing computer. Make sure that your solution use the point to separate the integer part of a real number from the decimal, not a comma.
Examples
Input
5 50
1 2 3 4 5
Output
12.000000
11.000000
10.000000
9.000000
8.000000
Input
2 2
1 100
Output
-1
Submitted Solution:
```
a,b=map(int,input().split())
x=[int(q) for q in input().split()]
l=sum(x)
total = l+b
each = total/a
reqd=0
z=max(x)
for i in range(a):
reqd+=abs(x[i]-z)
if b<reqd:
print(-1)
else:
for i in range(a):
print(each-x[i])
```
Yes
| 60,946 | [
0.28173828125,
0.18505859375,
0.53564453125,
0.2313232421875,
-0.5234375,
-0.3544921875,
-0.2236328125,
0.4580078125,
-0.005725860595703125,
0.61279296875,
0.71142578125,
-0.049102783203125,
0.0280303955078125,
-0.568359375,
-0.54150390625,
0.2362060546875,
-0.501953125,
-0.7207031... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A group of n merry programmers celebrate Robert Floyd's birthday. Polucarpus has got an honourable task of pouring Ber-Cola to everybody. Pouring the same amount of Ber-Cola to everybody is really important. In other words, the drink's volume in each of the n mugs must be the same.
Polycarpus has already began the process and he partially emptied the Ber-Cola bottle. Now the first mug has a1 milliliters of the drink, the second one has a2 milliliters and so on. The bottle has b milliliters left and Polycarpus plans to pour them into the mugs so that the main equation was fulfilled.
Write a program that would determine what volume of the drink Polycarpus needs to add into each mug to ensure that the following two conditions were fulfilled simultaneously:
* there were b milliliters poured in total. That is, the bottle need to be emptied;
* after the process is over, the volumes of the drink in the mugs should be equal.
Input
The first line contains a pair of integers n, b (2 β€ n β€ 100, 1 β€ b β€ 100), where n is the total number of friends in the group and b is the current volume of drink in the bottle. The second line contains a sequence of integers a1, a2, ..., an (0 β€ ai β€ 100), where ai is the current volume of drink in the i-th mug.
Output
Print a single number "-1" (without the quotes), if there is no solution. Otherwise, print n float numbers c1, c2, ..., cn, where ci is the volume of the drink to add in the i-th mug. Print the numbers with no less than 6 digits after the decimal point, print each ci on a single line. Polycarpus proved that if a solution exists then it is unique.
Russian locale is installed by default on the testing computer. Make sure that your solution use the point to separate the integer part of a real number from the decimal, not a comma.
Examples
Input
5 50
1 2 3 4 5
Output
12.000000
11.000000
10.000000
9.000000
8.000000
Input
2 2
1 100
Output
-1
Submitted Solution:
```
n,t=map(int,input().split())
l=list(map(int,input().split()))
X=float((sum(l)+t)/n )
#print(X)
for i in l:
if(i>X):
print(-1)
break
else:
for i in l:
print("{0:.6f}".format(X-i))
```
Yes
| 60,947 | [
0.277587890625,
0.1871337890625,
0.5400390625,
0.2327880859375,
-0.52783203125,
-0.35400390625,
-0.2218017578125,
0.45849609375,
-0.0015153884887695312,
0.61474609375,
0.70458984375,
-0.0478515625,
0.0227508544921875,
-0.572265625,
-0.54296875,
0.23583984375,
-0.496826171875,
-0.72... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A group of n merry programmers celebrate Robert Floyd's birthday. Polucarpus has got an honourable task of pouring Ber-Cola to everybody. Pouring the same amount of Ber-Cola to everybody is really important. In other words, the drink's volume in each of the n mugs must be the same.
Polycarpus has already began the process and he partially emptied the Ber-Cola bottle. Now the first mug has a1 milliliters of the drink, the second one has a2 milliliters and so on. The bottle has b milliliters left and Polycarpus plans to pour them into the mugs so that the main equation was fulfilled.
Write a program that would determine what volume of the drink Polycarpus needs to add into each mug to ensure that the following two conditions were fulfilled simultaneously:
* there were b milliliters poured in total. That is, the bottle need to be emptied;
* after the process is over, the volumes of the drink in the mugs should be equal.
Input
The first line contains a pair of integers n, b (2 β€ n β€ 100, 1 β€ b β€ 100), where n is the total number of friends in the group and b is the current volume of drink in the bottle. The second line contains a sequence of integers a1, a2, ..., an (0 β€ ai β€ 100), where ai is the current volume of drink in the i-th mug.
Output
Print a single number "-1" (without the quotes), if there is no solution. Otherwise, print n float numbers c1, c2, ..., cn, where ci is the volume of the drink to add in the i-th mug. Print the numbers with no less than 6 digits after the decimal point, print each ci on a single line. Polycarpus proved that if a solution exists then it is unique.
Russian locale is installed by default on the testing computer. Make sure that your solution use the point to separate the integer part of a real number from the decimal, not a comma.
Examples
Input
5 50
1 2 3 4 5
Output
12.000000
11.000000
10.000000
9.000000
8.000000
Input
2 2
1 100
Output
-1
Submitted Solution:
```
n, b = tuple(map(int, input().split()))
a = list(map(int, input().split()))
maximum = max(a)
d = []
for i in range(n):
diff = maximum - a[i]
if b >= diff:
d.append(a[i] + diff)
b -= diff
el = d[0]
res = 'ok'
for j in d:
if j != el:
res = 'not ok'
add = 0
if len(d) != len(a):
res = 'not ok'
else:
add += b / len(d)
# b -= b
if res == 'ok':
ans = [i-j for i,j in zip(d,a)]
for k in range(n):
ans[k] += add
if type(ans[k]) == int:
print ('{:.6f}'.format(ans[k]))
else:
print (ans[k])
else:
print (-1)
```
Yes
| 60,948 | [
0.28857421875,
0.176513671875,
0.54443359375,
0.23095703125,
-0.5498046875,
-0.37158203125,
-0.213134765625,
0.454345703125,
0.017120361328125,
0.60986328125,
0.70263671875,
-0.05389404296875,
0.017822265625,
-0.5517578125,
-0.552734375,
0.24072265625,
-0.50439453125,
-0.7387695312... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A group of n merry programmers celebrate Robert Floyd's birthday. Polucarpus has got an honourable task of pouring Ber-Cola to everybody. Pouring the same amount of Ber-Cola to everybody is really important. In other words, the drink's volume in each of the n mugs must be the same.
Polycarpus has already began the process and he partially emptied the Ber-Cola bottle. Now the first mug has a1 milliliters of the drink, the second one has a2 milliliters and so on. The bottle has b milliliters left and Polycarpus plans to pour them into the mugs so that the main equation was fulfilled.
Write a program that would determine what volume of the drink Polycarpus needs to add into each mug to ensure that the following two conditions were fulfilled simultaneously:
* there were b milliliters poured in total. That is, the bottle need to be emptied;
* after the process is over, the volumes of the drink in the mugs should be equal.
Input
The first line contains a pair of integers n, b (2 β€ n β€ 100, 1 β€ b β€ 100), where n is the total number of friends in the group and b is the current volume of drink in the bottle. The second line contains a sequence of integers a1, a2, ..., an (0 β€ ai β€ 100), where ai is the current volume of drink in the i-th mug.
Output
Print a single number "-1" (without the quotes), if there is no solution. Otherwise, print n float numbers c1, c2, ..., cn, where ci is the volume of the drink to add in the i-th mug. Print the numbers with no less than 6 digits after the decimal point, print each ci on a single line. Polycarpus proved that if a solution exists then it is unique.
Russian locale is installed by default on the testing computer. Make sure that your solution use the point to separate the integer part of a real number from the decimal, not a comma.
Examples
Input
5 50
1 2 3 4 5
Output
12.000000
11.000000
10.000000
9.000000
8.000000
Input
2 2
1 100
Output
-1
Submitted Solution:
```
n,b= map(int, input().split())
b=float(b)
arr = list(map(float, (input().split())))
total = b + sum(arr)
totalone = total/n
need=0.000000
needarr=[]
flag = ''
for i in range(n):
need=totalone-arr[i]
if(need > b):
print(-1)
flag='no'
break
else:
needarr.append(need)
if(flag!='no'):
for i in range(n):
print('{0:.6f}'.format(needarr[i]))
```
No
| 60,949 | [
0.277587890625,
0.186767578125,
0.53759765625,
0.2303466796875,
-0.52490234375,
-0.357177734375,
-0.224365234375,
0.459228515625,
-0.004520416259765625,
0.61572265625,
0.7109375,
-0.046173095703125,
0.026580810546875,
-0.56787109375,
-0.54150390625,
0.236083984375,
-0.50244140625,
... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A group of n merry programmers celebrate Robert Floyd's birthday. Polucarpus has got an honourable task of pouring Ber-Cola to everybody. Pouring the same amount of Ber-Cola to everybody is really important. In other words, the drink's volume in each of the n mugs must be the same.
Polycarpus has already began the process and he partially emptied the Ber-Cola bottle. Now the first mug has a1 milliliters of the drink, the second one has a2 milliliters and so on. The bottle has b milliliters left and Polycarpus plans to pour them into the mugs so that the main equation was fulfilled.
Write a program that would determine what volume of the drink Polycarpus needs to add into each mug to ensure that the following two conditions were fulfilled simultaneously:
* there were b milliliters poured in total. That is, the bottle need to be emptied;
* after the process is over, the volumes of the drink in the mugs should be equal.
Input
The first line contains a pair of integers n, b (2 β€ n β€ 100, 1 β€ b β€ 100), where n is the total number of friends in the group and b is the current volume of drink in the bottle. The second line contains a sequence of integers a1, a2, ..., an (0 β€ ai β€ 100), where ai is the current volume of drink in the i-th mug.
Output
Print a single number "-1" (without the quotes), if there is no solution. Otherwise, print n float numbers c1, c2, ..., cn, where ci is the volume of the drink to add in the i-th mug. Print the numbers with no less than 6 digits after the decimal point, print each ci on a single line. Polycarpus proved that if a solution exists then it is unique.
Russian locale is installed by default on the testing computer. Make sure that your solution use the point to separate the integer part of a real number from the decimal, not a comma.
Examples
Input
5 50
1 2 3 4 5
Output
12.000000
11.000000
10.000000
9.000000
8.000000
Input
2 2
1 100
Output
-1
Submitted Solution:
```
r = lambda: int(input())
ra = lambda: [*map(int, input().split())]
p = lambda a: print('{:.6f}'.format(a))
n, m = ra()
a = ra()
b = []
e = (m+sum(a))/n
for i in range(n):
b.append(float(('{:.6f}'.format(e-a[i]))))
m-=abs(b[len(b)-1])
a[i]+=b[len(b)-1]
if m<0:
print(-1)
else:
for i in b:
p(i)
```
No
| 60,950 | [
0.279296875,
0.1885986328125,
0.54296875,
0.2371826171875,
-0.521484375,
-0.344970703125,
-0.2236328125,
0.46044921875,
0.00849151611328125,
0.60595703125,
0.70849609375,
-0.06475830078125,
-0.0045318603515625,
-0.56396484375,
-0.5595703125,
0.2183837890625,
-0.490966796875,
-0.717... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A group of n merry programmers celebrate Robert Floyd's birthday. Polucarpus has got an honourable task of pouring Ber-Cola to everybody. Pouring the same amount of Ber-Cola to everybody is really important. In other words, the drink's volume in each of the n mugs must be the same.
Polycarpus has already began the process and he partially emptied the Ber-Cola bottle. Now the first mug has a1 milliliters of the drink, the second one has a2 milliliters and so on. The bottle has b milliliters left and Polycarpus plans to pour them into the mugs so that the main equation was fulfilled.
Write a program that would determine what volume of the drink Polycarpus needs to add into each mug to ensure that the following two conditions were fulfilled simultaneously:
* there were b milliliters poured in total. That is, the bottle need to be emptied;
* after the process is over, the volumes of the drink in the mugs should be equal.
Input
The first line contains a pair of integers n, b (2 β€ n β€ 100, 1 β€ b β€ 100), where n is the total number of friends in the group and b is the current volume of drink in the bottle. The second line contains a sequence of integers a1, a2, ..., an (0 β€ ai β€ 100), where ai is the current volume of drink in the i-th mug.
Output
Print a single number "-1" (without the quotes), if there is no solution. Otherwise, print n float numbers c1, c2, ..., cn, where ci is the volume of the drink to add in the i-th mug. Print the numbers with no less than 6 digits after the decimal point, print each ci on a single line. Polycarpus proved that if a solution exists then it is unique.
Russian locale is installed by default on the testing computer. Make sure that your solution use the point to separate the integer part of a real number from the decimal, not a comma.
Examples
Input
5 50
1 2 3 4 5
Output
12.000000
11.000000
10.000000
9.000000
8.000000
Input
2 2
1 100
Output
-1
Submitted Solution:
```
n, b = map(int, input().split())
a = list(float(x) for x in input().split())
s = max(a)
c = [0]*n
for i in range(n):
m = s-a[i]
b = b-m
c[i] = c[i]+m
if b > 0:
for i in range(n):
c[i] = c[i] + b/n
for i in range(n):
print("%.6f" % c[i])
else:
print("-1")
```
No
| 60,951 | [
0.277587890625,
0.186767578125,
0.53759765625,
0.2303466796875,
-0.52490234375,
-0.357177734375,
-0.224365234375,
0.459228515625,
-0.004520416259765625,
0.61572265625,
0.7109375,
-0.046173095703125,
0.026580810546875,
-0.56787109375,
-0.54150390625,
0.236083984375,
-0.50244140625,
... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A group of n merry programmers celebrate Robert Floyd's birthday. Polucarpus has got an honourable task of pouring Ber-Cola to everybody. Pouring the same amount of Ber-Cola to everybody is really important. In other words, the drink's volume in each of the n mugs must be the same.
Polycarpus has already began the process and he partially emptied the Ber-Cola bottle. Now the first mug has a1 milliliters of the drink, the second one has a2 milliliters and so on. The bottle has b milliliters left and Polycarpus plans to pour them into the mugs so that the main equation was fulfilled.
Write a program that would determine what volume of the drink Polycarpus needs to add into each mug to ensure that the following two conditions were fulfilled simultaneously:
* there were b milliliters poured in total. That is, the bottle need to be emptied;
* after the process is over, the volumes of the drink in the mugs should be equal.
Input
The first line contains a pair of integers n, b (2 β€ n β€ 100, 1 β€ b β€ 100), where n is the total number of friends in the group and b is the current volume of drink in the bottle. The second line contains a sequence of integers a1, a2, ..., an (0 β€ ai β€ 100), where ai is the current volume of drink in the i-th mug.
Output
Print a single number "-1" (without the quotes), if there is no solution. Otherwise, print n float numbers c1, c2, ..., cn, where ci is the volume of the drink to add in the i-th mug. Print the numbers with no less than 6 digits after the decimal point, print each ci on a single line. Polycarpus proved that if a solution exists then it is unique.
Russian locale is installed by default on the testing computer. Make sure that your solution use the point to separate the integer part of a real number from the decimal, not a comma.
Examples
Input
5 50
1 2 3 4 5
Output
12.000000
11.000000
10.000000
9.000000
8.000000
Input
2 2
1 100
Output
-1
Submitted Solution:
```
n, b = map(int, input().split())
s = list(map(int, input().split()))
sb = sum(s) + b
sb /= n
if sb - max(s) > 0:
for x in s:
print(sb-x)
else:
print('-1')
```
No
| 60,952 | [
0.277587890625,
0.186767578125,
0.53759765625,
0.2303466796875,
-0.52490234375,
-0.357177734375,
-0.224365234375,
0.459228515625,
-0.004520416259765625,
0.61572265625,
0.7109375,
-0.046173095703125,
0.026580810546875,
-0.56787109375,
-0.54150390625,
0.236083984375,
-0.50244140625,
... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is making a quest for his friends. He has already made n tasks, for each task the boy evaluated how interesting it is as an integer qi, and the time ti in minutes needed to complete the task.
An interesting feature of his quest is: each participant should get the task that is best suited for him, depending on his preferences. The task is chosen based on an interactive quiz that consists of some questions. The player should answer these questions with "yes" or "no". Depending on the answer to the question, the participant either moves to another question or goes to one of the tasks that are in the quest. In other words, the quest is a binary tree, its nodes contain questions and its leaves contain tasks.
We know that answering any of the questions that are asked before getting a task takes exactly one minute from the quest player. Polycarp knows that his friends are busy people and they can't participate in the quest for more than T minutes. Polycarp wants to choose some of the n tasks he made, invent the corresponding set of questions for them and use them to form an interactive quiz as a binary tree so that no matter how the player answers quiz questions, he spends at most T minutes on completing the whole quest (that is, answering all the questions and completing the task). Specifically, the quest can contain zero questions and go straight to the task. Each task can only be used once (i.e., the people who give different answers to questions should get different tasks).
Polycarp wants the total "interest" value of the tasks involved in the quest to be as large as possible. Help him determine the maximum possible total interest value of the task considering that the quest should be completed in T minutes at any variant of answering questions.
Input
The first line contains two integers n and T (1 β€ n β€ 1000, 1 β€ T β€ 100) β the number of tasks made by Polycarp and the maximum time a quest player should fit into.
Next n lines contain two integers ti, qi (1 β€ ti β€ T, 1 β€ qi β€ 1000) each β the time in minutes needed to complete the i-th task and its interest value.
Output
Print a single integer β the maximum possible total interest value of all the tasks in the quest.
Examples
Input
5 5
1 1
1 1
2 2
3 3
4 4
Output
11
Input
5 5
4 1
4 2
4 3
4 4
4 5
Output
9
Input
2 2
1 1
2 10
Output
10
Note
In the first sample test all the five tasks can be complemented with four questions and joined into one quest.
In the second sample test it is impossible to use all the five tasks, but you can take two of them, the most interesting ones.
In the third sample test the optimal strategy is to include only the second task into the quest.
Here is the picture that illustrates the answers to the sample tests. The blue circles represent the questions, the two arrows that go from every circle represent where a person goes depending on his answer to that question. The tasks are the red ovals.
<image>
Tags: dp, greedy
Correct Solution:
```
from collections import defaultdict
if __name__ == '__main__':
n, T = [int(_) for _ in input().split()]
data = defaultdict(list)
for i in range(n):
t, q = [int(_) for _ in input().split()]
data[T - t].append(q)
prev_level = []
for level_id in range(1, T + 1):
level = sorted(data[T - level_id] + prev_level, reverse=True)
if T - level_id <= 10:
max_size = 2 ** (T - level_id)
level = level[:max_size]
if len(level) % 2 == 1:
level.append(0)
prev_level = [
level[i] + level[i + 1]
for i in range(0, len(level), 2)
]
print(prev_level[0])
```
| 63,525 | [
0.4765625,
0.490966796875,
0.1439208984375,
0.4326171875,
-0.32177734375,
-0.288330078125,
-0.29931640625,
0.1876220703125,
0.278564453125,
0.41748046875,
0.6796875,
-0.220458984375,
0.1893310546875,
-0.7275390625,
-0.28173828125,
0.309326171875,
-0.9423828125,
-0.755859375,
-0.6... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has three sisters: Alice, Barbara, and Cerene. They're collecting coins. Currently, Alice has a coins, Barbara has b coins and Cerene has c coins. Recently Polycarp has returned from the trip around the world and brought n coins.
He wants to distribute all these n coins between his sisters in such a way that the number of coins Alice has is equal to the number of coins Barbara has and is equal to the number of coins Cerene has. In other words, if Polycarp gives A coins to Alice, B coins to Barbara and C coins to Cerene (A+B+C=n), then a + A = b + B = c + C.
Note that A, B or C (the number of coins Polycarp gives to Alice, Barbara and Cerene correspondingly) can be 0.
Your task is to find out if it is possible to distribute all n coins between sisters in a way described above.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 10^4) β the number of test cases.
The next t lines describe test cases. Each test case is given on a new line and consists of four space-separated integers a, b, c and n (1 β€ a, b, c, n β€ 10^8) β the number of coins Alice has, the number of coins Barbara has, the number of coins Cerene has and the number of coins Polycarp has.
Output
For each test case, print "YES" if Polycarp can distribute all n coins between his sisters and "NO" otherwise.
Example
Input
5
5 3 2 8
100 101 102 105
3 2 1 100000000
10 20 15 14
101 101 101 3
Output
YES
YES
NO
NO
YES
Tags: math
Correct Solution:
```
t=int(input())
for q in range(t):
a=[int(x) for x in input().split()]
total=a[3]
a=a[0:3]
a.sort(reverse=True)
diff1=a[0]-a[2]
diff2=a[0]-a[1]
total=total-diff1-diff2
if total%3==0 and total>=0:
print("YES")
else:
print("NO")
```
| 64,100 | [
0.371337890625,
0.4111328125,
0.00897979736328125,
-0.0667724609375,
-0.378173828125,
-0.2454833984375,
-0.2578125,
0.200927734375,
0.2022705078125,
0.705078125,
0.66455078125,
0.15185546875,
0.2178955078125,
-0.7626953125,
-0.68701171875,
-0.08978271484375,
-0.671875,
-0.575195312... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has three sisters: Alice, Barbara, and Cerene. They're collecting coins. Currently, Alice has a coins, Barbara has b coins and Cerene has c coins. Recently Polycarp has returned from the trip around the world and brought n coins.
He wants to distribute all these n coins between his sisters in such a way that the number of coins Alice has is equal to the number of coins Barbara has and is equal to the number of coins Cerene has. In other words, if Polycarp gives A coins to Alice, B coins to Barbara and C coins to Cerene (A+B+C=n), then a + A = b + B = c + C.
Note that A, B or C (the number of coins Polycarp gives to Alice, Barbara and Cerene correspondingly) can be 0.
Your task is to find out if it is possible to distribute all n coins between sisters in a way described above.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 10^4) β the number of test cases.
The next t lines describe test cases. Each test case is given on a new line and consists of four space-separated integers a, b, c and n (1 β€ a, b, c, n β€ 10^8) β the number of coins Alice has, the number of coins Barbara has, the number of coins Cerene has and the number of coins Polycarp has.
Output
For each test case, print "YES" if Polycarp can distribute all n coins between his sisters and "NO" otherwise.
Example
Input
5
5 3 2 8
100 101 102 105
3 2 1 100000000
10 20 15 14
101 101 101 3
Output
YES
YES
NO
NO
YES
Tags: math
Correct Solution:
```
def call():
a,b,c,n=map(int,input().split())
l=[a,b,c]
l.sort()
n-=2*l[2]-l[1]-l[0]
print(("YES","NO")[n<0 or n%3!=0])
for _ in range(int(input())):
call()
```
| 64,101 | [
0.343505859375,
0.44189453125,
-0.043609619140625,
-0.06689453125,
-0.356689453125,
-0.235107421875,
-0.29443359375,
0.25634765625,
0.2049560546875,
0.68896484375,
0.70166015625,
0.1856689453125,
0.256591796875,
-0.7822265625,
-0.69775390625,
-0.083740234375,
-0.67236328125,
-0.554... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has three sisters: Alice, Barbara, and Cerene. They're collecting coins. Currently, Alice has a coins, Barbara has b coins and Cerene has c coins. Recently Polycarp has returned from the trip around the world and brought n coins.
He wants to distribute all these n coins between his sisters in such a way that the number of coins Alice has is equal to the number of coins Barbara has and is equal to the number of coins Cerene has. In other words, if Polycarp gives A coins to Alice, B coins to Barbara and C coins to Cerene (A+B+C=n), then a + A = b + B = c + C.
Note that A, B or C (the number of coins Polycarp gives to Alice, Barbara and Cerene correspondingly) can be 0.
Your task is to find out if it is possible to distribute all n coins between sisters in a way described above.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 10^4) β the number of test cases.
The next t lines describe test cases. Each test case is given on a new line and consists of four space-separated integers a, b, c and n (1 β€ a, b, c, n β€ 10^8) β the number of coins Alice has, the number of coins Barbara has, the number of coins Cerene has and the number of coins Polycarp has.
Output
For each test case, print "YES" if Polycarp can distribute all n coins between his sisters and "NO" otherwise.
Example
Input
5
5 3 2 8
100 101 102 105
3 2 1 100000000
10 20 15 14
101 101 101 3
Output
YES
YES
NO
NO
YES
Tags: math
Correct Solution:
```
n = int(input())
for i in range(n):
x = list(map(int, input().split()))
if sum(x) % 3 == 0:
mean = sum(x) // 3
flag = True
for i in range(3):
if x[i] > mean:
flag = False
if flag:
print("YES")
else:
print("NO")
else:
print("NO")
```
| 64,102 | [
0.33349609375,
0.3857421875,
-0.01373291015625,
-0.044830322265625,
-0.3427734375,
-0.26123046875,
-0.249267578125,
0.251953125,
0.2169189453125,
0.69091796875,
0.68896484375,
0.1580810546875,
0.25146484375,
-0.77490234375,
-0.6923828125,
-0.08270263671875,
-0.6982421875,
-0.581054... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has three sisters: Alice, Barbara, and Cerene. They're collecting coins. Currently, Alice has a coins, Barbara has b coins and Cerene has c coins. Recently Polycarp has returned from the trip around the world and brought n coins.
He wants to distribute all these n coins between his sisters in such a way that the number of coins Alice has is equal to the number of coins Barbara has and is equal to the number of coins Cerene has. In other words, if Polycarp gives A coins to Alice, B coins to Barbara and C coins to Cerene (A+B+C=n), then a + A = b + B = c + C.
Note that A, B or C (the number of coins Polycarp gives to Alice, Barbara and Cerene correspondingly) can be 0.
Your task is to find out if it is possible to distribute all n coins between sisters in a way described above.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 10^4) β the number of test cases.
The next t lines describe test cases. Each test case is given on a new line and consists of four space-separated integers a, b, c and n (1 β€ a, b, c, n β€ 10^8) β the number of coins Alice has, the number of coins Barbara has, the number of coins Cerene has and the number of coins Polycarp has.
Output
For each test case, print "YES" if Polycarp can distribute all n coins between his sisters and "NO" otherwise.
Example
Input
5
5 3 2 8
100 101 102 105
3 2 1 100000000
10 20 15 14
101 101 101 3
Output
YES
YES
NO
NO
YES
Tags: math
Correct Solution:
```
t = int(input())
for i in range(t):
a, b, c, n = map(int, input().split())
mx = max(max(a, b), c)
mn = mx-a + mx-b + mx-c
res = "NO" if n<mn or (n-mn)%3!=0 else "YES"
print(res)
```
| 64,103 | [
0.3564453125,
0.422119140625,
0.010040283203125,
-0.04656982421875,
-0.390380859375,
-0.246826171875,
-0.258544921875,
0.220703125,
0.1842041015625,
0.6923828125,
0.66552734375,
0.17431640625,
0.262451171875,
-0.79931640625,
-0.68359375,
-0.0977783203125,
-0.6689453125,
-0.54541015... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has three sisters: Alice, Barbara, and Cerene. They're collecting coins. Currently, Alice has a coins, Barbara has b coins and Cerene has c coins. Recently Polycarp has returned from the trip around the world and brought n coins.
He wants to distribute all these n coins between his sisters in such a way that the number of coins Alice has is equal to the number of coins Barbara has and is equal to the number of coins Cerene has. In other words, if Polycarp gives A coins to Alice, B coins to Barbara and C coins to Cerene (A+B+C=n), then a + A = b + B = c + C.
Note that A, B or C (the number of coins Polycarp gives to Alice, Barbara and Cerene correspondingly) can be 0.
Your task is to find out if it is possible to distribute all n coins between sisters in a way described above.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 10^4) β the number of test cases.
The next t lines describe test cases. Each test case is given on a new line and consists of four space-separated integers a, b, c and n (1 β€ a, b, c, n β€ 10^8) β the number of coins Alice has, the number of coins Barbara has, the number of coins Cerene has and the number of coins Polycarp has.
Output
For each test case, print "YES" if Polycarp can distribute all n coins between his sisters and "NO" otherwise.
Example
Input
5
5 3 2 8
100 101 102 105
3 2 1 100000000
10 20 15 14
101 101 101 3
Output
YES
YES
NO
NO
YES
Tags: math
Correct Solution:
```
n=int(input())
for i in range(n):
l=list(map(int,input().split()))
s=sum(l)
k=l.pop()
l.sort()
a=l[2]
b=a-l[0]
c=a-l[1]
k=k-(b+c)
if(k>=0):
if((k%3)==0):
print("YES")
else:
print("NO")
else:
print("NO")
```
| 64,104 | [
0.33056640625,
0.429443359375,
0.015869140625,
-0.081298828125,
-0.380126953125,
-0.26416015625,
-0.271484375,
0.265625,
0.20068359375,
0.6669921875,
0.68896484375,
0.1539306640625,
0.267578125,
-0.76708984375,
-0.703125,
-0.07891845703125,
-0.7021484375,
-0.57275390625,
-0.57812... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has three sisters: Alice, Barbara, and Cerene. They're collecting coins. Currently, Alice has a coins, Barbara has b coins and Cerene has c coins. Recently Polycarp has returned from the trip around the world and brought n coins.
He wants to distribute all these n coins between his sisters in such a way that the number of coins Alice has is equal to the number of coins Barbara has and is equal to the number of coins Cerene has. In other words, if Polycarp gives A coins to Alice, B coins to Barbara and C coins to Cerene (A+B+C=n), then a + A = b + B = c + C.
Note that A, B or C (the number of coins Polycarp gives to Alice, Barbara and Cerene correspondingly) can be 0.
Your task is to find out if it is possible to distribute all n coins between sisters in a way described above.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 10^4) β the number of test cases.
The next t lines describe test cases. Each test case is given on a new line and consists of four space-separated integers a, b, c and n (1 β€ a, b, c, n β€ 10^8) β the number of coins Alice has, the number of coins Barbara has, the number of coins Cerene has and the number of coins Polycarp has.
Output
For each test case, print "YES" if Polycarp can distribute all n coins between his sisters and "NO" otherwise.
Example
Input
5
5 3 2 8
100 101 102 105
3 2 1 100000000
10 20 15 14
101 101 101 3
Output
YES
YES
NO
NO
YES
Tags: math
Correct Solution:
```
num_test = int(input())
for test in range(num_test):
test_input = input().split()
a = int(test_input[0])
b = int(test_input[1])
c = int(test_input[2])
n = int(test_input[3])
all_coin = a + b + c + n
if all_coin % 3 != 0:
print("NO")
else:
divided = int(all_coin / 3)
if divided < a or divided < b or divided < c:
print("NO")
else:
print("YES")
```
| 64,105 | [
0.380859375,
0.421142578125,
0.0224609375,
-0.0704345703125,
-0.388671875,
-0.255126953125,
-0.22509765625,
0.25244140625,
0.2279052734375,
0.69921875,
0.68896484375,
0.1531982421875,
0.25146484375,
-0.80126953125,
-0.728515625,
-0.11090087890625,
-0.65966796875,
-0.57421875,
-0.... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has three sisters: Alice, Barbara, and Cerene. They're collecting coins. Currently, Alice has a coins, Barbara has b coins and Cerene has c coins. Recently Polycarp has returned from the trip around the world and brought n coins.
He wants to distribute all these n coins between his sisters in such a way that the number of coins Alice has is equal to the number of coins Barbara has and is equal to the number of coins Cerene has. In other words, if Polycarp gives A coins to Alice, B coins to Barbara and C coins to Cerene (A+B+C=n), then a + A = b + B = c + C.
Note that A, B or C (the number of coins Polycarp gives to Alice, Barbara and Cerene correspondingly) can be 0.
Your task is to find out if it is possible to distribute all n coins between sisters in a way described above.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 10^4) β the number of test cases.
The next t lines describe test cases. Each test case is given on a new line and consists of four space-separated integers a, b, c and n (1 β€ a, b, c, n β€ 10^8) β the number of coins Alice has, the number of coins Barbara has, the number of coins Cerene has and the number of coins Polycarp has.
Output
For each test case, print "YES" if Polycarp can distribute all n coins between his sisters and "NO" otherwise.
Example
Input
5
5 3 2 8
100 101 102 105
3 2 1 100000000
10 20 15 14
101 101 101 3
Output
YES
YES
NO
NO
YES
Tags: math
Correct Solution:
```
t = int(input())
while(t):
a, b, c, n = map(int, input().strip().split())
final_coins = (a + b + c + n) / 3
if (a + b + c + n) % 3 == 0:
if a > final_coins or b > final_coins or c > final_coins:
print("NO")
else:
print("YES")
else:
print("NO")
t -= 1
```
| 64,106 | [
0.3583984375,
0.428955078125,
0.004184722900390625,
-0.11602783203125,
-0.362060546875,
-0.2489013671875,
-0.2457275390625,
0.2281494140625,
0.1944580078125,
0.6455078125,
0.6591796875,
0.1634521484375,
0.256591796875,
-0.78125,
-0.69384765625,
-0.10260009765625,
-0.68212890625,
-0... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has three sisters: Alice, Barbara, and Cerene. They're collecting coins. Currently, Alice has a coins, Barbara has b coins and Cerene has c coins. Recently Polycarp has returned from the trip around the world and brought n coins.
He wants to distribute all these n coins between his sisters in such a way that the number of coins Alice has is equal to the number of coins Barbara has and is equal to the number of coins Cerene has. In other words, if Polycarp gives A coins to Alice, B coins to Barbara and C coins to Cerene (A+B+C=n), then a + A = b + B = c + C.
Note that A, B or C (the number of coins Polycarp gives to Alice, Barbara and Cerene correspondingly) can be 0.
Your task is to find out if it is possible to distribute all n coins between sisters in a way described above.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 10^4) β the number of test cases.
The next t lines describe test cases. Each test case is given on a new line and consists of four space-separated integers a, b, c and n (1 β€ a, b, c, n β€ 10^8) β the number of coins Alice has, the number of coins Barbara has, the number of coins Cerene has and the number of coins Polycarp has.
Output
For each test case, print "YES" if Polycarp can distribute all n coins between his sisters and "NO" otherwise.
Example
Input
5
5 3 2 8
100 101 102 105
3 2 1 100000000
10 20 15 14
101 101 101 3
Output
YES
YES
NO
NO
YES
Tags: math
Correct Solution:
```
def main():
for _ in range(int(input())):
a = list(map(int,input().split()))
s = list(reversed(sorted(a[:3])))
n = a[3]
need = 0
need += s[0] - s[1]
need += s[0] - s[2]
if need > n:
print('NO')
else:
if (n - need) % 3 == 0:
print('YES')
else:
print('NO')
main()
```
| 64,107 | [
0.351318359375,
0.43017578125,
-0.00878143310546875,
-0.055206298828125,
-0.3857421875,
-0.2479248046875,
-0.26220703125,
0.2432861328125,
0.1846923828125,
0.69580078125,
0.708984375,
0.14208984375,
0.2578125,
-0.75390625,
-0.6845703125,
-0.08642578125,
-0.69091796875,
-0.569335937... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp has three sisters: Alice, Barbara, and Cerene. They're collecting coins. Currently, Alice has a coins, Barbara has b coins and Cerene has c coins. Recently Polycarp has returned from the trip around the world and brought n coins.
He wants to distribute all these n coins between his sisters in such a way that the number of coins Alice has is equal to the number of coins Barbara has and is equal to the number of coins Cerene has. In other words, if Polycarp gives A coins to Alice, B coins to Barbara and C coins to Cerene (A+B+C=n), then a + A = b + B = c + C.
Note that A, B or C (the number of coins Polycarp gives to Alice, Barbara and Cerene correspondingly) can be 0.
Your task is to find out if it is possible to distribute all n coins between sisters in a way described above.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 10^4) β the number of test cases.
The next t lines describe test cases. Each test case is given on a new line and consists of four space-separated integers a, b, c and n (1 β€ a, b, c, n β€ 10^8) β the number of coins Alice has, the number of coins Barbara has, the number of coins Cerene has and the number of coins Polycarp has.
Output
For each test case, print "YES" if Polycarp can distribute all n coins between his sisters and "NO" otherwise.
Example
Input
5
5 3 2 8
100 101 102 105
3 2 1 100000000
10 20 15 14
101 101 101 3
Output
YES
YES
NO
NO
YES
Submitted Solution:
```
I=input
n=int(I())
for _ in range(n):
a,b,c,m=map(int,I().split())
k=max(a,b,c)
if (a+b+c+m)%3==0 and (a+b+c+m)/3>=k:
print("YES")
else:
print("NO")
'''n,s,k=map(int,input().split())
a=list(map(int,input().split()))
i = 0
while max(s - i, 1) in a and min(s + i, n) in a:
i += 1
print(i)
'''
```
Yes
| 64,108 | [
0.384033203125,
0.40673828125,
-0.050262451171875,
-0.1090087890625,
-0.41162109375,
-0.1279296875,
-0.333740234375,
0.315185546875,
0.13037109375,
0.61865234375,
0.64453125,
0.11328125,
0.1900634765625,
-0.7744140625,
-0.6640625,
-0.1270751953125,
-0.6220703125,
-0.55615234375,
... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp has three sisters: Alice, Barbara, and Cerene. They're collecting coins. Currently, Alice has a coins, Barbara has b coins and Cerene has c coins. Recently Polycarp has returned from the trip around the world and brought n coins.
He wants to distribute all these n coins between his sisters in such a way that the number of coins Alice has is equal to the number of coins Barbara has and is equal to the number of coins Cerene has. In other words, if Polycarp gives A coins to Alice, B coins to Barbara and C coins to Cerene (A+B+C=n), then a + A = b + B = c + C.
Note that A, B or C (the number of coins Polycarp gives to Alice, Barbara and Cerene correspondingly) can be 0.
Your task is to find out if it is possible to distribute all n coins between sisters in a way described above.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 10^4) β the number of test cases.
The next t lines describe test cases. Each test case is given on a new line and consists of four space-separated integers a, b, c and n (1 β€ a, b, c, n β€ 10^8) β the number of coins Alice has, the number of coins Barbara has, the number of coins Cerene has and the number of coins Polycarp has.
Output
For each test case, print "YES" if Polycarp can distribute all n coins between his sisters and "NO" otherwise.
Example
Input
5
5 3 2 8
100 101 102 105
3 2 1 100000000
10 20 15 14
101 101 101 3
Output
YES
YES
NO
NO
YES
Submitted Solution:
```
t = int(input())
for each in range(t):
arr=[int(i) for i in input().split()]
n = arr[3]
tsum = sum(arr)
arr.pop(3)
if(tsum%3==0):
p = tsum/3
if(p<max(arr)):
print("NO")
else:
print("YES")
else:
print("NO")
```
Yes
| 64,109 | [
0.3857421875,
0.431884765625,
-0.0635986328125,
-0.14111328125,
-0.43701171875,
-0.1431884765625,
-0.348388671875,
0.286376953125,
0.1741943359375,
0.626953125,
0.59228515625,
0.1763916015625,
0.15087890625,
-0.734375,
-0.705078125,
-0.132080078125,
-0.58154296875,
-0.56298828125,
... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp has three sisters: Alice, Barbara, and Cerene. They're collecting coins. Currently, Alice has a coins, Barbara has b coins and Cerene has c coins. Recently Polycarp has returned from the trip around the world and brought n coins.
He wants to distribute all these n coins between his sisters in such a way that the number of coins Alice has is equal to the number of coins Barbara has and is equal to the number of coins Cerene has. In other words, if Polycarp gives A coins to Alice, B coins to Barbara and C coins to Cerene (A+B+C=n), then a + A = b + B = c + C.
Note that A, B or C (the number of coins Polycarp gives to Alice, Barbara and Cerene correspondingly) can be 0.
Your task is to find out if it is possible to distribute all n coins between sisters in a way described above.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 10^4) β the number of test cases.
The next t lines describe test cases. Each test case is given on a new line and consists of four space-separated integers a, b, c and n (1 β€ a, b, c, n β€ 10^8) β the number of coins Alice has, the number of coins Barbara has, the number of coins Cerene has and the number of coins Polycarp has.
Output
For each test case, print "YES" if Polycarp can distribute all n coins between his sisters and "NO" otherwise.
Example
Input
5
5 3 2 8
100 101 102 105
3 2 1 100000000
10 20 15 14
101 101 101 3
Output
YES
YES
NO
NO
YES
Submitted Solution:
```
t = int(input())
for number in range(t):
numbers = [int(x) for x in input().split()]
n = int(numbers[3])
l = numbers[:3]
l.sort()
n -= (2 * int(l[2])) - int(l[1]) - int(l[0])
if n % 3 == 0 and n >= 0:
print("YES")
else:
print("NO")
```
Yes
| 64,110 | [
0.402587890625,
0.3740234375,
-0.052734375,
-0.1484375,
-0.444091796875,
-0.1221923828125,
-0.360595703125,
0.322998046875,
0.125244140625,
0.64208984375,
0.60498046875,
0.1656494140625,
0.1573486328125,
-0.744140625,
-0.6640625,
-0.1385498046875,
-0.5966796875,
-0.583984375,
-0.... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp has three sisters: Alice, Barbara, and Cerene. They're collecting coins. Currently, Alice has a coins, Barbara has b coins and Cerene has c coins. Recently Polycarp has returned from the trip around the world and brought n coins.
He wants to distribute all these n coins between his sisters in such a way that the number of coins Alice has is equal to the number of coins Barbara has and is equal to the number of coins Cerene has. In other words, if Polycarp gives A coins to Alice, B coins to Barbara and C coins to Cerene (A+B+C=n), then a + A = b + B = c + C.
Note that A, B or C (the number of coins Polycarp gives to Alice, Barbara and Cerene correspondingly) can be 0.
Your task is to find out if it is possible to distribute all n coins between sisters in a way described above.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 10^4) β the number of test cases.
The next t lines describe test cases. Each test case is given on a new line and consists of four space-separated integers a, b, c and n (1 β€ a, b, c, n β€ 10^8) β the number of coins Alice has, the number of coins Barbara has, the number of coins Cerene has and the number of coins Polycarp has.
Output
For each test case, print "YES" if Polycarp can distribute all n coins between his sisters and "NO" otherwise.
Example
Input
5
5 3 2 8
100 101 102 105
3 2 1 100000000
10 20 15 14
101 101 101 3
Output
YES
YES
NO
NO
YES
Submitted Solution:
```
def arr_inp(n):
if n == 1:
return [int(x) for x in stdin.readline().split()]
elif n == 2:
return [float(x) for x in stdin.readline().split()]
else:
return [str(x) for x in stdin.readline().split()]
from sys import stdin
for i in range(int(input())):
a, b, c, n = arr_inp(1)
ar = sorted([a, b, c])
extra1, extra2 = ar[-1] - ar[0], ar[-1] - ar[1]
all = n - (extra2 + extra1)
print('NO' if (all % 3 or all < 0) else 'YES')
```
Yes
| 64,111 | [
0.406494140625,
0.3876953125,
-0.03643798828125,
-0.17919921875,
-0.419677734375,
-0.11212158203125,
-0.379638671875,
0.258544921875,
0.1510009765625,
0.65283203125,
0.64599609375,
0.1160888671875,
0.1685791015625,
-0.79150390625,
-0.6630859375,
-0.151611328125,
-0.56201171875,
-0.... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp has three sisters: Alice, Barbara, and Cerene. They're collecting coins. Currently, Alice has a coins, Barbara has b coins and Cerene has c coins. Recently Polycarp has returned from the trip around the world and brought n coins.
He wants to distribute all these n coins between his sisters in such a way that the number of coins Alice has is equal to the number of coins Barbara has and is equal to the number of coins Cerene has. In other words, if Polycarp gives A coins to Alice, B coins to Barbara and C coins to Cerene (A+B+C=n), then a + A = b + B = c + C.
Note that A, B or C (the number of coins Polycarp gives to Alice, Barbara and Cerene correspondingly) can be 0.
Your task is to find out if it is possible to distribute all n coins between sisters in a way described above.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 10^4) β the number of test cases.
The next t lines describe test cases. Each test case is given on a new line and consists of four space-separated integers a, b, c and n (1 β€ a, b, c, n β€ 10^8) β the number of coins Alice has, the number of coins Barbara has, the number of coins Cerene has and the number of coins Polycarp has.
Output
For each test case, print "YES" if Polycarp can distribute all n coins between his sisters and "NO" otherwise.
Example
Input
5
5 3 2 8
100 101 102 105
3 2 1 100000000
10 20 15 14
101 101 101 3
Output
YES
YES
NO
NO
YES
Submitted Solution:
```
t = int(input())
for i in range(t):
a,b,c,n = map(int, input().split())
coin = [a,b,c]
coin.sort()
rem = abs(coin[0]-coin[2]) + abs(coin[1]-coin[2])
if (n-rem)>=0 & (n-rem)%3==0:
print("YES\n")
else:
print("NO\n")
```
No
| 64,112 | [
0.43701171875,
0.41943359375,
-0.031585693359375,
-0.1451416015625,
-0.453857421875,
-0.1368408203125,
-0.337890625,
0.28759765625,
0.1373291015625,
0.68896484375,
0.63134765625,
0.167724609375,
0.170654296875,
-0.765625,
-0.6474609375,
-0.1412353515625,
-0.58642578125,
-0.56396484... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp has three sisters: Alice, Barbara, and Cerene. They're collecting coins. Currently, Alice has a coins, Barbara has b coins and Cerene has c coins. Recently Polycarp has returned from the trip around the world and brought n coins.
He wants to distribute all these n coins between his sisters in such a way that the number of coins Alice has is equal to the number of coins Barbara has and is equal to the number of coins Cerene has. In other words, if Polycarp gives A coins to Alice, B coins to Barbara and C coins to Cerene (A+B+C=n), then a + A = b + B = c + C.
Note that A, B or C (the number of coins Polycarp gives to Alice, Barbara and Cerene correspondingly) can be 0.
Your task is to find out if it is possible to distribute all n coins between sisters in a way described above.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 10^4) β the number of test cases.
The next t lines describe test cases. Each test case is given on a new line and consists of four space-separated integers a, b, c and n (1 β€ a, b, c, n β€ 10^8) β the number of coins Alice has, the number of coins Barbara has, the number of coins Cerene has and the number of coins Polycarp has.
Output
For each test case, print "YES" if Polycarp can distribute all n coins between his sisters and "NO" otherwise.
Example
Input
5
5 3 2 8
100 101 102 105
3 2 1 100000000
10 20 15 14
101 101 101 3
Output
YES
YES
NO
NO
YES
Submitted Solution:
```
z = int(input())
for i in range(0, z):
a = list(map(int, input().split()))
b = max(a) * 3 - sum(a) + a[-1]
if(a[0] == a[1] == a[2]):
print("YES")
elif((a[-1] - b) %3 == 0):
print("YES")
else:
print("NO")
```
No
| 64,113 | [
0.4091796875,
0.38818359375,
-0.03851318359375,
-0.148193359375,
-0.4462890625,
-0.11114501953125,
-0.361572265625,
0.3125,
0.1280517578125,
0.6298828125,
0.6201171875,
0.155517578125,
0.1829833984375,
-0.73974609375,
-0.67333984375,
-0.1435546875,
-0.587890625,
-0.544921875,
-0.... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp has three sisters: Alice, Barbara, and Cerene. They're collecting coins. Currently, Alice has a coins, Barbara has b coins and Cerene has c coins. Recently Polycarp has returned from the trip around the world and brought n coins.
He wants to distribute all these n coins between his sisters in such a way that the number of coins Alice has is equal to the number of coins Barbara has and is equal to the number of coins Cerene has. In other words, if Polycarp gives A coins to Alice, B coins to Barbara and C coins to Cerene (A+B+C=n), then a + A = b + B = c + C.
Note that A, B or C (the number of coins Polycarp gives to Alice, Barbara and Cerene correspondingly) can be 0.
Your task is to find out if it is possible to distribute all n coins between sisters in a way described above.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 10^4) β the number of test cases.
The next t lines describe test cases. Each test case is given on a new line and consists of four space-separated integers a, b, c and n (1 β€ a, b, c, n β€ 10^8) β the number of coins Alice has, the number of coins Barbara has, the number of coins Cerene has and the number of coins Polycarp has.
Output
For each test case, print "YES" if Polycarp can distribute all n coins between his sisters and "NO" otherwise.
Example
Input
5
5 3 2 8
100 101 102 105
3 2 1 100000000
10 20 15 14
101 101 101 3
Output
YES
YES
NO
NO
YES
Submitted Solution:
```
t = int(input())
for i in range(t):
a,b,c,n = map(int,input().split(' '))
if(((a + b + c + n) % 3) == 0):
x = (a+b+c+n)/3
if((x-a)+(x-b)+(x-c) == n):
print("YES")
else:
print("NO")
```
No
| 64,114 | [
0.398681640625,
0.384765625,
-0.051544189453125,
-0.1575927734375,
-0.42822265625,
-0.12841796875,
-0.346923828125,
0.2939453125,
0.1163330078125,
0.646484375,
0.61474609375,
0.16357421875,
0.1766357421875,
-0.76806640625,
-0.65869140625,
-0.153564453125,
-0.59814453125,
-0.5673828... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp has three sisters: Alice, Barbara, and Cerene. They're collecting coins. Currently, Alice has a coins, Barbara has b coins and Cerene has c coins. Recently Polycarp has returned from the trip around the world and brought n coins.
He wants to distribute all these n coins between his sisters in such a way that the number of coins Alice has is equal to the number of coins Barbara has and is equal to the number of coins Cerene has. In other words, if Polycarp gives A coins to Alice, B coins to Barbara and C coins to Cerene (A+B+C=n), then a + A = b + B = c + C.
Note that A, B or C (the number of coins Polycarp gives to Alice, Barbara and Cerene correspondingly) can be 0.
Your task is to find out if it is possible to distribute all n coins between sisters in a way described above.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 10^4) β the number of test cases.
The next t lines describe test cases. Each test case is given on a new line and consists of four space-separated integers a, b, c and n (1 β€ a, b, c, n β€ 10^8) β the number of coins Alice has, the number of coins Barbara has, the number of coins Cerene has and the number of coins Polycarp has.
Output
For each test case, print "YES" if Polycarp can distribute all n coins between his sisters and "NO" otherwise.
Example
Input
5
5 3 2 8
100 101 102 105
3 2 1 100000000
10 20 15 14
101 101 101 3
Output
YES
YES
NO
NO
YES
Submitted Solution:
```
def mysplit(a,b):
output_list = []
z = ""
for i in a:
if not i == b:
z += i
else:
output_list.append(int(z))
z = ""
output_list.append(int(z))
return output_list
def myjoin(a, b):
output_str = ""
for loc, i in enumerate(a):
if not loc == len(a) - 1:
output_str += i + b
output_str += a[-1]
return output_str
def maximum(a):
in_var = a[0]
for i in a:
if i > in_var:
in_var = i
return in_var
def polycarp():
lis = []
d = input()
for i in range(int(d)):
a,b,c,p = mysplit(input(), " ")
max_coins = maximum([a, b, c])
coins_needed = 3 * max_coins - a - b - c
what_isleft = p - coins_needed
if not what_isleft % 3:
lis.append("YES")
else:
lis.append("NO")
return myjoin(lis, "\n")
print(polycarp())
```
No
| 64,115 | [
0.451416015625,
0.36083984375,
-0.03955078125,
-0.138427734375,
-0.494873046875,
-0.1619873046875,
-0.377197265625,
0.308349609375,
0.145751953125,
0.62548828125,
0.6416015625,
0.1524658203125,
0.207763671875,
-0.7412109375,
-0.63720703125,
-0.1015625,
-0.58349609375,
-0.5625,
-0... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Screen resolution of Polycarp's monitor is a Γ b pixels. Unfortunately, there is one dead pixel at his screen. It has coordinates (x, y) (0 β€ x < a, 0 β€ y < b). You can consider columns of pixels to be numbered from 0 to a-1, and rows β from 0 to b-1.
Polycarp wants to open a rectangular window of maximal size, which doesn't contain the dead pixel. The boundaries of the window should be parallel to the sides of the screen.
Print the maximal area (in pixels) of a window that doesn't contain the dead pixel inside itself.
Input
In the first line you are given an integer t (1 β€ t β€ 10^4) β the number of test cases in the test. In the next lines you are given descriptions of t test cases.
Each test case contains a single line which consists of 4 integers a, b, x and y (1 β€ a, b β€ 10^4; 0 β€ x < a; 0 β€ y < b) β the resolution of the screen and the coordinates of a dead pixel. It is guaranteed that a+b>2 (e.g. a=b=1 is impossible).
Output
Print t integers β the answers for each test case. Each answer should contain an integer equal to the maximal possible area (in pixels) of a rectangular window, that doesn't contain the dead pixel.
Example
Input
6
8 8 0 0
1 10 0 3
17 31 10 4
2 1 0 0
5 10 3 9
10 10 4 8
Output
56
6
442
1
45
80
Note
In the first test case, the screen resolution is 8 Γ 8, and the upper left pixel is a dead pixel. Here you can see one of two possible layouts of the maximal window.
<image>
Tags: implementation
Correct Solution:
```
t = int(input())
while t>0:
t = t-1
# a,b,c = list(map(int,input().split()))
# n = int(input())
a,b,x,y = map(int,input().split())
one = (y)*(a)
two = (x)*(b)
three = ((a-1)-(x+1) +1)*(b)
four = ((b-1)-(y+1) +1)*(a)
# print(one)
# print(two)
# print(three)
# print(four)
print(max(one,two,three,four))
```
| 64,116 | [
0.54638671875,
-0.019622802734375,
-0.05670166015625,
0.252685546875,
-0.57177734375,
-0.48095703125,
-0.11065673828125,
0.18994140625,
0.140625,
0.92578125,
0.32470703125,
-0.04840087890625,
0.26025390625,
-0.456298828125,
-0.271728515625,
0.126220703125,
-0.428466796875,
-0.54492... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Screen resolution of Polycarp's monitor is a Γ b pixels. Unfortunately, there is one dead pixel at his screen. It has coordinates (x, y) (0 β€ x < a, 0 β€ y < b). You can consider columns of pixels to be numbered from 0 to a-1, and rows β from 0 to b-1.
Polycarp wants to open a rectangular window of maximal size, which doesn't contain the dead pixel. The boundaries of the window should be parallel to the sides of the screen.
Print the maximal area (in pixels) of a window that doesn't contain the dead pixel inside itself.
Input
In the first line you are given an integer t (1 β€ t β€ 10^4) β the number of test cases in the test. In the next lines you are given descriptions of t test cases.
Each test case contains a single line which consists of 4 integers a, b, x and y (1 β€ a, b β€ 10^4; 0 β€ x < a; 0 β€ y < b) β the resolution of the screen and the coordinates of a dead pixel. It is guaranteed that a+b>2 (e.g. a=b=1 is impossible).
Output
Print t integers β the answers for each test case. Each answer should contain an integer equal to the maximal possible area (in pixels) of a rectangular window, that doesn't contain the dead pixel.
Example
Input
6
8 8 0 0
1 10 0 3
17 31 10 4
2 1 0 0
5 10 3 9
10 10 4 8
Output
56
6
442
1
45
80
Note
In the first test case, the screen resolution is 8 Γ 8, and the upper left pixel is a dead pixel. Here you can see one of two possible layouts of the maximal window.
<image>
Tags: implementation
Correct Solution:
```
t = int(input())
for _ in range(t):
n,m,a,b = map(int,input().split())
print(max(max(a,n-a-1)*m,max(b,m-b-1)*n))
```
| 64,117 | [
0.53466796875,
-0.05377197265625,
-0.07818603515625,
0.29296875,
-0.5458984375,
-0.493896484375,
-0.11029052734375,
0.1629638671875,
0.178466796875,
0.90673828125,
0.345458984375,
-0.05035400390625,
0.247314453125,
-0.4150390625,
-0.2587890625,
0.1461181640625,
-0.4580078125,
-0.56... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Screen resolution of Polycarp's monitor is a Γ b pixels. Unfortunately, there is one dead pixel at his screen. It has coordinates (x, y) (0 β€ x < a, 0 β€ y < b). You can consider columns of pixels to be numbered from 0 to a-1, and rows β from 0 to b-1.
Polycarp wants to open a rectangular window of maximal size, which doesn't contain the dead pixel. The boundaries of the window should be parallel to the sides of the screen.
Print the maximal area (in pixels) of a window that doesn't contain the dead pixel inside itself.
Input
In the first line you are given an integer t (1 β€ t β€ 10^4) β the number of test cases in the test. In the next lines you are given descriptions of t test cases.
Each test case contains a single line which consists of 4 integers a, b, x and y (1 β€ a, b β€ 10^4; 0 β€ x < a; 0 β€ y < b) β the resolution of the screen and the coordinates of a dead pixel. It is guaranteed that a+b>2 (e.g. a=b=1 is impossible).
Output
Print t integers β the answers for each test case. Each answer should contain an integer equal to the maximal possible area (in pixels) of a rectangular window, that doesn't contain the dead pixel.
Example
Input
6
8 8 0 0
1 10 0 3
17 31 10 4
2 1 0 0
5 10 3 9
10 10 4 8
Output
56
6
442
1
45
80
Note
In the first test case, the screen resolution is 8 Γ 8, and the upper left pixel is a dead pixel. Here you can see one of two possible layouts of the maximal window.
<image>
Tags: implementation
Correct Solution:
```
t = int(input())
for i in range(t):
# a = int(input())
# b = int(input())
# x = int(input())
# y = int(input())
a, b, x, y = map(int, input().split())
x += 1
y += 1
row = max(a - x, x - 1)
col = max(b - y, y - 1)
result = max(row*b, a*col)
print(result)
```
| 64,118 | [
0.54296875,
-0.033935546875,
-0.046142578125,
0.271484375,
-0.56103515625,
-0.48095703125,
-0.1051025390625,
0.1788330078125,
0.14697265625,
0.91259765625,
0.3330078125,
-0.05462646484375,
0.232421875,
-0.44580078125,
-0.271728515625,
0.1494140625,
-0.4296875,
-0.54541015625,
-0.... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Screen resolution of Polycarp's monitor is a Γ b pixels. Unfortunately, there is one dead pixel at his screen. It has coordinates (x, y) (0 β€ x < a, 0 β€ y < b). You can consider columns of pixels to be numbered from 0 to a-1, and rows β from 0 to b-1.
Polycarp wants to open a rectangular window of maximal size, which doesn't contain the dead pixel. The boundaries of the window should be parallel to the sides of the screen.
Print the maximal area (in pixels) of a window that doesn't contain the dead pixel inside itself.
Input
In the first line you are given an integer t (1 β€ t β€ 10^4) β the number of test cases in the test. In the next lines you are given descriptions of t test cases.
Each test case contains a single line which consists of 4 integers a, b, x and y (1 β€ a, b β€ 10^4; 0 β€ x < a; 0 β€ y < b) β the resolution of the screen and the coordinates of a dead pixel. It is guaranteed that a+b>2 (e.g. a=b=1 is impossible).
Output
Print t integers β the answers for each test case. Each answer should contain an integer equal to the maximal possible area (in pixels) of a rectangular window, that doesn't contain the dead pixel.
Example
Input
6
8 8 0 0
1 10 0 3
17 31 10 4
2 1 0 0
5 10 3 9
10 10 4 8
Output
56
6
442
1
45
80
Note
In the first test case, the screen resolution is 8 Γ 8, and the upper left pixel is a dead pixel. Here you can see one of two possible layouts of the maximal window.
<image>
Tags: implementation
Correct Solution:
```
import sys
import math
from collections import defaultdict
from collections import deque
from itertools import combinations
from itertools import permutations
input = lambda : sys.stdin.readline().rstrip()
read = lambda : list(map(int, input().split()))
go = lambda : 1/0
def write(*args, sep="\n"):
for i in args:
sys.stdout.write("{}{}".format(i, sep))
INF = float('inf')
MOD = int(1e9 + 7)
YES = "YES"
NO = "NO"
for _ in range(int(input())):
try:
a, b, x, y = read()
up = y * a
down = (b - y - 1) * a
left = x * b
right = (a - x - 1) * b
print(max([up, down, left, right]))
except ZeroDivisionError:
continue
except Exception as e:
print(e)
continue
```
| 64,119 | [
0.489501953125,
-0.0755615234375,
-0.1163330078125,
0.284423828125,
-0.57763671875,
-0.447509765625,
-0.210205078125,
0.1337890625,
0.14306640625,
0.91748046875,
0.359619140625,
-0.1064453125,
0.2110595703125,
-0.34521484375,
-0.2666015625,
0.172607421875,
-0.445068359375,
-0.55273... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Screen resolution of Polycarp's monitor is a Γ b pixels. Unfortunately, there is one dead pixel at his screen. It has coordinates (x, y) (0 β€ x < a, 0 β€ y < b). You can consider columns of pixels to be numbered from 0 to a-1, and rows β from 0 to b-1.
Polycarp wants to open a rectangular window of maximal size, which doesn't contain the dead pixel. The boundaries of the window should be parallel to the sides of the screen.
Print the maximal area (in pixels) of a window that doesn't contain the dead pixel inside itself.
Input
In the first line you are given an integer t (1 β€ t β€ 10^4) β the number of test cases in the test. In the next lines you are given descriptions of t test cases.
Each test case contains a single line which consists of 4 integers a, b, x and y (1 β€ a, b β€ 10^4; 0 β€ x < a; 0 β€ y < b) β the resolution of the screen and the coordinates of a dead pixel. It is guaranteed that a+b>2 (e.g. a=b=1 is impossible).
Output
Print t integers β the answers for each test case. Each answer should contain an integer equal to the maximal possible area (in pixels) of a rectangular window, that doesn't contain the dead pixel.
Example
Input
6
8 8 0 0
1 10 0 3
17 31 10 4
2 1 0 0
5 10 3 9
10 10 4 8
Output
56
6
442
1
45
80
Note
In the first test case, the screen resolution is 8 Γ 8, and the upper left pixel is a dead pixel. Here you can see one of two possible layouts of the maximal window.
<image>
Tags: implementation
Correct Solution:
```
import math
t=int(input())
for g in range(0,t):
abxy=list(map(int,input().split()))
a=abxy[0]
b=abxy[1]
x=abxy[2]
y=abxy[3]
arr=[]
arr.append(a*y)
arr.append(a*(b-y-1))
arr.append(b*x)
arr.append(b*(a-x-1))
print(max(arr))
```
| 64,120 | [
0.5908203125,
-0.033721923828125,
-0.01116943359375,
0.277099609375,
-0.5615234375,
-0.5068359375,
-0.07330322265625,
0.13916015625,
0.2086181640625,
0.90771484375,
0.365234375,
-0.12225341796875,
0.212646484375,
-0.433349609375,
-0.24462890625,
0.130126953125,
-0.448486328125,
-0.... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Screen resolution of Polycarp's monitor is a Γ b pixels. Unfortunately, there is one dead pixel at his screen. It has coordinates (x, y) (0 β€ x < a, 0 β€ y < b). You can consider columns of pixels to be numbered from 0 to a-1, and rows β from 0 to b-1.
Polycarp wants to open a rectangular window of maximal size, which doesn't contain the dead pixel. The boundaries of the window should be parallel to the sides of the screen.
Print the maximal area (in pixels) of a window that doesn't contain the dead pixel inside itself.
Input
In the first line you are given an integer t (1 β€ t β€ 10^4) β the number of test cases in the test. In the next lines you are given descriptions of t test cases.
Each test case contains a single line which consists of 4 integers a, b, x and y (1 β€ a, b β€ 10^4; 0 β€ x < a; 0 β€ y < b) β the resolution of the screen and the coordinates of a dead pixel. It is guaranteed that a+b>2 (e.g. a=b=1 is impossible).
Output
Print t integers β the answers for each test case. Each answer should contain an integer equal to the maximal possible area (in pixels) of a rectangular window, that doesn't contain the dead pixel.
Example
Input
6
8 8 0 0
1 10 0 3
17 31 10 4
2 1 0 0
5 10 3 9
10 10 4 8
Output
56
6
442
1
45
80
Note
In the first test case, the screen resolution is 8 Γ 8, and the upper left pixel is a dead pixel. Here you can see one of two possible layouts of the maximal window.
<image>
Tags: implementation
Correct Solution:
```
for _ in range(int(input())):
a,b,x,y=map(int,input().split())
print(max(b*max(x,a-x-1),a*max(y,b-y-1)))
```
| 64,121 | [
0.541015625,
-0.038787841796875,
-0.06524658203125,
0.332763671875,
-0.55615234375,
-0.499267578125,
-0.10986328125,
0.1793212890625,
0.1727294921875,
0.92431640625,
0.3447265625,
-0.0210418701171875,
0.25390625,
-0.418701171875,
-0.2452392578125,
0.15283203125,
-0.45068359375,
-0.... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Screen resolution of Polycarp's monitor is a Γ b pixels. Unfortunately, there is one dead pixel at his screen. It has coordinates (x, y) (0 β€ x < a, 0 β€ y < b). You can consider columns of pixels to be numbered from 0 to a-1, and rows β from 0 to b-1.
Polycarp wants to open a rectangular window of maximal size, which doesn't contain the dead pixel. The boundaries of the window should be parallel to the sides of the screen.
Print the maximal area (in pixels) of a window that doesn't contain the dead pixel inside itself.
Input
In the first line you are given an integer t (1 β€ t β€ 10^4) β the number of test cases in the test. In the next lines you are given descriptions of t test cases.
Each test case contains a single line which consists of 4 integers a, b, x and y (1 β€ a, b β€ 10^4; 0 β€ x < a; 0 β€ y < b) β the resolution of the screen and the coordinates of a dead pixel. It is guaranteed that a+b>2 (e.g. a=b=1 is impossible).
Output
Print t integers β the answers for each test case. Each answer should contain an integer equal to the maximal possible area (in pixels) of a rectangular window, that doesn't contain the dead pixel.
Example
Input
6
8 8 0 0
1 10 0 3
17 31 10 4
2 1 0 0
5 10 3 9
10 10 4 8
Output
56
6
442
1
45
80
Note
In the first test case, the screen resolution is 8 Γ 8, and the upper left pixel is a dead pixel. Here you can see one of two possible layouts of the maximal window.
<image>
Tags: implementation
Correct Solution:
```
t=int(input())
for _ in range(t):
a,b,x,y=[int(s) for s in input().split()]
r1=b*x
r2=a*y
r3=(a-x-1)*b
r4=(b-y-1)*a
print(max(r1,r2,r3,r4))
```
| 64,122 | [
0.52197265625,
-0.043609619140625,
-0.059173583984375,
0.328369140625,
-0.5595703125,
-0.478759765625,
-0.10552978515625,
0.1680908203125,
0.177001953125,
0.892578125,
0.329833984375,
-0.050018310546875,
0.2398681640625,
-0.462646484375,
-0.266845703125,
0.160400390625,
-0.4318847656... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Screen resolution of Polycarp's monitor is a Γ b pixels. Unfortunately, there is one dead pixel at his screen. It has coordinates (x, y) (0 β€ x < a, 0 β€ y < b). You can consider columns of pixels to be numbered from 0 to a-1, and rows β from 0 to b-1.
Polycarp wants to open a rectangular window of maximal size, which doesn't contain the dead pixel. The boundaries of the window should be parallel to the sides of the screen.
Print the maximal area (in pixels) of a window that doesn't contain the dead pixel inside itself.
Input
In the first line you are given an integer t (1 β€ t β€ 10^4) β the number of test cases in the test. In the next lines you are given descriptions of t test cases.
Each test case contains a single line which consists of 4 integers a, b, x and y (1 β€ a, b β€ 10^4; 0 β€ x < a; 0 β€ y < b) β the resolution of the screen and the coordinates of a dead pixel. It is guaranteed that a+b>2 (e.g. a=b=1 is impossible).
Output
Print t integers β the answers for each test case. Each answer should contain an integer equal to the maximal possible area (in pixels) of a rectangular window, that doesn't contain the dead pixel.
Example
Input
6
8 8 0 0
1 10 0 3
17 31 10 4
2 1 0 0
5 10 3 9
10 10 4 8
Output
56
6
442
1
45
80
Note
In the first test case, the screen resolution is 8 Γ 8, and the upper left pixel is a dead pixel. Here you can see one of two possible layouts of the maximal window.
<image>
Tags: implementation
Correct Solution:
```
from collections import defaultdict, Counter
def getlist():
return list(map(int, input().split()))
def maplist():
return map(int, input().split())
def main():
t = int(input())
for num in range(t):
a,b,x,y = map(int, input().split())
if x>=abs(a-x):
size1 = abs(a -abs(a-x))*b
else:
size1 = abs(a-(x+1))*b
if y>=abs(b-y):
size2 = abs(b-abs(b-y))*a
else:
size2 = abs(b - (y + 1)) * a
# print(size1,size2)
print(max(size1,size2))
main()
```
| 64,123 | [
0.5263671875,
-0.037017822265625,
-0.067626953125,
0.2320556640625,
-0.5625,
-0.425537109375,
-0.1138916015625,
0.1580810546875,
0.1751708984375,
0.93115234375,
0.3662109375,
-0.09527587890625,
0.238525390625,
-0.397216796875,
-0.25,
0.12420654296875,
-0.466064453125,
-0.53515625,
... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Screen resolution of Polycarp's monitor is a Γ b pixels. Unfortunately, there is one dead pixel at his screen. It has coordinates (x, y) (0 β€ x < a, 0 β€ y < b). You can consider columns of pixels to be numbered from 0 to a-1, and rows β from 0 to b-1.
Polycarp wants to open a rectangular window of maximal size, which doesn't contain the dead pixel. The boundaries of the window should be parallel to the sides of the screen.
Print the maximal area (in pixels) of a window that doesn't contain the dead pixel inside itself.
Input
In the first line you are given an integer t (1 β€ t β€ 10^4) β the number of test cases in the test. In the next lines you are given descriptions of t test cases.
Each test case contains a single line which consists of 4 integers a, b, x and y (1 β€ a, b β€ 10^4; 0 β€ x < a; 0 β€ y < b) β the resolution of the screen and the coordinates of a dead pixel. It is guaranteed that a+b>2 (e.g. a=b=1 is impossible).
Output
Print t integers β the answers for each test case. Each answer should contain an integer equal to the maximal possible area (in pixels) of a rectangular window, that doesn't contain the dead pixel.
Example
Input
6
8 8 0 0
1 10 0 3
17 31 10 4
2 1 0 0
5 10 3 9
10 10 4 8
Output
56
6
442
1
45
80
Note
In the first test case, the screen resolution is 8 Γ 8, and the upper left pixel is a dead pixel. Here you can see one of two possible layouts of the maximal window.
<image>
Submitted Solution:
```
t=int(input())
A=[]
for i in range (t):
a, b, x, y=map(int, input().split())
A.append(max(x*b, y*a,(b-y-1)*a,(a-x-1)*b))
for i in A:
print(i)
```
Yes
| 64,124 | [
0.50439453125,
-0.035675048828125,
-0.1123046875,
0.336181640625,
-0.5849609375,
-0.310546875,
-0.20703125,
0.201171875,
0.1336669921875,
0.8271484375,
0.30810546875,
-0.01467132568359375,
0.249267578125,
-0.41748046875,
-0.2166748046875,
0.112060546875,
-0.40673828125,
-0.59619140... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Screen resolution of Polycarp's monitor is a Γ b pixels. Unfortunately, there is one dead pixel at his screen. It has coordinates (x, y) (0 β€ x < a, 0 β€ y < b). You can consider columns of pixels to be numbered from 0 to a-1, and rows β from 0 to b-1.
Polycarp wants to open a rectangular window of maximal size, which doesn't contain the dead pixel. The boundaries of the window should be parallel to the sides of the screen.
Print the maximal area (in pixels) of a window that doesn't contain the dead pixel inside itself.
Input
In the first line you are given an integer t (1 β€ t β€ 10^4) β the number of test cases in the test. In the next lines you are given descriptions of t test cases.
Each test case contains a single line which consists of 4 integers a, b, x and y (1 β€ a, b β€ 10^4; 0 β€ x < a; 0 β€ y < b) β the resolution of the screen and the coordinates of a dead pixel. It is guaranteed that a+b>2 (e.g. a=b=1 is impossible).
Output
Print t integers β the answers for each test case. Each answer should contain an integer equal to the maximal possible area (in pixels) of a rectangular window, that doesn't contain the dead pixel.
Example
Input
6
8 8 0 0
1 10 0 3
17 31 10 4
2 1 0 0
5 10 3 9
10 10 4 8
Output
56
6
442
1
45
80
Note
In the first test case, the screen resolution is 8 Γ 8, and the upper left pixel is a dead pixel. Here you can see one of two possible layouts of the maximal window.
<image>
Submitted Solution:
```
t = int(input())
new_l = list()
for i in range(t):
string = list(input().split(' '))
s1 = (int(string[0])-int(string[2])-1)*int(string[1])
s2 = (int(string[0]) - (int(string[0]) -
int(string[2])-1) - 1)*int(string[1])
s3 = int(string[0])*(int(string[1]) - int(string[3]) - 1)
s4 = int(string[0])*(int(string[1]) -
(int(string[1]) - int(string[3]) - 1) - 1)
new_l.append(max(s1,s2,s3,s4))
for i in new_l:
print(i)
```
Yes
| 64,125 | [
0.48388671875,
-0.054351806640625,
-0.0968017578125,
0.30126953125,
-0.5947265625,
-0.37451171875,
-0.19140625,
0.2017822265625,
0.11553955078125,
0.79736328125,
0.315185546875,
-0.033843994140625,
0.25390625,
-0.41748046875,
-0.2222900390625,
0.09197998046875,
-0.455810546875,
-0.... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Screen resolution of Polycarp's monitor is a Γ b pixels. Unfortunately, there is one dead pixel at his screen. It has coordinates (x, y) (0 β€ x < a, 0 β€ y < b). You can consider columns of pixels to be numbered from 0 to a-1, and rows β from 0 to b-1.
Polycarp wants to open a rectangular window of maximal size, which doesn't contain the dead pixel. The boundaries of the window should be parallel to the sides of the screen.
Print the maximal area (in pixels) of a window that doesn't contain the dead pixel inside itself.
Input
In the first line you are given an integer t (1 β€ t β€ 10^4) β the number of test cases in the test. In the next lines you are given descriptions of t test cases.
Each test case contains a single line which consists of 4 integers a, b, x and y (1 β€ a, b β€ 10^4; 0 β€ x < a; 0 β€ y < b) β the resolution of the screen and the coordinates of a dead pixel. It is guaranteed that a+b>2 (e.g. a=b=1 is impossible).
Output
Print t integers β the answers for each test case. Each answer should contain an integer equal to the maximal possible area (in pixels) of a rectangular window, that doesn't contain the dead pixel.
Example
Input
6
8 8 0 0
1 10 0 3
17 31 10 4
2 1 0 0
5 10 3 9
10 10 4 8
Output
56
6
442
1
45
80
Note
In the first test case, the screen resolution is 8 Γ 8, and the upper left pixel is a dead pixel. Here you can see one of two possible layouts of the maximal window.
<image>
Submitted Solution:
```
'''
the left, right top and bottom and take the max of those
'''
def solve(a, b, x, y):
return max(x*b,(a-x-1)*b, a*y, a*(b-y-1))
n = int(input())
for _ in range(n):
a, b, x, y = list(map(int, input().split()))
print(solve(a, b, x, y))
```
Yes
| 64,126 | [
0.492431640625,
-0.040924072265625,
-0.09747314453125,
0.34130859375,
-0.6064453125,
-0.31591796875,
-0.2081298828125,
0.2301025390625,
0.163330078125,
0.8466796875,
0.3251953125,
-0.005458831787109375,
0.276123046875,
-0.4140625,
-0.2083740234375,
0.135009765625,
-0.42431640625,
-... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Screen resolution of Polycarp's monitor is a Γ b pixels. Unfortunately, there is one dead pixel at his screen. It has coordinates (x, y) (0 β€ x < a, 0 β€ y < b). You can consider columns of pixels to be numbered from 0 to a-1, and rows β from 0 to b-1.
Polycarp wants to open a rectangular window of maximal size, which doesn't contain the dead pixel. The boundaries of the window should be parallel to the sides of the screen.
Print the maximal area (in pixels) of a window that doesn't contain the dead pixel inside itself.
Input
In the first line you are given an integer t (1 β€ t β€ 10^4) β the number of test cases in the test. In the next lines you are given descriptions of t test cases.
Each test case contains a single line which consists of 4 integers a, b, x and y (1 β€ a, b β€ 10^4; 0 β€ x < a; 0 β€ y < b) β the resolution of the screen and the coordinates of a dead pixel. It is guaranteed that a+b>2 (e.g. a=b=1 is impossible).
Output
Print t integers β the answers for each test case. Each answer should contain an integer equal to the maximal possible area (in pixels) of a rectangular window, that doesn't contain the dead pixel.
Example
Input
6
8 8 0 0
1 10 0 3
17 31 10 4
2 1 0 0
5 10 3 9
10 10 4 8
Output
56
6
442
1
45
80
Note
In the first test case, the screen resolution is 8 Γ 8, and the upper left pixel is a dead pixel. Here you can see one of two possible layouts of the maximal window.
<image>
Submitted Solution:
```
t = int(input())
for i in range(t):
a, b, x, y = map(int, input().split())
print(max(a * y, a * (b - y - 1), b * x, b * (a - x -1)))
```
Yes
| 64,127 | [
0.5,
-0.027313232421875,
-0.1357421875,
0.361328125,
-0.5888671875,
-0.3291015625,
-0.2158203125,
0.2166748046875,
0.14794921875,
0.83544921875,
0.31396484375,
0.018341064453125,
0.25732421875,
-0.441162109375,
-0.20849609375,
0.1297607421875,
-0.402587890625,
-0.63134765625,
-0.... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Screen resolution of Polycarp's monitor is a Γ b pixels. Unfortunately, there is one dead pixel at his screen. It has coordinates (x, y) (0 β€ x < a, 0 β€ y < b). You can consider columns of pixels to be numbered from 0 to a-1, and rows β from 0 to b-1.
Polycarp wants to open a rectangular window of maximal size, which doesn't contain the dead pixel. The boundaries of the window should be parallel to the sides of the screen.
Print the maximal area (in pixels) of a window that doesn't contain the dead pixel inside itself.
Input
In the first line you are given an integer t (1 β€ t β€ 10^4) β the number of test cases in the test. In the next lines you are given descriptions of t test cases.
Each test case contains a single line which consists of 4 integers a, b, x and y (1 β€ a, b β€ 10^4; 0 β€ x < a; 0 β€ y < b) β the resolution of the screen and the coordinates of a dead pixel. It is guaranteed that a+b>2 (e.g. a=b=1 is impossible).
Output
Print t integers β the answers for each test case. Each answer should contain an integer equal to the maximal possible area (in pixels) of a rectangular window, that doesn't contain the dead pixel.
Example
Input
6
8 8 0 0
1 10 0 3
17 31 10 4
2 1 0 0
5 10 3 9
10 10 4 8
Output
56
6
442
1
45
80
Note
In the first test case, the screen resolution is 8 Γ 8, and the upper left pixel is a dead pixel. Here you can see one of two possible layouts of the maximal window.
<image>
Submitted Solution:
```
for _ in range(int(input())):
a,b,x,y = map(int, input().split())
li = [
a*y, (a-x-1)*b, a*(b-y-1), (a-x-1)*(b-y-1)
]
print(max(li))
```
No
| 64,128 | [
0.50341796875,
-0.051177978515625,
-0.1204833984375,
0.35546875,
-0.58642578125,
-0.312255859375,
-0.214111328125,
0.2081298828125,
0.1436767578125,
0.84423828125,
0.3291015625,
-0.00553131103515625,
0.25927734375,
-0.42041015625,
-0.2164306640625,
0.1302490234375,
-0.40283203125,
... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Screen resolution of Polycarp's monitor is a Γ b pixels. Unfortunately, there is one dead pixel at his screen. It has coordinates (x, y) (0 β€ x < a, 0 β€ y < b). You can consider columns of pixels to be numbered from 0 to a-1, and rows β from 0 to b-1.
Polycarp wants to open a rectangular window of maximal size, which doesn't contain the dead pixel. The boundaries of the window should be parallel to the sides of the screen.
Print the maximal area (in pixels) of a window that doesn't contain the dead pixel inside itself.
Input
In the first line you are given an integer t (1 β€ t β€ 10^4) β the number of test cases in the test. In the next lines you are given descriptions of t test cases.
Each test case contains a single line which consists of 4 integers a, b, x and y (1 β€ a, b β€ 10^4; 0 β€ x < a; 0 β€ y < b) β the resolution of the screen and the coordinates of a dead pixel. It is guaranteed that a+b>2 (e.g. a=b=1 is impossible).
Output
Print t integers β the answers for each test case. Each answer should contain an integer equal to the maximal possible area (in pixels) of a rectangular window, that doesn't contain the dead pixel.
Example
Input
6
8 8 0 0
1 10 0 3
17 31 10 4
2 1 0 0
5 10 3 9
10 10 4 8
Output
56
6
442
1
45
80
Note
In the first test case, the screen resolution is 8 Γ 8, and the upper left pixel is a dead pixel. Here you can see one of two possible layouts of the maximal window.
<image>
Submitted Solution:
```
for i in range(int(input())):
a,b,x,y=map(int,input().split())
if x+y==0:print(a*b-b)
else:
if b/2>y:print(a*(b-y-1))
else:print(a*b - a*(b-y))
```
No
| 64,129 | [
0.50244140625,
-0.04412841796875,
-0.142333984375,
0.35986328125,
-0.5517578125,
-0.29638671875,
-0.193359375,
0.2000732421875,
0.162109375,
0.8271484375,
0.323974609375,
-0.0096435546875,
0.265625,
-0.43798828125,
-0.2021484375,
0.10992431640625,
-0.396728515625,
-0.5947265625,
... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Screen resolution of Polycarp's monitor is a Γ b pixels. Unfortunately, there is one dead pixel at his screen. It has coordinates (x, y) (0 β€ x < a, 0 β€ y < b). You can consider columns of pixels to be numbered from 0 to a-1, and rows β from 0 to b-1.
Polycarp wants to open a rectangular window of maximal size, which doesn't contain the dead pixel. The boundaries of the window should be parallel to the sides of the screen.
Print the maximal area (in pixels) of a window that doesn't contain the dead pixel inside itself.
Input
In the first line you are given an integer t (1 β€ t β€ 10^4) β the number of test cases in the test. In the next lines you are given descriptions of t test cases.
Each test case contains a single line which consists of 4 integers a, b, x and y (1 β€ a, b β€ 10^4; 0 β€ x < a; 0 β€ y < b) β the resolution of the screen and the coordinates of a dead pixel. It is guaranteed that a+b>2 (e.g. a=b=1 is impossible).
Output
Print t integers β the answers for each test case. Each answer should contain an integer equal to the maximal possible area (in pixels) of a rectangular window, that doesn't contain the dead pixel.
Example
Input
6
8 8 0 0
1 10 0 3
17 31 10 4
2 1 0 0
5 10 3 9
10 10 4 8
Output
56
6
442
1
45
80
Note
In the first test case, the screen resolution is 8 Γ 8, and the upper left pixel is a dead pixel. Here you can see one of two possible layouts of the maximal window.
<image>
Submitted Solution:
```
t = int(input("The number of tests is : "))
for i in range(t) :
string = str(input("Dates : "))
st = string.split()
a = int(st[0])
b = int(st[1])
x = int(st[2])
y = int(st[3])
case1 = (b-y-1)*a
case2 = y*a
case3 = x*b
case4 = (a-x-1)*b
case = max(case1, case2, case3, case4)
print(case)
```
No
| 64,130 | [
0.4951171875,
-0.060333251953125,
-0.0777587890625,
0.308349609375,
-0.68115234375,
-0.330810546875,
-0.176513671875,
0.185302734375,
0.1944580078125,
0.8447265625,
0.297119140625,
-0.053924560546875,
0.266357421875,
-0.39794921875,
-0.2176513671875,
0.08837890625,
-0.458251953125,
... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Screen resolution of Polycarp's monitor is a Γ b pixels. Unfortunately, there is one dead pixel at his screen. It has coordinates (x, y) (0 β€ x < a, 0 β€ y < b). You can consider columns of pixels to be numbered from 0 to a-1, and rows β from 0 to b-1.
Polycarp wants to open a rectangular window of maximal size, which doesn't contain the dead pixel. The boundaries of the window should be parallel to the sides of the screen.
Print the maximal area (in pixels) of a window that doesn't contain the dead pixel inside itself.
Input
In the first line you are given an integer t (1 β€ t β€ 10^4) β the number of test cases in the test. In the next lines you are given descriptions of t test cases.
Each test case contains a single line which consists of 4 integers a, b, x and y (1 β€ a, b β€ 10^4; 0 β€ x < a; 0 β€ y < b) β the resolution of the screen and the coordinates of a dead pixel. It is guaranteed that a+b>2 (e.g. a=b=1 is impossible).
Output
Print t integers β the answers for each test case. Each answer should contain an integer equal to the maximal possible area (in pixels) of a rectangular window, that doesn't contain the dead pixel.
Example
Input
6
8 8 0 0
1 10 0 3
17 31 10 4
2 1 0 0
5 10 3 9
10 10 4 8
Output
56
6
442
1
45
80
Note
In the first test case, the screen resolution is 8 Γ 8, and the upper left pixel is a dead pixel. Here you can see one of two possible layouts of the maximal window.
<image>
Submitted Solution:
```
x = int(input())
if (x>=1 and x<=10000):
tab = []
for i in range(x):
c = input().rstrip(" ")
c = c.split(" ")
if int(c[0]) + int(c[1]) > 2 and len(c)==4 and int(c[0])>int(c[2]) and int(c[1])>int(c[3]):
for j in range(len(c)):
tab.append(int(c[j]))
b = tab[3]
a = tab[0]
if tab[1] == 1:
b = 1
a = tab[0] - tab[2] - 1
elif (tab[1]//2) >= tab[3] :
b = tab[1] - tab[3] - 1
r = a*b
print(r)
tab = []
else:
print('impossible')
```
No
| 64,131 | [
0.52587890625,
-0.05853271484375,
-0.1103515625,
0.3037109375,
-0.5869140625,
-0.31494140625,
-0.2020263671875,
0.2044677734375,
0.1475830078125,
0.85888671875,
0.333740234375,
0.005115509033203125,
0.2337646484375,
-0.40478515625,
-0.1875,
0.119873046875,
-0.408935546875,
-0.59375... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is a beginner programmer. He is studying how to use a command line.
Polycarp faced the following problem. There are n files in a directory and he needs to delete some of them. Polycarp wants to run a single delete command with filename pattern as an argument. All the files to be deleted should match the pattern and all other files shouldn't match the pattern.
Polycarp doesn't know about an asterisk '*', the only special character he knows is a question mark '?' which matches any single character. All other characters in the pattern match themselves only.
Formally, a pattern matches a filename if and only if they have equal lengths and all characters in the corresponding positions are equal except when the character in the pattern is '?', in which case the corresponding filename character does not matter.
For example, the filename pattern "a?ba?":
* matches filenames "aabaa", "abba.", "a.ba9" and "a.ba.";
* does not match filenames "aaba", "abaab", "aabaaa" and "aabaa.".
Help Polycarp find a pattern which matches files to be deleted and only them or report if there is no such pattern.
Input
The first line of the input contains two integers n and m (1 β€ m β€ n β€ 100) β the total number of files and the number of files to be deleted.
The following n lines contain filenames, single filename per line. All filenames are non-empty strings containing only lowercase English letters, digits and dots ('.'). The length of each filename doesn't exceed 100. It is guaranteed that all filenames are distinct.
The last line of the input contains m distinct integer numbers in ascending order a1, a2, ..., am (1 β€ ai β€ n) β indices of files to be deleted. All files are indexed from 1 to n in order of their appearance in the input.
Output
If the required pattern exists, print "Yes" in the first line of the output. The second line should contain the required pattern. If there are multiple solutions, print any of them.
If the required pattern doesn't exist, print the only line containing "No".
Examples
Input
3 2
ab
ac
cd
1 2
Output
Yes
a?
Input
5 3
test
tezt
test.
.est
tes.
1 4 5
Output
Yes
?es?
Input
4 4
a
b
c
dd
1 2 3 4
Output
No
Input
6 3
.svn
.git
....
...
..
.
1 2 3
Output
Yes
.???
Tags: constructive algorithms, implementation
Correct Solution:
```
# _
#####################################################################################################################
def fileNamePattern(nNamesToDelete, name_sLength, namesToDelete, namesWithSimilarLength):
nNamesToTest = len(namesWithSimilarLength)
pattern = ''
for i in range(name_sLength):
letter = namesToDelete[0][i]
for j in range(1, nNamesToDelete):
if namesToDelete[j][i] != letter:
letter = '?'
break
for k in range(nNamesToTest):
if namesWithSimilarLength[k] and namesWithSimilarLength[k][i] != letter and letter != '?':
namesWithSimilarLength[k] = False
pattern += letter
for name in namesWithSimilarLength:
if name:
return 'No'
return f'Yes\n{pattern}'
def main():
nNames, nNamesToDelete = map(int, input().split())
rawStorage = [input() for x in range(nNames)]
indices = set(map(lambda x: int(x)-1, input().split()))
name_sLength = len(rawStorage[next(iter(indices))])
namesToDelete, namesWithSimilarLength = [], []
for i in range(nNames):
if i in indices:
if name_sLength != len(rawStorage[i]):
return 'No'
namesToDelete.append(rawStorage[i])
elif name_sLength == len(rawStorage[i]):
namesWithSimilarLength.append(rawStorage[i])
return fileNamePattern(nNamesToDelete, name_sLength, namesToDelete, namesWithSimilarLength)
if __name__ == '__main__':
print(main())
```
| 65,297 | [
0.52294921875,
0.200927734375,
0.55517578125,
0.353759765625,
-0.431396484375,
-0.1978759765625,
-0.1788330078125,
-0.267822265625,
0.332763671875,
1.4033203125,
0.884765625,
-0.11175537109375,
0.052947998046875,
-0.9619140625,
-0.7451171875,
0.11199951171875,
-0.19189453125,
-0.58... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is a beginner programmer. He is studying how to use a command line.
Polycarp faced the following problem. There are n files in a directory and he needs to delete some of them. Polycarp wants to run a single delete command with filename pattern as an argument. All the files to be deleted should match the pattern and all other files shouldn't match the pattern.
Polycarp doesn't know about an asterisk '*', the only special character he knows is a question mark '?' which matches any single character. All other characters in the pattern match themselves only.
Formally, a pattern matches a filename if and only if they have equal lengths and all characters in the corresponding positions are equal except when the character in the pattern is '?', in which case the corresponding filename character does not matter.
For example, the filename pattern "a?ba?":
* matches filenames "aabaa", "abba.", "a.ba9" and "a.ba.";
* does not match filenames "aaba", "abaab", "aabaaa" and "aabaa.".
Help Polycarp find a pattern which matches files to be deleted and only them or report if there is no such pattern.
Input
The first line of the input contains two integers n and m (1 β€ m β€ n β€ 100) β the total number of files and the number of files to be deleted.
The following n lines contain filenames, single filename per line. All filenames are non-empty strings containing only lowercase English letters, digits and dots ('.'). The length of each filename doesn't exceed 100. It is guaranteed that all filenames are distinct.
The last line of the input contains m distinct integer numbers in ascending order a1, a2, ..., am (1 β€ ai β€ n) β indices of files to be deleted. All files are indexed from 1 to n in order of their appearance in the input.
Output
If the required pattern exists, print "Yes" in the first line of the output. The second line should contain the required pattern. If there are multiple solutions, print any of them.
If the required pattern doesn't exist, print the only line containing "No".
Examples
Input
3 2
ab
ac
cd
1 2
Output
Yes
a?
Input
5 3
test
tezt
test.
.est
tes.
1 4 5
Output
Yes
?es?
Input
4 4
a
b
c
dd
1 2 3 4
Output
No
Input
6 3
.svn
.git
....
...
..
.
1 2 3
Output
Yes
.???
Tags: constructive algorithms, implementation
Correct Solution:
```
n, m = map(int,input().split())
w = [input() for _ in range(n)]
todel = [w[i-1] for i in map(int, input().split())]
if len(set(map(len,todel))) != 1:
print('No')
else:
pat = ''.join(['?' if len(set([todel[j][p] for j in range(m)])) != 1 else todel[0][p] for p in range(len(todel[0]))])
ok = True
for x in w:
if len(x) != len(pat):
continue
if not x in todel:
mat = True
for i in range(len(pat)):
if pat[i] != '?' and pat[i] != x[i]:
mat = False
break
if mat:
ok = False
break
if not ok:
print('No')
else:
print('Yes')
print(pat)
```
| 65,298 | [
0.52294921875,
0.200927734375,
0.55517578125,
0.353759765625,
-0.431396484375,
-0.1978759765625,
-0.1788330078125,
-0.267822265625,
0.332763671875,
1.4033203125,
0.884765625,
-0.11175537109375,
0.052947998046875,
-0.9619140625,
-0.7451171875,
0.11199951171875,
-0.19189453125,
-0.58... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is a beginner programmer. He is studying how to use a command line.
Polycarp faced the following problem. There are n files in a directory and he needs to delete some of them. Polycarp wants to run a single delete command with filename pattern as an argument. All the files to be deleted should match the pattern and all other files shouldn't match the pattern.
Polycarp doesn't know about an asterisk '*', the only special character he knows is a question mark '?' which matches any single character. All other characters in the pattern match themselves only.
Formally, a pattern matches a filename if and only if they have equal lengths and all characters in the corresponding positions are equal except when the character in the pattern is '?', in which case the corresponding filename character does not matter.
For example, the filename pattern "a?ba?":
* matches filenames "aabaa", "abba.", "a.ba9" and "a.ba.";
* does not match filenames "aaba", "abaab", "aabaaa" and "aabaa.".
Help Polycarp find a pattern which matches files to be deleted and only them or report if there is no such pattern.
Input
The first line of the input contains two integers n and m (1 β€ m β€ n β€ 100) β the total number of files and the number of files to be deleted.
The following n lines contain filenames, single filename per line. All filenames are non-empty strings containing only lowercase English letters, digits and dots ('.'). The length of each filename doesn't exceed 100. It is guaranteed that all filenames are distinct.
The last line of the input contains m distinct integer numbers in ascending order a1, a2, ..., am (1 β€ ai β€ n) β indices of files to be deleted. All files are indexed from 1 to n in order of their appearance in the input.
Output
If the required pattern exists, print "Yes" in the first line of the output. The second line should contain the required pattern. If there are multiple solutions, print any of them.
If the required pattern doesn't exist, print the only line containing "No".
Examples
Input
3 2
ab
ac
cd
1 2
Output
Yes
a?
Input
5 3
test
tezt
test.
.est
tes.
1 4 5
Output
Yes
?es?
Input
4 4
a
b
c
dd
1 2 3 4
Output
No
Input
6 3
.svn
.git
....
...
..
.
1 2 3
Output
Yes
.???
Tags: constructive algorithms, implementation
Correct Solution:
```
import sys
n, m = map(int, input().split())
file_name_list = []
for _ in range(n):
file_name_list.append(input())
file_pos_to_delete = list(map(int, input().split()))
file_to_delete_list = [file_name_list[pos - 1] for pos in file_pos_to_delete]
l = len(file_to_delete_list[0])
if any(len(e) != l for e in file_to_delete_list):
print('No')
sys.exit(0)
pattern = []
for i in range(l):
pattern.append(file_to_delete_list[0][i])
for j in range(1, m):
if pattern[-1] != file_to_delete_list[j][i]:
pattern[-1] = '?'
break
for i in range(n):
w = file_name_list[i]
if i + 1 not in file_pos_to_delete and len(w) == l and all(w[k] == pattern[k] or pattern[k] == '?' for k in range(l)):
print('No')
sys.exit(0)
print('Yes')
print(''.join(pattern))
```
| 65,299 | [
0.52294921875,
0.200927734375,
0.55517578125,
0.353759765625,
-0.431396484375,
-0.1978759765625,
-0.1788330078125,
-0.267822265625,
0.332763671875,
1.4033203125,
0.884765625,
-0.11175537109375,
0.052947998046875,
-0.9619140625,
-0.7451171875,
0.11199951171875,
-0.19189453125,
-0.58... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is a beginner programmer. He is studying how to use a command line.
Polycarp faced the following problem. There are n files in a directory and he needs to delete some of them. Polycarp wants to run a single delete command with filename pattern as an argument. All the files to be deleted should match the pattern and all other files shouldn't match the pattern.
Polycarp doesn't know about an asterisk '*', the only special character he knows is a question mark '?' which matches any single character. All other characters in the pattern match themselves only.
Formally, a pattern matches a filename if and only if they have equal lengths and all characters in the corresponding positions are equal except when the character in the pattern is '?', in which case the corresponding filename character does not matter.
For example, the filename pattern "a?ba?":
* matches filenames "aabaa", "abba.", "a.ba9" and "a.ba.";
* does not match filenames "aaba", "abaab", "aabaaa" and "aabaa.".
Help Polycarp find a pattern which matches files to be deleted and only them or report if there is no such pattern.
Input
The first line of the input contains two integers n and m (1 β€ m β€ n β€ 100) β the total number of files and the number of files to be deleted.
The following n lines contain filenames, single filename per line. All filenames are non-empty strings containing only lowercase English letters, digits and dots ('.'). The length of each filename doesn't exceed 100. It is guaranteed that all filenames are distinct.
The last line of the input contains m distinct integer numbers in ascending order a1, a2, ..., am (1 β€ ai β€ n) β indices of files to be deleted. All files are indexed from 1 to n in order of their appearance in the input.
Output
If the required pattern exists, print "Yes" in the first line of the output. The second line should contain the required pattern. If there are multiple solutions, print any of them.
If the required pattern doesn't exist, print the only line containing "No".
Examples
Input
3 2
ab
ac
cd
1 2
Output
Yes
a?
Input
5 3
test
tezt
test.
.est
tes.
1 4 5
Output
Yes
?es?
Input
4 4
a
b
c
dd
1 2 3 4
Output
No
Input
6 3
.svn
.git
....
...
..
.
1 2 3
Output
Yes
.???
Tags: constructive algorithms, implementation
Correct Solution:
```
m,n=list(map(int,input().split()))
s=[input().strip() for i in range(m)]
a=list(map(lambda x:int(x)-1,input().split()))
stmpl=s[a[0]]
f=1
def peres(s1,s2):
return ''.join([i if i==j else '?' for i,j in zip(s1,s2)])
for i in a:
if len(stmpl)!=len(s[i]):
f=0
break
stmpl=peres(stmpl,s[i])
for i,e in enumerate(s):
if i in a:
continue
if len(stmpl)==len(e) and stmpl==peres(stmpl,e):
f=0
break
if f:
print('Yes')
print(stmpl)
else:
print('No')
```
| 65,300 | [
0.52294921875,
0.200927734375,
0.55517578125,
0.353759765625,
-0.431396484375,
-0.1978759765625,
-0.1788330078125,
-0.267822265625,
0.332763671875,
1.4033203125,
0.884765625,
-0.11175537109375,
0.052947998046875,
-0.9619140625,
-0.7451171875,
0.11199951171875,
-0.19189453125,
-0.58... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is a beginner programmer. He is studying how to use a command line.
Polycarp faced the following problem. There are n files in a directory and he needs to delete some of them. Polycarp wants to run a single delete command with filename pattern as an argument. All the files to be deleted should match the pattern and all other files shouldn't match the pattern.
Polycarp doesn't know about an asterisk '*', the only special character he knows is a question mark '?' which matches any single character. All other characters in the pattern match themselves only.
Formally, a pattern matches a filename if and only if they have equal lengths and all characters in the corresponding positions are equal except when the character in the pattern is '?', in which case the corresponding filename character does not matter.
For example, the filename pattern "a?ba?":
* matches filenames "aabaa", "abba.", "a.ba9" and "a.ba.";
* does not match filenames "aaba", "abaab", "aabaaa" and "aabaa.".
Help Polycarp find a pattern which matches files to be deleted and only them or report if there is no such pattern.
Input
The first line of the input contains two integers n and m (1 β€ m β€ n β€ 100) β the total number of files and the number of files to be deleted.
The following n lines contain filenames, single filename per line. All filenames are non-empty strings containing only lowercase English letters, digits and dots ('.'). The length of each filename doesn't exceed 100. It is guaranteed that all filenames are distinct.
The last line of the input contains m distinct integer numbers in ascending order a1, a2, ..., am (1 β€ ai β€ n) β indices of files to be deleted. All files are indexed from 1 to n in order of their appearance in the input.
Output
If the required pattern exists, print "Yes" in the first line of the output. The second line should contain the required pattern. If there are multiple solutions, print any of them.
If the required pattern doesn't exist, print the only line containing "No".
Examples
Input
3 2
ab
ac
cd
1 2
Output
Yes
a?
Input
5 3
test
tezt
test.
.est
tes.
1 4 5
Output
Yes
?es?
Input
4 4
a
b
c
dd
1 2 3 4
Output
No
Input
6 3
.svn
.git
....
...
..
.
1 2 3
Output
Yes
.???
Tags: constructive algorithms, implementation
Correct Solution:
```
n = int(input().split()[0])
all_files = [str(input()) for i in range(n)]
index_to_del = [int(i) - 1 for i in (input().split())]
def find_pattern(all_files, index_to_del):
for i in index_to_del[1:]:
if len(all_files[i]) != len(all_files[index_to_del[0]]):
return "No"
pattern = ''
for i in range(len(all_files[index_to_del[0]])):
added = False
for j in (index_to_del[1:]):
if all_files[j][i] != all_files[index_to_del[0]][i]:
if not added:
pattern += '?'
added = True
if not added:
pattern += all_files[index_to_del[0]][i]
for i in range(len(all_files)):
if i not in index_to_del:
if len(all_files[i]) == len(pattern):
matching_chars = []
for index in range(len(pattern)):
matching_chars.append(all_files[i][index] == pattern[index] or pattern[index] == '?')
if all(matching_chars):
return "No"
print("Yes")
return pattern
print(find_pattern(all_files, index_to_del))
```
| 65,301 | [
0.52294921875,
0.200927734375,
0.55517578125,
0.353759765625,
-0.431396484375,
-0.1978759765625,
-0.1788330078125,
-0.267822265625,
0.332763671875,
1.4033203125,
0.884765625,
-0.11175537109375,
0.052947998046875,
-0.9619140625,
-0.7451171875,
0.11199951171875,
-0.19189453125,
-0.58... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is a beginner programmer. He is studying how to use a command line.
Polycarp faced the following problem. There are n files in a directory and he needs to delete some of them. Polycarp wants to run a single delete command with filename pattern as an argument. All the files to be deleted should match the pattern and all other files shouldn't match the pattern.
Polycarp doesn't know about an asterisk '*', the only special character he knows is a question mark '?' which matches any single character. All other characters in the pattern match themselves only.
Formally, a pattern matches a filename if and only if they have equal lengths and all characters in the corresponding positions are equal except when the character in the pattern is '?', in which case the corresponding filename character does not matter.
For example, the filename pattern "a?ba?":
* matches filenames "aabaa", "abba.", "a.ba9" and "a.ba.";
* does not match filenames "aaba", "abaab", "aabaaa" and "aabaa.".
Help Polycarp find a pattern which matches files to be deleted and only them or report if there is no such pattern.
Input
The first line of the input contains two integers n and m (1 β€ m β€ n β€ 100) β the total number of files and the number of files to be deleted.
The following n lines contain filenames, single filename per line. All filenames are non-empty strings containing only lowercase English letters, digits and dots ('.'). The length of each filename doesn't exceed 100. It is guaranteed that all filenames are distinct.
The last line of the input contains m distinct integer numbers in ascending order a1, a2, ..., am (1 β€ ai β€ n) β indices of files to be deleted. All files are indexed from 1 to n in order of their appearance in the input.
Output
If the required pattern exists, print "Yes" in the first line of the output. The second line should contain the required pattern. If there are multiple solutions, print any of them.
If the required pattern doesn't exist, print the only line containing "No".
Examples
Input
3 2
ab
ac
cd
1 2
Output
Yes
a?
Input
5 3
test
tezt
test.
.est
tes.
1 4 5
Output
Yes
?es?
Input
4 4
a
b
c
dd
1 2 3 4
Output
No
Input
6 3
.svn
.git
....
...
..
.
1 2 3
Output
Yes
.???
Tags: constructive algorithms, implementation
Correct Solution:
```
"""
Oh, Grantors of Dark Disgrace,
Do Not Wake Me Again.
"""
import sys
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())
si = lambda: input()
n, m = mi()
f = []
for i in range(n):
f.append(si())
lm = li()
l = len(f[lm[0]-1])
z = ['']*l
for v in lm:
if len(f[v-1]) != l:
print("No")
sys.exit(0)
else:
for i in range(len(z)):
z[i] += f[v-1][i]
x = ''
for i in range(len(z)):
if len(set(z[i])) == 1:
x += z[i][0]
else:
x += '?'
for i, j in enumerate(f):
if i+1 in lm or len(j) != l: continue
else:
b = 1
for p in range(len(j)):
if x[p]!='?' and (x[p] != j[p]):
b = 0
if b == 1:
print("No")
sys.exit(0)
print("Yes")
print(x)
```
| 65,302 | [
0.52294921875,
0.200927734375,
0.55517578125,
0.353759765625,
-0.431396484375,
-0.1978759765625,
-0.1788330078125,
-0.267822265625,
0.332763671875,
1.4033203125,
0.884765625,
-0.11175537109375,
0.052947998046875,
-0.9619140625,
-0.7451171875,
0.11199951171875,
-0.19189453125,
-0.58... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is a beginner programmer. He is studying how to use a command line.
Polycarp faced the following problem. There are n files in a directory and he needs to delete some of them. Polycarp wants to run a single delete command with filename pattern as an argument. All the files to be deleted should match the pattern and all other files shouldn't match the pattern.
Polycarp doesn't know about an asterisk '*', the only special character he knows is a question mark '?' which matches any single character. All other characters in the pattern match themselves only.
Formally, a pattern matches a filename if and only if they have equal lengths and all characters in the corresponding positions are equal except when the character in the pattern is '?', in which case the corresponding filename character does not matter.
For example, the filename pattern "a?ba?":
* matches filenames "aabaa", "abba.", "a.ba9" and "a.ba.";
* does not match filenames "aaba", "abaab", "aabaaa" and "aabaa.".
Help Polycarp find a pattern which matches files to be deleted and only them or report if there is no such pattern.
Input
The first line of the input contains two integers n and m (1 β€ m β€ n β€ 100) β the total number of files and the number of files to be deleted.
The following n lines contain filenames, single filename per line. All filenames are non-empty strings containing only lowercase English letters, digits and dots ('.'). The length of each filename doesn't exceed 100. It is guaranteed that all filenames are distinct.
The last line of the input contains m distinct integer numbers in ascending order a1, a2, ..., am (1 β€ ai β€ n) β indices of files to be deleted. All files are indexed from 1 to n in order of their appearance in the input.
Output
If the required pattern exists, print "Yes" in the first line of the output. The second line should contain the required pattern. If there are multiple solutions, print any of them.
If the required pattern doesn't exist, print the only line containing "No".
Examples
Input
3 2
ab
ac
cd
1 2
Output
Yes
a?
Input
5 3
test
tezt
test.
.est
tes.
1 4 5
Output
Yes
?es?
Input
4 4
a
b
c
dd
1 2 3 4
Output
No
Input
6 3
.svn
.git
....
...
..
.
1 2 3
Output
Yes
.???
Tags: constructive algorithms, implementation
Correct Solution:
```
n, m = map(int, input().split())
f = [input() for _ in range(n)]
d = set(map(int, input().split()))
c = {}
l = 0
for x in d:
l = len(f[x - 1])
c[l] = 1
if len(c) > 1:
print('No')
else:
t = ['?'] * l
for i in range(l):
c = {}
ch = ''
for x in d:
ch = f[x - 1][i]
c[ch] = 1
if 1 == len(c):
t[i] = ch
for i in range(n):
if (i + 1) not in d:
if len(f[i]) == l:
ok = 0
for j in range(l):
if t[j] != '?' and f[i][j] != t[j]:
ok = 1
break
if not ok:
print('No')
break
else:
print('Yes')
print(''.join(t))
```
| 65,303 | [
0.52294921875,
0.200927734375,
0.55517578125,
0.353759765625,
-0.431396484375,
-0.1978759765625,
-0.1788330078125,
-0.267822265625,
0.332763671875,
1.4033203125,
0.884765625,
-0.11175537109375,
0.052947998046875,
-0.9619140625,
-0.7451171875,
0.11199951171875,
-0.19189453125,
-0.58... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is a beginner programmer. He is studying how to use a command line.
Polycarp faced the following problem. There are n files in a directory and he needs to delete some of them. Polycarp wants to run a single delete command with filename pattern as an argument. All the files to be deleted should match the pattern and all other files shouldn't match the pattern.
Polycarp doesn't know about an asterisk '*', the only special character he knows is a question mark '?' which matches any single character. All other characters in the pattern match themselves only.
Formally, a pattern matches a filename if and only if they have equal lengths and all characters in the corresponding positions are equal except when the character in the pattern is '?', in which case the corresponding filename character does not matter.
For example, the filename pattern "a?ba?":
* matches filenames "aabaa", "abba.", "a.ba9" and "a.ba.";
* does not match filenames "aaba", "abaab", "aabaaa" and "aabaa.".
Help Polycarp find a pattern which matches files to be deleted and only them or report if there is no such pattern.
Input
The first line of the input contains two integers n and m (1 β€ m β€ n β€ 100) β the total number of files and the number of files to be deleted.
The following n lines contain filenames, single filename per line. All filenames are non-empty strings containing only lowercase English letters, digits and dots ('.'). The length of each filename doesn't exceed 100. It is guaranteed that all filenames are distinct.
The last line of the input contains m distinct integer numbers in ascending order a1, a2, ..., am (1 β€ ai β€ n) β indices of files to be deleted. All files are indexed from 1 to n in order of their appearance in the input.
Output
If the required pattern exists, print "Yes" in the first line of the output. The second line should contain the required pattern. If there are multiple solutions, print any of them.
If the required pattern doesn't exist, print the only line containing "No".
Examples
Input
3 2
ab
ac
cd
1 2
Output
Yes
a?
Input
5 3
test
tezt
test.
.est
tes.
1 4 5
Output
Yes
?es?
Input
4 4
a
b
c
dd
1 2 3 4
Output
No
Input
6 3
.svn
.git
....
...
..
.
1 2 3
Output
Yes
.???
Tags: constructive algorithms, implementation
Correct Solution:
```
import sys
import re
[words, selected] = input().split(" ")
[words, selected] = [int(words), int(selected)]
wordBuffer = []
selectedWords = []
for i in range(words):
wordBuffer.append(input())
buffer = input().split(" ")
for i in buffer:
selectedWords.append(wordBuffer[int(i) - 1])
for i in range(len(selectedWords)):
if (i > 0 and len(selectedWords[i - 1]) != len(selectedWords[i])):
print("No")
exit()
reg = ""
res = ""
for letter in range(len(selectedWords[0])):
isQuested = False
for i in range(selected):
if (i > 0 and selectedWords[i - 1][letter] != selectedWords[i][letter]):
reg += "."
res += "?"
isQuested = True
break
if (isQuested == False):
if (selectedWords[0][letter] == "."):
reg += "\\" + selectedWords[0][letter]
else:
reg += selectedWords[0][letter]
res += selectedWords[0][letter]
matches = 0
for i in wordBuffer:
if (re.fullmatch(reg, i) != None):
matches += 1
if (matches == selected):
print("Yes\n" + res)
else:
print("No")
```
| 65,304 | [
0.52294921875,
0.200927734375,
0.55517578125,
0.353759765625,
-0.431396484375,
-0.1978759765625,
-0.1788330078125,
-0.267822265625,
0.332763671875,
1.4033203125,
0.884765625,
-0.11175537109375,
0.052947998046875,
-0.9619140625,
-0.7451171875,
0.11199951171875,
-0.19189453125,
-0.58... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is a beginner programmer. He is studying how to use a command line.
Polycarp faced the following problem. There are n files in a directory and he needs to delete some of them. Polycarp wants to run a single delete command with filename pattern as an argument. All the files to be deleted should match the pattern and all other files shouldn't match the pattern.
Polycarp doesn't know about an asterisk '*', the only special character he knows is a question mark '?' which matches any single character. All other characters in the pattern match themselves only.
Formally, a pattern matches a filename if and only if they have equal lengths and all characters in the corresponding positions are equal except when the character in the pattern is '?', in which case the corresponding filename character does not matter.
For example, the filename pattern "a?ba?":
* matches filenames "aabaa", "abba.", "a.ba9" and "a.ba.";
* does not match filenames "aaba", "abaab", "aabaaa" and "aabaa.".
Help Polycarp find a pattern which matches files to be deleted and only them or report if there is no such pattern.
Input
The first line of the input contains two integers n and m (1 β€ m β€ n β€ 100) β the total number of files and the number of files to be deleted.
The following n lines contain filenames, single filename per line. All filenames are non-empty strings containing only lowercase English letters, digits and dots ('.'). The length of each filename doesn't exceed 100. It is guaranteed that all filenames are distinct.
The last line of the input contains m distinct integer numbers in ascending order a1, a2, ..., am (1 β€ ai β€ n) β indices of files to be deleted. All files are indexed from 1 to n in order of their appearance in the input.
Output
If the required pattern exists, print "Yes" in the first line of the output. The second line should contain the required pattern. If there are multiple solutions, print any of them.
If the required pattern doesn't exist, print the only line containing "No".
Examples
Input
3 2
ab
ac
cd
1 2
Output
Yes
a?
Input
5 3
test
tezt
test.
.est
tes.
1 4 5
Output
Yes
?es?
Input
4 4
a
b
c
dd
1 2 3 4
Output
No
Input
6 3
.svn
.git
....
...
..
.
1 2 3
Output
Yes
.???
Submitted Solution:
```
[m, n] = [int(x) for x in input().split()]
strings = []
for i in range(m):
strings.append(input())
to_delete_index = [int(x)-1 for x in input().split()]
to_delete = [strings[int(x)] for x in to_delete_index]
base_len = len(to_delete[0])
for s in to_delete:
if len(s) != base_len:
print('No')
exit()
match_string = ""
for i in range(base_len):
match = to_delete[0][i]
for s in to_delete:
if s[i] != match:
match = "?"
break
match_string += match
def match(s, match_string):
if len(s) != len(match_string):
return False
for i in range(len(s)):
if match_string[i] == "?":
continue
if match_string[i] != s[i]:
return False
return True
for i in range(len(strings)):
if i in to_delete_index:
continue
if match(strings[i], match_string):
print("No")
exit()
print("Yes")
print(match_string)
```
Yes
| 65,305 | [
0.5302734375,
0.230224609375,
0.51806640625,
0.296630859375,
-0.45556640625,
-0.1031494140625,
-0.292724609375,
-0.1962890625,
0.298828125,
1.32421875,
0.85595703125,
-0.115478515625,
0.0024662017822265625,
-0.90673828125,
-0.8076171875,
0.0521240234375,
-0.218017578125,
-0.5107421... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is a beginner programmer. He is studying how to use a command line.
Polycarp faced the following problem. There are n files in a directory and he needs to delete some of them. Polycarp wants to run a single delete command with filename pattern as an argument. All the files to be deleted should match the pattern and all other files shouldn't match the pattern.
Polycarp doesn't know about an asterisk '*', the only special character he knows is a question mark '?' which matches any single character. All other characters in the pattern match themselves only.
Formally, a pattern matches a filename if and only if they have equal lengths and all characters in the corresponding positions are equal except when the character in the pattern is '?', in which case the corresponding filename character does not matter.
For example, the filename pattern "a?ba?":
* matches filenames "aabaa", "abba.", "a.ba9" and "a.ba.";
* does not match filenames "aaba", "abaab", "aabaaa" and "aabaa.".
Help Polycarp find a pattern which matches files to be deleted and only them or report if there is no such pattern.
Input
The first line of the input contains two integers n and m (1 β€ m β€ n β€ 100) β the total number of files and the number of files to be deleted.
The following n lines contain filenames, single filename per line. All filenames are non-empty strings containing only lowercase English letters, digits and dots ('.'). The length of each filename doesn't exceed 100. It is guaranteed that all filenames are distinct.
The last line of the input contains m distinct integer numbers in ascending order a1, a2, ..., am (1 β€ ai β€ n) β indices of files to be deleted. All files are indexed from 1 to n in order of their appearance in the input.
Output
If the required pattern exists, print "Yes" in the first line of the output. The second line should contain the required pattern. If there are multiple solutions, print any of them.
If the required pattern doesn't exist, print the only line containing "No".
Examples
Input
3 2
ab
ac
cd
1 2
Output
Yes
a?
Input
5 3
test
tezt
test.
.est
tes.
1 4 5
Output
Yes
?es?
Input
4 4
a
b
c
dd
1 2 3 4
Output
No
Input
6 3
.svn
.git
....
...
..
.
1 2 3
Output
Yes
.???
Submitted Solution:
```
n, m = map(int, input().split())
a = []
for i in range(n):
a.append(input())
b = [int(_) for _ in input().split()]
p = list(a[b[0] - 1])
for i in range(1, len(b)):
s = a[b[i] - 1]
if len(s) != len(p):
print("No")
raise SystemExit
for j in range(len(s)):
if s[j] != p[j] and p[j] != '?':
p[j] = '?'
k = 0
f = False
for i in range(n):
if k < m and i + 1 == b[k]:
k += 1
continue
s = a[i]
if len(s) == len(p):
f = True
for j in range(len(s)):
if s[j] != p[j] and p[j] != '?':
f = False
break
if f:
print("No")
raise SystemExit
print("Yes")
print(''.join(p))
```
Yes
| 65,306 | [
0.5302734375,
0.230224609375,
0.51806640625,
0.296630859375,
-0.45556640625,
-0.1031494140625,
-0.292724609375,
-0.1962890625,
0.298828125,
1.32421875,
0.85595703125,
-0.115478515625,
0.0024662017822265625,
-0.90673828125,
-0.8076171875,
0.0521240234375,
-0.218017578125,
-0.5107421... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is a beginner programmer. He is studying how to use a command line.
Polycarp faced the following problem. There are n files in a directory and he needs to delete some of them. Polycarp wants to run a single delete command with filename pattern as an argument. All the files to be deleted should match the pattern and all other files shouldn't match the pattern.
Polycarp doesn't know about an asterisk '*', the only special character he knows is a question mark '?' which matches any single character. All other characters in the pattern match themselves only.
Formally, a pattern matches a filename if and only if they have equal lengths and all characters in the corresponding positions are equal except when the character in the pattern is '?', in which case the corresponding filename character does not matter.
For example, the filename pattern "a?ba?":
* matches filenames "aabaa", "abba.", "a.ba9" and "a.ba.";
* does not match filenames "aaba", "abaab", "aabaaa" and "aabaa.".
Help Polycarp find a pattern which matches files to be deleted and only them or report if there is no such pattern.
Input
The first line of the input contains two integers n and m (1 β€ m β€ n β€ 100) β the total number of files and the number of files to be deleted.
The following n lines contain filenames, single filename per line. All filenames are non-empty strings containing only lowercase English letters, digits and dots ('.'). The length of each filename doesn't exceed 100. It is guaranteed that all filenames are distinct.
The last line of the input contains m distinct integer numbers in ascending order a1, a2, ..., am (1 β€ ai β€ n) β indices of files to be deleted. All files are indexed from 1 to n in order of their appearance in the input.
Output
If the required pattern exists, print "Yes" in the first line of the output. The second line should contain the required pattern. If there are multiple solutions, print any of them.
If the required pattern doesn't exist, print the only line containing "No".
Examples
Input
3 2
ab
ac
cd
1 2
Output
Yes
a?
Input
5 3
test
tezt
test.
.est
tes.
1 4 5
Output
Yes
?es?
Input
4 4
a
b
c
dd
1 2 3 4
Output
No
Input
6 3
.svn
.git
....
...
..
.
1 2 3
Output
Yes
.???
Submitted Solution:
```
#!/bin/python
import sys
counter = 0
allstrs = []
def firstnum (inpu):
out = ""
for char in inpu:
if char == ' ':
break
out += char
return int(out)
def secondnum (inpu):
first = True
out = ""
for char in inpu:
if char == ' ' and not(first):
break
elif char == ' ' and first:
first = False
out += char
return int(out)
for line in sys.stdin:
if counter == 0:
counter += 1
else:
allstrs.append(line)
removalfiles = []
removalfilesnums = list(map(int, allstrs[allstrs.__len__() - 1].split(" ")))
for i in range(0, removalfilesnums.__len__() - 0):
removalfiles.append(allstrs[removalfilesnums[i] - 1])
removalfiles = [s.strip('\n') for s in removalfiles]
for ff in removalfiles:
if removalfiles[0].__len__() != ff.__len__():
print("No")
sys.exit(0)
outString = ""
for ii in range(0, removalfiles[0].__len__()):
broke = False
for ff in removalfiles:
if ff[ii] != removalfiles[0][ii]:
broke = True
outString += '?'
break
if not broke:
outString += removalfiles[0][ii]
checklist = [s.strip('\n') for s in [allstrs[i] for i in range(0, allstrs.__len__()) if i + 1 not in removalfilesnums]]
for line in checklist:
test = False
if line.__len__() == outString.__len__():
test = True
for charLine, charOut in zip(line, outString):
if charLine != charOut and charOut != '?':
test = False
if test:
print("No")
sys.exit(0)
print("Yes")
print(outString)
```
Yes
| 65,307 | [
0.5302734375,
0.230224609375,
0.51806640625,
0.296630859375,
-0.45556640625,
-0.1031494140625,
-0.292724609375,
-0.1962890625,
0.298828125,
1.32421875,
0.85595703125,
-0.115478515625,
0.0024662017822265625,
-0.90673828125,
-0.8076171875,
0.0521240234375,
-0.218017578125,
-0.5107421... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is a beginner programmer. He is studying how to use a command line.
Polycarp faced the following problem. There are n files in a directory and he needs to delete some of them. Polycarp wants to run a single delete command with filename pattern as an argument. All the files to be deleted should match the pattern and all other files shouldn't match the pattern.
Polycarp doesn't know about an asterisk '*', the only special character he knows is a question mark '?' which matches any single character. All other characters in the pattern match themselves only.
Formally, a pattern matches a filename if and only if they have equal lengths and all characters in the corresponding positions are equal except when the character in the pattern is '?', in which case the corresponding filename character does not matter.
For example, the filename pattern "a?ba?":
* matches filenames "aabaa", "abba.", "a.ba9" and "a.ba.";
* does not match filenames "aaba", "abaab", "aabaaa" and "aabaa.".
Help Polycarp find a pattern which matches files to be deleted and only them or report if there is no such pattern.
Input
The first line of the input contains two integers n and m (1 β€ m β€ n β€ 100) β the total number of files and the number of files to be deleted.
The following n lines contain filenames, single filename per line. All filenames are non-empty strings containing only lowercase English letters, digits and dots ('.'). The length of each filename doesn't exceed 100. It is guaranteed that all filenames are distinct.
The last line of the input contains m distinct integer numbers in ascending order a1, a2, ..., am (1 β€ ai β€ n) β indices of files to be deleted. All files are indexed from 1 to n in order of their appearance in the input.
Output
If the required pattern exists, print "Yes" in the first line of the output. The second line should contain the required pattern. If there are multiple solutions, print any of them.
If the required pattern doesn't exist, print the only line containing "No".
Examples
Input
3 2
ab
ac
cd
1 2
Output
Yes
a?
Input
5 3
test
tezt
test.
.est
tes.
1 4 5
Output
Yes
?es?
Input
4 4
a
b
c
dd
1 2 3 4
Output
No
Input
6 3
.svn
.git
....
...
..
.
1 2 3
Output
Yes
.???
Submitted Solution:
```
#Code by Sounak, IIESTS
#------------------------------warmup----------------------------
import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
#-------------------game starts now-----------------------------------------------------
n,m=map(int,input().split())
ini=list()
dl=list()
for i in range (n):
s=input()
ini.append(s)
a=list(map(int,input().split()))
ch=1
for i in a:
dl.append(ini[i-1])
l=len(dl[0])
c=list(dl[0])
for i in dl:
if len(i)!=l:
ch=0
break
for j in range (l):
if i[j]!=c[j]:
c[j]='?'
for i in range (n):
if i+1 in a:
continue
s=ini[i]
if len(s)!=l:
continue
ct=0
for j in range (l):
if s[j]==c[j] or c[j]=='?':
ct+=1
if ct==l:
ch=0
break
if ch==1:
print("Yes")
print(*c,sep='')
else:
print("No")
```
Yes
| 65,308 | [
0.5302734375,
0.230224609375,
0.51806640625,
0.296630859375,
-0.45556640625,
-0.1031494140625,
-0.292724609375,
-0.1962890625,
0.298828125,
1.32421875,
0.85595703125,
-0.115478515625,
0.0024662017822265625,
-0.90673828125,
-0.8076171875,
0.0521240234375,
-0.218017578125,
-0.5107421... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is a beginner programmer. He is studying how to use a command line.
Polycarp faced the following problem. There are n files in a directory and he needs to delete some of them. Polycarp wants to run a single delete command with filename pattern as an argument. All the files to be deleted should match the pattern and all other files shouldn't match the pattern.
Polycarp doesn't know about an asterisk '*', the only special character he knows is a question mark '?' which matches any single character. All other characters in the pattern match themselves only.
Formally, a pattern matches a filename if and only if they have equal lengths and all characters in the corresponding positions are equal except when the character in the pattern is '?', in which case the corresponding filename character does not matter.
For example, the filename pattern "a?ba?":
* matches filenames "aabaa", "abba.", "a.ba9" and "a.ba.";
* does not match filenames "aaba", "abaab", "aabaaa" and "aabaa.".
Help Polycarp find a pattern which matches files to be deleted and only them or report if there is no such pattern.
Input
The first line of the input contains two integers n and m (1 β€ m β€ n β€ 100) β the total number of files and the number of files to be deleted.
The following n lines contain filenames, single filename per line. All filenames are non-empty strings containing only lowercase English letters, digits and dots ('.'). The length of each filename doesn't exceed 100. It is guaranteed that all filenames are distinct.
The last line of the input contains m distinct integer numbers in ascending order a1, a2, ..., am (1 β€ ai β€ n) β indices of files to be deleted. All files are indexed from 1 to n in order of their appearance in the input.
Output
If the required pattern exists, print "Yes" in the first line of the output. The second line should contain the required pattern. If there are multiple solutions, print any of them.
If the required pattern doesn't exist, print the only line containing "No".
Examples
Input
3 2
ab
ac
cd
1 2
Output
Yes
a?
Input
5 3
test
tezt
test.
.est
tes.
1 4 5
Output
Yes
?es?
Input
4 4
a
b
c
dd
1 2 3 4
Output
No
Input
6 3
.svn
.git
....
...
..
.
1 2 3
Output
Yes
.???
Submitted Solution:
```
"""
Oh, Grantors of Dark Disgrace,
Do Not Wake Me Again.
"""
import sys
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())
si = lambda: input()
n, m = mi()
f = []
for i in range(n):
f.append(si())
lm = li()
l = len(f[lm[0]-1])
z = ['']*l
for v in lm:
if len(f[v-1]) != l:
print("No")
sys.exit(0)
else:
for i in range(len(z)):
z[i] += f[v-1][i]
x = ''
flag = 0
for i in range(len(z)):
if len(set(z[i])) == 1:
x += z[i][0]
else:
x += '?'
flag += 1
for i, j in enumerate(f):
if i+1 in lm or len(j) != l: continue
else:
b = 1
for p in range(len(j)):
if x[p]!='?' and (x[p] != j[p]):
b = 0
if b == 1:
print("No")
sys.exit(0)
if flag == len(x) and flag != 1:
print("No")
else:
print("Yes")
print(x)
```
No
| 65,309 | [
0.5302734375,
0.230224609375,
0.51806640625,
0.296630859375,
-0.45556640625,
-0.1031494140625,
-0.292724609375,
-0.1962890625,
0.298828125,
1.32421875,
0.85595703125,
-0.115478515625,
0.0024662017822265625,
-0.90673828125,
-0.8076171875,
0.0521240234375,
-0.218017578125,
-0.5107421... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is a beginner programmer. He is studying how to use a command line.
Polycarp faced the following problem. There are n files in a directory and he needs to delete some of them. Polycarp wants to run a single delete command with filename pattern as an argument. All the files to be deleted should match the pattern and all other files shouldn't match the pattern.
Polycarp doesn't know about an asterisk '*', the only special character he knows is a question mark '?' which matches any single character. All other characters in the pattern match themselves only.
Formally, a pattern matches a filename if and only if they have equal lengths and all characters in the corresponding positions are equal except when the character in the pattern is '?', in which case the corresponding filename character does not matter.
For example, the filename pattern "a?ba?":
* matches filenames "aabaa", "abba.", "a.ba9" and "a.ba.";
* does not match filenames "aaba", "abaab", "aabaaa" and "aabaa.".
Help Polycarp find a pattern which matches files to be deleted and only them or report if there is no such pattern.
Input
The first line of the input contains two integers n and m (1 β€ m β€ n β€ 100) β the total number of files and the number of files to be deleted.
The following n lines contain filenames, single filename per line. All filenames are non-empty strings containing only lowercase English letters, digits and dots ('.'). The length of each filename doesn't exceed 100. It is guaranteed that all filenames are distinct.
The last line of the input contains m distinct integer numbers in ascending order a1, a2, ..., am (1 β€ ai β€ n) β indices of files to be deleted. All files are indexed from 1 to n in order of their appearance in the input.
Output
If the required pattern exists, print "Yes" in the first line of the output. The second line should contain the required pattern. If there are multiple solutions, print any of them.
If the required pattern doesn't exist, print the only line containing "No".
Examples
Input
3 2
ab
ac
cd
1 2
Output
Yes
a?
Input
5 3
test
tezt
test.
.est
tes.
1 4 5
Output
Yes
?es?
Input
4 4
a
b
c
dd
1 2 3 4
Output
No
Input
6 3
.svn
.git
....
...
..
.
1 2 3
Output
Yes
.???
Submitted Solution:
```
def delete():
num_file,num_delete = map(int, input().split())
list_file = []
for i in range(num_file):
list_file.append(input())
delete_file = [int(i)-1 for i in input().split()]
ans=[]
delete_list = sorted([list_file[i]for i in delete_file],key=len)
## print(delete_list)
tmp = list(delete_list[0])
for i in delete_list[1:]:
name = list(i)
if len(tmp) != len(i):
ans.append(tmp)
tmp=list(i)
for j in range(len(tmp)):
if name[j] != tmp[j]:
tmp[j] = "?"
ans.append(tmp)
## print(ans)
for i in []+ans:
tmp = i[0]
p = 1
for j in i:
if tmp != j:
p=0
if p:
ans.remove(i)
if len(ans) == 0:
print("No")
else:
print("Yes")
for i in ans:
for c in i:
print(c,end="")
print(" ",end="")
delete()
```
No
| 65,310 | [
0.5302734375,
0.230224609375,
0.51806640625,
0.296630859375,
-0.45556640625,
-0.1031494140625,
-0.292724609375,
-0.1962890625,
0.298828125,
1.32421875,
0.85595703125,
-0.115478515625,
0.0024662017822265625,
-0.90673828125,
-0.8076171875,
0.0521240234375,
-0.218017578125,
-0.5107421... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is a beginner programmer. He is studying how to use a command line.
Polycarp faced the following problem. There are n files in a directory and he needs to delete some of them. Polycarp wants to run a single delete command with filename pattern as an argument. All the files to be deleted should match the pattern and all other files shouldn't match the pattern.
Polycarp doesn't know about an asterisk '*', the only special character he knows is a question mark '?' which matches any single character. All other characters in the pattern match themselves only.
Formally, a pattern matches a filename if and only if they have equal lengths and all characters in the corresponding positions are equal except when the character in the pattern is '?', in which case the corresponding filename character does not matter.
For example, the filename pattern "a?ba?":
* matches filenames "aabaa", "abba.", "a.ba9" and "a.ba.";
* does not match filenames "aaba", "abaab", "aabaaa" and "aabaa.".
Help Polycarp find a pattern which matches files to be deleted and only them or report if there is no such pattern.
Input
The first line of the input contains two integers n and m (1 β€ m β€ n β€ 100) β the total number of files and the number of files to be deleted.
The following n lines contain filenames, single filename per line. All filenames are non-empty strings containing only lowercase English letters, digits and dots ('.'). The length of each filename doesn't exceed 100. It is guaranteed that all filenames are distinct.
The last line of the input contains m distinct integer numbers in ascending order a1, a2, ..., am (1 β€ ai β€ n) β indices of files to be deleted. All files are indexed from 1 to n in order of their appearance in the input.
Output
If the required pattern exists, print "Yes" in the first line of the output. The second line should contain the required pattern. If there are multiple solutions, print any of them.
If the required pattern doesn't exist, print the only line containing "No".
Examples
Input
3 2
ab
ac
cd
1 2
Output
Yes
a?
Input
5 3
test
tezt
test.
.est
tes.
1 4 5
Output
Yes
?es?
Input
4 4
a
b
c
dd
1 2 3 4
Output
No
Input
6 3
.svn
.git
....
...
..
.
1 2 3
Output
Yes
.???
Submitted Solution:
```
def delete():
num_file,num_delete = map(int, input().split())
list_file = []
for i in range(num_file):
list_file.append(input())
delete_file = [int(i)-1 for i in input().split()]
ans=[]
delete_list = sorted([list_file[i]for i in delete_file],key=len)
## print(delete_list)
tmp = list(delete_list[0])
for i in delete_list[1:]:
name = list(i)
if len(tmp) != len(i):
ans.append(tmp)
tmp=list(i)
for j in range(len(tmp)):
if name[j] != tmp[j]:
tmp[j] = "?"
ans.append(tmp)
## print(ans)
for i in []+ans:
tmp = i[0]
p = 1
for j in i:
if tmp != j:
p=0
if p or all([i!='?' for j in i]):
ans.remove(i)
if len(ans) == 0:
print("No")
else:
print("Yes")
zzz = ""
for i in ans:
for c in i:
zzz+=c
zzz+=" "
print(zzz[:-1])
delete()
```
No
| 65,311 | [
0.5302734375,
0.230224609375,
0.51806640625,
0.296630859375,
-0.45556640625,
-0.1031494140625,
-0.292724609375,
-0.1962890625,
0.298828125,
1.32421875,
0.85595703125,
-0.115478515625,
0.0024662017822265625,
-0.90673828125,
-0.8076171875,
0.0521240234375,
-0.218017578125,
-0.5107421... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is a beginner programmer. He is studying how to use a command line.
Polycarp faced the following problem. There are n files in a directory and he needs to delete some of them. Polycarp wants to run a single delete command with filename pattern as an argument. All the files to be deleted should match the pattern and all other files shouldn't match the pattern.
Polycarp doesn't know about an asterisk '*', the only special character he knows is a question mark '?' which matches any single character. All other characters in the pattern match themselves only.
Formally, a pattern matches a filename if and only if they have equal lengths and all characters in the corresponding positions are equal except when the character in the pattern is '?', in which case the corresponding filename character does not matter.
For example, the filename pattern "a?ba?":
* matches filenames "aabaa", "abba.", "a.ba9" and "a.ba.";
* does not match filenames "aaba", "abaab", "aabaaa" and "aabaa.".
Help Polycarp find a pattern which matches files to be deleted and only them or report if there is no such pattern.
Input
The first line of the input contains two integers n and m (1 β€ m β€ n β€ 100) β the total number of files and the number of files to be deleted.
The following n lines contain filenames, single filename per line. All filenames are non-empty strings containing only lowercase English letters, digits and dots ('.'). The length of each filename doesn't exceed 100. It is guaranteed that all filenames are distinct.
The last line of the input contains m distinct integer numbers in ascending order a1, a2, ..., am (1 β€ ai β€ n) β indices of files to be deleted. All files are indexed from 1 to n in order of their appearance in the input.
Output
If the required pattern exists, print "Yes" in the first line of the output. The second line should contain the required pattern. If there are multiple solutions, print any of them.
If the required pattern doesn't exist, print the only line containing "No".
Examples
Input
3 2
ab
ac
cd
1 2
Output
Yes
a?
Input
5 3
test
tezt
test.
.est
tes.
1 4 5
Output
Yes
?es?
Input
4 4
a
b
c
dd
1 2 3 4
Output
No
Input
6 3
.svn
.git
....
...
..
.
1 2 3
Output
Yes
.???
Submitted Solution:
```
def delete():
num_file,num_delete = map(int, input().split())
list_file = []
for i in range(num_file):
list_file.append(input())
delete_file = [int(i)-1 for i in input().split()]
ans=[]
delete_list = sorted([list_file[i]for i in delete_file],key=len)
## print(delete_list)
tmp = list(delete_list[0])
for i in delete_list[1:]:
name = list(i)
if len(tmp) != len(i):
ans.append(tmp)
tmp=list(i)
for j in range(len(tmp)):
if name[j] != tmp[j]:
tmp[j] = "?"
ans.append(tmp)
## print(ans)
for i in []+ans:
tmp = i[0]
p = 1
for j in i:
if tmp != j:
p=0
if p:
ans.remove(i)
if len(ans) == 0:
print("No")
else:
print("Yes")
for i in ans:
for c in i:
print(c,end="")
print()
delete()
```
No
| 65,312 | [
0.5302734375,
0.230224609375,
0.51806640625,
0.296630859375,
-0.45556640625,
-0.1031494140625,
-0.292724609375,
-0.1962890625,
0.298828125,
1.32421875,
0.85595703125,
-0.115478515625,
0.0024662017822265625,
-0.90673828125,
-0.8076171875,
0.0521240234375,
-0.218017578125,
-0.5107421... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp's workday lasts exactly n minutes. He loves chocolate bars and can eat one bar in one minute. Today Polycarp has k bars at the beginning of the workday.
In some minutes of the workday Polycarp has important things to do and in such minutes he is not able to eat a chocolate bar. In other minutes he can either eat or not eat one chocolate bar. It is guaranteed, that in the first and in the last minutes of the workday Polycarp has no important things to do and he will always eat bars in this minutes to gladden himself at the begining and at the end of the workday. Also it is guaranteed, that k is strictly greater than 1.
Your task is to determine such an order of eating chocolate bars that the maximum break time between eating bars is as minimum as possible.
Consider that Polycarp eats a bar in the minute x and the next bar in the minute y (x < y). Then the break time is equal to y - x - 1 minutes. It is not necessary for Polycarp to eat all bars he has.
Input
The first line contains two integers n and k (2 β€ n β€ 200 000, 2 β€ k β€ n) β the length of the workday in minutes and the number of chocolate bars, which Polycarp has in the beginning of the workday.
The second line contains the string with length n consisting of zeros and ones. If the i-th symbol in the string equals to zero, Polycarp has no important things to do in the minute i and he can eat a chocolate bar. In the other case, Polycarp is busy in the minute i and can not eat a chocolate bar. It is guaranteed, that the first and the last characters of the string are equal to zero, and Polycarp always eats chocolate bars in these minutes.
Output
Print the minimum possible break in minutes between eating chocolate bars.
Examples
Input
3 3
010
Output
1
Input
8 3
01010110
Output
3
Note
In the first example Polycarp can not eat the chocolate bar in the second minute, so the time of the break equals to one minute.
In the second example Polycarp will eat bars in the minutes 1 and 8 anyway, also he needs to eat the chocolate bar in the minute 5, so that the time of the maximum break will be equal to 3 minutes.
Tags: *special, binary search
Correct Solution:
```
n, k = map(int, input().split())
s = input()
l, r = int(-1), int(n)
while r - l > 1:
m = (l+r)//2
c, p = 1, 0
cond = True
while p < n and c < k:
i = p + m + 1
while i >= p and (i >= n or s[i] == '1'):
i = i - 1;
if (i == p):
break
c = c + 1
p = i
cond = cond and (p == n-1)
if cond:
r = m
else:
l = m
print(int(r))
```
| 65,329 | [
0.576171875,
0.12115478515625,
0.1724853515625,
0.361083984375,
-0.375244140625,
-0.339599609375,
-0.1966552734375,
0.08099365234375,
0.18359375,
0.9443359375,
0.78369140625,
-0.04217529296875,
0.456298828125,
-0.89892578125,
-0.47412109375,
0.0005931854248046875,
-0.39990234375,
-... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp's workday lasts exactly n minutes. He loves chocolate bars and can eat one bar in one minute. Today Polycarp has k bars at the beginning of the workday.
In some minutes of the workday Polycarp has important things to do and in such minutes he is not able to eat a chocolate bar. In other minutes he can either eat or not eat one chocolate bar. It is guaranteed, that in the first and in the last minutes of the workday Polycarp has no important things to do and he will always eat bars in this minutes to gladden himself at the begining and at the end of the workday. Also it is guaranteed, that k is strictly greater than 1.
Your task is to determine such an order of eating chocolate bars that the maximum break time between eating bars is as minimum as possible.
Consider that Polycarp eats a bar in the minute x and the next bar in the minute y (x < y). Then the break time is equal to y - x - 1 minutes. It is not necessary for Polycarp to eat all bars he has.
Input
The first line contains two integers n and k (2 β€ n β€ 200 000, 2 β€ k β€ n) β the length of the workday in minutes and the number of chocolate bars, which Polycarp has in the beginning of the workday.
The second line contains the string with length n consisting of zeros and ones. If the i-th symbol in the string equals to zero, Polycarp has no important things to do in the minute i and he can eat a chocolate bar. In the other case, Polycarp is busy in the minute i and can not eat a chocolate bar. It is guaranteed, that the first and the last characters of the string are equal to zero, and Polycarp always eats chocolate bars in these minutes.
Output
Print the minimum possible break in minutes between eating chocolate bars.
Examples
Input
3 3
010
Output
1
Input
8 3
01010110
Output
3
Note
In the first example Polycarp can not eat the chocolate bar in the second minute, so the time of the break equals to one minute.
In the second example Polycarp will eat bars in the minutes 1 and 8 anyway, also he needs to eat the chocolate bar in the minute 5, so that the time of the maximum break will be equal to 3 minutes.
Tags: *special, binary search
Correct Solution:
```
import sys
from math import *
from fractions import gcd
from random import * # randint(inclusive,inclusive)
readints=lambda:map(int, input().strip('\n').split())
from itertools import permutations, combinations
s = "abcdefghijklmnopqrstuvwxyz"
# print('', end=" ")
# for i in {1..5}; do echo "hi"; done
n,k=readints()
s=input()
g=[0]*n
for i in range(n):
if s[i]=='0':
g[i]=i
else:
g[i]=g[i-1]
def f(hop):
at=0
used=0
while used<k-2 and at+hop<n:
to=g[at+hop]
if to==at:
break
used+=1
at=to
if n-1-at>hop:
return False
return True
lo=-1
hi=n+1
while hi-lo>1:
mid=(lo+hi)//2
if f(mid):
hi=mid
else:
lo=mid
print(hi-1)
```
| 65,330 | [
0.576171875,
0.12115478515625,
0.1724853515625,
0.361083984375,
-0.375244140625,
-0.339599609375,
-0.1966552734375,
0.08099365234375,
0.18359375,
0.9443359375,
0.78369140625,
-0.04217529296875,
0.456298828125,
-0.89892578125,
-0.47412109375,
0.0005931854248046875,
-0.39990234375,
-... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp's workday lasts exactly n minutes. He loves chocolate bars and can eat one bar in one minute. Today Polycarp has k bars at the beginning of the workday.
In some minutes of the workday Polycarp has important things to do and in such minutes he is not able to eat a chocolate bar. In other minutes he can either eat or not eat one chocolate bar. It is guaranteed, that in the first and in the last minutes of the workday Polycarp has no important things to do and he will always eat bars in this minutes to gladden himself at the begining and at the end of the workday. Also it is guaranteed, that k is strictly greater than 1.
Your task is to determine such an order of eating chocolate bars that the maximum break time between eating bars is as minimum as possible.
Consider that Polycarp eats a bar in the minute x and the next bar in the minute y (x < y). Then the break time is equal to y - x - 1 minutes. It is not necessary for Polycarp to eat all bars he has.
Input
The first line contains two integers n and k (2 β€ n β€ 200 000, 2 β€ k β€ n) β the length of the workday in minutes and the number of chocolate bars, which Polycarp has in the beginning of the workday.
The second line contains the string with length n consisting of zeros and ones. If the i-th symbol in the string equals to zero, Polycarp has no important things to do in the minute i and he can eat a chocolate bar. In the other case, Polycarp is busy in the minute i and can not eat a chocolate bar. It is guaranteed, that the first and the last characters of the string are equal to zero, and Polycarp always eats chocolate bars in these minutes.
Output
Print the minimum possible break in minutes between eating chocolate bars.
Examples
Input
3 3
010
Output
1
Input
8 3
01010110
Output
3
Note
In the first example Polycarp can not eat the chocolate bar in the second minute, so the time of the break equals to one minute.
In the second example Polycarp will eat bars in the minutes 1 and 8 anyway, also he needs to eat the chocolate bar in the minute 5, so that the time of the maximum break will be equal to 3 minutes.
Tags: *special, binary search
Correct Solution:
```
def check(p):
cur = k - 2
p+=1
lastfree = 0
lasteat = 0
for i in range(1, n-1):
if tm[i] == '0':
lastfree = i
if i - lasteat >= p:
if lasteat == lastfree or cur <= 0:
return False
lasteat = lastfree
cur -= 1
return True
def bs(l, r):
while(l < r):
mid = (l + r) >> 1
if check(mid):
r = mid
else:
l = mid + 1
return l
n, k = map(int, input().split())
tm = input()
print(bs(0, n))
```
| 65,331 | [
0.576171875,
0.12115478515625,
0.1724853515625,
0.361083984375,
-0.375244140625,
-0.339599609375,
-0.1966552734375,
0.08099365234375,
0.18359375,
0.9443359375,
0.78369140625,
-0.04217529296875,
0.456298828125,
-0.89892578125,
-0.47412109375,
0.0005931854248046875,
-0.39990234375,
-... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp's workday lasts exactly n minutes. He loves chocolate bars and can eat one bar in one minute. Today Polycarp has k bars at the beginning of the workday.
In some minutes of the workday Polycarp has important things to do and in such minutes he is not able to eat a chocolate bar. In other minutes he can either eat or not eat one chocolate bar. It is guaranteed, that in the first and in the last minutes of the workday Polycarp has no important things to do and he will always eat bars in this minutes to gladden himself at the begining and at the end of the workday. Also it is guaranteed, that k is strictly greater than 1.
Your task is to determine such an order of eating chocolate bars that the maximum break time between eating bars is as minimum as possible.
Consider that Polycarp eats a bar in the minute x and the next bar in the minute y (x < y). Then the break time is equal to y - x - 1 minutes. It is not necessary for Polycarp to eat all bars he has.
Input
The first line contains two integers n and k (2 β€ n β€ 200 000, 2 β€ k β€ n) β the length of the workday in minutes and the number of chocolate bars, which Polycarp has in the beginning of the workday.
The second line contains the string with length n consisting of zeros and ones. If the i-th symbol in the string equals to zero, Polycarp has no important things to do in the minute i and he can eat a chocolate bar. In the other case, Polycarp is busy in the minute i and can not eat a chocolate bar. It is guaranteed, that the first and the last characters of the string are equal to zero, and Polycarp always eats chocolate bars in these minutes.
Output
Print the minimum possible break in minutes between eating chocolate bars.
Examples
Input
3 3
010
Output
1
Input
8 3
01010110
Output
3
Note
In the first example Polycarp can not eat the chocolate bar in the second minute, so the time of the break equals to one minute.
In the second example Polycarp will eat bars in the minutes 1 and 8 anyway, also he needs to eat the chocolate bar in the minute 5, so that the time of the maximum break will be equal to 3 minutes.
Tags: *special, binary search
Correct Solution:
```
from sys import exit
n=0
k=0
s=""
for i in input().split():
if n==0:
n=int(i)
else:
k=int(i)
s=str(input())
node=[]
for i in range(len(s)):
if s[int(i)]=='0':
node.append(i+1)
node.append(1000000000)
def check(dis):
current=0
num=k-2
for i in range(len(node)-1):
if num<1:
break
if node[i]-node[current]<=dis and node[i+1]-node[current]>dis:
current=i
num-=1
if n-node[current]>dis:
return -1
return 1
left=1
right=n
while left+1<right:
mid=int((left+right)/2)
t=check(mid)
if t==1:
right=mid
else:
left=mid
for i in range(left,right+1):
if check(i)==1:
print(i-1)
exit(0)
print(0)
```
| 65,332 | [
0.576171875,
0.12115478515625,
0.1724853515625,
0.361083984375,
-0.375244140625,
-0.339599609375,
-0.1966552734375,
0.08099365234375,
0.18359375,
0.9443359375,
0.78369140625,
-0.04217529296875,
0.456298828125,
-0.89892578125,
-0.47412109375,
0.0005931854248046875,
-0.39990234375,
-... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp's workday lasts exactly n minutes. He loves chocolate bars and can eat one bar in one minute. Today Polycarp has k bars at the beginning of the workday.
In some minutes of the workday Polycarp has important things to do and in such minutes he is not able to eat a chocolate bar. In other minutes he can either eat or not eat one chocolate bar. It is guaranteed, that in the first and in the last minutes of the workday Polycarp has no important things to do and he will always eat bars in this minutes to gladden himself at the begining and at the end of the workday. Also it is guaranteed, that k is strictly greater than 1.
Your task is to determine such an order of eating chocolate bars that the maximum break time between eating bars is as minimum as possible.
Consider that Polycarp eats a bar in the minute x and the next bar in the minute y (x < y). Then the break time is equal to y - x - 1 minutes. It is not necessary for Polycarp to eat all bars he has.
Input
The first line contains two integers n and k (2 β€ n β€ 200 000, 2 β€ k β€ n) β the length of the workday in minutes and the number of chocolate bars, which Polycarp has in the beginning of the workday.
The second line contains the string with length n consisting of zeros and ones. If the i-th symbol in the string equals to zero, Polycarp has no important things to do in the minute i and he can eat a chocolate bar. In the other case, Polycarp is busy in the minute i and can not eat a chocolate bar. It is guaranteed, that the first and the last characters of the string are equal to zero, and Polycarp always eats chocolate bars in these minutes.
Output
Print the minimum possible break in minutes between eating chocolate bars.
Examples
Input
3 3
010
Output
1
Input
8 3
01010110
Output
3
Note
In the first example Polycarp can not eat the chocolate bar in the second minute, so the time of the break equals to one minute.
In the second example Polycarp will eat bars in the minutes 1 and 8 anyway, also he needs to eat the chocolate bar in the minute 5, so that the time of the maximum break will be equal to 3 minutes.
Tags: *special, binary search
Correct Solution:
```
import sys
from math import *
from fractions import gcd
from random import * # randint(inclusive,inclusive)
readints=lambda:map(int, input().strip('\n').split())
from itertools import permutations, combinations
s = "abcdefghijklmnopqrstuvwxyz"
# print('', end=" ")
# for i in {1..5}; do echo "hi"; done
n,k=readints()
s=input()
lo=-1
hi=n+1
def test(x):
have=k-1
last=0
arr=[]
for i in range(n):
if s[i]=='0':
arr.append(i)
arr.append(10**9)
for i in range(1,len(arr)):
if arr[i]-last-1>x:
if arr[i-1]==last:
return False
if have==0:
return False
if arr[i-1]-last-1>x:
return False
last=arr[i-1]
have-=1
return True
while hi-lo>1:
mid=(lo+hi)//2
if test(mid):
hi=mid
else:
lo=mid
print(hi)
```
| 65,333 | [
0.576171875,
0.12115478515625,
0.1724853515625,
0.361083984375,
-0.375244140625,
-0.339599609375,
-0.1966552734375,
0.08099365234375,
0.18359375,
0.9443359375,
0.78369140625,
-0.04217529296875,
0.456298828125,
-0.89892578125,
-0.47412109375,
0.0005931854248046875,
-0.39990234375,
-... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp's workday lasts exactly n minutes. He loves chocolate bars and can eat one bar in one minute. Today Polycarp has k bars at the beginning of the workday.
In some minutes of the workday Polycarp has important things to do and in such minutes he is not able to eat a chocolate bar. In other minutes he can either eat or not eat one chocolate bar. It is guaranteed, that in the first and in the last minutes of the workday Polycarp has no important things to do and he will always eat bars in this minutes to gladden himself at the begining and at the end of the workday. Also it is guaranteed, that k is strictly greater than 1.
Your task is to determine such an order of eating chocolate bars that the maximum break time between eating bars is as minimum as possible.
Consider that Polycarp eats a bar in the minute x and the next bar in the minute y (x < y). Then the break time is equal to y - x - 1 minutes. It is not necessary for Polycarp to eat all bars he has.
Input
The first line contains two integers n and k (2 β€ n β€ 200 000, 2 β€ k β€ n) β the length of the workday in minutes and the number of chocolate bars, which Polycarp has in the beginning of the workday.
The second line contains the string with length n consisting of zeros and ones. If the i-th symbol in the string equals to zero, Polycarp has no important things to do in the minute i and he can eat a chocolate bar. In the other case, Polycarp is busy in the minute i and can not eat a chocolate bar. It is guaranteed, that the first and the last characters of the string are equal to zero, and Polycarp always eats chocolate bars in these minutes.
Output
Print the minimum possible break in minutes between eating chocolate bars.
Examples
Input
3 3
010
Output
1
Input
8 3
01010110
Output
3
Note
In the first example Polycarp can not eat the chocolate bar in the second minute, so the time of the break equals to one minute.
In the second example Polycarp will eat bars in the minutes 1 and 8 anyway, also he needs to eat the chocolate bar in the minute 5, so that the time of the maximum break will be equal to 3 minutes.
Tags: *special, binary search
Correct Solution:
```
import sys
from math import *
from fractions import gcd
from random import * # randint(inclusive,inclusive)
readints=lambda:map(int, input().strip('\n').split())
from itertools import permutations, combinations
s = "abcdefghijklmnopqrstuvwxyz"
# print('', end=" ")
# for i in {1..5}; do echo "hi"; done
n,k=readints()
s=input()
lo=-1
hi=n+1
hop = [0]*n
for i in range(n):
if s[i]=='0':
hop[i]=i
else:
hop[i]=hop[i-1]
def test(jump):
at=0
used=0
while used < k-2:
if at+jump<n:
to = hop[at+jump]
if to == at:
break
at = to
used += 1
else:
break
if n-1-at>jump:
return False
return True
while hi-lo>1:
mid=(lo+hi)//2
if test(mid):
hi=mid
else:
lo=mid
print(hi-1)
```
| 65,334 | [
0.576171875,
0.12115478515625,
0.1724853515625,
0.361083984375,
-0.375244140625,
-0.339599609375,
-0.1966552734375,
0.08099365234375,
0.18359375,
0.9443359375,
0.78369140625,
-0.04217529296875,
0.456298828125,
-0.89892578125,
-0.47412109375,
0.0005931854248046875,
-0.39990234375,
-... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp's workday lasts exactly n minutes. He loves chocolate bars and can eat one bar in one minute. Today Polycarp has k bars at the beginning of the workday.
In some minutes of the workday Polycarp has important things to do and in such minutes he is not able to eat a chocolate bar. In other minutes he can either eat or not eat one chocolate bar. It is guaranteed, that in the first and in the last minutes of the workday Polycarp has no important things to do and he will always eat bars in this minutes to gladden himself at the begining and at the end of the workday. Also it is guaranteed, that k is strictly greater than 1.
Your task is to determine such an order of eating chocolate bars that the maximum break time between eating bars is as minimum as possible.
Consider that Polycarp eats a bar in the minute x and the next bar in the minute y (x < y). Then the break time is equal to y - x - 1 minutes. It is not necessary for Polycarp to eat all bars he has.
Input
The first line contains two integers n and k (2 β€ n β€ 200 000, 2 β€ k β€ n) β the length of the workday in minutes and the number of chocolate bars, which Polycarp has in the beginning of the workday.
The second line contains the string with length n consisting of zeros and ones. If the i-th symbol in the string equals to zero, Polycarp has no important things to do in the minute i and he can eat a chocolate bar. In the other case, Polycarp is busy in the minute i and can not eat a chocolate bar. It is guaranteed, that the first and the last characters of the string are equal to zero, and Polycarp always eats chocolate bars in these minutes.
Output
Print the minimum possible break in minutes between eating chocolate bars.
Examples
Input
3 3
010
Output
1
Input
8 3
01010110
Output
3
Note
In the first example Polycarp can not eat the chocolate bar in the second minute, so the time of the break equals to one minute.
In the second example Polycarp will eat bars in the minutes 1 and 8 anyway, also he needs to eat the chocolate bar in the minute 5, so that the time of the maximum break will be equal to 3 minutes.
Tags: *special, binary search
Correct Solution:
```
import sys
from math import *
from fractions import gcd
from random import * # randint(inclusive,inclusive)
readints=lambda:map(int, input().strip('\n').split())
from itertools import permutations, combinations
s = "abcdefghijklmnopqrstuvwxyz"
# print('', end=" ")
# for i in {1..5}; do echo "hi"; done
n,k=readints()
s=input()
g=[0]*n
for i in range(n):
if s[i]=='0':
g[i]=i
else:
g[i]=g[i-1]
def f(hop):
at=0
used=0
while used<k-2 and n-1-at>hop:
to=g[at+hop]
if to==at:
break
used+=1
at=to
if n-1-at>hop:
return False
return True
lo=-1
hi=n+1
while hi-lo>1:
mid=(lo+hi)//2
if f(mid):
hi=mid
else:
lo=mid
print(hi-1)
```
| 65,335 | [
0.576171875,
0.12115478515625,
0.1724853515625,
0.361083984375,
-0.375244140625,
-0.339599609375,
-0.1966552734375,
0.08099365234375,
0.18359375,
0.9443359375,
0.78369140625,
-0.04217529296875,
0.456298828125,
-0.89892578125,
-0.47412109375,
0.0005931854248046875,
-0.39990234375,
-... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp's workday lasts exactly n minutes. He loves chocolate bars and can eat one bar in one minute. Today Polycarp has k bars at the beginning of the workday.
In some minutes of the workday Polycarp has important things to do and in such minutes he is not able to eat a chocolate bar. In other minutes he can either eat or not eat one chocolate bar. It is guaranteed, that in the first and in the last minutes of the workday Polycarp has no important things to do and he will always eat bars in this minutes to gladden himself at the begining and at the end of the workday. Also it is guaranteed, that k is strictly greater than 1.
Your task is to determine such an order of eating chocolate bars that the maximum break time between eating bars is as minimum as possible.
Consider that Polycarp eats a bar in the minute x and the next bar in the minute y (x < y). Then the break time is equal to y - x - 1 minutes. It is not necessary for Polycarp to eat all bars he has.
Input
The first line contains two integers n and k (2 β€ n β€ 200 000, 2 β€ k β€ n) β the length of the workday in minutes and the number of chocolate bars, which Polycarp has in the beginning of the workday.
The second line contains the string with length n consisting of zeros and ones. If the i-th symbol in the string equals to zero, Polycarp has no important things to do in the minute i and he can eat a chocolate bar. In the other case, Polycarp is busy in the minute i and can not eat a chocolate bar. It is guaranteed, that the first and the last characters of the string are equal to zero, and Polycarp always eats chocolate bars in these minutes.
Output
Print the minimum possible break in minutes between eating chocolate bars.
Examples
Input
3 3
010
Output
1
Input
8 3
01010110
Output
3
Note
In the first example Polycarp can not eat the chocolate bar in the second minute, so the time of the break equals to one minute.
In the second example Polycarp will eat bars in the minutes 1 and 8 anyway, also he needs to eat the chocolate bar in the minute 5, so that the time of the maximum break will be equal to 3 minutes.
Tags: *special, binary search
Correct Solution:
```
def ok(x, k, s, n):
i = 0
k-=1
while i < len(s):
if(i + x + 1 >= len(s)):
k -= 1
#print(len(s) - 1)
break
j = n[i + x + 1]
if(j == i):
return 0
i = j
#print(i)
k -= 1
if i == len(s) - 1:
break
#print(k)
return k >= 0
n, k = map(int, input().split())
s = input()
n = [0]
for i in range(1, len(s)):
if s[i] == '0':
n.append(i)
else:
n.append(n[-1])
#print(ok(2, k, s, n))
#exit(0)
l = -1
r = len(s)
while r - l > 1:
m = (l + r)//2
if ok(m, k, s, n):
r = m
else:
l = m
print(r)
```
| 65,336 | [
0.576171875,
0.12115478515625,
0.1724853515625,
0.361083984375,
-0.375244140625,
-0.339599609375,
-0.1966552734375,
0.08099365234375,
0.18359375,
0.9443359375,
0.78369140625,
-0.04217529296875,
0.456298828125,
-0.89892578125,
-0.47412109375,
0.0005931854248046875,
-0.39990234375,
-... | 24 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.