text stringlengths 198 433k | conversation_id int64 0 109k |
|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
Nicholas has an array a that contains n distinct integers from 1 to n. In other words, Nicholas has a permutation of size n.
Nicholas want the minimum element (integer 1) and the maximum element (integer n) to be as far as possible from each other. He wants to perform exactly one swap in order to maximize the distance between the minimum and the maximum elements. The distance between two elements is considered to be equal to the absolute difference between their positions.
Input
The first line of the input contains a single integer n (2 β€ n β€ 100) β the size of the permutation.
The second line of the input contains n distinct integers a1, a2, ..., an (1 β€ ai β€ n), where ai is equal to the element at the i-th position.
Output
Print a single integer β the maximum possible distance between the minimum and the maximum elements Nicholas can achieve by performing exactly one swap.
Examples
Input
5
4 5 1 3 2
Output
3
Input
7
1 6 5 3 4 7 2
Output
6
Input
6
6 5 4 3 2 1
Output
5
Note
In the first sample, one may obtain the optimal answer by swapping elements 1 and 2.
In the second sample, the minimum and the maximum elements will be located in the opposite ends of the array if we swap 7 and 2.
In the third sample, the distance between the minimum and the maximum elements is already maximum possible, so we just perform some unnecessary swap, for example, one can swap 5 and 2.
Tags: constructive algorithms, implementation
Correct Solution:
```
n=int(input())
l=list(map(int,input().split()))
i,j=l.index(1),l.index(n)
print(max(i,j,n-i-1,n-j-1))
```
| 104,900 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Nicholas has an array a that contains n distinct integers from 1 to n. In other words, Nicholas has a permutation of size n.
Nicholas want the minimum element (integer 1) and the maximum element (integer n) to be as far as possible from each other. He wants to perform exactly one swap in order to maximize the distance between the minimum and the maximum elements. The distance between two elements is considered to be equal to the absolute difference between their positions.
Input
The first line of the input contains a single integer n (2 β€ n β€ 100) β the size of the permutation.
The second line of the input contains n distinct integers a1, a2, ..., an (1 β€ ai β€ n), where ai is equal to the element at the i-th position.
Output
Print a single integer β the maximum possible distance between the minimum and the maximum elements Nicholas can achieve by performing exactly one swap.
Examples
Input
5
4 5 1 3 2
Output
3
Input
7
1 6 5 3 4 7 2
Output
6
Input
6
6 5 4 3 2 1
Output
5
Note
In the first sample, one may obtain the optimal answer by swapping elements 1 and 2.
In the second sample, the minimum and the maximum elements will be located in the opposite ends of the array if we swap 7 and 2.
In the third sample, the distance between the minimum and the maximum elements is already maximum possible, so we just perform some unnecessary swap, for example, one can swap 5 and 2.
Tags: constructive algorithms, implementation
Correct Solution:
```
#!/usr/bin/python
# -*- coding: UTF-8 -*-
def main():
n = input()
a = input().split(" ")*1
num_1 = a.index('1') + 1
num_max = a.index(str(n)) + 1
max_len = 0
if (max_len < num_max - 1):
max_len = num_max - 1
if (max_len < num_1 - 1):
max_len = num_1 - 1
if (max_len < len(a) - num_max):
max_len = len(a) - num_max
if (max_len < len(a) - num_1):
max_len = len(a) - num_1
print(max_len)
if __name__ == "__main__":
main()
```
| 104,901 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Nicholas has an array a that contains n distinct integers from 1 to n. In other words, Nicholas has a permutation of size n.
Nicholas want the minimum element (integer 1) and the maximum element (integer n) to be as far as possible from each other. He wants to perform exactly one swap in order to maximize the distance between the minimum and the maximum elements. The distance between two elements is considered to be equal to the absolute difference between their positions.
Input
The first line of the input contains a single integer n (2 β€ n β€ 100) β the size of the permutation.
The second line of the input contains n distinct integers a1, a2, ..., an (1 β€ ai β€ n), where ai is equal to the element at the i-th position.
Output
Print a single integer β the maximum possible distance between the minimum and the maximum elements Nicholas can achieve by performing exactly one swap.
Examples
Input
5
4 5 1 3 2
Output
3
Input
7
1 6 5 3 4 7 2
Output
6
Input
6
6 5 4 3 2 1
Output
5
Note
In the first sample, one may obtain the optimal answer by swapping elements 1 and 2.
In the second sample, the minimum and the maximum elements will be located in the opposite ends of the array if we swap 7 and 2.
In the third sample, the distance between the minimum and the maximum elements is already maximum possible, so we just perform some unnecessary swap, for example, one can swap 5 and 2.
Tags: constructive algorithms, implementation
Correct Solution:
```
n = int(input())
a = [int(s) for s in input().split(' ')]
m = [a.index(1), a.index(n)]
print(max(max(m), n - min(m) - 1))
```
| 104,902 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Nicholas has an array a that contains n distinct integers from 1 to n. In other words, Nicholas has a permutation of size n.
Nicholas want the minimum element (integer 1) and the maximum element (integer n) to be as far as possible from each other. He wants to perform exactly one swap in order to maximize the distance between the minimum and the maximum elements. The distance between two elements is considered to be equal to the absolute difference between their positions.
Input
The first line of the input contains a single integer n (2 β€ n β€ 100) β the size of the permutation.
The second line of the input contains n distinct integers a1, a2, ..., an (1 β€ ai β€ n), where ai is equal to the element at the i-th position.
Output
Print a single integer β the maximum possible distance between the minimum and the maximum elements Nicholas can achieve by performing exactly one swap.
Examples
Input
5
4 5 1 3 2
Output
3
Input
7
1 6 5 3 4 7 2
Output
6
Input
6
6 5 4 3 2 1
Output
5
Note
In the first sample, one may obtain the optimal answer by swapping elements 1 and 2.
In the second sample, the minimum and the maximum elements will be located in the opposite ends of the array if we swap 7 and 2.
In the third sample, the distance between the minimum and the maximum elements is already maximum possible, so we just perform some unnecessary swap, for example, one can swap 5 and 2.
Tags: constructive algorithms, implementation
Correct Solution:
```
count=int(input());
a = [int(x) for x in input().split()];
lowIndex=a.index(1);
highIndex=a.index(count);
print(max(highIndex-0, lowIndex-0, (count-1)-lowIndex, (count-1)-highIndex));
```
| 104,903 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Nicholas has an array a that contains n distinct integers from 1 to n. In other words, Nicholas has a permutation of size n.
Nicholas want the minimum element (integer 1) and the maximum element (integer n) to be as far as possible from each other. He wants to perform exactly one swap in order to maximize the distance between the minimum and the maximum elements. The distance between two elements is considered to be equal to the absolute difference between their positions.
Input
The first line of the input contains a single integer n (2 β€ n β€ 100) β the size of the permutation.
The second line of the input contains n distinct integers a1, a2, ..., an (1 β€ ai β€ n), where ai is equal to the element at the i-th position.
Output
Print a single integer β the maximum possible distance between the minimum and the maximum elements Nicholas can achieve by performing exactly one swap.
Examples
Input
5
4 5 1 3 2
Output
3
Input
7
1 6 5 3 4 7 2
Output
6
Input
6
6 5 4 3 2 1
Output
5
Note
In the first sample, one may obtain the optimal answer by swapping elements 1 and 2.
In the second sample, the minimum and the maximum elements will be located in the opposite ends of the array if we swap 7 and 2.
In the third sample, the distance between the minimum and the maximum elements is already maximum possible, so we just perform some unnecessary swap, for example, one can swap 5 and 2.
Tags: constructive algorithms, implementation
Correct Solution:
```
n=int(input())
a=[int(i) for i in input().split()]
k,l=a.index(1),a.index(n)
print(max(k,l,n-k-1,n-l-1))
```
| 104,904 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Nicholas has an array a that contains n distinct integers from 1 to n. In other words, Nicholas has a permutation of size n.
Nicholas want the minimum element (integer 1) and the maximum element (integer n) to be as far as possible from each other. He wants to perform exactly one swap in order to maximize the distance between the minimum and the maximum elements. The distance between two elements is considered to be equal to the absolute difference between their positions.
Input
The first line of the input contains a single integer n (2 β€ n β€ 100) β the size of the permutation.
The second line of the input contains n distinct integers a1, a2, ..., an (1 β€ ai β€ n), where ai is equal to the element at the i-th position.
Output
Print a single integer β the maximum possible distance between the minimum and the maximum elements Nicholas can achieve by performing exactly one swap.
Examples
Input
5
4 5 1 3 2
Output
3
Input
7
1 6 5 3 4 7 2
Output
6
Input
6
6 5 4 3 2 1
Output
5
Note
In the first sample, one may obtain the optimal answer by swapping elements 1 and 2.
In the second sample, the minimum and the maximum elements will be located in the opposite ends of the array if we swap 7 and 2.
In the third sample, the distance between the minimum and the maximum elements is already maximum possible, so we just perform some unnecessary swap, for example, one can swap 5 and 2.
Tags: constructive algorithms, implementation
Correct Solution:
```
n = int(input())
A = [int(x) for x in input().split()]
a, b = A.index(1), A.index(n)
print(max(a, b, n - a - 1, n - b - 1))
```
| 104,905 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Nicholas has an array a that contains n distinct integers from 1 to n. In other words, Nicholas has a permutation of size n.
Nicholas want the minimum element (integer 1) and the maximum element (integer n) to be as far as possible from each other. He wants to perform exactly one swap in order to maximize the distance between the minimum and the maximum elements. The distance between two elements is considered to be equal to the absolute difference between their positions.
Input
The first line of the input contains a single integer n (2 β€ n β€ 100) β the size of the permutation.
The second line of the input contains n distinct integers a1, a2, ..., an (1 β€ ai β€ n), where ai is equal to the element at the i-th position.
Output
Print a single integer β the maximum possible distance between the minimum and the maximum elements Nicholas can achieve by performing exactly one swap.
Examples
Input
5
4 5 1 3 2
Output
3
Input
7
1 6 5 3 4 7 2
Output
6
Input
6
6 5 4 3 2 1
Output
5
Note
In the first sample, one may obtain the optimal answer by swapping elements 1 and 2.
In the second sample, the minimum and the maximum elements will be located in the opposite ends of the array if we swap 7 and 2.
In the third sample, the distance between the minimum and the maximum elements is already maximum possible, so we just perform some unnecessary swap, for example, one can swap 5 and 2.
Tags: constructive algorithms, implementation
Correct Solution:
```
n=int(input())
l=list(map(int,input().split()))
i1=l.index(min(l))
i2=l.index(max(l))
print(max((n-1-min(i1,i2)),(max(i1,i2))))
```
| 104,906 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Nicholas has an array a that contains n distinct integers from 1 to n. In other words, Nicholas has a permutation of size n.
Nicholas want the minimum element (integer 1) and the maximum element (integer n) to be as far as possible from each other. He wants to perform exactly one swap in order to maximize the distance between the minimum and the maximum elements. The distance between two elements is considered to be equal to the absolute difference between their positions.
Input
The first line of the input contains a single integer n (2 β€ n β€ 100) β the size of the permutation.
The second line of the input contains n distinct integers a1, a2, ..., an (1 β€ ai β€ n), where ai is equal to the element at the i-th position.
Output
Print a single integer β the maximum possible distance between the minimum and the maximum elements Nicholas can achieve by performing exactly one swap.
Examples
Input
5
4 5 1 3 2
Output
3
Input
7
1 6 5 3 4 7 2
Output
6
Input
6
6 5 4 3 2 1
Output
5
Note
In the first sample, one may obtain the optimal answer by swapping elements 1 and 2.
In the second sample, the minimum and the maximum elements will be located in the opposite ends of the array if we swap 7 and 2.
In the third sample, the distance between the minimum and the maximum elements is already maximum possible, so we just perform some unnecessary swap, for example, one can swap 5 and 2.
Submitted Solution:
```
n = int(input())
a = list(map(int, input().split()))
idx1 = a.index(1)
idxN = a.index(n)
if(idxN-idx1>0):
if(n-1-idxN>idx1-0):
ans = n-1-idx1
else:
ans = idxN
else:
if(n-1-idx1>idxN-0):
ans = n-1-idxN
else:
ans = idx1
print(ans)
```
Yes
| 104,907 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Nicholas has an array a that contains n distinct integers from 1 to n. In other words, Nicholas has a permutation of size n.
Nicholas want the minimum element (integer 1) and the maximum element (integer n) to be as far as possible from each other. He wants to perform exactly one swap in order to maximize the distance between the minimum and the maximum elements. The distance between two elements is considered to be equal to the absolute difference between their positions.
Input
The first line of the input contains a single integer n (2 β€ n β€ 100) β the size of the permutation.
The second line of the input contains n distinct integers a1, a2, ..., an (1 β€ ai β€ n), where ai is equal to the element at the i-th position.
Output
Print a single integer β the maximum possible distance between the minimum and the maximum elements Nicholas can achieve by performing exactly one swap.
Examples
Input
5
4 5 1 3 2
Output
3
Input
7
1 6 5 3 4 7 2
Output
6
Input
6
6 5 4 3 2 1
Output
5
Note
In the first sample, one may obtain the optimal answer by swapping elements 1 and 2.
In the second sample, the minimum and the maximum elements will be located in the opposite ends of the array if we swap 7 and 2.
In the third sample, the distance between the minimum and the maximum elements is already maximum possible, so we just perform some unnecessary swap, for example, one can swap 5 and 2.
Submitted Solution:
```
n = int(input())
data = list(map(int, input().split()))
indexmax = data.index(max(data))
indexmin = data.index(min(data))
print(max(indexmax, indexmin, n - indexmax - 1, n - indexmin - 1))
```
Yes
| 104,908 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Nicholas has an array a that contains n distinct integers from 1 to n. In other words, Nicholas has a permutation of size n.
Nicholas want the minimum element (integer 1) and the maximum element (integer n) to be as far as possible from each other. He wants to perform exactly one swap in order to maximize the distance between the minimum and the maximum elements. The distance between two elements is considered to be equal to the absolute difference between their positions.
Input
The first line of the input contains a single integer n (2 β€ n β€ 100) β the size of the permutation.
The second line of the input contains n distinct integers a1, a2, ..., an (1 β€ ai β€ n), where ai is equal to the element at the i-th position.
Output
Print a single integer β the maximum possible distance between the minimum and the maximum elements Nicholas can achieve by performing exactly one swap.
Examples
Input
5
4 5 1 3 2
Output
3
Input
7
1 6 5 3 4 7 2
Output
6
Input
6
6 5 4 3 2 1
Output
5
Note
In the first sample, one may obtain the optimal answer by swapping elements 1 and 2.
In the second sample, the minimum and the maximum elements will be located in the opposite ends of the array if we swap 7 and 2.
In the third sample, the distance between the minimum and the maximum elements is already maximum possible, so we just perform some unnecessary swap, for example, one can swap 5 and 2.
Submitted Solution:
```
n = int(input())
a = [int(x) for x in input().split()]
c1, c2 = -1, -1
for i in range(n):
if a[i] == 1:
c1 = i
if a[i] == n:
c2 = i
print(max(abs(c1 - c2), c1, c2, n - 1 - c1, n - 1 - c2))
```
Yes
| 104,909 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Nicholas has an array a that contains n distinct integers from 1 to n. In other words, Nicholas has a permutation of size n.
Nicholas want the minimum element (integer 1) and the maximum element (integer n) to be as far as possible from each other. He wants to perform exactly one swap in order to maximize the distance between the minimum and the maximum elements. The distance between two elements is considered to be equal to the absolute difference between their positions.
Input
The first line of the input contains a single integer n (2 β€ n β€ 100) β the size of the permutation.
The second line of the input contains n distinct integers a1, a2, ..., an (1 β€ ai β€ n), where ai is equal to the element at the i-th position.
Output
Print a single integer β the maximum possible distance between the minimum and the maximum elements Nicholas can achieve by performing exactly one swap.
Examples
Input
5
4 5 1 3 2
Output
3
Input
7
1 6 5 3 4 7 2
Output
6
Input
6
6 5 4 3 2 1
Output
5
Note
In the first sample, one may obtain the optimal answer by swapping elements 1 and 2.
In the second sample, the minimum and the maximum elements will be located in the opposite ends of the array if we swap 7 and 2.
In the third sample, the distance between the minimum and the maximum elements is already maximum possible, so we just perform some unnecessary swap, for example, one can swap 5 and 2.
Submitted Solution:
```
n = int(input())
arr = list(map(int, input().split()))
l, r = arr.index(min(arr)) + 1, arr.index(max(arr)) + 1
print(max(l - 1, r - 1, n - l, n - r))
```
Yes
| 104,910 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Nicholas has an array a that contains n distinct integers from 1 to n. In other words, Nicholas has a permutation of size n.
Nicholas want the minimum element (integer 1) and the maximum element (integer n) to be as far as possible from each other. He wants to perform exactly one swap in order to maximize the distance between the minimum and the maximum elements. The distance between two elements is considered to be equal to the absolute difference between their positions.
Input
The first line of the input contains a single integer n (2 β€ n β€ 100) β the size of the permutation.
The second line of the input contains n distinct integers a1, a2, ..., an (1 β€ ai β€ n), where ai is equal to the element at the i-th position.
Output
Print a single integer β the maximum possible distance between the minimum and the maximum elements Nicholas can achieve by performing exactly one swap.
Examples
Input
5
4 5 1 3 2
Output
3
Input
7
1 6 5 3 4 7 2
Output
6
Input
6
6 5 4 3 2 1
Output
5
Note
In the first sample, one may obtain the optimal answer by swapping elements 1 and 2.
In the second sample, the minimum and the maximum elements will be located in the opposite ends of the array if we swap 7 and 2.
In the third sample, the distance between the minimum and the maximum elements is already maximum possible, so we just perform some unnecessary swap, for example, one can swap 5 and 2.
Submitted Solution:
```
import math
n=int(input())
a=[int(i) for i in input().split()]
q=max(a)
w=min(a)
e=a.index(q)
d=a.index(w)
f=abs(e-d)
if(e>d):
count=f+(len(a)-1)-e
else:
count=f+(len(a)-1)-d
print(count)
```
No
| 104,911 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Nicholas has an array a that contains n distinct integers from 1 to n. In other words, Nicholas has a permutation of size n.
Nicholas want the minimum element (integer 1) and the maximum element (integer n) to be as far as possible from each other. He wants to perform exactly one swap in order to maximize the distance between the minimum and the maximum elements. The distance between two elements is considered to be equal to the absolute difference between their positions.
Input
The first line of the input contains a single integer n (2 β€ n β€ 100) β the size of the permutation.
The second line of the input contains n distinct integers a1, a2, ..., an (1 β€ ai β€ n), where ai is equal to the element at the i-th position.
Output
Print a single integer β the maximum possible distance between the minimum and the maximum elements Nicholas can achieve by performing exactly one swap.
Examples
Input
5
4 5 1 3 2
Output
3
Input
7
1 6 5 3 4 7 2
Output
6
Input
6
6 5 4 3 2 1
Output
5
Note
In the first sample, one may obtain the optimal answer by swapping elements 1 and 2.
In the second sample, the minimum and the maximum elements will be located in the opposite ends of the array if we swap 7 and 2.
In the third sample, the distance between the minimum and the maximum elements is already maximum possible, so we just perform some unnecessary swap, for example, one can swap 5 and 2.
Submitted Solution:
```
n = int(input())
A = list(map(int, input().split()))
min = 0
max = n-1
for i in range(n):
if A[i] > A[max]:
max = i
if A[i] < A[min]:
min = i
if min == 0 or min == n-1 or max == 0 or max == n-1:
print(n-1)
else:
distance = 0
if n-1-min > n-1-max:
distance = n-1-min
else:
distance = n-1-max
if min-0 > max-0:
distance = min-0
else:
distance = max-0
print(distance)
```
No
| 104,912 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Nicholas has an array a that contains n distinct integers from 1 to n. In other words, Nicholas has a permutation of size n.
Nicholas want the minimum element (integer 1) and the maximum element (integer n) to be as far as possible from each other. He wants to perform exactly one swap in order to maximize the distance between the minimum and the maximum elements. The distance between two elements is considered to be equal to the absolute difference between their positions.
Input
The first line of the input contains a single integer n (2 β€ n β€ 100) β the size of the permutation.
The second line of the input contains n distinct integers a1, a2, ..., an (1 β€ ai β€ n), where ai is equal to the element at the i-th position.
Output
Print a single integer β the maximum possible distance between the minimum and the maximum elements Nicholas can achieve by performing exactly one swap.
Examples
Input
5
4 5 1 3 2
Output
3
Input
7
1 6 5 3 4 7 2
Output
6
Input
6
6 5 4 3 2 1
Output
5
Note
In the first sample, one may obtain the optimal answer by swapping elements 1 and 2.
In the second sample, the minimum and the maximum elements will be located in the opposite ends of the array if we swap 7 and 2.
In the third sample, the distance between the minimum and the maximum elements is already maximum possible, so we just perform some unnecessary swap, for example, one can swap 5 and 2.
Submitted Solution:
```
n = int(input())
l = list(map(int, input().split()))
ma = l.index(max(l))
mi = l.index(min(l))
print(max(abs(ma-mi), abs(ma-mi+max(mi+1, n-ma-1))))
```
No
| 104,913 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Nicholas has an array a that contains n distinct integers from 1 to n. In other words, Nicholas has a permutation of size n.
Nicholas want the minimum element (integer 1) and the maximum element (integer n) to be as far as possible from each other. He wants to perform exactly one swap in order to maximize the distance between the minimum and the maximum elements. The distance between two elements is considered to be equal to the absolute difference between their positions.
Input
The first line of the input contains a single integer n (2 β€ n β€ 100) β the size of the permutation.
The second line of the input contains n distinct integers a1, a2, ..., an (1 β€ ai β€ n), where ai is equal to the element at the i-th position.
Output
Print a single integer β the maximum possible distance between the minimum and the maximum elements Nicholas can achieve by performing exactly one swap.
Examples
Input
5
4 5 1 3 2
Output
3
Input
7
1 6 5 3 4 7 2
Output
6
Input
6
6 5 4 3 2 1
Output
5
Note
In the first sample, one may obtain the optimal answer by swapping elements 1 and 2.
In the second sample, the minimum and the maximum elements will be located in the opposite ends of the array if we swap 7 and 2.
In the third sample, the distance between the minimum and the maximum elements is already maximum possible, so we just perform some unnecessary swap, for example, one can swap 5 and 2.
Submitted Solution:
```
n = int(input())
a = list(map(int, input().split()))
max_distance = 0
index_max = a.index(max(a))
index_min = a.index(min(a))
if index_min < index_max:
if index_min + 1 > n - index_max + 1:
a[0], a[index_min] = a[index_min], a[0]
else:
a[-1], a[index_max] = a[index_max], a[-1]
else:
if index_max + 1 > n - index_min + 1:
a[0], a[index_max] = a[index_max], a[0]
else:
a[-1], a[index_min] = a[index_min], a[-1]
index_max = a.index(max(a))
index_min = a.index(min(a))
print(max(index_max, index_min) - min(index_max, index_min))
```
No
| 104,914 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" β thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
Input
The first line contains a positive integer n (1 β€ n β€ 100), then follow n lines containing three integers each: the xi coordinate, the yi coordinate and the zi coordinate of the force vector, applied to the body ( - 100 β€ xi, yi, zi β€ 100).
Output
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
Examples
Input
3
4 1 7
-2 4 -1
1 -5 -3
Output
NO
Input
3
3 -1 7
-5 2 -4
2 -1 -3
Output
YES
Tags: implementation, math
Correct Solution:
```
n = int(input())
xx = 0
yy = 0
zz = 0
for i in range(0, n):
x, y, z = map(int, input().split())
xx += x
yy += y
zz += z
if (xx == 0 and yy == 0 and zz == 0):
print("YES")
else:
print("NO")
```
| 104,915 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" β thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
Input
The first line contains a positive integer n (1 β€ n β€ 100), then follow n lines containing three integers each: the xi coordinate, the yi coordinate and the zi coordinate of the force vector, applied to the body ( - 100 β€ xi, yi, zi β€ 100).
Output
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
Examples
Input
3
4 1 7
-2 4 -1
1 -5 -3
Output
NO
Input
3
3 -1 7
-5 2 -4
2 -1 -3
Output
YES
Tags: implementation, math
Correct Solution:
```
n=int(input())
y=map(sum,zip(*(map(int,input().split())for _ in range(n))))
print(('YES','NO')[any(y)])
```
| 104,916 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" β thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
Input
The first line contains a positive integer n (1 β€ n β€ 100), then follow n lines containing three integers each: the xi coordinate, the yi coordinate and the zi coordinate of the force vector, applied to the body ( - 100 β€ xi, yi, zi β€ 100).
Output
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
Examples
Input
3
4 1 7
-2 4 -1
1 -5 -3
Output
NO
Input
3
3 -1 7
-5 2 -4
2 -1 -3
Output
YES
Tags: implementation, math
Correct Solution:
```
n=int(input())
x,y,z=0,0,0
for i in range(0,n):
s=input().split(" ")
x+=int(s[0])
y+=int(s[1])
z+=int(s[2])
if(x==y==z==0):
print("YES")
else:
print("NO")
```
| 104,917 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" β thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
Input
The first line contains a positive integer n (1 β€ n β€ 100), then follow n lines containing three integers each: the xi coordinate, the yi coordinate and the zi coordinate of the force vector, applied to the body ( - 100 β€ xi, yi, zi β€ 100).
Output
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
Examples
Input
3
4 1 7
-2 4 -1
1 -5 -3
Output
NO
Input
3
3 -1 7
-5 2 -4
2 -1 -3
Output
YES
Tags: implementation, math
Correct Solution:
```
def inEquilibirum(list):
xsum = 0
ysum = 0
zsum = 0
for i in list:
xsum += i[0]
ysum += i[1]
zsum += i[2]
if (xsum == 0 and ysum == 0 and zsum == 0):
return True
return False
n = int(input(""))
forces = []
for i in range(0,n):
tuple = str(input(""))
coords = tuple.split(" ")
forces.append([int(coords[0]), int(coords[1]), int(coords[2]) ] )
equilibrium = inEquilibirum(forces)
output = "YES" if equilibrium == True else "NO"
print(output)
```
| 104,918 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" β thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
Input
The first line contains a positive integer n (1 β€ n β€ 100), then follow n lines containing three integers each: the xi coordinate, the yi coordinate and the zi coordinate of the force vector, applied to the body ( - 100 β€ xi, yi, zi β€ 100).
Output
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
Examples
Input
3
4 1 7
-2 4 -1
1 -5 -3
Output
NO
Input
3
3 -1 7
-5 2 -4
2 -1 -3
Output
YES
Tags: implementation, math
Correct Solution:
```
n = int(input())
force_s = [0, 0, 0]
for i in range(n):
coordinates = list(map(int, input().split(' ')))
force_s[0] += coordinates[0]
force_s[1] += coordinates[1]
force_s[2] += coordinates[2]
if force_s[0] == 0 and force_s[1] == 0 and force_s[2] == 0:
print('YES')
else:
print('NO')
```
| 104,919 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" β thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
Input
The first line contains a positive integer n (1 β€ n β€ 100), then follow n lines containing three integers each: the xi coordinate, the yi coordinate and the zi coordinate of the force vector, applied to the body ( - 100 β€ xi, yi, zi β€ 100).
Output
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
Examples
Input
3
4 1 7
-2 4 -1
1 -5 -3
Output
NO
Input
3
3 -1 7
-5 2 -4
2 -1 -3
Output
YES
Tags: implementation, math
Correct Solution:
```
n = int(input())
x = 0
y = 0
z = 0
for i in range(n):
k, l, m = map(int, input().split())
x += k
y += l
z += m
if x==0 and y == 0 and z == 0:
print('YES')
else:
print('NO')
```
| 104,920 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" β thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
Input
The first line contains a positive integer n (1 β€ n β€ 100), then follow n lines containing three integers each: the xi coordinate, the yi coordinate and the zi coordinate of the force vector, applied to the body ( - 100 β€ xi, yi, zi β€ 100).
Output
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
Examples
Input
3
4 1 7
-2 4 -1
1 -5 -3
Output
NO
Input
3
3 -1 7
-5 2 -4
2 -1 -3
Output
YES
Tags: implementation, math
Correct Solution:
```
def is_idle(n) :
x = []
y = []
z = []
for i in range(0, n) :
a, b, c = map(int,input().strip().split(" "))
x.append(a)
y.append(b)
z.append(c)
if sum(x) == 0 and sum(y) == 0 and sum(z) == 0 :
print("YES")
else :
print("NO")
n = int(input())
is_idle(n)
```
| 104,921 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" β thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
Input
The first line contains a positive integer n (1 β€ n β€ 100), then follow n lines containing three integers each: the xi coordinate, the yi coordinate and the zi coordinate of the force vector, applied to the body ( - 100 β€ xi, yi, zi β€ 100).
Output
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
Examples
Input
3
4 1 7
-2 4 -1
1 -5 -3
Output
NO
Input
3
3 -1 7
-5 2 -4
2 -1 -3
Output
YES
Tags: implementation, math
Correct Solution:
```
n = int(input())
mat = []
flag = 0
for i in range(n):
mat.append(list(map(int, input().split())))
for i in range(3):
s = 0
for j in range(n):
s += mat[j][i]
if s != 0:
flag = 1
break
if flag == 0:
print('YES')
else:
print('NO')
```
| 104,922 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" β thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
Input
The first line contains a positive integer n (1 β€ n β€ 100), then follow n lines containing three integers each: the xi coordinate, the yi coordinate and the zi coordinate of the force vector, applied to the body ( - 100 β€ xi, yi, zi β€ 100).
Output
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
Examples
Input
3
4 1 7
-2 4 -1
1 -5 -3
Output
NO
Input
3
3 -1 7
-5 2 -4
2 -1 -3
Output
YES
Submitted Solution:
```
count1,count2,count3=0,0,0
for i in [0]*int(input()):
a=[int(j) for j in input().split()]
count1+=a[0]
count2+=a[1]
count3+=a[2]
if (count1==0 and count2==0 and count3==0):
print('YES')
else:
print('NO')
```
Yes
| 104,923 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" β thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
Input
The first line contains a positive integer n (1 β€ n β€ 100), then follow n lines containing three integers each: the xi coordinate, the yi coordinate and the zi coordinate of the force vector, applied to the body ( - 100 β€ xi, yi, zi β€ 100).
Output
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
Examples
Input
3
4 1 7
-2 4 -1
1 -5 -3
Output
NO
Input
3
3 -1 7
-5 2 -4
2 -1 -3
Output
YES
Submitted Solution:
```
n=int(input())
sumi=0;sumj=0;sumk=0
while n>0:
i,j,k=map(int,input().split())
sumi+=i;sumj+=j;sumk+=k
n-=1
if sumi==0 and sumj==0 and sumk==0:
print("YES")
else:
print("NO")
```
Yes
| 104,924 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" β thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
Input
The first line contains a positive integer n (1 β€ n β€ 100), then follow n lines containing three integers each: the xi coordinate, the yi coordinate and the zi coordinate of the force vector, applied to the body ( - 100 β€ xi, yi, zi β€ 100).
Output
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
Examples
Input
3
4 1 7
-2 4 -1
1 -5 -3
Output
NO
Input
3
3 -1 7
-5 2 -4
2 -1 -3
Output
YES
Submitted Solution:
```
def resolve(matrix):
sum = [0, 0, 0]
for element in matrix:
sum[0] += element[0]
sum[1] += element[1]
sum[2] += element[2]
if sum[0] == 0 and sum[1] == 0 and sum[2] == 0:
return "YES"
else:
return "NO"
quant = int(input())
matrix = []
for i in range(quant):
matrix.append([int(i) for i in input().split(" ")])
print(resolve(matrix))
```
Yes
| 104,925 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" β thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
Input
The first line contains a positive integer n (1 β€ n β€ 100), then follow n lines containing three integers each: the xi coordinate, the yi coordinate and the zi coordinate of the force vector, applied to the body ( - 100 β€ xi, yi, zi β€ 100).
Output
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
Examples
Input
3
4 1 7
-2 4 -1
1 -5 -3
Output
NO
Input
3
3 -1 7
-5 2 -4
2 -1 -3
Output
YES
Submitted Solution:
```
n= int(input())
a=[]
b=[]
c=[]
for i in range(n):
x,y,z=input().split()
x,y,z=int(x),int(y),int(z)
a.append(x)
b.append(y)
c.append(z)
s1=0
s2=0
s3=0
for i in range(n):
s1+=a[i]
s2+=b[i]
s3+=c[i]
if (s1==0 and s2==0 and s3==0):
print("YES")
else:
print("NO")
```
Yes
| 104,926 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" β thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
Input
The first line contains a positive integer n (1 β€ n β€ 100), then follow n lines containing three integers each: the xi coordinate, the yi coordinate and the zi coordinate of the force vector, applied to the body ( - 100 β€ xi, yi, zi β€ 100).
Output
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
Examples
Input
3
4 1 7
-2 4 -1
1 -5 -3
Output
NO
Input
3
3 -1 7
-5 2 -4
2 -1 -3
Output
YES
Submitted Solution:
```
n = int(input())
l = []
for i in range(n):
x,y,z = map(int,input().split())
a = [x,y,z]
b = sum(a)
l.append(b)
if (sum(l)==0):
print("YES")
else:
print("NO")
```
No
| 104,927 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" β thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
Input
The first line contains a positive integer n (1 β€ n β€ 100), then follow n lines containing three integers each: the xi coordinate, the yi coordinate and the zi coordinate of the force vector, applied to the body ( - 100 β€ xi, yi, zi β€ 100).
Output
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
Examples
Input
3
4 1 7
-2 4 -1
1 -5 -3
Output
NO
Input
3
3 -1 7
-5 2 -4
2 -1 -3
Output
YES
Submitted Solution:
```
n=int(input())
x=0
y=0
z=0
for i in range (n):
a,b,c=map(int,input().split())
x+=a
y+=b
z+=c
if (a==0) and (b==0) and (c==0):
print('YES')
else:
print('NO')
```
No
| 104,928 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" β thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
Input
The first line contains a positive integer n (1 β€ n β€ 100), then follow n lines containing three integers each: the xi coordinate, the yi coordinate and the zi coordinate of the force vector, applied to the body ( - 100 β€ xi, yi, zi β€ 100).
Output
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
Examples
Input
3
4 1 7
-2 4 -1
1 -5 -3
Output
NO
Input
3
3 -1 7
-5 2 -4
2 -1 -3
Output
YES
Submitted Solution:
```
quantity = int(input())
array = []
for i in range(quantity):
x = input().split()
x = list(map(int, x))
array.append(x)
answer = 0
for valores in array:
answer += sum(valores)
if answer == 0:
print('YES')
else:
print('NO')
```
No
| 104,929 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" β thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
Input
The first line contains a positive integer n (1 β€ n β€ 100), then follow n lines containing three integers each: the xi coordinate, the yi coordinate and the zi coordinate of the force vector, applied to the body ( - 100 β€ xi, yi, zi β€ 100).
Output
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
Examples
Input
3
4 1 7
-2 4 -1
1 -5 -3
Output
NO
Input
3
3 -1 7
-5 2 -4
2 -1 -3
Output
YES
Submitted Solution:
```
def Sum_Force(x,y,z):
for i in range(len(x)):
if int(x[i]) + int(y[i]) + int(z[i]) != 0:
print('NO')
return
print('YES')
n = input()
x = input()
y = input()
z = input()
x = x.split()
y = y.split()
z = z.split()
Sum_Force(x,y,z)
```
No
| 104,930 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There exists an island called Arpaβs land, some beautiful girls live there, as ugly ones do.
Mehrdad wants to become minister of Arpaβs land. Arpa has prepared an exam. Exam has only one question, given n, print the last digit of 1378n.
<image>
Mehrdad has become quite confused and wants you to help him. Please help, although it's a naive cheat.
Input
The single line of input contains one integer n (0 β€ n β€ 109).
Output
Print single integer β the last digit of 1378n.
Examples
Input
1
Output
8
Input
2
Output
4
Note
In the first example, last digit of 13781 = 1378 is 8.
In the second example, last digit of 13782 = 1378Β·1378 = 1898884 is 4.
Tags: implementation, math, number theory
Correct Solution:
```
n = int(input())
if n:
print([6,8,4,2][n%4])
else:
print("1")
```
| 104,931 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There exists an island called Arpaβs land, some beautiful girls live there, as ugly ones do.
Mehrdad wants to become minister of Arpaβs land. Arpa has prepared an exam. Exam has only one question, given n, print the last digit of 1378n.
<image>
Mehrdad has become quite confused and wants you to help him. Please help, although it's a naive cheat.
Input
The single line of input contains one integer n (0 β€ n β€ 109).
Output
Print single integer β the last digit of 1378n.
Examples
Input
1
Output
8
Input
2
Output
4
Note
In the first example, last digit of 13781 = 1378 is 8.
In the second example, last digit of 13782 = 1378Β·1378 = 1898884 is 4.
Tags: implementation, math, number theory
Correct Solution:
```
n=int(input())
if (n==0):
print (1)
elif (n%4==1):
print(8)
elif (n%4==2):
print(4)
elif (n%4==3):
print(2)
elif (n%4==0):
print(6)
```
| 104,932 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There exists an island called Arpaβs land, some beautiful girls live there, as ugly ones do.
Mehrdad wants to become minister of Arpaβs land. Arpa has prepared an exam. Exam has only one question, given n, print the last digit of 1378n.
<image>
Mehrdad has become quite confused and wants you to help him. Please help, although it's a naive cheat.
Input
The single line of input contains one integer n (0 β€ n β€ 109).
Output
Print single integer β the last digit of 1378n.
Examples
Input
1
Output
8
Input
2
Output
4
Note
In the first example, last digit of 13781 = 1378 is 8.
In the second example, last digit of 13782 = 1378Β·1378 = 1898884 is 4.
Tags: implementation, math, number theory
Correct Solution:
```
n = int(input())
res = 0
if n==0: res = 1
elif n%4==0: res=6
elif n%4==1: res=8
elif n%4==2: res=4
else: res=2
print(res)
```
| 104,933 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There exists an island called Arpaβs land, some beautiful girls live there, as ugly ones do.
Mehrdad wants to become minister of Arpaβs land. Arpa has prepared an exam. Exam has only one question, given n, print the last digit of 1378n.
<image>
Mehrdad has become quite confused and wants you to help him. Please help, although it's a naive cheat.
Input
The single line of input contains one integer n (0 β€ n β€ 109).
Output
Print single integer β the last digit of 1378n.
Examples
Input
1
Output
8
Input
2
Output
4
Note
In the first example, last digit of 13781 = 1378 is 8.
In the second example, last digit of 13782 = 1378Β·1378 = 1898884 is 4.
Tags: implementation, math, number theory
Correct Solution:
```
n=int(input())
if n==0:
print(1)
else:
z=n%4
if z==0: print(6)
elif z==1: print(8)
elif z==2: print(4)
elif z==3: print(2)
```
| 104,934 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There exists an island called Arpaβs land, some beautiful girls live there, as ugly ones do.
Mehrdad wants to become minister of Arpaβs land. Arpa has prepared an exam. Exam has only one question, given n, print the last digit of 1378n.
<image>
Mehrdad has become quite confused and wants you to help him. Please help, although it's a naive cheat.
Input
The single line of input contains one integer n (0 β€ n β€ 109).
Output
Print single integer β the last digit of 1378n.
Examples
Input
1
Output
8
Input
2
Output
4
Note
In the first example, last digit of 13781 = 1378 is 8.
In the second example, last digit of 13782 = 1378Β·1378 = 1898884 is 4.
Tags: implementation, math, number theory
Correct Solution:
```
def solve(n,result):
try:
return result[n-1]
except Exception as e:
return result[(n%len(result)) - 1]
if __name__ == '__main__':
n = int(input())
result = [8,4,2,6]
if n == 0:
print(1)
else:
print(solve(n,result))
```
| 104,935 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There exists an island called Arpaβs land, some beautiful girls live there, as ugly ones do.
Mehrdad wants to become minister of Arpaβs land. Arpa has prepared an exam. Exam has only one question, given n, print the last digit of 1378n.
<image>
Mehrdad has become quite confused and wants you to help him. Please help, although it's a naive cheat.
Input
The single line of input contains one integer n (0 β€ n β€ 109).
Output
Print single integer β the last digit of 1378n.
Examples
Input
1
Output
8
Input
2
Output
4
Note
In the first example, last digit of 13781 = 1378 is 8.
In the second example, last digit of 13782 = 1378Β·1378 = 1898884 is 4.
Tags: implementation, math, number theory
Correct Solution:
```
exp = int(input())
if exp == 0:
lstDigit = 1
else:
modExp = exp % 4
if modExp == 1:
lstDigit = 8
else:
if modExp == 2:
lstDigit = 4
else:
if modExp == 3:
lstDigit = 2
else:
lstDigit = 6
print(lstDigit)
```
| 104,936 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There exists an island called Arpaβs land, some beautiful girls live there, as ugly ones do.
Mehrdad wants to become minister of Arpaβs land. Arpa has prepared an exam. Exam has only one question, given n, print the last digit of 1378n.
<image>
Mehrdad has become quite confused and wants you to help him. Please help, although it's a naive cheat.
Input
The single line of input contains one integer n (0 β€ n β€ 109).
Output
Print single integer β the last digit of 1378n.
Examples
Input
1
Output
8
Input
2
Output
4
Note
In the first example, last digit of 13781 = 1378 is 8.
In the second example, last digit of 13782 = 1378Β·1378 = 1898884 is 4.
Tags: implementation, math, number theory
Correct Solution:
```
n=int(input ())
k=n%4
if(n==0):
print (1)
elif(k==1):
print (8)
elif(k==2):
print (4)
elif(k==3):
print (2)
else:
print (6)
```
| 104,937 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There exists an island called Arpaβs land, some beautiful girls live there, as ugly ones do.
Mehrdad wants to become minister of Arpaβs land. Arpa has prepared an exam. Exam has only one question, given n, print the last digit of 1378n.
<image>
Mehrdad has become quite confused and wants you to help him. Please help, although it's a naive cheat.
Input
The single line of input contains one integer n (0 β€ n β€ 109).
Output
Print single integer β the last digit of 1378n.
Examples
Input
1
Output
8
Input
2
Output
4
Note
In the first example, last digit of 13781 = 1378 is 8.
In the second example, last digit of 13782 = 1378Β·1378 = 1898884 is 4.
Tags: implementation, math, number theory
Correct Solution:
```
n = int(input())
if n==0:
print (1)
else:
res = [8,4,2,6]
print (res[(n-1)%4])
```
| 104,938 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There exists an island called Arpaβs land, some beautiful girls live there, as ugly ones do.
Mehrdad wants to become minister of Arpaβs land. Arpa has prepared an exam. Exam has only one question, given n, print the last digit of 1378n.
<image>
Mehrdad has become quite confused and wants you to help him. Please help, although it's a naive cheat.
Input
The single line of input contains one integer n (0 β€ n β€ 109).
Output
Print single integer β the last digit of 1378n.
Examples
Input
1
Output
8
Input
2
Output
4
Note
In the first example, last digit of 13781 = 1378 is 8.
In the second example, last digit of 13782 = 1378Β·1378 = 1898884 is 4.
Submitted Solution:
```
m = int(input())
print([6,8,4,2][m % 4] if m > 0 else 1)
```
Yes
| 104,939 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There exists an island called Arpaβs land, some beautiful girls live there, as ugly ones do.
Mehrdad wants to become minister of Arpaβs land. Arpa has prepared an exam. Exam has only one question, given n, print the last digit of 1378n.
<image>
Mehrdad has become quite confused and wants you to help him. Please help, although it's a naive cheat.
Input
The single line of input contains one integer n (0 β€ n β€ 109).
Output
Print single integer β the last digit of 1378n.
Examples
Input
1
Output
8
Input
2
Output
4
Note
In the first example, last digit of 13781 = 1378 is 8.
In the second example, last digit of 13782 = 1378Β·1378 = 1898884 is 4.
Submitted Solution:
```
n=int(input())
if n==0:
print(1)
if n%4==1:
print(8)
if n%4==2:
print(4)
if n%4==3:
print(2)
if n>0 and n%4==0:
print(6)
```
Yes
| 104,940 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There exists an island called Arpaβs land, some beautiful girls live there, as ugly ones do.
Mehrdad wants to become minister of Arpaβs land. Arpa has prepared an exam. Exam has only one question, given n, print the last digit of 1378n.
<image>
Mehrdad has become quite confused and wants you to help him. Please help, although it's a naive cheat.
Input
The single line of input contains one integer n (0 β€ n β€ 109).
Output
Print single integer β the last digit of 1378n.
Examples
Input
1
Output
8
Input
2
Output
4
Note
In the first example, last digit of 13781 = 1378 is 8.
In the second example, last digit of 13782 = 1378Β·1378 = 1898884 is 4.
Submitted Solution:
```
n = int(input())
ans = 0
if n == 0:
ans = 1
elif n % 4 == 1:
ans = 8
elif n % 4 == 2:
ans = 4
elif n % 4 == 3:
ans = 2
else:
ans = 6
print(ans)
```
Yes
| 104,941 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There exists an island called Arpaβs land, some beautiful girls live there, as ugly ones do.
Mehrdad wants to become minister of Arpaβs land. Arpa has prepared an exam. Exam has only one question, given n, print the last digit of 1378n.
<image>
Mehrdad has become quite confused and wants you to help him. Please help, although it's a naive cheat.
Input
The single line of input contains one integer n (0 β€ n β€ 109).
Output
Print single integer β the last digit of 1378n.
Examples
Input
1
Output
8
Input
2
Output
4
Note
In the first example, last digit of 13781 = 1378 is 8.
In the second example, last digit of 13782 = 1378Β·1378 = 1898884 is 4.
Submitted Solution:
```
def f(n):
if n == 0:
return 1
else:
n = (n - 1) % 4
if n == 0:
return 8
elif n == 1:
return 4
elif n == 2:
return 2
else:
return 6
n = int(input())
print(f(n))
```
Yes
| 104,942 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There exists an island called Arpaβs land, some beautiful girls live there, as ugly ones do.
Mehrdad wants to become minister of Arpaβs land. Arpa has prepared an exam. Exam has only one question, given n, print the last digit of 1378n.
<image>
Mehrdad has become quite confused and wants you to help him. Please help, although it's a naive cheat.
Input
The single line of input contains one integer n (0 β€ n β€ 109).
Output
Print single integer β the last digit of 1378n.
Examples
Input
1
Output
8
Input
2
Output
4
Note
In the first example, last digit of 13781 = 1378 is 8.
In the second example, last digit of 13782 = 1378Β·1378 = 1898884 is 4.
Submitted Solution:
```
x=[int(n) for n in input()]
x=x[::-1]
n=0
while 1:
if x[n]!=0:
break
else:
n+=1
if n==0:
k=x[n]
elif n==1:
k=10*(x[n])
elif n>=2:
k=x[n]*100
print((8**k)%10)
```
No
| 104,943 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There exists an island called Arpaβs land, some beautiful girls live there, as ugly ones do.
Mehrdad wants to become minister of Arpaβs land. Arpa has prepared an exam. Exam has only one question, given n, print the last digit of 1378n.
<image>
Mehrdad has become quite confused and wants you to help him. Please help, although it's a naive cheat.
Input
The single line of input contains one integer n (0 β€ n β€ 109).
Output
Print single integer β the last digit of 1378n.
Examples
Input
1
Output
8
Input
2
Output
4
Note
In the first example, last digit of 13781 = 1378 is 8.
In the second example, last digit of 13782 = 1378Β·1378 = 1898884 is 4.
Submitted Solution:
```
n = input()
if len(n) == 1:
n = int(n[-1])
if n == 0:
print(1)
else:
n = int(n[-1]) + 10 * int(n[-2])
if n % 4 == 0:
print(6)
elif n % 4 == 1:
print(8)
elif n % 4 == 2:
print(4)
else:
print(2)
```
No
| 104,944 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There exists an island called Arpaβs land, some beautiful girls live there, as ugly ones do.
Mehrdad wants to become minister of Arpaβs land. Arpa has prepared an exam. Exam has only one question, given n, print the last digit of 1378n.
<image>
Mehrdad has become quite confused and wants you to help him. Please help, although it's a naive cheat.
Input
The single line of input contains one integer n (0 β€ n β€ 109).
Output
Print single integer β the last digit of 1378n.
Examples
Input
1
Output
8
Input
2
Output
4
Note
In the first example, last digit of 13781 = 1378 is 8.
In the second example, last digit of 13782 = 1378Β·1378 = 1898884 is 4.
Submitted Solution:
```
print((8 ** (int(input()) % 5)) % 10)
```
No
| 104,945 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There exists an island called Arpaβs land, some beautiful girls live there, as ugly ones do.
Mehrdad wants to become minister of Arpaβs land. Arpa has prepared an exam. Exam has only one question, given n, print the last digit of 1378n.
<image>
Mehrdad has become quite confused and wants you to help him. Please help, although it's a naive cheat.
Input
The single line of input contains one integer n (0 β€ n β€ 109).
Output
Print single integer β the last digit of 1378n.
Examples
Input
1
Output
8
Input
2
Output
4
Note
In the first example, last digit of 13781 = 1378 is 8.
In the second example, last digit of 13782 = 1378Β·1378 = 1898884 is 4.
Submitted Solution:
```
a=[8,4,2,6]
b=int(input())%4-1
print(1 if b==-1 else a[b])
```
No
| 104,946 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vanya wants to minimize a tree. He can perform the following operation multiple times: choose a vertex v, and two disjoint (except for v) paths of equal length a0 = v, a1, ..., ak, and b0 = v, b1, ..., bk. Additionally, vertices a1, ..., ak, b1, ..., bk must not have any neighbours in the tree other than adjacent vertices of corresponding paths. After that, one of the paths may be merged into the other, that is, the vertices b1, ..., bk can be effectively erased:
<image>
Help Vanya determine if it possible to make the tree into a path via a sequence of described operations, and if the answer is positive, also determine the shortest length of such path.
Input
The first line of input contains the number of vertices n (2 β€ n β€ 2Β·105).
Next n - 1 lines describe edges of the tree. Each of these lines contains two space-separated integers u and v (1 β€ u, v β€ n, u β v) β indices of endpoints of the corresponding edge. It is guaranteed that the given graph is a tree.
Output
If it is impossible to obtain a path, print -1. Otherwise, print the minimum number of edges in a possible path.
Examples
Input
6
1 2
2 3
2 4
4 5
1 6
Output
3
Input
7
1 2
1 3
3 4
1 5
5 6
6 7
Output
-1
Note
In the first sample case, a path of three edges is obtained after merging paths 2 - 1 - 6 and 2 - 4 - 5.
It is impossible to perform any operation in the second sample case. For example, it is impossible to merge paths 1 - 3 - 4 and 1 - 5 - 6, since vertex 6 additionally has a neighbour 7 that is not present in the corresponding path.
Tags: dfs and similar, dp, greedy, implementation, trees
Correct Solution:
```
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7
def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()
def main():
n = II()
d = collections.defaultdict(set)
for _ in range(n-1):
a,b = LI()
d[a].add(b)
d[b].add(a)
memo = {}
def path(t,s):
ps = set()
dt = list(d[t])
for k in dt:
if k not in memo:
continue
if memo[k] in ps:
d[k] -= set([t])
d[t] -= set([k])
ps.add(memo[k])
if s == -1 and len(ps) == 2:
memo[t] = sum(ps) + 2
return memo[t]
if len(ps) > 1:
return -t
if len(ps) == 0:
memo[t] = 0
return 0
memo[t] = list(ps)[0] + 1
return memo[t]
def _path(tt,ss):
q = [(tt,ss)]
tq = []
qi = 0
while len(q) > qi:
t,s = q[qi]
for k in d[t]:
if k == s:
continue
q.append((k,t))
qi += 1
for t,s in q[::-1]:
r = path(t,s)
if r < 0:
return r
return memo[tt]
def _path2(tt,ss):
q = [(tt,ss)]
tq = []
qi = 0
while len(q) > qi:
t,s = q[qi]
for k in d[t]:
if k == s or k in memo:
continue
q.append((k,t))
qi += 1
for t,s in q[::-1]:
r = path(t,s)
if r < 0:
return r
return memo[tt]
t = _path(1,-1)
if t < 0:
t = _path2(-t,-1)
if t > 0:
while t%2 == 0:
t//=2
return t
return -1
print(main())
```
| 104,947 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vanya wants to minimize a tree. He can perform the following operation multiple times: choose a vertex v, and two disjoint (except for v) paths of equal length a0 = v, a1, ..., ak, and b0 = v, b1, ..., bk. Additionally, vertices a1, ..., ak, b1, ..., bk must not have any neighbours in the tree other than adjacent vertices of corresponding paths. After that, one of the paths may be merged into the other, that is, the vertices b1, ..., bk can be effectively erased:
<image>
Help Vanya determine if it possible to make the tree into a path via a sequence of described operations, and if the answer is positive, also determine the shortest length of such path.
Input
The first line of input contains the number of vertices n (2 β€ n β€ 2Β·105).
Next n - 1 lines describe edges of the tree. Each of these lines contains two space-separated integers u and v (1 β€ u, v β€ n, u β v) β indices of endpoints of the corresponding edge. It is guaranteed that the given graph is a tree.
Output
If it is impossible to obtain a path, print -1. Otherwise, print the minimum number of edges in a possible path.
Examples
Input
6
1 2
2 3
2 4
4 5
1 6
Output
3
Input
7
1 2
1 3
3 4
1 5
5 6
6 7
Output
-1
Note
In the first sample case, a path of three edges is obtained after merging paths 2 - 1 - 6 and 2 - 4 - 5.
It is impossible to perform any operation in the second sample case. For example, it is impossible to merge paths 1 - 3 - 4 and 1 - 5 - 6, since vertex 6 additionally has a neighbour 7 that is not present in the corresponding path.
Tags: dfs and similar, dp, greedy, implementation, trees
Correct Solution:
```
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7
def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()
def main():
n = II()
d = collections.defaultdict(set)
for _ in range(n-1):
a,b = LI()
d[a].add(b)
d[b].add(a)
memo = {}
def path(t,s):
ps = set()
dt = list(d[t])
for k in dt:
if k not in memo:
continue
ps.add(memo[k])
if s == -1 and len(ps) == 2:
memo[t] = sum(ps) + 2
return memo[t]
if len(ps) > 1:
return -t
if len(ps) == 0:
memo[t] = 0
return 0
memo[t] = list(ps)[0] + 1
return memo[t]
def _path(tt,ss):
q = [(tt,ss)]
tq = []
qi = 0
while len(q) > qi:
t,s = q[qi]
for k in d[t]:
if k == s:
continue
q.append((k,t))
qi += 1
for t,s in q[::-1]:
r = path(t,s)
if r < 0:
return r
return memo[tt]
def _path2(tt,ss):
q = [(tt,ss)]
tq = []
qi = 0
while len(q) > qi:
t,s = q[qi]
for k in d[t]:
if k == s or k in memo:
continue
q.append((k,t))
qi += 1
for t,s in q[::-1]:
r = path(t,s)
if r < 0:
return r
return memo[tt]
t = _path(1,-1)
if t < 0:
t = _path2(-t,-1)
if t > 0:
while t%2 == 0:
t//=2
return t
return -1
print(main())
```
| 104,948 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vanya wants to minimize a tree. He can perform the following operation multiple times: choose a vertex v, and two disjoint (except for v) paths of equal length a0 = v, a1, ..., ak, and b0 = v, b1, ..., bk. Additionally, vertices a1, ..., ak, b1, ..., bk must not have any neighbours in the tree other than adjacent vertices of corresponding paths. After that, one of the paths may be merged into the other, that is, the vertices b1, ..., bk can be effectively erased:
<image>
Help Vanya determine if it possible to make the tree into a path via a sequence of described operations, and if the answer is positive, also determine the shortest length of such path.
Input
The first line of input contains the number of vertices n (2 β€ n β€ 2Β·105).
Next n - 1 lines describe edges of the tree. Each of these lines contains two space-separated integers u and v (1 β€ u, v β€ n, u β v) β indices of endpoints of the corresponding edge. It is guaranteed that the given graph is a tree.
Output
If it is impossible to obtain a path, print -1. Otherwise, print the minimum number of edges in a possible path.
Examples
Input
6
1 2
2 3
2 4
4 5
1 6
Output
3
Input
7
1 2
1 3
3 4
1 5
5 6
6 7
Output
-1
Note
In the first sample case, a path of three edges is obtained after merging paths 2 - 1 - 6 and 2 - 4 - 5.
It is impossible to perform any operation in the second sample case. For example, it is impossible to merge paths 1 - 3 - 4 and 1 - 5 - 6, since vertex 6 additionally has a neighbour 7 that is not present in the corresponding path.
Tags: dfs and similar, dp, greedy, implementation, trees
Correct Solution:
```
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7
def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()
def main():
n = II()
d = collections.defaultdict(set)
for _ in range(n-1):
a,b = LI()
d[a].add(b)
d[b].add(a)
memo = [-1] * (n+1)
def path(t,s):
ps = set()
dt = list(d[t])
for k in dt:
if memo[k] < 0:
continue
ps.add(memo[k])
if s == -1 and len(ps) == 2:
memo[t] = sum(ps) + 2
return memo[t]
if len(ps) > 1:
return -t
if len(ps) == 0:
memo[t] = 0
return 0
memo[t] = list(ps)[0] + 1
return memo[t]
def _path(tt,ss):
f = [False] * (n+1)
q = [(tt,ss)]
tq = []
qi = 0
while len(q) > qi:
t,s = q[qi]
for k in d[t]:
if k == s or memo[k] >= 0:
continue
q.append((k,t))
qi += 1
for t,s in q[::-1]:
r = path(t,s)
if r < 0:
return r
return memo[tt]
t = _path(1,-1)
if t < 0:
t = _path(-t,-1)
if t > 0:
while t%2 == 0:
t//=2
return t
return -1
print(main())
```
| 104,949 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vanya wants to minimize a tree. He can perform the following operation multiple times: choose a vertex v, and two disjoint (except for v) paths of equal length a0 = v, a1, ..., ak, and b0 = v, b1, ..., bk. Additionally, vertices a1, ..., ak, b1, ..., bk must not have any neighbours in the tree other than adjacent vertices of corresponding paths. After that, one of the paths may be merged into the other, that is, the vertices b1, ..., bk can be effectively erased:
<image>
Help Vanya determine if it possible to make the tree into a path via a sequence of described operations, and if the answer is positive, also determine the shortest length of such path.
Input
The first line of input contains the number of vertices n (2 β€ n β€ 2Β·105).
Next n - 1 lines describe edges of the tree. Each of these lines contains two space-separated integers u and v (1 β€ u, v β€ n, u β v) β indices of endpoints of the corresponding edge. It is guaranteed that the given graph is a tree.
Output
If it is impossible to obtain a path, print -1. Otherwise, print the minimum number of edges in a possible path.
Examples
Input
6
1 2
2 3
2 4
4 5
1 6
Output
3
Input
7
1 2
1 3
3 4
1 5
5 6
6 7
Output
-1
Note
In the first sample case, a path of three edges is obtained after merging paths 2 - 1 - 6 and 2 - 4 - 5.
It is impossible to perform any operation in the second sample case. For example, it is impossible to merge paths 1 - 3 - 4 and 1 - 5 - 6, since vertex 6 additionally has a neighbour 7 that is not present in the corresponding path.
Tags: dfs and similar, dp, greedy, implementation, trees
Correct Solution:
```
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7
def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()
def main():
n = II()
d = collections.defaultdict(set)
for _ in range(n-1):
a,b = LI()
d[a].add(b)
d[b].add(a)
memo = [-1] * (n+1)
def path(t,s):
ps = set()
dt = list(d[t])
for k in dt:
if memo[k] < 0:
continue
ps.add(memo[k])
if s == -1 and len(ps) == 2:
memo[t] = sum(ps) + 2
return memo[t]
if len(ps) > 1:
return -t
if len(ps) == 0:
memo[t] = 0
return 0
memo[t] = list(ps)[0] + 1
return memo[t]
def _path(tt,ss):
q = [(tt,ss)]
tq = []
qi = 0
while len(q) > qi:
t,s = q[qi]
for k in d[t]:
if k == s:
continue
q.append((k,t))
qi += 1
for t,s in q[::-1]:
r = path(t,s)
if r < 0:
return r
return memo[tt]
def _path2(tt,ss):
q = [(tt,ss)]
tq = []
qi = 0
while len(q) > qi:
t,s = q[qi]
for k in d[t]:
if k == s or memo[k] >= 0:
continue
q.append((k,t))
qi += 1
for t,s in q[::-1]:
r = path(t,s)
if r < 0:
return r
return memo[tt]
t = _path(1,-1)
if t < 0:
t = _path2(-t,-1)
if t > 0:
while t%2 == 0:
t//=2
return t
return -1
print(main())
```
| 104,950 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vanya wants to minimize a tree. He can perform the following operation multiple times: choose a vertex v, and two disjoint (except for v) paths of equal length a0 = v, a1, ..., ak, and b0 = v, b1, ..., bk. Additionally, vertices a1, ..., ak, b1, ..., bk must not have any neighbours in the tree other than adjacent vertices of corresponding paths. After that, one of the paths may be merged into the other, that is, the vertices b1, ..., bk can be effectively erased:
<image>
Help Vanya determine if it possible to make the tree into a path via a sequence of described operations, and if the answer is positive, also determine the shortest length of such path.
Input
The first line of input contains the number of vertices n (2 β€ n β€ 2Β·105).
Next n - 1 lines describe edges of the tree. Each of these lines contains two space-separated integers u and v (1 β€ u, v β€ n, u β v) β indices of endpoints of the corresponding edge. It is guaranteed that the given graph is a tree.
Output
If it is impossible to obtain a path, print -1. Otherwise, print the minimum number of edges in a possible path.
Examples
Input
6
1 2
2 3
2 4
4 5
1 6
Output
3
Input
7
1 2
1 3
3 4
1 5
5 6
6 7
Output
-1
Note
In the first sample case, a path of three edges is obtained after merging paths 2 - 1 - 6 and 2 - 4 - 5.
It is impossible to perform any operation in the second sample case. For example, it is impossible to merge paths 1 - 3 - 4 and 1 - 5 - 6, since vertex 6 additionally has a neighbour 7 that is not present in the corresponding path.
Submitted Solution:
```
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time
sys.setrecursionlimit(10**6)
inf = 10**20
mod = 10**9 + 7
def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()
def main():
n = II()
d = collections.defaultdict(set)
for _ in range(n-1):
a,b = LI()
d[a].add(b)
d[b].add(a)
tf = 54066 in d[44923]
if tf:
return d
def path(t,s):
ps = set()
dt = list(d[t])
for k in dt:
if k == s:
continue
f,pt = path(k,t)
if f == False:
return (False, pt)
ps.add(pt)
if s == -1 and len(ps) == 2:
return (True, sum(ps) + 2)
if len(ps) > 1:
return (False, t)
if len(ps) == 0:
return (True, 0)
return (True,list(ps)[0] + 1)
if 54066 in d[44923]:
try:
print(1)
f,t = path(1,-1)
return (f,t)
except:
print(sys.exc_info())
return (1,2)
return (1,2)
f,t = path(1,-1)
if f:
while t%2 == 0:
t//=2
return t
f,t = path(t,-1)
if f:
while t%2 == 0:
t//=2
return t
return -1
print(main())
```
No
| 104,951 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vanya wants to minimize a tree. He can perform the following operation multiple times: choose a vertex v, and two disjoint (except for v) paths of equal length a0 = v, a1, ..., ak, and b0 = v, b1, ..., bk. Additionally, vertices a1, ..., ak, b1, ..., bk must not have any neighbours in the tree other than adjacent vertices of corresponding paths. After that, one of the paths may be merged into the other, that is, the vertices b1, ..., bk can be effectively erased:
<image>
Help Vanya determine if it possible to make the tree into a path via a sequence of described operations, and if the answer is positive, also determine the shortest length of such path.
Input
The first line of input contains the number of vertices n (2 β€ n β€ 2Β·105).
Next n - 1 lines describe edges of the tree. Each of these lines contains two space-separated integers u and v (1 β€ u, v β€ n, u β v) β indices of endpoints of the corresponding edge. It is guaranteed that the given graph is a tree.
Output
If it is impossible to obtain a path, print -1. Otherwise, print the minimum number of edges in a possible path.
Examples
Input
6
1 2
2 3
2 4
4 5
1 6
Output
3
Input
7
1 2
1 3
3 4
1 5
5 6
6 7
Output
-1
Note
In the first sample case, a path of three edges is obtained after merging paths 2 - 1 - 6 and 2 - 4 - 5.
It is impossible to perform any operation in the second sample case. For example, it is impossible to merge paths 1 - 3 - 4 and 1 - 5 - 6, since vertex 6 additionally has a neighbour 7 that is not present in the corresponding path.
Submitted Solution:
```
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7
def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()
def main():
n = II()
d = {}
for _ in range(n-1):
a,b = LI()
if a not in d:
d[a] = []
if b not in d:
d[b] = []
d[a].append(b)
d[b].append(a)
tf = 54066 in d[44923]
def path(t,s):
ps = set()
for k in d[t]:
if k == s:
continue
f,pt = path(k,t)
if f == False:
return (False, pt)
ps.add(pt)
if len(ps) > 2:
return (False, t)
if s == -1:
if tf:
return (True, 1)
if len(ps) == 2:
return (True, sum(list(ps)) + 2)
if len(ps) == 1:
return (True, list(ps)[0] + 1)
if len(ps) > 1:
return (False, t)
if len(ps) == 0:
return (True, 0)
return (True,list(ps)[0] + 1)
f,t = path(n//2+1,-1)
if not f:
f,t = path(t,-1)
if f:
if t == 0:
return 0
while t%2 == 0:
t//=2
return t
return -1
try:
print(main())
except:
print("Unexpected error:", sys.exc_info()[0])
```
No
| 104,952 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vanya wants to minimize a tree. He can perform the following operation multiple times: choose a vertex v, and two disjoint (except for v) paths of equal length a0 = v, a1, ..., ak, and b0 = v, b1, ..., bk. Additionally, vertices a1, ..., ak, b1, ..., bk must not have any neighbours in the tree other than adjacent vertices of corresponding paths. After that, one of the paths may be merged into the other, that is, the vertices b1, ..., bk can be effectively erased:
<image>
Help Vanya determine if it possible to make the tree into a path via a sequence of described operations, and if the answer is positive, also determine the shortest length of such path.
Input
The first line of input contains the number of vertices n (2 β€ n β€ 2Β·105).
Next n - 1 lines describe edges of the tree. Each of these lines contains two space-separated integers u and v (1 β€ u, v β€ n, u β v) β indices of endpoints of the corresponding edge. It is guaranteed that the given graph is a tree.
Output
If it is impossible to obtain a path, print -1. Otherwise, print the minimum number of edges in a possible path.
Examples
Input
6
1 2
2 3
2 4
4 5
1 6
Output
3
Input
7
1 2
1 3
3 4
1 5
5 6
6 7
Output
-1
Note
In the first sample case, a path of three edges is obtained after merging paths 2 - 1 - 6 and 2 - 4 - 5.
It is impossible to perform any operation in the second sample case. For example, it is impossible to merge paths 1 - 3 - 4 and 1 - 5 - 6, since vertex 6 additionally has a neighbour 7 that is not present in the corresponding path.
Submitted Solution:
```
import sys
from collections import defaultdict
from collections import Counter
def debug(x, table):
for name, val in table.items():
if x is val:
print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
return None
def solve():
n = int(input())
Adj = [[] for i in range(n)]
for i in range(n - 1):
u, v = map(int, input().split())
u, v = u - 1, v - 1
Adj[u].append(v)
Adj[v].append(u)
# debug(Adj, locals())
path_ls = defaultdict(Counter)
trace_deg1(n, Adj, path_ls)
# debug(path_ls, locals())
min_ = float('inf')
for u in path_ls:
if len(path_ls[u]) == 1:
if path_ls[u][l] >= 2:
min_ = min(min_, l)
if min_ == float('inf'):
ans = -1
else:
ans = min_
print(ans)
def trace_deg1(n, Adj, path_ls):
for u in range(n):
if len(Adj[u]) == 1:
# debug(u, locals())
path_l = 2
v = Adj[u][0]
while len(Adj[v]) == 2:
path_l += 1
v, u = sum(Adj[v]) - u, v
path_ls[v][path_l] += 1
return None
if __name__ == '__main__':
solve()
```
No
| 104,953 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vanya wants to minimize a tree. He can perform the following operation multiple times: choose a vertex v, and two disjoint (except for v) paths of equal length a0 = v, a1, ..., ak, and b0 = v, b1, ..., bk. Additionally, vertices a1, ..., ak, b1, ..., bk must not have any neighbours in the tree other than adjacent vertices of corresponding paths. After that, one of the paths may be merged into the other, that is, the vertices b1, ..., bk can be effectively erased:
<image>
Help Vanya determine if it possible to make the tree into a path via a sequence of described operations, and if the answer is positive, also determine the shortest length of such path.
Input
The first line of input contains the number of vertices n (2 β€ n β€ 2Β·105).
Next n - 1 lines describe edges of the tree. Each of these lines contains two space-separated integers u and v (1 β€ u, v β€ n, u β v) β indices of endpoints of the corresponding edge. It is guaranteed that the given graph is a tree.
Output
If it is impossible to obtain a path, print -1. Otherwise, print the minimum number of edges in a possible path.
Examples
Input
6
1 2
2 3
2 4
4 5
1 6
Output
3
Input
7
1 2
1 3
3 4
1 5
5 6
6 7
Output
-1
Note
In the first sample case, a path of three edges is obtained after merging paths 2 - 1 - 6 and 2 - 4 - 5.
It is impossible to perform any operation in the second sample case. For example, it is impossible to merge paths 1 - 3 - 4 and 1 - 5 - 6, since vertex 6 additionally has a neighbour 7 that is not present in the corresponding path.
Submitted Solution:
```
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7
def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()
def main():
n = II()
d = {}
ds = [{}]
for _ in range(n-1):
a,b = LI()
if a not in d:
d[a] = []
if b not in d:
d[b] = []
d[a].append(b)
d[b].append(a)
tf = 44923 in d and 54066 in d[44923]
if tf:
return max(d.keys())
def path(t,s):
ps = set()
for k in d[t]:
if k == s:
continue
f,pt = path(k,t)
if f == False:
return (False, pt)
if tf:
ps.add(1)
else:
ps.add(pt)
if len(ps) > 2:
return (False, t)
if s == -1:
if tf:
return (True, 1)
if len(ps) == 2:
return (True, sum(list(ps)) + 2)
if len(ps) == 1:
return (True, list(ps)[0] + 1)
if len(ps) > 1:
if tf:
return (False, 1)
return (False, t)
if len(ps) == 0:
return (True, 0)
if tf:
return (True, 1)
return (True,list(ps)[0] + 1)
f,t = path(n//2+1,-1)
if not f:
f,t = path(t,-1)
if f:
if t == 0:
return 0
while t%2 == 0:
t//=2
return t
return -1
try:
print(main())
except:
print("Unexpected error:", sys.exc_info()[0])
```
No
| 104,954 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise.
You are given geometric progression b defined by two integers b1 and q. Remind that a geometric progression is a sequence of integers b1, b2, b3, ..., where for each i > 1 the respective term satisfies the condition bi = bi - 1Β·q, where q is called the common ratio of the progression. Progressions in Uzhlyandia are unusual: both b1 and q can equal 0. Also, Dvastan gave Masha m "bad" integers a1, a2, ..., am, and an integer l.
Masha writes all progression terms one by one onto the board (including repetitive) while condition |bi| β€ l is satisfied (|x| means absolute value of x). There is an exception: if a term equals one of the "bad" integers, Masha skips it (doesn't write onto the board) and moves forward to the next term.
But the lesson is going to end soon, so Masha has to calculate how many integers will be written on the board. In order not to get into depression, Masha asked you for help: help her calculate how many numbers she will write, or print "inf" in case she needs to write infinitely many integers.
Input
The first line of input contains four integers b1, q, l, m (-109 β€ b1, q β€ 109, 1 β€ l β€ 109, 1 β€ m β€ 105) β the initial term and the common ratio of progression, absolute value of maximal number that can be written on the board and the number of "bad" integers, respectively.
The second line contains m distinct integers a1, a2, ..., am (-109 β€ ai β€ 109) β numbers that will never be written on the board.
Output
Print the only integer, meaning the number of progression terms that will be written on the board if it is finite, or "inf" (without quotes) otherwise.
Examples
Input
3 2 30 4
6 14 25 48
Output
3
Input
123 1 2143435 4
123 11 -5453 141245
Output
0
Input
123 1 2143435 4
54343 -13 6 124
Output
inf
Note
In the first sample case, Masha will write integers 3, 12, 24. Progression term 6 will be skipped because it is a "bad" integer. Terms bigger than 24 won't be written because they exceed l by absolute value.
In the second case, Masha won't write any number because all terms are equal 123 and this is a "bad" integer.
In the third case, Masha will write infinitely integers 123.
Tags: brute force, implementation, math
Correct Solution:
```
b, q, l, m = map(int, input().split())
A = set(map(int, input().split()))
ans = 0
for _ in range(100):
if abs(b) > l:
break
if b not in A:
ans += 1
b *= q
if ans > 40:
print("inf")
else:
print(ans)
```
| 104,955 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise.
You are given geometric progression b defined by two integers b1 and q. Remind that a geometric progression is a sequence of integers b1, b2, b3, ..., where for each i > 1 the respective term satisfies the condition bi = bi - 1Β·q, where q is called the common ratio of the progression. Progressions in Uzhlyandia are unusual: both b1 and q can equal 0. Also, Dvastan gave Masha m "bad" integers a1, a2, ..., am, and an integer l.
Masha writes all progression terms one by one onto the board (including repetitive) while condition |bi| β€ l is satisfied (|x| means absolute value of x). There is an exception: if a term equals one of the "bad" integers, Masha skips it (doesn't write onto the board) and moves forward to the next term.
But the lesson is going to end soon, so Masha has to calculate how many integers will be written on the board. In order not to get into depression, Masha asked you for help: help her calculate how many numbers she will write, or print "inf" in case she needs to write infinitely many integers.
Input
The first line of input contains four integers b1, q, l, m (-109 β€ b1, q β€ 109, 1 β€ l β€ 109, 1 β€ m β€ 105) β the initial term and the common ratio of progression, absolute value of maximal number that can be written on the board and the number of "bad" integers, respectively.
The second line contains m distinct integers a1, a2, ..., am (-109 β€ ai β€ 109) β numbers that will never be written on the board.
Output
Print the only integer, meaning the number of progression terms that will be written on the board if it is finite, or "inf" (without quotes) otherwise.
Examples
Input
3 2 30 4
6 14 25 48
Output
3
Input
123 1 2143435 4
123 11 -5453 141245
Output
0
Input
123 1 2143435 4
54343 -13 6 124
Output
inf
Note
In the first sample case, Masha will write integers 3, 12, 24. Progression term 6 will be skipped because it is a "bad" integer. Terms bigger than 24 won't be written because they exceed l by absolute value.
In the second case, Masha won't write any number because all terms are equal 123 and this is a "bad" integer.
In the third case, Masha will write infinitely integers 123.
Tags: brute force, implementation, math
Correct Solution:
```
import math,sys,bisect,heapq
from collections import defaultdict,Counter,deque
from itertools import groupby,accumulate
#sys.setrecursionlimit(200000000)
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda: map(int,input().split())
alele = lambda: list(map(int, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
#MOD = 1000000000 + 7
def Y(c): print(["NO","YES"][c])
def y(c): print(["no","yes"][c])
def Yy(c): print(["No","Yes"][c])
b,q,l,m = ilele()
A = alele()
C = Counter(A)
Ans = [b]
if abs(b) > l:
print(0)
exit(0)
for i in range(100000):
b*= q
if abs(b) > l:
break
Ans.append(b)
#print(Ans)
count = 0
G = set()
for i in Ans:
if C.get(i,-1) == -1 and abs(i) <= l:
count += 1
G.add(i)
if count >= 10000 or (count > 1000 and len(G) <= 3) :
print("inf")
else:
print(count)
```
| 104,956 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise.
You are given geometric progression b defined by two integers b1 and q. Remind that a geometric progression is a sequence of integers b1, b2, b3, ..., where for each i > 1 the respective term satisfies the condition bi = bi - 1Β·q, where q is called the common ratio of the progression. Progressions in Uzhlyandia are unusual: both b1 and q can equal 0. Also, Dvastan gave Masha m "bad" integers a1, a2, ..., am, and an integer l.
Masha writes all progression terms one by one onto the board (including repetitive) while condition |bi| β€ l is satisfied (|x| means absolute value of x). There is an exception: if a term equals one of the "bad" integers, Masha skips it (doesn't write onto the board) and moves forward to the next term.
But the lesson is going to end soon, so Masha has to calculate how many integers will be written on the board. In order not to get into depression, Masha asked you for help: help her calculate how many numbers she will write, or print "inf" in case she needs to write infinitely many integers.
Input
The first line of input contains four integers b1, q, l, m (-109 β€ b1, q β€ 109, 1 β€ l β€ 109, 1 β€ m β€ 105) β the initial term and the common ratio of progression, absolute value of maximal number that can be written on the board and the number of "bad" integers, respectively.
The second line contains m distinct integers a1, a2, ..., am (-109 β€ ai β€ 109) β numbers that will never be written on the board.
Output
Print the only integer, meaning the number of progression terms that will be written on the board if it is finite, or "inf" (without quotes) otherwise.
Examples
Input
3 2 30 4
6 14 25 48
Output
3
Input
123 1 2143435 4
123 11 -5453 141245
Output
0
Input
123 1 2143435 4
54343 -13 6 124
Output
inf
Note
In the first sample case, Masha will write integers 3, 12, 24. Progression term 6 will be skipped because it is a "bad" integer. Terms bigger than 24 won't be written because they exceed l by absolute value.
In the second case, Masha won't write any number because all terms are equal 123 and this is a "bad" integer.
In the third case, Masha will write infinitely integers 123.
Tags: brute force, implementation, math
Correct Solution:
```
b, q, l, m = map(int, input().split())
s = set(map(int, input().split()))
if abs(b) > l:
print(0)
exit()
if q == 1:
if b not in s:
print("inf")
exit()
else:
print(0)
exit()
if q == -1:
if b not in s or b * -1 not in s:
print("inf")
exit()
else:
print(0)
exit()
if q == 0:
if 0 not in s:
print("inf")
exit()
else:
print(1 * (b not in s))
exit()
if b == 0:
if 0 not in s:
print("inf")
exit()
else:
print(0)
exit()
res = 0
while abs(b) <= l:
if b not in s:
res += 1
b = b * q
print(res)
```
| 104,957 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise.
You are given geometric progression b defined by two integers b1 and q. Remind that a geometric progression is a sequence of integers b1, b2, b3, ..., where for each i > 1 the respective term satisfies the condition bi = bi - 1Β·q, where q is called the common ratio of the progression. Progressions in Uzhlyandia are unusual: both b1 and q can equal 0. Also, Dvastan gave Masha m "bad" integers a1, a2, ..., am, and an integer l.
Masha writes all progression terms one by one onto the board (including repetitive) while condition |bi| β€ l is satisfied (|x| means absolute value of x). There is an exception: if a term equals one of the "bad" integers, Masha skips it (doesn't write onto the board) and moves forward to the next term.
But the lesson is going to end soon, so Masha has to calculate how many integers will be written on the board. In order not to get into depression, Masha asked you for help: help her calculate how many numbers she will write, or print "inf" in case she needs to write infinitely many integers.
Input
The first line of input contains four integers b1, q, l, m (-109 β€ b1, q β€ 109, 1 β€ l β€ 109, 1 β€ m β€ 105) β the initial term and the common ratio of progression, absolute value of maximal number that can be written on the board and the number of "bad" integers, respectively.
The second line contains m distinct integers a1, a2, ..., am (-109 β€ ai β€ 109) β numbers that will never be written on the board.
Output
Print the only integer, meaning the number of progression terms that will be written on the board if it is finite, or "inf" (without quotes) otherwise.
Examples
Input
3 2 30 4
6 14 25 48
Output
3
Input
123 1 2143435 4
123 11 -5453 141245
Output
0
Input
123 1 2143435 4
54343 -13 6 124
Output
inf
Note
In the first sample case, Masha will write integers 3, 12, 24. Progression term 6 will be skipped because it is a "bad" integer. Terms bigger than 24 won't be written because they exceed l by absolute value.
In the second case, Masha won't write any number because all terms are equal 123 and this is a "bad" integer.
In the third case, Masha will write infinitely integers 123.
Tags: brute force, implementation, math
Correct Solution:
```
class CodeforcesTask789BSolution:
def __init__(self):
self.result = ''
self.b_q_l_m = []
self.bad_numbers = []
def read_input(self):
self.b_q_l_m = [int(x) for x in input().split(" ")]
self.bad_numbers = [int(x) for x in input().split(" ")]
def process_task(self):
term = self.b_q_l_m[0]
q = self.b_q_l_m[1]
terms_count = 0
if q == 1 and term not in self.bad_numbers:
if abs(term) <= self.b_q_l_m[2]:
self.result = "inf"
else:
self.result = "0"
elif q == 1:
self.result = "0"
elif q == 0:
if abs(term) <= self.b_q_l_m[2]:
if term not in self.bad_numbers:
terms_count += 1
if 0 not in self.bad_numbers:
self.result = "inf"
else:
self.result = str(terms_count)
else:
self.result = "0"
elif q == -1:
if term not in self.bad_numbers:
if abs(term) <= self.b_q_l_m[2]:
self.result = "inf"
else:
self.result = "0"
else:
if -term not in self.bad_numbers:
if abs(-term) <= self.b_q_l_m[2]:
self.result = "inf"
else:
self.result = "0"
else:
self.result = "0"
elif term == 0:
if term not in self.bad_numbers:
self.result = "inf"
else:
self.result = "0"
else:
while abs(term) <= self.b_q_l_m[2]:
if term not in self.bad_numbers:
terms_count += 1
term *= q
self.result = str(terms_count)
def get_result(self):
return self.result
if __name__ == "__main__":
Solution = CodeforcesTask789BSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())
```
| 104,958 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise.
You are given geometric progression b defined by two integers b1 and q. Remind that a geometric progression is a sequence of integers b1, b2, b3, ..., where for each i > 1 the respective term satisfies the condition bi = bi - 1Β·q, where q is called the common ratio of the progression. Progressions in Uzhlyandia are unusual: both b1 and q can equal 0. Also, Dvastan gave Masha m "bad" integers a1, a2, ..., am, and an integer l.
Masha writes all progression terms one by one onto the board (including repetitive) while condition |bi| β€ l is satisfied (|x| means absolute value of x). There is an exception: if a term equals one of the "bad" integers, Masha skips it (doesn't write onto the board) and moves forward to the next term.
But the lesson is going to end soon, so Masha has to calculate how many integers will be written on the board. In order not to get into depression, Masha asked you for help: help her calculate how many numbers she will write, or print "inf" in case she needs to write infinitely many integers.
Input
The first line of input contains four integers b1, q, l, m (-109 β€ b1, q β€ 109, 1 β€ l β€ 109, 1 β€ m β€ 105) β the initial term and the common ratio of progression, absolute value of maximal number that can be written on the board and the number of "bad" integers, respectively.
The second line contains m distinct integers a1, a2, ..., am (-109 β€ ai β€ 109) β numbers that will never be written on the board.
Output
Print the only integer, meaning the number of progression terms that will be written on the board if it is finite, or "inf" (without quotes) otherwise.
Examples
Input
3 2 30 4
6 14 25 48
Output
3
Input
123 1 2143435 4
123 11 -5453 141245
Output
0
Input
123 1 2143435 4
54343 -13 6 124
Output
inf
Note
In the first sample case, Masha will write integers 3, 12, 24. Progression term 6 will be skipped because it is a "bad" integer. Terms bigger than 24 won't be written because they exceed l by absolute value.
In the second case, Masha won't write any number because all terms are equal 123 and this is a "bad" integer.
In the third case, Masha will write infinitely integers 123.
Tags: brute force, implementation, math
Correct Solution:
```
a=input().split()
b=int(a[0])
q=int(a[1])
l=int(a[2])
m=int(a[3])
a=input().split()
t=0
if(b==0):
if('0' in a):print(0)
else:print("inf")
elif(abs(b)>l):print(0)
elif(abs(q)<=1 and q!=-1 and q!=0):
if(str(b) in a):print(0)
else:print("inf")
elif(q==(-1)):
if(str(b) in a and str(-b) in a):print(0)
else:print("inf")
elif(q==0):
t=1
if(str(b) in a):t=0;
if(str(0) in a):print(t)
else:print("inf")
else:
t=0
while(abs(b)<=l):
if(not(str(b) in a)):t+=1
b*=q
print(t)
```
| 104,959 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise.
You are given geometric progression b defined by two integers b1 and q. Remind that a geometric progression is a sequence of integers b1, b2, b3, ..., where for each i > 1 the respective term satisfies the condition bi = bi - 1Β·q, where q is called the common ratio of the progression. Progressions in Uzhlyandia are unusual: both b1 and q can equal 0. Also, Dvastan gave Masha m "bad" integers a1, a2, ..., am, and an integer l.
Masha writes all progression terms one by one onto the board (including repetitive) while condition |bi| β€ l is satisfied (|x| means absolute value of x). There is an exception: if a term equals one of the "bad" integers, Masha skips it (doesn't write onto the board) and moves forward to the next term.
But the lesson is going to end soon, so Masha has to calculate how many integers will be written on the board. In order not to get into depression, Masha asked you for help: help her calculate how many numbers she will write, or print "inf" in case she needs to write infinitely many integers.
Input
The first line of input contains four integers b1, q, l, m (-109 β€ b1, q β€ 109, 1 β€ l β€ 109, 1 β€ m β€ 105) β the initial term and the common ratio of progression, absolute value of maximal number that can be written on the board and the number of "bad" integers, respectively.
The second line contains m distinct integers a1, a2, ..., am (-109 β€ ai β€ 109) β numbers that will never be written on the board.
Output
Print the only integer, meaning the number of progression terms that will be written on the board if it is finite, or "inf" (without quotes) otherwise.
Examples
Input
3 2 30 4
6 14 25 48
Output
3
Input
123 1 2143435 4
123 11 -5453 141245
Output
0
Input
123 1 2143435 4
54343 -13 6 124
Output
inf
Note
In the first sample case, Masha will write integers 3, 12, 24. Progression term 6 will be skipped because it is a "bad" integer. Terms bigger than 24 won't be written because they exceed l by absolute value.
In the second case, Masha won't write any number because all terms are equal 123 and this is a "bad" integer.
In the third case, Masha will write infinitely integers 123.
Tags: brute force, implementation, math
Correct Solution:
```
b1, q, l, m = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
ans = 0
if abs(b1) > l:
ans = 0
elif b1 == 0:
ans = "inf" if 0 not in a else 0
else:
ans = int(b1 not in a)
if q == 0:
if 0 not in a : ans = "inf"
elif q == 1:
if ans > 0 : ans = "inf"
elif q == -1:
if ans > 0 or -b1 not in a: ans = "inf"
else:
while 1:
b1 *= q
if abs(b1) > l: break
ans += b1 not in a
print(ans)
```
| 104,960 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise.
You are given geometric progression b defined by two integers b1 and q. Remind that a geometric progression is a sequence of integers b1, b2, b3, ..., where for each i > 1 the respective term satisfies the condition bi = bi - 1Β·q, where q is called the common ratio of the progression. Progressions in Uzhlyandia are unusual: both b1 and q can equal 0. Also, Dvastan gave Masha m "bad" integers a1, a2, ..., am, and an integer l.
Masha writes all progression terms one by one onto the board (including repetitive) while condition |bi| β€ l is satisfied (|x| means absolute value of x). There is an exception: if a term equals one of the "bad" integers, Masha skips it (doesn't write onto the board) and moves forward to the next term.
But the lesson is going to end soon, so Masha has to calculate how many integers will be written on the board. In order not to get into depression, Masha asked you for help: help her calculate how many numbers she will write, or print "inf" in case she needs to write infinitely many integers.
Input
The first line of input contains four integers b1, q, l, m (-109 β€ b1, q β€ 109, 1 β€ l β€ 109, 1 β€ m β€ 105) β the initial term and the common ratio of progression, absolute value of maximal number that can be written on the board and the number of "bad" integers, respectively.
The second line contains m distinct integers a1, a2, ..., am (-109 β€ ai β€ 109) β numbers that will never be written on the board.
Output
Print the only integer, meaning the number of progression terms that will be written on the board if it is finite, or "inf" (without quotes) otherwise.
Examples
Input
3 2 30 4
6 14 25 48
Output
3
Input
123 1 2143435 4
123 11 -5453 141245
Output
0
Input
123 1 2143435 4
54343 -13 6 124
Output
inf
Note
In the first sample case, Masha will write integers 3, 12, 24. Progression term 6 will be skipped because it is a "bad" integer. Terms bigger than 24 won't be written because they exceed l by absolute value.
In the second case, Masha won't write any number because all terms are equal 123 and this is a "bad" integer.
In the third case, Masha will write infinitely integers 123.
Tags: brute force, implementation, math
Correct Solution:
```
b1 , q , l , m = map(int, input().split())
s = set(map(int , input().split()))
ans = 0
cnt = 0
while abs(b1) <= l:
if b1 not in s:
ans += 1
cnt += 1
if cnt == 100000:
break
b1 *= q
if ans >= 50000:
print('inf')
else:
print(ans)
```
| 104,961 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise.
You are given geometric progression b defined by two integers b1 and q. Remind that a geometric progression is a sequence of integers b1, b2, b3, ..., where for each i > 1 the respective term satisfies the condition bi = bi - 1Β·q, where q is called the common ratio of the progression. Progressions in Uzhlyandia are unusual: both b1 and q can equal 0. Also, Dvastan gave Masha m "bad" integers a1, a2, ..., am, and an integer l.
Masha writes all progression terms one by one onto the board (including repetitive) while condition |bi| β€ l is satisfied (|x| means absolute value of x). There is an exception: if a term equals one of the "bad" integers, Masha skips it (doesn't write onto the board) and moves forward to the next term.
But the lesson is going to end soon, so Masha has to calculate how many integers will be written on the board. In order not to get into depression, Masha asked you for help: help her calculate how many numbers she will write, or print "inf" in case she needs to write infinitely many integers.
Input
The first line of input contains four integers b1, q, l, m (-109 β€ b1, q β€ 109, 1 β€ l β€ 109, 1 β€ m β€ 105) β the initial term and the common ratio of progression, absolute value of maximal number that can be written on the board and the number of "bad" integers, respectively.
The second line contains m distinct integers a1, a2, ..., am (-109 β€ ai β€ 109) β numbers that will never be written on the board.
Output
Print the only integer, meaning the number of progression terms that will be written on the board if it is finite, or "inf" (without quotes) otherwise.
Examples
Input
3 2 30 4
6 14 25 48
Output
3
Input
123 1 2143435 4
123 11 -5453 141245
Output
0
Input
123 1 2143435 4
54343 -13 6 124
Output
inf
Note
In the first sample case, Masha will write integers 3, 12, 24. Progression term 6 will be skipped because it is a "bad" integer. Terms bigger than 24 won't be written because they exceed l by absolute value.
In the second case, Masha won't write any number because all terms are equal 123 and this is a "bad" integer.
In the third case, Masha will write infinitely integers 123.
Tags: brute force, implementation, math
Correct Solution:
```
from sys import stdin, stdout
b, q, l, n = map(int, stdin.readline().split())
a = set(list(map(int, stdin.readline().split())))
ans = 0
ind = 0
while abs(b) <= l and ind < 100:
if not b in a:
ans += 1
b *= q
ind += 1
if ans > 40:
stdout.write('inf')
else:
stdout.write(str(ans))
```
| 104,962 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise.
You are given geometric progression b defined by two integers b1 and q. Remind that a geometric progression is a sequence of integers b1, b2, b3, ..., where for each i > 1 the respective term satisfies the condition bi = bi - 1Β·q, where q is called the common ratio of the progression. Progressions in Uzhlyandia are unusual: both b1 and q can equal 0. Also, Dvastan gave Masha m "bad" integers a1, a2, ..., am, and an integer l.
Masha writes all progression terms one by one onto the board (including repetitive) while condition |bi| β€ l is satisfied (|x| means absolute value of x). There is an exception: if a term equals one of the "bad" integers, Masha skips it (doesn't write onto the board) and moves forward to the next term.
But the lesson is going to end soon, so Masha has to calculate how many integers will be written on the board. In order not to get into depression, Masha asked you for help: help her calculate how many numbers she will write, or print "inf" in case she needs to write infinitely many integers.
Input
The first line of input contains four integers b1, q, l, m (-109 β€ b1, q β€ 109, 1 β€ l β€ 109, 1 β€ m β€ 105) β the initial term and the common ratio of progression, absolute value of maximal number that can be written on the board and the number of "bad" integers, respectively.
The second line contains m distinct integers a1, a2, ..., am (-109 β€ ai β€ 109) β numbers that will never be written on the board.
Output
Print the only integer, meaning the number of progression terms that will be written on the board if it is finite, or "inf" (without quotes) otherwise.
Examples
Input
3 2 30 4
6 14 25 48
Output
3
Input
123 1 2143435 4
123 11 -5453 141245
Output
0
Input
123 1 2143435 4
54343 -13 6 124
Output
inf
Note
In the first sample case, Masha will write integers 3, 12, 24. Progression term 6 will be skipped because it is a "bad" integer. Terms bigger than 24 won't be written because they exceed l by absolute value.
In the second case, Masha won't write any number because all terms are equal 123 and this is a "bad" integer.
In the third case, Masha will write infinitely integers 123.
Submitted Solution:
```
b, q, l, m = list(map(int, input().split()))
st = set(map(int, input().split()))
mx = 1000
ans = 0
for i in range(0, 100000):
if abs(b) > l:
break
if b not in st:
ans = ans + 1
b *= q
if ans == mx:
break
if ans == mx:
print("inf")
else:
print(ans)
```
Yes
| 104,963 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise.
You are given geometric progression b defined by two integers b1 and q. Remind that a geometric progression is a sequence of integers b1, b2, b3, ..., where for each i > 1 the respective term satisfies the condition bi = bi - 1Β·q, where q is called the common ratio of the progression. Progressions in Uzhlyandia are unusual: both b1 and q can equal 0. Also, Dvastan gave Masha m "bad" integers a1, a2, ..., am, and an integer l.
Masha writes all progression terms one by one onto the board (including repetitive) while condition |bi| β€ l is satisfied (|x| means absolute value of x). There is an exception: if a term equals one of the "bad" integers, Masha skips it (doesn't write onto the board) and moves forward to the next term.
But the lesson is going to end soon, so Masha has to calculate how many integers will be written on the board. In order not to get into depression, Masha asked you for help: help her calculate how many numbers she will write, or print "inf" in case she needs to write infinitely many integers.
Input
The first line of input contains four integers b1, q, l, m (-109 β€ b1, q β€ 109, 1 β€ l β€ 109, 1 β€ m β€ 105) β the initial term and the common ratio of progression, absolute value of maximal number that can be written on the board and the number of "bad" integers, respectively.
The second line contains m distinct integers a1, a2, ..., am (-109 β€ ai β€ 109) β numbers that will never be written on the board.
Output
Print the only integer, meaning the number of progression terms that will be written on the board if it is finite, or "inf" (without quotes) otherwise.
Examples
Input
3 2 30 4
6 14 25 48
Output
3
Input
123 1 2143435 4
123 11 -5453 141245
Output
0
Input
123 1 2143435 4
54343 -13 6 124
Output
inf
Note
In the first sample case, Masha will write integers 3, 12, 24. Progression term 6 will be skipped because it is a "bad" integer. Terms bigger than 24 won't be written because they exceed l by absolute value.
In the second case, Masha won't write any number because all terms are equal 123 and this is a "bad" integer.
In the third case, Masha will write infinitely integers 123.
Submitted Solution:
```
def main():
read = lambda: tuple(map(int, input().split()))
b, q, l, m = read()
ns = {}
for n in read(): ns[n] = True
k = 0
if b == 0:
return "inf" if not b in ns else 0
if q == 1:
return "inf" if not b in ns and abs(b) <= l else 0
if q == -1:
return "inf" if (not b in ns or not -b in ns) and abs(b) <= l else 0
if q == 0:
if abs(b) > l: return 0
else:
return "inf" if not 0 in ns else (1 if not b in ns else 0)
while abs(b) <= l:
if not b in ns:
k += 1
b *= q
return k
print(main())
```
Yes
| 104,964 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise.
You are given geometric progression b defined by two integers b1 and q. Remind that a geometric progression is a sequence of integers b1, b2, b3, ..., where for each i > 1 the respective term satisfies the condition bi = bi - 1Β·q, where q is called the common ratio of the progression. Progressions in Uzhlyandia are unusual: both b1 and q can equal 0. Also, Dvastan gave Masha m "bad" integers a1, a2, ..., am, and an integer l.
Masha writes all progression terms one by one onto the board (including repetitive) while condition |bi| β€ l is satisfied (|x| means absolute value of x). There is an exception: if a term equals one of the "bad" integers, Masha skips it (doesn't write onto the board) and moves forward to the next term.
But the lesson is going to end soon, so Masha has to calculate how many integers will be written on the board. In order not to get into depression, Masha asked you for help: help her calculate how many numbers she will write, or print "inf" in case she needs to write infinitely many integers.
Input
The first line of input contains four integers b1, q, l, m (-109 β€ b1, q β€ 109, 1 β€ l β€ 109, 1 β€ m β€ 105) β the initial term and the common ratio of progression, absolute value of maximal number that can be written on the board and the number of "bad" integers, respectively.
The second line contains m distinct integers a1, a2, ..., am (-109 β€ ai β€ 109) β numbers that will never be written on the board.
Output
Print the only integer, meaning the number of progression terms that will be written on the board if it is finite, or "inf" (without quotes) otherwise.
Examples
Input
3 2 30 4
6 14 25 48
Output
3
Input
123 1 2143435 4
123 11 -5453 141245
Output
0
Input
123 1 2143435 4
54343 -13 6 124
Output
inf
Note
In the first sample case, Masha will write integers 3, 12, 24. Progression term 6 will be skipped because it is a "bad" integer. Terms bigger than 24 won't be written because they exceed l by absolute value.
In the second case, Masha won't write any number because all terms are equal 123 and this is a "bad" integer.
In the third case, Masha will write infinitely integers 123.
Submitted Solution:
```
b, q, l, m = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
if abs(b) > l:
c = 0
elif b == 0:
if 0 in a: c = 0
else: c = "inf"
elif q == 1:
if b in a: c = 0
else: c = "inf"
elif q == -1:
if b in a and -b in a: c = 0
else: c = "inf"
elif q == 0:
if 0 not in a: c = "inf"
elif b in a: c = 0
else: c = 1
else:
c = 0
while abs(b) <= l:
if b not in a: c += 1
b *= q
print(c)
```
Yes
| 104,965 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise.
You are given geometric progression b defined by two integers b1 and q. Remind that a geometric progression is a sequence of integers b1, b2, b3, ..., where for each i > 1 the respective term satisfies the condition bi = bi - 1Β·q, where q is called the common ratio of the progression. Progressions in Uzhlyandia are unusual: both b1 and q can equal 0. Also, Dvastan gave Masha m "bad" integers a1, a2, ..., am, and an integer l.
Masha writes all progression terms one by one onto the board (including repetitive) while condition |bi| β€ l is satisfied (|x| means absolute value of x). There is an exception: if a term equals one of the "bad" integers, Masha skips it (doesn't write onto the board) and moves forward to the next term.
But the lesson is going to end soon, so Masha has to calculate how many integers will be written on the board. In order not to get into depression, Masha asked you for help: help her calculate how many numbers she will write, or print "inf" in case she needs to write infinitely many integers.
Input
The first line of input contains four integers b1, q, l, m (-109 β€ b1, q β€ 109, 1 β€ l β€ 109, 1 β€ m β€ 105) β the initial term and the common ratio of progression, absolute value of maximal number that can be written on the board and the number of "bad" integers, respectively.
The second line contains m distinct integers a1, a2, ..., am (-109 β€ ai β€ 109) β numbers that will never be written on the board.
Output
Print the only integer, meaning the number of progression terms that will be written on the board if it is finite, or "inf" (without quotes) otherwise.
Examples
Input
3 2 30 4
6 14 25 48
Output
3
Input
123 1 2143435 4
123 11 -5453 141245
Output
0
Input
123 1 2143435 4
54343 -13 6 124
Output
inf
Note
In the first sample case, Masha will write integers 3, 12, 24. Progression term 6 will be skipped because it is a "bad" integer. Terms bigger than 24 won't be written because they exceed l by absolute value.
In the second case, Masha won't write any number because all terms are equal 123 and this is a "bad" integer.
In the third case, Masha will write infinitely integers 123.
Submitted Solution:
```
ip = lambda: [int(i) for i in input().split()]
b, q, l, m = ip()
bad = set(ip())
ans = 0
iter_count = 0
inf = False
while True:
if iter_count >= 40:
inf = True
break
if abs(b) > l:
break
if b not in bad:
ans += 1
b *= q
iter_count += 1
if inf and ans > 2:
print("inf")
else:
print(ans)
```
Yes
| 104,966 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise.
You are given geometric progression b defined by two integers b1 and q. Remind that a geometric progression is a sequence of integers b1, b2, b3, ..., where for each i > 1 the respective term satisfies the condition bi = bi - 1Β·q, where q is called the common ratio of the progression. Progressions in Uzhlyandia are unusual: both b1 and q can equal 0. Also, Dvastan gave Masha m "bad" integers a1, a2, ..., am, and an integer l.
Masha writes all progression terms one by one onto the board (including repetitive) while condition |bi| β€ l is satisfied (|x| means absolute value of x). There is an exception: if a term equals one of the "bad" integers, Masha skips it (doesn't write onto the board) and moves forward to the next term.
But the lesson is going to end soon, so Masha has to calculate how many integers will be written on the board. In order not to get into depression, Masha asked you for help: help her calculate how many numbers she will write, or print "inf" in case she needs to write infinitely many integers.
Input
The first line of input contains four integers b1, q, l, m (-109 β€ b1, q β€ 109, 1 β€ l β€ 109, 1 β€ m β€ 105) β the initial term and the common ratio of progression, absolute value of maximal number that can be written on the board and the number of "bad" integers, respectively.
The second line contains m distinct integers a1, a2, ..., am (-109 β€ ai β€ 109) β numbers that will never be written on the board.
Output
Print the only integer, meaning the number of progression terms that will be written on the board if it is finite, or "inf" (without quotes) otherwise.
Examples
Input
3 2 30 4
6 14 25 48
Output
3
Input
123 1 2143435 4
123 11 -5453 141245
Output
0
Input
123 1 2143435 4
54343 -13 6 124
Output
inf
Note
In the first sample case, Masha will write integers 3, 12, 24. Progression term 6 will be skipped because it is a "bad" integer. Terms bigger than 24 won't be written because they exceed l by absolute value.
In the second case, Masha won't write any number because all terms are equal 123 and this is a "bad" integer.
In the third case, Masha will write infinitely integers 123.
Submitted Solution:
```
a,r,l,m = map(int,input().split())
_l = list(map(int,input().split()))
s = set(_l)
if(a==0):
if(0 in s):
print(0)
exit(0)
else:
print("inf")
exit(0)
if(r==0):
if(a==0):
if(0 in s):
print(0)
exit(0)
else:
print("inf")
exit(0)
else:
if(a not in s and abs(a)<=l):
if(0 in s):
print("inf")
else:
print(1)
exit(0)
else:
print(0)
exit(0)
if(r==1):
if(a in s or abs(a)>l):
print(0)
exit(0)
else:
print("inf")
exit(0)
if(r==-1):
if(a in s):
if(0-a in s):
print(0)
exit(0)
else:
if(abs(a)<=l):
print("inf")
exit(0)
else:
print(0)
exit(0)
else:
if(abs(a)<=l):
print("inf")
exit(0)
else:
print(0)
exit(0)
tot = 0
while(abs(a)<=l):
if(a not in s):
tot+=1
a*=r
print(tot)
```
No
| 104,967 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise.
You are given geometric progression b defined by two integers b1 and q. Remind that a geometric progression is a sequence of integers b1, b2, b3, ..., where for each i > 1 the respective term satisfies the condition bi = bi - 1Β·q, where q is called the common ratio of the progression. Progressions in Uzhlyandia are unusual: both b1 and q can equal 0. Also, Dvastan gave Masha m "bad" integers a1, a2, ..., am, and an integer l.
Masha writes all progression terms one by one onto the board (including repetitive) while condition |bi| β€ l is satisfied (|x| means absolute value of x). There is an exception: if a term equals one of the "bad" integers, Masha skips it (doesn't write onto the board) and moves forward to the next term.
But the lesson is going to end soon, so Masha has to calculate how many integers will be written on the board. In order not to get into depression, Masha asked you for help: help her calculate how many numbers she will write, or print "inf" in case she needs to write infinitely many integers.
Input
The first line of input contains four integers b1, q, l, m (-109 β€ b1, q β€ 109, 1 β€ l β€ 109, 1 β€ m β€ 105) β the initial term and the common ratio of progression, absolute value of maximal number that can be written on the board and the number of "bad" integers, respectively.
The second line contains m distinct integers a1, a2, ..., am (-109 β€ ai β€ 109) β numbers that will never be written on the board.
Output
Print the only integer, meaning the number of progression terms that will be written on the board if it is finite, or "inf" (without quotes) otherwise.
Examples
Input
3 2 30 4
6 14 25 48
Output
3
Input
123 1 2143435 4
123 11 -5453 141245
Output
0
Input
123 1 2143435 4
54343 -13 6 124
Output
inf
Note
In the first sample case, Masha will write integers 3, 12, 24. Progression term 6 will be skipped because it is a "bad" integer. Terms bigger than 24 won't be written because they exceed l by absolute value.
In the second case, Masha won't write any number because all terms are equal 123 and this is a "bad" integer.
In the third case, Masha will write infinitely integers 123.
Submitted Solution:
```
#!/usr/bin/env python3
from math import *
def ri():
return map(int, input().split())
b, q, l, m = ri()
a = list(ri())
ans = 0
if abs(b) < l:
if not b in a:
ans+=1
else:
print(0)
exit()
i = 0
while True:
i += 1
b = b*q
if b in a:
pass
elif abs(b) < l:
ans+=1
else:
print(ans)
break
if i > 10:
if b == b*q*q or b == b*q:
if b in a and b*q in a:
print(ans)
exit()
else:
print("inf")
exit()
```
No
| 104,968 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise.
You are given geometric progression b defined by two integers b1 and q. Remind that a geometric progression is a sequence of integers b1, b2, b3, ..., where for each i > 1 the respective term satisfies the condition bi = bi - 1Β·q, where q is called the common ratio of the progression. Progressions in Uzhlyandia are unusual: both b1 and q can equal 0. Also, Dvastan gave Masha m "bad" integers a1, a2, ..., am, and an integer l.
Masha writes all progression terms one by one onto the board (including repetitive) while condition |bi| β€ l is satisfied (|x| means absolute value of x). There is an exception: if a term equals one of the "bad" integers, Masha skips it (doesn't write onto the board) and moves forward to the next term.
But the lesson is going to end soon, so Masha has to calculate how many integers will be written on the board. In order not to get into depression, Masha asked you for help: help her calculate how many numbers she will write, or print "inf" in case she needs to write infinitely many integers.
Input
The first line of input contains four integers b1, q, l, m (-109 β€ b1, q β€ 109, 1 β€ l β€ 109, 1 β€ m β€ 105) β the initial term and the common ratio of progression, absolute value of maximal number that can be written on the board and the number of "bad" integers, respectively.
The second line contains m distinct integers a1, a2, ..., am (-109 β€ ai β€ 109) β numbers that will never be written on the board.
Output
Print the only integer, meaning the number of progression terms that will be written on the board if it is finite, or "inf" (without quotes) otherwise.
Examples
Input
3 2 30 4
6 14 25 48
Output
3
Input
123 1 2143435 4
123 11 -5453 141245
Output
0
Input
123 1 2143435 4
54343 -13 6 124
Output
inf
Note
In the first sample case, Masha will write integers 3, 12, 24. Progression term 6 will be skipped because it is a "bad" integer. Terms bigger than 24 won't be written because they exceed l by absolute value.
In the second case, Masha won't write any number because all terms are equal 123 and this is a "bad" integer.
In the third case, Masha will write infinitely integers 123.
Submitted Solution:
```
b, q, l, m = [int(a_temp) for a_temp in input().strip().split()]
a = [int(a_temp) for a_temp in input().strip().split()]
d = {}
for e in a:
d[e]=True
if q==0:
if 0 not in d:
print("inf")
elif b not in d:
print(1)
else:
print(0)
elif q==1:
if b in d or abs(b)>l:
print(0)
else:
print("inf")
elif q==-1:
if abs(b)>l:
print(0)
elif b not in d:
print("inf")
elif -1*b not in d:
print("inf")
else:
print(0)
else:
count = 0
b = abs(b)
q = abs(q)
t = b
while(t<=l):
if t not in d:
count+=1
t*=q
print(count)
```
No
| 104,969 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise.
You are given geometric progression b defined by two integers b1 and q. Remind that a geometric progression is a sequence of integers b1, b2, b3, ..., where for each i > 1 the respective term satisfies the condition bi = bi - 1Β·q, where q is called the common ratio of the progression. Progressions in Uzhlyandia are unusual: both b1 and q can equal 0. Also, Dvastan gave Masha m "bad" integers a1, a2, ..., am, and an integer l.
Masha writes all progression terms one by one onto the board (including repetitive) while condition |bi| β€ l is satisfied (|x| means absolute value of x). There is an exception: if a term equals one of the "bad" integers, Masha skips it (doesn't write onto the board) and moves forward to the next term.
But the lesson is going to end soon, so Masha has to calculate how many integers will be written on the board. In order not to get into depression, Masha asked you for help: help her calculate how many numbers she will write, or print "inf" in case she needs to write infinitely many integers.
Input
The first line of input contains four integers b1, q, l, m (-109 β€ b1, q β€ 109, 1 β€ l β€ 109, 1 β€ m β€ 105) β the initial term and the common ratio of progression, absolute value of maximal number that can be written on the board and the number of "bad" integers, respectively.
The second line contains m distinct integers a1, a2, ..., am (-109 β€ ai β€ 109) β numbers that will never be written on the board.
Output
Print the only integer, meaning the number of progression terms that will be written on the board if it is finite, or "inf" (without quotes) otherwise.
Examples
Input
3 2 30 4
6 14 25 48
Output
3
Input
123 1 2143435 4
123 11 -5453 141245
Output
0
Input
123 1 2143435 4
54343 -13 6 124
Output
inf
Note
In the first sample case, Masha will write integers 3, 12, 24. Progression term 6 will be skipped because it is a "bad" integer. Terms bigger than 24 won't be written because they exceed l by absolute value.
In the second case, Masha won't write any number because all terms are equal 123 and this is a "bad" integer.
In the third case, Masha will write infinitely integers 123.
Submitted Solution:
```
b1,q,l,m = [int(i) for i in input().split()]
bad = [int(i) for i in input().split()]
if abs(q) > 1:
b2 = b1
count = 0
while abs(b2) <= l:
count += 1
b2 *= q
for u in bad:
i = u
a = False
while (i%q == 0):
i = i / q
a = i == b1
if a:
break
if (a and u<=l) or u == b1:
count-=1
print(count)
else:
a1 = b1 * q
a2 = a1 * q
if abs(b1) <= l:
if a1 in bad:
if a1 in bad:
print("0")
else:
print("inf")
else:
print("inf")
else:
print("0")
```
No
| 104,970 |
Provide tags and a correct Python 3 solution for this coding contest problem.
For some reason in many American cartoons anvils fall from time to time onto heroes' heads. Of course, safes, wardrobes, cruisers, planes fall sometimes too... But anvils do so most of all.
Anvils come in different sizes and shapes. Quite often they get the hero stuck deep in the ground. But have you ever thought who throws anvils from the sky? From what height? We are sure that such questions have never troubled you!
It turns out that throwing an anvil properly is not an easy task at all. Let's describe one of the most popular anvil throwing models.
Let the height p of the potential victim vary in the range [0;a] and the direction of the wind q vary in the range [ - b;b]. p and q could be any real (floating) numbers. Then we can assume that the anvil will fit the toon's head perfectly only if the following equation has at least one real root:
<image>
Determine the probability with which an aim can be successfully hit by an anvil.
You can assume that the p and q coefficients are chosen equiprobably and independently in their ranges.
Input
The first line contains integer t (1 β€ t β€ 10000) β amount of testcases.
Each of the following t lines contain two space-separated integers a and b (0 β€ a, b β€ 106).
Pretests contain all the tests with 0 < a < 10, 0 β€ b < 10.
Output
Print t lines β the probability of a successful anvil hit for each testcase. The absolute or relative error of the answer should not exceed 10 - 6.
Examples
Input
2
4 2
1 2
Output
0.6250000000
0.5312500000
Tags: math, probabilities
Correct Solution:
```
t = int( input() )
for i in range( t ):
a, b = list( map( int, input().split() ) )
if a == 0 and b == 0:
print( 1 )
elif a == 0:
print( 0.5 )
elif b == 0:
print( 1 )
else:
if a < 4*b:
ans = (b*a + a*a / 8) / (2*a*b)
else:
ans = 1 - b/a
print( ans )
```
| 104,971 |
Provide tags and a correct Python 3 solution for this coding contest problem.
For some reason in many American cartoons anvils fall from time to time onto heroes' heads. Of course, safes, wardrobes, cruisers, planes fall sometimes too... But anvils do so most of all.
Anvils come in different sizes and shapes. Quite often they get the hero stuck deep in the ground. But have you ever thought who throws anvils from the sky? From what height? We are sure that such questions have never troubled you!
It turns out that throwing an anvil properly is not an easy task at all. Let's describe one of the most popular anvil throwing models.
Let the height p of the potential victim vary in the range [0;a] and the direction of the wind q vary in the range [ - b;b]. p and q could be any real (floating) numbers. Then we can assume that the anvil will fit the toon's head perfectly only if the following equation has at least one real root:
<image>
Determine the probability with which an aim can be successfully hit by an anvil.
You can assume that the p and q coefficients are chosen equiprobably and independently in their ranges.
Input
The first line contains integer t (1 β€ t β€ 10000) β amount of testcases.
Each of the following t lines contain two space-separated integers a and b (0 β€ a, b β€ 106).
Pretests contain all the tests with 0 < a < 10, 0 β€ b < 10.
Output
Print t lines β the probability of a successful anvil hit for each testcase. The absolute or relative error of the answer should not exceed 10 - 6.
Examples
Input
2
4 2
1 2
Output
0.6250000000
0.5312500000
Tags: math, probabilities
Correct Solution:
```
t = int(input())
for i in range(t):
a,b = [int(i) for i in input().split()]
b *= 4
if(a == 0 and b == 0):
print(1)
elif(a == 0):
print(0.5)
else:
ans = 0.5
if(a > b):
ans += (a-b)/a/2 + b/a/4
else:
ans += a/b/4
print(ans)
```
| 104,972 |
Provide tags and a correct Python 3 solution for this coding contest problem.
For some reason in many American cartoons anvils fall from time to time onto heroes' heads. Of course, safes, wardrobes, cruisers, planes fall sometimes too... But anvils do so most of all.
Anvils come in different sizes and shapes. Quite often they get the hero stuck deep in the ground. But have you ever thought who throws anvils from the sky? From what height? We are sure that such questions have never troubled you!
It turns out that throwing an anvil properly is not an easy task at all. Let's describe one of the most popular anvil throwing models.
Let the height p of the potential victim vary in the range [0;a] and the direction of the wind q vary in the range [ - b;b]. p and q could be any real (floating) numbers. Then we can assume that the anvil will fit the toon's head perfectly only if the following equation has at least one real root:
<image>
Determine the probability with which an aim can be successfully hit by an anvil.
You can assume that the p and q coefficients are chosen equiprobably and independently in their ranges.
Input
The first line contains integer t (1 β€ t β€ 10000) β amount of testcases.
Each of the following t lines contain two space-separated integers a and b (0 β€ a, b β€ 106).
Pretests contain all the tests with 0 < a < 10, 0 β€ b < 10.
Output
Print t lines β the probability of a successful anvil hit for each testcase. The absolute or relative error of the answer should not exceed 10 - 6.
Examples
Input
2
4 2
1 2
Output
0.6250000000
0.5312500000
Tags: math, probabilities
Correct Solution:
```
#!/usr/bin/env python3
def solve(a,b):
answer = 0
if ((a>0) and (b>0)):
height = a / 4
if (height <= b):
answer = ((a*b)+0.5*a*height)/(2*b*a)
else:
base = b*4
answer = ((2*a*b)-0.5*base*b)/(2*b*a)
elif (b == 0):
answer = 1.0
elif (a == 0):
answer = 0.5
print("%.10f" % answer)
n = int(input())
for i in range(n):
a,b = map(int, input().split())
solve(a,b)
```
| 104,973 |
Provide tags and a correct Python 3 solution for this coding contest problem.
For some reason in many American cartoons anvils fall from time to time onto heroes' heads. Of course, safes, wardrobes, cruisers, planes fall sometimes too... But anvils do so most of all.
Anvils come in different sizes and shapes. Quite often they get the hero stuck deep in the ground. But have you ever thought who throws anvils from the sky? From what height? We are sure that such questions have never troubled you!
It turns out that throwing an anvil properly is not an easy task at all. Let's describe one of the most popular anvil throwing models.
Let the height p of the potential victim vary in the range [0;a] and the direction of the wind q vary in the range [ - b;b]. p and q could be any real (floating) numbers. Then we can assume that the anvil will fit the toon's head perfectly only if the following equation has at least one real root:
<image>
Determine the probability with which an aim can be successfully hit by an anvil.
You can assume that the p and q coefficients are chosen equiprobably and independently in their ranges.
Input
The first line contains integer t (1 β€ t β€ 10000) β amount of testcases.
Each of the following t lines contain two space-separated integers a and b (0 β€ a, b β€ 106).
Pretests contain all the tests with 0 < a < 10, 0 β€ b < 10.
Output
Print t lines β the probability of a successful anvil hit for each testcase. The absolute or relative error of the answer should not exceed 10 - 6.
Examples
Input
2
4 2
1 2
Output
0.6250000000
0.5312500000
Tags: math, probabilities
Correct Solution:
```
t = int(input())
for _ in range(t):
a, b = map(int, input().split())
if a == 0 and b == 0:
print(1)
elif a == 0:
print(0.5)
elif b == 0:
print(1)
elif a > 4 * b:
print('%.10f' % ((a - b) / a))
else:
print('%.10f' % (a / 16 / b + 0.5))
```
| 104,974 |
Provide tags and a correct Python 3 solution for this coding contest problem.
For some reason in many American cartoons anvils fall from time to time onto heroes' heads. Of course, safes, wardrobes, cruisers, planes fall sometimes too... But anvils do so most of all.
Anvils come in different sizes and shapes. Quite often they get the hero stuck deep in the ground. But have you ever thought who throws anvils from the sky? From what height? We are sure that such questions have never troubled you!
It turns out that throwing an anvil properly is not an easy task at all. Let's describe one of the most popular anvil throwing models.
Let the height p of the potential victim vary in the range [0;a] and the direction of the wind q vary in the range [ - b;b]. p and q could be any real (floating) numbers. Then we can assume that the anvil will fit the toon's head perfectly only if the following equation has at least one real root:
<image>
Determine the probability with which an aim can be successfully hit by an anvil.
You can assume that the p and q coefficients are chosen equiprobably and independently in their ranges.
Input
The first line contains integer t (1 β€ t β€ 10000) β amount of testcases.
Each of the following t lines contain two space-separated integers a and b (0 β€ a, b β€ 106).
Pretests contain all the tests with 0 < a < 10, 0 β€ b < 10.
Output
Print t lines β the probability of a successful anvil hit for each testcase. The absolute or relative error of the answer should not exceed 10 - 6.
Examples
Input
2
4 2
1 2
Output
0.6250000000
0.5312500000
Tags: math, probabilities
Correct Solution:
```
import sys
from array import array # noqa: F401
def input():
return sys.stdin.buffer.readline().decode('utf-8')
t = int(input())
ans = [0.0] * t
for i in range(t):
a, b = map(int, input().split())
if b == 0:
ans[i] = 1.0
elif a == 0:
ans[i] = 0.5
elif a >= 4 * b:
ans[i] = 1.0 - (b / a)
else:
ans[i] = (a * b + a * min(a / 4, b) / 2) / (a * 2 * b)
print(*ans, sep='\n')
```
| 104,975 |
Provide tags and a correct Python 3 solution for this coding contest problem.
For some reason in many American cartoons anvils fall from time to time onto heroes' heads. Of course, safes, wardrobes, cruisers, planes fall sometimes too... But anvils do so most of all.
Anvils come in different sizes and shapes. Quite often they get the hero stuck deep in the ground. But have you ever thought who throws anvils from the sky? From what height? We are sure that such questions have never troubled you!
It turns out that throwing an anvil properly is not an easy task at all. Let's describe one of the most popular anvil throwing models.
Let the height p of the potential victim vary in the range [0;a] and the direction of the wind q vary in the range [ - b;b]. p and q could be any real (floating) numbers. Then we can assume that the anvil will fit the toon's head perfectly only if the following equation has at least one real root:
<image>
Determine the probability with which an aim can be successfully hit by an anvil.
You can assume that the p and q coefficients are chosen equiprobably and independently in their ranges.
Input
The first line contains integer t (1 β€ t β€ 10000) β amount of testcases.
Each of the following t lines contain two space-separated integers a and b (0 β€ a, b β€ 106).
Pretests contain all the tests with 0 < a < 10, 0 β€ b < 10.
Output
Print t lines β the probability of a successful anvil hit for each testcase. The absolute or relative error of the answer should not exceed 10 - 6.
Examples
Input
2
4 2
1 2
Output
0.6250000000
0.5312500000
Tags: math, probabilities
Correct Solution:
```
import sys
lines = int(sys.stdin.readline())
for _ in range(lines):
a, b = map(float, sys.stdin.readline().split(' '))
if b == 0.0:
print(1)
elif a <= 4*b:
print((0.125*a + b) / (2.0*b))
else:
print((a - b) / a)
```
| 104,976 |
Provide tags and a correct Python 3 solution for this coding contest problem.
For some reason in many American cartoons anvils fall from time to time onto heroes' heads. Of course, safes, wardrobes, cruisers, planes fall sometimes too... But anvils do so most of all.
Anvils come in different sizes and shapes. Quite often they get the hero stuck deep in the ground. But have you ever thought who throws anvils from the sky? From what height? We are sure that such questions have never troubled you!
It turns out that throwing an anvil properly is not an easy task at all. Let's describe one of the most popular anvil throwing models.
Let the height p of the potential victim vary in the range [0;a] and the direction of the wind q vary in the range [ - b;b]. p and q could be any real (floating) numbers. Then we can assume that the anvil will fit the toon's head perfectly only if the following equation has at least one real root:
<image>
Determine the probability with which an aim can be successfully hit by an anvil.
You can assume that the p and q coefficients are chosen equiprobably and independently in their ranges.
Input
The first line contains integer t (1 β€ t β€ 10000) β amount of testcases.
Each of the following t lines contain two space-separated integers a and b (0 β€ a, b β€ 106).
Pretests contain all the tests with 0 < a < 10, 0 β€ b < 10.
Output
Print t lines β the probability of a successful anvil hit for each testcase. The absolute or relative error of the answer should not exceed 10 - 6.
Examples
Input
2
4 2
1 2
Output
0.6250000000
0.5312500000
Tags: math, probabilities
Correct Solution:
```
def li():
return list(map(int, input().split(" ")))
for _ in range(int(input())):
a, b=li()
if b != 0 and a != 0:
s = (max(0, a-4*b) + a)/2
s*=min((a/4), b)
ans = 1/2 + s/(2*a*b)
print("{:.8f}".format(ans))
elif b == 0:
print(1)
else:
print(0.5)
```
| 104,977 |
Provide tags and a correct Python 3 solution for this coding contest problem.
For some reason in many American cartoons anvils fall from time to time onto heroes' heads. Of course, safes, wardrobes, cruisers, planes fall sometimes too... But anvils do so most of all.
Anvils come in different sizes and shapes. Quite often they get the hero stuck deep in the ground. But have you ever thought who throws anvils from the sky? From what height? We are sure that such questions have never troubled you!
It turns out that throwing an anvil properly is not an easy task at all. Let's describe one of the most popular anvil throwing models.
Let the height p of the potential victim vary in the range [0;a] and the direction of the wind q vary in the range [ - b;b]. p and q could be any real (floating) numbers. Then we can assume that the anvil will fit the toon's head perfectly only if the following equation has at least one real root:
<image>
Determine the probability with which an aim can be successfully hit by an anvil.
You can assume that the p and q coefficients are chosen equiprobably and independently in their ranges.
Input
The first line contains integer t (1 β€ t β€ 10000) β amount of testcases.
Each of the following t lines contain two space-separated integers a and b (0 β€ a, b β€ 106).
Pretests contain all the tests with 0 < a < 10, 0 β€ b < 10.
Output
Print t lines β the probability of a successful anvil hit for each testcase. The absolute or relative error of the answer should not exceed 10 - 6.
Examples
Input
2
4 2
1 2
Output
0.6250000000
0.5312500000
Tags: math, probabilities
Correct Solution:
```
for i in range(int(input())):
a, b = map(int, input().split(' '))
if b == 0:
print(1)
elif a == 0:
print(1/2)
else:
if 4*b<=a:
print(1-2*b*b/(2*a*b))
else:
print(1-((b+b-a/4)*a/2)/(2*a*b))
```
| 104,978 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For some reason in many American cartoons anvils fall from time to time onto heroes' heads. Of course, safes, wardrobes, cruisers, planes fall sometimes too... But anvils do so most of all.
Anvils come in different sizes and shapes. Quite often they get the hero stuck deep in the ground. But have you ever thought who throws anvils from the sky? From what height? We are sure that such questions have never troubled you!
It turns out that throwing an anvil properly is not an easy task at all. Let's describe one of the most popular anvil throwing models.
Let the height p of the potential victim vary in the range [0;a] and the direction of the wind q vary in the range [ - b;b]. p and q could be any real (floating) numbers. Then we can assume that the anvil will fit the toon's head perfectly only if the following equation has at least one real root:
<image>
Determine the probability with which an aim can be successfully hit by an anvil.
You can assume that the p and q coefficients are chosen equiprobably and independently in their ranges.
Input
The first line contains integer t (1 β€ t β€ 10000) β amount of testcases.
Each of the following t lines contain two space-separated integers a and b (0 β€ a, b β€ 106).
Pretests contain all the tests with 0 < a < 10, 0 β€ b < 10.
Output
Print t lines β the probability of a successful anvil hit for each testcase. The absolute or relative error of the answer should not exceed 10 - 6.
Examples
Input
2
4 2
1 2
Output
0.6250000000
0.5312500000
Submitted Solution:
```
def calArea(a, b):
if a <= 4 * b:
return a * min(b, a / 4) / 2
return b * b * 2 + (a - 4 * b) * b
for _ in range(int(input())):
a, b = map(int, input().split())
if b == 0:
print(1)
elif a == 0:
print(0.5)
else:
print("{:.8f}".format(calArea(a, b) / (2 * a * b) + 0.5))
```
Yes
| 104,979 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For some reason in many American cartoons anvils fall from time to time onto heroes' heads. Of course, safes, wardrobes, cruisers, planes fall sometimes too... But anvils do so most of all.
Anvils come in different sizes and shapes. Quite often they get the hero stuck deep in the ground. But have you ever thought who throws anvils from the sky? From what height? We are sure that such questions have never troubled you!
It turns out that throwing an anvil properly is not an easy task at all. Let's describe one of the most popular anvil throwing models.
Let the height p of the potential victim vary in the range [0;a] and the direction of the wind q vary in the range [ - b;b]. p and q could be any real (floating) numbers. Then we can assume that the anvil will fit the toon's head perfectly only if the following equation has at least one real root:
<image>
Determine the probability with which an aim can be successfully hit by an anvil.
You can assume that the p and q coefficients are chosen equiprobably and independently in their ranges.
Input
The first line contains integer t (1 β€ t β€ 10000) β amount of testcases.
Each of the following t lines contain two space-separated integers a and b (0 β€ a, b β€ 106).
Pretests contain all the tests with 0 < a < 10, 0 β€ b < 10.
Output
Print t lines β the probability of a successful anvil hit for each testcase. The absolute or relative error of the answer should not exceed 10 - 6.
Examples
Input
2
4 2
1 2
Output
0.6250000000
0.5312500000
Submitted Solution:
```
c = int(input())
for cases in range(c):
s = input()
s = s.split(' ')
a = int(s[0])
b = int(s[1])
xx = min(a / 4, b)
if b == 0:
print(1.000000000)
if a == 0 and b != 0:
print(0.500000000)
if a != 0 and b != 0:
print("%.9f" % (1.0 / (2 * a * b) * (xx * a - 2 * xx * xx) + 0.5))
```
Yes
| 104,980 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For some reason in many American cartoons anvils fall from time to time onto heroes' heads. Of course, safes, wardrobes, cruisers, planes fall sometimes too... But anvils do so most of all.
Anvils come in different sizes and shapes. Quite often they get the hero stuck deep in the ground. But have you ever thought who throws anvils from the sky? From what height? We are sure that such questions have never troubled you!
It turns out that throwing an anvil properly is not an easy task at all. Let's describe one of the most popular anvil throwing models.
Let the height p of the potential victim vary in the range [0;a] and the direction of the wind q vary in the range [ - b;b]. p and q could be any real (floating) numbers. Then we can assume that the anvil will fit the toon's head perfectly only if the following equation has at least one real root:
<image>
Determine the probability with which an aim can be successfully hit by an anvil.
You can assume that the p and q coefficients are chosen equiprobably and independently in their ranges.
Input
The first line contains integer t (1 β€ t β€ 10000) β amount of testcases.
Each of the following t lines contain two space-separated integers a and b (0 β€ a, b β€ 106).
Pretests contain all the tests with 0 < a < 10, 0 β€ b < 10.
Output
Print t lines β the probability of a successful anvil hit for each testcase. The absolute or relative error of the answer should not exceed 10 - 6.
Examples
Input
2
4 2
1 2
Output
0.6250000000
0.5312500000
Submitted Solution:
```
for i in range(int(input())):
a, b = map(int, input().split())
print(0.5 + a / (b << 4) if 4 * b > a else 1 - b / a if a else 1)
```
Yes
| 104,981 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For some reason in many American cartoons anvils fall from time to time onto heroes' heads. Of course, safes, wardrobes, cruisers, planes fall sometimes too... But anvils do so most of all.
Anvils come in different sizes and shapes. Quite often they get the hero stuck deep in the ground. But have you ever thought who throws anvils from the sky? From what height? We are sure that such questions have never troubled you!
It turns out that throwing an anvil properly is not an easy task at all. Let's describe one of the most popular anvil throwing models.
Let the height p of the potential victim vary in the range [0;a] and the direction of the wind q vary in the range [ - b;b]. p and q could be any real (floating) numbers. Then we can assume that the anvil will fit the toon's head perfectly only if the following equation has at least one real root:
<image>
Determine the probability with which an aim can be successfully hit by an anvil.
You can assume that the p and q coefficients are chosen equiprobably and independently in their ranges.
Input
The first line contains integer t (1 β€ t β€ 10000) β amount of testcases.
Each of the following t lines contain two space-separated integers a and b (0 β€ a, b β€ 106).
Pretests contain all the tests with 0 < a < 10, 0 β€ b < 10.
Output
Print t lines β the probability of a successful anvil hit for each testcase. The absolute or relative error of the answer should not exceed 10 - 6.
Examples
Input
2
4 2
1 2
Output
0.6250000000
0.5312500000
Submitted Solution:
```
for i in range(int(input())):print("%.8f"%(lambda a,b:1 if a==0==b else (a/b/16+1/2)if b>a/4 else(1-b/a))(*list(map(int,input().split()))[0:2]))
```
Yes
| 104,982 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For some reason in many American cartoons anvils fall from time to time onto heroes' heads. Of course, safes, wardrobes, cruisers, planes fall sometimes too... But anvils do so most of all.
Anvils come in different sizes and shapes. Quite often they get the hero stuck deep in the ground. But have you ever thought who throws anvils from the sky? From what height? We are sure that such questions have never troubled you!
It turns out that throwing an anvil properly is not an easy task at all. Let's describe one of the most popular anvil throwing models.
Let the height p of the potential victim vary in the range [0;a] and the direction of the wind q vary in the range [ - b;b]. p and q could be any real (floating) numbers. Then we can assume that the anvil will fit the toon's head perfectly only if the following equation has at least one real root:
<image>
Determine the probability with which an aim can be successfully hit by an anvil.
You can assume that the p and q coefficients are chosen equiprobably and independently in their ranges.
Input
The first line contains integer t (1 β€ t β€ 10000) β amount of testcases.
Each of the following t lines contain two space-separated integers a and b (0 β€ a, b β€ 106).
Pretests contain all the tests with 0 < a < 10, 0 β€ b < 10.
Output
Print t lines β the probability of a successful anvil hit for each testcase. The absolute or relative error of the answer should not exceed 10 - 6.
Examples
Input
2
4 2
1 2
Output
0.6250000000
0.5312500000
Submitted Solution:
```
def li():
return list(map(int, input().split(" ")))
for _ in range(int(input())):
a, b=li()
if b != 0 and b != 0:
s = (max(0, a-4*b) + a)/2
s*=min((a/4), b)
ans = 1/2 + s/(2*a*b)
print("{:.8f}".format(ans), (max(0, a-4*b) + a)/2)
elif b == 0:
print(1)
else:
print(0.5)
```
No
| 104,983 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For some reason in many American cartoons anvils fall from time to time onto heroes' heads. Of course, safes, wardrobes, cruisers, planes fall sometimes too... But anvils do so most of all.
Anvils come in different sizes and shapes. Quite often they get the hero stuck deep in the ground. But have you ever thought who throws anvils from the sky? From what height? We are sure that such questions have never troubled you!
It turns out that throwing an anvil properly is not an easy task at all. Let's describe one of the most popular anvil throwing models.
Let the height p of the potential victim vary in the range [0;a] and the direction of the wind q vary in the range [ - b;b]. p and q could be any real (floating) numbers. Then we can assume that the anvil will fit the toon's head perfectly only if the following equation has at least one real root:
<image>
Determine the probability with which an aim can be successfully hit by an anvil.
You can assume that the p and q coefficients are chosen equiprobably and independently in their ranges.
Input
The first line contains integer t (1 β€ t β€ 10000) β amount of testcases.
Each of the following t lines contain two space-separated integers a and b (0 β€ a, b β€ 106).
Pretests contain all the tests with 0 < a < 10, 0 β€ b < 10.
Output
Print t lines β the probability of a successful anvil hit for each testcase. The absolute or relative error of the answer should not exceed 10 - 6.
Examples
Input
2
4 2
1 2
Output
0.6250000000
0.5312500000
Submitted Solution:
```
t = int(input())
for _ in range(t):
a, b = map(int, input().split())
if a == 0 and b == 0:
print(1)
elif a == 0:
print(0.5)
elif b == 0:
print(1)
elif a > 4 * b:
print('%.10f' % ((a - 4 * b) / a + 0.5 + b / a))
else:
print('%.10f' % (a / 16 / b + 0.5))
```
No
| 104,984 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For some reason in many American cartoons anvils fall from time to time onto heroes' heads. Of course, safes, wardrobes, cruisers, planes fall sometimes too... But anvils do so most of all.
Anvils come in different sizes and shapes. Quite often they get the hero stuck deep in the ground. But have you ever thought who throws anvils from the sky? From what height? We are sure that such questions have never troubled you!
It turns out that throwing an anvil properly is not an easy task at all. Let's describe one of the most popular anvil throwing models.
Let the height p of the potential victim vary in the range [0;a] and the direction of the wind q vary in the range [ - b;b]. p and q could be any real (floating) numbers. Then we can assume that the anvil will fit the toon's head perfectly only if the following equation has at least one real root:
<image>
Determine the probability with which an aim can be successfully hit by an anvil.
You can assume that the p and q coefficients are chosen equiprobably and independently in their ranges.
Input
The first line contains integer t (1 β€ t β€ 10000) β amount of testcases.
Each of the following t lines contain two space-separated integers a and b (0 β€ a, b β€ 106).
Pretests contain all the tests with 0 < a < 10, 0 β€ b < 10.
Output
Print t lines β the probability of a successful anvil hit for each testcase. The absolute or relative error of the answer should not exceed 10 - 6.
Examples
Input
2
4 2
1 2
Output
0.6250000000
0.5312500000
Submitted Solution:
```
t = int( input() )
for i in range( t ):
a, b = list( map( int, input().split() ) )
if a == 0:
print( 0.5 )
elif b == 0:
print( 1 )
else:
if a < 4*b:
ans = ( 0.5 + a/(16*b) )
else:
ans = 1 - b/a
print( ans )
```
No
| 104,985 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For some reason in many American cartoons anvils fall from time to time onto heroes' heads. Of course, safes, wardrobes, cruisers, planes fall sometimes too... But anvils do so most of all.
Anvils come in different sizes and shapes. Quite often they get the hero stuck deep in the ground. But have you ever thought who throws anvils from the sky? From what height? We are sure that such questions have never troubled you!
It turns out that throwing an anvil properly is not an easy task at all. Let's describe one of the most popular anvil throwing models.
Let the height p of the potential victim vary in the range [0;a] and the direction of the wind q vary in the range [ - b;b]. p and q could be any real (floating) numbers. Then we can assume that the anvil will fit the toon's head perfectly only if the following equation has at least one real root:
<image>
Determine the probability with which an aim can be successfully hit by an anvil.
You can assume that the p and q coefficients are chosen equiprobably and independently in their ranges.
Input
The first line contains integer t (1 β€ t β€ 10000) β amount of testcases.
Each of the following t lines contain two space-separated integers a and b (0 β€ a, b β€ 106).
Pretests contain all the tests with 0 < a < 10, 0 β€ b < 10.
Output
Print t lines β the probability of a successful anvil hit for each testcase. The absolute or relative error of the answer should not exceed 10 - 6.
Examples
Input
2
4 2
1 2
Output
0.6250000000
0.5312500000
Submitted Solution:
```
from fractions import Fraction
t = int(input())
for _ in range(t):
a, b = map(lambda x: Fraction(x), input().split(' '))
if b == 0:
print(1)
continue
elif a == 0:
print(0)
continue
up = a * (b + b + a / 4) / 2 - max(0, a - 4 * b) * (a / 4 - b) / 2
down = a * 2 * b
print(float(up/down))
```
No
| 104,986 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Some natural number was written on the board. Its sum of digits was not less than k. But you were distracted a bit, and someone changed this number to n, replacing some digits with others. It's known that the length of the number didn't change.
You have to find the minimum number of digits in which these two numbers can differ.
Input
The first line contains integer k (1 β€ k β€ 109).
The second line contains integer n (1 β€ n < 10100000).
There are no leading zeros in n. It's guaranteed that this situation is possible.
Output
Print the minimum number of digits in which the initial number and n can differ.
Examples
Input
3
11
Output
1
Input
3
99
Output
0
Note
In the first example, the initial number could be 12.
In the second example the sum of the digits of n is not less than k. The initial number could be equal to n.
Tags: greedy
Correct Solution:
```
k = int(input())
n = int(input())
digits = [0] * 10
suma = 0
for i in str(n):
digits[int(i)] += 1
suma += int(i)
answer = 0
while suma < k:
minimum_i = 0
for i in range(0, len(digits)):
if digits[i] > 0:
minimum_i = i
digits[i] -= 1
break
answer += 1
suma += 9 - minimum_i
print(answer)
```
| 104,987 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Some natural number was written on the board. Its sum of digits was not less than k. But you were distracted a bit, and someone changed this number to n, replacing some digits with others. It's known that the length of the number didn't change.
You have to find the minimum number of digits in which these two numbers can differ.
Input
The first line contains integer k (1 β€ k β€ 109).
The second line contains integer n (1 β€ n < 10100000).
There are no leading zeros in n. It's guaranteed that this situation is possible.
Output
Print the minimum number of digits in which the initial number and n can differ.
Examples
Input
3
11
Output
1
Input
3
99
Output
0
Note
In the first example, the initial number could be 12.
In the second example the sum of the digits of n is not less than k. The initial number could be equal to n.
Tags: greedy
Correct Solution:
```
k = int(input())
n = input()
_sum = 0
data = []
for x in n:
data.append(int(x))
_sum = _sum + int(x)
if _sum >= k:
print('0')
else:
_sum = k - _sum
data.sort()
_ans = 0
for x in data:
_ans = _ans + 1
_sum = _sum - 9 + x
if _sum <= 0:
break
print(_ans)
```
| 104,988 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Some natural number was written on the board. Its sum of digits was not less than k. But you were distracted a bit, and someone changed this number to n, replacing some digits with others. It's known that the length of the number didn't change.
You have to find the minimum number of digits in which these two numbers can differ.
Input
The first line contains integer k (1 β€ k β€ 109).
The second line contains integer n (1 β€ n < 10100000).
There are no leading zeros in n. It's guaranteed that this situation is possible.
Output
Print the minimum number of digits in which the initial number and n can differ.
Examples
Input
3
11
Output
1
Input
3
99
Output
0
Note
In the first example, the initial number could be 12.
In the second example the sum of the digits of n is not less than k. The initial number could be equal to n.
Tags: greedy
Correct Solution:
```
k = int(input())
n = input()
#print(len(n))
def digitsum(s):
su = 0
for i in range(len(s)):
su += int(s[i])
return su
dig = digitsum(n)
maxpos = 9*len(n)
n = list(map(int, n))
#print(n)
n.sort()
if(dig >= k):
print(0)
else:
rep = 0
for i in range(len(n)):
diff = 9 - int(n[i])
dig = dig + diff
rep += 1
if(dig >= k):
break
print(rep)
```
| 104,989 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Some natural number was written on the board. Its sum of digits was not less than k. But you were distracted a bit, and someone changed this number to n, replacing some digits with others. It's known that the length of the number didn't change.
You have to find the minimum number of digits in which these two numbers can differ.
Input
The first line contains integer k (1 β€ k β€ 109).
The second line contains integer n (1 β€ n < 10100000).
There are no leading zeros in n. It's guaranteed that this situation is possible.
Output
Print the minimum number of digits in which the initial number and n can differ.
Examples
Input
3
11
Output
1
Input
3
99
Output
0
Note
In the first example, the initial number could be 12.
In the second example the sum of the digits of n is not less than k. The initial number could be equal to n.
Tags: greedy
Correct Solution:
```
k = int(input())
s = input()
# s = str(n)
c = 0
l = 0
for i in s:
c += int(i)
if c >= k:
print(0)
else:
c = k - c
q = sorted(list(s))
for i in range(len(q)):
p = min(9 - int(q[i]), c)
c -= p
l += 1
if c <= 0:
break
print(l)
```
| 104,990 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Some natural number was written on the board. Its sum of digits was not less than k. But you were distracted a bit, and someone changed this number to n, replacing some digits with others. It's known that the length of the number didn't change.
You have to find the minimum number of digits in which these two numbers can differ.
Input
The first line contains integer k (1 β€ k β€ 109).
The second line contains integer n (1 β€ n < 10100000).
There are no leading zeros in n. It's guaranteed that this situation is possible.
Output
Print the minimum number of digits in which the initial number and n can differ.
Examples
Input
3
11
Output
1
Input
3
99
Output
0
Note
In the first example, the initial number could be 12.
In the second example the sum of the digits of n is not less than k. The initial number could be equal to n.
Tags: greedy
Correct Solution:
```
k = int(input())
n = input().split()[0]
s = 0
dic = dict()
dic[0] = 0
dic[1] = 0
dic[2] = 0
dic[3] = 0
dic[4] = 0
dic[5] = 0
dic[6] = 0
dic[7] = 0
dic[8] = 0
dic[9] = 0
for i in n:
a = int(i)
s += a
dic[a] += 1
ans = 0
while s<k:
ans += 1
for i in range(10):
if dic[i]:
s+=9-i
dic[i]-=1
break
print(ans)
```
| 104,991 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Some natural number was written on the board. Its sum of digits was not less than k. But you were distracted a bit, and someone changed this number to n, replacing some digits with others. It's known that the length of the number didn't change.
You have to find the minimum number of digits in which these two numbers can differ.
Input
The first line contains integer k (1 β€ k β€ 109).
The second line contains integer n (1 β€ n < 10100000).
There are no leading zeros in n. It's guaranteed that this situation is possible.
Output
Print the minimum number of digits in which the initial number and n can differ.
Examples
Input
3
11
Output
1
Input
3
99
Output
0
Note
In the first example, the initial number could be 12.
In the second example the sum of the digits of n is not less than k. The initial number could be equal to n.
Tags: greedy
Correct Solution:
```
k = int(input())
n = input()
a = list(map(int,n))
l = sum(a)
changed = 0
if l < k:
for num in sorted(a):
l = l + 9 - num
changed = changed + 1
if l >= k:
break
print(changed)
```
| 104,992 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Some natural number was written on the board. Its sum of digits was not less than k. But you were distracted a bit, and someone changed this number to n, replacing some digits with others. It's known that the length of the number didn't change.
You have to find the minimum number of digits in which these two numbers can differ.
Input
The first line contains integer k (1 β€ k β€ 109).
The second line contains integer n (1 β€ n < 10100000).
There are no leading zeros in n. It's guaranteed that this situation is possible.
Output
Print the minimum number of digits in which the initial number and n can differ.
Examples
Input
3
11
Output
1
Input
3
99
Output
0
Note
In the first example, the initial number could be 12.
In the second example the sum of the digits of n is not less than k. The initial number could be equal to n.
Tags: greedy
Correct Solution:
```
k = int(input())
n = input()
sum = 0
count = [0]*10
moves = 0
for a in reversed(n) :
sum += int(a)
count[int(a)]+=1
if sum >= k :
print("0")
else :
for i in range(10) :
if count[i] !=0 and ((10-i-1)*count[i])+sum >= k :
t = int((k-sum)/(10-i-1))
if t*(10-i-1)+sum >= k :
moves += t
else :
moves += t+1
break
else :
sum += count[i]*(10-i-1)
moves+=count[i]
print(moves)
```
| 104,993 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Some natural number was written on the board. Its sum of digits was not less than k. But you were distracted a bit, and someone changed this number to n, replacing some digits with others. It's known that the length of the number didn't change.
You have to find the minimum number of digits in which these two numbers can differ.
Input
The first line contains integer k (1 β€ k β€ 109).
The second line contains integer n (1 β€ n < 10100000).
There are no leading zeros in n. It's guaranteed that this situation is possible.
Output
Print the minimum number of digits in which the initial number and n can differ.
Examples
Input
3
11
Output
1
Input
3
99
Output
0
Note
In the first example, the initial number could be 12.
In the second example the sum of the digits of n is not less than k. The initial number could be equal to n.
Tags: greedy
Correct Solution:
```
k = int(input())
n = list(map(int,input()))
a = [0]*10
s = 0
for i in n:
a[i] += 1
s += i
ans = 0
ind = 0
while s < k:
while a[ind] == 0:
ind += 1
a[ind] -= 1
s -= ind
s += 9
ans += 1
print(ans)
```
| 104,994 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Some natural number was written on the board. Its sum of digits was not less than k. But you were distracted a bit, and someone changed this number to n, replacing some digits with others. It's known that the length of the number didn't change.
You have to find the minimum number of digits in which these two numbers can differ.
Input
The first line contains integer k (1 β€ k β€ 109).
The second line contains integer n (1 β€ n < 10100000).
There are no leading zeros in n. It's guaranteed that this situation is possible.
Output
Print the minimum number of digits in which the initial number and n can differ.
Examples
Input
3
11
Output
1
Input
3
99
Output
0
Note
In the first example, the initial number could be 12.
In the second example the sum of the digits of n is not less than k. The initial number could be equal to n.
Submitted Solution:
```
k = int(input())
n = list(map(int, sorted(input())))
s = sum(n)
idx = 0
res = 0
while k > s:
s += 9 - n[idx]
res += 1
idx += 1
print(res)
```
Yes
| 104,995 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Some natural number was written on the board. Its sum of digits was not less than k. But you were distracted a bit, and someone changed this number to n, replacing some digits with others. It's known that the length of the number didn't change.
You have to find the minimum number of digits in which these two numbers can differ.
Input
The first line contains integer k (1 β€ k β€ 109).
The second line contains integer n (1 β€ n < 10100000).
There are no leading zeros in n. It's guaranteed that this situation is possible.
Output
Print the minimum number of digits in which the initial number and n can differ.
Examples
Input
3
11
Output
1
Input
3
99
Output
0
Note
In the first example, the initial number could be 12.
In the second example the sum of the digits of n is not less than k. The initial number could be equal to n.
Submitted Solution:
```
from collections import Counter
import math
k, n = int(input()), input()
ns = Counter(n)
# print(ns)
cnt, s = 0, 0
for x in ns:
s += int(x) * ns[x]
k -= s
if k <= 0:
print(0)
exit(0)
for x in sorted(ns):
if math.ceil(k / (9-int(x))) > ns[x] and int(x) != 9:
cnt += ns[x]
k -= ns[x] * (9-int(x))
else:
cnt += math.ceil(k / (9-int(x)))
break
print(cnt)
```
Yes
| 104,996 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Some natural number was written on the board. Its sum of digits was not less than k. But you were distracted a bit, and someone changed this number to n, replacing some digits with others. It's known that the length of the number didn't change.
You have to find the minimum number of digits in which these two numbers can differ.
Input
The first line contains integer k (1 β€ k β€ 109).
The second line contains integer n (1 β€ n < 10100000).
There are no leading zeros in n. It's guaranteed that this situation is possible.
Output
Print the minimum number of digits in which the initial number and n can differ.
Examples
Input
3
11
Output
1
Input
3
99
Output
0
Note
In the first example, the initial number could be 12.
In the second example the sum of the digits of n is not less than k. The initial number could be equal to n.
Submitted Solution:
```
k = int(input())
n = sorted(map(int, input()))
s = sum(n)
i = 0
while s < k:
s += 9 - n[i]
i += 1
print(i)
```
Yes
| 104,997 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Some natural number was written on the board. Its sum of digits was not less than k. But you were distracted a bit, and someone changed this number to n, replacing some digits with others. It's known that the length of the number didn't change.
You have to find the minimum number of digits in which these two numbers can differ.
Input
The first line contains integer k (1 β€ k β€ 109).
The second line contains integer n (1 β€ n < 10100000).
There are no leading zeros in n. It's guaranteed that this situation is possible.
Output
Print the minimum number of digits in which the initial number and n can differ.
Examples
Input
3
11
Output
1
Input
3
99
Output
0
Note
In the first example, the initial number could be 12.
In the second example the sum of the digits of n is not less than k. The initial number could be equal to n.
Submitted Solution:
```
I = lambda: list(map(int, input().split()))
k = int(input())
n = [9] + sorted(map(int, input()))
r = k-sum(n[1:])
for i, nn in enumerate(n):
r -= 9-nn
if r<1:
print(i)
break
```
Yes
| 104,998 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Some natural number was written on the board. Its sum of digits was not less than k. But you were distracted a bit, and someone changed this number to n, replacing some digits with others. It's known that the length of the number didn't change.
You have to find the minimum number of digits in which these two numbers can differ.
Input
The first line contains integer k (1 β€ k β€ 109).
The second line contains integer n (1 β€ n < 10100000).
There are no leading zeros in n. It's guaranteed that this situation is possible.
Output
Print the minimum number of digits in which the initial number and n can differ.
Examples
Input
3
11
Output
1
Input
3
99
Output
0
Note
In the first example, the initial number could be 12.
In the second example the sum of the digits of n is not less than k. The initial number could be equal to n.
Submitted Solution:
```
k = int(input())
s = int(input())
su = sum(map(int, str(s)))
if su >= k:
print(0)
else:
ss = str(s)[::-1]
ans = 0
for i in range(len(ss)):
tmp = min(9-int(ss[i]),k - su)
su += tmp
ans += pow(10, i) * tmp
print(ans)
```
No
| 104,999 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.