text stringlengths 198 433k | conversation_id int64 0 109k |
|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n lights aligned in a row. These lights are numbered 1 to n from left to right. Initially some of the lights are switched on. Shaass wants to switch all the lights on. At each step he can switch a light on (this light should be switched off at that moment) if there's at least one adjacent light which is already switched on.
He knows the initial state of lights and he's wondering how many different ways there exist to switch all the lights on. Please find the required number of ways modulo 1000000007 (109 + 7).
Input
The first line of the input contains two integers n and m where n is the number of lights in the sequence and m is the number of lights which are initially switched on, (1 β€ n β€ 1000, 1 β€ m β€ n). The second line contains m distinct integers, each between 1 to n inclusive, denoting the indices of lights which are initially switched on.
Output
In the only line of the output print the number of different possible ways to switch on all the lights modulo 1000000007 (109 + 7).
Examples
Input
3 1
1
Output
1
Input
4 2
1 4
Output
2
Input
11 2
4 8
Output
6720
Submitted Solution:
```
import math
def solve( n, list1):
list1.sort()
inf = int(1e9 + 7)
t1 = [list1[0] - 1, n - list1[-1]]
t2 = []
for i in range(1, len(list1)):
t2.append((list1[i] - list1[i - 1] - 1))
num1 = 1
for i in range(n - len(list1)):
num1 = num1 * (i + 1)
num1 = num1 % inf
num2 = 1
num2 = math.factorial(t1[0]) % inf
num2 = num2 % inf
num2 = num2 * math.factorial(t1[1]) % inf
num2 = num2 % inf
for i in range(len(t2)):
num2 = num2 * math.factorial(t2[i])
num2 = num2 % inf
num2 = pow(num2, inf - 2, inf)
num3 = 1
for i in range(len(t2)):
num3 = (num3 * pow(2, t2[i] - 1, inf)) % inf
num1 = num1 * num2
num1 = num1 % inf
num1 = num1 * num3
num1 = num1 % inf
return int(num1)
n,m = map(int,input().split())
list1 = list(map(int,input().split()))
print(solve(n,list1))
```
No
| 14,500 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n lights aligned in a row. These lights are numbered 1 to n from left to right. Initially some of the lights are switched on. Shaass wants to switch all the lights on. At each step he can switch a light on (this light should be switched off at that moment) if there's at least one adjacent light which is already switched on.
He knows the initial state of lights and he's wondering how many different ways there exist to switch all the lights on. Please find the required number of ways modulo 1000000007 (109 + 7).
Input
The first line of the input contains two integers n and m where n is the number of lights in the sequence and m is the number of lights which are initially switched on, (1 β€ n β€ 1000, 1 β€ m β€ n). The second line contains m distinct integers, each between 1 to n inclusive, denoting the indices of lights which are initially switched on.
Output
In the only line of the output print the number of different possible ways to switch on all the lights modulo 1000000007 (109 + 7).
Examples
Input
3 1
1
Output
1
Input
4 2
1 4
Output
2
Input
11 2
4 8
Output
6720
Submitted Solution:
```
pri=pow(10,9)+7
p=pri
fac=[1 for i in range((10**6)+1)]
for i in range(2,len(fac)):
fac[i]=(fac[i-1]*(i%pri))%pri
def modi(x):
return (pow(x,p-2,p))%p;
def ncr(n,r):
x=(fac[n]*((modi(fac[r])%p)*(modi(fac[n-r])%p))%p)%p
return x;
n,m=map(int,input().split())
z=list(map(int,input().split()))
ans=[]
for i in range(len(z)):
if(i==0):
ans.append(z[0]-1)
else:
ans.append(z[i]-z[i-1]-1)
ans.append(n-z[-1])
temp=[]
for i in range(len(ans)):
if(i==0 or i==len(ans)-1):
temp.append(1)
else:
temp.append(pow(2,max(0,ans[i]-1),pri))
seats=n-m
count=1
for i in range(len(ans)):
count=count*ncr(seats,ans[i])
seats-=ans[i]
count%=pri
for i in range(len(temp)):
count=count*temp[i]
count%=pri
print(count)
```
No
| 14,501 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first n. He writes down the following sequence of numbers: firstly all odd integers from 1 to n (in ascending order), then all even integers from 1 to n (also in ascending order). Help our hero to find out which number will stand at the position number k.
Input
The only line of input contains integers n and k (1 β€ k β€ n β€ 1012).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
Output
Print the number that will stand at the position number k after Volodya's manipulations.
Examples
Input
10 3
Output
5
Input
7 7
Output
6
Note
In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5.
Tags: math
Correct Solution:
```
n,k = [int(x) for x in input().split()]
value=int(n/2)
even=value
odd=value
if int(n%2) == 1:
odd+=1
if k<=odd:
print(2*k-1)
else:
t=(k-odd)
print(2*t)
```
| 14,502 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first n. He writes down the following sequence of numbers: firstly all odd integers from 1 to n (in ascending order), then all even integers from 1 to n (also in ascending order). Help our hero to find out which number will stand at the position number k.
Input
The only line of input contains integers n and k (1 β€ k β€ n β€ 1012).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
Output
Print the number that will stand at the position number k after Volodya's manipulations.
Examples
Input
10 3
Output
5
Input
7 7
Output
6
Note
In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5.
Tags: math
Correct Solution:
```
n, k = map(int, input().split())
if k > (n - n // 2):
print((k - n + n // 2) * 2)
else:
print(k * 2 - 1)
```
| 14,503 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first n. He writes down the following sequence of numbers: firstly all odd integers from 1 to n (in ascending order), then all even integers from 1 to n (also in ascending order). Help our hero to find out which number will stand at the position number k.
Input
The only line of input contains integers n and k (1 β€ k β€ n β€ 1012).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
Output
Print the number that will stand at the position number k after Volodya's manipulations.
Examples
Input
10 3
Output
5
Input
7 7
Output
6
Note
In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5.
Tags: math
Correct Solution:
```
a,b=map(int,input().split())
c=b-(a+1)//2
if c>0:
print(c*2)
else :
print(b*2-1)
```
| 14,504 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first n. He writes down the following sequence of numbers: firstly all odd integers from 1 to n (in ascending order), then all even integers from 1 to n (also in ascending order). Help our hero to find out which number will stand at the position number k.
Input
The only line of input contains integers n and k (1 β€ k β€ n β€ 1012).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
Output
Print the number that will stand at the position number k after Volodya's manipulations.
Examples
Input
10 3
Output
5
Input
7 7
Output
6
Note
In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5.
Tags: math
Correct Solution:
```
# import sys
# sys.stdin = open("test.in","r")
# sys.stdout = open("test.out","w")
n,k=map(int,input().split())
if n%2==1:
if k<=n//2+1:
print(2*k-1)
else:
k-=n//2+1
print(2*k)
else:
if k<=n//2:
print(2*k-1)
else:
k-=n//2
print(2*k)
```
| 14,505 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first n. He writes down the following sequence of numbers: firstly all odd integers from 1 to n (in ascending order), then all even integers from 1 to n (also in ascending order). Help our hero to find out which number will stand at the position number k.
Input
The only line of input contains integers n and k (1 β€ k β€ n β€ 1012).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
Output
Print the number that will stand at the position number k after Volodya's manipulations.
Examples
Input
10 3
Output
5
Input
7 7
Output
6
Note
In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5.
Tags: math
Correct Solution:
```
n,k= map(int, input().split())
last_index=0
if(n%2!=0):
last_index=(n+1)/2
else:
last_index=n/2
if(k>last_index):
print(int(k-last_index)*2)
else:
print(int(k*2)-1)
```
| 14,506 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first n. He writes down the following sequence of numbers: firstly all odd integers from 1 to n (in ascending order), then all even integers from 1 to n (also in ascending order). Help our hero to find out which number will stand at the position number k.
Input
The only line of input contains integers n and k (1 β€ k β€ n β€ 1012).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
Output
Print the number that will stand at the position number k after Volodya's manipulations.
Examples
Input
10 3
Output
5
Input
7 7
Output
6
Note
In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5.
Tags: math
Correct Solution:
```
string = input().split()
n = int(string[0])
k = int(string[1])
if(n%2 == 0):
if(k>(n/2)):
print(int(2*(k-n/2)))
else:
print(int(2*k-1))
n1 = (int)((n+1)/2)
if(n%2!=0 and k>n1):
print(int(2*(k-n1)))
if(n%2!=0 and k<=n1):
print(int(2*k-1))
```
| 14,507 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first n. He writes down the following sequence of numbers: firstly all odd integers from 1 to n (in ascending order), then all even integers from 1 to n (also in ascending order). Help our hero to find out which number will stand at the position number k.
Input
The only line of input contains integers n and k (1 β€ k β€ n β€ 1012).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
Output
Print the number that will stand at the position number k after Volodya's manipulations.
Examples
Input
10 3
Output
5
Input
7 7
Output
6
Note
In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5.
Tags: math
Correct Solution:
```
s=input('')
n,k=s.split(' ')
n=int(n)
k=int(k)
#print(type(n),type(k))
if(int(n%2)==0):
odd=int(n/2)
even=int(n/2)
else:
odd=int(n/2+1)
even=int(n/2)
#print(even,odd)
if(k<=odd):
value=2*(k-1)+1
else:
value=2*(k-odd)
print(value)
```
| 14,508 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first n. He writes down the following sequence of numbers: firstly all odd integers from 1 to n (in ascending order), then all even integers from 1 to n (also in ascending order). Help our hero to find out which number will stand at the position number k.
Input
The only line of input contains integers n and k (1 β€ k β€ n β€ 1012).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
Output
Print the number that will stand at the position number k after Volodya's manipulations.
Examples
Input
10 3
Output
5
Input
7 7
Output
6
Note
In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5.
Tags: math
Correct Solution:
```
n,b = map(int,input().split())
if n%2==0:
z = int(n/2)
else:
z = int(n/2)+1
if b<=z:print(2*b-1)
else:print((b-z)*2)
```
| 14,509 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first n. He writes down the following sequence of numbers: firstly all odd integers from 1 to n (in ascending order), then all even integers from 1 to n (also in ascending order). Help our hero to find out which number will stand at the position number k.
Input
The only line of input contains integers n and k (1 β€ k β€ n β€ 1012).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
Output
Print the number that will stand at the position number k after Volodya's manipulations.
Examples
Input
10 3
Output
5
Input
7 7
Output
6
Note
In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5.
Submitted Solution:
```
nk = [int(x) for x in input().split()]
n, k =nk[0], nk[1]
if 2 * k - 1 <= n:
print(2 * k - 1)
else:
print(2 * (n // 2) - 2 * (n - k))
```
Yes
| 14,510 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first n. He writes down the following sequence of numbers: firstly all odd integers from 1 to n (in ascending order), then all even integers from 1 to n (also in ascending order). Help our hero to find out which number will stand at the position number k.
Input
The only line of input contains integers n and k (1 β€ k β€ n β€ 1012).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
Output
Print the number that will stand at the position number k after Volodya's manipulations.
Examples
Input
10 3
Output
5
Input
7 7
Output
6
Note
In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5.
Submitted Solution:
```
import math
n, k = input().split(' ')
n = int(n)
k = int(k)
if k <= math.ceil(n / 2):
print(2*k - 1)
else:
print(2*(k - math.ceil(n / 2)))
```
Yes
| 14,511 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first n. He writes down the following sequence of numbers: firstly all odd integers from 1 to n (in ascending order), then all even integers from 1 to n (also in ascending order). Help our hero to find out which number will stand at the position number k.
Input
The only line of input contains integers n and k (1 β€ k β€ n β€ 1012).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
Output
Print the number that will stand at the position number k after Volodya's manipulations.
Examples
Input
10 3
Output
5
Input
7 7
Output
6
Note
In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5.
Submitted Solution:
```
n,k=map(int,input().split())
odd=(n+1)//2
if(k<=odd):
print(int(2*k-1))
else:
print(int((k-odd)*2))
```
Yes
| 14,512 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first n. He writes down the following sequence of numbers: firstly all odd integers from 1 to n (in ascending order), then all even integers from 1 to n (also in ascending order). Help our hero to find out which number will stand at the position number k.
Input
The only line of input contains integers n and k (1 β€ k β€ n β€ 1012).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
Output
Print the number that will stand at the position number k after Volodya's manipulations.
Examples
Input
10 3
Output
5
Input
7 7
Output
6
Note
In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5.
Submitted Solution:
```
a,b=input().split()
a=int(a)
b=int(b)
if a%2==0:
if b<=(a/2):
print(2*b-1)
else:
print(int(2*(b-(a/2))))
else:
if b<=((a+1)/2):
print(2*b-1)
else:
print(int(2*(b-((a+1)/2))))
```
Yes
| 14,513 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first n. He writes down the following sequence of numbers: firstly all odd integers from 1 to n (in ascending order), then all even integers from 1 to n (also in ascending order). Help our hero to find out which number will stand at the position number k.
Input
The only line of input contains integers n and k (1 β€ k β€ n β€ 1012).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
Output
Print the number that will stand at the position number k after Volodya's manipulations.
Examples
Input
10 3
Output
5
Input
7 7
Output
6
Note
In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5.
Submitted Solution:
```
n,k=map(int,input().split())
if k<(n//2 + n%2):
print(2*(k-1)+1)
else:
k-=n//2 + n%2
print(2*k)
```
No
| 14,514 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first n. He writes down the following sequence of numbers: firstly all odd integers from 1 to n (in ascending order), then all even integers from 1 to n (also in ascending order). Help our hero to find out which number will stand at the position number k.
Input
The only line of input contains integers n and k (1 β€ k β€ n β€ 1012).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
Output
Print the number that will stand at the position number k after Volodya's manipulations.
Examples
Input
10 3
Output
5
Input
7 7
Output
6
Note
In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5.
Submitted Solution:
```
a,b=map(int,input().split(" "))
if(b<=(a+1)/2):
print(b*2-1)
else:
print((b-(a+1))/2)
```
No
| 14,515 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first n. He writes down the following sequence of numbers: firstly all odd integers from 1 to n (in ascending order), then all even integers from 1 to n (also in ascending order). Help our hero to find out which number will stand at the position number k.
Input
The only line of input contains integers n and k (1 β€ k β€ n β€ 1012).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
Output
Print the number that will stand at the position number k after Volodya's manipulations.
Examples
Input
10 3
Output
5
Input
7 7
Output
6
Note
In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5.
Submitted Solution:
```
n,k=[int(i) for i in input().split(' ')]
if 2*(k-1)+1>n:
print(2*k%n)
else:
print(2*(k-1)+1)
```
No
| 14,516 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first n. He writes down the following sequence of numbers: firstly all odd integers from 1 to n (in ascending order), then all even integers from 1 to n (also in ascending order). Help our hero to find out which number will stand at the position number k.
Input
The only line of input contains integers n and k (1 β€ k β€ n β€ 1012).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
Output
Print the number that will stand at the position number k after Volodya's manipulations.
Examples
Input
10 3
Output
5
Input
7 7
Output
6
Note
In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5.
Submitted Solution:
```
n,k=map(int,input().split())
a=[]
for i in range(1,n,2):
a.append(i)
for i in range(0,n,2):
a.append(i)
print(a[k-1])
```
No
| 14,517 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Xenia the mathematician has a sequence consisting of n (n is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three a, b, c the following conditions held:
* a < b < c;
* a divides b, b divides c.
Naturally, Xenia wants each element of the sequence to belong to exactly one group of three. Thus, if the required partition exists, then it has <image> groups of three.
Help Xenia, find the required partition or else say that it doesn't exist.
Input
The first line contains integer n (3 β€ n β€ 99999) β the number of elements in the sequence. The next line contains n positive integers, each of them is at most 7.
It is guaranteed that n is divisible by 3.
Output
If the required partition exists, print <image> groups of three. Print each group as values of the elements it contains. You should print values in increasing order. Separate the groups and integers in groups by whitespaces. If there are multiple solutions, you can print any of them.
If there is no solution, print -1.
Examples
Input
6
1 1 1 2 2 2
Output
-1
Input
6
2 2 1 1 4 6
Output
1 2 4
1 2 6
Tags: greedy, implementation
Correct Solution:
```
n = int(input())
arr = list(map(int, input().split()))
track = [0] * 7
for i in arr:
track[i - 1] += 1
if(track[6] != 0 or track[4] != 0):
print(-1)
else:
c1 = track[0] == (track[3] + track[5])
if(c1):
_124 = track[3]
track[1] -= _124
if(track[1] >= 0):
#use remaining 2s on 126
_126 = track[1]
#subtract 126 pairings from 6
track[5] -= _126
if(track[5] == track[2]):
#works
_136 = track[2]
for i in range(_124):
print(1,2,4)
for i in range(_126):
print(1,2,6)
for i in range(_136):
print(1,3,6)
else:
print(-1)
else:
print(-1)
else:
print(-1)
```
| 14,518 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Xenia the mathematician has a sequence consisting of n (n is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three a, b, c the following conditions held:
* a < b < c;
* a divides b, b divides c.
Naturally, Xenia wants each element of the sequence to belong to exactly one group of three. Thus, if the required partition exists, then it has <image> groups of three.
Help Xenia, find the required partition or else say that it doesn't exist.
Input
The first line contains integer n (3 β€ n β€ 99999) β the number of elements in the sequence. The next line contains n positive integers, each of them is at most 7.
It is guaranteed that n is divisible by 3.
Output
If the required partition exists, print <image> groups of three. Print each group as values of the elements it contains. You should print values in increasing order. Separate the groups and integers in groups by whitespaces. If there are multiple solutions, you can print any of them.
If there is no solution, print -1.
Examples
Input
6
1 1 1 2 2 2
Output
-1
Input
6
2 2 1 1 4 6
Output
1 2 4
1 2 6
Tags: greedy, implementation
Correct Solution:
```
from collections import Counter
n=int(input())
arr=list(map(int,input().split()))
arr.append(2)
arr.append(3)
arr.append(4)
arr.append(6)
c=Counter(arr)
c[2]-=1
c[3]-=1
c[4]-=1
c[6]-=1
if c[1]!=n//3 or c[1]+c[2]+c[3]+c[4]+c[6]!=n:
print(-1)
else:
if c[4]>c[2]:
print(-1)
else:
if c[6]!=(-c[4]+c[2])+c[3]:
print(-1)
else:
for i in range(c[4]):
print(1,2,4)
c[2]-=c[4]
for i in range(c[2]):
print(1,2,6)
for i in range(c[3]):
print(1,3,6)
```
| 14,519 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Xenia the mathematician has a sequence consisting of n (n is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three a, b, c the following conditions held:
* a < b < c;
* a divides b, b divides c.
Naturally, Xenia wants each element of the sequence to belong to exactly one group of three. Thus, if the required partition exists, then it has <image> groups of three.
Help Xenia, find the required partition or else say that it doesn't exist.
Input
The first line contains integer n (3 β€ n β€ 99999) β the number of elements in the sequence. The next line contains n positive integers, each of them is at most 7.
It is guaranteed that n is divisible by 3.
Output
If the required partition exists, print <image> groups of three. Print each group as values of the elements it contains. You should print values in increasing order. Separate the groups and integers in groups by whitespaces. If there are multiple solutions, you can print any of them.
If there is no solution, print -1.
Examples
Input
6
1 1 1 2 2 2
Output
-1
Input
6
2 2 1 1 4 6
Output
1 2 4
1 2 6
Tags: greedy, implementation
Correct Solution:
```
n=int(input())
a,l,k=list(map(int,input().split())),[0]*5,n//3
for i in a:
if i==5or i==7:exit(print(-1))
elif i==3:l[4]+=1
else:l[i//2]+=1
if l[2]+l[3]!=k or l[0]!=k or l[4]+abs(l[1]-l[2])!=l[3]:print(-1)
else:exec("print(1,2,4);"*l[2]+"print(1,2,6);"*(l[1]-l[2])+"print(1,3,6);"*l[4])
```
| 14,520 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Xenia the mathematician has a sequence consisting of n (n is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three a, b, c the following conditions held:
* a < b < c;
* a divides b, b divides c.
Naturally, Xenia wants each element of the sequence to belong to exactly one group of three. Thus, if the required partition exists, then it has <image> groups of three.
Help Xenia, find the required partition or else say that it doesn't exist.
Input
The first line contains integer n (3 β€ n β€ 99999) β the number of elements in the sequence. The next line contains n positive integers, each of them is at most 7.
It is guaranteed that n is divisible by 3.
Output
If the required partition exists, print <image> groups of three. Print each group as values of the elements it contains. You should print values in increasing order. Separate the groups and integers in groups by whitespaces. If there are multiple solutions, you can print any of them.
If there is no solution, print -1.
Examples
Input
6
1 1 1 2 2 2
Output
-1
Input
6
2 2 1 1 4 6
Output
1 2 4
1 2 6
Tags: greedy, implementation
Correct Solution:
```
n=int(input())
arr=list(map(int,input().split()))
arr.sort()
t=0
ans=[]
boo=True
for i in range(0,n//3):
a=[]
a.append(arr[i])
if arr[i+n//3]>arr[i] and arr[i+n//3]%arr[i]==0:
a.append(arr[i+n//3])
else:
print(-1)
boo=False
break
if arr[i+n//3+n//3]>arr[i+n//3] and arr[i+n//3+n//3]%arr[i+n//3]==0:
a.append(arr[i+n//3+n//3])
else:
print(-1)
boo=False
break
ans.append(a)
if boo:
for i in ans:
for j in i:
print(j,end=' ')
print()
```
| 14,521 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Xenia the mathematician has a sequence consisting of n (n is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three a, b, c the following conditions held:
* a < b < c;
* a divides b, b divides c.
Naturally, Xenia wants each element of the sequence to belong to exactly one group of three. Thus, if the required partition exists, then it has <image> groups of three.
Help Xenia, find the required partition or else say that it doesn't exist.
Input
The first line contains integer n (3 β€ n β€ 99999) β the number of elements in the sequence. The next line contains n positive integers, each of them is at most 7.
It is guaranteed that n is divisible by 3.
Output
If the required partition exists, print <image> groups of three. Print each group as values of the elements it contains. You should print values in increasing order. Separate the groups and integers in groups by whitespaces. If there are multiple solutions, you can print any of them.
If there is no solution, print -1.
Examples
Input
6
1 1 1 2 2 2
Output
-1
Input
6
2 2 1 1 4 6
Output
1 2 4
1 2 6
Tags: greedy, implementation
Correct Solution:
```
n = int( input() )
a = list( map( int, input().split() ) )
cnt = [0]*8
for i in a:
cnt[i] += 1
p = []
k = 7
if cnt[5] > 0 or cnt[7] > 0 or (cnt[1]*3!=n):
print(-1)
exit(0)
#1 3 6
#1 2 4
#1 2 6
if cnt[6] > 0 and cnt[3] > 0:
for i in range( cnt[3] ):
p.append( [1,3,6] )
cnt[1] -= 1
cnt[3] -= 1
cnt[6] -= 1
if cnt[6] > 0 and cnt[2] > 0:
for i in range( cnt[6] ):
p.append( [1,2,6] )
cnt[1] -= 1
cnt[2] -= 1
cnt[6] -= 1
if cnt[4] > 0 and cnt[2] > 0:
for i in range( cnt[4] ):
p.append( [1,2,4] )
cnt[1] -= 1
cnt[2] -= 1
cnt[4] -= 1
#print(p)
if sum(cnt) != 0:
print( -1 )
exit(0)
for i in p:
for j in sorted(i):
print( j, end=' ' )
print()
```
| 14,522 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Xenia the mathematician has a sequence consisting of n (n is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three a, b, c the following conditions held:
* a < b < c;
* a divides b, b divides c.
Naturally, Xenia wants each element of the sequence to belong to exactly one group of three. Thus, if the required partition exists, then it has <image> groups of three.
Help Xenia, find the required partition or else say that it doesn't exist.
Input
The first line contains integer n (3 β€ n β€ 99999) β the number of elements in the sequence. The next line contains n positive integers, each of them is at most 7.
It is guaranteed that n is divisible by 3.
Output
If the required partition exists, print <image> groups of three. Print each group as values of the elements it contains. You should print values in increasing order. Separate the groups and integers in groups by whitespaces. If there are multiple solutions, you can print any of them.
If there is no solution, print -1.
Examples
Input
6
1 1 1 2 2 2
Output
-1
Input
6
2 2 1 1 4 6
Output
1 2 4
1 2 6
Tags: greedy, implementation
Correct Solution:
```
# It's all about what U BELIEVE
def gint(): return int(input())
def gint_arr(): return list(map(int, input().split()))
def gfloat(): return float(input())
def gfloat_arr(): return list(map(float, input().split()))
def pair_int(): return map(int, input().split())
###############################################################################
INF = (1 << 31)
dx = [-1, 0, 1, 0]
dy = [ 0, 1, 0, -1]
###############################################################################
############################ SOLUTION IS COMING ###############################
###############################################################################
n = gint()
a = gint_arr()
if 5 in a or 7 in a:
print(-1)
exit()
cnt = {}
for i in range(1, 7):
cnt[i] = a.count(i)
res = []
fail = False
while sum(cnt.values()) and not fail:
seq = []
if not cnt[1]:
fail = True
break
else:
seq.append(1)
cnt[1] -= 1
if not cnt[2] and not cnt[3]:
fail = True
elif cnt[2]:
seq.append(2)
cnt[2] -= 1
if not cnt[4]:
if not cnt[6]:
fail = True
else:
seq.append(6)
cnt[6] -= 1
else:
seq.append(4)
cnt[4] -= 1
else:
seq.append(3)
cnt[3] -= 1
if not cnt[6]:
fail = True
else:
seq.append(6)
cnt[6] -= 1
if len(seq) != 3:
fail = True
else:
res.append(seq)
if fail:
print(-1)
else:
for i in res:
print(*i)
```
| 14,523 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Xenia the mathematician has a sequence consisting of n (n is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three a, b, c the following conditions held:
* a < b < c;
* a divides b, b divides c.
Naturally, Xenia wants each element of the sequence to belong to exactly one group of three. Thus, if the required partition exists, then it has <image> groups of three.
Help Xenia, find the required partition or else say that it doesn't exist.
Input
The first line contains integer n (3 β€ n β€ 99999) β the number of elements in the sequence. The next line contains n positive integers, each of them is at most 7.
It is guaranteed that n is divisible by 3.
Output
If the required partition exists, print <image> groups of three. Print each group as values of the elements it contains. You should print values in increasing order. Separate the groups and integers in groups by whitespaces. If there are multiple solutions, you can print any of them.
If there is no solution, print -1.
Examples
Input
6
1 1 1 2 2 2
Output
-1
Input
6
2 2 1 1 4 6
Output
1 2 4
1 2 6
Tags: greedy, implementation
Correct Solution:
```
n=int(input())
A=list(map(int,input().split()))
A.sort()
D=[]
Diff=n//3
Bool=False
for val in range(Diff):
if A[val] < A[val+Diff] and A[val+Diff] < A[val+2*Diff]:
if A[val+Diff]%A[val] == 0 and A[val+2*Diff]%A[val+Diff] == 0:
pass
else:
Bool=True
break
else:
Bool=True
break
if Bool == True:
print(-1)
else:
for val in range(Diff):
print(A[val],A[val+Diff],A[val+2*Diff])
```
| 14,524 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Xenia the mathematician has a sequence consisting of n (n is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three a, b, c the following conditions held:
* a < b < c;
* a divides b, b divides c.
Naturally, Xenia wants each element of the sequence to belong to exactly one group of three. Thus, if the required partition exists, then it has <image> groups of three.
Help Xenia, find the required partition or else say that it doesn't exist.
Input
The first line contains integer n (3 β€ n β€ 99999) β the number of elements in the sequence. The next line contains n positive integers, each of them is at most 7.
It is guaranteed that n is divisible by 3.
Output
If the required partition exists, print <image> groups of three. Print each group as values of the elements it contains. You should print values in increasing order. Separate the groups and integers in groups by whitespaces. If there are multiple solutions, you can print any of them.
If there is no solution, print -1.
Examples
Input
6
1 1 1 2 2 2
Output
-1
Input
6
2 2 1 1 4 6
Output
1 2 4
1 2 6
Tags: greedy, implementation
Correct Solution:
```
n= int(input())
#val= list(map(int,input().split()))
ans=[0]*8
for i in map(int,input().split()):
ans[i]+=1
grp=n//3
if ans[1]==grp and (ans[2]+ans[3])==grp and (ans[4]+ans[6])==grp and ans[3]<=ans[6]:
print('1 2 4\n'*ans[4]+ '1 2 6\n'*(ans[6]-ans[3]) + '1 3 6\n'*(ans[3]))
else:
print(-1)
```
| 14,525 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Xenia the mathematician has a sequence consisting of n (n is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three a, b, c the following conditions held:
* a < b < c;
* a divides b, b divides c.
Naturally, Xenia wants each element of the sequence to belong to exactly one group of three. Thus, if the required partition exists, then it has <image> groups of three.
Help Xenia, find the required partition or else say that it doesn't exist.
Input
The first line contains integer n (3 β€ n β€ 99999) β the number of elements in the sequence. The next line contains n positive integers, each of them is at most 7.
It is guaranteed that n is divisible by 3.
Output
If the required partition exists, print <image> groups of three. Print each group as values of the elements it contains. You should print values in increasing order. Separate the groups and integers in groups by whitespaces. If there are multiple solutions, you can print any of them.
If there is no solution, print -1.
Examples
Input
6
1 1 1 2 2 2
Output
-1
Input
6
2 2 1 1 4 6
Output
1 2 4
1 2 6
Submitted Solution:
```
import sys,os,io,time,copy
if os.path.exists('input.txt'):
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
import math
n=int(input())
arr=list(map(int,input().split()))
dic={1:0,2:0,3:0,4:0,5:0,6:0,7:0}
for a in arr:
dic[a]+=1
x=min(dic[1],dic[2],dic[4])
dic[1]-=x
dic[2]-=x
dic[4]-=x
y=min(dic[1],dic[2],dic[6])
dic[1]-=y
dic[2]-=y
dic[6]-=y
z=min(dic[1],dic[3],dic[6])
dic[1]-=z
dic[3]-=z
dic[6]-=z
flag=0
for d in dic:
if dic[d]!=0:
flag=1
if flag==0:
for i in range(x):
print("1 2 4")
for i in range(y):
print("1 2 6")
for i in range(z):
print("1 3 6")
else:
print(-1)
```
Yes
| 14,526 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Xenia the mathematician has a sequence consisting of n (n is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three a, b, c the following conditions held:
* a < b < c;
* a divides b, b divides c.
Naturally, Xenia wants each element of the sequence to belong to exactly one group of three. Thus, if the required partition exists, then it has <image> groups of three.
Help Xenia, find the required partition or else say that it doesn't exist.
Input
The first line contains integer n (3 β€ n β€ 99999) β the number of elements in the sequence. The next line contains n positive integers, each of them is at most 7.
It is guaranteed that n is divisible by 3.
Output
If the required partition exists, print <image> groups of three. Print each group as values of the elements it contains. You should print values in increasing order. Separate the groups and integers in groups by whitespaces. If there are multiple solutions, you can print any of them.
If there is no solution, print -1.
Examples
Input
6
1 1 1 2 2 2
Output
-1
Input
6
2 2 1 1 4 6
Output
1 2 4
1 2 6
Submitted Solution:
```
import io, os
import sys
from atexit import register
from collections import Counter
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
sys.stdout = io.BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
tokens = []
tokens_next = 0
def nextStr():
global tokens, tokens_next
while tokens_next >= len(tokens):
tokens = input().split()
tokens_next = 0
tokens_next += 1
return tokens[tokens_next - 1]
def nextInt():
return int(nextStr())
def nextIntArr(n):
return [nextInt() for i in range(n)]
def print(s, end='\n'):
sys.stdout.write((str(s) + end).encode())
n = nextInt()
a = nextIntArr(n)
cnt = Counter(a)
res = []
for comb in [[1, 3, 6], [1, 2, 4], [1, 2, 6]]:
cur = zip(*[[i] * cnt[i] for i in comb])
cur = list(cur)
for i in comb:
cnt[i] -= len(cur)
res.extend(cur)
if list(cnt.elements()):
print(-1)
exit(0)
for i in res:
print(' '.join(map(str, i)))
```
Yes
| 14,527 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Xenia the mathematician has a sequence consisting of n (n is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three a, b, c the following conditions held:
* a < b < c;
* a divides b, b divides c.
Naturally, Xenia wants each element of the sequence to belong to exactly one group of three. Thus, if the required partition exists, then it has <image> groups of three.
Help Xenia, find the required partition or else say that it doesn't exist.
Input
The first line contains integer n (3 β€ n β€ 99999) β the number of elements in the sequence. The next line contains n positive integers, each of them is at most 7.
It is guaranteed that n is divisible by 3.
Output
If the required partition exists, print <image> groups of three. Print each group as values of the elements it contains. You should print values in increasing order. Separate the groups and integers in groups by whitespaces. If there are multiple solutions, you can print any of them.
If there is no solution, print -1.
Examples
Input
6
1 1 1 2 2 2
Output
-1
Input
6
2 2 1 1 4 6
Output
1 2 4
1 2 6
Submitted Solution:
```
#------------------------------what is this I don't know....just makes my mess faster--------------------------------------
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
#----------------------------------Real game starts here--------------------------------------
'''
___________________THIS IS AESTROIX CODE________________________
KARMANYA GUPTA
'''
#_______________________________________________________________#
def fact(x):
if x == 0:
return 1
else:
return x * fact(x-1)
def lower_bound(li, num): #return 0 if all are greater or equal to
answer = -1
start = 0
end = len(li)-1
while(start <= end):
middle = (end+start)//2
if li[middle] >= num:
answer = middle
end = middle - 1
else:
start = middle + 1
return answer #index where x is not less than num
def upper_bound(li, num): #return n-1 if all are small or equal
answer = -1
start = 0
end = len(li)-1
while(start <= end):
middle = (end+start)//2
if li[middle] <= num:
answer = middle
start = middle + 1
else:
end = middle - 1
return answer #index where x is not greater than num
def abs(x):
return x if x >=0 else -x
def binary_search(li, val, lb, ub):
ans = 0
while(lb <= ub):
mid = (lb+ub)//2
#print(mid, li[mid])
if li[mid] > val:
ub = mid-1
elif val > li[mid]:
lb = mid + 1
else:
ans = 1
break
return ans
#_______________________________________________________________#
for _ in range(1):
cnt = dict()
ans = []
for i in range(1,8):
cnt.setdefault(i,0)
n = int(input())
nums = list(map(int, input().split()))
for i in nums:
cnt[i] += 1
if cnt[5] != 0 or cnt[7] != 0:
print(-1)
break
while(cnt[3] > 0):
ans.append((1,3,6))
cnt[1] -= 1
cnt[3] -= 1
cnt[6] -= 1
while(cnt[4] > 0):
ans.append((1,2,4))
cnt[1] -= 1
cnt[2] -= 1
cnt[4] -= 1
while(cnt[6] > 0):
ans.append((1,2,6))
cnt[2] -= 1
cnt[1] -= 1
cnt[6] -= 1
flag = 1
for num,val in cnt.items():
if val != 0:
flag = 0
break
if flag == 0:
print(-1)
else:
for i in range(len(ans)):
print(ans[i][0], ans[i][1], ans[i][2])
```
Yes
| 14,528 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Xenia the mathematician has a sequence consisting of n (n is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three a, b, c the following conditions held:
* a < b < c;
* a divides b, b divides c.
Naturally, Xenia wants each element of the sequence to belong to exactly one group of three. Thus, if the required partition exists, then it has <image> groups of three.
Help Xenia, find the required partition or else say that it doesn't exist.
Input
The first line contains integer n (3 β€ n β€ 99999) β the number of elements in the sequence. The next line contains n positive integers, each of them is at most 7.
It is guaranteed that n is divisible by 3.
Output
If the required partition exists, print <image> groups of three. Print each group as values of the elements it contains. You should print values in increasing order. Separate the groups and integers in groups by whitespaces. If there are multiple solutions, you can print any of them.
If there is no solution, print -1.
Examples
Input
6
1 1 1 2 2 2
Output
-1
Input
6
2 2 1 1 4 6
Output
1 2 4
1 2 6
Submitted Solution:
```
import sys
from math import *
def minp():
return sys.stdin.readline().strip()
def mint():
return int(minp())
def mints():
return map(int, minp().split())
n = mint()
c = [0]*10
for i in mints():
c[i] += 1
if n // 3 == c[1] and c[0] == 0 and c[5] == 0 and c[7] == 0 \
and c[6] - c[3] == c[2] - c[4] and c[2] - c[4] >= 0:
for i in range(c[4]):
print(1,2,4)
for i in range(c[2]-c[4]):
print(1,2,6)
for i in range(c[3]):
print(1,3,6)
else:
print(-1)
```
Yes
| 14,529 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Xenia the mathematician has a sequence consisting of n (n is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three a, b, c the following conditions held:
* a < b < c;
* a divides b, b divides c.
Naturally, Xenia wants each element of the sequence to belong to exactly one group of three. Thus, if the required partition exists, then it has <image> groups of three.
Help Xenia, find the required partition or else say that it doesn't exist.
Input
The first line contains integer n (3 β€ n β€ 99999) β the number of elements in the sequence. The next line contains n positive integers, each of them is at most 7.
It is guaranteed that n is divisible by 3.
Output
If the required partition exists, print <image> groups of three. Print each group as values of the elements it contains. You should print values in increasing order. Separate the groups and integers in groups by whitespaces. If there are multiple solutions, you can print any of them.
If there is no solution, print -1.
Examples
Input
6
1 1 1 2 2 2
Output
-1
Input
6
2 2 1 1 4 6
Output
1 2 4
1 2 6
Submitted Solution:
```
import io, os
import sys
from atexit import register
from collections import Counter
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
sys.stdout = io.BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
tokens = []
tokens_next = 0
def nextStr():
global tokens, tokens_next
while tokens_next >= len(tokens):
tokens = input().split()
tokens_next = 0
tokens_next += 1
return tokens[tokens_next - 1]
def nextInt():
return int(nextStr())
def nextIntArr(n):
return [nextInt() for i in range(n)]
def print(s, end='\n'):
sys.stdout.write((str(s) + end).encode())
n = nextInt()
a = nextIntArr(n)
cnt = Counter(a)
if cnt[5] or cnt[7]:
print(-1)
exit(0)
res = []
res.extend(zip([1] * cnt[1], [3] * cnt[3], [6] * cnt[6]))
cnt[1] -= len(res)
cnt[3] -= len(res)
cnt[6] -= len(res)
res.extend(zip([1] * cnt[1], [2] * cnt[2], [4] * cnt[4]))
cnt[1] -= len(res)
cnt[2] -= len(res)
cnt[4] -= len(res)
res.extend(zip([1] * cnt[1], [2] * cnt[2], [6] * cnt[6]))
cnt[1] -= len(res)
cnt[2] -= len(res)
cnt[6] -= len(res)
if list(cnt.elements()):
print(-1)
exit(0)
for i in res:
print(' '.join(map(str, i)))
```
No
| 14,530 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Xenia the mathematician has a sequence consisting of n (n is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three a, b, c the following conditions held:
* a < b < c;
* a divides b, b divides c.
Naturally, Xenia wants each element of the sequence to belong to exactly one group of three. Thus, if the required partition exists, then it has <image> groups of three.
Help Xenia, find the required partition or else say that it doesn't exist.
Input
The first line contains integer n (3 β€ n β€ 99999) β the number of elements in the sequence. The next line contains n positive integers, each of them is at most 7.
It is guaranteed that n is divisible by 3.
Output
If the required partition exists, print <image> groups of three. Print each group as values of the elements it contains. You should print values in increasing order. Separate the groups and integers in groups by whitespaces. If there are multiple solutions, you can print any of them.
If there is no solution, print -1.
Examples
Input
6
1 1 1 2 2 2
Output
-1
Input
6
2 2 1 1 4 6
Output
1 2 4
1 2 6
Submitted Solution:
```
n = int(input())
a = list(map(int,input().split()))
c = [0]*8
for i in a:
c[i]+=1
if c[5] or c[7]:
print(-1)
exit(0)
t1 = c[3]
c[3] = 0
c[1] -= t1
c[6] -= t1
t2 = c[6]
c[1] -= t2
c[6] = 0
c[2] -= t2
t3 = c[4]
c[4] = 0
c[2] -= t3
c[1] -= t3
if c.count(0) != 8:
print(-1)
else:
for i in range(t1):
print('1 3 6')
for i in range(t2):
print('1 2 6')
for i in range(t3):
print('1 2 4')
```
No
| 14,531 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Xenia the mathematician has a sequence consisting of n (n is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three a, b, c the following conditions held:
* a < b < c;
* a divides b, b divides c.
Naturally, Xenia wants each element of the sequence to belong to exactly one group of three. Thus, if the required partition exists, then it has <image> groups of three.
Help Xenia, find the required partition or else say that it doesn't exist.
Input
The first line contains integer n (3 β€ n β€ 99999) β the number of elements in the sequence. The next line contains n positive integers, each of them is at most 7.
It is guaranteed that n is divisible by 3.
Output
If the required partition exists, print <image> groups of three. Print each group as values of the elements it contains. You should print values in increasing order. Separate the groups and integers in groups by whitespaces. If there are multiple solutions, you can print any of them.
If there is no solution, print -1.
Examples
Input
6
1 1 1 2 2 2
Output
-1
Input
6
2 2 1 1 4 6
Output
1 2 4
1 2 6
Submitted Solution:
```
n=int(input())
l=list(map(int,input().split()))
d={}
error=0
l.sort()
for i in l:
if i==5 or i==7:
error+=1
if i not in d:
d[i]=0
d[i]+=1
if l.count(1)!=int(n/3) or l.count(2)+l.count(3)!=int(n/3) or len(d)<3 or error>0 or (l.count(3)>0 and l.count(3)!=l.count(6)):
print("-1")
else:
for i in range(int(n/3)):
for j in range(i,n,int(n/3)):
print(l[j],end=" ")
print()
```
No
| 14,532 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Xenia the mathematician has a sequence consisting of n (n is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three a, b, c the following conditions held:
* a < b < c;
* a divides b, b divides c.
Naturally, Xenia wants each element of the sequence to belong to exactly one group of three. Thus, if the required partition exists, then it has <image> groups of three.
Help Xenia, find the required partition or else say that it doesn't exist.
Input
The first line contains integer n (3 β€ n β€ 99999) β the number of elements in the sequence. The next line contains n positive integers, each of them is at most 7.
It is guaranteed that n is divisible by 3.
Output
If the required partition exists, print <image> groups of three. Print each group as values of the elements it contains. You should print values in increasing order. Separate the groups and integers in groups by whitespaces. If there are multiple solutions, you can print any of them.
If there is no solution, print -1.
Examples
Input
6
1 1 1 2 2 2
Output
-1
Input
6
2 2 1 1 4 6
Output
1 2 4
1 2 6
Submitted Solution:
```
n=int(input())
z=list(map(int,input().split()))
o1=z.count(1)
o2=z.count(2)
o3=z.count(3)
o4=z.count(4)
o6=z.count(6)
if(5 in z or 7 in z):
print(-1)
else:
k1=[1,2,4]
k2=[1,3,6]
k3=[1,2,6]
p=min(o1,o2,o4)
k1=k1*p
o1=o1-p
o2=o2-p
o4=o4-p
p1=min(o1,o2,o6)
k3=k3*p1
o1-=1
o2-=1
o6-=1
p2=min(o1,o3,o6)
k2=k2*p2
o1-=1
o3-=1
o6-=1
if(len(k1)+len(k2)+len(k3)==n):
if(len(k1)!=0):
print(*k1)
if(len(k2)!=0):
print(*k2)
if(len(k3)!=0):
print(*k3)
else:
print(-1)
```
No
| 14,533 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a string of decimal digits s. Let's define bij = siΒ·sj. Find in matrix b the number of such rectangles that the sum bij for all cells (i, j) that are the elements of the rectangle equals a in each rectangle.
A rectangle in a matrix is a group of four integers (x, y, z, t) (x β€ y, z β€ t). The elements of the rectangle are all cells (i, j) such that x β€ i β€ y, z β€ j β€ t.
Input
The first line contains integer a (0 β€ a β€ 109), the second line contains a string of decimal integers s (1 β€ |s| β€ 4000).
Output
Print a single integer β the answer to a problem.
Please, do not write the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
10
12345
Output
6
Input
16
439873893693495623498263984765
Output
40
Tags: combinatorics, data structures, implementation
Correct Solution:
```
a = int(input())
s = input()
d = {}
for i in range(len(s)):
for j in range(i, len(s)):
if j == i: t = int(s[j])
else: t += int(s[j])
d[t] = d.get(t, 0) + 1
if a == 0:
if 0 in d:
cnt_pairs = (len(s) * (len(s) + 1)) // 2
print((d[0] * cnt_pairs) + (d[0] * (cnt_pairs - d[0])))
else:
print(0)
else:
c = 0
for f in d:
if f != 0 and a % f == 0 and (a//f) in d:
c += d[f] * d[a//f]
print(c)
```
| 14,534 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a string of decimal digits s. Let's define bij = siΒ·sj. Find in matrix b the number of such rectangles that the sum bij for all cells (i, j) that are the elements of the rectangle equals a in each rectangle.
A rectangle in a matrix is a group of four integers (x, y, z, t) (x β€ y, z β€ t). The elements of the rectangle are all cells (i, j) such that x β€ i β€ y, z β€ j β€ t.
Input
The first line contains integer a (0 β€ a β€ 109), the second line contains a string of decimal integers s (1 β€ |s| β€ 4000).
Output
Print a single integer β the answer to a problem.
Please, do not write the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
10
12345
Output
6
Input
16
439873893693495623498263984765
Output
40
Tags: combinatorics, data structures, implementation
Correct Solution:
```
import math
def main(arr,a):
f=[]
for i in range(1,int(math.sqrt(a))+1):
f1=i
f2=a/i
if f2==int(f2):
f.append(f1)
if f2!=f1:
f.append(int(f2))
f.sort()
prefix=[0]
for i in range(len(arr)):
prefix.append(prefix[-1]+arr[i])
diff={}
for i in range(len(prefix)):
for j in range(0,i):
val= prefix[i]-prefix[j]
if val not in diff:
diff[val]=0
diff[val]+=1
if a==0:
for e in diff:
f.append(e)
f.append(0)
f.sort()
ans=0
i=0
j=len(f)-1
while i<=j:
f1=f[i]
f2=f[j]
if f1 in diff and f2 in diff:
if f1==f2:
ans+=diff[f1]*diff[f2]
else:
ans+=2*(diff[f1]*diff[f2])
i+=1
j-=1
return ans
a=int(input())
arr=[int(c) for c in input()]
print(main(arr,a))
```
| 14,535 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a string of decimal digits s. Let's define bij = siΒ·sj. Find in matrix b the number of such rectangles that the sum bij for all cells (i, j) that are the elements of the rectangle equals a in each rectangle.
A rectangle in a matrix is a group of four integers (x, y, z, t) (x β€ y, z β€ t). The elements of the rectangle are all cells (i, j) such that x β€ i β€ y, z β€ j β€ t.
Input
The first line contains integer a (0 β€ a β€ 109), the second line contains a string of decimal integers s (1 β€ |s| β€ 4000).
Output
Print a single integer β the answer to a problem.
Please, do not write the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
10
12345
Output
6
Input
16
439873893693495623498263984765
Output
40
Tags: combinatorics, data structures, implementation
Correct Solution:
```
import sys,collections as cc
input = sys.stdin.readline
I = lambda : list(map(int,input().split()))
a,=I()
s=list(map(int,[i for i in input().strip()]))
d=cc.Counter([])
n=len(s)
for i in range(1,n+1):
su=sum(s[:i])
for j in range(i,n):
d[su]+=1
su=su-s[j-i]+s[j]
d[su]+=1
an=0
if a==0:
an=(n*(n+1)//2)**2
del d[0]
xx=sum(d.values())
for i in d:
an-=d[i]*(xx)
else:
for i in d.keys():
if i!=0 and a%i==0:
an=an+(d[i]*d[a//i])
print(an)
```
| 14,536 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a string of decimal digits s. Let's define bij = siΒ·sj. Find in matrix b the number of such rectangles that the sum bij for all cells (i, j) that are the elements of the rectangle equals a in each rectangle.
A rectangle in a matrix is a group of four integers (x, y, z, t) (x β€ y, z β€ t). The elements of the rectangle are all cells (i, j) such that x β€ i β€ y, z β€ j β€ t.
Input
The first line contains integer a (0 β€ a β€ 109), the second line contains a string of decimal integers s (1 β€ |s| β€ 4000).
Output
Print a single integer β the answer to a problem.
Please, do not write the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
10
12345
Output
6
Input
16
439873893693495623498263984765
Output
40
Tags: combinatorics, data structures, implementation
Correct Solution:
```
import sys
from collections import defaultdict as dd
from collections import deque
def eprint(*args):
print(*args, file=sys.stderr)
pl=1
from math import *
import copy
#sys.setrecursionlimit(10**6)
if pl:
input=sys.stdin.readline
def li():
return [int(xxx) for xxx in input().split()]
def fi():
return int(input())
def si():
return list(input().rstrip())
def mi():
return map(int,input().split())
d=[]
from bisect import *
from itertools import permutations
from bisect import *
f=[0 for i in range(100)]
for i in range(1,100):
if i==1:
f[i]=1
else:
f[i]=2*f[i-1]+1
#print(f[:15])
def rec(n,k):
s=[]
while n!=0:
n,r=n//k,n%k
#print(n,r)
if r<0:
r-=k
n+=1
#print(s,n,r)
s.append(r)
return s
n=fi()
s=si()
a=[]
for i in range(len(s)):
a.append(int(s[i]))
d={}
nn=len(s)
for i in range(nn):
c=0
for j in range(i,nn):
c+=a[j]
if c not in d:
d[c]=1
else:
d[c]+=1
ans=0
#print(d)
if n==0 and 0 in d:
for j in d:
if j==0:
ans+=d[0]*d[0]
else:
ans+=d[j]*d[0]*2
for j in range(1,int(sqrt(n))+1):
if n%j==0:
if n//j==j:
if j in d:
ans+=(d[j]*(d[j]))
elif n//j in d and j in d:
ans+=d[j]*d[n//j]*2
print(ans)
```
| 14,537 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a string of decimal digits s. Let's define bij = siΒ·sj. Find in matrix b the number of such rectangles that the sum bij for all cells (i, j) that are the elements of the rectangle equals a in each rectangle.
A rectangle in a matrix is a group of four integers (x, y, z, t) (x β€ y, z β€ t). The elements of the rectangle are all cells (i, j) such that x β€ i β€ y, z β€ j β€ t.
Input
The first line contains integer a (0 β€ a β€ 109), the second line contains a string of decimal integers s (1 β€ |s| β€ 4000).
Output
Print a single integer β the answer to a problem.
Please, do not write the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
10
12345
Output
6
Input
16
439873893693495623498263984765
Output
40
Tags: combinatorics, data structures, implementation
Correct Solution:
```
def divisors(x):
def f(y, q):
t = -len(r)
while not y % q:
y //= q
for i in range(t, 0):
r.append(r[t] * q)
return y
r, p = [1], 7
x = f(f(f(x, 2), 3), 5)
while x >= p * p:
for s in 4, 2, 4, 2, 4, 6, 2, 6:
if not x % p:
x = f(x, p)
p += s
if x > 1:
f(x, x)
return r
def main():
a, s = int(input()), input()
if not a:
z = sum(x * (x + 1) for x in map(len, s.translate(
str.maketrans('123456789', ' ')).split())) // 2
x = len(s)
print((x * (x + 1) - z) * z)
return
sums, x, cnt = {}, 0, 1
for u in map(int, s):
if u:
sums[x] = cnt
x += u
cnt = 1
else:
cnt += 1
if x * x < a:
print(0)
return
sums[x], u = cnt, a // x
l = [v for v in divisors(a) if v <= x]
z = a // max(l)
d = {x: 0 for x in l if z <= x}
for x in d:
for k, v in sums.items():
u = sums.get(k + x, 0)
if u:
d[x] += v * u
print(sum(u * d[a // x] for x, u in d.items()))
if __name__ == '__main__':
main()
# Made By Mostafa_Khaled
```
| 14,538 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a string of decimal digits s. Let's define bij = siΒ·sj. Find in matrix b the number of such rectangles that the sum bij for all cells (i, j) that are the elements of the rectangle equals a in each rectangle.
A rectangle in a matrix is a group of four integers (x, y, z, t) (x β€ y, z β€ t). The elements of the rectangle are all cells (i, j) such that x β€ i β€ y, z β€ j β€ t.
Input
The first line contains integer a (0 β€ a β€ 109), the second line contains a string of decimal integers s (1 β€ |s| β€ 4000).
Output
Print a single integer β the answer to a problem.
Please, do not write the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
10
12345
Output
6
Input
16
439873893693495623498263984765
Output
40
Tags: combinatorics, data structures, implementation
Correct Solution:
```
def divisors(x):
def f(y, q):
t = -len(r)
while not y % q:
y //= q
for i in range(t, 0):
r.append(r[t] * q)
return y
r, p = [1], 7
x = f(f(f(x, 2), 3), 5)
while x >= p * p:
for s in 4, 2, 4, 2, 4, 6, 2, 6:
if not x % p:
x = f(x, p)
p += s
if x > 1:
f(x, x)
return r
def main():
a, s = int(input()), input()
if not a:
z = sum(x * (x + 1) for x in map(len, s.translate(
str.maketrans('123456789', ' ')).split())) // 2
x = len(s)
print((x * (x + 1) - z) * z)
return
sums, x, cnt = {}, 0, 1
for u in map(int, s):
if u:
sums[x] = cnt
x += u
cnt = 1
else:
cnt += 1
if x * x < a:
print(0)
return
sums[x], u = cnt, a // x
l = [v for v in divisors(a) if v <= x]
z = a // max(l)
d = {x: 0 for x in l if z <= x}
for x in d:
for k, v in sums.items():
u = sums.get(k + x, 0)
if u:
d[x] += v * u
print(sum(u * d[a // x] for x, u in d.items()))
if __name__ == '__main__':
main()
```
| 14,539 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a string of decimal digits s. Let's define bij = siΒ·sj. Find in matrix b the number of such rectangles that the sum bij for all cells (i, j) that are the elements of the rectangle equals a in each rectangle.
A rectangle in a matrix is a group of four integers (x, y, z, t) (x β€ y, z β€ t). The elements of the rectangle are all cells (i, j) such that x β€ i β€ y, z β€ j β€ t.
Input
The first line contains integer a (0 β€ a β€ 109), the second line contains a string of decimal integers s (1 β€ |s| β€ 4000).
Output
Print a single integer β the answer to a problem.
Please, do not write the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
10
12345
Output
6
Input
16
439873893693495623498263984765
Output
40
Submitted Solution:
```
import math
def main(arr,a):
f=[]
for i in range(1,int(math.sqrt(a))+1):
f1=i
f2=a/i
if f2==int(f2):
f.append(f1)
if f2!=f1:
f.append(int(f2))
f.sort()
prefix=[0]
for i in range(len(arr)):
prefix.append(prefix[-1]+arr[i])
diff={}
for i in range(len(prefix)):
for j in range(0,i):
val= prefix[i]-prefix[j]
if val not in diff:
diff[val]=0
diff[val]+=1
ans=0
i=0
j=len(f)-1
while i<=j:
f1=f[i]
f2=f[j]
if f1 in diff and f2 in diff:
if f1==f2:
ans+=diff[f1]*diff[f2]
else:
ans+=2*(diff[f1]*diff[f2])
i+=1
j-=1
return ans
a=int(input())
arr=[int(c) for c in input()]
print(main(arr,a))
```
No
| 14,540 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a string of decimal digits s. Let's define bij = siΒ·sj. Find in matrix b the number of such rectangles that the sum bij for all cells (i, j) that are the elements of the rectangle equals a in each rectangle.
A rectangle in a matrix is a group of four integers (x, y, z, t) (x β€ y, z β€ t). The elements of the rectangle are all cells (i, j) such that x β€ i β€ y, z β€ j β€ t.
Input
The first line contains integer a (0 β€ a β€ 109), the second line contains a string of decimal integers s (1 β€ |s| β€ 4000).
Output
Print a single integer β the answer to a problem.
Please, do not write the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
10
12345
Output
6
Input
16
439873893693495623498263984765
Output
40
Submitted Solution:
```
import sys
from collections import defaultdict as dd
from collections import deque
def eprint(*args):
print(*args, file=sys.stderr)
pl=1
from math import *
import copy
#sys.setrecursionlimit(10**6)
if pl:
input=sys.stdin.readline
else:
sys.stdin=open('input.txt', 'r')
sys.stdout=open('all.txt','w')
def li():
return [int(xxx) for xxx in input().split()]
def fi():
return int(input())
def si():
return list(input().rstrip())
def mi():
return map(int,input().split())
d=[]
from bisect import *
from itertools import permutations
from bisect import *
f=[0 for i in range(100)]
for i in range(1,100):
if i==1:
f[i]=1
else:
f[i]=2*f[i-1]+1
#print(f[:15])
def rec(n,k):
s=[]
while n!=0:
n,r=n//k,n%k
#print(n,r)
if r<0:
r-=k
n+=1
#print(s,n,r)
s.append(r)
return s
n=fi()
s=si()
a=[]
for i in range(len(s)):
a.append(int(s[i]))
d={}
nn=len(s)
for i in range(nn):
c=0
for j in range(i,nn):
c+=a[j]
if c not in d:
d[c]=1
else:
d[c]+=1
ans=0
#print(d)
for j in range(1,int(sqrt(n))+1):
if n%j==0:
if n//j==j:
if j in d:
ans+=(d[j]*(d[j]))
elif n//j in d and j in d:
ans+=d[j]*d[n//j]*2
print(ans)
```
No
| 14,541 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a string of decimal digits s. Let's define bij = siΒ·sj. Find in matrix b the number of such rectangles that the sum bij for all cells (i, j) that are the elements of the rectangle equals a in each rectangle.
A rectangle in a matrix is a group of four integers (x, y, z, t) (x β€ y, z β€ t). The elements of the rectangle are all cells (i, j) such that x β€ i β€ y, z β€ j β€ t.
Input
The first line contains integer a (0 β€ a β€ 109), the second line contains a string of decimal integers s (1 β€ |s| β€ 4000).
Output
Print a single integer β the answer to a problem.
Please, do not write the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
10
12345
Output
6
Input
16
439873893693495623498263984765
Output
40
Submitted Solution:
```
import sys,collections as cc
input = sys.stdin.readline
I = lambda : list(map(int,input().split()))
a,=I()
s=list(map(int,[i for i in input().strip()]))
d=cc.Counter([])
n=len(s)
for i in range(1,n+1):
su=sum(s[:i])
for j in range(i,n):
d[su]+=1
su=su-s[j-i]+s[j]
d[su]+=1
an=0
if a==0:
an=d[0]*(sum(d.values()))
else:
for i in d.keys():
if i!=0 and a%i==0:
an=an+(d[i]*d[a//i])
print(an)
```
No
| 14,542 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a string of decimal digits s. Let's define bij = siΒ·sj. Find in matrix b the number of such rectangles that the sum bij for all cells (i, j) that are the elements of the rectangle equals a in each rectangle.
A rectangle in a matrix is a group of four integers (x, y, z, t) (x β€ y, z β€ t). The elements of the rectangle are all cells (i, j) such that x β€ i β€ y, z β€ j β€ t.
Input
The first line contains integer a (0 β€ a β€ 109), the second line contains a string of decimal integers s (1 β€ |s| β€ 4000).
Output
Print a single integer β the answer to a problem.
Please, do not write the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
10
12345
Output
6
Input
16
439873893693495623498263984765
Output
40
Submitted Solution:
```
def genprimes(limit):
lim12 = max(limit, 12)
lim = lim12 // 6
sieve = [False, True, True] * lim
lim = lim * 3 - 1
for i, s in enumerate(sieve):
if s:
p, pp = i * 2 + 3, (i + 3) * i * 2 + 3
le = (lim - pp) // p + 1
if le > 0:
sieve[pp::p] = [False] * le
else:
break
sieve[0] = sieve[3] = True
res = [i for i, s in zip(range(3, lim12, 2), sieve) if s]
for i, p in enumerate((2, 3, 5, 7)):
res[i] = p
while res[-1] >= limit:
del res[-1]
return res
def factor(x):
result = []
for p in genprimes(int(x ** .5) + 1):
cnt = 0
while not x % p:
x //= p
cnt += 1
if cnt:
result.append((p, cnt))
if x == 1:
return result
if x > 1:
result.append((x, 1))
return result
def divisors(x):
l = [1]
for k, v in factor(x):
for x in l[:]:
for j in range(v):
x *= k
l.append(x)
return l
def main():
a, s, l, x = int(input()), input(), [0], 0
if not a:
x, z = len(s), s.count('0')
print((x * (x + 1) - z) * z)
return
d = dict.fromkeys(divisors(a), 0)
for u in map(int, s):
x += u
for y in l:
if x - y in d:
d[x - y] += 1
l.append(x)
print(sum(u * d[a // x] for x, u in d.items()))
if __name__ == '__main__':
main()
```
No
| 14,543 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Fox Ciel has a board with n rows and n columns. So, the board consists of n Γ n cells. Each cell contains either a symbol '.', or a symbol '#'.
A cross on the board is a connected set of exactly five cells of the board that looks like a cross. The picture below shows how it looks.
<image>
Ciel wants to draw several (may be zero) crosses on the board. Each cross must cover exactly five cells with symbols '#', and any cell with symbol '#' must belong to some cross. No two crosses can share a cell.
Please, tell Ciel if she can draw the crosses in the described way.
Input
The first line contains an integer n (3 β€ n β€ 100) β the size of the board.
Each of the next n lines describes one row of the board. The i-th line describes the i-th row of the board and consists of n characters. Each character is either a symbol '.', or a symbol '#'.
Output
Output a single line with "YES" if Ciel can draw the crosses in the described way. Otherwise output a single line with "NO".
Examples
Input
5
.#...
####.
.####
...#.
.....
Output
YES
Input
4
####
####
####
####
Output
NO
Input
6
.#....
####..
.####.
.#.##.
######
.#..#.
Output
YES
Input
6
.#..#.
######
.####.
.####.
######
.#..#.
Output
NO
Input
3
...
...
...
Output
YES
Note
In example 1, you can draw two crosses. The picture below shows what they look like.
<image>
In example 2, the board contains 16 cells with '#', but each cross contains 5. Since 16 is not a multiple of 5, so it's impossible to cover all.
Tags: greedy, implementation
Correct Solution:
```
n=int(input())
board=[""]*n
c=0
for i in range(n):
board[i]=list(input())
for i in range(1,n-1):
for j in range(1,n-1):
if(board[i][j]=='#' and board[i-1][j]=='#' and board[i+1][j]=='#' and board[i][j-1]=='#' and board[i][j+1]=='#'):
board[i][j]='.'
board[i-1][j]='.'
board[i+1][j]='.'
board[i][j-1]='.'
board[i][j+1]='.'
c= sum(board[i].count('#') for i in range(n))
print ('YES') if c==0 else print('NO')
```
| 14,544 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Fox Ciel has a board with n rows and n columns. So, the board consists of n Γ n cells. Each cell contains either a symbol '.', or a symbol '#'.
A cross on the board is a connected set of exactly five cells of the board that looks like a cross. The picture below shows how it looks.
<image>
Ciel wants to draw several (may be zero) crosses on the board. Each cross must cover exactly five cells with symbols '#', and any cell with symbol '#' must belong to some cross. No two crosses can share a cell.
Please, tell Ciel if she can draw the crosses in the described way.
Input
The first line contains an integer n (3 β€ n β€ 100) β the size of the board.
Each of the next n lines describes one row of the board. The i-th line describes the i-th row of the board and consists of n characters. Each character is either a symbol '.', or a symbol '#'.
Output
Output a single line with "YES" if Ciel can draw the crosses in the described way. Otherwise output a single line with "NO".
Examples
Input
5
.#...
####.
.####
...#.
.....
Output
YES
Input
4
####
####
####
####
Output
NO
Input
6
.#....
####..
.####.
.#.##.
######
.#..#.
Output
YES
Input
6
.#..#.
######
.####.
.####.
######
.#..#.
Output
NO
Input
3
...
...
...
Output
YES
Note
In example 1, you can draw two crosses. The picture below shows what they look like.
<image>
In example 2, the board contains 16 cells with '#', but each cross contains 5. Since 16 is not a multiple of 5, so it's impossible to cover all.
Tags: greedy, implementation
Correct Solution:
```
def cross(i, j, v, n):
v[i*n+j] = '.'
if v[(i+1)*n+j] == '#':
v[(i+1)*n+j] = '.'
if v[(i+2)*n+j] == '#':
v[(i+2)*n+j] = '.'
if v[(i+1)*n+j+1] == '#':
v[(i+1)*n+j+1] = '.'
if v[(i+1)*n+j-1] == '#':
v[(i+1)*n+j-1] = '.'
return True
else:
return False
else:
return False
else:
return False
else:
return False
n = int(input())
v = ['.'] * n * n
ans = True
for i in range(n):
s = input()
for j in range(n):
v[i*n+j] = s[j]
for i in range(n):
if ans:
for j in range(n):
if v[i*n+j] == '#':
if j == 0 or j == (n - 1) or i > (n - 3):
ans = False
break
else:
ans = cross(i, j, v, n)
else:
break
if ans:
print('YES')
else:
print('NO')
```
| 14,545 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Fox Ciel has a board with n rows and n columns. So, the board consists of n Γ n cells. Each cell contains either a symbol '.', or a symbol '#'.
A cross on the board is a connected set of exactly five cells of the board that looks like a cross. The picture below shows how it looks.
<image>
Ciel wants to draw several (may be zero) crosses on the board. Each cross must cover exactly five cells with symbols '#', and any cell with symbol '#' must belong to some cross. No two crosses can share a cell.
Please, tell Ciel if she can draw the crosses in the described way.
Input
The first line contains an integer n (3 β€ n β€ 100) β the size of the board.
Each of the next n lines describes one row of the board. The i-th line describes the i-th row of the board and consists of n characters. Each character is either a symbol '.', or a symbol '#'.
Output
Output a single line with "YES" if Ciel can draw the crosses in the described way. Otherwise output a single line with "NO".
Examples
Input
5
.#...
####.
.####
...#.
.....
Output
YES
Input
4
####
####
####
####
Output
NO
Input
6
.#....
####..
.####.
.#.##.
######
.#..#.
Output
YES
Input
6
.#..#.
######
.####.
.####.
######
.#..#.
Output
NO
Input
3
...
...
...
Output
YES
Note
In example 1, you can draw two crosses. The picture below shows what they look like.
<image>
In example 2, the board contains 16 cells with '#', but each cross contains 5. Since 16 is not a multiple of 5, so it's impossible to cover all.
Tags: greedy, implementation
Correct Solution:
```
def fits(x, y):
global n
return x >= 0 and x < n and y >= 0 and y < n
def paint(x, y):
global a
a[x][y] = '.'
a[x - 1][y] = '.'
a[x + 1][y] = '.'
a[x][y - 1] = '.'
a[x][y + 1] = '.'
def check(x, y):
global a
dx = [0, 0, -1, 1]
dy = [1, -1, 0, 0]
cnt = 0
for i in range(4):
if (fits(x + dx[i], y + dy[i]) and a[x + dx[i]][y + dy[i]] == '#'):
cnt += 1
if (a[x][y] == '#'):
cnt += 1
if (cnt == 5):
paint(x, y)
n = int(input())
a = []
for i in range(n):
a.append(list(input()))
for i in range(n):
for j in range(n):
check(i, j)
cnt = 0
for el in a:
for el2 in el:
if el2 == '#':
cnt += 1
if (cnt == 0):
print('YES')
else:
print('NO')
```
| 14,546 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Fox Ciel has a board with n rows and n columns. So, the board consists of n Γ n cells. Each cell contains either a symbol '.', or a symbol '#'.
A cross on the board is a connected set of exactly five cells of the board that looks like a cross. The picture below shows how it looks.
<image>
Ciel wants to draw several (may be zero) crosses on the board. Each cross must cover exactly five cells with symbols '#', and any cell with symbol '#' must belong to some cross. No two crosses can share a cell.
Please, tell Ciel if she can draw the crosses in the described way.
Input
The first line contains an integer n (3 β€ n β€ 100) β the size of the board.
Each of the next n lines describes one row of the board. The i-th line describes the i-th row of the board and consists of n characters. Each character is either a symbol '.', or a symbol '#'.
Output
Output a single line with "YES" if Ciel can draw the crosses in the described way. Otherwise output a single line with "NO".
Examples
Input
5
.#...
####.
.####
...#.
.....
Output
YES
Input
4
####
####
####
####
Output
NO
Input
6
.#....
####..
.####.
.#.##.
######
.#..#.
Output
YES
Input
6
.#..#.
######
.####.
.####.
######
.#..#.
Output
NO
Input
3
...
...
...
Output
YES
Note
In example 1, you can draw two crosses. The picture below shows what they look like.
<image>
In example 2, the board contains 16 cells with '#', but each cross contains 5. Since 16 is not a multiple of 5, so it's impossible to cover all.
Tags: greedy, implementation
Correct Solution:
```
n = int(input())
a = []
for i in range(n):
a.append(list(1 if c == '#' else 0 for c in input()))
for i in range(n):
for j in range(n):
if a[i][j]:
if i + 2 >= n or j + 1 >= n or j == 0:
print('NO')
exit()
if a[i + 1][j] + a[i + 2][j] + a[i + 1][j - 1] + a[i + 1][j + 1] != 4:
print('NO')
exit()
a[i][j] = a[i + 1][j] = a[i + 2][j] = a[i + 1][j - 1] = a[i + 1][j + 1] = 0
print('YES')
```
| 14,547 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Fox Ciel has a board with n rows and n columns. So, the board consists of n Γ n cells. Each cell contains either a symbol '.', or a symbol '#'.
A cross on the board is a connected set of exactly five cells of the board that looks like a cross. The picture below shows how it looks.
<image>
Ciel wants to draw several (may be zero) crosses on the board. Each cross must cover exactly five cells with symbols '#', and any cell with symbol '#' must belong to some cross. No two crosses can share a cell.
Please, tell Ciel if she can draw the crosses in the described way.
Input
The first line contains an integer n (3 β€ n β€ 100) β the size of the board.
Each of the next n lines describes one row of the board. The i-th line describes the i-th row of the board and consists of n characters. Each character is either a symbol '.', or a symbol '#'.
Output
Output a single line with "YES" if Ciel can draw the crosses in the described way. Otherwise output a single line with "NO".
Examples
Input
5
.#...
####.
.####
...#.
.....
Output
YES
Input
4
####
####
####
####
Output
NO
Input
6
.#....
####..
.####.
.#.##.
######
.#..#.
Output
YES
Input
6
.#..#.
######
.####.
.####.
######
.#..#.
Output
NO
Input
3
...
...
...
Output
YES
Note
In example 1, you can draw two crosses. The picture below shows what they look like.
<image>
In example 2, the board contains 16 cells with '#', but each cross contains 5. Since 16 is not a multiple of 5, so it's impossible to cover all.
Tags: greedy, implementation
Correct Solution:
```
n = int(input())
ar = [list(input()) for _ in range(n)]
for i in range(1, n-1):
for j in range(1, n-1):
if ar[i][j] == "#" and ar[i-1][j] == "#" and ar[i+1][j] == "#" and ar[i][j+1] == "#" and ar[i][j-1] == "#":
ar[i][j] = ar[i+1][j] = ar[i-1][j] = ar[i][j+1] = ar[i][j-1] = "."
flag = True
for i in range(n):
if ar[i].count("#") > 0:
flag = False
break
print("YES" if flag else "NO")
```
| 14,548 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Fox Ciel has a board with n rows and n columns. So, the board consists of n Γ n cells. Each cell contains either a symbol '.', or a symbol '#'.
A cross on the board is a connected set of exactly five cells of the board that looks like a cross. The picture below shows how it looks.
<image>
Ciel wants to draw several (may be zero) crosses on the board. Each cross must cover exactly five cells with symbols '#', and any cell with symbol '#' must belong to some cross. No two crosses can share a cell.
Please, tell Ciel if she can draw the crosses in the described way.
Input
The first line contains an integer n (3 β€ n β€ 100) β the size of the board.
Each of the next n lines describes one row of the board. The i-th line describes the i-th row of the board and consists of n characters. Each character is either a symbol '.', or a symbol '#'.
Output
Output a single line with "YES" if Ciel can draw the crosses in the described way. Otherwise output a single line with "NO".
Examples
Input
5
.#...
####.
.####
...#.
.....
Output
YES
Input
4
####
####
####
####
Output
NO
Input
6
.#....
####..
.####.
.#.##.
######
.#..#.
Output
YES
Input
6
.#..#.
######
.####.
.####.
######
.#..#.
Output
NO
Input
3
...
...
...
Output
YES
Note
In example 1, you can draw two crosses. The picture below shows what they look like.
<image>
In example 2, the board contains 16 cells with '#', but each cross contains 5. Since 16 is not a multiple of 5, so it's impossible to cover all.
Tags: greedy, implementation
Correct Solution:
```
n=int(input())
a=[[] for i in range(n)]
for i in range(n):
s=input().strip()
for j in s:
a[i]+=[j]
kr=0
for i in range(n):
for j in range(n):
#print(i,j)
if a[i][j]=='#':
kr+=1
if 0<i<n-1 and 0<j<n-1 and a[i][j]=='#':
if a[i][j-1]==a[i][j+1]==a[i-1][j]==a[i+1][j]=='#':
kr-=3
a[i][j-1],a[i][j+1],a[i-1][j],a[i+1][j],a[i][j]='.','.','.','.','.'
if kr:
print('NO')
else:
print('YES')
```
| 14,549 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Fox Ciel has a board with n rows and n columns. So, the board consists of n Γ n cells. Each cell contains either a symbol '.', or a symbol '#'.
A cross on the board is a connected set of exactly five cells of the board that looks like a cross. The picture below shows how it looks.
<image>
Ciel wants to draw several (may be zero) crosses on the board. Each cross must cover exactly five cells with symbols '#', and any cell with symbol '#' must belong to some cross. No two crosses can share a cell.
Please, tell Ciel if she can draw the crosses in the described way.
Input
The first line contains an integer n (3 β€ n β€ 100) β the size of the board.
Each of the next n lines describes one row of the board. The i-th line describes the i-th row of the board and consists of n characters. Each character is either a symbol '.', or a symbol '#'.
Output
Output a single line with "YES" if Ciel can draw the crosses in the described way. Otherwise output a single line with "NO".
Examples
Input
5
.#...
####.
.####
...#.
.....
Output
YES
Input
4
####
####
####
####
Output
NO
Input
6
.#....
####..
.####.
.#.##.
######
.#..#.
Output
YES
Input
6
.#..#.
######
.####.
.####.
######
.#..#.
Output
NO
Input
3
...
...
...
Output
YES
Note
In example 1, you can draw two crosses. The picture below shows what they look like.
<image>
In example 2, the board contains 16 cells with '#', but each cross contains 5. Since 16 is not a multiple of 5, so it's impossible to cover all.
Tags: greedy, implementation
Correct Solution:
```
h = int(input())
l = [c == '#' for _ in range(h) for c in input()]
w = len(l) // h
cross = (0, w - 1, w, w + 1, 2 * w)
for i in range(1, (h - 2) * w - 1):
if all(l[_ + i] for _ in cross):
for _ in cross:
l[_ + i] = False
print(('YES', 'NO')[any(l)])
# Made By Mostafa_Khaled
```
| 14,550 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Fox Ciel has a board with n rows and n columns. So, the board consists of n Γ n cells. Each cell contains either a symbol '.', or a symbol '#'.
A cross on the board is a connected set of exactly five cells of the board that looks like a cross. The picture below shows how it looks.
<image>
Ciel wants to draw several (may be zero) crosses on the board. Each cross must cover exactly five cells with symbols '#', and any cell with symbol '#' must belong to some cross. No two crosses can share a cell.
Please, tell Ciel if she can draw the crosses in the described way.
Input
The first line contains an integer n (3 β€ n β€ 100) β the size of the board.
Each of the next n lines describes one row of the board. The i-th line describes the i-th row of the board and consists of n characters. Each character is either a symbol '.', or a symbol '#'.
Output
Output a single line with "YES" if Ciel can draw the crosses in the described way. Otherwise output a single line with "NO".
Examples
Input
5
.#...
####.
.####
...#.
.....
Output
YES
Input
4
####
####
####
####
Output
NO
Input
6
.#....
####..
.####.
.#.##.
######
.#..#.
Output
YES
Input
6
.#..#.
######
.####.
.####.
######
.#..#.
Output
NO
Input
3
...
...
...
Output
YES
Note
In example 1, you can draw two crosses. The picture below shows what they look like.
<image>
In example 2, the board contains 16 cells with '#', but each cross contains 5. Since 16 is not a multiple of 5, so it's impossible to cover all.
Tags: greedy, implementation
Correct Solution:
```
n = int(input())
matriz = []
yes = True
for i in range(n):
matriz.append(list(input()))
for i in range(1,n-1):
for j in range(1, n-1):
if(matriz[i][j] == '#' and matriz[i-1][j] == '#' and matriz[i+1][j] == '#' and matriz[i][j-1] == '#' and matriz[i][j+1] == '#'):
matriz[i][j] = '.'
matriz[i-1][j] = '.'
matriz[i+1][j] = '.'
matriz[i][j-1] = '.'
matriz[i][j+1] = '.'
for i in range(n):
for j in range(n):
if(matriz[i][j] != '.'):
print('NO')
yes = False
break
if(yes == False):
break
if(yes):
print('YES')
```
| 14,551 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Fox Ciel has a board with n rows and n columns. So, the board consists of n Γ n cells. Each cell contains either a symbol '.', or a symbol '#'.
A cross on the board is a connected set of exactly five cells of the board that looks like a cross. The picture below shows how it looks.
<image>
Ciel wants to draw several (may be zero) crosses on the board. Each cross must cover exactly five cells with symbols '#', and any cell with symbol '#' must belong to some cross. No two crosses can share a cell.
Please, tell Ciel if she can draw the crosses in the described way.
Input
The first line contains an integer n (3 β€ n β€ 100) β the size of the board.
Each of the next n lines describes one row of the board. The i-th line describes the i-th row of the board and consists of n characters. Each character is either a symbol '.', or a symbol '#'.
Output
Output a single line with "YES" if Ciel can draw the crosses in the described way. Otherwise output a single line with "NO".
Examples
Input
5
.#...
####.
.####
...#.
.....
Output
YES
Input
4
####
####
####
####
Output
NO
Input
6
.#....
####..
.####.
.#.##.
######
.#..#.
Output
YES
Input
6
.#..#.
######
.####.
.####.
######
.#..#.
Output
NO
Input
3
...
...
...
Output
YES
Note
In example 1, you can draw two crosses. The picture below shows what they look like.
<image>
In example 2, the board contains 16 cells with '#', but each cross contains 5. Since 16 is not a multiple of 5, so it's impossible to cover all.
Submitted Solution:
```
n=int(input())
l=[]
for i in range(n):
l.append(list(input()))
f=0
for j in range(n-2):
for k in range(n):
if(l[j][k]=='#'):
if(l[j+1][k]=='#'):
if(-1<(k-1)<n):
if(l[j+1][k-1]=='#'):
if(-1<(k+1)<n):
if(l[j+1][k+1]=='#'):
if(l[j+2][k]=='#'):
l[j][k]='.'
l[j+1][k]='.'
l[j+1][k-1]='.'
l[j+1][k+1]='.'
l[j+2][k]='.'
else:
f=1
break
else:
f=1
break
else:
f=1
break
else:
f=1
break
else:
f=1
break
else:
f=1
break
if(f!=1):
for j in range(n-2,n):
for k in range(n):
if(l[j][k]=='#'):
f=1
if(f==1):
break
if(f==0):
print('YES')
else:
print('NO')
```
Yes
| 14,552 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Fox Ciel has a board with n rows and n columns. So, the board consists of n Γ n cells. Each cell contains either a symbol '.', or a symbol '#'.
A cross on the board is a connected set of exactly five cells of the board that looks like a cross. The picture below shows how it looks.
<image>
Ciel wants to draw several (may be zero) crosses on the board. Each cross must cover exactly five cells with symbols '#', and any cell with symbol '#' must belong to some cross. No two crosses can share a cell.
Please, tell Ciel if she can draw the crosses in the described way.
Input
The first line contains an integer n (3 β€ n β€ 100) β the size of the board.
Each of the next n lines describes one row of the board. The i-th line describes the i-th row of the board and consists of n characters. Each character is either a symbol '.', or a symbol '#'.
Output
Output a single line with "YES" if Ciel can draw the crosses in the described way. Otherwise output a single line with "NO".
Examples
Input
5
.#...
####.
.####
...#.
.....
Output
YES
Input
4
####
####
####
####
Output
NO
Input
6
.#....
####..
.####.
.#.##.
######
.#..#.
Output
YES
Input
6
.#..#.
######
.####.
.####.
######
.#..#.
Output
NO
Input
3
...
...
...
Output
YES
Note
In example 1, you can draw two crosses. The picture below shows what they look like.
<image>
In example 2, the board contains 16 cells with '#', but each cross contains 5. Since 16 is not a multiple of 5, so it's impossible to cover all.
Submitted Solution:
```
def cross(n, lst):
for i in range(n):
for j in range(n):
if lst[i][j] == '#':
if i < n - 2 and 1 <= j <= n - 2 and lst[i + 1][j - 1] == '#' and lst[i + 1][j] == '#' and lst[i + 1][
j + 1] == '#' and lst[i + 2][j] == '#':
lst[i][j] = '.'
lst[i + 1][j - 1] = '.'
lst[i + 1][j] = '.'
lst[i + 1][j + 1] = '.'
lst[i + 2][j] = '.'
else:
return "NO"
return "YES"
N = int(input())
a = [list(input()) for i in range(N)]
print(cross(N, a))
```
Yes
| 14,553 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Fox Ciel has a board with n rows and n columns. So, the board consists of n Γ n cells. Each cell contains either a symbol '.', or a symbol '#'.
A cross on the board is a connected set of exactly five cells of the board that looks like a cross. The picture below shows how it looks.
<image>
Ciel wants to draw several (may be zero) crosses on the board. Each cross must cover exactly five cells with symbols '#', and any cell with symbol '#' must belong to some cross. No two crosses can share a cell.
Please, tell Ciel if she can draw the crosses in the described way.
Input
The first line contains an integer n (3 β€ n β€ 100) β the size of the board.
Each of the next n lines describes one row of the board. The i-th line describes the i-th row of the board and consists of n characters. Each character is either a symbol '.', or a symbol '#'.
Output
Output a single line with "YES" if Ciel can draw the crosses in the described way. Otherwise output a single line with "NO".
Examples
Input
5
.#...
####.
.####
...#.
.....
Output
YES
Input
4
####
####
####
####
Output
NO
Input
6
.#....
####..
.####.
.#.##.
######
.#..#.
Output
YES
Input
6
.#..#.
######
.####.
.####.
######
.#..#.
Output
NO
Input
3
...
...
...
Output
YES
Note
In example 1, you can draw two crosses. The picture below shows what they look like.
<image>
In example 2, the board contains 16 cells with '#', but each cross contains 5. Since 16 is not a multiple of 5, so it's impossible to cover all.
Submitted Solution:
```
def check():
for i in range(n):
for j in range(n):
if board[i][j] == '#':
return False
return True
n = int(input())
board = []
for i in range(n):
board.append([char for char in input()])
for i in range(1,n-1):
for j in range(1,n-1):
if board[i][j] == '#' and board[i][j-1] == board[i][j+1] == board[i-1][j] == board[i+1][j] == '#':
board[i][j] = board[i][j-1] = board[i][j+1] = board[i-1][j] = board[i+1][j] = '@'
print("YES" if check() else "NO")
```
Yes
| 14,554 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Fox Ciel has a board with n rows and n columns. So, the board consists of n Γ n cells. Each cell contains either a symbol '.', or a symbol '#'.
A cross on the board is a connected set of exactly five cells of the board that looks like a cross. The picture below shows how it looks.
<image>
Ciel wants to draw several (may be zero) crosses on the board. Each cross must cover exactly five cells with symbols '#', and any cell with symbol '#' must belong to some cross. No two crosses can share a cell.
Please, tell Ciel if she can draw the crosses in the described way.
Input
The first line contains an integer n (3 β€ n β€ 100) β the size of the board.
Each of the next n lines describes one row of the board. The i-th line describes the i-th row of the board and consists of n characters. Each character is either a symbol '.', or a symbol '#'.
Output
Output a single line with "YES" if Ciel can draw the crosses in the described way. Otherwise output a single line with "NO".
Examples
Input
5
.#...
####.
.####
...#.
.....
Output
YES
Input
4
####
####
####
####
Output
NO
Input
6
.#....
####..
.####.
.#.##.
######
.#..#.
Output
YES
Input
6
.#..#.
######
.####.
.####.
######
.#..#.
Output
NO
Input
3
...
...
...
Output
YES
Note
In example 1, you can draw two crosses. The picture below shows what they look like.
<image>
In example 2, the board contains 16 cells with '#', but each cross contains 5. Since 16 is not a multiple of 5, so it's impossible to cover all.
Submitted Solution:
```
n=int(input())
l=[]
for i in range(n):
l.append(list(input()))
c=0
for i in range(1,n-1):
for j in range(1,n-1):
if(l[i][j]==l[i][j+1]==l[i][j-1]==l[i-1][j]==l[i+1][j]=='#'):
l[i][j]=l[i][j+1]=l[i][j-1]=l[i-1][j]=l[i+1][j]='.'
for i in range(n):
if(l[i].count('#')>0):
c=1
break
if(c==0):
print("YES")
else:
print("NO")
```
Yes
| 14,555 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Fox Ciel has a board with n rows and n columns. So, the board consists of n Γ n cells. Each cell contains either a symbol '.', or a symbol '#'.
A cross on the board is a connected set of exactly five cells of the board that looks like a cross. The picture below shows how it looks.
<image>
Ciel wants to draw several (may be zero) crosses on the board. Each cross must cover exactly five cells with symbols '#', and any cell with symbol '#' must belong to some cross. No two crosses can share a cell.
Please, tell Ciel if she can draw the crosses in the described way.
Input
The first line contains an integer n (3 β€ n β€ 100) β the size of the board.
Each of the next n lines describes one row of the board. The i-th line describes the i-th row of the board and consists of n characters. Each character is either a symbol '.', or a symbol '#'.
Output
Output a single line with "YES" if Ciel can draw the crosses in the described way. Otherwise output a single line with "NO".
Examples
Input
5
.#...
####.
.####
...#.
.....
Output
YES
Input
4
####
####
####
####
Output
NO
Input
6
.#....
####..
.####.
.#.##.
######
.#..#.
Output
YES
Input
6
.#..#.
######
.####.
.####.
######
.#..#.
Output
NO
Input
3
...
...
...
Output
YES
Note
In example 1, you can draw two crosses. The picture below shows what they look like.
<image>
In example 2, the board contains 16 cells with '#', but each cross contains 5. Since 16 is not a multiple of 5, so it's impossible to cover all.
Submitted Solution:
```
def check(i, j):
global matrix, n
if j==0 or j==n-1 or i>n-3:
return False
matrix[i][j] = '.'
matrix[i+1][j] = '.'
matrix[i+2][j] = '.'
matrix[i+1][j-1] = '.'
matrix[i+1][j+1] = '.'
return True
n = int(input())
matrix = []
for i in range(n):
l = list(input())
matrix.append(l)
ans = True
for i in range(n):
for j in range(n):
if matrix[i][j] == '#':
ans = check(i, j)
if not ans:
break
if ans:
print("YES")
else:
print("NO")
```
No
| 14,556 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Fox Ciel has a board with n rows and n columns. So, the board consists of n Γ n cells. Each cell contains either a symbol '.', or a symbol '#'.
A cross on the board is a connected set of exactly five cells of the board that looks like a cross. The picture below shows how it looks.
<image>
Ciel wants to draw several (may be zero) crosses on the board. Each cross must cover exactly five cells with symbols '#', and any cell with symbol '#' must belong to some cross. No two crosses can share a cell.
Please, tell Ciel if she can draw the crosses in the described way.
Input
The first line contains an integer n (3 β€ n β€ 100) β the size of the board.
Each of the next n lines describes one row of the board. The i-th line describes the i-th row of the board and consists of n characters. Each character is either a symbol '.', or a symbol '#'.
Output
Output a single line with "YES" if Ciel can draw the crosses in the described way. Otherwise output a single line with "NO".
Examples
Input
5
.#...
####.
.####
...#.
.....
Output
YES
Input
4
####
####
####
####
Output
NO
Input
6
.#....
####..
.####.
.#.##.
######
.#..#.
Output
YES
Input
6
.#..#.
######
.####.
.####.
######
.#..#.
Output
NO
Input
3
...
...
...
Output
YES
Note
In example 1, you can draw two crosses. The picture below shows what they look like.
<image>
In example 2, the board contains 16 cells with '#', but each cross contains 5. Since 16 is not a multiple of 5, so it's impossible to cover all.
Submitted Solution:
```
n=int(input())
l=[]
for i in range(n):
l.append(list(input()))
f=0
for j in range(n-2):
for k in range(n):
if(l[j][k]=='#'):
if(l[j+1][k]=='#'):
if(-1<(k-1)<n):
if(l[j+1][k-1]=='#'):
if(-1<(k+1)<n):
if(l[j+1][k+1]=='#'):
if(l[j+2][k]=='#'):
l[j][k]='.'
l[j+1][k]='.'
l[j+1][k-1]='.'
l[j+1][k+1]='.'
l[j+2][k]='.'
else:
f=1
break
else:
f=1
break
else:
f=1
break
else:
f=1
break
else:
f=1
break
else:
f=1
break
if(f==0):
print('YES')
else:
print('NO')
```
No
| 14,557 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Fox Ciel has a board with n rows and n columns. So, the board consists of n Γ n cells. Each cell contains either a symbol '.', or a symbol '#'.
A cross on the board is a connected set of exactly five cells of the board that looks like a cross. The picture below shows how it looks.
<image>
Ciel wants to draw several (may be zero) crosses on the board. Each cross must cover exactly five cells with symbols '#', and any cell with symbol '#' must belong to some cross. No two crosses can share a cell.
Please, tell Ciel if she can draw the crosses in the described way.
Input
The first line contains an integer n (3 β€ n β€ 100) β the size of the board.
Each of the next n lines describes one row of the board. The i-th line describes the i-th row of the board and consists of n characters. Each character is either a symbol '.', or a symbol '#'.
Output
Output a single line with "YES" if Ciel can draw the crosses in the described way. Otherwise output a single line with "NO".
Examples
Input
5
.#...
####.
.####
...#.
.....
Output
YES
Input
4
####
####
####
####
Output
NO
Input
6
.#....
####..
.####.
.#.##.
######
.#..#.
Output
YES
Input
6
.#..#.
######
.####.
.####.
######
.#..#.
Output
NO
Input
3
...
...
...
Output
YES
Note
In example 1, you can draw two crosses. The picture below shows what they look like.
<image>
In example 2, the board contains 16 cells with '#', but each cross contains 5. Since 16 is not a multiple of 5, so it's impossible to cover all.
Submitted Solution:
```
if __name__ == '__main__':
n = int(input())
x = [list(input()) for i in range(n)]
y = [['.' for j in range(n)] for i in range(n)]
error = False
for i in range(n):
for j in range(n):
if x[i][j] == '.' and y[i][j] == '.':
continue
elif x[i][j] == '.' and y[i][j] == '#':
error = True
break
elif x[i][j] == '#' and y[i][j] == '.':
if j == 0 or j == n - 1 or i > n - 3:
error = True
break
else:
y[i][j] = '#'
y[i + 1][j - 1] = '#'
y[i + 1][j] = '#'
y[i + 1][j + 1] = '#'
y[i + 2][j] = '#'
if not error:
print('YES')
else:
print('NO')
```
No
| 14,558 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Fox Ciel has a board with n rows and n columns. So, the board consists of n Γ n cells. Each cell contains either a symbol '.', or a symbol '#'.
A cross on the board is a connected set of exactly five cells of the board that looks like a cross. The picture below shows how it looks.
<image>
Ciel wants to draw several (may be zero) crosses on the board. Each cross must cover exactly five cells with symbols '#', and any cell with symbol '#' must belong to some cross. No two crosses can share a cell.
Please, tell Ciel if she can draw the crosses in the described way.
Input
The first line contains an integer n (3 β€ n β€ 100) β the size of the board.
Each of the next n lines describes one row of the board. The i-th line describes the i-th row of the board and consists of n characters. Each character is either a symbol '.', or a symbol '#'.
Output
Output a single line with "YES" if Ciel can draw the crosses in the described way. Otherwise output a single line with "NO".
Examples
Input
5
.#...
####.
.####
...#.
.....
Output
YES
Input
4
####
####
####
####
Output
NO
Input
6
.#....
####..
.####.
.#.##.
######
.#..#.
Output
YES
Input
6
.#..#.
######
.####.
.####.
######
.#..#.
Output
NO
Input
3
...
...
...
Output
YES
Note
In example 1, you can draw two crosses. The picture below shows what they look like.
<image>
In example 2, the board contains 16 cells with '#', but each cross contains 5. Since 16 is not a multiple of 5, so it's impossible to cover all.
Submitted Solution:
```
n = int(input())
s = [list(input()) for i in range(n)]
for i in range(1,n-1):
for j in range(1,n-1):
tmp = s[i][i] =='#' and s[i-1][j] == '#' and s[i+1][j] == '#' and s[i][j-1] == '#' and s[i][j+1] == '#'
if tmp :
s[i][i] =s[i-1][j] = s[i+1][j] = s[i][j-1] = s[i][j+1] = '.'
print(['YES' , 'NO'][s.count('#')==0])
```
No
| 14,559 |
Provide tags and a correct Python 3 solution for this coding contest problem.
<image>
Input
The input contains a single floating-point number x with exactly 6 decimal places (0 < x < 5).
Output
Output two integers separated by a single space. Each integer should be between 1 and 10, inclusive. If several solutions exist, output any of them. Solution will exist for all tests.
Examples
Input
1.200000
Output
3 2
Input
2.572479
Output
10 3
Input
4.024922
Output
9 9
Tags: *special
Correct Solution:
```
from math import *
r = float(input())
for a in range(1,11):
for h in range(1,11):
R = a*a*h*0.5/sqrt(h*h+a*a/4)/a
if abs(R-r)<1e-5:
print(a,h)
exit()
```
| 14,560 |
Provide tags and a correct Python 3 solution for this coding contest problem.
<image>
Input
The input contains a single floating-point number x with exactly 6 decimal places (0 < x < 5).
Output
Output two integers separated by a single space. Each integer should be between 1 and 10, inclusive. If several solutions exist, output any of them. Solution will exist for all tests.
Examples
Input
1.200000
Output
3 2
Input
2.572479
Output
10 3
Input
4.024922
Output
9 9
Tags: *special
Correct Solution:
```
r=float(input())
a=0
h=0
for i in range(1,11):
for j in range(1,11):
c=pow(j*j+i*i/4.,0.5)
rtest=i*j*0.5/c
if abs(rtest-r)<0.00001:
a=i
h=j
print(a,h)
```
| 14,561 |
Provide tags and a correct Python 3 solution for this coding contest problem.
<image>
Input
The input contains a single floating-point number x with exactly 6 decimal places (0 < x < 5).
Output
Output two integers separated by a single space. Each integer should be between 1 and 10, inclusive. If several solutions exist, output any of them. Solution will exist for all tests.
Examples
Input
1.200000
Output
3 2
Input
2.572479
Output
10 3
Input
4.024922
Output
9 9
Tags: *special
Correct Solution:
```
k = float(input())
flag = True
for i in range(1, 11):
for j in range(1, 11):
if abs(k - i / 2 * j / ((i / 2) ** 2 + j ** 2) ** (1 / 2)) <= 1e-6:
flag = False
print(i, j)
break
if not flag:
break
```
| 14,562 |
Provide tags and a correct Python 3 solution for this coding contest problem.
<image>
Input
The input contains a single floating-point number x with exactly 6 decimal places (0 < x < 5).
Output
Output two integers separated by a single space. Each integer should be between 1 and 10, inclusive. If several solutions exist, output any of them. Solution will exist for all tests.
Examples
Input
1.200000
Output
3 2
Input
2.572479
Output
10 3
Input
4.024922
Output
9 9
Tags: *special
Correct Solution:
```
x = float(input())
for a in range(1, 10+1):
for h in range(1, 10+1):
if abs(x - (4/(a*a) + 1/(h*h)) ** (-0.5)) <= 10 ** -5:
print(a, h)
quit()
```
| 14,563 |
Provide tags and a correct Python 3 solution for this coding contest problem.
<image>
Input
The input contains a single floating-point number x with exactly 6 decimal places (0 < x < 5).
Output
Output two integers separated by a single space. Each integer should be between 1 and 10, inclusive. If several solutions exist, output any of them. Solution will exist for all tests.
Examples
Input
1.200000
Output
3 2
Input
2.572479
Output
10 3
Input
4.024922
Output
9 9
Tags: *special
Correct Solution:
```
from math import sqrt
eps = 1e-5
def check(a, h, x):
return abs(x * sqrt(4 * h * h + a * a) - a * h) < eps
def main():
x = float(input())
for a in range(1, 11):
for h in range(1, 11):
if check(a, h, x):
print(a, h)
return
main()
```
| 14,564 |
Provide tags and a correct Python 3 solution for this coding contest problem.
<image>
Input
The input contains a single floating-point number x with exactly 6 decimal places (0 < x < 5).
Output
Output two integers separated by a single space. Each integer should be between 1 and 10, inclusive. If several solutions exist, output any of them. Solution will exist for all tests.
Examples
Input
1.200000
Output
3 2
Input
2.572479
Output
10 3
Input
4.024922
Output
9 9
Tags: *special
Correct Solution:
```
from math import sqrt
import sys
x = float(input())
for a in range(1, 11):
for h in range(1, 11):
if abs(x -( a * h / sqrt(a * a + 4 * h * h)) )< 0.00001:
print(a, h)
sys.exit()
```
| 14,565 |
Provide tags and a correct Python 3 solution for this coding contest problem.
<image>
Input
The input contains a single floating-point number x with exactly 6 decimal places (0 < x < 5).
Output
Output two integers separated by a single space. Each integer should be between 1 and 10, inclusive. If several solutions exist, output any of them. Solution will exist for all tests.
Examples
Input
1.200000
Output
3 2
Input
2.572479
Output
10 3
Input
4.024922
Output
9 9
Tags: *special
Correct Solution:
```
import sys
from math import sqrt, pi
X = float(input())
def rad_len(a, h, c):
x = c * a/2
# y = c * sqrt((a / 2)**2 + h**2)
y = c * h
return sqrt((x - a/2)**2 + (y - 0)**2)
def get_max_radius(a, h):
lo = 0.0
hi = 1.0
while abs(lo - hi) > 1e-9:
# print(lo, hi, rad_len(a, h, lo), rad_len(a, h, hi))
p = lo + (hi - lo) / 3
q = lo + 2 * (hi - lo) / 3
if rad_len(a, h, p) > rad_len(a, h, q):
lo = p
else:
hi = q
# for cx in range(100 + 0):
# print(rad_len(a, h, cx / 100.0))
return rad_len(a, h, lo)
for i in range(9, -1, -1):
for ai in range(1, 11):
for hi in range(1, 11):
a = float(ai)
h = float(hi)
r = get_max_radius(a, h)
if abs(r - X) < 10**(-i):
print(ai, hi)
sys.exit(0)
```
| 14,566 |
Provide tags and a correct Python 3 solution for this coding contest problem.
<image>
Input
The input contains a single floating-point number x with exactly 6 decimal places (0 < x < 5).
Output
Output two integers separated by a single space. Each integer should be between 1 and 10, inclusive. If several solutions exist, output any of them. Solution will exist for all tests.
Examples
Input
1.200000
Output
3 2
Input
2.572479
Output
10 3
Input
4.024922
Output
9 9
Tags: *special
Correct Solution:
```
import sys
x = float(sys.stdin.readline())
diff = x
for a in range(1, 11):
for h in range(1, 11):
t = pow((a*a*h*h)/(a*a+4*h*h), 0.5)
if diff > abs(x - t):
diff = abs(x-t)
ans_a = a
ans_h = h
print(ans_a, ans_h)
```
| 14,567 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
<image>
Input
The input contains a single floating-point number x with exactly 6 decimal places (0 < x < 5).
Output
Output two integers separated by a single space. Each integer should be between 1 and 10, inclusive. If several solutions exist, output any of them. Solution will exist for all tests.
Examples
Input
1.200000
Output
3 2
Input
2.572479
Output
10 3
Input
4.024922
Output
9 9
Submitted Solution:
```
import math as m
x= float(input())
for a in range (1,10+1):
for h in range (1,10+1):
if abs(x - ( (a*h)/ (2* m.sqrt(a*a/4 +h*h) )) ) <= 10**-5:
print (a,h)
quit()
```
Yes
| 14,568 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
<image>
Input
The input contains a single floating-point number x with exactly 6 decimal places (0 < x < 5).
Output
Output two integers separated by a single space. Each integer should be between 1 and 10, inclusive. If several solutions exist, output any of them. Solution will exist for all tests.
Examples
Input
1.200000
Output
3 2
Input
2.572479
Output
10 3
Input
4.024922
Output
9 9
Submitted Solution:
```
import math
s=input()
r=float(s)
def okrugl(fl):
return (round(fl*1000000)/1000000)
flag=1
for a in range(1,11):
for h in range(1,11):
#print(((a*h)/(math.sqrt(a*a+h*h*4))))0
if okrugl((a*h)/(math.sqrt(a*a+h*h*4)))==r:
if flag:
print(a," ",h)
flag=0
```
Yes
| 14,569 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
<image>
Input
The input contains a single floating-point number x with exactly 6 decimal places (0 < x < 5).
Output
Output two integers separated by a single space. Each integer should be between 1 and 10, inclusive. If several solutions exist, output any of them. Solution will exist for all tests.
Examples
Input
1.200000
Output
3 2
Input
2.572479
Output
10 3
Input
4.024922
Output
9 9
Submitted Solution:
```
k = float(input())
eps = 10 ** -5
for x in range(1, 11):
for y in range(1, 11):
if abs(x**2 * y**2 / (x**2 + 4 * y**2) - k**2) < eps:
print(x, y)
break
else: continue
break
```
Yes
| 14,570 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
<image>
Input
The input contains a single floating-point number x with exactly 6 decimal places (0 < x < 5).
Output
Output two integers separated by a single space. Each integer should be between 1 and 10, inclusive. If several solutions exist, output any of them. Solution will exist for all tests.
Examples
Input
1.200000
Output
3 2
Input
2.572479
Output
10 3
Input
4.024922
Output
9 9
Submitted Solution:
```
from math import sqrt
d = 1e-5
r = float(input())
for a in range(1, 11):
for h in range(1, 11):
if abs((h * a / 2) / sqrt((h ** 2) + ((a / 2) ** 2)) - r) <= d:
ans_a = a
ans_h = h
print(ans_a, ans_h)
```
Yes
| 14,571 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
<image>
Input
The input contains a single floating-point number x with exactly 6 decimal places (0 < x < 5).
Output
Output two integers separated by a single space. Each integer should be between 1 and 10, inclusive. If several solutions exist, output any of them. Solution will exist for all tests.
Examples
Input
1.200000
Output
3 2
Input
2.572479
Output
10 3
Input
4.024922
Output
9 9
Submitted Solution:
```
from math import sqrt
import sys
x = float(input())
for a in range(1, 11):
for h in range(1, 11):
if x -( a * h / sqrt(a * a + 4 * h * h)) < 0.000001:
print(a, h)
sys.exit()
```
No
| 14,572 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
<image>
Input
The input contains a single floating-point number x with exactly 6 decimal places (0 < x < 5).
Output
Output two integers separated by a single space. Each integer should be between 1 and 10, inclusive. If several solutions exist, output any of them. Solution will exist for all tests.
Examples
Input
1.200000
Output
3 2
Input
2.572479
Output
10 3
Input
4.024922
Output
9 9
Submitted Solution:
```
from math import sqrt
eps = 1e-6
x = float(input())
for a in range(1, 11):
for h in range(1, 11):
if abs(x * sqrt(4 * h * h + a * a) - a * h) < eps:
print(a, h)
break
```
No
| 14,573 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
<image>
Input
The input contains a single floating-point number x with exactly 6 decimal places (0 < x < 5).
Output
Output two integers separated by a single space. Each integer should be between 1 and 10, inclusive. If several solutions exist, output any of them. Solution will exist for all tests.
Examples
Input
1.200000
Output
3 2
Input
2.572479
Output
10 3
Input
4.024922
Output
9 9
Submitted Solution:
```
print (10, 10)
```
No
| 14,574 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
<image>
Input
The input contains a single floating-point number x with exactly 6 decimal places (0 < x < 5).
Output
Output two integers separated by a single space. Each integer should be between 1 and 10, inclusive. If several solutions exist, output any of them. Solution will exist for all tests.
Examples
Input
1.200000
Output
3 2
Input
2.572479
Output
10 3
Input
4.024922
Output
9 9
Submitted Solution:
```
print(10, 1)
```
No
| 14,575 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1, p2, ..., pn.
Your task is to find such permutation p of length n, that the group of numbers |p1 - p2|, |p2 - p3|, ..., |pn - 1 - pn| has exactly k distinct elements.
Input
The single line of the input contains two space-separated positive integers n, k (1 β€ k < n β€ 105).
Output
Print n integers forming the permutation. If there are multiple answers, print any of them.
Examples
Input
3 2
Output
1 3 2
Input
3 1
Output
1 2 3
Input
5 2
Output
1 3 2 4 5
Note
By |x| we denote the absolute value of number x.
Tags: constructive algorithms, greedy
Correct Solution:
```
import itertools
import math
def main():
n, k = map(int, input().split())
a = 1
b = n
res = []
for i in range(k - 1):
if i % 2:
res.append(a)
a += 1
else:
res.append(b)
b -= 1
if k % 2:
res += range(b, a - 1, -1)
else:
res += range(a, b + 1)
print(" ".join(map(str, res)))
if __name__ == "__main__":
main()
```
| 14,576 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1, p2, ..., pn.
Your task is to find such permutation p of length n, that the group of numbers |p1 - p2|, |p2 - p3|, ..., |pn - 1 - pn| has exactly k distinct elements.
Input
The single line of the input contains two space-separated positive integers n, k (1 β€ k < n β€ 105).
Output
Print n integers forming the permutation. If there are multiple answers, print any of them.
Examples
Input
3 2
Output
1 3 2
Input
3 1
Output
1 2 3
Input
5 2
Output
1 3 2 4 5
Note
By |x| we denote the absolute value of number x.
Tags: constructive algorithms, greedy
Correct Solution:
```
n, k = map(int, input().split())
res = []
for i in range(1, k+2):
if i % 2 == 1:
res.append((i+1) // 2)
else:
res.append(k + 2 - (i//2))
res += list(range(k+2, n+1))
print(*res)
```
| 14,577 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1, p2, ..., pn.
Your task is to find such permutation p of length n, that the group of numbers |p1 - p2|, |p2 - p3|, ..., |pn - 1 - pn| has exactly k distinct elements.
Input
The single line of the input contains two space-separated positive integers n, k (1 β€ k < n β€ 105).
Output
Print n integers forming the permutation. If there are multiple answers, print any of them.
Examples
Input
3 2
Output
1 3 2
Input
3 1
Output
1 2 3
Input
5 2
Output
1 3 2 4 5
Note
By |x| we denote the absolute value of number x.
Tags: constructive algorithms, greedy
Correct Solution:
```
from sys import exit
n,k = map(int,input().split())
if n<=2:
print(*[i for i in range(1,n+1)])
exit()
else:
d = [1]
for i in range(n+1):
if k<=0:
break
if i%2==0:
d.append(k+d[-1])
k-=1
else:
d.append(d[-1]-k)
k-=1
if len(d)==n:
print(*d)
else:
r = set(d)
print(*d,*[i for i in range(1,n+1) if i not in r])
```
| 14,578 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1, p2, ..., pn.
Your task is to find such permutation p of length n, that the group of numbers |p1 - p2|, |p2 - p3|, ..., |pn - 1 - pn| has exactly k distinct elements.
Input
The single line of the input contains two space-separated positive integers n, k (1 β€ k < n β€ 105).
Output
Print n integers forming the permutation. If there are multiple answers, print any of them.
Examples
Input
3 2
Output
1 3 2
Input
3 1
Output
1 2 3
Input
5 2
Output
1 3 2 4 5
Note
By |x| we denote the absolute value of number x.
Tags: constructive algorithms, greedy
Correct Solution:
```
entry = input().split()
p = int(entry[0])
k = int(entry[1])
forward = 1
backward = k + 1
answer = []
for controller in range((k//2) + 1):
answer.append(str(forward))
if forward != backward:
answer.append(str(backward))
forward += 1
backward -= 1
for filler in range(k+2, p+1):
answer.append(str(filler))
print(' '.join(answer))
```
| 14,579 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1, p2, ..., pn.
Your task is to find such permutation p of length n, that the group of numbers |p1 - p2|, |p2 - p3|, ..., |pn - 1 - pn| has exactly k distinct elements.
Input
The single line of the input contains two space-separated positive integers n, k (1 β€ k < n β€ 105).
Output
Print n integers forming the permutation. If there are multiple answers, print any of them.
Examples
Input
3 2
Output
1 3 2
Input
3 1
Output
1 2 3
Input
5 2
Output
1 3 2 4 5
Note
By |x| we denote the absolute value of number x.
Tags: constructive algorithms, greedy
Correct Solution:
```
n,k = input().split()
answer = []
answer.append(1)
appendVar = 1
lowVar = 2
highVar = 1 + int(k)
for i in range(1, int(k) + 1):
if i % 2 == 1:
appendVar = highVar
highVar -= 1
answer.append(appendVar)
else:
appendVar = lowVar
lowVar += 1
answer.append(appendVar)
for i in range(int(k)+2, int(n) + 1):
answer.append(i)
print(*answer)
```
| 14,580 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1, p2, ..., pn.
Your task is to find such permutation p of length n, that the group of numbers |p1 - p2|, |p2 - p3|, ..., |pn - 1 - pn| has exactly k distinct elements.
Input
The single line of the input contains two space-separated positive integers n, k (1 β€ k < n β€ 105).
Output
Print n integers forming the permutation. If there are multiple answers, print any of them.
Examples
Input
3 2
Output
1 3 2
Input
3 1
Output
1 2 3
Input
5 2
Output
1 3 2 4 5
Note
By |x| we denote the absolute value of number x.
Tags: constructive algorithms, greedy
Correct Solution:
```
n,k=input().split()
n=int(n)
k=int(k)-1
b=[]
s=(k+3)//2
b.append(s)
i=0
if k%2==0:
i=1
else: i=-1
while k>-1:
s=s+i
b.append(s)
if i>0:
i=-1*i-1
else: i=-1*i+1
k-=1
while s<n:
s+=1
b.append(s)
for d in range(len(b)):
print(b[d],end=' ')
```
| 14,581 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1, p2, ..., pn.
Your task is to find such permutation p of length n, that the group of numbers |p1 - p2|, |p2 - p3|, ..., |pn - 1 - pn| has exactly k distinct elements.
Input
The single line of the input contains two space-separated positive integers n, k (1 β€ k < n β€ 105).
Output
Print n integers forming the permutation. If there are multiple answers, print any of them.
Examples
Input
3 2
Output
1 3 2
Input
3 1
Output
1 2 3
Input
5 2
Output
1 3 2 4 5
Note
By |x| we denote the absolute value of number x.
Tags: constructive algorithms, greedy
Correct Solution:
```
f = input()
n , k = map(int , f.split(' '))
x = n
y = 1
for i in range(k):
if(i % 2 == 0):
print(x, end=" ")
x -= 1
else:
print(y, end=" ")
y += 1
bas = 0
t = 0
if k % 2 == 0:
bas = y
t = 1
else:
bas = x
t = -1
for i in range(n - k):
print(bas, end = " ")
bas += t
```
| 14,582 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1, p2, ..., pn.
Your task is to find such permutation p of length n, that the group of numbers |p1 - p2|, |p2 - p3|, ..., |pn - 1 - pn| has exactly k distinct elements.
Input
The single line of the input contains two space-separated positive integers n, k (1 β€ k < n β€ 105).
Output
Print n integers forming the permutation. If there are multiple answers, print any of them.
Examples
Input
3 2
Output
1 3 2
Input
3 1
Output
1 2 3
Input
5 2
Output
1 3 2 4 5
Note
By |x| we denote the absolute value of number x.
Tags: constructive algorithms, greedy
Correct Solution:
```
# Description of the problem can be found at http://codeforces.com/problemset/problem/482/A
n, k = map(int, input().split())
l_n = list()
h = n
l = 1
for i in range(n):
if i < k:
if i % 2 == 0:
l_n.append(i // 2 + 1)
l = i // 2 + 1
else:
l_n.append(n - i // 2)
h = n - i // 2
else:
if i % 2 == 1:
l_n.extend(l + x for x in range(1, n + 1 - i))
if i % 2 == 0:
l_n.extend(h - x for x in range(1, n + 1 - i))
break
print(" ".join(str(x) for x in l_n))
```
| 14,583 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1, p2, ..., pn.
Your task is to find such permutation p of length n, that the group of numbers |p1 - p2|, |p2 - p3|, ..., |pn - 1 - pn| has exactly k distinct elements.
Input
The single line of the input contains two space-separated positive integers n, k (1 β€ k < n β€ 105).
Output
Print n integers forming the permutation. If there are multiple answers, print any of them.
Examples
Input
3 2
Output
1 3 2
Input
3 1
Output
1 2 3
Input
5 2
Output
1 3 2 4 5
Note
By |x| we denote the absolute value of number x.
Submitted Solution:
```
n,k = map(int,input().split())
a = [i for i in range(1,n+1)]
ans = []
l = 0
r = n-1
while l<r:
ans.append(a[l])
ans.append(a[r])
l+=1
r-=1
if l<=r:
ans.append(a[l])
ans = ans[:k]
if k%2==1:
ans += a[k//2+1:k//2+1 + n-k]
else:
ans += a[k//2:k//2 + n-k][::-1]
print(*ans)
```
Yes
| 14,584 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1, p2, ..., pn.
Your task is to find such permutation p of length n, that the group of numbers |p1 - p2|, |p2 - p3|, ..., |pn - 1 - pn| has exactly k distinct elements.
Input
The single line of the input contains two space-separated positive integers n, k (1 β€ k < n β€ 105).
Output
Print n integers forming the permutation. If there are multiple answers, print any of them.
Examples
Input
3 2
Output
1 3 2
Input
3 1
Output
1 2 3
Input
5 2
Output
1 3 2 4 5
Note
By |x| we denote the absolute value of number x.
Submitted Solution:
```
a, b = map(int, input().split(' '))
for i in range(1, a - b + 1):
print(i)
curr = i
if b % 2 == 0:
for i in range(b, 0, -1):
if i % 2 == 0:
curr = curr + i
else:
curr = curr - i
print(curr)
else:
for i in range(b, 0, -1):
if i % 2 == 1:
curr = curr + i
else:
curr = curr - i
print(curr)
```
Yes
| 14,585 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1, p2, ..., pn.
Your task is to find such permutation p of length n, that the group of numbers |p1 - p2|, |p2 - p3|, ..., |pn - 1 - pn| has exactly k distinct elements.
Input
The single line of the input contains two space-separated positive integers n, k (1 β€ k < n β€ 105).
Output
Print n integers forming the permutation. If there are multiple answers, print any of them.
Examples
Input
3 2
Output
1 3 2
Input
3 1
Output
1 2 3
Input
5 2
Output
1 3 2 4 5
Note
By |x| we denote the absolute value of number x.
Submitted Solution:
```
#l1 = int(input())
l2 = input().split()
x = int(l2[0])
y = int(l2[1])
c = x - y
d = True;
for i in range (1, x - y + 1):
print(str(i) + " ", end = '')
v = y
while (v >= 1):
if (d):
print(str(c+v) + " ", end = '')
c += v;
d = False;
else:
print(str(c-v) + " ", end = '')
c -= v;
d = True;
v -= 1
```
Yes
| 14,586 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1, p2, ..., pn.
Your task is to find such permutation p of length n, that the group of numbers |p1 - p2|, |p2 - p3|, ..., |pn - 1 - pn| has exactly k distinct elements.
Input
The single line of the input contains two space-separated positive integers n, k (1 β€ k < n β€ 105).
Output
Print n integers forming the permutation. If there are multiple answers, print any of them.
Examples
Input
3 2
Output
1 3 2
Input
3 1
Output
1 2 3
Input
5 2
Output
1 3 2 4 5
Note
By |x| we denote the absolute value of number x.
Submitted Solution:
```
'''input
3 2
'''
n, k = map(int, input().split())
cur1 = 1
cur2 = n
temp = 0
tt = 0
for i in range(n):
if i < k:
if (i & 1) == 0:
print(cur1, end = ' ')
cur1 += 1
temp = cur1
tt = 1
else:
print(cur2, end = ' ')
cur2 -= 1
temp = cur2
tt = -1
else:
if tt == 1:
print(cur1, end = ' ')
cur1 += 1
else:
print(cur2, end = ' ')
cur2 -= 1
print()
```
Yes
| 14,587 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1, p2, ..., pn.
Your task is to find such permutation p of length n, that the group of numbers |p1 - p2|, |p2 - p3|, ..., |pn - 1 - pn| has exactly k distinct elements.
Input
The single line of the input contains two space-separated positive integers n, k (1 β€ k < n β€ 105).
Output
Print n integers forming the permutation. If there are multiple answers, print any of them.
Examples
Input
3 2
Output
1 3 2
Input
3 1
Output
1 2 3
Input
5 2
Output
1 3 2 4 5
Note
By |x| we denote the absolute value of number x.
Submitted Solution:
```
n,k=map(int,input().split())
s=''
for i in range(k//2):
s+=str(i+1)+' '
s+=str(n-i)+' '
if k!=1 and k%2: s+=[n-k//2]
for i in range(k//2+1,n-(-(-k//2))+1):
s+=str(i)+' '
print(s)
```
No
| 14,588 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1, p2, ..., pn.
Your task is to find such permutation p of length n, that the group of numbers |p1 - p2|, |p2 - p3|, ..., |pn - 1 - pn| has exactly k distinct elements.
Input
The single line of the input contains two space-separated positive integers n, k (1 β€ k < n β€ 105).
Output
Print n integers forming the permutation. If there are multiple answers, print any of them.
Examples
Input
3 2
Output
1 3 2
Input
3 1
Output
1 2 3
Input
5 2
Output
1 3 2 4 5
Note
By |x| we denote the absolute value of number x.
Submitted Solution:
```
import sys
n, k = map(int, input().split())
if k == 1:
for i in range(1, n+1):
print(i, end=' ')
sys.exit();
for i in range(0, k//2):
print(i+1, n-i, end=' ')
if k%2:
z = 0
for i in range(n-k//2, k//2+2, -1):
z = i
print(i, end=' ')
print(z-2, z-1)
else:
for i in range(n-k//2, k//2, -1):
print(i, end=' ')
```
No
| 14,589 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1, p2, ..., pn.
Your task is to find such permutation p of length n, that the group of numbers |p1 - p2|, |p2 - p3|, ..., |pn - 1 - pn| has exactly k distinct elements.
Input
The single line of the input contains two space-separated positive integers n, k (1 β€ k < n β€ 105).
Output
Print n integers forming the permutation. If there are multiple answers, print any of them.
Examples
Input
3 2
Output
1 3 2
Input
3 1
Output
1 2 3
Input
5 2
Output
1 3 2 4 5
Note
By |x| we denote the absolute value of number x.
Submitted Solution:
```
n,k = map(int,input().split())
ll = [str(i) for i in range(1,n+1)]
print(' '.join([ll[0]] + [ll[k]] + ll[1:k] + ll[k+1:]))
```
No
| 14,590 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1, p2, ..., pn.
Your task is to find such permutation p of length n, that the group of numbers |p1 - p2|, |p2 - p3|, ..., |pn - 1 - pn| has exactly k distinct elements.
Input
The single line of the input contains two space-separated positive integers n, k (1 β€ k < n β€ 105).
Output
Print n integers forming the permutation. If there are multiple answers, print any of them.
Examples
Input
3 2
Output
1 3 2
Input
3 1
Output
1 2 3
Input
5 2
Output
1 3 2 4 5
Note
By |x| we denote the absolute value of number x.
Submitted Solution:
```
# python3
n, k = [int(x) for x in input().split()]
begin = 1
if k == 1:
for x in range(1, n+1):
print(x, end=" ")
else:
# k = 2, +2 -1: 1 3 2
# k = 3, +3 -2 + 1: 1 4 2 3
# k = 4, +4 -3 + 2 -1: 1 5 2 4 3
for y in range(n-k-1):
print(begin+y, end=" ")
diff = n-k
high = n
while high >= diff + 1:
print(diff, end=" ")
print(high, end=" ")
diff += 1
high -= 1
print(high)
# if diff == high and k % 2 != 0:
# print(high)
# for z in range((k+1)/2):
# # Difference continues to decrease by 1
# print(diff + z, end=" ")
# print(n - z, end=" ")
# if k % 2 == 0:
# print((diff+n)//2)
```
No
| 14,591 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Shuseki Islands are an archipelago of 30001 small islands in the Yutampo Sea. The islands are evenly spaced along a line, numbered from 0 to 30000 from the west to the east. These islands are known to contain many treasures. There are n gems in the Shuseki Islands in total, and the i-th gem is located on island pi.
Mr. Kitayuta has just arrived at island 0. With his great jumping ability, he will repeatedly perform jumps between islands to the east according to the following process:
* First, he will jump from island 0 to island d.
* After that, he will continue jumping according to the following rule. Let l be the length of the previous jump, that is, if his previous jump was from island prev to island cur, let l = cur - prev. He will perform a jump of length l - 1, l or l + 1 to the east. That is, he will jump to island (cur + l - 1), (cur + l) or (cur + l + 1) (if they exist). The length of a jump must be positive, that is, he cannot perform a jump of length 0 when l = 1. If there is no valid destination, he will stop jumping.
Mr. Kitayuta will collect the gems on the islands visited during the process. Find the maximum number of gems that he can collect.
Input
The first line of the input contains two space-separated integers n and d (1 β€ n, d β€ 30000), denoting the number of the gems in the Shuseki Islands and the length of the Mr. Kitayuta's first jump, respectively.
The next n lines describe the location of the gems. The i-th of them (1 β€ i β€ n) contains a integer pi (d β€ p1 β€ p2 β€ ... β€ pn β€ 30000), denoting the number of the island that contains the i-th gem.
Output
Print the maximum number of gems that Mr. Kitayuta can collect.
Examples
Input
4 10
10
21
27
27
Output
3
Input
8 8
9
19
28
36
45
55
66
78
Output
6
Input
13 7
8
8
9
16
17
17
18
21
23
24
24
26
30
Output
4
Note
In the first sample, the optimal route is 0 β 10 (+1 gem) β 19 β 27 (+2 gems) β ...
In the second sample, the optimal route is 0 β 8 β 15 β 21 β 28 (+1 gem) β 36 (+1 gem) β 45 (+1 gem) β 55 (+1 gem) β 66 (+1 gem) β 78 (+1 gem) β ...
In the third sample, the optimal route is 0 β 7 β 13 β 18 (+1 gem) β 24 (+2 gems) β 30 (+1 gem) β ...
Submitted Solution:
```
import sys
sys.setrecursionlimit(30005)
from sys import stdin,stdout
n,d=map(int,stdin.readline().split(' '))
coins=[0 for i in range(30001)];m=-1
for _ in range(n):
t1=int(stdin.readline());m=max(m,t1)
coins[t1]+=1
dp=[-1 for i in range(30001)]
def jump(sp,x,l):
global coins,dp,m,n
#print("\t"*sp,x,l)
if x>m:
return 0
if dp[x]!=-1:
#print("using dp")
return dp[x]
else:
ans=coins[x];inc=0
if x+l-1<30001 and l!=1:
inc=max(inc,jump(sp+1,x+l-1,l-1))
if x+l<30001 and l!=0:
inc=max(inc,jump(sp+1,x+l,l))
if x+l+1<30001:
inc=max(inc,jump(sp+1,x+l+1,l+1))
dp[x]=ans+inc
return ans+inc
print(jump(0,d,d))
#print(dp[:100])
```
No
| 14,592 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Shuseki Islands are an archipelago of 30001 small islands in the Yutampo Sea. The islands are evenly spaced along a line, numbered from 0 to 30000 from the west to the east. These islands are known to contain many treasures. There are n gems in the Shuseki Islands in total, and the i-th gem is located on island pi.
Mr. Kitayuta has just arrived at island 0. With his great jumping ability, he will repeatedly perform jumps between islands to the east according to the following process:
* First, he will jump from island 0 to island d.
* After that, he will continue jumping according to the following rule. Let l be the length of the previous jump, that is, if his previous jump was from island prev to island cur, let l = cur - prev. He will perform a jump of length l - 1, l or l + 1 to the east. That is, he will jump to island (cur + l - 1), (cur + l) or (cur + l + 1) (if they exist). The length of a jump must be positive, that is, he cannot perform a jump of length 0 when l = 1. If there is no valid destination, he will stop jumping.
Mr. Kitayuta will collect the gems on the islands visited during the process. Find the maximum number of gems that he can collect.
Input
The first line of the input contains two space-separated integers n and d (1 β€ n, d β€ 30000), denoting the number of the gems in the Shuseki Islands and the length of the Mr. Kitayuta's first jump, respectively.
The next n lines describe the location of the gems. The i-th of them (1 β€ i β€ n) contains a integer pi (d β€ p1 β€ p2 β€ ... β€ pn β€ 30000), denoting the number of the island that contains the i-th gem.
Output
Print the maximum number of gems that Mr. Kitayuta can collect.
Examples
Input
4 10
10
21
27
27
Output
3
Input
8 8
9
19
28
36
45
55
66
78
Output
6
Input
13 7
8
8
9
16
17
17
18
21
23
24
24
26
30
Output
4
Note
In the first sample, the optimal route is 0 β 10 (+1 gem) β 19 β 27 (+2 gems) β ...
In the second sample, the optimal route is 0 β 8 β 15 β 21 β 28 (+1 gem) β 36 (+1 gem) β 45 (+1 gem) β 55 (+1 gem) β 66 (+1 gem) β 78 (+1 gem) β ...
In the third sample, the optimal route is 0 β 7 β 13 β 18 (+1 gem) β 24 (+2 gems) β 30 (+1 gem) β ...
Submitted Solution:
```
import bisect
import os, sys, atexit,threading
from io import BytesIO, StringIO
input = BytesIO(os.read(0, os.fstat(0).st_size)).readline
_OUTPUT_BUFFER = StringIO()
sys.stdout = _OUTPUT_BUFFER
@atexit.register
def write():
sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
def calculate(i,l):
global maxGem,offset
if l==0 or i>maxGem :
return 0
# print (i, l,offset)
if dp[i][l-offset]==-1:
answer = 0
answer+=gems[i]
answer+=max(calculate(i+l-1,l-1),calculate(i+l,l),calculate(i+l+1,l+1))
dp[i][l-offset] = answer
return dp[i][l-offset]
def solve():
n,d = map(int,input().split())
global maxGem, offset
for _ in range(n):
gem = int(input())
gems[gem]+=1
maxGem = max(maxGem,gem)
if d<=maxGem:
totalDpLength = d+245-max(d-245,0)+1
offset = max(d-245,0)
for _ in range(maxGem+1):
dp.append([-1]*totalDpLength)
for x in range(maxGem+1,d-1,-1):
for y in range(totalDpLength+offset,offset-1,-1):
# print ("x,y ",x,y)
calculate(x,y)
print (dp[d][d])
else:
print (0)
try:
dp = []
gems = [0]*30001
maxGem = 0
offset = 0
solve()
except Exception as e:
print (e)
```
No
| 14,593 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Shuseki Islands are an archipelago of 30001 small islands in the Yutampo Sea. The islands are evenly spaced along a line, numbered from 0 to 30000 from the west to the east. These islands are known to contain many treasures. There are n gems in the Shuseki Islands in total, and the i-th gem is located on island pi.
Mr. Kitayuta has just arrived at island 0. With his great jumping ability, he will repeatedly perform jumps between islands to the east according to the following process:
* First, he will jump from island 0 to island d.
* After that, he will continue jumping according to the following rule. Let l be the length of the previous jump, that is, if his previous jump was from island prev to island cur, let l = cur - prev. He will perform a jump of length l - 1, l or l + 1 to the east. That is, he will jump to island (cur + l - 1), (cur + l) or (cur + l + 1) (if they exist). The length of a jump must be positive, that is, he cannot perform a jump of length 0 when l = 1. If there is no valid destination, he will stop jumping.
Mr. Kitayuta will collect the gems on the islands visited during the process. Find the maximum number of gems that he can collect.
Input
The first line of the input contains two space-separated integers n and d (1 β€ n, d β€ 30000), denoting the number of the gems in the Shuseki Islands and the length of the Mr. Kitayuta's first jump, respectively.
The next n lines describe the location of the gems. The i-th of them (1 β€ i β€ n) contains a integer pi (d β€ p1 β€ p2 β€ ... β€ pn β€ 30000), denoting the number of the island that contains the i-th gem.
Output
Print the maximum number of gems that Mr. Kitayuta can collect.
Examples
Input
4 10
10
21
27
27
Output
3
Input
8 8
9
19
28
36
45
55
66
78
Output
6
Input
13 7
8
8
9
16
17
17
18
21
23
24
24
26
30
Output
4
Note
In the first sample, the optimal route is 0 β 10 (+1 gem) β 19 β 27 (+2 gems) β ...
In the second sample, the optimal route is 0 β 8 β 15 β 21 β 28 (+1 gem) β 36 (+1 gem) β 45 (+1 gem) β 55 (+1 gem) β 66 (+1 gem) β 78 (+1 gem) β ...
In the third sample, the optimal route is 0 β 7 β 13 β 18 (+1 gem) β 24 (+2 gems) β 30 (+1 gem) β ...
Submitted Solution:
```
import bisect
import os, sys, atexit,threading
from io import BytesIO, StringIO
input = BytesIO(os.read(0, os.fstat(0).st_size)).readline
_OUTPUT_BUFFER = StringIO()
sys.stdout = _OUTPUT_BUFFER
@atexit.register
def write():
sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
def calculate(i,l):
global maxGem,offset
if l==0 or i>maxGem :
return 0
# print (i, l,offset)
if dp[i][l-offset]==-1:
answer = 0
answer+=gems[i]
answer+=max(calculate(i+l-1,l-1),calculate(i+l,l),calculate(i+l+1,l+1))
dp[i][l-offset] = answer
return dp[i][l-offset]
def solve():
n,d = map(int,input().split())
global maxGem, offset
for _ in range(n):
gem = int(input())
gems[gem]+=1
maxGem = max(maxGem,gem)
totalDpLength = d+245-max(d-245,0)+1
offset = max(d-245,0)
for _ in range(maxGem+1):
dp.append([-1]*(totalDpLength+1))
for x in range(maxGem+1,d-1,-1):
for y in range(totalDpLength+offset,offset-1,-1):
# print ("x,y ",x,y)
calculate(x,y)
print (dp[d][d])
try:
dp = []
gems = [0]*30001
maxGem = 0
offset = 0
solve()
except Exception as e:
print (e)
```
No
| 14,594 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Shuseki Islands are an archipelago of 30001 small islands in the Yutampo Sea. The islands are evenly spaced along a line, numbered from 0 to 30000 from the west to the east. These islands are known to contain many treasures. There are n gems in the Shuseki Islands in total, and the i-th gem is located on island pi.
Mr. Kitayuta has just arrived at island 0. With his great jumping ability, he will repeatedly perform jumps between islands to the east according to the following process:
* First, he will jump from island 0 to island d.
* After that, he will continue jumping according to the following rule. Let l be the length of the previous jump, that is, if his previous jump was from island prev to island cur, let l = cur - prev. He will perform a jump of length l - 1, l or l + 1 to the east. That is, he will jump to island (cur + l - 1), (cur + l) or (cur + l + 1) (if they exist). The length of a jump must be positive, that is, he cannot perform a jump of length 0 when l = 1. If there is no valid destination, he will stop jumping.
Mr. Kitayuta will collect the gems on the islands visited during the process. Find the maximum number of gems that he can collect.
Input
The first line of the input contains two space-separated integers n and d (1 β€ n, d β€ 30000), denoting the number of the gems in the Shuseki Islands and the length of the Mr. Kitayuta's first jump, respectively.
The next n lines describe the location of the gems. The i-th of them (1 β€ i β€ n) contains a integer pi (d β€ p1 β€ p2 β€ ... β€ pn β€ 30000), denoting the number of the island that contains the i-th gem.
Output
Print the maximum number of gems that Mr. Kitayuta can collect.
Examples
Input
4 10
10
21
27
27
Output
3
Input
8 8
9
19
28
36
45
55
66
78
Output
6
Input
13 7
8
8
9
16
17
17
18
21
23
24
24
26
30
Output
4
Note
In the first sample, the optimal route is 0 β 10 (+1 gem) β 19 β 27 (+2 gems) β ...
In the second sample, the optimal route is 0 β 8 β 15 β 21 β 28 (+1 gem) β 36 (+1 gem) β 45 (+1 gem) β 55 (+1 gem) β 66 (+1 gem) β 78 (+1 gem) β ...
In the third sample, the optimal route is 0 β 7 β 13 β 18 (+1 gem) β 24 (+2 gems) β 30 (+1 gem) β ...
Submitted Solution:
```
import bisect
import os, sys, atexit,threading
from io import BytesIO, StringIO
input = BytesIO(os.read(0, os.fstat(0).st_size)).readline
_OUTPUT_BUFFER = StringIO()
sys.stdout = _OUTPUT_BUFFER
@atexit.register
def write():
sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
def calculate(i,l):
global maxGem,offset
if l==0 or l<offset or i>maxGem :
return 0
# print (i, l,offset)
if dp[i][l-offset]==-1:
answer = 0
answer+=gems[i]
answer+=max(calculate(i+l-1,l-1),calculate(i+l,l),calculate(i+l+1,l+1))
dp[i][l-offset] = answer
return dp[i][l-offset]
def solve():
n,d = map(int,input().split())
global maxGem, offset
for _ in range(n):
gem = int(input())
gems[gem]+=1
maxGem = max(maxGem,gem)
if d<=maxGem:
totalDpLength = d+245-max(d-245,0)+1
offset = max(d-245,0)
for _ in range(maxGem+1):
dp.append([-1]*totalDpLength)
for x in range(maxGem+1,d-1,-1):
for y in range(totalDpLength+offset-1,offset-1,-1):
# print ("x,y ",x,y)
calculate(x,y)
print (dp[d][d])
else:
print (0)
try:
dp = []
gems = [0]*30001
maxGem = 0
offset = 0
solve()
except Exception as e:
print (e)
```
No
| 14,595 |
Provide tags and a correct Python 3 solution for this coding contest problem.
ATMs of a well-known bank of a small country are arranged so that they can not give any amount of money requested by the user. Due to the limited size of the bill dispenser (the device that is directly giving money from an ATM) and some peculiarities of the ATM structure, you can get at most k bills from it, and the bills may be of at most two distinct denominations.
For example, if a country uses bills with denominations 10, 50, 100, 500, 1000 and 5000 burles, then at k = 20 such ATM can give sums 100 000 burles and 96 000 burles, but it cannot give sums 99 000 and 101 000 burles.
Let's suppose that the country uses bills of n distinct denominations, and the ATM that you are using has an unlimited number of bills of each type. You know that during the day you will need to withdraw a certain amount of cash q times. You know that when the ATM has multiple ways to give money, it chooses the one which requires the minimum number of bills, or displays an error message if it cannot be done. Determine the result of each of the q of requests for cash withdrawal.
Input
The first line contains two integers n, k (1 β€ n β€ 5000, 1 β€ k β€ 20).
The next line contains n space-separated integers ai (1 β€ ai β€ 107) β the denominations of the bills that are used in the country. Numbers ai follow in the strictly increasing order.
The next line contains integer q (1 β€ q β€ 20) β the number of requests for cash withdrawal that you will make.
The next q lines contain numbers xi (1 β€ xi β€ 2Β·108) β the sums of money in burles that you are going to withdraw from the ATM.
Output
For each request for cash withdrawal print on a single line the minimum number of bills it can be done, or print - 1, if it is impossible to get the corresponding sum.
Examples
Input
6 20
10 50 100 500 1000 5000
8
4200
100000
95000
96000
99000
10100
2015
9950
Output
6
20
19
20
-1
3
-1
-1
Input
5 2
1 2 3 5 8
8
1
3
5
7
9
11
13
15
Output
1
1
1
2
2
2
2
-1
Tags: binary search, sortings
Correct Solution:
```
f = lambda: map(int, input().split())
n, k = f()
t = list(f())
d = {0: 0}
for q in t:
for i in range(1, k + 1): d[q * i] = i
for j in range(int(input())):
a = int(input())
p = [i + d[a - b] for b, i in d.items() if a - b in d]
print(min(p) if p and min(p) <= k else -1)
```
| 14,596 |
Provide tags and a correct Python 3 solution for this coding contest problem.
ATMs of a well-known bank of a small country are arranged so that they can not give any amount of money requested by the user. Due to the limited size of the bill dispenser (the device that is directly giving money from an ATM) and some peculiarities of the ATM structure, you can get at most k bills from it, and the bills may be of at most two distinct denominations.
For example, if a country uses bills with denominations 10, 50, 100, 500, 1000 and 5000 burles, then at k = 20 such ATM can give sums 100 000 burles and 96 000 burles, but it cannot give sums 99 000 and 101 000 burles.
Let's suppose that the country uses bills of n distinct denominations, and the ATM that you are using has an unlimited number of bills of each type. You know that during the day you will need to withdraw a certain amount of cash q times. You know that when the ATM has multiple ways to give money, it chooses the one which requires the minimum number of bills, or displays an error message if it cannot be done. Determine the result of each of the q of requests for cash withdrawal.
Input
The first line contains two integers n, k (1 β€ n β€ 5000, 1 β€ k β€ 20).
The next line contains n space-separated integers ai (1 β€ ai β€ 107) β the denominations of the bills that are used in the country. Numbers ai follow in the strictly increasing order.
The next line contains integer q (1 β€ q β€ 20) β the number of requests for cash withdrawal that you will make.
The next q lines contain numbers xi (1 β€ xi β€ 2Β·108) β the sums of money in burles that you are going to withdraw from the ATM.
Output
For each request for cash withdrawal print on a single line the minimum number of bills it can be done, or print - 1, if it is impossible to get the corresponding sum.
Examples
Input
6 20
10 50 100 500 1000 5000
8
4200
100000
95000
96000
99000
10100
2015
9950
Output
6
20
19
20
-1
3
-1
-1
Input
5 2
1 2 3 5 8
8
1
3
5
7
9
11
13
15
Output
1
1
1
2
2
2
2
-1
Tags: binary search, sortings
Correct Solution:
```
f = lambda: map(int, input().split())
n, k = f()
t = list(f())
d = {0: 0}
for q in t:
for i in range(1, k + 1): d[q * i] = i
for j in range(int(input())):
a = int(input())
p = [i + d[a - b] for b, i in d.items() if a - b in d]
print(min(p) if p and min(p) <= k else -1)
# Made By Mostafa_Khaled
```
| 14,597 |
Provide tags and a correct Python 3 solution for this coding contest problem.
ATMs of a well-known bank of a small country are arranged so that they can not give any amount of money requested by the user. Due to the limited size of the bill dispenser (the device that is directly giving money from an ATM) and some peculiarities of the ATM structure, you can get at most k bills from it, and the bills may be of at most two distinct denominations.
For example, if a country uses bills with denominations 10, 50, 100, 500, 1000 and 5000 burles, then at k = 20 such ATM can give sums 100 000 burles and 96 000 burles, but it cannot give sums 99 000 and 101 000 burles.
Let's suppose that the country uses bills of n distinct denominations, and the ATM that you are using has an unlimited number of bills of each type. You know that during the day you will need to withdraw a certain amount of cash q times. You know that when the ATM has multiple ways to give money, it chooses the one which requires the minimum number of bills, or displays an error message if it cannot be done. Determine the result of each of the q of requests for cash withdrawal.
Input
The first line contains two integers n, k (1 β€ n β€ 5000, 1 β€ k β€ 20).
The next line contains n space-separated integers ai (1 β€ ai β€ 107) β the denominations of the bills that are used in the country. Numbers ai follow in the strictly increasing order.
The next line contains integer q (1 β€ q β€ 20) β the number of requests for cash withdrawal that you will make.
The next q lines contain numbers xi (1 β€ xi β€ 2Β·108) β the sums of money in burles that you are going to withdraw from the ATM.
Output
For each request for cash withdrawal print on a single line the minimum number of bills it can be done, or print - 1, if it is impossible to get the corresponding sum.
Examples
Input
6 20
10 50 100 500 1000 5000
8
4200
100000
95000
96000
99000
10100
2015
9950
Output
6
20
19
20
-1
3
-1
-1
Input
5 2
1 2 3 5 8
8
1
3
5
7
9
11
13
15
Output
1
1
1
2
2
2
2
-1
Tags: binary search, sortings
Correct Solution:
```
n, k = map(int, input().split())
a = set(map(int, input().split()))
q = int(input())
# def isIn(x, fm, to):
# if fm >= to:
# return a[fm] == x
# t = a[(fm+to) // 2]
# if t > x:
# return isIn(x, fm, (fm+to) // 2 - 1)
# elif t < x:
# return isIn(x, (fm+to) // 2 + 1, to)
# else:
# return True
for _ in range(q):
x = int(input())
if x in a:
print(1)
continue
found = False
for i in range(2, k + 1):
for j in range(1, i // 2 + 1):
for l in a:
t = x - l * j
if t % (i - j) != 0:
continue
# if isIn(t // (i - j), 0, n - 1):
if t // (i - j) in a:
print(i)
found = True
break
if found:
break
if found:
break
if not found:
print(-1)
```
| 14,598 |
Provide tags and a correct Python 3 solution for this coding contest problem.
ATMs of a well-known bank of a small country are arranged so that they can not give any amount of money requested by the user. Due to the limited size of the bill dispenser (the device that is directly giving money from an ATM) and some peculiarities of the ATM structure, you can get at most k bills from it, and the bills may be of at most two distinct denominations.
For example, if a country uses bills with denominations 10, 50, 100, 500, 1000 and 5000 burles, then at k = 20 such ATM can give sums 100 000 burles and 96 000 burles, but it cannot give sums 99 000 and 101 000 burles.
Let's suppose that the country uses bills of n distinct denominations, and the ATM that you are using has an unlimited number of bills of each type. You know that during the day you will need to withdraw a certain amount of cash q times. You know that when the ATM has multiple ways to give money, it chooses the one which requires the minimum number of bills, or displays an error message if it cannot be done. Determine the result of each of the q of requests for cash withdrawal.
Input
The first line contains two integers n, k (1 β€ n β€ 5000, 1 β€ k β€ 20).
The next line contains n space-separated integers ai (1 β€ ai β€ 107) β the denominations of the bills that are used in the country. Numbers ai follow in the strictly increasing order.
The next line contains integer q (1 β€ q β€ 20) β the number of requests for cash withdrawal that you will make.
The next q lines contain numbers xi (1 β€ xi β€ 2Β·108) β the sums of money in burles that you are going to withdraw from the ATM.
Output
For each request for cash withdrawal print on a single line the minimum number of bills it can be done, or print - 1, if it is impossible to get the corresponding sum.
Examples
Input
6 20
10 50 100 500 1000 5000
8
4200
100000
95000
96000
99000
10100
2015
9950
Output
6
20
19
20
-1
3
-1
-1
Input
5 2
1 2 3 5 8
8
1
3
5
7
9
11
13
15
Output
1
1
1
2
2
2
2
-1
Tags: binary search, sortings
Correct Solution:
```
n_k = input()
n_k = n_k.split(" ")
n = int(n_k[0])
k = int(n_k[1])
ais = input()
ais = ais.split(" ")
q = int(input())
pares = {}
for a in ais:
a = int(a)
for i in range(k):
p = int((i+1)*a)
if (p not in pares) or (i+1 < pares[p]):
pares[p] = i+1
m = 1000000000
for i in range(q):
x = int(input())
ans = 1000;
minimo = m
for plata, deuda in pares.items():
if plata == x:
if deuda <= k:
if deuda < minimo:
minimo = deuda
else:
r = x-plata
if r in pares:
if deuda+pares[r] < minimo:
if deuda + pares[r] <= k:
minimo = deuda+pares[r]
if minimo == m:
print(-1)
else:
print(minimo)
```
| 14,599 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.