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.
Ivan has number b. He is sorting through the numbers a from 1 to 10^{18}, and for every a writes ([a, b])/(a) on blackboard. Here [a, b] stands for least common multiple of a and b. Ivan is very lazy, that's why this task bored him soon. But he is interested in how many different numbers he would write on the board if he would finish the task. Help him to find the quantity of different numbers he would write on the board.
Input
The only line contains one integer β b (1 β€ b β€ 10^{10}).
Output
Print one number β answer for the problem.
Examples
Input
1
Output
1
Input
2
Output
2
Note
In the first example [a, 1] = a, therefore ([a, b])/(a) is always equal to 1.
In the second example [a, 2] can be equal to a or 2 β
a depending on parity of a. ([a, b])/(a) can be equal to 1 and 2. | instruction | 0 | 90,953 | 22 | 181,906 |
Tags: math, number theory
Correct Solution:
```
b=int(input())
import math
def cd(n) :
cnt = 0
for i in range(1, (int)(math.sqrt(n)) + 1) :
if (n % i == 0) :
# If divisors are equal,
# count only one
if (n / i == i) :
cnt = cnt + 1
else : # Otherwise count both
cnt = cnt + 2
return cnt
print(cd(b))
``` | output | 1 | 90,953 | 22 | 181,907 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ivan has number b. He is sorting through the numbers a from 1 to 10^{18}, and for every a writes ([a, b])/(a) on blackboard. Here [a, b] stands for least common multiple of a and b. Ivan is very lazy, that's why this task bored him soon. But he is interested in how many different numbers he would write on the board if he would finish the task. Help him to find the quantity of different numbers he would write on the board.
Input
The only line contains one integer β b (1 β€ b β€ 10^{10}).
Output
Print one number β answer for the problem.
Examples
Input
1
Output
1
Input
2
Output
2
Note
In the first example [a, 1] = a, therefore ([a, b])/(a) is always equal to 1.
In the second example [a, 2] can be equal to a or 2 β
a depending on parity of a. ([a, b])/(a) can be equal to 1 and 2. | instruction | 0 | 90,954 | 22 | 181,908 |
Tags: math, number theory
Correct Solution:
```
def prime(b):
i = 1
if b == 1:
return 1
count = 0
while i * i <= b:
if b % i == 0:
if i * i != b:
count += 2
else:
count += 1
i += 1
return count
b = int(input())
print(prime(b))
``` | output | 1 | 90,954 | 22 | 181,909 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ivan has number b. He is sorting through the numbers a from 1 to 10^{18}, and for every a writes ([a, b])/(a) on blackboard. Here [a, b] stands for least common multiple of a and b. Ivan is very lazy, that's why this task bored him soon. But he is interested in how many different numbers he would write on the board if he would finish the task. Help him to find the quantity of different numbers he would write on the board.
Input
The only line contains one integer β b (1 β€ b β€ 10^{10}).
Output
Print one number β answer for the problem.
Examples
Input
1
Output
1
Input
2
Output
2
Note
In the first example [a, 1] = a, therefore ([a, b])/(a) is always equal to 1.
In the second example [a, 2] can be equal to a or 2 β
a depending on parity of a. ([a, b])/(a) can be equal to 1 and 2. | instruction | 0 | 90,957 | 22 | 181,914 |
Tags: math, number theory
Correct Solution:
```
def divisors(n):
divisior = 0
for i in range(1,int(n**0.5)+1):
if n%i==0:
if n/i==i:
divisior+=1
else:
divisior+=2
return divisior
print (divisors(int(input())))
``` | output | 1 | 90,957 | 22 | 181,915 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Suppose you have two polynomials <image> and <image>. Then polynomial <image> can be uniquely represented in the following way:
<image>
This can be done using [long division](https://en.wikipedia.org/wiki/Polynomial_long_division). Here, <image> denotes the degree of polynomial P(x). <image> is called the remainder of division of polynomial <image> by polynomial <image>, it is also denoted as <image>.
Since there is a way to divide polynomials with remainder, we can define Euclid's algorithm of finding the greatest common divisor of two polynomials. The algorithm takes two polynomials <image>. If the polynomial <image> is zero, the result is <image>, otherwise the result is the value the algorithm returns for pair <image>. On each step the degree of the second argument decreases, so the algorithm works in finite number of steps. But how large that number could be? You are to answer this question.
You are given an integer n. You have to build two polynomials with degrees not greater than n, such that their coefficients are integers not exceeding 1 by their absolute value, the leading coefficients (ones with the greatest power of x) are equal to one, and the described Euclid's algorithm performs exactly n steps finding their greatest common divisor. Moreover, the degree of the first polynomial should be greater than the degree of the second. By a step of the algorithm we mean the transition from pair <image> to pair <image>.
Input
You are given a single integer n (1 β€ n β€ 150) β the number of steps of the algorithm you need to reach.
Output
Print two polynomials in the following format.
In the first line print a single integer m (0 β€ m β€ n) β the degree of the polynomial.
In the second line print m + 1 integers between - 1 and 1 β the coefficients of the polynomial, from constant to leading.
The degree of the first polynomial should be greater than the degree of the second polynomial, the leading coefficients should be equal to 1. Euclid's algorithm should perform exactly n steps when called using these polynomials.
If there is no answer for the given n, print -1.
If there are multiple answer, print any of them.
Examples
Input
1
Output
1
0 1
0
1
Input
2
Output
2
-1 0 1
1
0 1
Note
In the second example you can print polynomials x2 - 1 and x. The sequence of transitions is
(x2 - 1, x) β (x, - 1) β ( - 1, 0).
There are two steps in it. | instruction | 0 | 91,382 | 22 | 182,764 |
Tags: constructive algorithms, math
Correct Solution:
```
from random import getrandbits as R
rb=lambda:R(1)
def modu(p,q):
if len(q)==1:
return [0]
p=p[:]
for d in range(len(p)-1,len(q)-2,-1):
#print(d)
a = p.pop()
b = q[-1]
B = [-k*a/b for k in q[:-1]]
#print(B)
for i in range(len(B)):
p[i+1+len(p)-1-(len(q)-1)] += B[i]
while len(p)>1 and abs(p[-1])<1E-6:
p.pop()
return p
def gcd(p,q):
#print(p,q)
if len(q)==1 and abs(q[0])<1E-6:
return p,1
#if len(q)<=1:
# return q,1
else:
p,iters = gcd(q,modu(p,q))
return p,iters+1
#p,iters = gcd([5,3,2],[-10,1])
#print(p,iters)
#q,iters = gcd([2,5,4,1],[3,4,1])
#print(q,iters)
for n in [int(input())]:#range(150,0,-1):
while True:
p = [1]*(n+1)
q = [1]*(n)
for i in range(n):
p[i]=rb()
for i in range(n-1):
q[i]=rb()
Q,iters = gcd(p,q)
if iters<n+1:
continue
#print(Q,iters)
print(len(p)-1)
print(*p)
print(len(q)-1)
print(*q)
break
``` | output | 1 | 91,382 | 22 | 182,765 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Suppose you have two polynomials <image> and <image>. Then polynomial <image> can be uniquely represented in the following way:
<image>
This can be done using [long division](https://en.wikipedia.org/wiki/Polynomial_long_division). Here, <image> denotes the degree of polynomial P(x). <image> is called the remainder of division of polynomial <image> by polynomial <image>, it is also denoted as <image>.
Since there is a way to divide polynomials with remainder, we can define Euclid's algorithm of finding the greatest common divisor of two polynomials. The algorithm takes two polynomials <image>. If the polynomial <image> is zero, the result is <image>, otherwise the result is the value the algorithm returns for pair <image>. On each step the degree of the second argument decreases, so the algorithm works in finite number of steps. But how large that number could be? You are to answer this question.
You are given an integer n. You have to build two polynomials with degrees not greater than n, such that their coefficients are integers not exceeding 1 by their absolute value, the leading coefficients (ones with the greatest power of x) are equal to one, and the described Euclid's algorithm performs exactly n steps finding their greatest common divisor. Moreover, the degree of the first polynomial should be greater than the degree of the second. By a step of the algorithm we mean the transition from pair <image> to pair <image>.
Input
You are given a single integer n (1 β€ n β€ 150) β the number of steps of the algorithm you need to reach.
Output
Print two polynomials in the following format.
In the first line print a single integer m (0 β€ m β€ n) β the degree of the polynomial.
In the second line print m + 1 integers between - 1 and 1 β the coefficients of the polynomial, from constant to leading.
The degree of the first polynomial should be greater than the degree of the second polynomial, the leading coefficients should be equal to 1. Euclid's algorithm should perform exactly n steps when called using these polynomials.
If there is no answer for the given n, print -1.
If there are multiple answer, print any of them.
Examples
Input
1
Output
1
0 1
0
1
Input
2
Output
2
-1 0 1
1
0 1
Note
In the second example you can print polynomials x2 - 1 and x. The sequence of transitions is
(x2 - 1, x) β (x, - 1) β ( - 1, 0).
There are two steps in it. | instruction | 0 | 91,383 | 22 | 182,766 |
Tags: constructive algorithms, math
Correct Solution:
```
a_coeffs = [1, 0, -1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, -1, 0, 1, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, -1, 0, 1, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, -1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, -1, 0, 1, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 1, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, -1, 0, 1, 0, -1, 0, 0, 0, 1]
b_coeffs = [1, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, -1, 0]
def rem(a, b):
assert len(a) == len(b) + 1
coeff = a[0] * b[0]
if a[0] == -1:
a = [-c for c in a]
if b[0] == -1:
b = [-c for c in b]
b = b + [0]
assert len(a) == len(b)
r = [c1 - c2 for (c1, c2) in zip(a, b)]
assert r[0] == 0 and r[1] == 0 and r[2] != 0
r = r[2:]
r = [coeff * c for c in r]
return r
def solve(n):
a, b = a_coeffs, b_coeffs
for _ in range(n, 150):
a, b = b, rem(a, b)
if a[0] == -1:
a = [-c for c in a]
if b[0] == -1:
b = [-c for c in b]
return a, b
n = int(input())
a, b = solve(n)
print(len(a) - 1)
print(' '.join(str(c) for c in reversed(a)))
print(len(b) - 1)
print(' '.join(str(c) for c in reversed(b)))
``` | output | 1 | 91,383 | 22 | 182,767 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Suppose you have two polynomials <image> and <image>. Then polynomial <image> can be uniquely represented in the following way:
<image>
This can be done using [long division](https://en.wikipedia.org/wiki/Polynomial_long_division). Here, <image> denotes the degree of polynomial P(x). <image> is called the remainder of division of polynomial <image> by polynomial <image>, it is also denoted as <image>.
Since there is a way to divide polynomials with remainder, we can define Euclid's algorithm of finding the greatest common divisor of two polynomials. The algorithm takes two polynomials <image>. If the polynomial <image> is zero, the result is <image>, otherwise the result is the value the algorithm returns for pair <image>. On each step the degree of the second argument decreases, so the algorithm works in finite number of steps. But how large that number could be? You are to answer this question.
You are given an integer n. You have to build two polynomials with degrees not greater than n, such that their coefficients are integers not exceeding 1 by their absolute value, the leading coefficients (ones with the greatest power of x) are equal to one, and the described Euclid's algorithm performs exactly n steps finding their greatest common divisor. Moreover, the degree of the first polynomial should be greater than the degree of the second. By a step of the algorithm we mean the transition from pair <image> to pair <image>.
Input
You are given a single integer n (1 β€ n β€ 150) β the number of steps of the algorithm you need to reach.
Output
Print two polynomials in the following format.
In the first line print a single integer m (0 β€ m β€ n) β the degree of the polynomial.
In the second line print m + 1 integers between - 1 and 1 β the coefficients of the polynomial, from constant to leading.
The degree of the first polynomial should be greater than the degree of the second polynomial, the leading coefficients should be equal to 1. Euclid's algorithm should perform exactly n steps when called using these polynomials.
If there is no answer for the given n, print -1.
If there are multiple answer, print any of them.
Examples
Input
1
Output
1
0 1
0
1
Input
2
Output
2
-1 0 1
1
0 1
Note
In the second example you can print polynomials x2 - 1 and x. The sequence of transitions is
(x2 - 1, x) β (x, - 1) β ( - 1, 0).
There are two steps in it. | instruction | 0 | 91,384 | 22 | 182,768 |
Tags: constructive algorithms, math
Correct Solution:
```
"""
NTC here
"""
import sys
inp= sys.stdin.readline
input = lambda : inp().strip()
flush= sys.stdout.flush
# import threading
# sys.setrecursionlimit(10**6)
# threading.stack_size(2**25)
def iin(): return int(input())
def lin(): return list(map(int, input().split()))
# range = xrange
# input = raw_input
def main():
n = iin()
ans = [0]*(n+1)
ans[0]=1
ans1 = [0]*(n+1)
sol = 0
# print(ans, ans1)
for i in range(n):
su = ans1[:]
for j in range(n):
su[j+1]+=ans[j]
if su[j+1]>1:su[j+1]=0
# print(1, su, ans)
ans, ans1= su, ans
# print(ans, ans1, mx)
if sol:
print(-1)
else:
m1, m2=0, 0
for i in range(n+1):
if abs(ans[i]):
m1 = i+1
if abs(ans1[i]):
m2 = i+1
print(m1-1)
print( *ans[:m1])
print( m2-1)
print( *ans1[:m2])
main()
# threading.Thread(target=main).start()
``` | output | 1 | 91,384 | 22 | 182,769 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Suppose you have two polynomials <image> and <image>. Then polynomial <image> can be uniquely represented in the following way:
<image>
This can be done using [long division](https://en.wikipedia.org/wiki/Polynomial_long_division). Here, <image> denotes the degree of polynomial P(x). <image> is called the remainder of division of polynomial <image> by polynomial <image>, it is also denoted as <image>.
Since there is a way to divide polynomials with remainder, we can define Euclid's algorithm of finding the greatest common divisor of two polynomials. The algorithm takes two polynomials <image>. If the polynomial <image> is zero, the result is <image>, otherwise the result is the value the algorithm returns for pair <image>. On each step the degree of the second argument decreases, so the algorithm works in finite number of steps. But how large that number could be? You are to answer this question.
You are given an integer n. You have to build two polynomials with degrees not greater than n, such that their coefficients are integers not exceeding 1 by their absolute value, the leading coefficients (ones with the greatest power of x) are equal to one, and the described Euclid's algorithm performs exactly n steps finding their greatest common divisor. Moreover, the degree of the first polynomial should be greater than the degree of the second. By a step of the algorithm we mean the transition from pair <image> to pair <image>.
Input
You are given a single integer n (1 β€ n β€ 150) β the number of steps of the algorithm you need to reach.
Output
Print two polynomials in the following format.
In the first line print a single integer m (0 β€ m β€ n) β the degree of the polynomial.
In the second line print m + 1 integers between - 1 and 1 β the coefficients of the polynomial, from constant to leading.
The degree of the first polynomial should be greater than the degree of the second polynomial, the leading coefficients should be equal to 1. Euclid's algorithm should perform exactly n steps when called using these polynomials.
If there is no answer for the given n, print -1.
If there are multiple answer, print any of them.
Examples
Input
1
Output
1
0 1
0
1
Input
2
Output
2
-1 0 1
1
0 1
Note
In the second example you can print polynomials x2 - 1 and x. The sequence of transitions is
(x2 - 1, x) β (x, - 1) β ( - 1, 0).
There are two steps in it. | instruction | 0 | 91,385 | 22 | 182,770 |
Tags: constructive algorithms, math
Correct Solution:
```
def divisors(M):
d=[]
i=1
while M>=i**2:
if M%i==0:
d.append(i)
if i**2!=M:
d.append(M//i)
i=i+1
return d
def popcount(x):
x = x - ((x >> 1) & 0x55555555)
x = (x & 0x33333333) + ((x >> 2) & 0x33333333)
x = (x + (x >> 4)) & 0x0f0f0f0f
x = x + (x >> 8)
x = x + (x >> 16)
return x & 0x0000007f
def eratosthenes(n):
res=[0 for i in range(n+1)]
prime=set([])
for i in range(2,n+1):
if not res[i]:
prime.add(i)
for j in range(1,n//i+1):
res[i*j]=1
return prime
def factorization(n):
res=[]
for p in prime:
if n%p==0:
while n%p==0:
n//=p
res.append(p)
if n!=1:
res.append(n)
return res
def euler_phi(n):
res = n
for x in range(2,n+1):
if x ** 2 > n:
break
if n%x==0:
res = res//x * (x-1)
while n%x==0:
n //= x
if n!=1:
res = res//n * (n-1)
return res
def ind(b,n):
res=0
while n%b==0:
res+=1
n//=b
return res
def isPrimeMR(n):
d = n - 1
d = d // (d & -d)
L = [2, 3, 5, 7, 11, 13, 17]
for a in L:
t = d
y = pow(a, t, n)
if y == 1: continue
while y != n - 1:
y = (y * y) % n
if y == 1 or t == n - 1: return 0
t <<= 1
return 1
def findFactorRho(n):
from math import gcd
m = 1 << n.bit_length() // 8
for c in range(1, 99):
f = lambda x: (x * x + c) % n
y, r, q, g = 2, 1, 1, 1
while g == 1:
x = y
for i in range(r):
y = f(y)
k = 0
while k < r and g == 1:
ys = y
for i in range(min(m, r - k)):
y = f(y)
q = q * abs(x - y) % n
g = gcd(q, n)
k += m
r <<= 1
if g == n:
g = 1
while g == 1:
ys = f(ys)
g = gcd(abs(x - ys), n)
if g < n:
if isPrimeMR(g): return g
elif isPrimeMR(n // g): return n // g
return findFactorRho(g)
def primeFactor(n):
i = 2
ret = {}
rhoFlg = 0
while i*i <= n:
k = 0
while n % i == 0:
n //= i
k += 1
if k: ret[i] = k
i += 1 + i % 2
if i == 101 and n >= 2 ** 20:
while n > 1:
if isPrimeMR(n):
ret[n], n = 1, 1
else:
rhoFlg = 1
j = findFactorRho(n)
k = 0
while n % j == 0:
n //= j
k += 1
ret[j] = k
if n > 1: ret[n] = 1
if rhoFlg: ret = {x: ret[x] for x in sorted(ret)}
return ret
def divisors(n):
res = [1]
prime = primeFactor(n)
for p in prime:
newres = []
for d in res:
for j in range(prime[p]+1):
newres.append(d*p**j)
res = newres
res.sort()
return res
def xorfactorial(num):
if num==0:
return 0
elif num==1:
return 1
elif num==2:
return 3
elif num==3:
return 0
else:
x=baseorder(num)
return (2**x)*((num-2**x+1)%2)+function(num-2**x)
def xorconv(n,X,Y):
if n==0:
res=[(X[0]*Y[0])%mod]
return res
x=[X[i]+X[i+2**(n-1)] for i in range(2**(n-1))]
y=[Y[i]+Y[i+2**(n-1)] for i in range(2**(n-1))]
z=[X[i]-X[i+2**(n-1)] for i in range(2**(n-1))]
w=[Y[i]-Y[i+2**(n-1)] for i in range(2**(n-1))]
res1=xorconv(n-1,x,y)
res2=xorconv(n-1,z,w)
former=[(res1[i]+res2[i])*inv for i in range(2**(n-1))]
latter=[(res1[i]-res2[i])*inv for i in range(2**(n-1))]
former=list(map(lambda x:x%mod,former))
latter=list(map(lambda x:x%mod,latter))
return former+latter
def merge_sort(A,B):
pos_A,pos_B = 0,0
n,m = len(A),len(B)
res = []
while pos_A < n and pos_B < m:
a,b = A[pos_A],B[pos_B]
if a < b:
res.append(a)
pos_A += 1
else:
res.append(b)
pos_B += 1
res += A[pos_A:]
res += B[pos_B:]
return res
class UnionFindVerSize():
def __init__(self, N):
self._parent = [n for n in range(0, N)]
self._size = [1] * N
self.group = N
def find_root(self, x):
if self._parent[x] == x: return x
self._parent[x] = self.find_root(self._parent[x])
stack = [x]
while self._parent[stack[-1]]!=stack[-1]:
stack.append(self._parent[stack[-1]])
for v in stack:
self._parent[v] = stack[-1]
return self._parent[x]
def unite(self, x, y):
gx = self.find_root(x)
gy = self.find_root(y)
if gx == gy: return
self.group -= 1
if self._size[gx] < self._size[gy]:
self._parent[gx] = gy
self._size[gy] += self._size[gx]
else:
self._parent[gy] = gx
self._size[gx] += self._size[gy]
def get_size(self, x):
return self._size[self.find_root(x)]
def is_same_group(self, x, y):
return self.find_root(x) == self.find_root(y)
class WeightedUnionFind():
def __init__(self,N):
self.parent = [i for i in range(N)]
self.size = [1 for i in range(N)]
self.val = [0 for i in range(N)]
self.flag = True
self.edge = [[] for i in range(N)]
def dfs(self,v,pv):
stack = [(v,pv)]
new_parent = self.parent[pv]
while stack:
v,pv = stack.pop()
self.parent[v] = new_parent
for nv,w in self.edge[v]:
if nv!=pv:
self.val[nv] = self.val[v] + w
stack.append((nv,v))
def unite(self,x,y,w):
if not self.flag:
return
if self.parent[x]==self.parent[y]:
self.flag = (self.val[x] - self.val[y] == w)
return
if self.size[self.parent[x]]>self.size[self.parent[y]]:
self.edge[x].append((y,-w))
self.edge[y].append((x,w))
self.size[x] += self.size[y]
self.val[y] = self.val[x] - w
self.dfs(y,x)
else:
self.edge[x].append((y,-w))
self.edge[y].append((x,w))
self.size[y] += self.size[x]
self.val[x] = self.val[y] + w
self.dfs(x,y)
class Dijkstra():
class Edge():
def __init__(self, _to, _cost):
self.to = _to
self.cost = _cost
def __init__(self, V):
self.G = [[] for i in range(V)]
self._E = 0
self._V = V
@property
def E(self):
return self._E
@property
def V(self):
return self._V
def add_edge(self, _from, _to, _cost):
self.G[_from].append(self.Edge(_to, _cost))
self._E += 1
def shortest_path(self, s):
import heapq
que = []
d = [10**15] * self.V
d[s] = 0
heapq.heappush(que, (0, s))
while len(que) != 0:
cost, v = heapq.heappop(que)
if d[v] < cost: continue
for i in range(len(self.G[v])):
e = self.G[v][i]
if d[e.to] > d[v] + e.cost:
d[e.to] = d[v] + e.cost
heapq.heappush(que, (d[e.to], e.to))
return d
#Z[i]:length of the longest list starting from S[i] which is also a prefix of S
#O(|S|)
def Z_algorithm(s):
N = len(s)
Z_alg = [0]*N
Z_alg[0] = N
i = 1
j = 0
while i < N:
while i+j < N and s[j] == s[i+j]:
j += 1
Z_alg[i] = j
if j == 0:
i += 1
continue
k = 1
while i+k < N and k + Z_alg[k]<j:
Z_alg[i+k] = Z_alg[k]
k += 1
i += k
j -= k
return Z_alg
class BIT():
def __init__(self,n,mod=0):
self.BIT = [0]*(n+1)
self.num = n
self.mod = mod
def query(self,idx):
res_sum = 0
mod = self.mod
while idx > 0:
res_sum += self.BIT[idx]
if mod:
res_sum %= mod
idx -= idx&(-idx)
return res_sum
#Ai += x O(logN)
def update(self,idx,x):
mod = self.mod
while idx <= self.num:
self.BIT[idx] += x
if mod:
self.BIT[idx] %= mod
idx += idx&(-idx)
return
class dancinglink():
def __init__(self,n,debug=False):
self.n = n
self.debug = debug
self._left = [i-1 for i in range(n)]
self._right = [i+1 for i in range(n)]
self.exist = [True for i in range(n)]
def pop(self,k):
if self.debug:
assert self.exist[k]
L = self._left[k]
R = self._right[k]
if L!=-1:
if R!=self.n:
self._right[L],self._left[R] = R,L
else:
self._right[L] = self.n
elif R!=self.n:
self._left[R] = -1
self.exist[k] = False
def left(self,idx,k=1):
if self.debug:
assert self.exist[idx]
res = idx
while k:
res = self._left[res]
if res==-1:
break
k -= 1
return res
def right(self,idx,k=1):
if self.debug:
assert self.exist[idx]
res = idx
while k:
res = self._right[res]
if res==self.n:
break
k -= 1
return res
class SparseTable():
def __init__(self,A,merge_func,ide_ele):
N=len(A)
n=N.bit_length()
self.table=[[ide_ele for i in range(n)] for i in range(N)]
self.merge_func=merge_func
for i in range(N):
self.table[i][0]=A[i]
for j in range(1,n):
for i in range(0,N-2**j+1):
f=self.table[i][j-1]
s=self.table[i+2**(j-1)][j-1]
self.table[i][j]=self.merge_func(f,s)
def query(self,s,t):
b=t-s+1
m=b.bit_length()-1
return self.merge_func(self.table[s][m],self.table[t-2**m+1][m])
class BinaryTrie:
class node:
def __init__(self,val):
self.left = None
self.right = None
self.max = val
def __init__(self):
self.root = self.node(-10**15)
def append(self,key,val):
pos = self.root
for i in range(29,-1,-1):
pos.max = max(pos.max,val)
if key>>i & 1:
if pos.right is None:
pos.right = self.node(val)
pos = pos.right
else:
pos = pos.right
else:
if pos.left is None:
pos.left = self.node(val)
pos = pos.left
else:
pos = pos.left
pos.max = max(pos.max,val)
def search(self,M,xor):
res = -10**15
pos = self.root
for i in range(29,-1,-1):
if pos is None:
break
if M>>i & 1:
if xor>>i & 1:
if pos.right:
res = max(res,pos.right.max)
pos = pos.left
else:
if pos.left:
res = max(res,pos.left.max)
pos = pos.right
else:
if xor>>i & 1:
pos = pos.right
else:
pos = pos.left
if pos:
res = max(res,pos.max)
return res
def solveequation(edge,ans,n,m):
#edge=[[to,dire,id]...]
x=[0]*m
used=[False]*n
for v in range(n):
if used[v]:
continue
y = dfs(v)
if y!=0:
return False
return x
def dfs(v):
used[v]=True
r=ans[v]
for to,dire,id in edge[v]:
if used[to]:
continue
y=dfs(to)
if dire==-1:
x[id]=y
else:
x[id]=-y
r+=y
return r
class SegmentTree:
def __init__(self, init_val, segfunc, ide_ele):
n = len(init_val)
self.segfunc = segfunc
self.ide_ele = ide_ele
self.num = 1 << (n - 1).bit_length()
self.tree = [ide_ele] * 2 * self.num
self.size = n
for i in range(n):
self.tree[self.num + i] = init_val[i]
for i in range(self.num - 1, 0, -1):
self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])
def update(self, k, x):
k += self.num
self.tree[k] = x
while k > 1:
self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
k >>= 1
def query(self, l, r):
if r==self.size:
r = self.num
res = self.ide_ele
l += self.num
r += self.num
while l < r:
if l & 1:
res = self.segfunc(res, self.tree[l])
l += 1
if r & 1:
res = self.segfunc(res, self.tree[r - 1])
l >>= 1
r >>= 1
return res
def bisect_l(self,l,r,x):
l += self.num
r += self.num
Lmin = -1
Rmin = -1
while l<r:
if l & 1:
if self.tree[l] <= x and Lmin==-1:
Lmin = l
l += 1
if r & 1:
if self.tree[r-1] <=x:
Rmin = r-1
l >>= 1
r >>= 1
if Lmin != -1:
pos = Lmin
while pos<self.num:
if self.tree[2 * pos] <=x:
pos = 2 * pos
else:
pos = 2 * pos +1
return pos-self.num
elif Rmin != -1:
pos = Rmin
while pos<self.num:
if self.tree[2 * pos] <=x:
pos = 2 * pos
else:
pos = 2 * pos +1
return pos-self.num
else:
return -1
import sys,random,bisect
from collections import deque,defaultdict
from heapq import heapify,heappop,heappush
from itertools import permutations
from math import gcd,log
input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())
def construct(n):
A = [1]
B = [0]
for i in range(n):
next_A1 = [0 for j in range(len(A)+1)]
next_A2 = [0 for j in range(len(A)+1)]
next_B = [A[j] for j in range(len(A))]
for j in range(len(A)):
next_A1[j+1] = A[j]
next_A2[j+1] = -A[j]
for j in range(len(B)):
next_A1[j] += B[j]
next_A2[j] += B[j]
if max(abs(a) for a in next_A1)<=1:
A = next_A1
else:
assert max(abs(a) for a in next_A2)<=1
A = next_A2
B = next_B
return A,B
N = int(input())
A,B = construct(N)
if A[-1]==-1:
for i in range(len(A)):
A[i] *= -1
if B[-1]==-1:
for i in range(len(B)):
B[i] *= -1
print(len(A)-1)
print(*A)
print(len(B)-1)
print(*B)
``` | output | 1 | 91,385 | 22 | 182,771 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Suppose you have two polynomials <image> and <image>. Then polynomial <image> can be uniquely represented in the following way:
<image>
This can be done using [long division](https://en.wikipedia.org/wiki/Polynomial_long_division). Here, <image> denotes the degree of polynomial P(x). <image> is called the remainder of division of polynomial <image> by polynomial <image>, it is also denoted as <image>.
Since there is a way to divide polynomials with remainder, we can define Euclid's algorithm of finding the greatest common divisor of two polynomials. The algorithm takes two polynomials <image>. If the polynomial <image> is zero, the result is <image>, otherwise the result is the value the algorithm returns for pair <image>. On each step the degree of the second argument decreases, so the algorithm works in finite number of steps. But how large that number could be? You are to answer this question.
You are given an integer n. You have to build two polynomials with degrees not greater than n, such that their coefficients are integers not exceeding 1 by their absolute value, the leading coefficients (ones with the greatest power of x) are equal to one, and the described Euclid's algorithm performs exactly n steps finding their greatest common divisor. Moreover, the degree of the first polynomial should be greater than the degree of the second. By a step of the algorithm we mean the transition from pair <image> to pair <image>.
Input
You are given a single integer n (1 β€ n β€ 150) β the number of steps of the algorithm you need to reach.
Output
Print two polynomials in the following format.
In the first line print a single integer m (0 β€ m β€ n) β the degree of the polynomial.
In the second line print m + 1 integers between - 1 and 1 β the coefficients of the polynomial, from constant to leading.
The degree of the first polynomial should be greater than the degree of the second polynomial, the leading coefficients should be equal to 1. Euclid's algorithm should perform exactly n steps when called using these polynomials.
If there is no answer for the given n, print -1.
If there are multiple answer, print any of them.
Examples
Input
1
Output
1
0 1
0
1
Input
2
Output
2
-1 0 1
1
0 1
Note
In the second example you can print polynomials x2 - 1 and x. The sequence of transitions is
(x2 - 1, x) β (x, - 1) β ( - 1, 0).
There are two steps in it. | instruction | 0 | 91,386 | 22 | 182,772 |
Tags: constructive algorithms, math
Correct Solution:
```
import sys
n = int(sys.stdin.readline().split()[0])
class Polynomial:
def __init__(self, coef):
first_nonzero = False
index = len(coef) - 1
while not first_nonzero:
if not coef[index] == 0:
first_nonzero = True
else:
if index == 0:
first_nonzero = True
else:
index -= 1
self.degree = index
self.coef = [coef[j] for j in range(index + 1)]
def multiply_by_x(self):
new_coef = [0]
for j in range(self.degree + 1):
new_coef.append(self.coef[j])
return Polynomial(new_coef)
def minus(self):
new_coef = [-self.coef[j] for j in range(self.degree + 1)]
return Polynomial(new_coef)
def add(self, other):
other_coef = other.coef
new_coef = [0 for j in range(max(self.degree, other.degree) + 1)]
m = min(self.degree, other.degree)
M = max(self.degree, other.degree)
if self.degree > other.degree:
bigger_poly = self
else:
bigger_poly = other
for j in range(m + 1):
new_coef[j] = self.coef[j] + other.coef[j]
for j in range(m + 1, M+1):
new_coef[j] = bigger_poly.coef[j]
return Polynomial(new_coef)
def is_legal(self):
result = True
bools = [None for j in range(self.degree + 1)]
bools[self.degree] = self.coef[self.degree] == 1
for j in range(self.degree):
bools[j] = self.coef[j] == 0 or self.coef[j] == 1 or self.coef[j] == -1
for j in range(self.degree + 1):
result = result and bools[j]
return result
def print(self):
output = ""
for j in range(self.degree + 1):
output += str(self.coef[j]) + " "
print(output)
f = []
f.append(Polynomial([1]))
f.append(Polynomial([0, 1]))
for j in range(2, 151):
xf = f[j-1].multiply_by_x()
t_1 = xf.add(f[j - 2])
t_2 = xf.add(f[j - 2].minus())
if t_1.is_legal():
f.append(t_1)
elif t_2.is_legal():
f.append(t_2)
#print(":(")
print(f[n].degree)
f[n].print()
print(f[n-1].degree)
f[n-1].print()
#for j in range(len(f)):
#f[j].print()
``` | output | 1 | 91,386 | 22 | 182,773 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Suppose you have two polynomials <image> and <image>. Then polynomial <image> can be uniquely represented in the following way:
<image>
This can be done using [long division](https://en.wikipedia.org/wiki/Polynomial_long_division). Here, <image> denotes the degree of polynomial P(x). <image> is called the remainder of division of polynomial <image> by polynomial <image>, it is also denoted as <image>.
Since there is a way to divide polynomials with remainder, we can define Euclid's algorithm of finding the greatest common divisor of two polynomials. The algorithm takes two polynomials <image>. If the polynomial <image> is zero, the result is <image>, otherwise the result is the value the algorithm returns for pair <image>. On each step the degree of the second argument decreases, so the algorithm works in finite number of steps. But how large that number could be? You are to answer this question.
You are given an integer n. You have to build two polynomials with degrees not greater than n, such that their coefficients are integers not exceeding 1 by their absolute value, the leading coefficients (ones with the greatest power of x) are equal to one, and the described Euclid's algorithm performs exactly n steps finding their greatest common divisor. Moreover, the degree of the first polynomial should be greater than the degree of the second. By a step of the algorithm we mean the transition from pair <image> to pair <image>.
Input
You are given a single integer n (1 β€ n β€ 150) β the number of steps of the algorithm you need to reach.
Output
Print two polynomials in the following format.
In the first line print a single integer m (0 β€ m β€ n) β the degree of the polynomial.
In the second line print m + 1 integers between - 1 and 1 β the coefficients of the polynomial, from constant to leading.
The degree of the first polynomial should be greater than the degree of the second polynomial, the leading coefficients should be equal to 1. Euclid's algorithm should perform exactly n steps when called using these polynomials.
If there is no answer for the given n, print -1.
If there are multiple answer, print any of them.
Examples
Input
1
Output
1
0 1
0
1
Input
2
Output
2
-1 0 1
1
0 1
Note
In the second example you can print polynomials x2 - 1 and x. The sequence of transitions is
(x2 - 1, x) β (x, - 1) β ( - 1, 0).
There are two steps in it. | instruction | 0 | 91,387 | 22 | 182,774 |
Tags: constructive algorithms, math
Correct Solution:
```
n = int(input())
a = [1]
b = []
for _ in range(n):
c = [0]+a[:]
d = a[:]
for i,u in enumerate(b): c[i]+=u
a = [u%2 for u in c]
b = [u%2 for u in d]
print(len(a)-1)
print(*a)
print(len(b)-1)
print(*b)
``` | output | 1 | 91,387 | 22 | 182,775 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Suppose you have two polynomials <image> and <image>. Then polynomial <image> can be uniquely represented in the following way:
<image>
This can be done using [long division](https://en.wikipedia.org/wiki/Polynomial_long_division). Here, <image> denotes the degree of polynomial P(x). <image> is called the remainder of division of polynomial <image> by polynomial <image>, it is also denoted as <image>.
Since there is a way to divide polynomials with remainder, we can define Euclid's algorithm of finding the greatest common divisor of two polynomials. The algorithm takes two polynomials <image>. If the polynomial <image> is zero, the result is <image>, otherwise the result is the value the algorithm returns for pair <image>. On each step the degree of the second argument decreases, so the algorithm works in finite number of steps. But how large that number could be? You are to answer this question.
You are given an integer n. You have to build two polynomials with degrees not greater than n, such that their coefficients are integers not exceeding 1 by their absolute value, the leading coefficients (ones with the greatest power of x) are equal to one, and the described Euclid's algorithm performs exactly n steps finding their greatest common divisor. Moreover, the degree of the first polynomial should be greater than the degree of the second. By a step of the algorithm we mean the transition from pair <image> to pair <image>.
Input
You are given a single integer n (1 β€ n β€ 150) β the number of steps of the algorithm you need to reach.
Output
Print two polynomials in the following format.
In the first line print a single integer m (0 β€ m β€ n) β the degree of the polynomial.
In the second line print m + 1 integers between - 1 and 1 β the coefficients of the polynomial, from constant to leading.
The degree of the first polynomial should be greater than the degree of the second polynomial, the leading coefficients should be equal to 1. Euclid's algorithm should perform exactly n steps when called using these polynomials.
If there is no answer for the given n, print -1.
If there are multiple answer, print any of them.
Examples
Input
1
Output
1
0 1
0
1
Input
2
Output
2
-1 0 1
1
0 1
Note
In the second example you can print polynomials x2 - 1 and x. The sequence of transitions is
(x2 - 1, x) β (x, - 1) β ( - 1, 0).
There are two steps in it. | instruction | 0 | 91,388 | 22 | 182,776 |
Tags: constructive algorithms, math
Correct Solution:
```
# python3
# utf-8
n = int(input())
A = [1]
B = []
for _ in range(n):
new_A = [0] + A[:]
new_B = A[:]
for i, b in enumerate(B):
new_A[i] += b
A = [a % 2 for a in new_A]
B = [b % 2 for b in new_B]
print(len(A) - 1)
print(*A)
print(len(B) - 1)
print(*B)
``` | output | 1 | 91,388 | 22 | 182,777 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Suppose you have two polynomials <image> and <image>. Then polynomial <image> can be uniquely represented in the following way:
<image>
This can be done using [long division](https://en.wikipedia.org/wiki/Polynomial_long_division). Here, <image> denotes the degree of polynomial P(x). <image> is called the remainder of division of polynomial <image> by polynomial <image>, it is also denoted as <image>.
Since there is a way to divide polynomials with remainder, we can define Euclid's algorithm of finding the greatest common divisor of two polynomials. The algorithm takes two polynomials <image>. If the polynomial <image> is zero, the result is <image>, otherwise the result is the value the algorithm returns for pair <image>. On each step the degree of the second argument decreases, so the algorithm works in finite number of steps. But how large that number could be? You are to answer this question.
You are given an integer n. You have to build two polynomials with degrees not greater than n, such that their coefficients are integers not exceeding 1 by their absolute value, the leading coefficients (ones with the greatest power of x) are equal to one, and the described Euclid's algorithm performs exactly n steps finding their greatest common divisor. Moreover, the degree of the first polynomial should be greater than the degree of the second. By a step of the algorithm we mean the transition from pair <image> to pair <image>.
Input
You are given a single integer n (1 β€ n β€ 150) β the number of steps of the algorithm you need to reach.
Output
Print two polynomials in the following format.
In the first line print a single integer m (0 β€ m β€ n) β the degree of the polynomial.
In the second line print m + 1 integers between - 1 and 1 β the coefficients of the polynomial, from constant to leading.
The degree of the first polynomial should be greater than the degree of the second polynomial, the leading coefficients should be equal to 1. Euclid's algorithm should perform exactly n steps when called using these polynomials.
If there is no answer for the given n, print -1.
If there are multiple answer, print any of them.
Examples
Input
1
Output
1
0 1
0
1
Input
2
Output
2
-1 0 1
1
0 1
Note
In the second example you can print polynomials x2 - 1 and x. The sequence of transitions is
(x2 - 1, x) β (x, - 1) β ( - 1, 0).
There are two steps in it. | instruction | 0 | 91,389 | 22 | 182,778 |
Tags: constructive algorithms, math
Correct Solution:
```
n = int(input())
a, b = [1], [0]
for i in range(n):
new_b = a[:]
a1 = a[:]
a2 = a[:]
a1.append(0)
a2.append(0)
for i in range(-1, -len(b) - 1, -1):
a1[i] += b[i]
for i in range(-1, -len(b) - 1, -1):
a2[i] -= b[i]
if max([abs(kek) for kek in a1]) < 2:
a = a1
elif max([abs(kek) for kek in a2]) < 2:
a = a2
else:
print("oops")
exit(0)
b = new_b
print(len(a) - 1)
print(*(a[::-1]))
print(len(b) - 1)
print(*(b[::-1]))
``` | output | 1 | 91,389 | 22 | 182,779 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Suppose you have two polynomials <image> and <image>. Then polynomial <image> can be uniquely represented in the following way:
<image>
This can be done using [long division](https://en.wikipedia.org/wiki/Polynomial_long_division). Here, <image> denotes the degree of polynomial P(x). <image> is called the remainder of division of polynomial <image> by polynomial <image>, it is also denoted as <image>.
Since there is a way to divide polynomials with remainder, we can define Euclid's algorithm of finding the greatest common divisor of two polynomials. The algorithm takes two polynomials <image>. If the polynomial <image> is zero, the result is <image>, otherwise the result is the value the algorithm returns for pair <image>. On each step the degree of the second argument decreases, so the algorithm works in finite number of steps. But how large that number could be? You are to answer this question.
You are given an integer n. You have to build two polynomials with degrees not greater than n, such that their coefficients are integers not exceeding 1 by their absolute value, the leading coefficients (ones with the greatest power of x) are equal to one, and the described Euclid's algorithm performs exactly n steps finding their greatest common divisor. Moreover, the degree of the first polynomial should be greater than the degree of the second. By a step of the algorithm we mean the transition from pair <image> to pair <image>.
Input
You are given a single integer n (1 β€ n β€ 150) β the number of steps of the algorithm you need to reach.
Output
Print two polynomials in the following format.
In the first line print a single integer m (0 β€ m β€ n) β the degree of the polynomial.
In the second line print m + 1 integers between - 1 and 1 β the coefficients of the polynomial, from constant to leading.
The degree of the first polynomial should be greater than the degree of the second polynomial, the leading coefficients should be equal to 1. Euclid's algorithm should perform exactly n steps when called using these polynomials.
If there is no answer for the given n, print -1.
If there are multiple answer, print any of them.
Examples
Input
1
Output
1
0 1
0
1
Input
2
Output
2
-1 0 1
1
0 1
Note
In the second example you can print polynomials x2 - 1 and x. The sequence of transitions is
(x2 - 1, x) β (x, - 1) β ( - 1, 0).
There are two steps in it.
Submitted Solution:
```
n = int(input())
def print_poly(a):
print(len(a) - 1)
print(' '.join(map(str, a)))
def shift_add(a, mul, b):
c = [0] * (len(a) + 1)
for i in range(len(a)): c[i + 1] = a[i] * mul
for i in range(len(b)): c[i] += b[i]
return c
a = [0, 1]
b = [1]
for i in range(n - 1):
c = shift_add(a, 1, b)
if max(c) <= 1 and min(c) >= -1:
a, b = c, a
else:
c = shift_add(a, -1, b)
if max(c) <= 1 and min(c) >= -1:
a, b = c, a
else:
print('> <')
if a[-1] == -1:
a = list(map(lambda x: -x, a))
if b[-1] == -1:
b = list(map(lambda x: -x, b))
print_poly(a)
print_poly(b)
``` | instruction | 0 | 91,390 | 22 | 182,780 |
Yes | output | 1 | 91,390 | 22 | 182,781 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Suppose you have two polynomials <image> and <image>. Then polynomial <image> can be uniquely represented in the following way:
<image>
This can be done using [long division](https://en.wikipedia.org/wiki/Polynomial_long_division). Here, <image> denotes the degree of polynomial P(x). <image> is called the remainder of division of polynomial <image> by polynomial <image>, it is also denoted as <image>.
Since there is a way to divide polynomials with remainder, we can define Euclid's algorithm of finding the greatest common divisor of two polynomials. The algorithm takes two polynomials <image>. If the polynomial <image> is zero, the result is <image>, otherwise the result is the value the algorithm returns for pair <image>. On each step the degree of the second argument decreases, so the algorithm works in finite number of steps. But how large that number could be? You are to answer this question.
You are given an integer n. You have to build two polynomials with degrees not greater than n, such that their coefficients are integers not exceeding 1 by their absolute value, the leading coefficients (ones with the greatest power of x) are equal to one, and the described Euclid's algorithm performs exactly n steps finding their greatest common divisor. Moreover, the degree of the first polynomial should be greater than the degree of the second. By a step of the algorithm we mean the transition from pair <image> to pair <image>.
Input
You are given a single integer n (1 β€ n β€ 150) β the number of steps of the algorithm you need to reach.
Output
Print two polynomials in the following format.
In the first line print a single integer m (0 β€ m β€ n) β the degree of the polynomial.
In the second line print m + 1 integers between - 1 and 1 β the coefficients of the polynomial, from constant to leading.
The degree of the first polynomial should be greater than the degree of the second polynomial, the leading coefficients should be equal to 1. Euclid's algorithm should perform exactly n steps when called using these polynomials.
If there is no answer for the given n, print -1.
If there are multiple answer, print any of them.
Examples
Input
1
Output
1
0 1
0
1
Input
2
Output
2
-1 0 1
1
0 1
Note
In the second example you can print polynomials x2 - 1 and x. The sequence of transitions is
(x2 - 1, x) β (x, - 1) β ( - 1, 0).
There are two steps in it.
Submitted Solution:
```
n = int(input())
a = [1]
b = [0]
for i in range(n):
c = a.copy()
a.append(0)
for i in range(len(a) - 1, 0, -1):
a[i] = a[i - 1]
if i < len(b):
a[i] += b[i]
a[i] %= 2
a[0] = b[0]
b = c.copy()
print(len(a) - 1)
for i in a:
print(i, end=' ')
print('')
print(len(b) - 1)
for i in b:
print(i, end=' ')
``` | instruction | 0 | 91,391 | 22 | 182,782 |
Yes | output | 1 | 91,391 | 22 | 182,783 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Suppose you have two polynomials <image> and <image>. Then polynomial <image> can be uniquely represented in the following way:
<image>
This can be done using [long division](https://en.wikipedia.org/wiki/Polynomial_long_division). Here, <image> denotes the degree of polynomial P(x). <image> is called the remainder of division of polynomial <image> by polynomial <image>, it is also denoted as <image>.
Since there is a way to divide polynomials with remainder, we can define Euclid's algorithm of finding the greatest common divisor of two polynomials. The algorithm takes two polynomials <image>. If the polynomial <image> is zero, the result is <image>, otherwise the result is the value the algorithm returns for pair <image>. On each step the degree of the second argument decreases, so the algorithm works in finite number of steps. But how large that number could be? You are to answer this question.
You are given an integer n. You have to build two polynomials with degrees not greater than n, such that their coefficients are integers not exceeding 1 by their absolute value, the leading coefficients (ones with the greatest power of x) are equal to one, and the described Euclid's algorithm performs exactly n steps finding their greatest common divisor. Moreover, the degree of the first polynomial should be greater than the degree of the second. By a step of the algorithm we mean the transition from pair <image> to pair <image>.
Input
You are given a single integer n (1 β€ n β€ 150) β the number of steps of the algorithm you need to reach.
Output
Print two polynomials in the following format.
In the first line print a single integer m (0 β€ m β€ n) β the degree of the polynomial.
In the second line print m + 1 integers between - 1 and 1 β the coefficients of the polynomial, from constant to leading.
The degree of the first polynomial should be greater than the degree of the second polynomial, the leading coefficients should be equal to 1. Euclid's algorithm should perform exactly n steps when called using these polynomials.
If there is no answer for the given n, print -1.
If there are multiple answer, print any of them.
Examples
Input
1
Output
1
0 1
0
1
Input
2
Output
2
-1 0 1
1
0 1
Note
In the second example you can print polynomials x2 - 1 and x. The sequence of transitions is
(x2 - 1, x) β (x, - 1) β ( - 1, 0).
There are two steps in it.
Submitted Solution:
```
B = [1, 0] # 1x + 0
R = [1] # 0x + 1
A = list(B)
n = int(input())
for i in range(1, n):
A += [0]
# print('A =', A)
# print('R =', R)
# print('B =', B)
for j in range(-1, -len(R)-1, -1):
A[len(A)+j] += R[len(R)+j]
if A[len(A)+j] == 2:
A[len(A)+j] = 0
R = list(B)
B = list(A)
# print(i, A, R)
print(len(B)-1)
for u in reversed(B):
print(u, end=' ')
print()
print(len(R)-1)
for u in reversed(R):
print(u, end=' ')
print()
``` | instruction | 0 | 91,392 | 22 | 182,784 |
Yes | output | 1 | 91,392 | 22 | 182,785 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Suppose you have two polynomials <image> and <image>. Then polynomial <image> can be uniquely represented in the following way:
<image>
This can be done using [long division](https://en.wikipedia.org/wiki/Polynomial_long_division). Here, <image> denotes the degree of polynomial P(x). <image> is called the remainder of division of polynomial <image> by polynomial <image>, it is also denoted as <image>.
Since there is a way to divide polynomials with remainder, we can define Euclid's algorithm of finding the greatest common divisor of two polynomials. The algorithm takes two polynomials <image>. If the polynomial <image> is zero, the result is <image>, otherwise the result is the value the algorithm returns for pair <image>. On each step the degree of the second argument decreases, so the algorithm works in finite number of steps. But how large that number could be? You are to answer this question.
You are given an integer n. You have to build two polynomials with degrees not greater than n, such that their coefficients are integers not exceeding 1 by their absolute value, the leading coefficients (ones with the greatest power of x) are equal to one, and the described Euclid's algorithm performs exactly n steps finding their greatest common divisor. Moreover, the degree of the first polynomial should be greater than the degree of the second. By a step of the algorithm we mean the transition from pair <image> to pair <image>.
Input
You are given a single integer n (1 β€ n β€ 150) β the number of steps of the algorithm you need to reach.
Output
Print two polynomials in the following format.
In the first line print a single integer m (0 β€ m β€ n) β the degree of the polynomial.
In the second line print m + 1 integers between - 1 and 1 β the coefficients of the polynomial, from constant to leading.
The degree of the first polynomial should be greater than the degree of the second polynomial, the leading coefficients should be equal to 1. Euclid's algorithm should perform exactly n steps when called using these polynomials.
If there is no answer for the given n, print -1.
If there are multiple answer, print any of them.
Examples
Input
1
Output
1
0 1
0
1
Input
2
Output
2
-1 0 1
1
0 1
Note
In the second example you can print polynomials x2 - 1 and x. The sequence of transitions is
(x2 - 1, x) β (x, - 1) β ( - 1, 0).
There are two steps in it.
Submitted Solution:
```
import sys
#f = open('input', 'r')
f = sys.stdin
n = f.readline()
n = int(n)
t = [[0], [1]]
for j in range(n):
cur = [0] + t[-1]
for i, x in enumerate(t[-2]):
cur[i] += x
if min(cur) < -1 or max(cur) > 1:
cur = [0] + t[-1]
for i, x in enumerate(t[-2]):
cur[i] -= x
t.append(cur)
print(len(t[n+1])-1)
print(' '.join([str(x) for x in t[n+1]]))
print(len(t[n])-1)
print(' '.join([str(x) for x in t[n]]))
``` | instruction | 0 | 91,393 | 22 | 182,786 |
Yes | output | 1 | 91,393 | 22 | 182,787 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Suppose you have two polynomials <image> and <image>. Then polynomial <image> can be uniquely represented in the following way:
<image>
This can be done using [long division](https://en.wikipedia.org/wiki/Polynomial_long_division). Here, <image> denotes the degree of polynomial P(x). <image> is called the remainder of division of polynomial <image> by polynomial <image>, it is also denoted as <image>.
Since there is a way to divide polynomials with remainder, we can define Euclid's algorithm of finding the greatest common divisor of two polynomials. The algorithm takes two polynomials <image>. If the polynomial <image> is zero, the result is <image>, otherwise the result is the value the algorithm returns for pair <image>. On each step the degree of the second argument decreases, so the algorithm works in finite number of steps. But how large that number could be? You are to answer this question.
You are given an integer n. You have to build two polynomials with degrees not greater than n, such that their coefficients are integers not exceeding 1 by their absolute value, the leading coefficients (ones with the greatest power of x) are equal to one, and the described Euclid's algorithm performs exactly n steps finding their greatest common divisor. Moreover, the degree of the first polynomial should be greater than the degree of the second. By a step of the algorithm we mean the transition from pair <image> to pair <image>.
Input
You are given a single integer n (1 β€ n β€ 150) β the number of steps of the algorithm you need to reach.
Output
Print two polynomials in the following format.
In the first line print a single integer m (0 β€ m β€ n) β the degree of the polynomial.
In the second line print m + 1 integers between - 1 and 1 β the coefficients of the polynomial, from constant to leading.
The degree of the first polynomial should be greater than the degree of the second polynomial, the leading coefficients should be equal to 1. Euclid's algorithm should perform exactly n steps when called using these polynomials.
If there is no answer for the given n, print -1.
If there are multiple answer, print any of them.
Examples
Input
1
Output
1
0 1
0
1
Input
2
Output
2
-1 0 1
1
0 1
Note
In the second example you can print polynomials x2 - 1 and x. The sequence of transitions is
(x2 - 1, x) β (x, - 1) β ( - 1, 0).
There are two steps in it.
Submitted Solution:
```
n = int(input())
print(n)
print(1, '0 ' * n)
print(0)
print(1)
``` | instruction | 0 | 91,394 | 22 | 182,788 |
No | output | 1 | 91,394 | 22 | 182,789 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Suppose you have two polynomials <image> and <image>. Then polynomial <image> can be uniquely represented in the following way:
<image>
This can be done using [long division](https://en.wikipedia.org/wiki/Polynomial_long_division). Here, <image> denotes the degree of polynomial P(x). <image> is called the remainder of division of polynomial <image> by polynomial <image>, it is also denoted as <image>.
Since there is a way to divide polynomials with remainder, we can define Euclid's algorithm of finding the greatest common divisor of two polynomials. The algorithm takes two polynomials <image>. If the polynomial <image> is zero, the result is <image>, otherwise the result is the value the algorithm returns for pair <image>. On each step the degree of the second argument decreases, so the algorithm works in finite number of steps. But how large that number could be? You are to answer this question.
You are given an integer n. You have to build two polynomials with degrees not greater than n, such that their coefficients are integers not exceeding 1 by their absolute value, the leading coefficients (ones with the greatest power of x) are equal to one, and the described Euclid's algorithm performs exactly n steps finding their greatest common divisor. Moreover, the degree of the first polynomial should be greater than the degree of the second. By a step of the algorithm we mean the transition from pair <image> to pair <image>.
Input
You are given a single integer n (1 β€ n β€ 150) β the number of steps of the algorithm you need to reach.
Output
Print two polynomials in the following format.
In the first line print a single integer m (0 β€ m β€ n) β the degree of the polynomial.
In the second line print m + 1 integers between - 1 and 1 β the coefficients of the polynomial, from constant to leading.
The degree of the first polynomial should be greater than the degree of the second polynomial, the leading coefficients should be equal to 1. Euclid's algorithm should perform exactly n steps when called using these polynomials.
If there is no answer for the given n, print -1.
If there are multiple answer, print any of them.
Examples
Input
1
Output
1
0 1
0
1
Input
2
Output
2
-1 0 1
1
0 1
Note
In the second example you can print polynomials x2 - 1 and x. The sequence of transitions is
(x2 - 1, x) β (x, - 1) β ( - 1, 0).
There are two steps in it.
Submitted Solution:
```
n=int(input())
if n%2==0:
ch1="-1"
ch2=" "
for i in range(n):
if i==n-1 or i==n-3:
ch1+="1 "
else:
ch1+="0 "
for i in range(n-1):
if n-i%4==0:
ch2+="1"
else:
ch2+="0"
else:
ch1=""
ch2="-1 "
for i in range(n-1):
if i==n-1 or i==n-3:
ch2+="1 "
else:
ch2+="0 "
for i in range(n):
if n-i%4==0:
ch1+="1 "
else:
ch1+="0 "
print(n)
print(ch1)
print(n-1)
print(ch2)
``` | instruction | 0 | 91,395 | 22 | 182,790 |
No | output | 1 | 91,395 | 22 | 182,791 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Suppose you have two polynomials <image> and <image>. Then polynomial <image> can be uniquely represented in the following way:
<image>
This can be done using [long division](https://en.wikipedia.org/wiki/Polynomial_long_division). Here, <image> denotes the degree of polynomial P(x). <image> is called the remainder of division of polynomial <image> by polynomial <image>, it is also denoted as <image>.
Since there is a way to divide polynomials with remainder, we can define Euclid's algorithm of finding the greatest common divisor of two polynomials. The algorithm takes two polynomials <image>. If the polynomial <image> is zero, the result is <image>, otherwise the result is the value the algorithm returns for pair <image>. On each step the degree of the second argument decreases, so the algorithm works in finite number of steps. But how large that number could be? You are to answer this question.
You are given an integer n. You have to build two polynomials with degrees not greater than n, such that their coefficients are integers not exceeding 1 by their absolute value, the leading coefficients (ones with the greatest power of x) are equal to one, and the described Euclid's algorithm performs exactly n steps finding their greatest common divisor. Moreover, the degree of the first polynomial should be greater than the degree of the second. By a step of the algorithm we mean the transition from pair <image> to pair <image>.
Input
You are given a single integer n (1 β€ n β€ 150) β the number of steps of the algorithm you need to reach.
Output
Print two polynomials in the following format.
In the first line print a single integer m (0 β€ m β€ n) β the degree of the polynomial.
In the second line print m + 1 integers between - 1 and 1 β the coefficients of the polynomial, from constant to leading.
The degree of the first polynomial should be greater than the degree of the second polynomial, the leading coefficients should be equal to 1. Euclid's algorithm should perform exactly n steps when called using these polynomials.
If there is no answer for the given n, print -1.
If there are multiple answer, print any of them.
Examples
Input
1
Output
1
0 1
0
1
Input
2
Output
2
-1 0 1
1
0 1
Note
In the second example you can print polynomials x2 - 1 and x. The sequence of transitions is
(x2 - 1, x) β (x, - 1) β ( - 1, 0).
There are two steps in it.
Submitted Solution:
```
#!/usr/bin/env python3
class Polynomial:
def __init__(self, ar):
if isinstance(ar, Polynomial):
ar = ar.ar
self.ar = ar[:]
def add(A, B):
res = []
for x, y in zip_longest(A.ar, B.ar, fillvalue=0):
if abs(x + y) > 1:
return
res.append(x+y)
return Polynomial(res)
def muld(self, d, coeff):
return Polynomial([0]*d + [coeff * x for x in self.ar])
def degree(self):
return len(self.ar)-1
def __repr__(self):
return ' '.join(map(str, self.ar))
# def __repr__(self):
# s = ''
# for d, c in reversed(list(enumerate(self.ar))):
# if d == 0 and c != 0:
# s += '{} 1'.format(('-' if c < 1 else '+'), str(c))
# elif d == 1 and c != 0:
# s += '{} x '.format(('-' if c < 1 else '+'))
# elif c != 0:
# s += '{} x^{} '.format(('-' if c < 1 else '+'), d)
# if s:
# return s[2:].strip() if s[0] == '+' else s.strip()
# else:
# return '0'
def solve():
n = get(int)
def possible(A, B):
A, B = Polynomial(A), Polynomial(B)
muld = n - A.degree()
for d in range(muld+1):
for coeff in [1, -1]:
val = Polynomial.add(A.muld(d, coeff), B)
if val is not None:
# print('{} % {} = {}'.format(val, A, B))
yield val
# @printRecursionTree
def gcd(A, B, k):
if A.degree() > n or B.degree() > n or A.degree() <= B.degree():
return
if k == n:
return A, B
for X in possible(A, B):
val = gcd(X, A, k+1)
if val is not None:
return val
for rem in [[1], [-1]]:
ans = gcd(Polynomial([0, 1]), Polynomial(rem), 1)
if ans is not None:
a, b = ans
if a.ar[-1] == 1 and b.ar[-1] == 1:
return '{}\n{}\n{}\n{}'.format(a.degree(), a, b.degree(), b)
return -1
_testcases = """
9
2
-1 0 1
1
0 1
""".strip()
# ======================= B O I L E R P L A T E ======================= #
# Practicality beats purity
from bisect import bisect_left, bisect_right
from collections import defaultdict
from functools import lru_cache
from itertools import zip_longest
from heapq import heapify, heappop, heappush
from operator import itemgetter, attrgetter
import bisect
import collections
import functools
import heapq
import itertools
import math
import operator
import re
import string
import sys
inf = float('inf')
cache = lru_cache(None)
sys.setrecursionlimit(10000)
def tree():
return collections.defaultdict(tree)
def equal(x, y, epsilon=1e-6):
# https://code.google.com/codejam/kickstart/resources/faq#real-number-behavior
if -epsilon <= x - y <= epsilon:
return True
if -epsilon <= x <= epsilon or -epsilon <= y <= epsilon:
return False
return (-epsilon <= (x - y) / x <= epsilon or -epsilon <= (x - y) / y <= epsilon)
def get(_type): # For easy input
if type(_type) == list:
if len(_type) == 1:
_type = _type[0]
return list(map(_type, input().strip().split()))
else:
return [_type[i](inp) for i, inp in enumerate(input().strip().split())]
else:
return _type(input().strip())
if __name__ == '__main__':
printRecursionTree = timeit = lambda x: x
_p, print = print, lambda *a, **b: None
_p(solve())
``` | instruction | 0 | 91,396 | 22 | 182,792 |
No | output | 1 | 91,396 | 22 | 182,793 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Suppose you have two polynomials <image> and <image>. Then polynomial <image> can be uniquely represented in the following way:
<image>
This can be done using [long division](https://en.wikipedia.org/wiki/Polynomial_long_division). Here, <image> denotes the degree of polynomial P(x). <image> is called the remainder of division of polynomial <image> by polynomial <image>, it is also denoted as <image>.
Since there is a way to divide polynomials with remainder, we can define Euclid's algorithm of finding the greatest common divisor of two polynomials. The algorithm takes two polynomials <image>. If the polynomial <image> is zero, the result is <image>, otherwise the result is the value the algorithm returns for pair <image>. On each step the degree of the second argument decreases, so the algorithm works in finite number of steps. But how large that number could be? You are to answer this question.
You are given an integer n. You have to build two polynomials with degrees not greater than n, such that their coefficients are integers not exceeding 1 by their absolute value, the leading coefficients (ones with the greatest power of x) are equal to one, and the described Euclid's algorithm performs exactly n steps finding their greatest common divisor. Moreover, the degree of the first polynomial should be greater than the degree of the second. By a step of the algorithm we mean the transition from pair <image> to pair <image>.
Input
You are given a single integer n (1 β€ n β€ 150) β the number of steps of the algorithm you need to reach.
Output
Print two polynomials in the following format.
In the first line print a single integer m (0 β€ m β€ n) β the degree of the polynomial.
In the second line print m + 1 integers between - 1 and 1 β the coefficients of the polynomial, from constant to leading.
The degree of the first polynomial should be greater than the degree of the second polynomial, the leading coefficients should be equal to 1. Euclid's algorithm should perform exactly n steps when called using these polynomials.
If there is no answer for the given n, print -1.
If there are multiple answer, print any of them.
Examples
Input
1
Output
1
0 1
0
1
Input
2
Output
2
-1 0 1
1
0 1
Note
In the second example you can print polynomials x2 - 1 and x. The sequence of transitions is
(x2 - 1, x) β (x, - 1) β ( - 1, 0).
There are two steps in it.
Submitted Solution:
```
n = int(input())
if n == 1:
print(1)
print(0, 1)
print(0)
print(1)
elif n == 2:
print(2)
print(-1, 0, 1)
print(1)
print(0, 1)
elif n % 2 == 1:
print(n)
for i in range(n + 1):
print(1, end=' ')
print()
print(n - 1)
for i in range(n - 3):
print(0, end=' ')
print(-1, 0, 1, end=' ')
else:
n-=1
print(n)
for i in range(n + 1):
print(1, end=' ')
print()
print(n - 1)
for i in range(n - 2):
print(0, end=' ')
print(-1, 1, end=' ')
``` | instruction | 0 | 91,397 | 22 | 182,794 |
No | output | 1 | 91,397 | 22 | 182,795 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an array consisting of n integers a_1, a_2, ..., a_n, and a positive integer m. It is guaranteed that m is a divisor of n.
In a single move, you can choose any position i between 1 and n and increase a_i by 1.
Let's calculate c_r (0 β€ r β€ m-1) β the number of elements having remainder r when divided by m. In other words, for each remainder, let's find the number of corresponding elements in a with that remainder.
Your task is to change the array in such a way that c_0 = c_1 = ... = c_{m-1} = n/m.
Find the minimum number of moves to satisfy the above requirement.
Input
The first line of input contains two integers n and m (1 β€ n β€ 2 β
10^5, 1 β€ m β€ n). It is guaranteed that m is a divisor of n.
The second line of input contains n integers a_1, a_2, ..., a_n (0 β€ a_i β€ 10^9), the elements of the array.
Output
In the first line, print a single integer β the minimum number of moves required to satisfy the following condition: for each remainder from 0 to m - 1, the number of elements of the array having this remainder equals n/m.
In the second line, print any array satisfying the condition and can be obtained from the given array with the minimum number of moves. The values of the elements of the resulting array must not exceed 10^{18}.
Examples
Input
6 3
3 2 0 6 10 12
Output
3
3 2 0 7 10 14
Input
4 2
0 1 2 3
Output
0
0 1 2 3 | instruction | 0 | 91,431 | 22 | 182,862 |
Tags: data structures, greedy, implementation
Correct Solution:
```
from collections import defaultdict
n,m = map(int,input().split())
k = n//m
l = list(map(int,input().split()))
s = sum(l)
#mod_list = []
occ = defaultdict(list)
for i,a in enumerate(l):
rem = a%m
occ[rem].append(i)
#mod_list.append(rem)
j = 0
for i in range(m):
while len(occ[i]) > k:
while j < i or len(occ[j % m]) >= k: j += 1
key = occ[i].pop()
l[key] += (j - i) % m
occ[j % m].append(k)
print(sum(l) - s)
print(*l)
``` | output | 1 | 91,431 | 22 | 182,863 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an array consisting of n integers a_1, a_2, ..., a_n, and a positive integer m. It is guaranteed that m is a divisor of n.
In a single move, you can choose any position i between 1 and n and increase a_i by 1.
Let's calculate c_r (0 β€ r β€ m-1) β the number of elements having remainder r when divided by m. In other words, for each remainder, let's find the number of corresponding elements in a with that remainder.
Your task is to change the array in such a way that c_0 = c_1 = ... = c_{m-1} = n/m.
Find the minimum number of moves to satisfy the above requirement.
Input
The first line of input contains two integers n and m (1 β€ n β€ 2 β
10^5, 1 β€ m β€ n). It is guaranteed that m is a divisor of n.
The second line of input contains n integers a_1, a_2, ..., a_n (0 β€ a_i β€ 10^9), the elements of the array.
Output
In the first line, print a single integer β the minimum number of moves required to satisfy the following condition: for each remainder from 0 to m - 1, the number of elements of the array having this remainder equals n/m.
In the second line, print any array satisfying the condition and can be obtained from the given array with the minimum number of moves. The values of the elements of the resulting array must not exceed 10^{18}.
Examples
Input
6 3
3 2 0 6 10 12
Output
3
3 2 0 7 10 14
Input
4 2
0 1 2 3
Output
0
0 1 2 3 | instruction | 0 | 91,436 | 22 | 182,872 |
Tags: data structures, greedy, implementation
Correct Solution:
```
n, m = map(int, input().split())
a = list(map(int, input().split()))
s = [[] for _ in range(m)]
for i in range(n):
s[a[i] % m].append(i)
f = []
c = 0
for _ in range(2):
for i in range(m):
while len(s[i]) > n // m:
f.append((s[i].pop(), i))
while len(s[i]) < n // m and f:
v, p = f.pop()
s[i].append(v)
if i > p:
d = i - p
else:
d = i + m - p
a[v] += d
c += d
print(c)
print(*a)
``` | output | 1 | 91,436 | 22 | 182,873 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a square matrix n Γ n, consisting of non-negative integer numbers. You should find such a way on it that
* starts in the upper left cell of the matrix;
* each following cell is to the right or down from the current cell;
* the way ends in the bottom right cell.
Moreover, if we multiply together all the numbers along the way, the result should be the least "round". In other words, it should end in the least possible number of zeros.
Input
The first line contains an integer number n (2 β€ n β€ 1000), n is the size of the matrix. Then follow n lines containing the matrix elements (non-negative integer numbers not exceeding 109).
Output
In the first line print the least number of trailing zeros. In the second line print the correspondent way itself.
Examples
Input
3
1 2 3
4 5 6
7 8 9
Output
0
DDRR | instruction | 0 | 92,055 | 22 | 184,110 |
Tags: dp, math
Correct Solution:
```
#2B - The least round way
n = int(input())
m = []
for i in range(n):
m.append(list(map(int, input().split())))
#Empty nxn matrix for the divisors of 2
div2 = [[0 for i in range(n)] for ii in range(n)]
#Empty nxn matrix for the divisors of 5
div5 = [[0 for i in range(n)] for ii in range(n)]
ans = 0
#Loop for cases where we have 0 in input
for i in range(n):
for ii in range(n):
if m[i][ii] == 0:
ans = 1
#The following variable will store the final path
path = 'R' * ii + 'D' * i + 'R' * (n - 1 - ii) + 'D' * (n - 1 - i)
m[i][ii] = 10
#Loop for rest of the cases
#We try to find cells that decompose in factors of 2 and 5
for i in range(n):
for ii in range(n):
x = m[i][ii]
while x % 2 == 0 and x > 0:
div2[i][ii] += 1
x //= 2
while x % 5 == 0 and x > 0:
div5[i][ii] += 1
x //= 5
#Now, we start the actual movement
#We add each number we pass to the previous one as we go
for i in range(1, n):
div2[i][0] += div2[i - 1][0]
div2[0][i] += div2[0][i - 1]
div5[i][0] += div5[i - 1][0]
div5[0][i] += div5[0][i - 1]
#We apply the previous loop procedure to the entire list
for i in range(1, n):
for ii in range(1, n):
div2[i][ii] += min(div2[i - 1][ii], div2[i][ii - 1])
div5[i][ii] += min(div5[i - 1][ii], div5[i][ii - 1])
#We record the number of zeros resulted from our movement
if div2[-1][-1] < div5[-1][-1]:
dp = div2
else:
dp = div5
if ans == 1 and dp[-1][-1]:
print(ans)
print(path)
#We start from the top left corner, recording our moves on our
#way to the bottom right corner
else:
i, ii = n - 1, n - 1
path = ''
#Now, we determine the direction we moved into by comparing our
#current position to the previous one and include the record in path
while i or ii:
if not i:
path += 'R'
ii -= 1
elif not ii:
path += 'D'
i -= 1
else:
if dp[i - 1][ii] < dp[i][ii - 1]:
path += 'D'
i -= 1
else:
path += 'R'
ii -= 1
path = path[::-1]
#Now, we print the least number of trailing zeros, then the record of the moves
print(dp[-1][-1])
print(path)
``` | output | 1 | 92,055 | 22 | 184,111 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bitwise exclusive OR (or bitwise addition modulo two) is a binary operation which is equivalent to applying logical exclusive OR to every pair of bits located on the same positions in binary notation of operands. In other words, a binary digit of the result is equal to 1 if and only if bits on the respective positions in the operands are different.
For example, if X = 10910 = 11011012, Y = 4110 = 1010012, then:
X xor Y = 6810 = 10001002.
Write a program, which takes two non-negative integers A and B as an input and finds two non-negative integers X and Y, which satisfy the following conditions:
* A = X + Y
* B = X xor Y, where xor is bitwise exclusive or.
* X is the smallest number among all numbers for which the first two conditions are true.
Input
The first line contains integer number A and the second line contains integer number B (0 β€ A, B β€ 264 - 1).
Output
The only output line should contain two integer non-negative numbers X and Y. Print the only number -1 if there is no answer.
Examples
Input
142
76
Output
33 109 | instruction | 0 | 92,267 | 22 | 184,534 |
Tags: dp, greedy, math
Correct Solution:
```
a=int(input())
b=int(input())
if(a>=b):
if((a-b)%2==1):
print(-1)
exit(0)
f=b
s=(a-b)//2
t=s
if((f^s)==f+s):
print(t,end=" ")
print(f+s)
exit(0)
if((f^t)==f+t):
print(s,end=" ")
print(f+t)
exit(0)
if((t^s)==t+s):
print(f,end=" ")
print(t+s)
exit(0)
print(-1)
``` | output | 1 | 92,267 | 22 | 184,535 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bitwise exclusive OR (or bitwise addition modulo two) is a binary operation which is equivalent to applying logical exclusive OR to every pair of bits located on the same positions in binary notation of operands. In other words, a binary digit of the result is equal to 1 if and only if bits on the respective positions in the operands are different.
For example, if X = 10910 = 11011012, Y = 4110 = 1010012, then:
X xor Y = 6810 = 10001002.
Write a program, which takes two non-negative integers A and B as an input and finds two non-negative integers X and Y, which satisfy the following conditions:
* A = X + Y
* B = X xor Y, where xor is bitwise exclusive or.
* X is the smallest number among all numbers for which the first two conditions are true.
Input
The first line contains integer number A and the second line contains integer number B (0 β€ A, B β€ 264 - 1).
Output
The only output line should contain two integer non-negative numbers X and Y. Print the only number -1 if there is no answer.
Examples
Input
142
76
Output
33 109 | instruction | 0 | 92,268 | 22 | 184,536 |
Tags: dp, greedy, math
Correct Solution:
```
A = int(input())
B = int(input())
x = (A - B)//2
y = x ^ B
if x + y == A and x ^ y == B:
print(x,y)
else:
print(-1)
``` | output | 1 | 92,268 | 22 | 184,537 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bitwise exclusive OR (or bitwise addition modulo two) is a binary operation which is equivalent to applying logical exclusive OR to every pair of bits located on the same positions in binary notation of operands. In other words, a binary digit of the result is equal to 1 if and only if bits on the respective positions in the operands are different.
For example, if X = 10910 = 11011012, Y = 4110 = 1010012, then:
X xor Y = 6810 = 10001002.
Write a program, which takes two non-negative integers A and B as an input and finds two non-negative integers X and Y, which satisfy the following conditions:
* A = X + Y
* B = X xor Y, where xor is bitwise exclusive or.
* X is the smallest number among all numbers for which the first two conditions are true.
Input
The first line contains integer number A and the second line contains integer number B (0 β€ A, B β€ 264 - 1).
Output
The only output line should contain two integer non-negative numbers X and Y. Print the only number -1 if there is no answer.
Examples
Input
142
76
Output
33 109 | instruction | 0 | 92,269 | 22 | 184,538 |
Tags: dp, greedy, math
Correct Solution:
```
A = int(input())
B = int(input())
if A < B:
print(-1)
else:
v = A - B
if v%2 :
print(-1)
else:
v //=2
if B&v:
print(-1)
else:
print(f'{v} {v+B}')
``` | output | 1 | 92,269 | 22 | 184,539 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bitwise exclusive OR (or bitwise addition modulo two) is a binary operation which is equivalent to applying logical exclusive OR to every pair of bits located on the same positions in binary notation of operands. In other words, a binary digit of the result is equal to 1 if and only if bits on the respective positions in the operands are different.
For example, if X = 10910 = 11011012, Y = 4110 = 1010012, then:
X xor Y = 6810 = 10001002.
Write a program, which takes two non-negative integers A and B as an input and finds two non-negative integers X and Y, which satisfy the following conditions:
* A = X + Y
* B = X xor Y, where xor is bitwise exclusive or.
* X is the smallest number among all numbers for which the first two conditions are true.
Input
The first line contains integer number A and the second line contains integer number B (0 β€ A, B β€ 264 - 1).
Output
The only output line should contain two integer non-negative numbers X and Y. Print the only number -1 if there is no answer.
Examples
Input
142
76
Output
33 109 | instruction | 0 | 92,270 | 22 | 184,540 |
Tags: dp, greedy, math
Correct Solution:
```
a, b = int(input()), int(input())
x, y = (a - b) >> 1, (a - b) // 2 + b
if a < b or (a + b) & 1 or x & (a - x) != x:
print("-1")
else: print(x, y)
``` | output | 1 | 92,270 | 22 | 184,541 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bitwise exclusive OR (or bitwise addition modulo two) is a binary operation which is equivalent to applying logical exclusive OR to every pair of bits located on the same positions in binary notation of operands. In other words, a binary digit of the result is equal to 1 if and only if bits on the respective positions in the operands are different.
For example, if X = 10910 = 11011012, Y = 4110 = 1010012, then:
X xor Y = 6810 = 10001002.
Write a program, which takes two non-negative integers A and B as an input and finds two non-negative integers X and Y, which satisfy the following conditions:
* A = X + Y
* B = X xor Y, where xor is bitwise exclusive or.
* X is the smallest number among all numbers for which the first two conditions are true.
Input
The first line contains integer number A and the second line contains integer number B (0 β€ A, B β€ 264 - 1).
Output
The only output line should contain two integer non-negative numbers X and Y. Print the only number -1 if there is no answer.
Examples
Input
142
76
Output
33 109 | instruction | 0 | 92,271 | 22 | 184,542 |
Tags: dp, greedy, math
Correct Solution:
```
_a = int(input())
_b = int(input())
A = bin(_a)[2:]
B = bin(_b)[2:]
if len(A) < len(B):
A,B = B,A
B = "0"*(len(A) - len(B)) + B
X = ""
Y = ""
need_carry = False
for a,b in zip(A,B):
if a + b == "11":
X += "0"
Y += "1"
elif a + b == "10":
if need_carry:
X += "1"
Y += "1"
need_carry = True
else:
X += "0"
Y += "0"
need_carry = True
elif a + b == "01":
X += "0"
Y += "1"
elif a + b == "00":
if need_carry:
X += "1"
Y += "1"
need_carry = False
else:
X += "0"
Y += "0"
need_carry = False
x = int(X, base=2)
y = int(Y, base=2)
if x+y == _a and x^y == _b:
print (x,y)
else:
print ("-1")
``` | output | 1 | 92,271 | 22 | 184,543 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bitwise exclusive OR (or bitwise addition modulo two) is a binary operation which is equivalent to applying logical exclusive OR to every pair of bits located on the same positions in binary notation of operands. In other words, a binary digit of the result is equal to 1 if and only if bits on the respective positions in the operands are different.
For example, if X = 10910 = 11011012, Y = 4110 = 1010012, then:
X xor Y = 6810 = 10001002.
Write a program, which takes two non-negative integers A and B as an input and finds two non-negative integers X and Y, which satisfy the following conditions:
* A = X + Y
* B = X xor Y, where xor is bitwise exclusive or.
* X is the smallest number among all numbers for which the first two conditions are true.
Input
The first line contains integer number A and the second line contains integer number B (0 β€ A, B β€ 264 - 1).
Output
The only output line should contain two integer non-negative numbers X and Y. Print the only number -1 if there is no answer.
Examples
Input
142
76
Output
33 109 | instruction | 0 | 92,272 | 22 | 184,544 |
Tags: dp, greedy, math
Correct Solution:
```
#Code by Sounak, IIESTS
#------------------------------warmup----------------------------
import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
from collections import defaultdict
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
#-------------------game starts now-----------------------------------------------------
a=int(input())
b=int(input())
x=(a-b)//2
y=x+b
if a<b or a%2!=b%2 or x&(a-x)!=x:
print(-1)
else:
print(x,y)
``` | output | 1 | 92,272 | 22 | 184,545 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bitwise exclusive OR (or bitwise addition modulo two) is a binary operation which is equivalent to applying logical exclusive OR to every pair of bits located on the same positions in binary notation of operands. In other words, a binary digit of the result is equal to 1 if and only if bits on the respective positions in the operands are different.
For example, if X = 10910 = 11011012, Y = 4110 = 1010012, then:
X xor Y = 6810 = 10001002.
Write a program, which takes two non-negative integers A and B as an input and finds two non-negative integers X and Y, which satisfy the following conditions:
* A = X + Y
* B = X xor Y, where xor is bitwise exclusive or.
* X is the smallest number among all numbers for which the first two conditions are true.
Input
The first line contains integer number A and the second line contains integer number B (0 β€ A, B β€ 264 - 1).
Output
The only output line should contain two integer non-negative numbers X and Y. Print the only number -1 if there is no answer.
Examples
Input
142
76
Output
33 109 | instruction | 0 | 92,273 | 22 | 184,546 |
Tags: dp, greedy, math
Correct Solution:
```
A, B = int(input()), int(input())
if A < B:
print(-1)
X = (A - B) // 2
Y = X + B
if X + Y != A or X^Y != B:
print(-1)
else:
print(X, Y)
``` | output | 1 | 92,273 | 22 | 184,547 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bitwise exclusive OR (or bitwise addition modulo two) is a binary operation which is equivalent to applying logical exclusive OR to every pair of bits located on the same positions in binary notation of operands. In other words, a binary digit of the result is equal to 1 if and only if bits on the respective positions in the operands are different.
For example, if X = 10910 = 11011012, Y = 4110 = 1010012, then:
X xor Y = 6810 = 10001002.
Write a program, which takes two non-negative integers A and B as an input and finds two non-negative integers X and Y, which satisfy the following conditions:
* A = X + Y
* B = X xor Y, where xor is bitwise exclusive or.
* X is the smallest number among all numbers for which the first two conditions are true.
Input
The first line contains integer number A and the second line contains integer number B (0 β€ A, B β€ 264 - 1).
Output
The only output line should contain two integer non-negative numbers X and Y. Print the only number -1 if there is no answer.
Examples
Input
142
76
Output
33 109 | instruction | 0 | 92,274 | 22 | 184,548 |
Tags: dp, greedy, math
Correct Solution:
```
A, B = int(input()), int(input())
#print(*[(A - B) // 2, (A + B) // 2] if A >= B and (A - B) % 2 == 0 else -1)
if A >= B and (A - B) % 2 == 0:
print((A - B) // 2, (A + B) // 2)
else:
print(-1)
``` | output | 1 | 92,274 | 22 | 184,549 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bitwise exclusive OR (or bitwise addition modulo two) is a binary operation which is equivalent to applying logical exclusive OR to every pair of bits located on the same positions in binary notation of operands. In other words, a binary digit of the result is equal to 1 if and only if bits on the respective positions in the operands are different.
For example, if X = 10910 = 11011012, Y = 4110 = 1010012, then:
X xor Y = 6810 = 10001002.
Write a program, which takes two non-negative integers A and B as an input and finds two non-negative integers X and Y, which satisfy the following conditions:
* A = X + Y
* B = X xor Y, where xor is bitwise exclusive or.
* X is the smallest number among all numbers for which the first two conditions are true.
Input
The first line contains integer number A and the second line contains integer number B (0 β€ A, B β€ 264 - 1).
Output
The only output line should contain two integer non-negative numbers X and Y. Print the only number -1 if there is no answer.
Examples
Input
142
76
Output
33 109
Submitted Solution:
```
import math
from collections import defaultdict
from sys import stdin
R = lambda: map(int, stdin.readline().split())
a, b = int(input()), int(input())
dp = [[[0, 0] for j in range(2)] for i in range(70)]
dp[0][0][0] = dp[0][1][0] = 1
trace = defaultdict(tuple)
for i in range(65):
ai, bi = (a >> i & 1), (b >> i & 1)
for bt in range(2):
for cy in range(2):
if dp[i][bt][cy]:
if ai == ((bi ^ bt & 1) + bt + cy) & 1:
ncy = ((bi ^ bt & 1) + bt + cy) >> 1 & 1
dp[i + 1][0][ncy] = dp[i + 1][1][ncy] = 1
trace[tuple((i + 1, 0, ncy))] = trace[tuple((i + 1, 1, ncy))] = tuple((i, bt, cy))
else:
dp[i][bt][cy] = 0
cur = tuple((64, 0, 0)) if dp[64][0][0] else tuple((64, 1, 0)) if dp[64][1][0] else 0
if not cur:
print(-1)
else:
res = 0
while cur:
res = (cur[1] << cur[0]) | res
cur = trace[cur]
print(min(res, a - res), max(res, a - res), sep=' ')
``` | instruction | 0 | 92,278 | 22 | 184,556 |
Yes | output | 1 | 92,278 | 22 | 184,557 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bitwise exclusive OR (or bitwise addition modulo two) is a binary operation which is equivalent to applying logical exclusive OR to every pair of bits located on the same positions in binary notation of operands. In other words, a binary digit of the result is equal to 1 if and only if bits on the respective positions in the operands are different.
For example, if X = 10910 = 11011012, Y = 4110 = 1010012, then:
X xor Y = 6810 = 10001002.
Write a program, which takes two non-negative integers A and B as an input and finds two non-negative integers X and Y, which satisfy the following conditions:
* A = X + Y
* B = X xor Y, where xor is bitwise exclusive or.
* X is the smallest number among all numbers for which the first two conditions are true.
Input
The first line contains integer number A and the second line contains integer number B (0 β€ A, B β€ 264 - 1).
Output
The only output line should contain two integer non-negative numbers X and Y. Print the only number -1 if there is no answer.
Examples
Input
142
76
Output
33 109
Submitted Solution:
```
def xor(a,b,y):
if y^a == b:
return 1
return 0
def find(x,y):
for i in range(x//2):
if xor(i,x-i,y):
return i
return -1
x = int(input())
y = int(input())
k = find(x,y)
if k !=-1:
print(k,x-k)
else:
print(-1)
``` | instruction | 0 | 92,279 | 22 | 184,558 |
No | output | 1 | 92,279 | 22 | 184,559 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bitwise exclusive OR (or bitwise addition modulo two) is a binary operation which is equivalent to applying logical exclusive OR to every pair of bits located on the same positions in binary notation of operands. In other words, a binary digit of the result is equal to 1 if and only if bits on the respective positions in the operands are different.
For example, if X = 10910 = 11011012, Y = 4110 = 1010012, then:
X xor Y = 6810 = 10001002.
Write a program, which takes two non-negative integers A and B as an input and finds two non-negative integers X and Y, which satisfy the following conditions:
* A = X + Y
* B = X xor Y, where xor is bitwise exclusive or.
* X is the smallest number among all numbers for which the first two conditions are true.
Input
The first line contains integer number A and the second line contains integer number B (0 β€ A, B β€ 264 - 1).
Output
The only output line should contain two integer non-negative numbers X and Y. Print the only number -1 if there is no answer.
Examples
Input
142
76
Output
33 109
Submitted Solution:
```
import math
R = lambda: map(int, input().split())
a = int(input())
b = int(input())
dp = [[-1] * 4 for i in range(66)]
dp[-1][0] = dp[-1][1] = 0
for i in range(64):
if (a >> i & 1) == 0 and (b >> i & 1) == 0:
dp[i][0] = 0 if dp[i - 1][0] >= 0 else (1 if dp[i - 1][1] else -1)
dp[i][3] = 0 if dp[i - 1][0] >= 0 else (1 if dp[i - 1][1] else -1)
elif (a >> i & 1) == 1 and (b >> i & 1) == 1:
dp[i][0] = 0 if dp[i - 1][0] >= 0 else (1 if dp[i - 1][1] else -1)
dp[i][1] = 0 if dp[i - 1][0] >= 0 else (1 if dp[i - 1][1] else -1)
elif (a >> i & 1) == 0 and (b >> i & 1) == 1:
dp[i][2] = 2 if dp[i - 1][2] >= 0 else (3 if dp[i - 1][3] else -1)
dp[i][3] = 2 if dp[i - 1][2] >= 0 else (3 if dp[i - 1][3] else -1)
else:
dp[i][0] = 2 if dp[i - 1][2] >= 0 else (3 if dp[i - 1][3] else -1)
dp[i][3] = 2 if dp[i - 1][2] >= 0 else (3 if dp[i - 1][3] else -1)
if dp[63][0] < 0 and dp[63][1] < 0:
print(-1)
exit(0)
nxt = 0 if dp[63][0] >= 0 else 1
res = 0
for i in range(63, -1, -1):
res = nxt & 1 << i | res
nxt = dp[i][nxt]
x, y = min(res, a - res), max(res, a - res)
if x + y == a and x ^ y == b:
print(x, y, sep=' ')
else:
print(-1)
``` | instruction | 0 | 92,280 | 22 | 184,560 |
No | output | 1 | 92,280 | 22 | 184,561 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bitwise exclusive OR (or bitwise addition modulo two) is a binary operation which is equivalent to applying logical exclusive OR to every pair of bits located on the same positions in binary notation of operands. In other words, a binary digit of the result is equal to 1 if and only if bits on the respective positions in the operands are different.
For example, if X = 10910 = 11011012, Y = 4110 = 1010012, then:
X xor Y = 6810 = 10001002.
Write a program, which takes two non-negative integers A and B as an input and finds two non-negative integers X and Y, which satisfy the following conditions:
* A = X + Y
* B = X xor Y, where xor is bitwise exclusive or.
* X is the smallest number among all numbers for which the first two conditions are true.
Input
The first line contains integer number A and the second line contains integer number B (0 β€ A, B β€ 264 - 1).
Output
The only output line should contain two integer non-negative numbers X and Y. Print the only number -1 if there is no answer.
Examples
Input
142
76
Output
33 109
Submitted Solution:
```
# bsdk idhar kya dekhne ko aaya hai, khud kr!!!
# import math
# from itertools import *
# import random
# import calendar
# import datetime
# import webbrowser
a = int(input())
b = int(input())
for i in range(1, a):
flag = 0
for j in range(1, a - i):
if i + j == a and i ^ j == b:
print(i, j)
flag = 1
break
if flag == 1:
break
else:
print(-1)
``` | instruction | 0 | 92,282 | 22 | 184,564 |
No | output | 1 | 92,282 | 22 | 184,565 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two integers x and y (it is guaranteed that x > y). You may choose any prime integer p and subtract it any number of times from x. Is it possible to make x equal to y?
Recall that a prime number is a positive integer that has exactly two positive divisors: 1 and this integer itself. The sequence of prime numbers starts with 2, 3, 5, 7, 11.
Your program should solve t independent test cases.
Input
The first line contains one integer t (1 β€ t β€ 1000) β the number of test cases.
Then t lines follow, each describing a test case. Each line contains two integers x and y (1 β€ y < x β€ 10^{18}).
Output
For each test case, print YES if it is possible to choose a prime number p and subtract it any number of times from x so that x becomes equal to y. Otherwise, print NO.
You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answer).
Example
Input
4
100 98
42 32
1000000000000000000 1
41 40
Output
YES
YES
YES
NO
Note
In the first test of the example you may choose p = 2 and subtract it once.
In the second test of the example you may choose p = 5 and subtract it twice. Note that you cannot choose p = 7, subtract it, then choose p = 3 and subtract it again.
In the third test of the example you may choose p = 3 and subtract it 333333333333333333 times. | instruction | 0 | 92,694 | 22 | 185,388 |
Tags: math, number theory
Correct Solution:
```
for j in range(int(input())):
(x,y) = [int(e) for e in input().split()]
if x-y == 1:
print("NO")
else:
print("YES")
``` | output | 1 | 92,694 | 22 | 185,389 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two integers x and y (it is guaranteed that x > y). You may choose any prime integer p and subtract it any number of times from x. Is it possible to make x equal to y?
Recall that a prime number is a positive integer that has exactly two positive divisors: 1 and this integer itself. The sequence of prime numbers starts with 2, 3, 5, 7, 11.
Your program should solve t independent test cases.
Input
The first line contains one integer t (1 β€ t β€ 1000) β the number of test cases.
Then t lines follow, each describing a test case. Each line contains two integers x and y (1 β€ y < x β€ 10^{18}).
Output
For each test case, print YES if it is possible to choose a prime number p and subtract it any number of times from x so that x becomes equal to y. Otherwise, print NO.
You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answer).
Example
Input
4
100 98
42 32
1000000000000000000 1
41 40
Output
YES
YES
YES
NO
Note
In the first test of the example you may choose p = 2 and subtract it once.
In the second test of the example you may choose p = 5 and subtract it twice. Note that you cannot choose p = 7, subtract it, then choose p = 3 and subtract it again.
In the third test of the example you may choose p = 3 and subtract it 333333333333333333 times. | instruction | 0 | 92,695 | 22 | 185,390 |
Tags: math, number theory
Correct Solution:
```
for _ in " "*int(input()):a,b=map(int,input().split());print("YES" if a-b!=1 else "NO")
``` | output | 1 | 92,695 | 22 | 185,391 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two integers x and y (it is guaranteed that x > y). You may choose any prime integer p and subtract it any number of times from x. Is it possible to make x equal to y?
Recall that a prime number is a positive integer that has exactly two positive divisors: 1 and this integer itself. The sequence of prime numbers starts with 2, 3, 5, 7, 11.
Your program should solve t independent test cases.
Input
The first line contains one integer t (1 β€ t β€ 1000) β the number of test cases.
Then t lines follow, each describing a test case. Each line contains two integers x and y (1 β€ y < x β€ 10^{18}).
Output
For each test case, print YES if it is possible to choose a prime number p and subtract it any number of times from x so that x becomes equal to y. Otherwise, print NO.
You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answer).
Example
Input
4
100 98
42 32
1000000000000000000 1
41 40
Output
YES
YES
YES
NO
Note
In the first test of the example you may choose p = 2 and subtract it once.
In the second test of the example you may choose p = 5 and subtract it twice. Note that you cannot choose p = 7, subtract it, then choose p = 3 and subtract it again.
In the third test of the example you may choose p = 3 and subtract it 333333333333333333 times. | instruction | 0 | 92,696 | 22 | 185,392 |
Tags: math, number theory
Correct Solution:
```
for i in range(int(input())):
m = list(map(int,input().split()))
if m[0]-m[1] == 1:
print("NO")
else:
print("YES")
``` | output | 1 | 92,696 | 22 | 185,393 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two integers x and y (it is guaranteed that x > y). You may choose any prime integer p and subtract it any number of times from x. Is it possible to make x equal to y?
Recall that a prime number is a positive integer that has exactly two positive divisors: 1 and this integer itself. The sequence of prime numbers starts with 2, 3, 5, 7, 11.
Your program should solve t independent test cases.
Input
The first line contains one integer t (1 β€ t β€ 1000) β the number of test cases.
Then t lines follow, each describing a test case. Each line contains two integers x and y (1 β€ y < x β€ 10^{18}).
Output
For each test case, print YES if it is possible to choose a prime number p and subtract it any number of times from x so that x becomes equal to y. Otherwise, print NO.
You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answer).
Example
Input
4
100 98
42 32
1000000000000000000 1
41 40
Output
YES
YES
YES
NO
Note
In the first test of the example you may choose p = 2 and subtract it once.
In the second test of the example you may choose p = 5 and subtract it twice. Note that you cannot choose p = 7, subtract it, then choose p = 3 and subtract it again.
In the third test of the example you may choose p = 3 and subtract it 333333333333333333 times. | instruction | 0 | 92,697 | 22 | 185,394 |
Tags: math, number theory
Correct Solution:
```
def f():
n = int(input())
for _ in range(n):
a,b = map(int, input().split())
print("YES" if a-b > 1 else "NO")
f()
``` | output | 1 | 92,697 | 22 | 185,395 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two integers x and y (it is guaranteed that x > y). You may choose any prime integer p and subtract it any number of times from x. Is it possible to make x equal to y?
Recall that a prime number is a positive integer that has exactly two positive divisors: 1 and this integer itself. The sequence of prime numbers starts with 2, 3, 5, 7, 11.
Your program should solve t independent test cases.
Input
The first line contains one integer t (1 β€ t β€ 1000) β the number of test cases.
Then t lines follow, each describing a test case. Each line contains two integers x and y (1 β€ y < x β€ 10^{18}).
Output
For each test case, print YES if it is possible to choose a prime number p and subtract it any number of times from x so that x becomes equal to y. Otherwise, print NO.
You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answer).
Example
Input
4
100 98
42 32
1000000000000000000 1
41 40
Output
YES
YES
YES
NO
Note
In the first test of the example you may choose p = 2 and subtract it once.
In the second test of the example you may choose p = 5 and subtract it twice. Note that you cannot choose p = 7, subtract it, then choose p = 3 and subtract it again.
In the third test of the example you may choose p = 3 and subtract it 333333333333333333 times. | instruction | 0 | 92,698 | 22 | 185,396 |
Tags: math, number theory
Correct Solution:
```
t = int(input())
for j in range(1, t + 1):
x = list(map(int, input().split()))
c = x[0] - x[1]
if c == 1:
print('NO')
else:
print('YES')
``` | output | 1 | 92,698 | 22 | 185,397 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two integers x and y (it is guaranteed that x > y). You may choose any prime integer p and subtract it any number of times from x. Is it possible to make x equal to y?
Recall that a prime number is a positive integer that has exactly two positive divisors: 1 and this integer itself. The sequence of prime numbers starts with 2, 3, 5, 7, 11.
Your program should solve t independent test cases.
Input
The first line contains one integer t (1 β€ t β€ 1000) β the number of test cases.
Then t lines follow, each describing a test case. Each line contains two integers x and y (1 β€ y < x β€ 10^{18}).
Output
For each test case, print YES if it is possible to choose a prime number p and subtract it any number of times from x so that x becomes equal to y. Otherwise, print NO.
You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answer).
Example
Input
4
100 98
42 32
1000000000000000000 1
41 40
Output
YES
YES
YES
NO
Note
In the first test of the example you may choose p = 2 and subtract it once.
In the second test of the example you may choose p = 5 and subtract it twice. Note that you cannot choose p = 7, subtract it, then choose p = 3 and subtract it again.
In the third test of the example you may choose p = 3 and subtract it 333333333333333333 times. | instruction | 0 | 92,699 | 22 | 185,398 |
Tags: math, number theory
Correct Solution:
```
for _ in range(int(input())):
x, y = [int(x) for x in input().split()]
print(["No", "Yes"][x-y>1])
``` | output | 1 | 92,699 | 22 | 185,399 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two integers x and y (it is guaranteed that x > y). You may choose any prime integer p and subtract it any number of times from x. Is it possible to make x equal to y?
Recall that a prime number is a positive integer that has exactly two positive divisors: 1 and this integer itself. The sequence of prime numbers starts with 2, 3, 5, 7, 11.
Your program should solve t independent test cases.
Input
The first line contains one integer t (1 β€ t β€ 1000) β the number of test cases.
Then t lines follow, each describing a test case. Each line contains two integers x and y (1 β€ y < x β€ 10^{18}).
Output
For each test case, print YES if it is possible to choose a prime number p and subtract it any number of times from x so that x becomes equal to y. Otherwise, print NO.
You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answer).
Example
Input
4
100 98
42 32
1000000000000000000 1
41 40
Output
YES
YES
YES
NO
Note
In the first test of the example you may choose p = 2 and subtract it once.
In the second test of the example you may choose p = 5 and subtract it twice. Note that you cannot choose p = 7, subtract it, then choose p = 3 and subtract it again.
In the third test of the example you may choose p = 3 and subtract it 333333333333333333 times. | instruction | 0 | 92,700 | 22 | 185,400 |
Tags: math, number theory
Correct Solution:
```
de = [2,3,5,7,11]
for i in range(int(input())):
a,b = map(int,input().split())
c = a-b
if c%2 == 1 and c>1:
c-=3
print('YES' if c%2 == 0 else 'NO')
``` | output | 1 | 92,700 | 22 | 185,401 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two integers x and y (it is guaranteed that x > y). You may choose any prime integer p and subtract it any number of times from x. Is it possible to make x equal to y?
Recall that a prime number is a positive integer that has exactly two positive divisors: 1 and this integer itself. The sequence of prime numbers starts with 2, 3, 5, 7, 11.
Your program should solve t independent test cases.
Input
The first line contains one integer t (1 β€ t β€ 1000) β the number of test cases.
Then t lines follow, each describing a test case. Each line contains two integers x and y (1 β€ y < x β€ 10^{18}).
Output
For each test case, print YES if it is possible to choose a prime number p and subtract it any number of times from x so that x becomes equal to y. Otherwise, print NO.
You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answer).
Example
Input
4
100 98
42 32
1000000000000000000 1
41 40
Output
YES
YES
YES
NO
Note
In the first test of the example you may choose p = 2 and subtract it once.
In the second test of the example you may choose p = 5 and subtract it twice. Note that you cannot choose p = 7, subtract it, then choose p = 3 and subtract it again.
In the third test of the example you may choose p = 3 and subtract it 333333333333333333 times. | instruction | 0 | 92,701 | 22 | 185,402 |
Tags: math, number theory
Correct Solution:
```
t = int(input())
for _ in range(t):
a, b = [int(i) for i in input().split()]
if a - 2 >= b:
print("YES")
else:
print("NO")
``` | output | 1 | 92,701 | 22 | 185,403 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two integers x and y (it is guaranteed that x > y). You may choose any prime integer p and subtract it any number of times from x. Is it possible to make x equal to y?
Recall that a prime number is a positive integer that has exactly two positive divisors: 1 and this integer itself. The sequence of prime numbers starts with 2, 3, 5, 7, 11.
Your program should solve t independent test cases.
Input
The first line contains one integer t (1 β€ t β€ 1000) β the number of test cases.
Then t lines follow, each describing a test case. Each line contains two integers x and y (1 β€ y < x β€ 10^{18}).
Output
For each test case, print YES if it is possible to choose a prime number p and subtract it any number of times from x so that x becomes equal to y. Otherwise, print NO.
You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answer).
Example
Input
4
100 98
42 32
1000000000000000000 1
41 40
Output
YES
YES
YES
NO
Note
In the first test of the example you may choose p = 2 and subtract it once.
In the second test of the example you may choose p = 5 and subtract it twice. Note that you cannot choose p = 7, subtract it, then choose p = 3 and subtract it again.
In the third test of the example you may choose p = 3 and subtract it 333333333333333333 times.
Submitted Solution:
```
for i in range(int(input())):
a,b=list(map(int,input().split()))
print("NYOE S"[a-b>1::2])
``` | instruction | 0 | 92,702 | 22 | 185,404 |
Yes | output | 1 | 92,702 | 22 | 185,405 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two integers x and y (it is guaranteed that x > y). You may choose any prime integer p and subtract it any number of times from x. Is it possible to make x equal to y?
Recall that a prime number is a positive integer that has exactly two positive divisors: 1 and this integer itself. The sequence of prime numbers starts with 2, 3, 5, 7, 11.
Your program should solve t independent test cases.
Input
The first line contains one integer t (1 β€ t β€ 1000) β the number of test cases.
Then t lines follow, each describing a test case. Each line contains two integers x and y (1 β€ y < x β€ 10^{18}).
Output
For each test case, print YES if it is possible to choose a prime number p and subtract it any number of times from x so that x becomes equal to y. Otherwise, print NO.
You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answer).
Example
Input
4
100 98
42 32
1000000000000000000 1
41 40
Output
YES
YES
YES
NO
Note
In the first test of the example you may choose p = 2 and subtract it once.
In the second test of the example you may choose p = 5 and subtract it twice. Note that you cannot choose p = 7, subtract it, then choose p = 3 and subtract it again.
In the third test of the example you may choose p = 3 and subtract it 333333333333333333 times.
Submitted Solution:
```
elem = int(input())
for x in range(elem):
ar = []
for t in input().split(' '):
ar.append(int(t))
temp = ar[0] - ar[1]
if temp>1:
print('YES')
else:
print('NO')
``` | instruction | 0 | 92,703 | 22 | 185,406 |
Yes | output | 1 | 92,703 | 22 | 185,407 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two integers x and y (it is guaranteed that x > y). You may choose any prime integer p and subtract it any number of times from x. Is it possible to make x equal to y?
Recall that a prime number is a positive integer that has exactly two positive divisors: 1 and this integer itself. The sequence of prime numbers starts with 2, 3, 5, 7, 11.
Your program should solve t independent test cases.
Input
The first line contains one integer t (1 β€ t β€ 1000) β the number of test cases.
Then t lines follow, each describing a test case. Each line contains two integers x and y (1 β€ y < x β€ 10^{18}).
Output
For each test case, print YES if it is possible to choose a prime number p and subtract it any number of times from x so that x becomes equal to y. Otherwise, print NO.
You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answer).
Example
Input
4
100 98
42 32
1000000000000000000 1
41 40
Output
YES
YES
YES
NO
Note
In the first test of the example you may choose p = 2 and subtract it once.
In the second test of the example you may choose p = 5 and subtract it twice. Note that you cannot choose p = 7, subtract it, then choose p = 3 and subtract it again.
In the third test of the example you may choose p = 3 and subtract it 333333333333333333 times.
Submitted Solution:
```
def mp():
return map(int, input().split())
t = int(input())
for tt in range(t):
x, y = mp()
if x - y == 1:
print('NO')
else:
print('YES')
``` | instruction | 0 | 92,704 | 22 | 185,408 |
Yes | output | 1 | 92,704 | 22 | 185,409 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two integers x and y (it is guaranteed that x > y). You may choose any prime integer p and subtract it any number of times from x. Is it possible to make x equal to y?
Recall that a prime number is a positive integer that has exactly two positive divisors: 1 and this integer itself. The sequence of prime numbers starts with 2, 3, 5, 7, 11.
Your program should solve t independent test cases.
Input
The first line contains one integer t (1 β€ t β€ 1000) β the number of test cases.
Then t lines follow, each describing a test case. Each line contains two integers x and y (1 β€ y < x β€ 10^{18}).
Output
For each test case, print YES if it is possible to choose a prime number p and subtract it any number of times from x so that x becomes equal to y. Otherwise, print NO.
You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answer).
Example
Input
4
100 98
42 32
1000000000000000000 1
41 40
Output
YES
YES
YES
NO
Note
In the first test of the example you may choose p = 2 and subtract it once.
In the second test of the example you may choose p = 5 and subtract it twice. Note that you cannot choose p = 7, subtract it, then choose p = 3 and subtract it again.
In the third test of the example you may choose p = 3 and subtract it 333333333333333333 times.
Submitted Solution:
```
'''input
4
100 98
42 32
1000000000000000000 1
41 40
'''
for _ in range(int(input())):
x, y = [int(i) for i in input().split()]
d = x - y
if d > 1:
print("YES")
else:
print("NO")
``` | instruction | 0 | 92,705 | 22 | 185,410 |
Yes | output | 1 | 92,705 | 22 | 185,411 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two integers x and y (it is guaranteed that x > y). You may choose any prime integer p and subtract it any number of times from x. Is it possible to make x equal to y?
Recall that a prime number is a positive integer that has exactly two positive divisors: 1 and this integer itself. The sequence of prime numbers starts with 2, 3, 5, 7, 11.
Your program should solve t independent test cases.
Input
The first line contains one integer t (1 β€ t β€ 1000) β the number of test cases.
Then t lines follow, each describing a test case. Each line contains two integers x and y (1 β€ y < x β€ 10^{18}).
Output
For each test case, print YES if it is possible to choose a prime number p and subtract it any number of times from x so that x becomes equal to y. Otherwise, print NO.
You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answer).
Example
Input
4
100 98
42 32
1000000000000000000 1
41 40
Output
YES
YES
YES
NO
Note
In the first test of the example you may choose p = 2 and subtract it once.
In the second test of the example you may choose p = 5 and subtract it twice. Note that you cannot choose p = 7, subtract it, then choose p = 3 and subtract it again.
In the third test of the example you may choose p = 3 and subtract it 333333333333333333 times.
Submitted Solution:
```
n=int(input())
for i in range(n):
a,b=map(int,input().split())
if (abs(a-b)%2!=0)&(abs(a-b)%3!=0)&(abs(a-b)%5!=0)&(abs(a-b)%7!=0):
print('No')
else:
print('Yes')
``` | instruction | 0 | 92,706 | 22 | 185,412 |
No | output | 1 | 92,706 | 22 | 185,413 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two integers x and y (it is guaranteed that x > y). You may choose any prime integer p and subtract it any number of times from x. Is it possible to make x equal to y?
Recall that a prime number is a positive integer that has exactly two positive divisors: 1 and this integer itself. The sequence of prime numbers starts with 2, 3, 5, 7, 11.
Your program should solve t independent test cases.
Input
The first line contains one integer t (1 β€ t β€ 1000) β the number of test cases.
Then t lines follow, each describing a test case. Each line contains two integers x and y (1 β€ y < x β€ 10^{18}).
Output
For each test case, print YES if it is possible to choose a prime number p and subtract it any number of times from x so that x becomes equal to y. Otherwise, print NO.
You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answer).
Example
Input
4
100 98
42 32
1000000000000000000 1
41 40
Output
YES
YES
YES
NO
Note
In the first test of the example you may choose p = 2 and subtract it once.
In the second test of the example you may choose p = 5 and subtract it twice. Note that you cannot choose p = 7, subtract it, then choose p = 3 and subtract it again.
In the third test of the example you may choose p = 3 and subtract it 333333333333333333 times.
Submitted Solution:
```
t = int(input())
ans = [True] * t
for i in range(t):
x, y = map(int, input().split())
x -= y
if x == 1:
ans[i] = False
continue
d = 2
while d <= x:
if x % d:
d += 1
else:
x //= d
break
else:
ans[i] = False
for i in ans:
print('YES' if ans[i] else 'NO')
``` | instruction | 0 | 92,707 | 22 | 185,414 |
No | output | 1 | 92,707 | 22 | 185,415 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two integers x and y (it is guaranteed that x > y). You may choose any prime integer p and subtract it any number of times from x. Is it possible to make x equal to y?
Recall that a prime number is a positive integer that has exactly two positive divisors: 1 and this integer itself. The sequence of prime numbers starts with 2, 3, 5, 7, 11.
Your program should solve t independent test cases.
Input
The first line contains one integer t (1 β€ t β€ 1000) β the number of test cases.
Then t lines follow, each describing a test case. Each line contains two integers x and y (1 β€ y < x β€ 10^{18}).
Output
For each test case, print YES if it is possible to choose a prime number p and subtract it any number of times from x so that x becomes equal to y. Otherwise, print NO.
You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answer).
Example
Input
4
100 98
42 32
1000000000000000000 1
41 40
Output
YES
YES
YES
NO
Note
In the first test of the example you may choose p = 2 and subtract it once.
In the second test of the example you may choose p = 5 and subtract it twice. Note that you cannot choose p = 7, subtract it, then choose p = 3 and subtract it again.
In the third test of the example you may choose p = 3 and subtract it 333333333333333333 times.
Submitted Solution:
```
n, ans, z = int(input()), [], 0
for i in range(n):
x, y = map(int, input().split())
z = x - y
if z%2 == 0 or z%3 == 0 or z%5 == 0 or z%7 == 0 or z%11 == 0 or z%13 == 0 or z%17 == 0 or z%19 == 0 or z%23 == 0 or z%31 == 0:
ans.append(1)
else:
ans.append(0)
for i in range(n):
if ans[i] == 1:
print("YES")
else:
print("NO")
``` | instruction | 0 | 92,708 | 22 | 185,416 |
No | output | 1 | 92,708 | 22 | 185,417 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two integers x and y (it is guaranteed that x > y). You may choose any prime integer p and subtract it any number of times from x. Is it possible to make x equal to y?
Recall that a prime number is a positive integer that has exactly two positive divisors: 1 and this integer itself. The sequence of prime numbers starts with 2, 3, 5, 7, 11.
Your program should solve t independent test cases.
Input
The first line contains one integer t (1 β€ t β€ 1000) β the number of test cases.
Then t lines follow, each describing a test case. Each line contains two integers x and y (1 β€ y < x β€ 10^{18}).
Output
For each test case, print YES if it is possible to choose a prime number p and subtract it any number of times from x so that x becomes equal to y. Otherwise, print NO.
You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answer).
Example
Input
4
100 98
42 32
1000000000000000000 1
41 40
Output
YES
YES
YES
NO
Note
In the first test of the example you may choose p = 2 and subtract it once.
In the second test of the example you may choose p = 5 and subtract it twice. Note that you cannot choose p = 7, subtract it, then choose p = 3 and subtract it again.
In the third test of the example you may choose p = 3 and subtract it 333333333333333333 times.
Submitted Solution:
```
num = int(input())
for i in range(num):
l = input().split()
a = int(l[0])
b = int(l[1])
if a % b == 0:
print(0)
else:
print(int(b - (a % b)))
``` | instruction | 0 | 92,709 | 22 | 185,418 |
No | output | 1 | 92,709 | 22 | 185,419 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.