message stringlengths 2 44.5k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 42 109k | cluster float64 5 5 | __index_level_0__ int64 84 217k |
|---|---|---|---|---|---|
Provide a correct Python 3 solution for this coding contest problem.
<image>
At the request of a friend who started learning abacus, you decided to create a program to display the abacus beads. Create a program that takes a certain number as input and outputs a row of abacus beads. However, the number of digits of the abacus to be displayed is 5 digits, and the arrangement of beads from 0 to 9 is as follows using'*' (half-width asterisk),''(half-width blank), and'=' (half-width equal). It shall be expressed as.
<image>
Input
Multiple test cases are given. Up to 5 digits (integer) are given on one line for each test case.
The number of test cases does not exceed 1024.
Output
Output the abacus bead arrangement for each test case. Insert a blank line between the test cases.
Example
Input
2006
1111
Output
****
*
=====
* *
****
* ***
*****
*****
*****
=====
****
*
*****
*****
***** | instruction | 0 | 84,111 | 5 | 168,222 |
"Correct Solution:
```
abacus = ["* = ****", "* =* ***", "* =** **", "* =*** *", "* =**** ",
" *= ****", " *=* ***", " *=** **", " *=*** *", " *=**** "]
first = False
while 1:
try:
n = input()
except EOFError:
break
if first:
print()
else:
first = True
n = n.zfill(5)
nlist = list(n)
ans = []
for n in nlist:
ans.append(list(abacus[int(n)]))
ans_t = [list(x) for x in zip(*ans)]
for i in range(8):
print(''.join(a for a in ans_t[i]))
``` | output | 1 | 84,111 | 5 | 168,223 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a positive integer n.
Find a sequence of fractions (a_i)/(b_i), i = 1 … k (where a_i and b_i are positive integers) for some k such that:
$$$ \begin{cases} $b_i$ divides $n$, $1 < b_i < n$ for $i = 1 … k$ \\\ $1 ≤ a_i < b_i$ for $i = 1 … k$ \\\ \text{$∑_{i=1}^k (a_i)/(b_i) = 1 - 1/n$} \end{cases} $$$
Input
The input consists of a single integer n (2 ≤ n ≤ 10^9).
Output
In the first line print "YES" if there exists such a sequence of fractions or "NO" otherwise.
If there exists such a sequence, next lines should contain a description of the sequence in the following format.
The second line should contain integer k (1 ≤ k ≤ 100 000) — the number of elements in the sequence. It is guaranteed that if such a sequence exists, then there exists a sequence of length at most 100 000.
Next k lines should contain fractions of the sequence with two integers a_i and b_i on each line.
Examples
Input
2
Output
NO
Input
6
Output
YES
2
1 2
1 3
Note
In the second example there is a sequence 1/2, 1/3 such that 1/2 + 1/3 = 1 - 1/6.
Submitted Solution:
```
from math import sqrt
def phi(u):
ans = u
for i in range(2, int(sqrt(n)) + 1):
if u % i == 0:
while u % i == 0:
u = u / i
ans = ans - int(ans / i)
if n > 1:
ans = ans - int(ans / n)
return ans
def binpow(u, a, mod):
ans = 1
if a == 0:
return 1;
while a > 0:
if a % 2 == 0:
u = (u ** 2) % mod
a = int(a / 2)
else :
ans = (ans * u) % mod
a = a - 1
return int(ans)
n = int(input())
b1 = 1
b2 = 0
nn = n
for i in range(2, int(sqrt(n)) + 1):
if n%i == 0 :
while nn % i == 0:
b1 = b1 * i
nn = nn / i
b2 = int(n / b1)
break
if b2 < 2:
print("NO")
exit()
print("YES")
print(2)
print(b1 - binpow(b2, phi(b1) - 1, b1), b1)
print(b2 - binpow(b1, phi(b2) - 1, b2), b2)
``` | instruction | 0 | 84,266 | 5 | 168,532 |
No | output | 1 | 84,266 | 5 | 168,533 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a positive integer n.
Find a sequence of fractions (a_i)/(b_i), i = 1 … k (where a_i and b_i are positive integers) for some k such that:
$$$ \begin{cases} $b_i$ divides $n$, $1 < b_i < n$ for $i = 1 … k$ \\\ $1 ≤ a_i < b_i$ for $i = 1 … k$ \\\ \text{$∑_{i=1}^k (a_i)/(b_i) = 1 - 1/n$} \end{cases} $$$
Input
The input consists of a single integer n (2 ≤ n ≤ 10^9).
Output
In the first line print "YES" if there exists such a sequence of fractions or "NO" otherwise.
If there exists such a sequence, next lines should contain a description of the sequence in the following format.
The second line should contain integer k (1 ≤ k ≤ 100 000) — the number of elements in the sequence. It is guaranteed that if such a sequence exists, then there exists a sequence of length at most 100 000.
Next k lines should contain fractions of the sequence with two integers a_i and b_i on each line.
Examples
Input
2
Output
NO
Input
6
Output
YES
2
1 2
1 3
Note
In the second example there is a sequence 1/2, 1/3 such that 1/2 + 1/3 = 1 - 1/6.
Submitted Solution:
```
from math import sqrt
from itertools import count, islice
from functools import reduce
def isPrime(n):
return n > 1 and all(n % i for i in islice(count(2), int(sqrt(n) - 1)))
def factors(n: int):
_factors = []
for i in range(2, int(sqrt(n)) + 2):
times = 0
while n % i == 0:
times += 1
n //= i
if times:
_factors.append((i, times))
return _factors
if __name__ == '__main__':
n = int(input())
if isPrime(n):
print('NO')
else:
print('YES')
_factors = factors(n)
print(len(_factors))
for p, t in _factors:
for tt in range(1, t + 1):
print('1 {}'.format(p ** tt))
``` | instruction | 0 | 84,267 | 5 | 168,534 |
No | output | 1 | 84,267 | 5 | 168,535 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a positive integer n.
Find a sequence of fractions (a_i)/(b_i), i = 1 … k (where a_i and b_i are positive integers) for some k such that:
$$$ \begin{cases} $b_i$ divides $n$, $1 < b_i < n$ for $i = 1 … k$ \\\ $1 ≤ a_i < b_i$ for $i = 1 … k$ \\\ \text{$∑_{i=1}^k (a_i)/(b_i) = 1 - 1/n$} \end{cases} $$$
Input
The input consists of a single integer n (2 ≤ n ≤ 10^9).
Output
In the first line print "YES" if there exists such a sequence of fractions or "NO" otherwise.
If there exists such a sequence, next lines should contain a description of the sequence in the following format.
The second line should contain integer k (1 ≤ k ≤ 100 000) — the number of elements in the sequence. It is guaranteed that if such a sequence exists, then there exists a sequence of length at most 100 000.
Next k lines should contain fractions of the sequence with two integers a_i and b_i on each line.
Examples
Input
2
Output
NO
Input
6
Output
YES
2
1 2
1 3
Note
In the second example there is a sequence 1/2, 1/3 such that 1/2 + 1/3 = 1 - 1/6.
Submitted Solution:
```
from math import sqrt
from itertools import count, islice
from fractions import Fraction
def isPrime(n):
return n > 1 and all(n % i for i in islice(count(2), int(sqrt(n) - 1)))
def factors(n: int):
_factors = []
for i in range(2, int(sqrt(n)) + 1):
times = 0
while n % i == 0:
times += 1
n //= i
if times:
_factors.append((i, times))
if n > 1:
_factors.append((n, 1))
return _factors
if __name__ == '__main__':
n = int(input())
_f = factors(n)
sz = len(_f)
if sz < 2:
print('NO')
else:
print('YES')
print(sum(fr[1] for fr in _f))
sum = Fraction(0, 1)
for p, t in _f:
for tt in range(1, t + 1):
if p <= sqrt(n):
den = p ** tt
sum += Fraction(1, den)
print('1 {}'.format(den))
else:
nn = Fraction(n - 1, n) - sum
print('{} {}'.format(nn.numerator, nn.denominator))
``` | instruction | 0 | 84,268 | 5 | 168,536 |
No | output | 1 | 84,268 | 5 | 168,537 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given array a with n integers and m queries. The i-th query is given with three integers li, ri, xi.
For the i-th query find any position pi (li ≤ pi ≤ ri) so that api ≠ xi.
Input
The first line contains two integers n, m (1 ≤ n, m ≤ 2·105) — the number of elements in a and the number of queries.
The second line contains n integers ai (1 ≤ ai ≤ 106) — the elements of the array a.
Each of the next m lines contains three integers li, ri, xi (1 ≤ li ≤ ri ≤ n, 1 ≤ xi ≤ 106) — the parameters of the i-th query.
Output
Print m lines. On the i-th line print integer pi — the position of any number not equal to xi in segment [li, ri] or the value - 1 if there is no such number.
Examples
Input
6 4
1 2 1 1 3 5
1 4 1
2 6 2
3 4 1
3 4 2
Output
2
6
-1
4
Submitted Solution:
```
from sys import stdin
n,m = [int(i) for i in stdin.readline().split()]
a = [int(i) for i in stdin.readline().split()]
b = [None] * n
b[0] = -1
ans = [None] * m
for i in range(1,len(a)):
if a[i] == a[i - 1]:
b[i] = b[i - 1]
else:
b[i] = i - 1
for i in range(m):
l,r,x = [int(j) for j in stdin.readline().split()]
k = r - 1
if a[k] != x:
ans[i] = str(k + 1)
elif b[k] + 1 >= l:
ans[i] = str(b[k] + 1)
else:
ans[i] = ('-1')
print('\n'.join(ans))
``` | instruction | 0 | 84,635 | 5 | 169,270 |
Yes | output | 1 | 84,635 | 5 | 169,271 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given array a with n integers and m queries. The i-th query is given with three integers li, ri, xi.
For the i-th query find any position pi (li ≤ pi ≤ ri) so that api ≠ xi.
Input
The first line contains two integers n, m (1 ≤ n, m ≤ 2·105) — the number of elements in a and the number of queries.
The second line contains n integers ai (1 ≤ ai ≤ 106) — the elements of the array a.
Each of the next m lines contains three integers li, ri, xi (1 ≤ li ≤ ri ≤ n, 1 ≤ xi ≤ 106) — the parameters of the i-th query.
Output
Print m lines. On the i-th line print integer pi — the position of any number not equal to xi in segment [li, ri] or the value - 1 if there is no such number.
Examples
Input
6 4
1 2 1 1 3 5
1 4 1
2 6 2
3 4 1
3 4 2
Output
2
6
-1
4
Submitted Solution:
```
from sys import *
def input():
return stdin.readline()
n ,m = map(int, input().split())
a = list(map(int, input().split()))
ans=[]
difPre=[-1 for i in range(n)]
for i in range(1,n):
if a[i]==a[i-1]:
difPre[i]=difPre[i-1]
else:
difPre[i]=i-1
for i in range(m):
l,r,x=map(int,input().split())
if a[r-1]!=x:
ans.append(str(r))
else:
if difPre[r-1]>=l-1:
ans.append(str(difPre[r-1]+1))
else:
ans.append('-1')
print('\n'.join(ans))
``` | instruction | 0 | 84,636 | 5 | 169,272 |
Yes | output | 1 | 84,636 | 5 | 169,273 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given array a with n integers and m queries. The i-th query is given with three integers li, ri, xi.
For the i-th query find any position pi (li ≤ pi ≤ ri) so that api ≠ xi.
Input
The first line contains two integers n, m (1 ≤ n, m ≤ 2·105) — the number of elements in a and the number of queries.
The second line contains n integers ai (1 ≤ ai ≤ 106) — the elements of the array a.
Each of the next m lines contains three integers li, ri, xi (1 ≤ li ≤ ri ≤ n, 1 ≤ xi ≤ 106) — the parameters of the i-th query.
Output
Print m lines. On the i-th line print integer pi — the position of any number not equal to xi in segment [li, ri] or the value - 1 if there is no such number.
Examples
Input
6 4
1 2 1 1 3 5
1 4 1
2 6 2
3 4 1
3 4 2
Output
2
6
-1
4
Submitted Solution:
```
n,m = [int(i) for i in input().split()]
a = input().split()
result = []
prev = [-1]*n
for i in range(1,n):
if a[i] != a[i-1]:
prev[i] = i-1
else:
prev[i] = prev[i-1]
for i in range(m):
l,r,x = input().split()
r = int(r)
if a[r-1] != x:
answer = r
elif prev[r-1]<int(l)-1:
answer = -1
else:
answer = prev[r-1]+1
result.append(str(answer))
print('\n' .join(result))
``` | instruction | 0 | 84,637 | 5 | 169,274 |
Yes | output | 1 | 84,637 | 5 | 169,275 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given array a with n integers and m queries. The i-th query is given with three integers li, ri, xi.
For the i-th query find any position pi (li ≤ pi ≤ ri) so that api ≠ xi.
Input
The first line contains two integers n, m (1 ≤ n, m ≤ 2·105) — the number of elements in a and the number of queries.
The second line contains n integers ai (1 ≤ ai ≤ 106) — the elements of the array a.
Each of the next m lines contains three integers li, ri, xi (1 ≤ li ≤ ri ≤ n, 1 ≤ xi ≤ 106) — the parameters of the i-th query.
Output
Print m lines. On the i-th line print integer pi — the position of any number not equal to xi in segment [li, ri] or the value - 1 if there is no such number.
Examples
Input
6 4
1 2 1 1 3 5
1 4 1
2 6 2
3 4 1
3 4 2
Output
2
6
-1
4
Submitted Solution:
```
n,m=map(int,input().split())
a=list(map(int,input().split()))
b=[]
for i in range(n):
if i==0 or a[i]!=a[i-1]:
b.append(i)
else:
b.append(b[i-1])
ans=[]
for i in range(m):
l,r,x=map(int,input().split())
ans.append(r if a[r-1]!=x else (b[r-1] if b[r-1]>=l else -1))
print('\n'.join(map(str,ans)))
``` | instruction | 0 | 84,638 | 5 | 169,276 |
Yes | output | 1 | 84,638 | 5 | 169,277 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given array a with n integers and m queries. The i-th query is given with three integers li, ri, xi.
For the i-th query find any position pi (li ≤ pi ≤ ri) so that api ≠ xi.
Input
The first line contains two integers n, m (1 ≤ n, m ≤ 2·105) — the number of elements in a and the number of queries.
The second line contains n integers ai (1 ≤ ai ≤ 106) — the elements of the array a.
Each of the next m lines contains three integers li, ri, xi (1 ≤ li ≤ ri ≤ n, 1 ≤ xi ≤ 106) — the parameters of the i-th query.
Output
Print m lines. On the i-th line print integer pi — the position of any number not equal to xi in segment [li, ri] or the value - 1 if there is no such number.
Examples
Input
6 4
1 2 1 1 3 5
1 4 1
2 6 2
3 4 1
3 4 2
Output
2
6
-1
4
Submitted Solution:
```
# -*- coding: utf-8 -*-
"""
Created on Tue May 17 15:26:55 2016
@author: Alex
"""
n,m = map(int,input().split())
l = list(map(int,input().split()))
leng = len(l)
prev = [-1 for i in range(n)]
for i in range(n-1):
if l[i] != l[i+1]:
prev[i+1] = i
else:
prev[i+1] = prev[i]
for i in range(m):
b = False
le,ri,xi = map(int,input().split())
if l[ri-1]!=xi:
print(ri)
elif prev[ri-1]<=le-1:
print(-1)
else:
print(prev[ri-1]+1)
``` | instruction | 0 | 84,639 | 5 | 169,278 |
No | output | 1 | 84,639 | 5 | 169,279 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given array a with n integers and m queries. The i-th query is given with three integers li, ri, xi.
For the i-th query find any position pi (li ≤ pi ≤ ri) so that api ≠ xi.
Input
The first line contains two integers n, m (1 ≤ n, m ≤ 2·105) — the number of elements in a and the number of queries.
The second line contains n integers ai (1 ≤ ai ≤ 106) — the elements of the array a.
Each of the next m lines contains three integers li, ri, xi (1 ≤ li ≤ ri ≤ n, 1 ≤ xi ≤ 106) — the parameters of the i-th query.
Output
Print m lines. On the i-th line print integer pi — the position of any number not equal to xi in segment [li, ri] or the value - 1 if there is no such number.
Examples
Input
6 4
1 2 1 1 3 5
1 4 1
2 6 2
3 4 1
3 4 2
Output
2
6
-1
4
Submitted Solution:
```
n,m = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [-1]
ans = []
for i in range(1,len(a)):
if a[i] == a[i - 1]:
b.append(b[i - 1])
else:
b.append(i - 1)
for i in range(m):
l,r,x = [int(j) for j in input().split()]
k = r - 1
while b[k] != -1 and k >= l - 1:
if a[k] != x:
ans.append(k + 1)
break
k = b[k]
if len(ans) < i + 1:
ans.append(-1)
print(*ans, sep = '\n')
``` | instruction | 0 | 84,640 | 5 | 169,280 |
No | output | 1 | 84,640 | 5 | 169,281 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given array a with n integers and m queries. The i-th query is given with three integers li, ri, xi.
For the i-th query find any position pi (li ≤ pi ≤ ri) so that api ≠ xi.
Input
The first line contains two integers n, m (1 ≤ n, m ≤ 2·105) — the number of elements in a and the number of queries.
The second line contains n integers ai (1 ≤ ai ≤ 106) — the elements of the array a.
Each of the next m lines contains three integers li, ri, xi (1 ≤ li ≤ ri ≤ n, 1 ≤ xi ≤ 106) — the parameters of the i-th query.
Output
Print m lines. On the i-th line print integer pi — the position of any number not equal to xi in segment [li, ri] or the value - 1 if there is no such number.
Examples
Input
6 4
1 2 1 1 3 5
1 4 1
2 6 2
3 4 1
3 4 2
Output
2
6
-1
4
Submitted Solution:
```
from sys import stdin, stdout
from collections import defaultdict
cin = stdin.readline
cout = stdout.write
mp = lambda:list(map(int, cin().split()))
def binSearch(p, q, x):
low = p
high = q
while low<=high:
mid = (low+high)//2
dif = mid-low
if not dif:
if d[x][low+1]-d[x][low] > 1:
#print(2)
return d[x][low]+1
else:
#print(d[x][high])
return d[x][low]-1
elif d[x][mid] == d[x][low]+dif:
low = mid+1
else:
high = mid-1
n, m = mp()
a = mp()
d = defaultdict(list)
for i in range(n):
d[a[i]].append(i+1)
for _ in range(m):
l, r, x = mp()
if l in d[x]:
y = d[x].index(l)
else:
cout(str(l)+'\n')
continue
ind = y + r-l
if len(d[x])>ind and d[x][ind] == r:
cout('-1\n')
else:
if len(d[x])==1:
cout(str(r)+'\n')
else:
pos = binSearch(y, min(ind, len(d[x])-1), x)
cout(str(pos) + '\n')
``` | instruction | 0 | 84,641 | 5 | 169,282 |
No | output | 1 | 84,641 | 5 | 169,283 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given array a with n integers and m queries. The i-th query is given with three integers li, ri, xi.
For the i-th query find any position pi (li ≤ pi ≤ ri) so that api ≠ xi.
Input
The first line contains two integers n, m (1 ≤ n, m ≤ 2·105) — the number of elements in a and the number of queries.
The second line contains n integers ai (1 ≤ ai ≤ 106) — the elements of the array a.
Each of the next m lines contains three integers li, ri, xi (1 ≤ li ≤ ri ≤ n, 1 ≤ xi ≤ 106) — the parameters of the i-th query.
Output
Print m lines. On the i-th line print integer pi — the position of any number not equal to xi in segment [li, ri] or the value - 1 if there is no such number.
Examples
Input
6 4
1 2 1 1 3 5
1 4 1
2 6 2
3 4 1
3 4 2
Output
2
6
-1
4
Submitted Solution:
```
import sys
from random import randint
def work(ind,n):
for i in range(1,n):
if a[i] == a[i-1]:
ind[i] = ind[i-1]
else:
ind[i] = i-1
return ind
def work1(ind,answer):
q = sys.stdin.readline().split(' ')#input().split(' ')
#p = [randint(0,n),randint(0,n)]
#q = [min(p),max(p),randint(0,int(1e6))]
l = int(q[0])-1
r = int(q[1])-1
x = int(q[2])
if x == a[r]:
if ind[r]>=l:
#print(ind[r]+1)
#answer+= str(ind[r]+1)+' '
print(str(ind[r]+1)+' ')
else:
print(-1)
#answer+= '-1 '
else:
#print(int(r)+1)
#answer+= str(ind[r]+1)+' '
print(str(ind[r]+1)+' ')
return answer
n = sys.stdin.readline().split(' ')#input().split(' ')
m = int(n[1])
n = int(n[0])
a = [int(k) for k in sys.stdin.readline().split(' ')]
#n = int(2e5)
#m = int(2e5)
#a = [randint(0,int(1e6+1)) for i in range(n)]
ind = work(ind =[-1]*n,n = n)
answer=''
for i in range(m):
answer = work1(ind,answer)
print(answer)
#10 1
#1 2 2 2 2 1 1 2 1 1
#4 9 1
``` | instruction | 0 | 84,642 | 5 | 169,284 |
No | output | 1 | 84,642 | 5 | 169,285 |
Provide a correct Python 3 solution for this coding contest problem.
There is a sequence X of length N, where every element is initially 0. Let X_i denote the i-th element of X.
You are given a sequence A of length N. The i-th element of A is A_i. Determine if we can make X equal to A by repeating the operation below. If we can, find the minimum number of operations required.
* Choose an integer i such that 1\leq i\leq N-1. Replace the value of X_{i+1} with the value of X_i plus 1.
Constraints
* 1 \leq N \leq 2 \times 10^5
* 0 \leq A_i \leq 10^9(1\leq i\leq N)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1
:
A_N
Output
If we can make X equal to A by repeating the operation, print the minimum number of operations required. If we cannot, print -1.
Examples
Input
4
0
1
1
2
Output
3
Input
3
1
2
1
Output
-1
Input
9
0
1
1
0
1
2
2
1
2
Output
8 | instruction | 0 | 84,862 | 5 | 169,724 |
"Correct Solution:
```
N = int(input())
A = [int(input()) for _ in range(N)]
if A[0]:
print(-1)
exit()
ans = 0
dp = A[-1]
for a, b in zip(A[-2::-1], A[-1::-1]):
if a == b - 1:
continue
elif a >= b:
ans += dp
dp = a
else:
print(-1)
exit()
print(ans + dp)
``` | output | 1 | 84,862 | 5 | 169,725 |
Provide a correct Python 3 solution for this coding contest problem.
There is a sequence X of length N, where every element is initially 0. Let X_i denote the i-th element of X.
You are given a sequence A of length N. The i-th element of A is A_i. Determine if we can make X equal to A by repeating the operation below. If we can, find the minimum number of operations required.
* Choose an integer i such that 1\leq i\leq N-1. Replace the value of X_{i+1} with the value of X_i plus 1.
Constraints
* 1 \leq N \leq 2 \times 10^5
* 0 \leq A_i \leq 10^9(1\leq i\leq N)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1
:
A_N
Output
If we can make X equal to A by repeating the operation, print the minimum number of operations required. If we cannot, print -1.
Examples
Input
4
0
1
1
2
Output
3
Input
3
1
2
1
Output
-1
Input
9
0
1
1
0
1
2
2
1
2
Output
8 | instruction | 0 | 84,863 | 5 | 169,726 |
"Correct Solution:
```
n = int(input())
a = [int(input()) for i in range(n)]
def check():
globals()
s = 0
if a[0]!=0:
return -1
for i in range(n-1):
if a[i+1]<=a[i]:
s+=a[i]
if a[i+1]>a[i]+1:
return -1
return s+a[-1]
print(check())
``` | output | 1 | 84,863 | 5 | 169,727 |
Provide a correct Python 3 solution for this coding contest problem.
There is a sequence X of length N, where every element is initially 0. Let X_i denote the i-th element of X.
You are given a sequence A of length N. The i-th element of A is A_i. Determine if we can make X equal to A by repeating the operation below. If we can, find the minimum number of operations required.
* Choose an integer i such that 1\leq i\leq N-1. Replace the value of X_{i+1} with the value of X_i plus 1.
Constraints
* 1 \leq N \leq 2 \times 10^5
* 0 \leq A_i \leq 10^9(1\leq i\leq N)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1
:
A_N
Output
If we can make X equal to A by repeating the operation, print the minimum number of operations required. If we cannot, print -1.
Examples
Input
4
0
1
1
2
Output
3
Input
3
1
2
1
Output
-1
Input
9
0
1
1
0
1
2
2
1
2
Output
8 | instruction | 0 | 84,864 | 5 | 169,728 |
"Correct Solution:
```
N = int(input())
ans = 0
L = []
isok = True
for i in range(N):
n = int(input())
if n>i: isok = False
L.append(n)
for i in range(N-1):
if L[i+1] <= L[i]:
ans += L[i+1]
elif L[i+1] == L[i]+1:
ans += 1
elif L[i+1] > L[i]:
isok=False
break
if isok:
print(ans)
else:
print(-1)
``` | output | 1 | 84,864 | 5 | 169,729 |
Provide a correct Python 3 solution for this coding contest problem.
There is a sequence X of length N, where every element is initially 0. Let X_i denote the i-th element of X.
You are given a sequence A of length N. The i-th element of A is A_i. Determine if we can make X equal to A by repeating the operation below. If we can, find the minimum number of operations required.
* Choose an integer i such that 1\leq i\leq N-1. Replace the value of X_{i+1} with the value of X_i plus 1.
Constraints
* 1 \leq N \leq 2 \times 10^5
* 0 \leq A_i \leq 10^9(1\leq i\leq N)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1
:
A_N
Output
If we can make X equal to A by repeating the operation, print the minimum number of operations required. If we cannot, print -1.
Examples
Input
4
0
1
1
2
Output
3
Input
3
1
2
1
Output
-1
Input
9
0
1
1
0
1
2
2
1
2
Output
8 | instruction | 0 | 84,865 | 5 | 169,730 |
"Correct Solution:
```
n=int(input())
a=[int(input())for i in range(n)]
x,y=-1,-1
for i in a:
if i-x>1:print(-1);exit()
elif i==x+1:y+=1
else:y+=i
x=i
print(y)
``` | output | 1 | 84,865 | 5 | 169,731 |
Provide a correct Python 3 solution for this coding contest problem.
There is a sequence X of length N, where every element is initially 0. Let X_i denote the i-th element of X.
You are given a sequence A of length N. The i-th element of A is A_i. Determine if we can make X equal to A by repeating the operation below. If we can, find the minimum number of operations required.
* Choose an integer i such that 1\leq i\leq N-1. Replace the value of X_{i+1} with the value of X_i plus 1.
Constraints
* 1 \leq N \leq 2 \times 10^5
* 0 \leq A_i \leq 10^9(1\leq i\leq N)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1
:
A_N
Output
If we can make X equal to A by repeating the operation, print the minimum number of operations required. If we cannot, print -1.
Examples
Input
4
0
1
1
2
Output
3
Input
3
1
2
1
Output
-1
Input
9
0
1
1
0
1
2
2
1
2
Output
8 | instruction | 0 | 84,866 | 5 | 169,732 |
"Correct Solution:
```
import sys
input = sys.stdin.readline
cur = -1
c = 0
for i in range(int(input())):
pre,cur = cur,int(input())
if cur == 0:
continue
elif cur == pre + 1:
c += 1
elif cur <= pre:
c += cur
else:
print(-1)
exit()
print(c)
``` | output | 1 | 84,866 | 5 | 169,733 |
Provide a correct Python 3 solution for this coding contest problem.
There is a sequence X of length N, where every element is initially 0. Let X_i denote the i-th element of X.
You are given a sequence A of length N. The i-th element of A is A_i. Determine if we can make X equal to A by repeating the operation below. If we can, find the minimum number of operations required.
* Choose an integer i such that 1\leq i\leq N-1. Replace the value of X_{i+1} with the value of X_i plus 1.
Constraints
* 1 \leq N \leq 2 \times 10^5
* 0 \leq A_i \leq 10^9(1\leq i\leq N)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1
:
A_N
Output
If we can make X equal to A by repeating the operation, print the minimum number of operations required. If we cannot, print -1.
Examples
Input
4
0
1
1
2
Output
3
Input
3
1
2
1
Output
-1
Input
9
0
1
1
0
1
2
2
1
2
Output
8 | instruction | 0 | 84,867 | 5 | 169,734 |
"Correct Solution:
```
n = int(input())
A = [int(input())for _ in range(n)]
if A[0] != 0:
print(-1)
exit()
ans = A[-1]
for a, prev_a in reversed(tuple(zip(A, A[1:]))):
if a == prev_a-1:
continue
if a < prev_a-1:
print(-1)
break
ans += a
else:
print(ans)
``` | output | 1 | 84,867 | 5 | 169,735 |
Provide a correct Python 3 solution for this coding contest problem.
There is a sequence X of length N, where every element is initially 0. Let X_i denote the i-th element of X.
You are given a sequence A of length N. The i-th element of A is A_i. Determine if we can make X equal to A by repeating the operation below. If we can, find the minimum number of operations required.
* Choose an integer i such that 1\leq i\leq N-1. Replace the value of X_{i+1} with the value of X_i plus 1.
Constraints
* 1 \leq N \leq 2 \times 10^5
* 0 \leq A_i \leq 10^9(1\leq i\leq N)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1
:
A_N
Output
If we can make X equal to A by repeating the operation, print the minimum number of operations required. If we cannot, print -1.
Examples
Input
4
0
1
1
2
Output
3
Input
3
1
2
1
Output
-1
Input
9
0
1
1
0
1
2
2
1
2
Output
8 | instruction | 0 | 84,868 | 5 | 169,736 |
"Correct Solution:
```
N = int(input())
A = [int(input()) for _ in range(N)]
ok = True
pre = -1
for i, a in enumerate(A):
if a > pre + 1:
ok = False
break
pre = a
if not ok:
print(-1)
else:
c = 0
for i in range(N-1):
if A[i+1] != A[i] + 1:
c += A[i+1]
else:
c += 1
print(c)
``` | output | 1 | 84,868 | 5 | 169,737 |
Provide a correct Python 3 solution for this coding contest problem.
There is a sequence X of length N, where every element is initially 0. Let X_i denote the i-th element of X.
You are given a sequence A of length N. The i-th element of A is A_i. Determine if we can make X equal to A by repeating the operation below. If we can, find the minimum number of operations required.
* Choose an integer i such that 1\leq i\leq N-1. Replace the value of X_{i+1} with the value of X_i plus 1.
Constraints
* 1 \leq N \leq 2 \times 10^5
* 0 \leq A_i \leq 10^9(1\leq i\leq N)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1
:
A_N
Output
If we can make X equal to A by repeating the operation, print the minimum number of operations required. If we cannot, print -1.
Examples
Input
4
0
1
1
2
Output
3
Input
3
1
2
1
Output
-1
Input
9
0
1
1
0
1
2
2
1
2
Output
8 | instruction | 0 | 84,869 | 5 | 169,738 |
"Correct Solution:
```
n = int(input())
a = [int(input()) for _i in range(n)] + [-1]
result = -1
for i in range(n):
if a[i-1] == a[i]:
result += a[i]
elif a[i-1] + 1 == a[i]:
result += 1
elif a[i-1] > a[i]:
result += a[i]
else:
result = -1
break
print(result)
``` | output | 1 | 84,869 | 5 | 169,739 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a sequence X of length N, where every element is initially 0. Let X_i denote the i-th element of X.
You are given a sequence A of length N. The i-th element of A is A_i. Determine if we can make X equal to A by repeating the operation below. If we can, find the minimum number of operations required.
* Choose an integer i such that 1\leq i\leq N-1. Replace the value of X_{i+1} with the value of X_i plus 1.
Constraints
* 1 \leq N \leq 2 \times 10^5
* 0 \leq A_i \leq 10^9(1\leq i\leq N)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1
:
A_N
Output
If we can make X equal to A by repeating the operation, print the minimum number of operations required. If we cannot, print -1.
Examples
Input
4
0
1
1
2
Output
3
Input
3
1
2
1
Output
-1
Input
9
0
1
1
0
1
2
2
1
2
Output
8
Submitted Solution:
```
import sys
#sys.stdin=open("data.txt")
input=sys.stdin.readline
n=int(input())
a=[int(input()) for _ in range(n)]
bad=(a[0]!=0)
for i in range(n-1):
if a[i]+1<a[i+1]:
bad=True
if bad: print(-1)
else:
# calculate answer
ans=[0]*n
for i in range(n):
ans[i-a[i]]=a[i]
print(sum(ans))
``` | instruction | 0 | 84,870 | 5 | 169,740 |
Yes | output | 1 | 84,870 | 5 | 169,741 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a sequence X of length N, where every element is initially 0. Let X_i denote the i-th element of X.
You are given a sequence A of length N. The i-th element of A is A_i. Determine if we can make X equal to A by repeating the operation below. If we can, find the minimum number of operations required.
* Choose an integer i such that 1\leq i\leq N-1. Replace the value of X_{i+1} with the value of X_i plus 1.
Constraints
* 1 \leq N \leq 2 \times 10^5
* 0 \leq A_i \leq 10^9(1\leq i\leq N)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1
:
A_N
Output
If we can make X equal to A by repeating the operation, print the minimum number of operations required. If we cannot, print -1.
Examples
Input
4
0
1
1
2
Output
3
Input
3
1
2
1
Output
-1
Input
9
0
1
1
0
1
2
2
1
2
Output
8
Submitted Solution:
```
N = int(input())
ans = 0
arr = [-1]
for i in range(N):
A = int(input())
if A > arr[i] + 1:
print(-1)
break
if A == arr[i] + 1 and i != 0:
ans += 1
else:
ans += A
arr.append(A)
else:
print(ans)
``` | instruction | 0 | 84,871 | 5 | 169,742 |
Yes | output | 1 | 84,871 | 5 | 169,743 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a sequence X of length N, where every element is initially 0. Let X_i denote the i-th element of X.
You are given a sequence A of length N. The i-th element of A is A_i. Determine if we can make X equal to A by repeating the operation below. If we can, find the minimum number of operations required.
* Choose an integer i such that 1\leq i\leq N-1. Replace the value of X_{i+1} with the value of X_i plus 1.
Constraints
* 1 \leq N \leq 2 \times 10^5
* 0 \leq A_i \leq 10^9(1\leq i\leq N)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1
:
A_N
Output
If we can make X equal to A by repeating the operation, print the minimum number of operations required. If we cannot, print -1.
Examples
Input
4
0
1
1
2
Output
3
Input
3
1
2
1
Output
-1
Input
9
0
1
1
0
1
2
2
1
2
Output
8
Submitted Solution:
```
N = int(input())
A = [int(input()) for _ in range(N)]
if A[0] > 0:
print(-1)
else:
ans = 0
for n in range(N-1, -1, -1):
if A[n] - A[n-1] > 1 or A[n] > n:
print(-1)
break
else:
if A[n] - A[n-1] == 1:
ans += 1
else:
ans += A[n]
else:
print(ans)
``` | instruction | 0 | 84,872 | 5 | 169,744 |
Yes | output | 1 | 84,872 | 5 | 169,745 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a sequence X of length N, where every element is initially 0. Let X_i denote the i-th element of X.
You are given a sequence A of length N. The i-th element of A is A_i. Determine if we can make X equal to A by repeating the operation below. If we can, find the minimum number of operations required.
* Choose an integer i such that 1\leq i\leq N-1. Replace the value of X_{i+1} with the value of X_i plus 1.
Constraints
* 1 \leq N \leq 2 \times 10^5
* 0 \leq A_i \leq 10^9(1\leq i\leq N)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1
:
A_N
Output
If we can make X equal to A by repeating the operation, print the minimum number of operations required. If we cannot, print -1.
Examples
Input
4
0
1
1
2
Output
3
Input
3
1
2
1
Output
-1
Input
9
0
1
1
0
1
2
2
1
2
Output
8
Submitted Solution:
```
n = int(input())
ans = -1
prev = -1
for _ in range(n):
a = int(input())
if prev+1 == a:
prev = a
ans += 1
continue
if prev+1 < a:
print(-1)
break
ans += a
prev = a
else:
print(ans)
``` | instruction | 0 | 84,873 | 5 | 169,746 |
Yes | output | 1 | 84,873 | 5 | 169,747 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a sequence X of length N, where every element is initially 0. Let X_i denote the i-th element of X.
You are given a sequence A of length N. The i-th element of A is A_i. Determine if we can make X equal to A by repeating the operation below. If we can, find the minimum number of operations required.
* Choose an integer i such that 1\leq i\leq N-1. Replace the value of X_{i+1} with the value of X_i plus 1.
Constraints
* 1 \leq N \leq 2 \times 10^5
* 0 \leq A_i \leq 10^9(1\leq i\leq N)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1
:
A_N
Output
If we can make X equal to A by repeating the operation, print the minimum number of operations required. If we cannot, print -1.
Examples
Input
4
0
1
1
2
Output
3
Input
3
1
2
1
Output
-1
Input
9
0
1
1
0
1
2
2
1
2
Output
8
Submitted Solution:
```
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()
def resolve():
N = I()
A = [I() for _ in range(N)]
is_ok = True
# A[0]!=0か、A[i]+1 < A[i+1]があるとダメ
if A[0] != 0:
is_ok = False
else:
for i in range(N - 1):
if A[i] + 1 < A[i+1]:
is_ok = False
break
ans = len([i for i in A if i > 0])
if is_ok:
# A[i] >= A[i+1] >= 2のとき、余計に1手
for i in range(N - 1):
if A[i] >= A[i+1] >= 2:
ans += 1
if is_ok:
print(ans)
else:
print(-1)
if __name__ == '__main__':
resolve()
``` | instruction | 0 | 84,874 | 5 | 169,748 |
No | output | 1 | 84,874 | 5 | 169,749 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a sequence X of length N, where every element is initially 0. Let X_i denote the i-th element of X.
You are given a sequence A of length N. The i-th element of A is A_i. Determine if we can make X equal to A by repeating the operation below. If we can, find the minimum number of operations required.
* Choose an integer i such that 1\leq i\leq N-1. Replace the value of X_{i+1} with the value of X_i plus 1.
Constraints
* 1 \leq N \leq 2 \times 10^5
* 0 \leq A_i \leq 10^9(1\leq i\leq N)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1
:
A_N
Output
If we can make X equal to A by repeating the operation, print the minimum number of operations required. If we cannot, print -1.
Examples
Input
4
0
1
1
2
Output
3
Input
3
1
2
1
Output
-1
Input
9
0
1
1
0
1
2
2
1
2
Output
8
Submitted Solution:
```
n = int(input())
a = [int(input()) for _ in range(n)]
for i in range(1,n):
if a[i]-a[i-1] > 1:
print(-1)
exit(0)
cnt = 0
cur = 0
for i in range(n-1,-1,-1):
if cur < a[i]:
cur = a[i]
cnt += a[i]
if cur:
cur -= 1
print(cnt)
``` | instruction | 0 | 84,875 | 5 | 169,750 |
No | output | 1 | 84,875 | 5 | 169,751 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a sequence X of length N, where every element is initially 0. Let X_i denote the i-th element of X.
You are given a sequence A of length N. The i-th element of A is A_i. Determine if we can make X equal to A by repeating the operation below. If we can, find the minimum number of operations required.
* Choose an integer i such that 1\leq i\leq N-1. Replace the value of X_{i+1} with the value of X_i plus 1.
Constraints
* 1 \leq N \leq 2 \times 10^5
* 0 \leq A_i \leq 10^9(1\leq i\leq N)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1
:
A_N
Output
If we can make X equal to A by repeating the operation, print the minimum number of operations required. If we cannot, print -1.
Examples
Input
4
0
1
1
2
Output
3
Input
3
1
2
1
Output
-1
Input
9
0
1
1
0
1
2
2
1
2
Output
8
Submitted Solution:
```
def main():
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#main code here!
n=I()
lis=LI2()
ind=[i for i in range(n)]
if lis[0]!=0:
print(-1)
sys.exit()
for i in range(1,n):
if lis[i]==0:
ind[i]=0
else:
ind[i]=ind[i-1]+1
for i in range(n):
if lis[i]>ind[i]:
print(-1)
sys.exit()
ans=0
mem=0
'''for i in range(n):
j=n-i-1
u=lis[j]
if lis[j-1]!=lis[j]-1:
ans+=u
ans+=mem
mem=0
else:
mem=lis[j]'''
for i in range(n-1):
x=lis[i]
if lis[i+1]==lis[i]+1:
continue
else:
ans+=x
if n!=1 and lis[-1]==lis[-2]+1:
ans+=lis[-1]
print(ans)
if __name__=="__main__":
main()
``` | instruction | 0 | 84,876 | 5 | 169,752 |
No | output | 1 | 84,876 | 5 | 169,753 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a sequence X of length N, where every element is initially 0. Let X_i denote the i-th element of X.
You are given a sequence A of length N. The i-th element of A is A_i. Determine if we can make X equal to A by repeating the operation below. If we can, find the minimum number of operations required.
* Choose an integer i such that 1\leq i\leq N-1. Replace the value of X_{i+1} with the value of X_i plus 1.
Constraints
* 1 \leq N \leq 2 \times 10^5
* 0 \leq A_i \leq 10^9(1\leq i\leq N)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1
:
A_N
Output
If we can make X equal to A by repeating the operation, print the minimum number of operations required. If we cannot, print -1.
Examples
Input
4
0
1
1
2
Output
3
Input
3
1
2
1
Output
-1
Input
9
0
1
1
0
1
2
2
1
2
Output
8
Submitted Solution:
```
n = int(input())
a = [int(input()) for i in range(n)]
ans,flag = 0,True
for i in range(n-1):
if a[i]+1==a[i+1]: ans+=1
elif a[i]>=a[i+1]: ans+=a[i+1]
else:
flag = False
break
if flag: print(ans)
else: print(-1)
``` | instruction | 0 | 84,877 | 5 | 169,754 |
No | output | 1 | 84,877 | 5 | 169,755 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a set consisting of N distinct integers. The i-th smallest element in this set is S_i. We want to divide this set into two sets, X and Y, such that:
* The absolute difference of any two distinct elements in X is A or greater.
* The absolute difference of any two distinct elements in Y is B or greater.
How many ways are there to perform such division, modulo 10^9 + 7? Note that one of X and Y may be empty.
Constraints
* All input values are integers.
* 1 ≦ N ≦ 10^5
* 1 ≦ A , B ≦ 10^{18}
* 0 ≦ S_i ≦ 10^{18}(1 ≦ i ≦ N)
* S_i < S_{i+1}(1 ≦ i ≦ N - 1)
Input
The input is given from Standard Input in the following format:
N A B
S_1
:
S_N
Output
Print the number of the different divisions under the conditions, modulo 10^9 + 7.
Examples
Input
5 3 7
1
3
6
9
12
Output
5
Input
7 5 3
0
2
4
7
8
11
15
Output
4
Input
8 2 9
3
4
5
13
15
22
26
32
Output
13
Input
3 3 4
5
6
7
Output
0
Submitted Solution:
```
import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
MOD = 10**9 + 7
def main(N, A, B, S):
if A > B:
A, B = B, A
if np.max(S[2:] - S[:-2]) < A:
return 0
INF = 1 << 62
S = np.append(S, INF)
# A 未満でたどって、Xがどこまで置けるか
X = np.zeros_like(S)
for i in range(1, N + 1):
if S[i] - S[i - 1] >= A:
X[i] = X[i - 1]
else:
X[i] = i
# 直前の Y としてありうる最も右
Y = np.searchsorted(S, S - B, side='right') - 1
dp = np.zeros_like(S)
dp_cum = np.zeros_like(S)
dp[0] = 1
dp_cum[0] = 1
for n in range(1, N + 1):
if X[n - 1] == 0:
# 初出の Y
dp[n] = 1
# 直前の Y の範囲
l, r = max(0, X[n - 1] - 1), min(n - 1, Y[n])
if l <= r:
dp[n] += dp_cum[r] - dp_cum[l] + dp[l]
dp[n] %= MOD
dp_cum[n] = (dp_cum[n - 1] + dp[n]) % MOD
return dp[-1]
signature = '(i8,i8,i8,i8[:],)'
if sys.argv[-1] == 'ONLINE_JUDGE':
from numba.pycc import CC
cc = CC('my_module')
cc.export('main', signature)(main)
cc.compile()
from my_module import main
N, A, B = map(int, readline().split())
S = np.array(read().split(), np.int64)
print(main(N, A, B, S))
``` | instruction | 0 | 84,916 | 5 | 169,832 |
No | output | 1 | 84,916 | 5 | 169,833 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a set consisting of N distinct integers. The i-th smallest element in this set is S_i. We want to divide this set into two sets, X and Y, such that:
* The absolute difference of any two distinct elements in X is A or greater.
* The absolute difference of any two distinct elements in Y is B or greater.
How many ways are there to perform such division, modulo 10^9 + 7? Note that one of X and Y may be empty.
Constraints
* All input values are integers.
* 1 ≦ N ≦ 10^5
* 1 ≦ A , B ≦ 10^{18}
* 0 ≦ S_i ≦ 10^{18}(1 ≦ i ≦ N)
* S_i < S_{i+1}(1 ≦ i ≦ N - 1)
Input
The input is given from Standard Input in the following format:
N A B
S_1
:
S_N
Output
Print the number of the different divisions under the conditions, modulo 10^9 + 7.
Examples
Input
5 3 7
1
3
6
9
12
Output
5
Input
7 5 3
0
2
4
7
8
11
15
Output
4
Input
8 2 9
3
4
5
13
15
22
26
32
Output
13
Input
3 3 4
5
6
7
Output
0
Submitted Solution:
```
import sys
input = sys.stdin.readline
from bisect import bisect_left, bisect_right
INF = 10**18 + 100
N,A,B = map(int,input().split())
S = [-INF] + [int(x) for x in sys.stdin.read().split()]
MOD = 10**9 + 7
dpX = [0] * (N+1) # 最後にYを選んだとして、直前に選んだXがどこにあるか
dpY = [0] * (N+1) # 最後にXを選んだとして、直前に選んだYがどこにあるか
dpX[0] = 1
dpY[0] = 1
dpX_cum = [1] * (N+1) + [0]
dpY_cum = [1] * (N+1) + [0]
dpX_left = 0
dpY_left = 0
for n,x in enumerate(S[2:],2):
iA = bisect_right(S,x-A)
iB = bisect_right(S,x-B)
# ....XY
xy = dpY_cum[iB-1] - dpY_cum[dpY_left-1]
# ....YX
yx = dpX_cum[iA-1] - dpX_cum[dpX_left-1]
# ....XX が不可能なら捨てる。明示的に捨てるのではなく、生きている番号だけ持つ
if iA != n:
dpY_left = n-1
if iB != n:
dpX_left = n-1
dpX[n-1] = xy
dpX_cum[n-1] = (dpX_cum[n-2] + xy) % MOD
dpX_cum[n] = dpX_cum[n-1]
dpY[n-1] = yx
dpY_cum[n-1] = (dpY_cum[n-2] + yx) % MOD
dpY_cum[n] = dpY_cum[n-1]
answer = dpX_cum[N-1] - dpX_cum[dpX_left-1]
answer += dpY_cum[N-1] - dpY_cum[dpY_left-1]
answer %= MOD
print(answer)
``` | instruction | 0 | 84,917 | 5 | 169,834 |
No | output | 1 | 84,917 | 5 | 169,835 |
Provide a correct Python 3 solution for this coding contest problem.
Example
Input
4
Durett 7
Gayles 3
Facenda 6
Daughtery 0
1
+ Mccourtney 2
Output
Mccourtney is not working now.
Durett is working hard now. | instruction | 0 | 84,974 | 5 | 169,948 |
"Correct Solution:
```
from heapq import heappush, heappop, heapify
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
N = int(readline())
P = []; Q = []
E = []; R = {}
L = N + 20000
for i in range(N):
s, a = readline().split(); a = int(a) * L + i
E.append(s)
Q.append((-a, i))
R[s] = (i, a)
heapify(Q)
for i in range(N // 5):
b, i = heappop(Q)
P.append((-b, i))
heapify(P)
pn = len(P); qn = len(Q)
ln = N
cur = N
M = int(readline())
for i in range(M):
p, *g = readline().split()
db = dk = -1
if p == "+":
t, b = g; b = int(b) * L + cur
E.append(t)
R[t] = (cur, b)
ln += 1
if ln >= 5 and -Q[0][0] < b:
da = 1
pn += 1
heappush(P, (b, cur))
if pn > ln // 5:
while 1:
c, k = heappop(P)
if E[k] is not None:
if c == b:
da = 0
else:
db = 0
dk = k
heappush(Q, (-c, k))
break
pn -= 1; qn += 1
else:
da = 0
qn += 1
heappush(Q, (-b, cur))
if pn < ln // 5:
while 1:
c, k = heappop(Q)
if E[k] is not None:
if -b == c:
da = 1
else:
db = 1
dk = k
heappush(P, (-c, k))
break
pn += 1; qn -= 1
if da:
write("%s is working hard now.\n" % t)
else:
write("%s is not working now.\n" % t)
cur += 1
else:
t, = g
j, b = R[t]
E[j] = None
ln -= 1
if P and P[0][0] <= b:
pn -= 1
if pn < ln // 5:
while 1:
c, k = heappop(Q)
if E[k] is not None:
heappush(P, (-c, k))
db = 1; dk = k
break
pn += 1; qn -= 1
else:
qn -= 1
if pn > ln // 5:
while 1:
c, k = heappop(P)
if E[k] is not None:
heappush(Q, (-c, k))
db = 0; dk = k
break
qn += 1; pn -= 1
if db != -1:
if db:
write("%s is working hard now.\n" % E[dk])
else:
write("%s is not working now.\n" % E[dk])
solve()
``` | output | 1 | 84,974 | 5 | 169,949 |
Provide a correct Python 3 solution for this coding contest problem.
E-training
Nene is writing a program to look up $ N $ integers $ V_1, V_2, V_3, \ cdots, V_N $ for programming training.
As told by his instructor, Umiko, Nene wrote a program to look up multiples of 2, 3, and 6.
Multiples of 2 were $ A $, multiples of 3 were $ B $, and multiples of 6 were $ C $.
Umiko told me to look up the number of "numbers that are neither multiples of 2 nor multiples of 3".
However, Nene was tired, so she decided to cheat only for the answer.
Based only on the values of $ N, A, B, and C $, you can find the number of "numbers that are neither multiples of 2 nor multiples of 3". Create a program that asks for this.
input
$ N, A, B, C $ are given separated by blanks.
output
Output the number of "numbers that are neither multiples of 2 nor multiples of 3" in the data. However, insert a line break at the end.
Constraint
* $ N $ is an integer greater than or equal to $ 1 $ and less than or equal to $ 100 $
* $ A, B, C $ are integers greater than or equal to $ 0 $ and less than or equal to $ N $
* No inconsistent data is given, such as $ A $ being greater than $ N $
Input example 1
6 3 2 1
Output example 1
2
For example, if your data is $ 2, 3, 4, 5, 6, 7 $, then $ 5 $ and $ 7 $ are "numbers that are neither multiples of 2 nor multiples of 3".
Input example 2
10 9 9 9
Output example 2
1
Example
Input
6 3 2 1
Output
2 | instruction | 0 | 84,975 | 5 | 169,950 |
"Correct Solution:
```
N, A, B, C = [int(x) for x in input().split()]
ans = N - (A + B) + C
print(ans)
``` | output | 1 | 84,975 | 5 | 169,951 |
Provide a correct Python 3 solution for this coding contest problem.
E-training
Nene is writing a program to look up $ N $ integers $ V_1, V_2, V_3, \ cdots, V_N $ for programming training.
As told by his instructor, Umiko, Nene wrote a program to look up multiples of 2, 3, and 6.
Multiples of 2 were $ A $, multiples of 3 were $ B $, and multiples of 6 were $ C $.
Umiko told me to look up the number of "numbers that are neither multiples of 2 nor multiples of 3".
However, Nene was tired, so she decided to cheat only for the answer.
Based only on the values of $ N, A, B, and C $, you can find the number of "numbers that are neither multiples of 2 nor multiples of 3". Create a program that asks for this.
input
$ N, A, B, C $ are given separated by blanks.
output
Output the number of "numbers that are neither multiples of 2 nor multiples of 3" in the data. However, insert a line break at the end.
Constraint
* $ N $ is an integer greater than or equal to $ 1 $ and less than or equal to $ 100 $
* $ A, B, C $ are integers greater than or equal to $ 0 $ and less than or equal to $ N $
* No inconsistent data is given, such as $ A $ being greater than $ N $
Input example 1
6 3 2 1
Output example 1
2
For example, if your data is $ 2, 3, 4, 5, 6, 7 $, then $ 5 $ and $ 7 $ are "numbers that are neither multiples of 2 nor multiples of 3".
Input example 2
10 9 9 9
Output example 2
1
Example
Input
6 3 2 1
Output
2 | instruction | 0 | 84,976 | 5 | 169,952 |
"Correct Solution:
```
N,A,B,C=map(int,input().split())
print(N-A-B+C)
``` | output | 1 | 84,976 | 5 | 169,953 |
Provide a correct Python 3 solution for this coding contest problem.
E-training
Nene is writing a program to look up $ N $ integers $ V_1, V_2, V_3, \ cdots, V_N $ for programming training.
As told by his instructor, Umiko, Nene wrote a program to look up multiples of 2, 3, and 6.
Multiples of 2 were $ A $, multiples of 3 were $ B $, and multiples of 6 were $ C $.
Umiko told me to look up the number of "numbers that are neither multiples of 2 nor multiples of 3".
However, Nene was tired, so she decided to cheat only for the answer.
Based only on the values of $ N, A, B, and C $, you can find the number of "numbers that are neither multiples of 2 nor multiples of 3". Create a program that asks for this.
input
$ N, A, B, C $ are given separated by blanks.
output
Output the number of "numbers that are neither multiples of 2 nor multiples of 3" in the data. However, insert a line break at the end.
Constraint
* $ N $ is an integer greater than or equal to $ 1 $ and less than or equal to $ 100 $
* $ A, B, C $ are integers greater than or equal to $ 0 $ and less than or equal to $ N $
* No inconsistent data is given, such as $ A $ being greater than $ N $
Input example 1
6 3 2 1
Output example 1
2
For example, if your data is $ 2, 3, 4, 5, 6, 7 $, then $ 5 $ and $ 7 $ are "numbers that are neither multiples of 2 nor multiples of 3".
Input example 2
10 9 9 9
Output example 2
1
Example
Input
6 3 2 1
Output
2 | instruction | 0 | 84,977 | 5 | 169,954 |
"Correct Solution:
```
n,a,b,c = map(int,input().split())
print(n - (a+b-c))
``` | output | 1 | 84,977 | 5 | 169,955 |
Provide a correct Python 3 solution for this coding contest problem.
E-training
Nene is writing a program to look up $ N $ integers $ V_1, V_2, V_3, \ cdots, V_N $ for programming training.
As told by his instructor, Umiko, Nene wrote a program to look up multiples of 2, 3, and 6.
Multiples of 2 were $ A $, multiples of 3 were $ B $, and multiples of 6 were $ C $.
Umiko told me to look up the number of "numbers that are neither multiples of 2 nor multiples of 3".
However, Nene was tired, so she decided to cheat only for the answer.
Based only on the values of $ N, A, B, and C $, you can find the number of "numbers that are neither multiples of 2 nor multiples of 3". Create a program that asks for this.
input
$ N, A, B, C $ are given separated by blanks.
output
Output the number of "numbers that are neither multiples of 2 nor multiples of 3" in the data. However, insert a line break at the end.
Constraint
* $ N $ is an integer greater than or equal to $ 1 $ and less than or equal to $ 100 $
* $ A, B, C $ are integers greater than or equal to $ 0 $ and less than or equal to $ N $
* No inconsistent data is given, such as $ A $ being greater than $ N $
Input example 1
6 3 2 1
Output example 1
2
For example, if your data is $ 2, 3, 4, 5, 6, 7 $, then $ 5 $ and $ 7 $ are "numbers that are neither multiples of 2 nor multiples of 3".
Input example 2
10 9 9 9
Output example 2
1
Example
Input
6 3 2 1
Output
2 | instruction | 0 | 84,978 | 5 | 169,956 |
"Correct Solution:
```
n, a, b, c = map(int, input().split())
print(n-(c+a-c+b-c))
``` | output | 1 | 84,978 | 5 | 169,957 |
Provide a correct Python 3 solution for this coding contest problem.
E-training
Nene is writing a program to look up $ N $ integers $ V_1, V_2, V_3, \ cdots, V_N $ for programming training.
As told by his instructor, Umiko, Nene wrote a program to look up multiples of 2, 3, and 6.
Multiples of 2 were $ A $, multiples of 3 were $ B $, and multiples of 6 were $ C $.
Umiko told me to look up the number of "numbers that are neither multiples of 2 nor multiples of 3".
However, Nene was tired, so she decided to cheat only for the answer.
Based only on the values of $ N, A, B, and C $, you can find the number of "numbers that are neither multiples of 2 nor multiples of 3". Create a program that asks for this.
input
$ N, A, B, C $ are given separated by blanks.
output
Output the number of "numbers that are neither multiples of 2 nor multiples of 3" in the data. However, insert a line break at the end.
Constraint
* $ N $ is an integer greater than or equal to $ 1 $ and less than or equal to $ 100 $
* $ A, B, C $ are integers greater than or equal to $ 0 $ and less than or equal to $ N $
* No inconsistent data is given, such as $ A $ being greater than $ N $
Input example 1
6 3 2 1
Output example 1
2
For example, if your data is $ 2, 3, 4, 5, 6, 7 $, then $ 5 $ and $ 7 $ are "numbers that are neither multiples of 2 nor multiples of 3".
Input example 2
10 9 9 9
Output example 2
1
Example
Input
6 3 2 1
Output
2 | instruction | 0 | 84,979 | 5 | 169,958 |
"Correct Solution:
```
n,a,b,c=map(int,input().split())
print((n+c)-(a+b))
``` | output | 1 | 84,979 | 5 | 169,959 |
Provide a correct Python 3 solution for this coding contest problem.
E-training
Nene is writing a program to look up $ N $ integers $ V_1, V_2, V_3, \ cdots, V_N $ for programming training.
As told by his instructor, Umiko, Nene wrote a program to look up multiples of 2, 3, and 6.
Multiples of 2 were $ A $, multiples of 3 were $ B $, and multiples of 6 were $ C $.
Umiko told me to look up the number of "numbers that are neither multiples of 2 nor multiples of 3".
However, Nene was tired, so she decided to cheat only for the answer.
Based only on the values of $ N, A, B, and C $, you can find the number of "numbers that are neither multiples of 2 nor multiples of 3". Create a program that asks for this.
input
$ N, A, B, C $ are given separated by blanks.
output
Output the number of "numbers that are neither multiples of 2 nor multiples of 3" in the data. However, insert a line break at the end.
Constraint
* $ N $ is an integer greater than or equal to $ 1 $ and less than or equal to $ 100 $
* $ A, B, C $ are integers greater than or equal to $ 0 $ and less than or equal to $ N $
* No inconsistent data is given, such as $ A $ being greater than $ N $
Input example 1
6 3 2 1
Output example 1
2
For example, if your data is $ 2, 3, 4, 5, 6, 7 $, then $ 5 $ and $ 7 $ are "numbers that are neither multiples of 2 nor multiples of 3".
Input example 2
10 9 9 9
Output example 2
1
Example
Input
6 3 2 1
Output
2 | instruction | 0 | 84,980 | 5 | 169,960 |
"Correct Solution:
```
n, a, b, c = map(int, input().split())
print(n-a-b+c)
``` | output | 1 | 84,980 | 5 | 169,961 |
Provide a correct Python 3 solution for this coding contest problem.
E-training
Nene is writing a program to look up $ N $ integers $ V_1, V_2, V_3, \ cdots, V_N $ for programming training.
As told by his instructor, Umiko, Nene wrote a program to look up multiples of 2, 3, and 6.
Multiples of 2 were $ A $, multiples of 3 were $ B $, and multiples of 6 were $ C $.
Umiko told me to look up the number of "numbers that are neither multiples of 2 nor multiples of 3".
However, Nene was tired, so she decided to cheat only for the answer.
Based only on the values of $ N, A, B, and C $, you can find the number of "numbers that are neither multiples of 2 nor multiples of 3". Create a program that asks for this.
input
$ N, A, B, C $ are given separated by blanks.
output
Output the number of "numbers that are neither multiples of 2 nor multiples of 3" in the data. However, insert a line break at the end.
Constraint
* $ N $ is an integer greater than or equal to $ 1 $ and less than or equal to $ 100 $
* $ A, B, C $ are integers greater than or equal to $ 0 $ and less than or equal to $ N $
* No inconsistent data is given, such as $ A $ being greater than $ N $
Input example 1
6 3 2 1
Output example 1
2
For example, if your data is $ 2, 3, 4, 5, 6, 7 $, then $ 5 $ and $ 7 $ are "numbers that are neither multiples of 2 nor multiples of 3".
Input example 2
10 9 9 9
Output example 2
1
Example
Input
6 3 2 1
Output
2 | instruction | 0 | 84,981 | 5 | 169,962 |
"Correct Solution:
```
n,a,b,c=map(int,input().split());print(n-a-b+c)
``` | output | 1 | 84,981 | 5 | 169,963 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For given a sequence $A = \\{a_0, a_1, ..., a_{n-1}\\}$, print the previous permutation and the next permutation in lexicographic order.
Constraints
* $1 \leq n \leq 9$
* $a_i$ consist of $1, 2, ..., n$
Input
A sequence is given in the following format.
$n$
$a_0 \; a_1 \; ... \; a_{n-1}$
Output
Print the previous permutation, the given sequence and the next permutation in the 1st, 2nd and 3rd lines respectively. Separate adjacency elements by a space character. Note that if there is no permutation, print nothing in the corresponding line.
Examples
Input
3
2 1 3
Output
1 3 2
2 1 3
2 3 1
Input
3
3 2 1
Output
3 1 2
3 2 1
Submitted Solution:
```
import itertools
from typing import List, Tuple
def print_elems(elems):
print(" ".join([str(elem) for elem in elems]))
if __name__ == "__main__":
n = int(input())
nums = tuple(map(lambda x: int(x), input().split()))
nums_permutated = list(itertools.permutations(sorted(nums)))
if (1 == len(nums_permutated)):
print(nums[0])
exit(0)
for idx in range(1, len(nums_permutated)):
if (nums == nums_permutated[idx - 1]):
print_elems(nums_permutated[idx - 1])
print_elems(nums_permutated[idx])
exit(0)
if (nums == nums_permutated[idx]):
print_elems(nums_permutated[idx - 1])
print_elems(nums_permutated[idx])
if (idx != len(nums_permutated) - 1):
print_elems(nums_permutated[idx + 1])
exit(0)
``` | instruction | 0 | 85,004 | 5 | 170,008 |
Yes | output | 1 | 85,004 | 5 | 170,009 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For given a sequence $A = \\{a_0, a_1, ..., a_{n-1}\\}$, print the previous permutation and the next permutation in lexicographic order.
Constraints
* $1 \leq n \leq 9$
* $a_i$ consist of $1, 2, ..., n$
Input
A sequence is given in the following format.
$n$
$a_0 \; a_1 \; ... \; a_{n-1}$
Output
Print the previous permutation, the given sequence and the next permutation in the 1st, 2nd and 3rd lines respectively. Separate adjacency elements by a space character. Note that if there is no permutation, print nothing in the corresponding line.
Examples
Input
3
2 1 3
Output
1 3 2
2 1 3
2 3 1
Input
3
3 2 1
Output
3 1 2
3 2 1
Submitted Solution:
```
from itertools import permutations
input()
L = [int(x) for x in input().split()]
k = tuple(L)
prev = None
L.sort()
f = 0
for s in permutations(L):
if s == k:
if prev:
print(*prev)
print(*s)
f += 1
else:
if f > 0:
print(*s)
break
prev = s
``` | instruction | 0 | 85,006 | 5 | 170,012 |
Yes | output | 1 | 85,006 | 5 | 170,013 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a sequence a_1, a_2, ..., a_n consisting of n integers.
You can choose any non-negative integer D (i.e. D ≥ 0), and for each a_i you can:
* add D (only once), i. e. perform a_i := a_i + D, or
* subtract D (only once), i. e. perform a_i := a_i - D, or
* leave the value of a_i unchanged.
It is possible that after an operation the value a_i becomes negative.
Your goal is to choose such minimum non-negative integer D and perform changes in such a way, that all a_i are equal (i.e. a_1=a_2=...=a_n).
Print the required D or, if it is impossible to choose such value D, print -1.
For example, for array [2, 8] the value D=3 is minimum possible because you can obtain the array [5, 5] if you will add D to 2 and subtract D from 8. And for array [1, 4, 7, 7] the value D=3 is also minimum possible. You can add it to 1 and subtract it from 7 and obtain the array [4, 4, 4, 4].
Input
The first line of the input contains one integer n (1 ≤ n ≤ 100) — the number of elements in a.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 100) — the sequence a.
Output
Print one integer — the minimum non-negative integer value D such that if you add this value to some a_i, subtract this value from some a_i and leave some a_i without changes, all obtained values become equal.
If it is impossible to choose such value D, print -1.
Examples
Input
6
1 4 4 7 4 1
Output
3
Input
5
2 2 5 2 5
Output
3
Input
4
1 3 3 7
Output
-1
Input
2
2 8
Output
3
Submitted Solution:
```
import math
n=input()
a=list(map(lambda x:int(x),input().split()))
a_min=min(a)
a_max=max(a)
isFind=False
ans=math.inf
for i in range(a_min,a_max+1):
diff=0
flag=True
for j in a:
if j-i==0:
continue
else:
if diff==0:
diff=abs(i-j)
elif abs(j-i)!=diff:
flag=False
break
if flag:
ans=min(ans,diff)
isFind=True
if not isFind:
print(-1)
else:
print(ans)
``` | instruction | 0 | 85,082 | 5 | 170,164 |
Yes | output | 1 | 85,082 | 5 | 170,165 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a sequence a_1, a_2, ..., a_n consisting of n integers.
You can choose any non-negative integer D (i.e. D ≥ 0), and for each a_i you can:
* add D (only once), i. e. perform a_i := a_i + D, or
* subtract D (only once), i. e. perform a_i := a_i - D, or
* leave the value of a_i unchanged.
It is possible that after an operation the value a_i becomes negative.
Your goal is to choose such minimum non-negative integer D and perform changes in such a way, that all a_i are equal (i.e. a_1=a_2=...=a_n).
Print the required D or, if it is impossible to choose such value D, print -1.
For example, for array [2, 8] the value D=3 is minimum possible because you can obtain the array [5, 5] if you will add D to 2 and subtract D from 8. And for array [1, 4, 7, 7] the value D=3 is also minimum possible. You can add it to 1 and subtract it from 7 and obtain the array [4, 4, 4, 4].
Input
The first line of the input contains one integer n (1 ≤ n ≤ 100) — the number of elements in a.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 100) — the sequence a.
Output
Print one integer — the minimum non-negative integer value D such that if you add this value to some a_i, subtract this value from some a_i and leave some a_i without changes, all obtained values become equal.
If it is impossible to choose such value D, print -1.
Examples
Input
6
1 4 4 7 4 1
Output
3
Input
5
2 2 5 2 5
Output
3
Input
4
1 3 3 7
Output
-1
Input
2
2 8
Output
3
Submitted Solution:
```
n=int(input())
a=[int(a) for a in input().split()]
a.sort()
s=set()
min1=-9999
for i in a:
s.add(i)
if i>min1:
min2=min1
min1=i
if len(s)==2:
print (max(a)-min(a))
elif len(s)==3:
if (min2-min(a)==max(a)-min2):
print (min2-min(a))
else:
print (-1)
else:
print (-1)
``` | instruction | 0 | 85,086 | 5 | 170,172 |
No | output | 1 | 85,086 | 5 | 170,173 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a sequence a_1, a_2, ..., a_n consisting of n integers.
You can choose any non-negative integer D (i.e. D ≥ 0), and for each a_i you can:
* add D (only once), i. e. perform a_i := a_i + D, or
* subtract D (only once), i. e. perform a_i := a_i - D, or
* leave the value of a_i unchanged.
It is possible that after an operation the value a_i becomes negative.
Your goal is to choose such minimum non-negative integer D and perform changes in such a way, that all a_i are equal (i.e. a_1=a_2=...=a_n).
Print the required D or, if it is impossible to choose such value D, print -1.
For example, for array [2, 8] the value D=3 is minimum possible because you can obtain the array [5, 5] if you will add D to 2 and subtract D from 8. And for array [1, 4, 7, 7] the value D=3 is also minimum possible. You can add it to 1 and subtract it from 7 and obtain the array [4, 4, 4, 4].
Input
The first line of the input contains one integer n (1 ≤ n ≤ 100) — the number of elements in a.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 100) — the sequence a.
Output
Print one integer — the minimum non-negative integer value D such that if you add this value to some a_i, subtract this value from some a_i and leave some a_i without changes, all obtained values become equal.
If it is impossible to choose such value D, print -1.
Examples
Input
6
1 4 4 7 4 1
Output
3
Input
5
2 2 5 2 5
Output
3
Input
4
1 3 3 7
Output
-1
Input
2
2 8
Output
3
Submitted Solution:
```
import os
import sys
def log(*args, **kwargs):
if os.environ.get('CODEFR'):
print(*args, **kwargs)
n = int(input())
a = sorted(list(set(list(map(int, input().split())))))
if len(a) == 1:
print(0)
sys.exit(0)
if len(a) == 2:
result = (abs(a[0] - a[1]) / 2)
if result != int(result):
print(-1)
else:
print(int(result))
sys.exit(0)
if len(a) == 3:
if a[2] - a[1] == a[1] - a[0]:
print(abs(a[0] - a[1]))
else:
print(-1)
sys.exit(0)
if len(a) > 3:
print(-1)
sys.exit(0)
``` | instruction | 0 | 85,087 | 5 | 170,174 |
No | output | 1 | 85,087 | 5 | 170,175 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a sequence a_1, a_2, ..., a_n consisting of n integers.
You can choose any non-negative integer D (i.e. D ≥ 0), and for each a_i you can:
* add D (only once), i. e. perform a_i := a_i + D, or
* subtract D (only once), i. e. perform a_i := a_i - D, or
* leave the value of a_i unchanged.
It is possible that after an operation the value a_i becomes negative.
Your goal is to choose such minimum non-negative integer D and perform changes in such a way, that all a_i are equal (i.e. a_1=a_2=...=a_n).
Print the required D or, if it is impossible to choose such value D, print -1.
For example, for array [2, 8] the value D=3 is minimum possible because you can obtain the array [5, 5] if you will add D to 2 and subtract D from 8. And for array [1, 4, 7, 7] the value D=3 is also minimum possible. You can add it to 1 and subtract it from 7 and obtain the array [4, 4, 4, 4].
Input
The first line of the input contains one integer n (1 ≤ n ≤ 100) — the number of elements in a.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 100) — the sequence a.
Output
Print one integer — the minimum non-negative integer value D such that if you add this value to some a_i, subtract this value from some a_i and leave some a_i without changes, all obtained values become equal.
If it is impossible to choose such value D, print -1.
Examples
Input
6
1 4 4 7 4 1
Output
3
Input
5
2 2 5 2 5
Output
3
Input
4
1 3 3 7
Output
-1
Input
2
2 8
Output
3
Submitted Solution:
```
n=int(input())
a=[int(i) for i in input().split()]
c=list(set(a))
if(len(c)==1):
print(0)
elif(len(c)==2):
if(abs(c[1]-c[0])%2==0):
print(abs(c[1]-c[0])//2)
else:
print(abs(c[1]-c[0]))
elif(len(c)==3):
if(abs(c[2]-c[1])==abs(c[1]-c[0])):
print(abs(c[2]-c[1]))
else:
print(-1)
else:
print(-1)
``` | instruction | 0 | 85,088 | 5 | 170,176 |
No | output | 1 | 85,088 | 5 | 170,177 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a sequence a_1, a_2, ..., a_n consisting of n integers.
You can choose any non-negative integer D (i.e. D ≥ 0), and for each a_i you can:
* add D (only once), i. e. perform a_i := a_i + D, or
* subtract D (only once), i. e. perform a_i := a_i - D, or
* leave the value of a_i unchanged.
It is possible that after an operation the value a_i becomes negative.
Your goal is to choose such minimum non-negative integer D and perform changes in such a way, that all a_i are equal (i.e. a_1=a_2=...=a_n).
Print the required D or, if it is impossible to choose such value D, print -1.
For example, for array [2, 8] the value D=3 is minimum possible because you can obtain the array [5, 5] if you will add D to 2 and subtract D from 8. And for array [1, 4, 7, 7] the value D=3 is also minimum possible. You can add it to 1 and subtract it from 7 and obtain the array [4, 4, 4, 4].
Input
The first line of the input contains one integer n (1 ≤ n ≤ 100) — the number of elements in a.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 100) — the sequence a.
Output
Print one integer — the minimum non-negative integer value D such that if you add this value to some a_i, subtract this value from some a_i and leave some a_i without changes, all obtained values become equal.
If it is impossible to choose such value D, print -1.
Examples
Input
6
1 4 4 7 4 1
Output
3
Input
5
2 2 5 2 5
Output
3
Input
4
1 3 3 7
Output
-1
Input
2
2 8
Output
3
Submitted Solution:
```
sizes=int(input())
number = list(map(int, list(input().split())))
l=[]
for i in range(sizes):
l.append(number[i])
mi=min(l)
ma=max(l)
li = list(set(l))
if len(li)==1:
print(0)
elif len(li)==3:
difference = (ma-mi)/2
if ma-difference==mi+difference==li[1]:
print(int(difference))
elif len(li)==2:
difference = ma-mi
print(int(difference))
else:
print(-1)
``` | instruction | 0 | 85,089 | 5 | 170,178 |
No | output | 1 | 85,089 | 5 | 170,179 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given four positive integers n, m, a, b (1 ≤ b ≤ n ≤ 50; 1 ≤ a ≤ m ≤ 50). Find any such rectangular matrix of size n × m that satisfies all of the following conditions:
* each row of the matrix contains exactly a ones;
* each column of the matrix contains exactly b ones;
* all other elements are zeros.
If the desired matrix does not exist, indicate this.
For example, for n=3, m=6, a=2, b=1, there exists a matrix satisfying the conditions above:
$$$ \begin{vmatrix} 0 & 1 & 0 & 0 & 0 & 1 \\\ 1 & 0 & 0 & 1 & 0 & 0 \\\ 0 & 0 & 1 & 0 & 1 & 0 \end{vmatrix} $$$
Input
The first line contains an integer t (1 ≤ t ≤ 1000) — the number of test cases. Then t test cases follow.
Each test case is described by four positive integers n, m, a, b (1 ≤ b ≤ n ≤ 50; 1 ≤ a ≤ m ≤ 50), where n and m are the sizes of the matrix, and a and b are the number of ones for rows and columns, respectively.
Output
For each test case print:
* "YES" (without quotes) and the required matrix (if there are several answers, print any) if it exists, or
* "NO" (without quotes) if it does not exist.
To print the matrix n × m, print n rows, each of which consists of m numbers 0 or 1 describing a row of the matrix. Numbers must be printed without spaces.
Example
Input
5
3 6 2 1
2 2 2 1
2 2 2 2
4 4 2 2
2 1 1 2
Output
YES
010001
100100
001010
NO
YES
11
11
YES
1100
1100
0011
0011
YES
1
1
Submitted Solution:
```
t = int(input())
while t > 0:
n, m, a, b = map(int, input().split())
if n * a != m * b:
print('No')
else:
print('Yes')
x = '1'*a+'0'*(m-a)
for i in range(n):
print(x)
x = x[m-a:] + x[:m-a]
t -= 1
``` | instruction | 0 | 85,159 | 5 | 170,318 |
Yes | output | 1 | 85,159 | 5 | 170,319 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given four positive integers n, m, a, b (1 ≤ b ≤ n ≤ 50; 1 ≤ a ≤ m ≤ 50). Find any such rectangular matrix of size n × m that satisfies all of the following conditions:
* each row of the matrix contains exactly a ones;
* each column of the matrix contains exactly b ones;
* all other elements are zeros.
If the desired matrix does not exist, indicate this.
For example, for n=3, m=6, a=2, b=1, there exists a matrix satisfying the conditions above:
$$$ \begin{vmatrix} 0 & 1 & 0 & 0 & 0 & 1 \\\ 1 & 0 & 0 & 1 & 0 & 0 \\\ 0 & 0 & 1 & 0 & 1 & 0 \end{vmatrix} $$$
Input
The first line contains an integer t (1 ≤ t ≤ 1000) — the number of test cases. Then t test cases follow.
Each test case is described by four positive integers n, m, a, b (1 ≤ b ≤ n ≤ 50; 1 ≤ a ≤ m ≤ 50), where n and m are the sizes of the matrix, and a and b are the number of ones for rows and columns, respectively.
Output
For each test case print:
* "YES" (without quotes) and the required matrix (if there are several answers, print any) if it exists, or
* "NO" (without quotes) if it does not exist.
To print the matrix n × m, print n rows, each of which consists of m numbers 0 or 1 describing a row of the matrix. Numbers must be printed without spaces.
Example
Input
5
3 6 2 1
2 2 2 1
2 2 2 2
4 4 2 2
2 1 1 2
Output
YES
010001
100100
001010
NO
YES
11
11
YES
1100
1100
0011
0011
YES
1
1
Submitted Solution:
```
from sys import stdin, gettrace
if not gettrace():
def input():
return next(stdin)[:-1]
# def input():
# return stdin.buffer.readline()
def main():
def solve():
n,m,a,b = map(int, input().split())
if n*a != m*b:
print("NO")
return
print("YES")
for i in range(n):
grid = ['0'] * m
for j in range(i*a, (i+1)*a):
grid[j%m] = '1'
print(''.join(grid))
q = int(input())
for _ in range(q):
solve()
if __name__ == "__main__":
main()
``` | instruction | 0 | 85,161 | 5 | 170,322 |
Yes | output | 1 | 85,161 | 5 | 170,323 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given four positive integers n, m, a, b (1 ≤ b ≤ n ≤ 50; 1 ≤ a ≤ m ≤ 50). Find any such rectangular matrix of size n × m that satisfies all of the following conditions:
* each row of the matrix contains exactly a ones;
* each column of the matrix contains exactly b ones;
* all other elements are zeros.
If the desired matrix does not exist, indicate this.
For example, for n=3, m=6, a=2, b=1, there exists a matrix satisfying the conditions above:
$$$ \begin{vmatrix} 0 & 1 & 0 & 0 & 0 & 1 \\\ 1 & 0 & 0 & 1 & 0 & 0 \\\ 0 & 0 & 1 & 0 & 1 & 0 \end{vmatrix} $$$
Input
The first line contains an integer t (1 ≤ t ≤ 1000) — the number of test cases. Then t test cases follow.
Each test case is described by four positive integers n, m, a, b (1 ≤ b ≤ n ≤ 50; 1 ≤ a ≤ m ≤ 50), where n and m are the sizes of the matrix, and a and b are the number of ones for rows and columns, respectively.
Output
For each test case print:
* "YES" (without quotes) and the required matrix (if there are several answers, print any) if it exists, or
* "NO" (without quotes) if it does not exist.
To print the matrix n × m, print n rows, each of which consists of m numbers 0 or 1 describing a row of the matrix. Numbers must be printed without spaces.
Example
Input
5
3 6 2 1
2 2 2 1
2 2 2 2
4 4 2 2
2 1 1 2
Output
YES
010001
100100
001010
NO
YES
11
11
YES
1100
1100
0011
0011
YES
1
1
Submitted Solution:
```
"""
from collections import defaultdict
from itertools import product
t = int(input())
for i in range(t):
n,m = list(map(int, input().split()))
store = [defaultdict(int) for i in range(m)]
strings = []
for j in range(n):
s = input()
strings.append(s)
for k in range(len(s)):
store[k][s[k]] += 1
ans = [set() for i in range(m)]
for mi in range(len(store)):
m = store[mi]
for i,j in m.items():
ans[mi].add(i)
test = sorted(ans, key=lambda x: len(x))
#print(test)
if len(test) > 1 and len(test[-2]) > 5:
final = False
else:
final = False
for answer in product(*ans):
main = answer
got =True
for string in strings:
count = 0
#print(string, main)
for ind in range(len(main)):
if string[ind]!=main[ind]:
count += 1
if count > 1:
got = False
break
if count > 1:
got = False
break
if got:
print("".join(answer))
final = True
break
if not final:
print(-1)"""
t = int(input())
for i in range(t):
n,m,a,b = list(map(int, input().split()))
#print(n,m,a,b)
if n*a==m*b:
print("YES")
matrix = [["0"]*m for j in range(n)]
col = 0
for row in range(n):
#print("ROW", row, "COLUMN", col)
tot = 0
while True:
if tot==a:
break
#print(row, col,a,b)
matrix[row][col] = "1"
col += 1
tot += 1
col %= m
col %= m
for ma in matrix:
print("".join(ma))
else:
print("NO")
``` | instruction | 0 | 85,162 | 5 | 170,324 |
Yes | output | 1 | 85,162 | 5 | 170,325 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given four positive integers n, m, a, b (1 ≤ b ≤ n ≤ 50; 1 ≤ a ≤ m ≤ 50). Find any such rectangular matrix of size n × m that satisfies all of the following conditions:
* each row of the matrix contains exactly a ones;
* each column of the matrix contains exactly b ones;
* all other elements are zeros.
If the desired matrix does not exist, indicate this.
For example, for n=3, m=6, a=2, b=1, there exists a matrix satisfying the conditions above:
$$$ \begin{vmatrix} 0 & 1 & 0 & 0 & 0 & 1 \\\ 1 & 0 & 0 & 1 & 0 & 0 \\\ 0 & 0 & 1 & 0 & 1 & 0 \end{vmatrix} $$$
Input
The first line contains an integer t (1 ≤ t ≤ 1000) — the number of test cases. Then t test cases follow.
Each test case is described by four positive integers n, m, a, b (1 ≤ b ≤ n ≤ 50; 1 ≤ a ≤ m ≤ 50), where n and m are the sizes of the matrix, and a and b are the number of ones for rows and columns, respectively.
Output
For each test case print:
* "YES" (without quotes) and the required matrix (if there are several answers, print any) if it exists, or
* "NO" (without quotes) if it does not exist.
To print the matrix n × m, print n rows, each of which consists of m numbers 0 or 1 describing a row of the matrix. Numbers must be printed without spaces.
Example
Input
5
3 6 2 1
2 2 2 1
2 2 2 2
4 4 2 2
2 1 1 2
Output
YES
010001
100100
001010
NO
YES
11
11
YES
1100
1100
0011
0011
YES
1
1
Submitted Solution:
```
# 1 ≤ b ≤ n ≤ 50
# 1 ≤ a ≤ m ≤ 50
t = int(input())
for iterator in range(t):
n, m, a, b = (int(i) for i in input().split())
if ((n <= m and m % n == 0 and m // a == n // b and n % b == 0) or
(n > m and n % m == 0 and m // a == n // b and n % b == 0)):
print('YES')
fr = n // b
for i in range(n):
print(''.join(['1' if (j+i) % fr == 0 else '0' for j in range(m)]))
else:
print('NO')
``` | instruction | 0 | 85,164 | 5 | 170,328 |
No | output | 1 | 85,164 | 5 | 170,329 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given four positive integers n, m, a, b (1 ≤ b ≤ n ≤ 50; 1 ≤ a ≤ m ≤ 50). Find any such rectangular matrix of size n × m that satisfies all of the following conditions:
* each row of the matrix contains exactly a ones;
* each column of the matrix contains exactly b ones;
* all other elements are zeros.
If the desired matrix does not exist, indicate this.
For example, for n=3, m=6, a=2, b=1, there exists a matrix satisfying the conditions above:
$$$ \begin{vmatrix} 0 & 1 & 0 & 0 & 0 & 1 \\\ 1 & 0 & 0 & 1 & 0 & 0 \\\ 0 & 0 & 1 & 0 & 1 & 0 \end{vmatrix} $$$
Input
The first line contains an integer t (1 ≤ t ≤ 1000) — the number of test cases. Then t test cases follow.
Each test case is described by four positive integers n, m, a, b (1 ≤ b ≤ n ≤ 50; 1 ≤ a ≤ m ≤ 50), where n and m are the sizes of the matrix, and a and b are the number of ones for rows and columns, respectively.
Output
For each test case print:
* "YES" (without quotes) and the required matrix (if there are several answers, print any) if it exists, or
* "NO" (without quotes) if it does not exist.
To print the matrix n × m, print n rows, each of which consists of m numbers 0 or 1 describing a row of the matrix. Numbers must be printed without spaces.
Example
Input
5
3 6 2 1
2 2 2 1
2 2 2 2
4 4 2 2
2 1 1 2
Output
YES
010001
100100
001010
NO
YES
11
11
YES
1100
1100
0011
0011
YES
1
1
Submitted Solution:
```
for t in range(int(input())):
n,m,a,b=map(int,input().split())
x=["0"]*a+["1"]*(m-a)
if n*a==m*b:
print("YES")
for i in range(n):
x=x[a:]+x[:a]
print("".join(x))
else:
print("NO")
``` | instruction | 0 | 85,165 | 5 | 170,330 |
No | output | 1 | 85,165 | 5 | 170,331 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.