message stringlengths 2 57.2k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 61 108k | cluster float64 22 22 | __index_level_0__ int64 122 217k |
|---|---|---|---|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
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. | instruction | 0 | 84,260 | 22 | 168,520 |
Tags: math
Correct 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()
a1 = b1 - binpow(b2, phi(b1) - 1, b1)
a2 = b2 - int((a1*b2+1)/b1)
print("YES")
print(2)
print(a1, b1)
print(a2, b2)
``` | output | 1 | 84,260 | 22 | 168,521 |
Provide tags and a correct Python 3 solution for this coding contest problem.
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. | instruction | 0 | 84,261 | 22 | 168,522 |
Tags: math
Correct Solution:
```
# ========== //\\ //|| ||====//||
# || // \\ || || // ||
# || //====\\ || || // ||
# || // \\ || || // ||
# ========== // \\ ======== ||//====||
# code
def egcd(a, b):
if a == 0 :
return b, 0, 1
gcd, x1, y1 = egcd(b % a, a)
x = y1 - (b//a) * x1
y = x1
return gcd, x, y
def main():
n = int(input())
div = []
d = set()
m = n
i = 2
while i * i <= n:
cnt = 0
while n % i == 0:
cnt += 1
n //= i
d.add(i)
if cnt > 0:
div.append((cnt, i))
i += 1
if n > 1:
div.append((1, n))
d.add(n)
for i in d:
if i == m:
d.remove(i)
break
if len(d) < 2:
print('NO')
return
ans1 = 1
for i in range(div[0][0]):
ans1 *= div[0][1]
ans2 = 1
for i in div[1:]:
for j in range(i[0]):
ans2 *= i[1]
gcd, x, y = egcd(ans2, -ans1)
if x < 0 or y < 0:
gcd, x, y = egcd(ans1, -ans2)
x,y = y,x
print('YES')
print(2)
if ans2 * x + ans1 * y == m - 1:
print(x, ans1)
print(y, ans2)
elif ans2 * (ans1 - x) + ans1 * y == m - 1:
print(ans1 - x, ans1)
print(y, ans2)
elif ans2 * x + ans1 * (ans2 - y) == m - 1:
print(x, ans1)
print(ans2 - y, ans2)
else:
print(ans1 - x, ans1)
print(ans2 - y, ans2)
return
if __name__ == "__main__":
main()
``` | output | 1 | 84,261 | 22 | 168,523 |
Provide tags and a correct Python 3 solution for this coding contest problem.
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. | instruction | 0 | 84,262 | 22 | 168,524 |
Tags: math
Correct 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)
return _factors
if __name__ == '__main__':
n = int(input())
_f = factors(n)
sz = len(_f)
if sz < 2:
print('NO')
else:
print('YES\n2')
for i in range(1, _f[0]):
num, den = i, _f[0]
frac = Fraction(num, den)
frac = Fraction(n - 1, n) - frac
if frac.denominator < n:
print(num, den)
print(frac.numerator, frac.denominator)
break
``` | output | 1 | 84,262 | 22 | 168,525 |
Provide tags and a correct Python 3 solution for this coding contest problem.
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. | instruction | 0 | 84,263 | 22 | 168,526 |
Tags: math
Correct Solution:
```
from math import gcd
def check(e,f,n):
i=1
while i*e<=n:
if (n-(i*e))%f==0:
return ((n-(i*e))//f)
i+=1
def prime(x):
b=[]
i=2
while i*i<=x:
if x%i==0:
if x//i==i:
b.append(i)
else:
b.extend([i,x//i])
i+=1
return b
k=int(input())
a=prime(k)
a.sort()
e,f=-1,-1
l=len(a)
for i in range(l):
if gcd(a[i],a[l-1-i])==1:
e=a[i]
f=a[l-i-1]
break
if e==-1:
print("NO")
else:
x=check(e,f,k-1)
y=(k-1-x*f)//e
print("YES")
print(2)
print(x,e)
print(y,f)
``` | output | 1 | 84,263 | 22 | 168,527 |
Provide tags and a correct Python 3 solution for this coding contest problem.
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. | instruction | 0 | 84,264 | 22 | 168,528 |
Tags: math
Correct Solution:
```
import math
# method to print the divisors
def ps(n) :
a=[]
# Note that this loop runs till square root
i = 1
while i <= math.sqrt(n):
if (n % i == 0) :
# If divisors are equal, print only one
if (n / i == i) :
a.append(i)
else :
# Otherwise print both
a.extend([i , n//i])
i = i + 1
return a
def gcd(a,b):
if a%b==0:
return b
else:
return gcd(b,a%b)
def sol(a, b, n):
i = 0
while i * a <= n:
if (n - (i * a)) % b == 0:
return int((n - (i * a)) / b)
i = i + 1
n=int(input())
a=ps(n)
a.sort()
e=-1
d=len(a)
for i in range(1,(len(a)+1)//2):
if gcd(a[i],a[d-1-i])==1:
e=a[i]
f=a[d-i-1]
if e==-1:
print("NO")
else:
a=sol(e,f,n-1)
b=(n-1-a*f)//e
print("YES")
print(2)
print(a,e)
print(b,f)
``` | output | 1 | 84,264 | 22 | 168,529 |
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:
```
import math
# method to print the divisors
def ps(n) :
a=[]
# Note that this loop runs till square root
i = 1
while i <= math.sqrt(n):
if (n % i == 0) :
# If divisors are equal, print only one
if (n / i == i) :
a.append(i)
else :
# Otherwise print both
a.extend([i , n//i])
i = i + 1
return a
def gcd(a,b):
if a%b==0:
return b
else:
return gcd(b,a%b)
def sol(a, b, n):
i = 0
while i * a <= n:
if (n - (i * a)) % b == 0:
return int((n - (i * a)) / b)
i = i + 1
n=int(input())
a=ps(n)
a.sort()
e=-1
d=len(a)
for i in range(1,(len(a)+1)//2):
if gcd(a[i],a[d-1-i])==1:
e=a[i]
f=a[d-i-1]
if e==-1:
print("NO")
else:
a=sol(e,f,n-1)
b=(n-1-a*f)//e
print("YES")
print(2)
print(a,b)
print(e,f)
``` | instruction | 0 | 84,265 | 22 | 168,530 |
No | output | 1 | 84,265 | 22 | 168,531 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a multiset of n integers. You should select exactly k of them in a such way that the difference between any two of them is divisible by m, or tell that it is impossible.
Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number in multiset of selected numbers should not exceed the number of its occurrences in the original multiset.
Input
First line contains three integers n, k and m (2 ≤ k ≤ n ≤ 100 000, 1 ≤ m ≤ 100 000) — number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers.
Second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the numbers in the multiset.
Output
If it is not possible to select k numbers in the desired way, output «No» (without the quotes).
Otherwise, in the first line of output print «Yes» (without the quotes). In the second line print k integers b1, b2, ..., bk — the selected numbers. If there are multiple possible solutions, print any of them.
Examples
Input
3 2 3
1 8 4
Output
Yes
1 4
Input
3 3 3
1 8 4
Output
No
Input
4 3 5
2 7 7 7
Output
Yes
2 7 7 | instruction | 0 | 84,718 | 22 | 169,436 |
Tags: implementation, math, number theory
Correct Solution:
```
read=lambda : map(int,input().split())
n,k,m=read()
a=list(read())
r=[[] for _ in range(m)]
p=-1
for d in a:
t=d%m
r[t].append(d)
if len(r[t])>=k:
p=t
break
if p<0:
print('No')
else:
print('Yes')
print(' '.join(map(str,r[p])))
``` | output | 1 | 84,718 | 22 | 169,437 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a multiset of n integers. You should select exactly k of them in a such way that the difference between any two of them is divisible by m, or tell that it is impossible.
Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number in multiset of selected numbers should not exceed the number of its occurrences in the original multiset.
Input
First line contains three integers n, k and m (2 ≤ k ≤ n ≤ 100 000, 1 ≤ m ≤ 100 000) — number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers.
Second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the numbers in the multiset.
Output
If it is not possible to select k numbers in the desired way, output «No» (without the quotes).
Otherwise, in the first line of output print «Yes» (without the quotes). In the second line print k integers b1, b2, ..., bk — the selected numbers. If there are multiple possible solutions, print any of them.
Examples
Input
3 2 3
1 8 4
Output
Yes
1 4
Input
3 3 3
1 8 4
Output
No
Input
4 3 5
2 7 7 7
Output
Yes
2 7 7 | instruction | 0 | 84,719 | 22 | 169,438 |
Tags: implementation, math, number theory
Correct Solution:
```
n,k,m=map(int,input().split())
a=list(map(int,input().split()))
mods=[0]*m
mod=0
for i in range(n):
mod=a[i]%m
mods[mod]+=1
if mods[mod]==k:
break
else:
print('No')
exit()
print('Yes')
results=[None]*k
count=0
for i in range(n):
cur=a[i]
if cur%m==mod:
results[count]=cur
count+=1
if count==k:
print(' '.join(map(str,results)))
break
``` | output | 1 | 84,719 | 22 | 169,439 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a multiset of n integers. You should select exactly k of them in a such way that the difference between any two of them is divisible by m, or tell that it is impossible.
Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number in multiset of selected numbers should not exceed the number of its occurrences in the original multiset.
Input
First line contains three integers n, k and m (2 ≤ k ≤ n ≤ 100 000, 1 ≤ m ≤ 100 000) — number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers.
Second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the numbers in the multiset.
Output
If it is not possible to select k numbers in the desired way, output «No» (without the quotes).
Otherwise, in the first line of output print «Yes» (without the quotes). In the second line print k integers b1, b2, ..., bk — the selected numbers. If there are multiple possible solutions, print any of them.
Examples
Input
3 2 3
1 8 4
Output
Yes
1 4
Input
3 3 3
1 8 4
Output
No
Input
4 3 5
2 7 7 7
Output
Yes
2 7 7 | instruction | 0 | 84,720 | 22 | 169,440 |
Tags: implementation, math, number theory
Correct Solution:
```
import sys
import math
import itertools
import collections
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return list(map(int, input().split()))
def lcm(a, b): return abs(a * b) // math.gcd(a, b)
def wr(arr): return ' '.join(map(str, arr))
def revn(n): return str(n)[::-1]
def dd(): return collections.defaultdict(int)
def ddl(): return collections.defaultdict(list)
def sieve(n):
if n < 2: return list()
prime = [True for _ in range(n + 1)]
p = 3
while p * p <= n:
if prime[p]:
for i in range(p * 2, n + 1, p):
prime[i] = False
p += 2
r = [2]
for p in range(3, n + 1, 2):
if prime[p]:
r.append(p)
return r
def divs(n, start=1):
r = []
for i in range(start, int(math.sqrt(n) + 1)):
if (n % i == 0):
if (n / i == i):
r.append(i)
else:
r.extend([i, n // i])
return r
def divn(n, primes):
divs_number = 1
for i in primes:
if n == 1:
return divs_number
t = 1
while n % i == 0:
t += 1
n //= i
divs_number *= t
def prime(n):
if n == 2: return True
if n % 2 == 0 or n <= 1: return False
sqr = int(math.sqrt(n)) + 1
for d in range(3, sqr, 2):
if n % d == 0: return False
return True
def convn(number, base):
newnumber = 0
while number > 0:
newnumber += number % base
number //= base
return newnumber
def cdiv(n, k): return n // k + (n % k != 0)
n, k, m = mi()
a = sorted(li())
ans = ddl()
for i in range(n):
ans[(a[i] - a[0]) % m].append(a[i])
for i in range(m):
if len(ans[i]) >= k:
print('Yes')
exit(print(wr(ans[i][:k])))
print('No')
``` | output | 1 | 84,720 | 22 | 169,441 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a multiset of n integers. You should select exactly k of them in a such way that the difference between any two of them is divisible by m, or tell that it is impossible.
Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number in multiset of selected numbers should not exceed the number of its occurrences in the original multiset.
Input
First line contains three integers n, k and m (2 ≤ k ≤ n ≤ 100 000, 1 ≤ m ≤ 100 000) — number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers.
Second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the numbers in the multiset.
Output
If it is not possible to select k numbers in the desired way, output «No» (without the quotes).
Otherwise, in the first line of output print «Yes» (without the quotes). In the second line print k integers b1, b2, ..., bk — the selected numbers. If there are multiple possible solutions, print any of them.
Examples
Input
3 2 3
1 8 4
Output
Yes
1 4
Input
3 3 3
1 8 4
Output
No
Input
4 3 5
2 7 7 7
Output
Yes
2 7 7 | instruction | 0 | 84,721 | 22 | 169,442 |
Tags: implementation, math, number theory
Correct Solution:
```
inp = list(map(int,input().split(' ')))
n, k, m = inp[0], inp[1], inp[2]
nums = [[] for i in range(m)]
for input in list(map(int,input().split(' '))):
nums[input%m].append(input)
done=False
for j in nums:
if len(j) >= k:
done=True
print('Yes')
print(" ".join(list(map(str,j[:k]))))
break
if not done:
print('No')
``` | output | 1 | 84,721 | 22 | 169,443 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a multiset of n integers. You should select exactly k of them in a such way that the difference between any two of them is divisible by m, or tell that it is impossible.
Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number in multiset of selected numbers should not exceed the number of its occurrences in the original multiset.
Input
First line contains three integers n, k and m (2 ≤ k ≤ n ≤ 100 000, 1 ≤ m ≤ 100 000) — number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers.
Second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the numbers in the multiset.
Output
If it is not possible to select k numbers in the desired way, output «No» (without the quotes).
Otherwise, in the first line of output print «Yes» (without the quotes). In the second line print k integers b1, b2, ..., bk — the selected numbers. If there are multiple possible solutions, print any of them.
Examples
Input
3 2 3
1 8 4
Output
Yes
1 4
Input
3 3 3
1 8 4
Output
No
Input
4 3 5
2 7 7 7
Output
Yes
2 7 7 | instruction | 0 | 84,722 | 22 | 169,444 |
Tags: implementation, math, number theory
Correct Solution:
```
n,k,m=map(int,input().split())
a=input().split()
b=[[]for i in range(0,m)]
for i in range(0,n):
c=int(a[i])
b[c%m].append(c)
if len(b[c%m])==k:
print('Yes')
print(' '.join(map(str,b[c%m])))
exit()
print('No')
# Made By Mostafa_Khaled
``` | output | 1 | 84,722 | 22 | 169,445 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a multiset of n integers. You should select exactly k of them in a such way that the difference between any two of them is divisible by m, or tell that it is impossible.
Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number in multiset of selected numbers should not exceed the number of its occurrences in the original multiset.
Input
First line contains three integers n, k and m (2 ≤ k ≤ n ≤ 100 000, 1 ≤ m ≤ 100 000) — number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers.
Second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the numbers in the multiset.
Output
If it is not possible to select k numbers in the desired way, output «No» (without the quotes).
Otherwise, in the first line of output print «Yes» (without the quotes). In the second line print k integers b1, b2, ..., bk — the selected numbers. If there are multiple possible solutions, print any of them.
Examples
Input
3 2 3
1 8 4
Output
Yes
1 4
Input
3 3 3
1 8 4
Output
No
Input
4 3 5
2 7 7 7
Output
Yes
2 7 7 | instruction | 0 | 84,723 | 22 | 169,446 |
Tags: implementation, math, number theory
Correct Solution:
```
n,k,m = map(int,input().split())
A = input().split()
B = [[] for x in range(0,m)]
for i in range(0,len(A)):
x = int(A[i])
B[x%m].append(x)
if len(B[x%m])==k:
print("Yes")
print(" ".join(map(str, B[x%m])))
exit()
print("No")
``` | output | 1 | 84,723 | 22 | 169,447 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a multiset of n integers. You should select exactly k of them in a such way that the difference between any two of them is divisible by m, or tell that it is impossible.
Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number in multiset of selected numbers should not exceed the number of its occurrences in the original multiset.
Input
First line contains three integers n, k and m (2 ≤ k ≤ n ≤ 100 000, 1 ≤ m ≤ 100 000) — number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers.
Second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the numbers in the multiset.
Output
If it is not possible to select k numbers in the desired way, output «No» (without the quotes).
Otherwise, in the first line of output print «Yes» (without the quotes). In the second line print k integers b1, b2, ..., bk — the selected numbers. If there are multiple possible solutions, print any of them.
Examples
Input
3 2 3
1 8 4
Output
Yes
1 4
Input
3 3 3
1 8 4
Output
No
Input
4 3 5
2 7 7 7
Output
Yes
2 7 7 | instruction | 0 | 84,724 | 22 | 169,448 |
Tags: implementation, math, number theory
Correct Solution:
```
import math
import re
def ria():
return [int(i) for i in input().split()]
def ri():
return int(input())
def rfa():
return [float(i) for i in input().split()]
n, k, m = ria()
mp = {}
ar = ria()
mx = 0
for i in ar:
if i % m not in mp:
mp[i % m] = []
mp[i % m].append(i)
if mx < len(mp[i % m]):
mx = len(mp[i % m])
if mx<k:
print('No')
exit(0)
print('Yes')
for i in mp:
i=mp[i]
if len(i) >= mx:
for j in range(k):
print(i[j], end=' ')
break
``` | output | 1 | 84,724 | 22 | 169,449 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a multiset of n integers. You should select exactly k of them in a such way that the difference between any two of them is divisible by m, or tell that it is impossible.
Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number in multiset of selected numbers should not exceed the number of its occurrences in the original multiset.
Input
First line contains three integers n, k and m (2 ≤ k ≤ n ≤ 100 000, 1 ≤ m ≤ 100 000) — number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers.
Second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the numbers in the multiset.
Output
If it is not possible to select k numbers in the desired way, output «No» (without the quotes).
Otherwise, in the first line of output print «Yes» (without the quotes). In the second line print k integers b1, b2, ..., bk — the selected numbers. If there are multiple possible solutions, print any of them.
Examples
Input
3 2 3
1 8 4
Output
Yes
1 4
Input
3 3 3
1 8 4
Output
No
Input
4 3 5
2 7 7 7
Output
Yes
2 7 7 | instruction | 0 | 84,725 | 22 | 169,450 |
Tags: implementation, math, number theory
Correct Solution:
```
from collections import defaultdict
def divisibility(nums,k,m):
remainder = defaultdict(list)
for num in nums:
r = num%m
remainder[r].append(num)
for keys,values in remainder.items():
if len(values)>=k:
return values
return None
if __name__=="__main__":
n,k,m = [int(i) for i in input().split()]
nums = [int(i) for i in input().split()]
# n,k,m = 3,2,3
# nums = [1,8,4]
if divisibility(nums,k,m)==None:
print("No")
else:
values = divisibility(nums,k,m)
print("Yes")
values = values[:k]
for i in range(len(values)):
if i==len(values)-1:
print(values[i])
else:
print(values[i],end = " ")
``` | output | 1 | 84,725 | 22 | 169,451 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a multiset of n integers. You should select exactly k of them in a such way that the difference between any two of them is divisible by m, or tell that it is impossible.
Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number in multiset of selected numbers should not exceed the number of its occurrences in the original multiset.
Input
First line contains three integers n, k and m (2 ≤ k ≤ n ≤ 100 000, 1 ≤ m ≤ 100 000) — number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers.
Second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the numbers in the multiset.
Output
If it is not possible to select k numbers in the desired way, output «No» (without the quotes).
Otherwise, in the first line of output print «Yes» (without the quotes). In the second line print k integers b1, b2, ..., bk — the selected numbers. If there are multiple possible solutions, print any of them.
Examples
Input
3 2 3
1 8 4
Output
Yes
1 4
Input
3 3 3
1 8 4
Output
No
Input
4 3 5
2 7 7 7
Output
Yes
2 7 7
Submitted Solution:
```
n, k, m = [int(i) for i in input().split()]
s = [int(i) for i in input().split()]
mi = [[] for i in range(m)]
for i in s:
mi[i%m].append(i)
for i in range(m):
if len(mi[i]) >= k:
print("Yes")
print(*mi[i][:k])
exit(0)
break
print("No")
``` | instruction | 0 | 84,726 | 22 | 169,452 |
Yes | output | 1 | 84,726 | 22 | 169,453 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a multiset of n integers. You should select exactly k of them in a such way that the difference between any two of them is divisible by m, or tell that it is impossible.
Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number in multiset of selected numbers should not exceed the number of its occurrences in the original multiset.
Input
First line contains three integers n, k and m (2 ≤ k ≤ n ≤ 100 000, 1 ≤ m ≤ 100 000) — number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers.
Second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the numbers in the multiset.
Output
If it is not possible to select k numbers in the desired way, output «No» (without the quotes).
Otherwise, in the first line of output print «Yes» (without the quotes). In the second line print k integers b1, b2, ..., bk — the selected numbers. If there are multiple possible solutions, print any of them.
Examples
Input
3 2 3
1 8 4
Output
Yes
1 4
Input
3 3 3
1 8 4
Output
No
Input
4 3 5
2 7 7 7
Output
Yes
2 7 7
Submitted Solution:
```
def solve():
n, k, m = [int(st) for st in input().split(" ")]
a = [int(st) for st in input().split(" ")]
division = {}
for i in range(len(a)):
num = a[i]
if num%m in division:
division[num%m][0] += 1
division[num%m][1].append(i)
else:
division[num%m] = [1, [i]]
for mod in division:
if division[mod][0] >= k:
return ("Yes", [a[index] for index in division[mod][1][:k]])
return ("No", [])
status, list_ = solve()
print(status)
if status == "Yes":
for num in list_:
print(num, end = " ")
``` | instruction | 0 | 84,727 | 22 | 169,454 |
Yes | output | 1 | 84,727 | 22 | 169,455 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a multiset of n integers. You should select exactly k of them in a such way that the difference between any two of them is divisible by m, or tell that it is impossible.
Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number in multiset of selected numbers should not exceed the number of its occurrences in the original multiset.
Input
First line contains three integers n, k and m (2 ≤ k ≤ n ≤ 100 000, 1 ≤ m ≤ 100 000) — number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers.
Second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the numbers in the multiset.
Output
If it is not possible to select k numbers in the desired way, output «No» (without the quotes).
Otherwise, in the first line of output print «Yes» (without the quotes). In the second line print k integers b1, b2, ..., bk — the selected numbers. If there are multiple possible solutions, print any of them.
Examples
Input
3 2 3
1 8 4
Output
Yes
1 4
Input
3 3 3
1 8 4
Output
No
Input
4 3 5
2 7 7 7
Output
Yes
2 7 7
Submitted Solution:
```
n, k, m = map(int, input().split())
remainders = dict()
for i in map(int, input().split()):
if i % m not in remainders:
remainders[i % m] = []
remainders[i % m].append(i)
if len(remainders[i % m]) >= k:
print('Yes')
print(' '.join(map(str, remainders[i % m])))
break
else:
print('No')
``` | instruction | 0 | 84,728 | 22 | 169,456 |
Yes | output | 1 | 84,728 | 22 | 169,457 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a multiset of n integers. You should select exactly k of them in a such way that the difference between any two of them is divisible by m, or tell that it is impossible.
Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number in multiset of selected numbers should not exceed the number of its occurrences in the original multiset.
Input
First line contains three integers n, k and m (2 ≤ k ≤ n ≤ 100 000, 1 ≤ m ≤ 100 000) — number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers.
Second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the numbers in the multiset.
Output
If it is not possible to select k numbers in the desired way, output «No» (without the quotes).
Otherwise, in the first line of output print «Yes» (without the quotes). In the second line print k integers b1, b2, ..., bk — the selected numbers. If there are multiple possible solutions, print any of them.
Examples
Input
3 2 3
1 8 4
Output
Yes
1 4
Input
3 3 3
1 8 4
Output
No
Input
4 3 5
2 7 7 7
Output
Yes
2 7 7
Submitted Solution:
```
n,k,m=map(int,input().split())
a=list(map(int,input().split()))
s=[]
c=[]
for i in range(m):
c.append(0)
s.append([])
for i in a:
j=i%m
c[j]=c[j]+1
s[j].append(i)
if c[j]==k:
print('Yes')
for z in s[j]:
print(z,end=' ')
break
if c[j]!=k:
print('No')
``` | instruction | 0 | 84,729 | 22 | 169,458 |
Yes | output | 1 | 84,729 | 22 | 169,459 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a multiset of n integers. You should select exactly k of them in a such way that the difference between any two of them is divisible by m, or tell that it is impossible.
Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number in multiset of selected numbers should not exceed the number of its occurrences in the original multiset.
Input
First line contains three integers n, k and m (2 ≤ k ≤ n ≤ 100 000, 1 ≤ m ≤ 100 000) — number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers.
Second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the numbers in the multiset.
Output
If it is not possible to select k numbers in the desired way, output «No» (without the quotes).
Otherwise, in the first line of output print «Yes» (without the quotes). In the second line print k integers b1, b2, ..., bk — the selected numbers. If there are multiple possible solutions, print any of them.
Examples
Input
3 2 3
1 8 4
Output
Yes
1 4
Input
3 3 3
1 8 4
Output
No
Input
4 3 5
2 7 7 7
Output
Yes
2 7 7
Submitted Solution:
```
def fun(arr,k,m):
res = []
for i in range(len(arr)):
res.append(arr[i]%m)
resset=list(set(res))
maxIndex = 0
for item in resset:
if res.count(item)>maxIndex:
maxIndex = item
if res.count(maxIndex)<k:
return []
aaa = []
for i in range(len(res)):
if(res[i]==maxIndex):
aaa.append(i)
return aaa
n,k,m=list(map(int,input().split(" ")))
arr = list(map(int,input().split(" ")))
aaa = fun(arr,k,m)
if(len(aaa) == 0):
print("NO")
else:
print("YES")
print(" ".join(str(arr[i]) for i in aaa[:k])+" ")
``` | instruction | 0 | 84,730 | 22 | 169,460 |
No | output | 1 | 84,730 | 22 | 169,461 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a multiset of n integers. You should select exactly k of them in a such way that the difference between any two of them is divisible by m, or tell that it is impossible.
Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number in multiset of selected numbers should not exceed the number of its occurrences in the original multiset.
Input
First line contains three integers n, k and m (2 ≤ k ≤ n ≤ 100 000, 1 ≤ m ≤ 100 000) — number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers.
Second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the numbers in the multiset.
Output
If it is not possible to select k numbers in the desired way, output «No» (without the quotes).
Otherwise, in the first line of output print «Yes» (without the quotes). In the second line print k integers b1, b2, ..., bk — the selected numbers. If there are multiple possible solutions, print any of them.
Examples
Input
3 2 3
1 8 4
Output
Yes
1 4
Input
3 3 3
1 8 4
Output
No
Input
4 3 5
2 7 7 7
Output
Yes
2 7 7
Submitted Solution:
```
from itertools import *
[n, k, m] = [int(i) for i in input().split()]
arr=list(map(int,input().split()))
const = 2
arr2 = []
s = ''
s2 = ''
for i in combinations(arr, k):
arr2.append(i)
for i in range(len(arr2)):
for j in range(len(arr2[i])):
s = s + str(arr2[i][j])
s2 = s2 + str(arr2[i][j]) + ' '
#print(s)
flag = True
for i in combinations(s, const):
if (int(s[0])-int(s[1]))%m != 0:
flag = False
if flag == True:
print('YES')
print(s2)
break
s = ''
s2 = ''
if flag == False:
print('NO')
``` | instruction | 0 | 84,731 | 22 | 169,462 |
No | output | 1 | 84,731 | 22 | 169,463 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a multiset of n integers. You should select exactly k of them in a such way that the difference between any two of them is divisible by m, or tell that it is impossible.
Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number in multiset of selected numbers should not exceed the number of its occurrences in the original multiset.
Input
First line contains three integers n, k and m (2 ≤ k ≤ n ≤ 100 000, 1 ≤ m ≤ 100 000) — number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers.
Second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the numbers in the multiset.
Output
If it is not possible to select k numbers in the desired way, output «No» (without the quotes).
Otherwise, in the first line of output print «Yes» (without the quotes). In the second line print k integers b1, b2, ..., bk — the selected numbers. If there are multiple possible solutions, print any of them.
Examples
Input
3 2 3
1 8 4
Output
Yes
1 4
Input
3 3 3
1 8 4
Output
No
Input
4 3 5
2 7 7 7
Output
Yes
2 7 7
Submitted Solution:
```
k, n, m = list(map(int, input().split()))
multiset = list(map(int, input().split()))
lis = []
for i in multiset:
if i % m == 0:
lis.append(str(i))
if len(lis) >= n:
lis = lis[:n]
print("Yes")
print(" ".join(lis))
quit()
lis = []
for j in multiset:
if (j + m) in multiset and multiset.count(j + m) + multiset.count(j) >= n:
print("Yes")
for y in range(multiset.count(j + m)):
lis.append(str(j + m))
for x in range(multiset.count(j)):
lis.append(str(j))
lis = lis[:n]
print(" ".join(lis))
quit()
print("No")
``` | instruction | 0 | 84,732 | 22 | 169,464 |
No | output | 1 | 84,732 | 22 | 169,465 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a multiset of n integers. You should select exactly k of them in a such way that the difference between any two of them is divisible by m, or tell that it is impossible.
Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number in multiset of selected numbers should not exceed the number of its occurrences in the original multiset.
Input
First line contains three integers n, k and m (2 ≤ k ≤ n ≤ 100 000, 1 ≤ m ≤ 100 000) — number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers.
Second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the numbers in the multiset.
Output
If it is not possible to select k numbers in the desired way, output «No» (without the quotes).
Otherwise, in the first line of output print «Yes» (without the quotes). In the second line print k integers b1, b2, ..., bk — the selected numbers. If there are multiple possible solutions, print any of them.
Examples
Input
3 2 3
1 8 4
Output
Yes
1 4
Input
3 3 3
1 8 4
Output
No
Input
4 3 5
2 7 7 7
Output
Yes
2 7 7
Submitted Solution:
```
from collections import defaultdict as dis
n,k,m=map(int,input().split())
l=list(map(int,input().split()))
d=dis(list)
for i in l:
d[i%m].append(i)
x=[]
for i in d:
if len(d[i])>=k:
x+=d[i][:k]
if x:
print("Yes"," ".join(map(str,x)),sep='\n')
else:
print("No")
``` | instruction | 0 | 84,733 | 22 | 169,466 |
No | output | 1 | 84,733 | 22 | 169,467 |
Provide a correct Python 3 solution for this coding contest problem.
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 | instruction | 0 | 84,910 | 22 | 169,820 |
"Correct Solution:
```
import sys
from bisect import bisect
class BinaryIndexedTree:
def __init__(self, n, MOD):
self.size = n + 1
self.tree = [0] * (n + 2)
self.MOD = MOD
def sum(self, i):
i += 1
s = 0
while i > 0:
s = (s + self.tree[i]) % self.MOD
i -= i & -i
return s
def add(self, i, x):
i += 1
while i <= self.size:
self.tree[i] = (self.tree[i] + x) % self.MOD
i += i & -i
def debug_print(self, limit=None):
if limit is None:
limit = self.size
acc = [0] + [self.sum(i) for i in range(limit)]
aaa = [a1 - a0 for a0, a1 in zip(acc, acc[1:])]
print(aaa)
def solve(n, a, b, sss):
if a > b:
a, b = b, a
for s0, s2 in zip(sss, sss[2:]):
if s2 - s0 < a:
return 0
MOD = 10 ** 9 + 7
bit = BinaryIndexedTree(n, MOD)
bit.add(0, 1)
bit.add(1, 1)
sss.insert(0, -10 ** 18 - 1)
pos = 0
for i in range(1, n):
s0 = sss[i]
s1 = sss[i + 1]
lim = bisect(sss, s1 - b) - 1
if lim >= pos:
bit.add(i + 1, bit.sum(lim))
if s1 - s0 < a:
bit.add(i - 1, -bit.sum(i - 1))
pos = i - 1
return bit.sum(n)
n, a, b, *sss = map(int, sys.stdin.read().split())
print(solve(n, a, b, sss))
``` | output | 1 | 84,910 | 22 | 169,821 |
Provide a correct Python 3 solution for this coding contest problem.
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 | instruction | 0 | 84,911 | 22 | 169,822 |
"Correct 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] # -1
dpY_cum = [1] * (N+1) + [0] # -1
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] if iB >= dpY_left else 0
# ....YX
yx = dpX_cum[iA-1] - dpX_cum[dpX_left-1] if iA >= dpX_left else 0
# ....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)
``` | output | 1 | 84,911 | 22 | 169,823 |
Provide a correct Python 3 solution for this coding contest problem.
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 | instruction | 0 | 84,912 | 22 | 169,824 |
"Correct Solution:
```
mod=10**9+7
import bisect,sys
input=sys.stdin.readline
N,A,B=map(int,input().split())
S=[int(input()) for i in range(N)]
datax=[i for i in range(N+1)]
datay=[i for i in range(N+1)]
for i in range(2,N+1):
if S[i-1]-S[i-2]>=A:
datax[i]=datax[i-1]
if S[i-1]-S[i-2]>=B:
datay[i]=datay[i-1]
#print(datax)
#print(datay)
dpx=[0]*(N+1)
imosx=[0]*(N+1)
dpy=[0]*(N+1)
imosy=[0]*(N+1)
dpx[0]=1
dpy[0]=1
imosx[0]=1
imosy[0]=1
for i in range(1,N):
id=bisect.bisect_right(S,S[i]-B)
R=min(id+1,i)
L=datax[i]
if R>=L:
dpx[i]=(imosy[R-1]-imosy[L-2]*(L>=2))%mod
imosx[i]=(imosx[i-1]+dpx[i])%mod
else:
imosx[i]=imosx[i-1]
id=bisect.bisect_right(S,S[i]-A)
R=min(id+1,i)
L=datay[i]
if R>=L:
dpy[i]=(imosx[R-1]-imosx[L-2]*(L>=2))%mod
imosy[i]=(imosy[i-1]+dpy[i])%mod
else:
imosy[i]=imosy[i-1]
i=N
R=i
L=datax[i]
if R>=L:
dpx[i]=(imosy[R-1]-imosy[L-2]*(L>=2))%mod
imosx[i]=(imosx[i-1]+dpx[i])%mod
else:
imosx[i]=imosx[i-1]
R=i
L=datay[i]
if R>=L:
dpy[i]=(imosx[R-1]-imosx[L-2]*(L>=2))%mod
imosy[i]=(imosy[i-1]+dpy[i])%mod
else:
imosy[i]=imosy[i-1]
#print(dpx)
#print(dpy)
print((dpx[-1]+dpy[-1])%mod)
``` | output | 1 | 84,912 | 22 | 169,825 |
Provide a correct Python 3 solution for this coding contest problem.
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 | instruction | 0 | 84,913 | 22 | 169,826 |
"Correct Solution:
```
"""
https://atcoder.jp/contests/agc009/tasks/agc009_c
A <= B としてよい
dpだろうなぁ
dpA[i][X] = 1つ前を置いたのがBで、Aに置かれた最大がindexXの時の置き方
dpB[i][X] = 同様
if S[i]-S[i-1] >= B:
dpA[i][X] = dpA[i-1][X]
if X == i-1:
dpA[i][X] = ///
推移は、BITですればおk
もし差がB以下ならば→直前にBを置いていた場所に重ねおきはできない
→直前にAに置いていて、なおかつ最後にBに置いたのとの差がB以下の場合だけBにおける
→dpA[i][i-1]以外は0になる
#直前とB以上の差があるとき
if X != i-1:
dpBに置く[i][最後にAに置いたのがX] = dpB[i-1][X]
else:
dpB[i][i-1] = ΣdpA[i-1][y] (y<=S-B)
#差がないとき
if X == i-1:
dpB[i][i-1] = ΣdpA[i-1][y] (y<=S-B)
else:
dpB[i][X] = 0
"""
import sys
from sys import stdin
from collections import deque
def bitadd(a,w,bit): #aにwを加える(1-origin)
x = a
while x <= (len(bit)-1):
bit[x] += w
x += x & (-1 * x)
def bitsum(a,bit): #ind 1~aまでの和を求める
ret = 0
x = a
while x > 0:
ret += bit[x]
x -= x & (-1 * x)
return ret
N,A,B = map(int,stdin.readline().split())
mod = 10**9+7
BITA = [0] * (N+3)
BITB = [0] * (N+3)
bitadd(1,1,BITA)
#bitadd(0,1,BITB)
aq = deque([])
bq = deque([])
Slis = [float("-inf")]
for loop in range(N):
S = int(stdin.readline())
aq.append( (S,loop+2) )
bq.append( (S,loop+2) )
while aq[0][0] <= S-A:
aq.popleft()
while bq[0][0] <= S-B:
bq.popleft()
#dpAへの推移(Bに置く)
#Bに置けるのは、1つ前との差がB以上の場合全部おk
#そうでない場合、前にAにおいていて、かつ差がB以上の場合
"""
#全てokの場合
if S - Slis[-1] >= B:
Aans = bitsum(bq[0][1]-1,BITB)
Aans %= mod
else: #そうでない場合→直前にAに置いていた場合のみ可能→bitをリセットする必要あり
Aans = bitsum(bq[0][1]-1,BITB)
Aans %= mod
if S - Slis[-1] >= A:
Bans = bitsum(aq[0][1]-1,BITA)
Bans %= mod
else:
Bans = bitsum(aq[0][1]-1,BITA)
Bans %= mod
"""
Aans = bitsum(bq[0][1]-1,BITB)
Bans = bitsum(aq[0][1]-1,BITA)
if Aans < 0:
Aans = 0
if Bans < 0:
Bans = 0
Aans %= mod
Bans %= mod
#print (Aans,Bans)
#更新
if S - Slis[-1] >= B:
bitadd(loop+1,Aans,BITA)
else:
nowsum = bitsum(N+2,BITA)
bitadd(1,-1*nowsum,BITA)
bitadd(loop+1,Aans,BITA)
if S - Slis[-1] >= A:
bitadd(loop+1,Bans,BITB)
else:
nowsum = bitsum(N+2,BITB)
bitadd(1,-1*nowsum,BITB)
bitadd(loop+1,Bans,BITB)
Slis.append(S)
if len(Slis) >= 3 and Slis[-1] - Slis[-3] < min(A,B):
print (0)
sys.exit()
print ((bitsum(N+2,BITA) + bitsum(N+2,BITB))% mod)
``` | output | 1 | 84,913 | 22 | 169,827 |
Provide a correct Python 3 solution for this coding contest problem.
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 | instruction | 0 | 84,914 | 22 | 169,828 |
"Correct Solution:
```
import sys
readline = sys.stdin.readline
class Lazysegtree:
#RUQ
def __init__(self, A, intv, initialize = True, segf = min):
#区間は 1-indexed で管理
self.N = len(A)
self.N0 = 2**(self.N-1).bit_length()
self.intv = intv
self.segf = segf
self.lazy = [None]*(2*self.N0)
if initialize:
self.data = [intv]*self.N0 + A + [intv]*(self.N0 - self.N)
for i in range(self.N0-1, -1, -1):
self.data[i] = self.segf(self.data[2*i], self.data[2*i+1])
else:
self.data = [intv]*(2*self.N0)
def _ascend(self, k):
k = k >> 1
c = k.bit_length()
for j in range(c):
idx = k >> j
self.data[idx] = self.segf(self.data[2*idx], self.data[2*idx+1])
def _descend(self, k):
k = k >> 1
idx = 1
c = k.bit_length()
for j in range(1, c+1):
idx = k >> (c - j)
if self.lazy[idx] is None:
continue
self.data[2*idx] = self.data[2*idx+1] = self.lazy[2*idx] \
= self.lazy[2*idx+1] = self.lazy[idx]
self.lazy[idx] = None
def query(self, l, r):
L = l+self.N0
R = r+self.N0
self._descend(L//(L & -L))
self._descend(R//(R & -R)-1)
s = self.intv
while L < R:
if R & 1:
R -= 1
s = self.segf(s, self.data[R])
if L & 1:
s = self.segf(s, self.data[L])
L += 1
L >>= 1
R >>= 1
return s
def update(self, l, r, x):
L = l+self.N0
R = r+self.N0
Li = L//(L & -L)
Ri = R//(R & -R)
self._descend(Li)
self._descend(Ri-1)
while L < R :
if R & 1:
R -= 1
self.data[R] = x
self.lazy[R] = x
if L & 1:
self.data[L] = x
self.lazy[L] = x
L += 1
L >>= 1
R >>= 1
self._ascend(Li)
self._ascend(Ri-1)
inf = 10**19
N, A, B = map(int, readline().split())
S = [-inf] + [int(readline()) for _ in range(N)]
MOD = 10**9+7
dpa = Lazysegtree([1] + [0]*N, 0, initialize = True, segf = lambda x, y: (x+y)%MOD)
dpb = Lazysegtree([1] + [0]*N, 0, initialize = True, segf = lambda x, y: (x+y)%MOD)
for i in range(1, N+1):
oka = 0
ng = i
while abs(oka-ng) > 1:
med = (oka+ng)//2
if S[i] - S[med] >= A:
oka = med
else:
ng = med
okb = 0
ng = i
while abs(okb-ng) > 1:
med = (okb+ng)//2
if S[i] - S[med] >= B:
okb = med
else:
ng = med
tb = dpa.query(0, okb+1)
dpa.update(i-1, i, dpb.query(0, oka+1))
dpb.update(i-1, i, tb)
if S[i] - S[i-1] < A:
dpa.update(0, i-1, 0)
if S[i] - S[i-1] < B:
dpb.update(0, i-1, 0)
print((dpa.query(0, N+1) + dpb.query(0, N+1)) % MOD)
``` | output | 1 | 84,914 | 22 | 169,829 |
Provide a correct Python 3 solution for this coding contest problem.
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 | instruction | 0 | 84,915 | 22 | 169,830 |
"Correct Solution:
```
from bisect import bisect_left
N,A,B=map(int,input().split())
inf,mod=float("inf"),10**9+7
S=[int(input()) for i in range(N)]
St_A=[0]*N
St_B=[0]*N
J_A,J_B=[0],[0]
for i in range(N):
St_A[i]=bisect_left(S,S[i]+A)-1
St_B[i]=bisect_left(S,S[i]+B)-1
J_A.append(J_A[-1]+int(St_A[i]!=i))
J_B.append(J_B[-1]+int(St_B[i]!=i))
#print(St_A,St_B)
#print(J_A,J_B)
dp_A=[0]*N
dp_B=[0]*N
dp_A[-1],dp_B[-1]=1,1
for i in range(N-1)[::-1]:
if St_A[i]==i:
dp_A[i]=(dp_A[i+1]+dp_B[i+1])%mod
else:
if J_B[St_A[i]]-J_B[i+1]==0:
dp_A[i]=dp_B[St_A[i]]
else:
dp_A[i]=0
if St_B[i]==i:
dp_B[i]=(dp_A[i+1]+dp_B[i+1])%mod
else:
if J_A[St_B[i]]-J_A[i+1]==0:
dp_B[i]=dp_A[St_B[i]]
else:
dp_B[i]=0
#print(dp_A)
#print(dp_B)
print((dp_A[0]+dp_B[0])%mod)
``` | output | 1 | 84,915 | 22 | 169,831 |
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 bisect
input = sys.stdin.readline
class Bit:
def __init__(self,n):
self.size = n
self.tree = [0]*(n+1)
def sum(self,i):
s = 0
while i > 0:
s += self.tree[i]
i -= i & -i
return s
def add(self,i,x):
while i <= self.size:
self.tree[i] += x
i += i & -i
n,x,y = map(int,input().split())
a = [int(input()) for i in range(n)]
mod = 10**9+7
bsx = [0]*n
bsy = [0]*n
rowx = [0]*n
rowy = [0]*n
for i in range(n):
bsx[i] = bisect.bisect_right(a,a[i]-x)
bsy[i] = bisect.bisect_right(a,a[i]-y)
j = n-i-1
if j == 0:
continue
if a[j-1]+x <= a[j]:
rowx[j-1] += rowx[j]+1
else:
rowx[j-1] = 0
if a[j-1]+y <= a[j]:
rowy[j-1] += rowy[j]+1
else:
rowy[j-1] = 0
sm1 = [0 for i in range(n)]
sm2 = [0 for i in range(n)]
#sm1[i]: dp[i+1][i]
#sm2[i]: dp[i][i+1]
bit1 = Bit(n+2)
bit2 = Bit(n+2)
for i in range(n):
if i == 0:
sm1[i] = 1
sm2[i] = 1
else:
sm1[i] = bit2.sum(min(i,bsx[i]+1))%mod
sm2[i] = bit1.sum(min(i,bsy[i]+1))%mod
bit1.add(i+1,sm1[i])
bit1.add(i+rowx[i]+2,-sm1[i])
bit2.add(i+1,sm2[i])
bit2.add(i+rowy[i]+2,-sm2[i])
print(sm1[-1]+sm2[-1])
``` | instruction | 0 | 84,918 | 22 | 169,836 |
No | output | 1 | 84,918 | 22 | 169,837 |
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:
```
"""
https://atcoder.jp/contests/agc009/tasks/agc009_c
A <= B としてよい
dpだろうなぁ
dpA[i][X] = 1つ前を置いたのがBで、Aに置かれた最大がindexXの時の置き方
dpB[i][X] = 同様
if S[i]-S[i-1] >= B:
dpA[i][X] = dpA[i-1][X]
if X == i-1:
dpA[i][X] = ///
推移は、BITですればおk
もし差がB以下ならば→直前にBを置いていた場所に重ねおきはできない
→直前にAに置いていて、なおかつ最後にBに置いたのとの差がB以下の場合だけBにおける
→dpA[i][i-1]以外は0になる
"""
import sys
from sys import stdin
from collections import deque
def bitadd(a,w,bit): #aにwを加える(1-origin)
x = a
while x <= (len(bit)-1):
bit[x] += w
x += x & (-1 * x)
def bitsum(a,bit): #ind 1~aまでの和を求める
ret = 0
x = a
while x > 0:
ret += bit[x]
x -= x & (-1 * x)
return ret
N,A,B = map(int,stdin.readline().split())
mod = 10**9+7
BITA = [0] * (N+20)
BITB = [0] * (N+20)
bitadd(1,1,BITA)
#bitadd(0,1,BITB)
aq = deque([])
bq = deque([])
Slis = [float("-inf")]
for loop in range(N):
S = int(stdin.readline())
aq.append( (S,loop+2) )
bq.append( (S,loop+2) )
while aq[0][0] <= S-A:
aq.popleft()
while bq[0][0] <= S-B:
bq.popleft()
#dpAへの推移(Bに置く)
#Bに置けるのは、1つ前との差がB以上の場合全部おk
#そうでない場合、前にAにおいていて、かつ差がB以上の場合
#全てokの場合
if S - Slis[-1] >= B:
Aans = bitsum(N+2,BITB)
Aans %= mod
else: #そうでない場合→直前にAに置いていた場合のみ可能→bitをリセットする必要あり
Aans = bitsum(bq[0][1]-1,BITB)
Aans %= mod
if S - Slis[-1] >= A:
Bans = bitsum(N+2,BITA)
Bans %= mod
else:
Bans = bitsum(aq[0][1]-1,BITA)
Bans %= mod
if Aans < 0:
Aans = 0
if Bans < 0:
Bans = 0
#print (Aans,Bans)
#更新
if S - Slis[-1] >= B:
bitadd(loop+1,Aans,BITA)
else:
nowsum = bitsum(N+2,BITA)
bitadd(1,-1*nowsum,BITA)
bitadd(loop+1,Aans,BITA)
if S - Slis[-1] >= A:
bitadd(loop+1,Bans,BITB)
else:
nowsum = bitsum(N+2,BITB)
bitadd(1,-1*nowsum,BITB)
bitadd(loop+1,Bans,BITB)
Slis.append(S)
print ((bitsum(N+2,BITA) + bitsum(N+2,BITB))% mod)
``` | instruction | 0 | 84,919 | 22 | 169,838 |
No | output | 1 | 84,919 | 22 | 169,839 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a sequence of numbers a1, a2, ..., an, and a number m.
Check if it is possible to choose a non-empty subsequence aij such that the sum of numbers in this subsequence is divisible by m.
Input
The first line contains two numbers, n and m (1 ≤ n ≤ 106, 2 ≤ m ≤ 103) — the size of the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109).
Output
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
Examples
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
Note
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence. | instruction | 0 | 85,353 | 22 | 170,706 |
Tags: combinatorics, data structures, dp, two pointers
Correct Solution:
```
n, m = list(map(int, input().split()))
def intmodm(num):
return int(num) % m
a = list(map(intmodm, input().split()))
states = [[-1] * m]
# states[0][0] = 0
for index in range(n):
states.append(states[-1][:])
num = a[index]
for i in range(m):
if states[-2][i] != -1 and states[-1][(i + num) % m] == -1:
states[-1][(i + num) % m] = index
if states[-1][num % m] == -1:
states[-1][num % m] = index
# print(states)
if states[-1][0] != -1:
print("YES")
break
else:
print("NO")
``` | output | 1 | 85,353 | 22 | 170,707 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a sequence of numbers a1, a2, ..., an, and a number m.
Check if it is possible to choose a non-empty subsequence aij such that the sum of numbers in this subsequence is divisible by m.
Input
The first line contains two numbers, n and m (1 ≤ n ≤ 106, 2 ≤ m ≤ 103) — the size of the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109).
Output
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
Examples
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
Note
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence. | instruction | 0 | 85,354 | 22 | 170,708 |
Tags: combinatorics, data structures, dp, two pointers
Correct Solution:
```
import os
import sys
from io import BytesIO, IOBase
from collections import Counter
import math as mt
import inspect, re
def varname(p): # prints name of the variable
for line in inspect.getframeinfo(inspect.currentframe().f_back)[3]:
m = re.search(r'\bvarname\s*\(\s*([A-Za-z_][A-Za-z0-9_]*)\s*\)', line)
if m:
return m.group(1)
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)
def gcd(a, b):
if a == 0:
return b
return gcd(b % a, a)
def lcm(a, b):
return (a * b) / gcd(a, b)
mod = int(1e9) + 7
def power(k, n):
if n == 0:
return 1
if n % 2:
return (power(k, n - 1) * k) % mod
t = power(k, n // 2)
return (t * t) % mod
def totalPrimeFactors(n):
count = 0
if (n % 2) == 0:
count += 1
while (n % 2) == 0:
n //= 2
i = 3
while i * i <= n:
if (n % i) == 0:
count += 1
while (n % i) == 0:
n //= i
i += 2
if n > 2:
count += 1
return count
# #MAXN = int(1e7 + 1)
# # spf = [0 for i in range(MAXN)]
#
#
# def sieve():
# spf[1] = 1
# for i in range(2, MAXN):
# spf[i] = i
# for i in range(4, MAXN, 2):
# spf[i] = 2
#
# for i in range(3, mt.ceil(mt.sqrt(MAXN))):
# if (spf[i] == i):
# for j in range(i * i, MAXN, i):
# if (spf[j] == j):
# spf[j] = i
#
#
# def getFactorization(x):
# ret = 0
# while (x != 1):
# k = spf[x]
# ret += 1
# # ret.add(spf[x])
# while x % k == 0:
# x //= k
#
# return ret
# Driver code
# precalculating Smallest Prime Factor
# sieve()
def main():
n, m = map(int, input().split())
a = list(map(int, input().split()))
k = [0 for i in range(m)]
if m<n:
print('YES')
return
dp=[[0 for i in range(m)] for j in range(n)]
for i in range(n):
dp[i][a[i]%m]=1
if dp[0][0]:
print('YES')
return
for i in range(1, n):
for j in range(m):
if dp[i-1][j]:
dp[i][(a[i]+j)%m]=1
dp[i][j]=1
if dp[i][0]:
print('YES')
return
print('NO')
return
if __name__ == "__main__":
main()
``` | output | 1 | 85,354 | 22 | 170,709 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a sequence of numbers a1, a2, ..., an, and a number m.
Check if it is possible to choose a non-empty subsequence aij such that the sum of numbers in this subsequence is divisible by m.
Input
The first line contains two numbers, n and m (1 ≤ n ≤ 106, 2 ≤ m ≤ 103) — the size of the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109).
Output
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
Examples
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
Note
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence. | instruction | 0 | 85,355 | 22 | 170,710 |
Tags: combinatorics, data structures, dp, two pointers
Correct Solution:
```
numElementos, modulo = input().split()
numElementos = int(numElementos)
modulo = int(modulo)
modulos = []
for i in range(modulo):
modulos.append(False)
restantePossivel = []
for i in range(modulo + 1):
restantePossivel.append(modulos.copy())
ultimoElemento = min(numElementos, modulo)
elementos = input().split()
for i in range(1, ultimoElemento + 1, 1):
elementoI = int(elementos[i - 1])
for restante in range(0, modulo, 1):
if restantePossivel[i - 1][restante]:
restantePosAdd = (restante + elementoI) % modulo
restantePossivel[i][restantePosAdd] = True
restantePossivel[i][restante] = True
restantePossivel[i][elementoI % modulo] = True
if numElementos > modulo or restantePossivel[ultimoElemento][0]:
print('YES')
else:
print('NO')
'''
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
Input
4 7
1 2 3 3
Output
YES
Input
1 47
0
Output
YES
Input
2 47
1 0
Output
YES
'''
``` | output | 1 | 85,355 | 22 | 170,711 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a sequence of numbers a1, a2, ..., an, and a number m.
Check if it is possible to choose a non-empty subsequence aij such that the sum of numbers in this subsequence is divisible by m.
Input
The first line contains two numbers, n and m (1 ≤ n ≤ 106, 2 ≤ m ≤ 103) — the size of the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109).
Output
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
Examples
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
Note
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence. | instruction | 0 | 85,356 | 22 | 170,712 |
Tags: combinatorics, data structures, dp, two pointers
Correct Solution:
```
def modulus(arr, m, n):
for i in range(n):
arr[i] %= m
f = [0] * m
s = [0] * m
f[arr[0]] = 1
if f[0]:
return 1
for i in arr[1:]:
for j in range(m):
if f[j]:
s[j] = 1
elif i < j:
if f[j - i]:
s[j] = 1
elif i > j:
if f[j - i + m]:
s[j] = 1
else:
s[j] = 1
if s[0]:
return 1
f, s = s, f
return 0
n, m = map(int, input().split())
arr = list(map(int, input().split()))
print("YES") if modulus(arr, m, n) else print("NO")
``` | output | 1 | 85,356 | 22 | 170,713 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a sequence of numbers a1, a2, ..., an, and a number m.
Check if it is possible to choose a non-empty subsequence aij such that the sum of numbers in this subsequence is divisible by m.
Input
The first line contains two numbers, n and m (1 ≤ n ≤ 106, 2 ≤ m ≤ 103) — the size of the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109).
Output
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
Examples
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
Note
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence. | instruction | 0 | 85,357 | 22 | 170,714 |
Tags: combinatorics, data structures, dp, two pointers
Correct Solution:
```
num_elementos, modulo = [ int(x) for x in input().split() ]
modulos = [False] * modulo
restante_possivel = [ modulos.copy() for _ in range(modulo + 1) ]
ultimo_elemento = min(num_elementos, modulo)
elementos = input().split()
for i in range(1, ultimo_elemento + 1):
elemento = int(elementos[i - 1])
for restante in range(0, modulo):
if restante_possivel[i - 1][restante]:
restante_pos_add = (restante + elemento) % modulo
restante_possivel[i][restante_pos_add] = True
restante_possivel[i][restante] = True
restante_possivel[i][elemento % modulo] = True
if num_elementos > modulo or restante_possivel[ultimo_elemento][0]:
print('YES')
else:
print('NO')
``` | output | 1 | 85,357 | 22 | 170,715 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a sequence of numbers a1, a2, ..., an, and a number m.
Check if it is possible to choose a non-empty subsequence aij such that the sum of numbers in this subsequence is divisible by m.
Input
The first line contains two numbers, n and m (1 ≤ n ≤ 106, 2 ≤ m ≤ 103) — the size of the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109).
Output
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
Examples
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
Note
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence. | instruction | 0 | 85,358 | 22 | 170,716 |
Tags: combinatorics, data structures, dp, two pointers
Correct Solution:
```
__author__ = 'dwliv_000'
(n,m)=(int(i) for i in input().split())
c=[int(i)%m for i in input().split()]
z=[False]*m
for j in c:
q=z[:]
q[j]=True
for i in range(m):
if(z[i]):
q[(i+j)%m]=True
z=q[:]
if z[0]:
print('YES')
exit(0)
print('NO')
``` | output | 1 | 85,358 | 22 | 170,717 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a sequence of numbers a1, a2, ..., an, and a number m.
Check if it is possible to choose a non-empty subsequence aij such that the sum of numbers in this subsequence is divisible by m.
Input
The first line contains two numbers, n and m (1 ≤ n ≤ 106, 2 ≤ m ≤ 103) — the size of the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109).
Output
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
Examples
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
Note
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence. | instruction | 0 | 85,359 | 22 | 170,718 |
Tags: combinatorics, data structures, dp, two pointers
Correct Solution:
```
def main():
n, m = map(int, input().split())
l = [False] * m
l1 = l.copy()
for i in map(int, input().split()):
i %= m
l1[i] = True
for j, f in enumerate(l, i - m):
if f:
l1[j] = True
if l1[0]:
print("YES")
return
for j, f in enumerate(l1):
if f:
l[j] = True
print("NO")
if __name__ == '__main__':
main()
``` | output | 1 | 85,359 | 22 | 170,719 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a sequence of numbers a1, a2, ..., an, and a number m.
Check if it is possible to choose a non-empty subsequence aij such that the sum of numbers in this subsequence is divisible by m.
Input
The first line contains two numbers, n and m (1 ≤ n ≤ 106, 2 ≤ m ≤ 103) — the size of the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109).
Output
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
Examples
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
Note
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence. | instruction | 0 | 85,360 | 22 | 170,720 |
Tags: combinatorics, data structures, dp, two pointers
Correct Solution:
```
(n,m)=map(int,input().split())
if n>m:print("YES")
else:
t=[0 for i in range(m)]
s=input().split()
for i in range(len(s)):
h=int(s[i])%m
v=[0 for i in range(m)]
for j in range(m):
if t[j]==1:v[(h+j)%m]=1
for j in range(m):
if v[j]==1:t[j]=1
t[h]=1
if t[0]==1:print("YES")
else:print("NO")
``` | output | 1 | 85,360 | 22 | 170,721 |
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 of numbers a1, a2, ..., an, and a number m.
Check if it is possible to choose a non-empty subsequence aij such that the sum of numbers in this subsequence is divisible by m.
Input
The first line contains two numbers, n and m (1 ≤ n ≤ 106, 2 ≤ m ≤ 103) — the size of the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109).
Output
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
Examples
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
Note
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence.
Submitted Solution:
```
n, m = list(map(int, input().split()))
lst = list(map(int, input().split()))
if n > m:
print('YES')
else:
def rec(ps, sum, cnt):
if ps >= n:
if sum == 0 and cnt > 0:
return 1
else:
return 0
# print(lst[ps], sum)
if dp[ps][sum] != -1:
return dp[ps][sum]
dp[ps][sum] = rec(ps+1, (sum + lst[ps])%m, cnt+1) | rec(ps+1, sum, cnt)
return dp[ps][sum]
dp = [[-1 for _ in range(m+7)] for _ in range(n+7)]
if rec(0,0,0) == 1:
print('YES')
else:
print('NO')
``` | instruction | 0 | 85,363 | 22 | 170,726 |
Yes | output | 1 | 85,363 | 22 | 170,727 |
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 of numbers a1, a2, ..., an, and a number m.
Check if it is possible to choose a non-empty subsequence aij such that the sum of numbers in this subsequence is divisible by m.
Input
The first line contains two numbers, n and m (1 ≤ n ≤ 106, 2 ≤ m ≤ 103) — the size of the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109).
Output
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
Examples
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
Note
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence.
Submitted Solution:
```
from collections import *
n,k=map(int,input().split())
l=list(map(int,input().split()))
d=[0]*k
for i in l:
d[i%k]+=1
if(d[0]>0):
print('YES')
else:
f=0
for i in range(1,k):
if(d[i]>0 and d[i]%k==0):
f=1
break
elif(i!=k-i-1 and d[i]>0 and d[k-1-i]>0):
f=1
break
if(f==1):
print("YES")
else:
if(k%2==0):
if(d[k//2]>1):
print("YES")
else:
print("NO")
else:
print("NO")
``` | instruction | 0 | 85,365 | 22 | 170,730 |
No | output | 1 | 85,365 | 22 | 170,731 |
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 of numbers a1, a2, ..., an, and a number m.
Check if it is possible to choose a non-empty subsequence aij such that the sum of numbers in this subsequence is divisible by m.
Input
The first line contains two numbers, n and m (1 ≤ n ≤ 106, 2 ≤ m ≤ 103) — the size of the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109).
Output
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
Examples
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
Note
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence.
Submitted Solution:
```
from math import sqrt,gcd,ceil,floor,log,factorial
from itertools import permutations,combinations
from collections import Counter, defaultdict
def knapsack(n,m,a):
dp = [[0 for j in range(m+1)] for i in range(n+1)]
for i in range(n+1):
for j in range(m+1):
if i==0 and j==0:
dp[i][j]=1
continue
elif i==0:
continue
elif j==0:
dp[i][j]=1
continue
if j>=a[i-1]:
dp[i][j] = dp[i-1][j] or dp[i-1][j-a[i-1]]
else:
dp[i][j] = dp[i-1][j]
#print(dp)
return dp[n][m]
def lcm(a,b):
return (a*b)//gcd(a,b)
n,m = map(int,input().split())
a = list(map(int,input().split()))
mod = list(map(lambda x: x%m,a))
#print(*mod)
if 0 in mod:
print('YES')
else:
d=Counter(mod)
flag=0
for key in d:
if d[key]>=lcm(key,m)//key:
print('YES')
flag=1
break
if flag==0:
for i in range(1,m//2+1):
if m%2==0 and i==m//2:
if d[key]>1:
print('YES')
flag=1
break
else:
if d[m-key]>0:
print('YES')
flag=1
break
if flag==0:
mod.sort()
if knapsack(n,m,mod):
print('YES')
else:
print('NO')
``` | instruction | 0 | 85,367 | 22 | 170,734 |
No | output | 1 | 85,367 | 22 | 170,735 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Arpa has found a list containing n numbers. He calls a list bad if and only if it is not empty and gcd (see notes section for more information) of numbers in the list is 1.
Arpa can perform two types of operations:
* Choose a number and delete it with cost x.
* Choose a number and increase it by 1 with cost y.
Arpa can apply these operations to as many numbers as he wishes, and he is allowed to apply the second operation arbitrarily many times on the same number.
Help Arpa to find the minimum possible cost to make the list good.
Input
First line contains three integers n, x and y (1 ≤ n ≤ 5·105, 1 ≤ x, y ≤ 109) — the number of elements in the list and the integers x and y.
Second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the elements of the list.
Output
Print a single integer: the minimum possible cost to make the list good.
Examples
Input
4 23 17
1 17 17 16
Output
40
Input
10 6 2
100 49 71 73 66 96 8 60 41 63
Output
10
Note
In example, number 1 must be deleted (with cost 23) and number 16 must increased by 1 (with cost 17).
A gcd (greatest common divisor) of a set of numbers is the maximum integer that divides all integers in the set. Read more about gcd [here](https://en.wikipedia.org/wiki/Greatest_common_divisor).
Submitted Solution:
```
import sys
import math
lines = sys.stdin.read().splitlines()
n, x, y = [int(x) for x in lines[0].split()]
numbers = [int(x) for x in lines[1].split()]
def getPrimes(n):
primes = [2]
for i in range(3, n+1, 2):
prime = True
for p in primes:
if i % p == 0:
prime = False
break
if not prime:
continue
yield i
primes.append(i)
minCost = x*n
baseCost = 0
maxElem = max(numbers)
# primes = getPrimes(maxElem+1)
for p in getPrimes(maxElem+1):
if baseCost > minCost:
break
# print(p)
totalcost = 0
for n in numbers:
xcost = x
ycost = ((p-n%p)%p)*y
if n < p and ycost > xcost:
numbers.remove(n)
baseCost += xcost
totalcost += min(xcost, ycost)
if totalcost+baseCost> minCost:
continue
if totalcost+baseCost < minCost:
minCost = totalcost+baseCost
print(minCost)
``` | instruction | 0 | 85,441 | 22 | 170,882 |
No | output | 1 | 85,441 | 22 | 170,883 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Arpa has found a list containing n numbers. He calls a list bad if and only if it is not empty and gcd (see notes section for more information) of numbers in the list is 1.
Arpa can perform two types of operations:
* Choose a number and delete it with cost x.
* Choose a number and increase it by 1 with cost y.
Arpa can apply these operations to as many numbers as he wishes, and he is allowed to apply the second operation arbitrarily many times on the same number.
Help Arpa to find the minimum possible cost to make the list good.
Input
First line contains three integers n, x and y (1 ≤ n ≤ 5·105, 1 ≤ x, y ≤ 109) — the number of elements in the list and the integers x and y.
Second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the elements of the list.
Output
Print a single integer: the minimum possible cost to make the list good.
Examples
Input
4 23 17
1 17 17 16
Output
40
Input
10 6 2
100 49 71 73 66 96 8 60 41 63
Output
10
Note
In example, number 1 must be deleted (with cost 23) and number 16 must increased by 1 (with cost 17).
A gcd (greatest common divisor) of a set of numbers is the maximum integer that divides all integers in the set. Read more about gcd [here](https://en.wikipedia.org/wiki/Greatest_common_divisor).
Submitted Solution:
```
import sys
import math
lines = sys.stdin.read().splitlines()
n, x, y = [int(x) for x in lines[0].split()]
numbers = [int(x) for x in lines[1].split()]
def getPrimes(n):
primes = [2]
for i in range(3, n+1, 2):
prime = True
for p in primes:
if i % p == 0:
prime = False
break
if not prime:
continue
primes.append(i)
return primes
minCost = x*n
baseCost = 0
maxElem = max(numbers)
primes = getPrimes(maxElem+1)
for p in primes:
# print(p)
totalcost = 0
for n in numbers:
xcost = x
ycost = ((p-n%p)%p)*y
if n < p and ycost > xcost:
numbers.remove(n)
baseCost += xcost
totalcost += min(xcost, ycost)
if totalcost +baseCost> minCost:
continue
if totalcost+baseCost < minCost:
minCost = totalcost
print(minCost)
``` | instruction | 0 | 85,442 | 22 | 170,884 |
No | output | 1 | 85,442 | 22 | 170,885 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Arpa has found a list containing n numbers. He calls a list bad if and only if it is not empty and gcd (see notes section for more information) of numbers in the list is 1.
Arpa can perform two types of operations:
* Choose a number and delete it with cost x.
* Choose a number and increase it by 1 with cost y.
Arpa can apply these operations to as many numbers as he wishes, and he is allowed to apply the second operation arbitrarily many times on the same number.
Help Arpa to find the minimum possible cost to make the list good.
Input
First line contains three integers n, x and y (1 ≤ n ≤ 5·105, 1 ≤ x, y ≤ 109) — the number of elements in the list and the integers x and y.
Second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the elements of the list.
Output
Print a single integer: the minimum possible cost to make the list good.
Examples
Input
4 23 17
1 17 17 16
Output
40
Input
10 6 2
100 49 71 73 66 96 8 60 41 63
Output
10
Note
In example, number 1 must be deleted (with cost 23) and number 16 must increased by 1 (with cost 17).
A gcd (greatest common divisor) of a set of numbers is the maximum integer that divides all integers in the set. Read more about gcd [here](https://en.wikipedia.org/wiki/Greatest_common_divisor).
Submitted Solution:
```
def gcd(a):
result = a[0]
for x in a[1:]:
if result < x:
temp = result
result = x
x = temp
while x != 0:
temp = x
x = result % x
result = temp
return result
def transformCost(num, divisor, x, y):
incrementCost = 0
while num % divisor != 0:
incrementCost += y
num += 1
return min(x, incrementCost)
def solveCase(a, n, x, y):
aCopy = a.copy()
minCost = 99999999
for divisor in range(2, max(a)+1):
cost = 0
for elem in a:
cost += transformCost(elem, divisor, x, y)
print(cost)
minCost = min(minCost, cost)
print(minCost)
def main():
[n, x, y] = [int(i) for i in input().split(' ')]
a = [int(i) for i in input().split(' ')]
solveCase(a, n, x, y)
main()
``` | instruction | 0 | 85,443 | 22 | 170,886 |
No | output | 1 | 85,443 | 22 | 170,887 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Arpa has found a list containing n numbers. He calls a list bad if and only if it is not empty and gcd (see notes section for more information) of numbers in the list is 1.
Arpa can perform two types of operations:
* Choose a number and delete it with cost x.
* Choose a number and increase it by 1 with cost y.
Arpa can apply these operations to as many numbers as he wishes, and he is allowed to apply the second operation arbitrarily many times on the same number.
Help Arpa to find the minimum possible cost to make the list good.
Input
First line contains three integers n, x and y (1 ≤ n ≤ 5·105, 1 ≤ x, y ≤ 109) — the number of elements in the list and the integers x and y.
Second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the elements of the list.
Output
Print a single integer: the minimum possible cost to make the list good.
Examples
Input
4 23 17
1 17 17 16
Output
40
Input
10 6 2
100 49 71 73 66 96 8 60 41 63
Output
10
Note
In example, number 1 must be deleted (with cost 23) and number 16 must increased by 1 (with cost 17).
A gcd (greatest common divisor) of a set of numbers is the maximum integer that divides all integers in the set. Read more about gcd [here](https://en.wikipedia.org/wiki/Greatest_common_divisor).
Submitted Solution:
```
# ------------------- fast io --------------------
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")
# ------------------- fast io --------------------
from math import gcd, ceil
def prod(a, mod=10**9+7):
ans = 1
for each in a:
ans = (ans * each) % mod
return ans
def lcm(a, b): return a * b // gcd(a, b)
def binary(x, length=16):
y = bin(x)[2:]
return y if len(y) >= length else "0" * (length - len(y)) + y
from math import inf
for _ in range(int(input()) if not True else 1):
n, x, y = map(int, input().split())
#c, d = map(int, input().split())
a = list(map(int, input().split()))
#b = list(map(int, input().split()))
#s = input()
count = [0]*(10**6 + 69)
rangesum = [0]*(10**6 + 69)
cnt = [0]*(10**6 + 69)
for i in a:
cnt[i] += 1
for i in range(1, 10**6 + 1):
count[i] = count[i-1] + cnt[i]
rangesum[i] = rangesum[i-1] + i * cnt[i]
ans = inf
for g in range(2, 10**6 + 1):
# making gcd of all numbers = g
total = 0
for mult in range(g, 10**6+1, g):
if x <= y:
total += x*(count[mult-1] - count[mult-g])
else:
p = min(x//y, g-1)
total += y * ((count[mult-1]-count[mult-p-1])*mult - (rangesum[mult-1]-rangesum[mult-p-1])) + x * (count[mult-p-1] - count[mult-g])
#total += y * (count.query(mult-p, mult-1) * mult - rangesum.query(mult-p, mult-1)) + \
# x * (count.query(mult-g+1, mult-p-1))
ans = min(ans, total)
print(ans)
``` | instruction | 0 | 85,444 | 22 | 170,888 |
No | output | 1 | 85,444 | 22 | 170,889 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alice and Bob begin their day with a quick game. They first choose a starting number X0 ≥ 3 and try to reach one million by the process described below.
Alice goes first and then they take alternating turns. In the i-th turn, the player whose turn it is selects a prime number smaller than the current number, and announces the smallest multiple of this prime number that is not smaller than the current number.
Formally, he or she selects a prime p < Xi - 1 and then finds the minimum Xi ≥ Xi - 1 such that p divides Xi. Note that if the selected prime p already divides Xi - 1, then the number does not change.
Eve has witnessed the state of the game after two turns. Given X2, help her determine what is the smallest possible starting number X0. Note that the players don't necessarily play optimally. You should consider all possible game evolutions.
Input
The input contains a single integer X2 (4 ≤ X2 ≤ 106). It is guaranteed that the integer X2 is composite, that is, is not prime.
Output
Output a single integer — the minimum possible X0.
Examples
Input
14
Output
6
Input
20
Output
15
Input
8192
Output
8191
Note
In the first test, the smallest possible starting number is X0 = 6. One possible course of the game is as follows:
* Alice picks prime 5 and announces X1 = 10
* Bob picks prime 7 and announces X2 = 14.
In the second case, let X0 = 15.
* Alice picks prime 2 and announces X1 = 16
* Bob picks prime 5 and announces X2 = 20. | instruction | 0 | 85,477 | 22 | 170,954 |
Tags: math, number theory
Correct Solution:
```
from math import sqrt
import sys
# from io import StringIO
#
# sys.stdin = StringIO(open(__file__.replace('.py', '.in')).read())
def largest_prime_factor(n):
for i in range(2, int(sqrt(n) + 1)):
if n % i == 0:
return largest_prime_factor(n // i)
return n
x2 = int(input())
p2 = largest_prime_factor(x2)
m = sys.maxsize
for x1 in range(x2 - p2 + 1, x2 + 1):
p1 = largest_prime_factor(x1)
if p1 != x1 and m > x1 - p1 + 1:
m = x1 - p1 + 1
print(m)
``` | output | 1 | 85,477 | 22 | 170,955 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alice and Bob begin their day with a quick game. They first choose a starting number X0 ≥ 3 and try to reach one million by the process described below.
Alice goes first and then they take alternating turns. In the i-th turn, the player whose turn it is selects a prime number smaller than the current number, and announces the smallest multiple of this prime number that is not smaller than the current number.
Formally, he or she selects a prime p < Xi - 1 and then finds the minimum Xi ≥ Xi - 1 such that p divides Xi. Note that if the selected prime p already divides Xi - 1, then the number does not change.
Eve has witnessed the state of the game after two turns. Given X2, help her determine what is the smallest possible starting number X0. Note that the players don't necessarily play optimally. You should consider all possible game evolutions.
Input
The input contains a single integer X2 (4 ≤ X2 ≤ 106). It is guaranteed that the integer X2 is composite, that is, is not prime.
Output
Output a single integer — the minimum possible X0.
Examples
Input
14
Output
6
Input
20
Output
15
Input
8192
Output
8191
Note
In the first test, the smallest possible starting number is X0 = 6. One possible course of the game is as follows:
* Alice picks prime 5 and announces X1 = 10
* Bob picks prime 7 and announces X2 = 14.
In the second case, let X0 = 15.
* Alice picks prime 2 and announces X1 = 16
* Bob picks prime 5 and announces X2 = 20. | instruction | 0 | 85,478 | 22 | 170,956 |
Tags: math, number theory
Correct Solution:
```
# -*- coding: utf - 8 -*-
"""""""""""""""""""""""""""""""""""""""""""""
| author: mr.math - Hakimov Rahimjon |
| e-mail: mr.math0777@gmail.com |
| created: 10.03.2018 20:50 |
"""""""""""""""""""""""""""""""""""""""""""""
# inp = open("input.txt", "r"); input = inp.readline; out = open("output.txt", "w"); print = out.write
TN = 1
# ===========================================
def resheto(l, k, n):
i=0
while i<len(l):
if l[i]%k == 0: l=l[:i]+l[i+1:]
i+=1
lst = []
for i in l:
if n % i == 0: lst.append(i)
return lst
# ===========================================
def solution():
x2 = int(input())
n = 1000001
max_prime = [0] * n
s = list(range(n))
s[1] = 0
for i in s:
if i > 1 and s[i]:
for j in range(2 * i, n, i):
s[j] = 0
max_prime[j] = i
min_x0 = n
for x in range(x2 - max_prime[x2] + 1, x2 + 1):
max_div = max_prime[x]
tmp = x - max_div + 1
if max_div and tmp < min_x0:
min_x0 = tmp
print(min_x0)
# ===========================================
while TN != 0:
solution()
TN -= 1
# ===========================================
# inp.close()
# out.close()
``` | output | 1 | 85,478 | 22 | 170,957 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given q queries in the following form:
Given three integers l_i, r_i and d_i, find minimum positive integer x_i such that it is divisible by d_i and it does not belong to the segment [l_i, r_i].
Can you answer all the queries?
Recall that a number x belongs to segment [l, r] if l ≤ x ≤ r.
Input
The first line contains one integer q (1 ≤ q ≤ 500) — the number of queries.
Then q lines follow, each containing a query given in the format l_i r_i d_i (1 ≤ l_i ≤ r_i ≤ 10^9, 1 ≤ d_i ≤ 10^9). l_i, r_i and d_i are integers.
Output
For each query print one integer: the answer to this query.
Example
Input
5
2 4 2
5 10 4
3 10 1
1 2 3
4 6 5
Output
6
4
1
3
10 | instruction | 0 | 85,741 | 22 | 171,482 |
Tags: math
Correct Solution:
```
n = int(input())
for i in range(n):
a = list(map(int,input().split(" ")))
if a[1] >= a[2] >= a[0] or a[0] >= a[2] >= a[1]:
if a[1] > a[0]:
a[0],a[1] = a[1], a[0]
print(a[0]//a[2]*a[2]+a[2])
else:
print(a[2])
``` | output | 1 | 85,741 | 22 | 171,483 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given q queries in the following form:
Given three integers l_i, r_i and d_i, find minimum positive integer x_i such that it is divisible by d_i and it does not belong to the segment [l_i, r_i].
Can you answer all the queries?
Recall that a number x belongs to segment [l, r] if l ≤ x ≤ r.
Input
The first line contains one integer q (1 ≤ q ≤ 500) — the number of queries.
Then q lines follow, each containing a query given in the format l_i r_i d_i (1 ≤ l_i ≤ r_i ≤ 10^9, 1 ≤ d_i ≤ 10^9). l_i, r_i and d_i are integers.
Output
For each query print one integer: the answer to this query.
Example
Input
5
2 4 2
5 10 4
3 10 1
1 2 3
4 6 5
Output
6
4
1
3
10 | instruction | 0 | 85,742 | 22 | 171,484 |
Tags: math
Correct Solution:
```
def f(l, r, d):
if d>r:
return d
for i in range(d,l,d):
if i%d ==0:
return i
return (int(r/d)+1)*d
n = int(input())
for i in range(n):
row = input().split(' ')
l = int(row[0])
r = int(row[1])
d = int(row[2])
print(str(int(f(l,r,d))))
``` | output | 1 | 85,742 | 22 | 171,485 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given q queries in the following form:
Given three integers l_i, r_i and d_i, find minimum positive integer x_i such that it is divisible by d_i and it does not belong to the segment [l_i, r_i].
Can you answer all the queries?
Recall that a number x belongs to segment [l, r] if l ≤ x ≤ r.
Input
The first line contains one integer q (1 ≤ q ≤ 500) — the number of queries.
Then q lines follow, each containing a query given in the format l_i r_i d_i (1 ≤ l_i ≤ r_i ≤ 10^9, 1 ≤ d_i ≤ 10^9). l_i, r_i and d_i are integers.
Output
For each query print one integer: the answer to this query.
Example
Input
5
2 4 2
5 10 4
3 10 1
1 2 3
4 6 5
Output
6
4
1
3
10 | instruction | 0 | 85,743 | 22 | 171,486 |
Tags: math
Correct Solution:
```
test_cases = int(input())
for i in range(test_cases) :
left, right, divisor = map(int, input().split(" "))
if divisor < left :
print(divisor)
else :
print(divisor * ((right // divisor) + 1))
``` | output | 1 | 85,743 | 22 | 171,487 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.