message stringlengths 2 44.5k | message_type stringclasses 2
values | message_id int64 0 1 | conversation_id int64 42 109k | cluster float64 5 5 | __index_level_0__ int64 84 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Programmers' kids solve this riddle in 5-10 minutes. How fast can you do it?
Input
The input contains a single integer n (0 ≤ n ≤ 2000000000).
Output
Output a single integer.
Examples
Input
11
Output
2
Input
14
Output
0
Input
61441
Output
2
Input
571576
Output
10
Input
2128506
Output
3
Submitted Solution:
```
import random
inp = int(input())
print(random.randint(0,100))
``` | instruction | 0 | 57,675 | 5 | 115,350 |
No | output | 1 | 57,675 | 5 | 115,351 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Programmers' kids solve this riddle in 5-10 minutes. How fast can you do it?
Input
The input contains a single integer n (0 ≤ n ≤ 2000000000).
Output
Output a single integer.
Examples
Input
11
Output
2
Input
14
Output
0
Input
61441
Output
2
Input
571576
Output
10
Input
2128506
Output
3
Submitted Solution:
```
print(0)
``` | instruction | 0 | 57,676 | 5 | 115,352 |
No | output | 1 | 57,676 | 5 | 115,353 |
Provide a correct Python 3 solution for this coding contest problem.
Find the number of integers between 1 and N (inclusive) that contains exactly K non-zero digits when written in base ten.
Constraints
* 1 \leq N < 10^{100}
* 1 \leq K \leq 3
Input
Input is given from Standard Input in the following format:
N
K
Output
Print the count.
Examples
Input
100
1
Output
19
Input
25
2
Output
14
Input
314159
2
Output
937
Input
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
3
Output
117879300 | instruction | 0 | 57,786 | 5 | 115,572 |
"Correct Solution:
```
n = input()
k = int(input())
l = len(n)
dp = [[[0,0] for j in range(5)] for i in range(l+1)]
dp[0][0][1] = 1
for i in range(l):
for j in range(k+1):
dp[i+1][j+1][0] += 9 * dp[i][j][0]
dp[i+1][j ][0] += dp[i][j][0]
if n[i] == '0':
dp[i+1][j ][1] = dp[i][j][1]
else:
dp[i+1][j ][0] += dp[i][j][1]
dp[i+1][j+1][0] += (int(n[i]) - 1)*dp[i][j][1]
dp[i+1][j+1][1] += dp[i][j][1]
print(dp[l][k][1] + dp[l][k][0] )
``` | output | 1 | 57,786 | 5 | 115,573 |
Provide a correct Python 3 solution for this coding contest problem.
Find the number of integers between 1 and N (inclusive) that contains exactly K non-zero digits when written in base ten.
Constraints
* 1 \leq N < 10^{100}
* 1 \leq K \leq 3
Input
Input is given from Standard Input in the following format:
N
K
Output
Print the count.
Examples
Input
100
1
Output
19
Input
25
2
Output
14
Input
314159
2
Output
937
Input
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
3
Output
117879300 | instruction | 0 | 57,788 | 5 | 115,576 |
"Correct Solution:
```
n=input()
k=int(input())
m=len(n)
DP=[[[0]*(k+1) for _ in range(2)] for _ in range(m+1)]
DP[0][0][0]=1
for i in range(1,m+1):
N=int(n[i-1])
for j in range(k+1):
DP[i][1][j] +=DP[i-1][1][j]
if N!=0:DP[i][1][j] +=DP[i-1][0][j]
else:DP[i][0][j] +=DP[i-1][0][j]
if j!=0:
DP[i][1][j] +=9*DP[i-1][1][j-1]
if N!=0:
DP[i][0][j] +=DP[i-1][0][j-1]
DP[i][1][j] +=(N-1)*DP[i-1][0][j-1]
print(DP[m][0][k]+DP[m][1][k])
``` | output | 1 | 57,788 | 5 | 115,577 |
Provide a correct Python 3 solution for this coding contest problem.
Find the number of integers between 1 and N (inclusive) that contains exactly K non-zero digits when written in base ten.
Constraints
* 1 \leq N < 10^{100}
* 1 \leq K \leq 3
Input
Input is given from Standard Input in the following format:
N
K
Output
Print the count.
Examples
Input
100
1
Output
19
Input
25
2
Output
14
Input
314159
2
Output
937
Input
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
3
Output
117879300 | instruction | 0 | 57,789 | 5 | 115,578 |
"Correct Solution:
```
N = input()
K = int(input())
def solve(N, K):
l = len(N)
dp = [[[0] * (10) for i in range(2)] for _ in range(l+1)]
dp[0][0][0] = 1
for i in range(l):
D = int(N[i])
for j in range(2):
for k in range(K+1):
for d in range(10):
if j == 0 and d > D: break
dp[i+1][j or (d < D)][k if d == 0 else k+1] += dp[i][j][k]
return dp[l][0][K] + dp[l][1][K]
print(solve(N,K))
``` | output | 1 | 57,789 | 5 | 115,579 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Find the number of integers between 1 and N (inclusive) that contains exactly K non-zero digits when written in base ten.
Constraints
* 1 \leq N < 10^{100}
* 1 \leq K \leq 3
Input
Input is given from Standard Input in the following format:
N
K
Output
Print the count.
Examples
Input
100
1
Output
19
Input
25
2
Output
14
Input
314159
2
Output
937
Input
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
3
Output
117879300
Submitted Solution:
```
def f(s, t, k):
n = len(s)
if k > n: return 0
a = max(t, int(s[0]))
if a == 0: return f(s[1:], t, k)
if k == 1: return a + (n - 1) * 9
z = 0
if k - 1 <= n: z += f(s[1:], 9, k)
z += (a - 1) * f(s[1:], 9, k - 1)
z += f(s[1:], t, k - 1)
return z
s = input()
k = int(input())
print(f(s, 0, k))
``` | instruction | 0 | 57,792 | 5 | 115,584 |
Yes | output | 1 | 57,792 | 5 | 115,585 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Find the number of integers between 1 and N (inclusive) that contains exactly K non-zero digits when written in base ten.
Constraints
* 1 \leq N < 10^{100}
* 1 \leq K \leq 3
Input
Input is given from Standard Input in the following format:
N
K
Output
Print the count.
Examples
Input
100
1
Output
19
Input
25
2
Output
14
Input
314159
2
Output
937
Input
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
3
Output
117879300
Submitted Solution:
```
from functools import lru_cache
N=int(input())
K=int(input())
@lru_cache(None)
def F(N, K):
"""N以下で0でないものがちょうどK個。0を含める"""
# assert N >= 0
if N < 10:
if K == 0:
return 1
if K == 1:
return N
return 0
q,r = divmod(N,10)
ret = 0
if K >= 1:
# 1の位が nonzero
ret += F(q, K-1) * r
ret += F(q-1, K-1) * (9-r)
# 1の位が zero
ret += F(q, K)
return ret
# F(100, 1), F(25, 2), F(314159, 2)
print(F(N, K))
``` | instruction | 0 | 57,794 | 5 | 115,588 |
Yes | output | 1 | 57,794 | 5 | 115,589 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Find the number of integers between 1 and N (inclusive) that contains exactly K non-zero digits when written in base ten.
Constraints
* 1 \leq N < 10^{100}
* 1 \leq K \leq 3
Input
Input is given from Standard Input in the following format:
N
K
Output
Print the count.
Examples
Input
100
1
Output
19
Input
25
2
Output
14
Input
314159
2
Output
937
Input
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
3
Output
117879300
Submitted Solution:
```
n = list(input())
k = int(input())
keta = len(n)
ans = 0
if k == 1:
ans += 9 * (keta-1) + int(n[0])
if k == 2:
ans +=int(n[0])*9*(keta-1) - (9-int(n[1]))*(keta-1) + 81*(keta-2)*(keta-1)/2
if k == 3:
if keta < 3:
ans = 0
else:
ans += int(n[0])*81*(keta-1)*(keta-2)/2 - (10-int(n[1]))*9 + (int(n[2]))
for i in range(keta-2):
ans += 729*(keta-i-2)*(keta-i-3)/2
print(int(ans))
``` | instruction | 0 | 57,796 | 5 | 115,592 |
No | output | 1 | 57,796 | 5 | 115,593 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Find the number of integers between 1 and N (inclusive) that contains exactly K non-zero digits when written in base ten.
Constraints
* 1 \leq N < 10^{100}
* 1 \leq K \leq 3
Input
Input is given from Standard Input in the following format:
N
K
Output
Print the count.
Examples
Input
100
1
Output
19
Input
25
2
Output
14
Input
314159
2
Output
937
Input
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
3
Output
117879300
Submitted Solution:
```
n = int(input())
k = int(input())
ans = 0
for i in range(1, n+1):
x = str(i).replace('0', '')
if len(x) == k:
ans += 1
print(ans)
``` | instruction | 0 | 57,798 | 5 | 115,596 |
No | output | 1 | 57,798 | 5 | 115,597 |
Provide a correct Python 3 solution for this coding contest problem.
You are given an integer sequence A of length N and an integer K. You will perform the following operation on this sequence Q times:
* Choose a contiguous subsequence of length K, then remove the smallest element among the K elements contained in the chosen subsequence (if there are multiple such elements, choose one of them as you like).
Let X and Y be the values of the largest and smallest element removed in the Q operations. You would like X-Y to be as small as possible. Find the smallest possible value of X-Y when the Q operations are performed optimally.
Constraints
* 1 \leq N \leq 2000
* 1 \leq K \leq N
* 1 \leq Q \leq N-K+1
* 1 \leq A_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K Q
A_1 A_2 ... A_N
Output
Print the smallest possible value of X-Y.
Examples
Input
5 3 2
4 3 1 5 2
Output
1
Input
10 1 6
1 1 2 3 5 8 13 21 34 55
Output
7
Input
11 7 5
24979445 861648772 623690081 433933447 476190629 262703497 211047202 971407775 628894325 731963982 822804784
Output
451211184 | instruction | 0 | 57,838 | 5 | 115,676 |
"Correct Solution:
```
N, K, Q = map(int, input().split())
A = [int(i) for i in input().split()]
def solve() :
if Q == 1 : return 0
ret = float('inf')
for i in range(N) :
l = -1
for j in range(i, max(-1, i - K), -1) :
if A[j] < A[i] :
l = j
break
r = N
for j in range(i, min(N, i + K)) :
if A[j] < A[i] :
r = j
break
if r - l - 1 < K :
continue
B = A[::]
B.pop(i)
C = [-1]
for j in range(N - 1) :
if B[j] < A[i] :
C.append(j)
C.append(N - 1)
D = []
for j in range(len(C) - 1) :
if C[j+1] - C[j] >= K :
D += sorted(B[C[j]+1:C[j+1]])[:C[j+1] - C[j] - K]
if len(D) >= Q - 1 :
D.sort()
ret = min(ret, D[Q-2] - A[i])
return ret
print(solve())
``` | output | 1 | 57,838 | 5 | 115,677 |
Provide a correct Python 3 solution for this coding contest problem.
You are given an integer sequence A of length N and an integer K. You will perform the following operation on this sequence Q times:
* Choose a contiguous subsequence of length K, then remove the smallest element among the K elements contained in the chosen subsequence (if there are multiple such elements, choose one of them as you like).
Let X and Y be the values of the largest and smallest element removed in the Q operations. You would like X-Y to be as small as possible. Find the smallest possible value of X-Y when the Q operations are performed optimally.
Constraints
* 1 \leq N \leq 2000
* 1 \leq K \leq N
* 1 \leq Q \leq N-K+1
* 1 \leq A_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K Q
A_1 A_2 ... A_N
Output
Print the smallest possible value of X-Y.
Examples
Input
5 3 2
4 3 1 5 2
Output
1
Input
10 1 6
1 1 2 3 5 8 13 21 34 55
Output
7
Input
11 7 5
24979445 861648772 623690081 433933447 476190629 262703497 211047202 971407775 628894325 731963982 822804784
Output
451211184 | instruction | 0 | 57,839 | 5 | 115,678 |
"Correct Solution:
```
import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]
n,k,q=MI()
aa=LI()
pp=list(sorted(set(aa)))
# 最大-最小を返す
def diff(p):
can=[]
cur=[]
for a in aa+[-1]:
if a<p:
if len(cur)==n:
can=cur
break
if len(cur)>=k:
cur.sort()
if k==1:can+=cur
else:can+=cur[:-(k-1)]
cur=[]
else:
cur.append(a)
if len(can)<q:
return -1
can.sort()
res=can[q-1]-can[0]
return res
#print(pp)
ans=10**16
for p in pp:
ret=diff(p)
if ret==-1:break
#print(p,ret)
ans=min(ans,ret)
print(ans)
``` | output | 1 | 57,839 | 5 | 115,679 |
Provide a correct Python 3 solution for this coding contest problem.
You are given an integer sequence A of length N and an integer K. You will perform the following operation on this sequence Q times:
* Choose a contiguous subsequence of length K, then remove the smallest element among the K elements contained in the chosen subsequence (if there are multiple such elements, choose one of them as you like).
Let X and Y be the values of the largest and smallest element removed in the Q operations. You would like X-Y to be as small as possible. Find the smallest possible value of X-Y when the Q operations are performed optimally.
Constraints
* 1 \leq N \leq 2000
* 1 \leq K \leq N
* 1 \leq Q \leq N-K+1
* 1 \leq A_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K Q
A_1 A_2 ... A_N
Output
Print the smallest possible value of X-Y.
Examples
Input
5 3 2
4 3 1 5 2
Output
1
Input
10 1 6
1 1 2 3 5 8 13 21 34 55
Output
7
Input
11 7 5
24979445 861648772 623690081 433933447 476190629 262703497 211047202 971407775 628894325 731963982 822804784
Output
451211184 | instruction | 0 | 57,840 | 5 | 115,680 |
"Correct Solution:
```
import sys
input = sys.stdin.readline
def main():
n, k, q = map(int, input().split())
a = list(map(int, input().split()))
b = [[v, i]for i, v in enumerate(a)]
b.sort()
index = [0]*n
for i in range(n):
index[i] = b[i][1]
judge = [[] for i in range(n)]
already = [-1, n]
for i in range(n):
for j in range(len(already)-1):
key = a[already[j]+1:already[j+1]]
if len(key) >= k:
judge[i].append(key)
already.append(index[i])
already.sort()
ans = 1e9
for i in range(n):
if not judge[i]:
break
m = b[i][0]
sub = []
for values in judge[i]:
values.sort()
for j in range(len(values)-k+1):
sub.append(values[j])
sub.sort()
if len(sub) < q:
break
M = sub[q-1]
ans = min(ans, M-m)
print(ans)
if __name__ == "__main__":
main()
``` | output | 1 | 57,840 | 5 | 115,681 |
Provide a correct Python 3 solution for this coding contest problem.
You are given an integer sequence A of length N and an integer K. You will perform the following operation on this sequence Q times:
* Choose a contiguous subsequence of length K, then remove the smallest element among the K elements contained in the chosen subsequence (if there are multiple such elements, choose one of them as you like).
Let X and Y be the values of the largest and smallest element removed in the Q operations. You would like X-Y to be as small as possible. Find the smallest possible value of X-Y when the Q operations are performed optimally.
Constraints
* 1 \leq N \leq 2000
* 1 \leq K \leq N
* 1 \leq Q \leq N-K+1
* 1 \leq A_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K Q
A_1 A_2 ... A_N
Output
Print the smallest possible value of X-Y.
Examples
Input
5 3 2
4 3 1 5 2
Output
1
Input
10 1 6
1 1 2 3 5 8 13 21 34 55
Output
7
Input
11 7 5
24979445 861648772 623690081 433933447 476190629 262703497 211047202 971407775 628894325 731963982 822804784
Output
451211184 | instruction | 0 | 57,841 | 5 | 115,682 |
"Correct Solution:
```
inf = float('inf')
N, K, Q = map(int, input().split())
a = tuple(map(int, input().split()))
ans = inf
for ma in sorted(set(a)):
res = []
seq = 0
for i, aa in enumerate(a):
if aa >= ma:
# 最小値以上の要素は部分列に含めてよい
seq += 1
else:
# 最小値未満の要素が来たら、
# それまでの部分列を処理する
if seq >= K:
res.extend(sorted(a[i - seq:i])[:seq - K + 1])
seq = 0
if seq >= K:
res.extend(list(sorted(a[-seq:]))[:seq - K + 1])
seq = 0
if len(res) < Q: continue
res.sort()
ans = min(ans, res[Q - 1] - ma)
print(ans)
``` | output | 1 | 57,841 | 5 | 115,683 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an integer sequence A of length N and an integer K. You will perform the following operation on this sequence Q times:
* Choose a contiguous subsequence of length K, then remove the smallest element among the K elements contained in the chosen subsequence (if there are multiple such elements, choose one of them as you like).
Let X and Y be the values of the largest and smallest element removed in the Q operations. You would like X-Y to be as small as possible. Find the smallest possible value of X-Y when the Q operations are performed optimally.
Constraints
* 1 \leq N \leq 2000
* 1 \leq K \leq N
* 1 \leq Q \leq N-K+1
* 1 \leq A_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K Q
A_1 A_2 ... A_N
Output
Print the smallest possible value of X-Y.
Examples
Input
5 3 2
4 3 1 5 2
Output
1
Input
10 1 6
1 1 2 3 5 8 13 21 34 55
Output
7
Input
11 7 5
24979445 861648772 623690081 433933447 476190629 262703497 211047202 971407775 628894325 731963982 822804784
Output
451211184
Submitted Solution:
```
N, K, Q, *A = map(int, open(0).read().split())
ans = float("inf")
for Y in set(A):
C = []
tmp = []
for a in A:
if a >= Y:
tmp.append(a)
else:
if len(tmp) >= K:
C += sorted(tmp)[:len(tmp) - K + 1]
tmp = []
if len(tmp) >= K:
C += sorted(tmp)[:len(tmp) - K + 1]
if len(C) >= Q:
C.sort()
X = C[Q - 1]
ans = min(ans, X - Y)
print(ans)
``` | instruction | 0 | 57,843 | 5 | 115,686 |
Yes | output | 1 | 57,843 | 5 | 115,687 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an integer sequence A of length N and an integer K. You will perform the following operation on this sequence Q times:
* Choose a contiguous subsequence of length K, then remove the smallest element among the K elements contained in the chosen subsequence (if there are multiple such elements, choose one of them as you like).
Let X and Y be the values of the largest and smallest element removed in the Q operations. You would like X-Y to be as small as possible. Find the smallest possible value of X-Y when the Q operations are performed optimally.
Constraints
* 1 \leq N \leq 2000
* 1 \leq K \leq N
* 1 \leq Q \leq N-K+1
* 1 \leq A_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K Q
A_1 A_2 ... A_N
Output
Print the smallest possible value of X-Y.
Examples
Input
5 3 2
4 3 1 5 2
Output
1
Input
10 1 6
1 1 2 3 5 8 13 21 34 55
Output
7
Input
11 7 5
24979445 861648772 623690081 433933447 476190629 262703497 211047202 971407775 628894325 731963982 822804784
Output
451211184
Submitted Solution:
```
from itertools import*
N,K,Q,*A=map(int,open(0).read().split())
l=len
s=sorted
a=1e9
for Y in A:
C=s(sum((v[:len(v)-K+1]for v in(s(v)for k,v in groupby(A,lambda a:a>=Y)if k)if l(v)>=K),[]))
if l(C)>=Q:a=min(a,C[Q-1]-Y)
print(a)
``` | instruction | 0 | 57,844 | 5 | 115,688 |
Yes | output | 1 | 57,844 | 5 | 115,689 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an integer sequence A of length N and an integer K. You will perform the following operation on this sequence Q times:
* Choose a contiguous subsequence of length K, then remove the smallest element among the K elements contained in the chosen subsequence (if there are multiple such elements, choose one of them as you like).
Let X and Y be the values of the largest and smallest element removed in the Q operations. You would like X-Y to be as small as possible. Find the smallest possible value of X-Y when the Q operations are performed optimally.
Constraints
* 1 \leq N \leq 2000
* 1 \leq K \leq N
* 1 \leq Q \leq N-K+1
* 1 \leq A_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K Q
A_1 A_2 ... A_N
Output
Print the smallest possible value of X-Y.
Examples
Input
5 3 2
4 3 1 5 2
Output
1
Input
10 1 6
1 1 2 3 5 8 13 21 34 55
Output
7
Input
11 7 5
24979445 861648772 623690081 433933447 476190629 262703497 211047202 971407775 628894325 731963982 822804784
Output
451211184
Submitted Solution:
```
import sys, heapq
def input():
return sys.stdin.readline()[:-1]
n, k, q = map(int, input().split())
a = list(map(int, input().split()))
b = sorted(a)
a = [0] + a + [0]
ans = 10**30
for x in b:
removed = []
que = []
for i in range(n+2):
if a[i] < x:
que = []
else:
heapq.heappush(que, a[i])
if len(que) == k:
removed.append(heapq.heappop(que))
if len(removed) < q:
continue
removed.sort()
ans = min(ans, removed[q-1] - x)
print(ans)
``` | instruction | 0 | 57,845 | 5 | 115,690 |
Yes | output | 1 | 57,845 | 5 | 115,691 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an integer sequence A of length N and an integer K. You will perform the following operation on this sequence Q times:
* Choose a contiguous subsequence of length K, then remove the smallest element among the K elements contained in the chosen subsequence (if there are multiple such elements, choose one of them as you like).
Let X and Y be the values of the largest and smallest element removed in the Q operations. You would like X-Y to be as small as possible. Find the smallest possible value of X-Y when the Q operations are performed optimally.
Constraints
* 1 \leq N \leq 2000
* 1 \leq K \leq N
* 1 \leq Q \leq N-K+1
* 1 \leq A_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K Q
A_1 A_2 ... A_N
Output
Print the smallest possible value of X-Y.
Examples
Input
5 3 2
4 3 1 5 2
Output
1
Input
10 1 6
1 1 2 3 5 8 13 21 34 55
Output
7
Input
11 7 5
24979445 861648772 623690081 433933447 476190629 262703497 211047202 971407775 628894325 731963982 822804784
Output
451211184
Submitted Solution:
```
import sys
input = sys.stdin.readline
N, K, Q = map(int, input().split())
a = list(map(int, input().split()))
ta = a + []
res = pow(10, 10)
for x in sorted(a):
t = sorted(ta)
if t[Q - 1] == pow(10, 10): break
res = min(res, t[Q - 1] - t[0])
for i in range(N):
if a[i] == x:
for j in range(i - K + 1, i + K):
if j in range(N):
ta[j] = pow(10, 10)
break
print(res)
``` | instruction | 0 | 57,846 | 5 | 115,692 |
No | output | 1 | 57,846 | 5 | 115,693 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an integer sequence A of length N and an integer K. You will perform the following operation on this sequence Q times:
* Choose a contiguous subsequence of length K, then remove the smallest element among the K elements contained in the chosen subsequence (if there are multiple such elements, choose one of them as you like).
Let X and Y be the values of the largest and smallest element removed in the Q operations. You would like X-Y to be as small as possible. Find the smallest possible value of X-Y when the Q operations are performed optimally.
Constraints
* 1 \leq N \leq 2000
* 1 \leq K \leq N
* 1 \leq Q \leq N-K+1
* 1 \leq A_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K Q
A_1 A_2 ... A_N
Output
Print the smallest possible value of X-Y.
Examples
Input
5 3 2
4 3 1 5 2
Output
1
Input
10 1 6
1 1 2 3 5 8 13 21 34 55
Output
7
Input
11 7 5
24979445 861648772 623690081 433933447 476190629 262703497 211047202 971407775 628894325 731963982 822804784
Output
451211184
Submitted Solution:
```
# -*- coding: utf-8 -*-
import sys
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7
N, K, Q = MAP()
A = LIST()
ans = INF
# 使う要素の最小値とする値xを全探索
for x in A:
# 数列Aをx未満の値で区切った数列Bを作る
B = []
tmp = []
for i in range(N):
if A[i] >= x:
tmp.append(A[i])
else:
B.append(tmp)
tmp = []
B.append(tmp)
# 数列B内の各数列から、使える要素を集める
C = []
for li in B:
m = len(li)
li.sort()
C += li[:max(m-K+1, 0)]
# 集めた要素からQ個をクエリで使うので、小さい方からQ番目が使う要素の最大値y
C.sort()
if len(C) < Q:
continue
y = C[Q-1]
ans = min(ans, y - x)
print(ans)
``` | instruction | 0 | 57,847 | 5 | 115,694 |
No | output | 1 | 57,847 | 5 | 115,695 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an integer sequence A of length N and an integer K. You will perform the following operation on this sequence Q times:
* Choose a contiguous subsequence of length K, then remove the smallest element among the K elements contained in the chosen subsequence (if there are multiple such elements, choose one of them as you like).
Let X and Y be the values of the largest and smallest element removed in the Q operations. You would like X-Y to be as small as possible. Find the smallest possible value of X-Y when the Q operations are performed optimally.
Constraints
* 1 \leq N \leq 2000
* 1 \leq K \leq N
* 1 \leq Q \leq N-K+1
* 1 \leq A_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K Q
A_1 A_2 ... A_N
Output
Print the smallest possible value of X-Y.
Examples
Input
5 3 2
4 3 1 5 2
Output
1
Input
10 1 6
1 1 2 3 5 8 13 21 34 55
Output
7
Input
11 7 5
24979445 861648772 623690081 433933447 476190629 262703497 211047202 971407775 628894325 731963982 822804784
Output
451211184
Submitted Solution:
```
n, k, q = map(int, input().split())
a = list(map(int, input().split()))
d = [a]
sa = sorted(a)
ans = sa[q - 1] - sa[0]
while True:
newd = list()
li = list()
for sub in d:
for c in sub:
if c != sa[0]:
li.append(c)
else:
newd.append(li)
li = list()
newd.append(li)
w = 0
d = list()
for li in newd:
if len(li) < k:
continue
else:
w += len(li) - k + 1
d.append(li)
if w >= q:
sa = sa[1:]
ans = min(sa[q - 1] - sa[0], ans)
else:
break
print(ans)
``` | instruction | 0 | 57,848 | 5 | 115,696 |
No | output | 1 | 57,848 | 5 | 115,697 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an integer sequence A of length N and an integer K. You will perform the following operation on this sequence Q times:
* Choose a contiguous subsequence of length K, then remove the smallest element among the K elements contained in the chosen subsequence (if there are multiple such elements, choose one of them as you like).
Let X and Y be the values of the largest and smallest element removed in the Q operations. You would like X-Y to be as small as possible. Find the smallest possible value of X-Y when the Q operations are performed optimally.
Constraints
* 1 \leq N \leq 2000
* 1 \leq K \leq N
* 1 \leq Q \leq N-K+1
* 1 \leq A_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K Q
A_1 A_2 ... A_N
Output
Print the smallest possible value of X-Y.
Examples
Input
5 3 2
4 3 1 5 2
Output
1
Input
10 1 6
1 1 2 3 5 8 13 21 34 55
Output
7
Input
11 7 5
24979445 861648772 623690081 433933447 476190629 262703497 211047202 971407775 628894325 731963982 822804784
Output
451211184
Submitted Solution:
```
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def bs(f, mi, ma):
mm = -1
while ma > mi:
mm = (ma+mi) // 2
if f(mm):
mi = mm + 1
else:
ma = mm
if f(mm):
return mm + 1
return mm
def main():
n,k,q = LI()
a = LI()
sa = sorted(a)
r = sa[-1] - sa[0]
# print(sorted([[a[i],i] for i in range(n)]))
for i in range(n):
if sa[i] == sa[i-1]:
continue
mi = sa[i]
def f(i):
ma = sa[i]
c = 0
cc = 0
g = 0
ss = 1
for t in a:
if t < mi:
if c > k and c > cc:
g += c - max(k, cc)
ss = 0
c = 0
cc = 0
continue
if t > ma:
cc += 1
c += 1
if ss == 1 and c > cc:
g += c - cc
elif c > k and c > cc:
g += c - max(k, cc)
# print(mi, ma, cc, i, g, q)
return g < q
l = bs(f, i+1, n)
# print(i,l,mi)
if l >= n or l <= i:
continue
t = sa[l] - mi
if r > t:
r = t
return r
print(main())
``` | instruction | 0 | 57,849 | 5 | 115,698 |
No | output | 1 | 57,849 | 5 | 115,699 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Write a program which reads a sequence of integers $A = \\{a_0, a_1, ..., a_{n-1}\\}$ and swap specified elements by a list of the following operation:
* swapRange($b, e, t$): For each integer $k$ ($0 \leq k < (e - b)$, swap element $(b + k)$ and element $(t + k)$.
Constraints
* $1 \leq n \leq 1,000$
* $-1,000,000,000 \leq a_i \leq 1,000,000,000$
* $1 \leq q \leq 1,000$
* $0 \leq b_i < e_i \leq n$
* $0 \leq t_i < t_i + (e_i - b_i) \leq n$
* Given swap ranges do not overlap each other
Input
The input is given in the following format.
$n$
$a_0 \; a_1 \; ...,\; a_{n-1}$
$q$
$b_1 \; e_1 \; t_1$
$b_2 \; e_2 \; t_2$
:
$b_{q} \; e_{q} \; t_{q}$
In the first line, $n$ (the number of elements in $A$) is given. In the second line, $a_i$ (each element in $A$) are given. In the third line, the number of queries $q$ is given and each query is given by three integers $b_i \; e_i \; t_i$ in the following $q$ lines.
Output
Print all elements of $A$ in a line after performing the given operations. Put a single space character between adjacency elements and a newline at the end of the last element.
Example
Input
11
1 2 3 4 5 6 7 8 9 10 11
1
1 4 7
Output
1 8 9 10 5 6 7 2 3 4 11
Submitted Solution:
```
n = int(input())
a = list(map(int,input().split()))
q = int(input())
for i in range(q):
b,e,t = map(int,input().split())
for k in range(e-b):
a[b+k],a[t+k] = a[t+k],a[b+k]
print(*a)
``` | instruction | 0 | 57,977 | 5 | 115,954 |
Yes | output | 1 | 57,977 | 5 | 115,955 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Write a program which reads a sequence of integers $A = \\{a_0, a_1, ..., a_{n-1}\\}$ and swap specified elements by a list of the following operation:
* swapRange($b, e, t$): For each integer $k$ ($0 \leq k < (e - b)$, swap element $(b + k)$ and element $(t + k)$.
Constraints
* $1 \leq n \leq 1,000$
* $-1,000,000,000 \leq a_i \leq 1,000,000,000$
* $1 \leq q \leq 1,000$
* $0 \leq b_i < e_i \leq n$
* $0 \leq t_i < t_i + (e_i - b_i) \leq n$
* Given swap ranges do not overlap each other
Input
The input is given in the following format.
$n$
$a_0 \; a_1 \; ...,\; a_{n-1}$
$q$
$b_1 \; e_1 \; t_1$
$b_2 \; e_2 \; t_2$
:
$b_{q} \; e_{q} \; t_{q}$
In the first line, $n$ (the number of elements in $A$) is given. In the second line, $a_i$ (each element in $A$) are given. In the third line, the number of queries $q$ is given and each query is given by three integers $b_i \; e_i \; t_i$ in the following $q$ lines.
Output
Print all elements of $A$ in a line after performing the given operations. Put a single space character between adjacency elements and a newline at the end of the last element.
Example
Input
11
1 2 3 4 5 6 7 8 9 10 11
1
1 4 7
Output
1 8 9 10 5 6 7 2 3 4 11
Submitted Solution:
```
n = int(input())
a = list(map(int, input().split()))
q = int(input())
for _ in range(q):
b, e, t = map(int, input().split())
for k in range(e-b):
a[t+k],a[b+k] = a[b+k],a[t+k]
print(*a)
``` | instruction | 0 | 57,978 | 5 | 115,956 |
Yes | output | 1 | 57,978 | 5 | 115,957 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Write a program which reads a sequence of integers $A = \\{a_0, a_1, ..., a_{n-1}\\}$ and swap specified elements by a list of the following operation:
* swapRange($b, e, t$): For each integer $k$ ($0 \leq k < (e - b)$, swap element $(b + k)$ and element $(t + k)$.
Constraints
* $1 \leq n \leq 1,000$
* $-1,000,000,000 \leq a_i \leq 1,000,000,000$
* $1 \leq q \leq 1,000$
* $0 \leq b_i < e_i \leq n$
* $0 \leq t_i < t_i + (e_i - b_i) \leq n$
* Given swap ranges do not overlap each other
Input
The input is given in the following format.
$n$
$a_0 \; a_1 \; ...,\; a_{n-1}$
$q$
$b_1 \; e_1 \; t_1$
$b_2 \; e_2 \; t_2$
:
$b_{q} \; e_{q} \; t_{q}$
In the first line, $n$ (the number of elements in $A$) is given. In the second line, $a_i$ (each element in $A$) are given. In the third line, the number of queries $q$ is given and each query is given by three integers $b_i \; e_i \; t_i$ in the following $q$ lines.
Output
Print all elements of $A$ in a line after performing the given operations. Put a single space character between adjacency elements and a newline at the end of the last element.
Example
Input
11
1 2 3 4 5 6 7 8 9 10 11
1
1 4 7
Output
1 8 9 10 5 6 7 2 3 4 11
Submitted Solution:
```
n = int(input())
a = list(map(int, input().split()))
q = int(input())
for i in range(q):
b, e, t = map(int, input().split())
if b < t:
a = a[:b] + a[t:t+e-b] + a[e:t] + a[b:e] + a[t+e-b:]
else:
a = a[:t] + a[b:e] + a[t+e-b:b] + a[t:t+e-b] + a[e:]
print(*a)
``` | instruction | 0 | 57,979 | 5 | 115,958 |
Yes | output | 1 | 57,979 | 5 | 115,959 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Write a program which reads a sequence of integers $A = \\{a_0, a_1, ..., a_{n-1}\\}$ and swap specified elements by a list of the following operation:
* swapRange($b, e, t$): For each integer $k$ ($0 \leq k < (e - b)$, swap element $(b + k)$ and element $(t + k)$.
Constraints
* $1 \leq n \leq 1,000$
* $-1,000,000,000 \leq a_i \leq 1,000,000,000$
* $1 \leq q \leq 1,000$
* $0 \leq b_i < e_i \leq n$
* $0 \leq t_i < t_i + (e_i - b_i) \leq n$
* Given swap ranges do not overlap each other
Input
The input is given in the following format.
$n$
$a_0 \; a_1 \; ...,\; a_{n-1}$
$q$
$b_1 \; e_1 \; t_1$
$b_2 \; e_2 \; t_2$
:
$b_{q} \; e_{q} \; t_{q}$
In the first line, $n$ (the number of elements in $A$) is given. In the second line, $a_i$ (each element in $A$) are given. In the third line, the number of queries $q$ is given and each query is given by three integers $b_i \; e_i \; t_i$ in the following $q$ lines.
Output
Print all elements of $A$ in a line after performing the given operations. Put a single space character between adjacency elements and a newline at the end of the last element.
Example
Input
11
1 2 3 4 5 6 7 8 9 10 11
1
1 4 7
Output
1 8 9 10 5 6 7 2 3 4 11
Submitted Solution:
```
# AOJ ITP2_4_C: Swap
# Python3 2018.6.24 bal4u
n = int(input())
a = list(map(int, input().split()))
q = int(input())
for i in range(q):
b, e, t = map(int, input().split())
s = t+e-b
if t > b:
a = a[:b] + a[t:s] + a[e:t] + a[b:e] + a[s:]
else:
a = a[:t] + a[b:e] + a[s:b] + a[t:s] + a[e:]
print(*a)
``` | instruction | 0 | 57,980 | 5 | 115,960 |
Yes | output | 1 | 57,980 | 5 | 115,961 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Write a program which reads a sequence of integers $A = \\{a_0, a_1, ..., a_{n-1}\\}$ and swap specified elements by a list of the following operation:
* swapRange($b, e, t$): For each integer $k$ ($0 \leq k < (e - b)$, swap element $(b + k)$ and element $(t + k)$.
Constraints
* $1 \leq n \leq 1,000$
* $-1,000,000,000 \leq a_i \leq 1,000,000,000$
* $1 \leq q \leq 1,000$
* $0 \leq b_i < e_i \leq n$
* $0 \leq t_i < t_i + (e_i - b_i) \leq n$
* Given swap ranges do not overlap each other
Input
The input is given in the following format.
$n$
$a_0 \; a_1 \; ...,\; a_{n-1}$
$q$
$b_1 \; e_1 \; t_1$
$b_2 \; e_2 \; t_2$
:
$b_{q} \; e_{q} \; t_{q}$
In the first line, $n$ (the number of elements in $A$) is given. In the second line, $a_i$ (each element in $A$) are given. In the third line, the number of queries $q$ is given and each query is given by three integers $b_i \; e_i \; t_i$ in the following $q$ lines.
Output
Print all elements of $A$ in a line after performing the given operations. Put a single space character between adjacency elements and a newline at the end of the last element.
Example
Input
11
1 2 3 4 5 6 7 8 9 10 11
1
1 4 7
Output
1 8 9 10 5 6 7 2 3 4 11
Submitted Solution:
```
# AOJ ITP2_4_A: Reverse
# Python3 2018.6.24 bal4u
n = int(input())
a = list(map(int, input().split()))
q = int(input())
for i in range(q):
b, e, t = map(int, input().split())
a = a[:b] + a[t:t+e-b] + a[e:t] + a[b:e] + a[t+e-b:]
print(*a)
``` | instruction | 0 | 57,982 | 5 | 115,964 |
No | output | 1 | 57,982 | 5 | 115,965 |
Provide a correct Python 3 solution for this coding contest problem.
When Masha came to math classes today, she saw two integer sequences of length n - 1 on the blackboard. Let's denote the elements of the first sequence as a_i (0 ≤ a_i ≤ 3), and the elements of the second sequence as b_i (0 ≤ b_i ≤ 3).
Masha became interested if or not there is an integer sequence of length n, which elements we will denote as t_i (0 ≤ t_i ≤ 3), so that for every i (1 ≤ i ≤ n - 1) the following is true:
* a_i = t_i | t_{i + 1} (where | denotes the [bitwise OR operation](https://en.wikipedia.org/wiki/Bitwise_operation#OR)) and
* b_i = t_i \& t_{i + 1} (where \& denotes the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND)).
The question appeared to be too difficult for Masha, so now she asked you to check whether such a sequence t_i of length n exists. If it exists, find such a sequence. If there are multiple such sequences, find any of them.
Input
The first line contains a single integer n (2 ≤ n ≤ 10^5) — the length of the sequence t_i.
The second line contains n - 1 integers a_1, a_2, …, a_{n-1} (0 ≤ a_i ≤ 3) — the first sequence on the blackboard.
The third line contains n - 1 integers b_1, b_2, …, b_{n-1} (0 ≤ b_i ≤ 3) — the second sequence on the blackboard.
Output
In the first line print "YES" (without quotes), if there is a sequence t_i that satisfies the conditions from the statements, and "NO" (without quotes), if there is no such sequence.
If there is such a sequence, on the second line print n integers t_1, t_2, …, t_n (0 ≤ t_i ≤ 3) — the sequence that satisfies the statements conditions.
If there are multiple answers, print any of them.
Examples
Input
4
3 3 2
1 2 0
Output
YES
1 3 2 0
Input
3
1 3
3 2
Output
NO
Note
In the first example it's easy to see that the sequence from output satisfies the given conditions:
* t_1 | t_2 = (01_2) | (11_2) = (11_2) = 3 = a_1 and t_1 \& t_2 = (01_2) \& (11_2) = (01_2) = 1 = b_1;
* t_2 | t_3 = (11_2) | (10_2) = (11_2) = 3 = a_2 and t_2 \& t_3 = (11_2) \& (10_2) = (10_2) = 2 = b_2;
* t_3 | t_4 = (10_2) | (00_2) = (10_2) = 2 = a_3 and t_3 \& t_4 = (10_2) \& (00_2) = (00_2) = 0 = b_3.
In the second example there is no such sequence. | instruction | 0 | 57,992 | 5 | 115,984 |
"Correct Solution:
```
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
t = [[-1] * n for i in range(4)]
t[0][0] = 0
t[1][0] = 1
t[2][0] = 2
t[3][0] = 3
for i in range(1, n):
for j in range(4):
if t[j][i - 1] != -1:
for k in range(4):
if (t[j][i - 1] & k == b[i - 1]) and (t[j][i - 1] | k == a[i - 1]):
t[j][i] = k
break
for j in range(4):
if t[j][n - 1] != -1:
print("YES")
print(*t[j])
break
else:
print("NO")
``` | output | 1 | 57,992 | 5 | 115,985 |
Provide a correct Python 3 solution for this coding contest problem.
When Masha came to math classes today, she saw two integer sequences of length n - 1 on the blackboard. Let's denote the elements of the first sequence as a_i (0 ≤ a_i ≤ 3), and the elements of the second sequence as b_i (0 ≤ b_i ≤ 3).
Masha became interested if or not there is an integer sequence of length n, which elements we will denote as t_i (0 ≤ t_i ≤ 3), so that for every i (1 ≤ i ≤ n - 1) the following is true:
* a_i = t_i | t_{i + 1} (where | denotes the [bitwise OR operation](https://en.wikipedia.org/wiki/Bitwise_operation#OR)) and
* b_i = t_i \& t_{i + 1} (where \& denotes the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND)).
The question appeared to be too difficult for Masha, so now she asked you to check whether such a sequence t_i of length n exists. If it exists, find such a sequence. If there are multiple such sequences, find any of them.
Input
The first line contains a single integer n (2 ≤ n ≤ 10^5) — the length of the sequence t_i.
The second line contains n - 1 integers a_1, a_2, …, a_{n-1} (0 ≤ a_i ≤ 3) — the first sequence on the blackboard.
The third line contains n - 1 integers b_1, b_2, …, b_{n-1} (0 ≤ b_i ≤ 3) — the second sequence on the blackboard.
Output
In the first line print "YES" (without quotes), if there is a sequence t_i that satisfies the conditions from the statements, and "NO" (without quotes), if there is no such sequence.
If there is such a sequence, on the second line print n integers t_1, t_2, …, t_n (0 ≤ t_i ≤ 3) — the sequence that satisfies the statements conditions.
If there are multiple answers, print any of them.
Examples
Input
4
3 3 2
1 2 0
Output
YES
1 3 2 0
Input
3
1 3
3 2
Output
NO
Note
In the first example it's easy to see that the sequence from output satisfies the given conditions:
* t_1 | t_2 = (01_2) | (11_2) = (11_2) = 3 = a_1 and t_1 \& t_2 = (01_2) \& (11_2) = (01_2) = 1 = b_1;
* t_2 | t_3 = (11_2) | (10_2) = (11_2) = 3 = a_2 and t_2 \& t_3 = (11_2) \& (10_2) = (10_2) = 2 = b_2;
* t_3 | t_4 = (10_2) | (00_2) = (10_2) = 2 = a_3 and t_3 \& t_4 = (10_2) \& (00_2) = (00_2) = 0 = b_3.
In the second example there is no such sequence. | instruction | 0 | 57,993 | 5 | 115,986 |
"Correct Solution:
```
from itertools import product
#def loop(n, t=[]):
#if n == 1:
#return True, t
#for i in range(3):
#l = loop(n - 1, t + [i])
#if l[0]:
#for j in range(n - 1):
#if not (t[j] | t[j + 1] == a[j] and t[j] & t[j + 1] == b[j]):
#break
#else:
#return True, l[1]
#return False, []
def next(p, o, a):
for i in range(4):
if (p | i == o and p & i == a):
return i
def check(t):
for j in range(n - 1):
if not (t[j] | t[j + 1] == a[j] and t[j] & t[j + 1] == b[j]):
return False
return True
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
#print(loop(n))
#for i in product(*['0123' for i in range(n)]):
#if check([int(j) for j in i]):
#print('YES')
#print(' '.join(i))
#break
#else:
#print('NO')
for j in range(4):
t = [j]
for i in range(1, n):
nxt = next(t[-1], a[i-1], b[i-1])
if nxt is None:
break
t.append(nxt)
else:
print('YES')
print(' '.join(str(i) for i in t))
break
else:
print('NO')
``` | output | 1 | 57,993 | 5 | 115,987 |
Provide a correct Python 3 solution for this coding contest problem.
When Masha came to math classes today, she saw two integer sequences of length n - 1 on the blackboard. Let's denote the elements of the first sequence as a_i (0 ≤ a_i ≤ 3), and the elements of the second sequence as b_i (0 ≤ b_i ≤ 3).
Masha became interested if or not there is an integer sequence of length n, which elements we will denote as t_i (0 ≤ t_i ≤ 3), so that for every i (1 ≤ i ≤ n - 1) the following is true:
* a_i = t_i | t_{i + 1} (where | denotes the [bitwise OR operation](https://en.wikipedia.org/wiki/Bitwise_operation#OR)) and
* b_i = t_i \& t_{i + 1} (where \& denotes the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND)).
The question appeared to be too difficult for Masha, so now she asked you to check whether such a sequence t_i of length n exists. If it exists, find such a sequence. If there are multiple such sequences, find any of them.
Input
The first line contains a single integer n (2 ≤ n ≤ 10^5) — the length of the sequence t_i.
The second line contains n - 1 integers a_1, a_2, …, a_{n-1} (0 ≤ a_i ≤ 3) — the first sequence on the blackboard.
The third line contains n - 1 integers b_1, b_2, …, b_{n-1} (0 ≤ b_i ≤ 3) — the second sequence on the blackboard.
Output
In the first line print "YES" (without quotes), if there is a sequence t_i that satisfies the conditions from the statements, and "NO" (without quotes), if there is no such sequence.
If there is such a sequence, on the second line print n integers t_1, t_2, …, t_n (0 ≤ t_i ≤ 3) — the sequence that satisfies the statements conditions.
If there are multiple answers, print any of them.
Examples
Input
4
3 3 2
1 2 0
Output
YES
1 3 2 0
Input
3
1 3
3 2
Output
NO
Note
In the first example it's easy to see that the sequence from output satisfies the given conditions:
* t_1 | t_2 = (01_2) | (11_2) = (11_2) = 3 = a_1 and t_1 \& t_2 = (01_2) \& (11_2) = (01_2) = 1 = b_1;
* t_2 | t_3 = (11_2) | (10_2) = (11_2) = 3 = a_2 and t_2 \& t_3 = (11_2) \& (10_2) = (10_2) = 2 = b_2;
* t_3 | t_4 = (10_2) | (00_2) = (10_2) = 2 = a_3 and t_3 \& t_4 = (10_2) \& (00_2) = (00_2) = 0 = b_3.
In the second example there is no such sequence. | instruction | 0 | 57,994 | 5 | 115,988 |
"Correct Solution:
```
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(n-1):
if a[i] == 3:
a[i] = '11'
elif a[i] == 2:
a[i] = '10'
elif a[i] == 1:
a[i] = '01'
elif a[i] == 0:
a[i] = '00'
for i in range(n-1):
if b[i] == 3:
b[i] = '11'
elif b[i] == 2:
b[i] = '10'
elif b[i] == 1:
b[i] = '01'
elif b[i] == 0:
b[i] = '00'
def Checker(z, x, y):
if z == '0':
if x == '0' and y == '0':
return '0'
elif x == '0' and y == '1':
return None
elif x == '1' and y == '0':
return '1'
elif x == '1' and y == '1':
return None
elif z == '1':
if x == '0' and y == '0':
return None
elif x == '0' and y == '1':
return None
elif x == '1' and y == '0':
return '0'
elif x == '1' and y == '1':
return '1'
s = []
flag = True
for ti in ['00', '01', '10', '11']:
t = ti
if len(s) == n:
break
elif (Checker(t[0], a[0][0], b[0][0]) is not None) and (Checker(t[1], a[0][1], b[0][1]) is not None):
s.append(t)
for i in range(n-1):
c = Checker(t[0], a[i][0], b[i][0])
e = Checker(t[1], a[i][1], b[i][1])
if (c is not None) and (e is not None):
k = ''.join([c, e])
s.append(k)
t = k
else:
s.clear()
break
elif t == '11':
flag = False
if flag and s:
print('YES')
for i in range(n):
if s[i] == '11':
print(3, end=' ')
elif s[i] == '10':
print(2, end=' ')
elif s[i] == '01':
print(1, end=' ')
elif s[i] == '00':
print(0, end=' ')
else:
print('NO')
``` | output | 1 | 57,994 | 5 | 115,989 |
Provide a correct Python 3 solution for this coding contest problem.
When Masha came to math classes today, she saw two integer sequences of length n - 1 on the blackboard. Let's denote the elements of the first sequence as a_i (0 ≤ a_i ≤ 3), and the elements of the second sequence as b_i (0 ≤ b_i ≤ 3).
Masha became interested if or not there is an integer sequence of length n, which elements we will denote as t_i (0 ≤ t_i ≤ 3), so that for every i (1 ≤ i ≤ n - 1) the following is true:
* a_i = t_i | t_{i + 1} (where | denotes the [bitwise OR operation](https://en.wikipedia.org/wiki/Bitwise_operation#OR)) and
* b_i = t_i \& t_{i + 1} (where \& denotes the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND)).
The question appeared to be too difficult for Masha, so now she asked you to check whether such a sequence t_i of length n exists. If it exists, find such a sequence. If there are multiple such sequences, find any of them.
Input
The first line contains a single integer n (2 ≤ n ≤ 10^5) — the length of the sequence t_i.
The second line contains n - 1 integers a_1, a_2, …, a_{n-1} (0 ≤ a_i ≤ 3) — the first sequence on the blackboard.
The third line contains n - 1 integers b_1, b_2, …, b_{n-1} (0 ≤ b_i ≤ 3) — the second sequence on the blackboard.
Output
In the first line print "YES" (without quotes), if there is a sequence t_i that satisfies the conditions from the statements, and "NO" (without quotes), if there is no such sequence.
If there is such a sequence, on the second line print n integers t_1, t_2, …, t_n (0 ≤ t_i ≤ 3) — the sequence that satisfies the statements conditions.
If there are multiple answers, print any of them.
Examples
Input
4
3 3 2
1 2 0
Output
YES
1 3 2 0
Input
3
1 3
3 2
Output
NO
Note
In the first example it's easy to see that the sequence from output satisfies the given conditions:
* t_1 | t_2 = (01_2) | (11_2) = (11_2) = 3 = a_1 and t_1 \& t_2 = (01_2) \& (11_2) = (01_2) = 1 = b_1;
* t_2 | t_3 = (11_2) | (10_2) = (11_2) = 3 = a_2 and t_2 \& t_3 = (11_2) \& (10_2) = (10_2) = 2 = b_2;
* t_3 | t_4 = (10_2) | (00_2) = (10_2) = 2 = a_3 and t_3 \& t_4 = (10_2) \& (00_2) = (00_2) = 0 = b_3.
In the second example there is no such sequence. | instruction | 0 | 57,995 | 5 | 115,990 |
"Correct Solution:
```
n = int(input())
flag = 0
argsa = list(map(int, input().split()))
argsb = list(map(int, input().split()))
argst = [0]
for i in range (n-1):
for j in range (4):
if (argst[i] & j == argsb[i]) and (argst[i] | j == argsa[i]):
argst.append(j)
flag = 1
break
if not(flag):
flag = 2
break
flag = 0
if flag == 2:
flag = 0
argst = []
argst.append(1)
for i in range(n - 1):
for j in range(4):
if (argst[i] & j == argsb[i]) and (argst[i] | j == argsa[i]):
argst.append(j)
flag = 1
break
if not(flag):
flag = 2
break
flag = 0
if flag == 2:
flag = 0
argst = [2]
for i in range(n - 1):
for j in range(4):
if (argst[i] & j == argsb[i]) and (argst[i] | j == argsa[i]):
argst.append(j)
flag = 1
break
if not(flag):
flag = 2
break
flag = 0
if flag == 2:
flag = 0
argst = [3]
for i in range(n - 1):
for j in range(4):
if (argst[i] & j == argsb[i]) and (argst[i] | j == argsa[i]):
argst.append(j)
flag = 1
break
if not(flag):
flag = 2
break
flag = 0
if not(flag == 2):
print('YES',end='\n')
print(*argst)
else:
print('NO')
``` | output | 1 | 57,995 | 5 | 115,991 |
Provide a correct Python 3 solution for this coding contest problem.
When Masha came to math classes today, she saw two integer sequences of length n - 1 on the blackboard. Let's denote the elements of the first sequence as a_i (0 ≤ a_i ≤ 3), and the elements of the second sequence as b_i (0 ≤ b_i ≤ 3).
Masha became interested if or not there is an integer sequence of length n, which elements we will denote as t_i (0 ≤ t_i ≤ 3), so that for every i (1 ≤ i ≤ n - 1) the following is true:
* a_i = t_i | t_{i + 1} (where | denotes the [bitwise OR operation](https://en.wikipedia.org/wiki/Bitwise_operation#OR)) and
* b_i = t_i \& t_{i + 1} (where \& denotes the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND)).
The question appeared to be too difficult for Masha, so now she asked you to check whether such a sequence t_i of length n exists. If it exists, find such a sequence. If there are multiple such sequences, find any of them.
Input
The first line contains a single integer n (2 ≤ n ≤ 10^5) — the length of the sequence t_i.
The second line contains n - 1 integers a_1, a_2, …, a_{n-1} (0 ≤ a_i ≤ 3) — the first sequence on the blackboard.
The third line contains n - 1 integers b_1, b_2, …, b_{n-1} (0 ≤ b_i ≤ 3) — the second sequence on the blackboard.
Output
In the first line print "YES" (without quotes), if there is a sequence t_i that satisfies the conditions from the statements, and "NO" (without quotes), if there is no such sequence.
If there is such a sequence, on the second line print n integers t_1, t_2, …, t_n (0 ≤ t_i ≤ 3) — the sequence that satisfies the statements conditions.
If there are multiple answers, print any of them.
Examples
Input
4
3 3 2
1 2 0
Output
YES
1 3 2 0
Input
3
1 3
3 2
Output
NO
Note
In the first example it's easy to see that the sequence from output satisfies the given conditions:
* t_1 | t_2 = (01_2) | (11_2) = (11_2) = 3 = a_1 and t_1 \& t_2 = (01_2) \& (11_2) = (01_2) = 1 = b_1;
* t_2 | t_3 = (11_2) | (10_2) = (11_2) = 3 = a_2 and t_2 \& t_3 = (11_2) \& (10_2) = (10_2) = 2 = b_2;
* t_3 | t_4 = (10_2) | (00_2) = (10_2) = 2 = a_3 and t_3 \& t_4 = (10_2) \& (00_2) = (00_2) = 0 = b_3.
In the second example there is no such sequence. | instruction | 0 | 57,996 | 5 | 115,992 |
"Correct Solution:
```
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
for i in range(4):
c=[-1]*n
c[0]=i
for j in range(n-1):
if c[j] == -1:
break
for k in range(4):
if((c[j]|k)==a[j] and (c[j]&k)==b[j]):
c[j+1]=k
if -1 not in c:
print("YES")
print(*c)
exit(0)
print("NO")
``` | output | 1 | 57,996 | 5 | 115,993 |
Provide a correct Python 3 solution for this coding contest problem.
When Masha came to math classes today, she saw two integer sequences of length n - 1 on the blackboard. Let's denote the elements of the first sequence as a_i (0 ≤ a_i ≤ 3), and the elements of the second sequence as b_i (0 ≤ b_i ≤ 3).
Masha became interested if or not there is an integer sequence of length n, which elements we will denote as t_i (0 ≤ t_i ≤ 3), so that for every i (1 ≤ i ≤ n - 1) the following is true:
* a_i = t_i | t_{i + 1} (where | denotes the [bitwise OR operation](https://en.wikipedia.org/wiki/Bitwise_operation#OR)) and
* b_i = t_i \& t_{i + 1} (where \& denotes the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND)).
The question appeared to be too difficult for Masha, so now she asked you to check whether such a sequence t_i of length n exists. If it exists, find such a sequence. If there are multiple such sequences, find any of them.
Input
The first line contains a single integer n (2 ≤ n ≤ 10^5) — the length of the sequence t_i.
The second line contains n - 1 integers a_1, a_2, …, a_{n-1} (0 ≤ a_i ≤ 3) — the first sequence on the blackboard.
The third line contains n - 1 integers b_1, b_2, …, b_{n-1} (0 ≤ b_i ≤ 3) — the second sequence on the blackboard.
Output
In the first line print "YES" (without quotes), if there is a sequence t_i that satisfies the conditions from the statements, and "NO" (without quotes), if there is no such sequence.
If there is such a sequence, on the second line print n integers t_1, t_2, …, t_n (0 ≤ t_i ≤ 3) — the sequence that satisfies the statements conditions.
If there are multiple answers, print any of them.
Examples
Input
4
3 3 2
1 2 0
Output
YES
1 3 2 0
Input
3
1 3
3 2
Output
NO
Note
In the first example it's easy to see that the sequence from output satisfies the given conditions:
* t_1 | t_2 = (01_2) | (11_2) = (11_2) = 3 = a_1 and t_1 \& t_2 = (01_2) \& (11_2) = (01_2) = 1 = b_1;
* t_2 | t_3 = (11_2) | (10_2) = (11_2) = 3 = a_2 and t_2 \& t_3 = (11_2) \& (10_2) = (10_2) = 2 = b_2;
* t_3 | t_4 = (10_2) | (00_2) = (10_2) = 2 = a_3 and t_3 \& t_4 = (10_2) \& (00_2) = (00_2) = 0 = b_3.
In the second example there is no such sequence. | instruction | 0 | 57,997 | 5 | 115,994 |
"Correct Solution:
```
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
pos_and = [
{(0, 1), (0, 2), (0, 3), (0, 0), (1, 2)},
{(1, 3), (1, 1)},
{(2, 3), (2, 2)},
{(3, 3)}
]
pos_or = [
{(0, 0)},
{(0, 1), (1, 1)},
{(0, 2), (2, 2)},
{(0, 3), (1, 3), (2, 3), (3, 3), (1, 2)}
]
# for i in range(4):
# for j in range(4):
# print(i, j, [x for x in pos_and[i].intersection(pos_or[j])])
res1 = []
flag1 = False
for i in range(n - 1):
pairs = [x for x in pos_and[b[i]].intersection(pos_or[a[i]])]
pairs.sort()
if len(pairs) == 0:
flag1 = True
break
for pair in pairs:
rev_pair = (pair[1], pair[0])
if len(res1) == 0:
res1.append(pair[0])
res1.append(pair[1])
break
if res1[-1] == pair[0]:
res1.append(pair[1])
break
elif res1[-1] == rev_pair[0]:
res1.append(rev_pair[1])
break
if len(res1) != i + 2:
flag1 = True
break
res2 = []
flag2 = False
for i in range(n - 1):
pairs = [x for x in pos_and[b[i]].intersection(pos_or[a[i]])]
pairs.sort()
if len(pairs) == 0:
flag2 = True
break
for pair in pairs:
rev_pair = (pair[1], pair[0])
if len(res2) == 0:
res2.append(rev_pair[0])
res2.append(rev_pair[1])
break
if res2[-1] == pair[0]:
res2.append(pair[1])
break
elif res2[-1] == rev_pair[0]:
res2.append(rev_pair[1])
break
if len(res2) != i + 2:
flag2 = True
break
if flag1 and flag2 and a[0] == 3 and b[0] == 0:
res1 = []
flag1 = False
for i in range(n - 1):
pairs = [x for x in pos_and[b[i]].intersection(pos_or[a[i]])]
pairs.sort()
if len(pairs) == 0:
flag1 = True
break
for pair in pairs:
rev_pair = (pair[1], pair[0])
if len(res1) == 0:
res1.append(pairs[1][0])
res1.append(pairs[1][1])
break
if res1[-1] == pair[0]:
res1.append(pair[1])
break
elif res1[-1] == rev_pair[0]:
res1.append(rev_pair[1])
break
if len(res1) != i + 2:
flag1 = True
break
res2 = []
flag2 = False
for i in range(n - 1):
pairs = [x for x in pos_and[b[i]].intersection(pos_or[a[i]])]
pairs.sort()
if len(pairs) == 0:
flag2 = True
break
for pair in pairs:
rev_pair = (pair[1], pair[0])
if len(res2) == 0:
res2.append(pairs[1][1])
res2.append(pairs[1][0])
break
if res2[-1] == pair[0]:
res2.append(pair[1])
break
elif res2[-1] == rev_pair[0]:
res2.append(rev_pair[1])
break
if len(res2) != i + 2:
flag2 = True
break
if not flag2:
print("YES")
print(*res2)
elif not flag1:
print("YES")
print(*res1)
else:
print("NO")
``` | output | 1 | 57,997 | 5 | 115,995 |
Provide a correct Python 3 solution for this coding contest problem.
When Masha came to math classes today, she saw two integer sequences of length n - 1 on the blackboard. Let's denote the elements of the first sequence as a_i (0 ≤ a_i ≤ 3), and the elements of the second sequence as b_i (0 ≤ b_i ≤ 3).
Masha became interested if or not there is an integer sequence of length n, which elements we will denote as t_i (0 ≤ t_i ≤ 3), so that for every i (1 ≤ i ≤ n - 1) the following is true:
* a_i = t_i | t_{i + 1} (where | denotes the [bitwise OR operation](https://en.wikipedia.org/wiki/Bitwise_operation#OR)) and
* b_i = t_i \& t_{i + 1} (where \& denotes the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND)).
The question appeared to be too difficult for Masha, so now she asked you to check whether such a sequence t_i of length n exists. If it exists, find such a sequence. If there are multiple such sequences, find any of them.
Input
The first line contains a single integer n (2 ≤ n ≤ 10^5) — the length of the sequence t_i.
The second line contains n - 1 integers a_1, a_2, …, a_{n-1} (0 ≤ a_i ≤ 3) — the first sequence on the blackboard.
The third line contains n - 1 integers b_1, b_2, …, b_{n-1} (0 ≤ b_i ≤ 3) — the second sequence on the blackboard.
Output
In the first line print "YES" (without quotes), if there is a sequence t_i that satisfies the conditions from the statements, and "NO" (without quotes), if there is no such sequence.
If there is such a sequence, on the second line print n integers t_1, t_2, …, t_n (0 ≤ t_i ≤ 3) — the sequence that satisfies the statements conditions.
If there are multiple answers, print any of them.
Examples
Input
4
3 3 2
1 2 0
Output
YES
1 3 2 0
Input
3
1 3
3 2
Output
NO
Note
In the first example it's easy to see that the sequence from output satisfies the given conditions:
* t_1 | t_2 = (01_2) | (11_2) = (11_2) = 3 = a_1 and t_1 \& t_2 = (01_2) \& (11_2) = (01_2) = 1 = b_1;
* t_2 | t_3 = (11_2) | (10_2) = (11_2) = 3 = a_2 and t_2 \& t_3 = (11_2) \& (10_2) = (10_2) = 2 = b_2;
* t_3 | t_4 = (10_2) | (00_2) = (10_2) = 2 = a_3 and t_3 \& t_4 = (10_2) \& (00_2) = (00_2) = 0 = b_3.
In the second example there is no such sequence. | instruction | 0 | 57,998 | 5 | 115,996 |
"Correct Solution:
```
#Code by Sounak, IIESTS
#------------------------------warmup----------------------------
import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
import threading
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-----------------------------------------------------
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for k in range(4):
t = [-1] * n
t[0] = k
x = False
for i in range(1, n):
x = False
for j in range(4):
if a[i-1] == (j | t[i - 1]) and b[i-1] == (j & t[i - 1]):
t[i] = j
x = True
if not x:
break
if x:
print("YES")
print(*t)
exit(0)
print("NO")
``` | output | 1 | 57,998 | 5 | 115,997 |
Provide a correct Python 3 solution for this coding contest problem.
When Masha came to math classes today, she saw two integer sequences of length n - 1 on the blackboard. Let's denote the elements of the first sequence as a_i (0 ≤ a_i ≤ 3), and the elements of the second sequence as b_i (0 ≤ b_i ≤ 3).
Masha became interested if or not there is an integer sequence of length n, which elements we will denote as t_i (0 ≤ t_i ≤ 3), so that for every i (1 ≤ i ≤ n - 1) the following is true:
* a_i = t_i | t_{i + 1} (where | denotes the [bitwise OR operation](https://en.wikipedia.org/wiki/Bitwise_operation#OR)) and
* b_i = t_i \& t_{i + 1} (where \& denotes the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND)).
The question appeared to be too difficult for Masha, so now she asked you to check whether such a sequence t_i of length n exists. If it exists, find such a sequence. If there are multiple such sequences, find any of them.
Input
The first line contains a single integer n (2 ≤ n ≤ 10^5) — the length of the sequence t_i.
The second line contains n - 1 integers a_1, a_2, …, a_{n-1} (0 ≤ a_i ≤ 3) — the first sequence on the blackboard.
The third line contains n - 1 integers b_1, b_2, …, b_{n-1} (0 ≤ b_i ≤ 3) — the second sequence on the blackboard.
Output
In the first line print "YES" (without quotes), if there is a sequence t_i that satisfies the conditions from the statements, and "NO" (without quotes), if there is no such sequence.
If there is such a sequence, on the second line print n integers t_1, t_2, …, t_n (0 ≤ t_i ≤ 3) — the sequence that satisfies the statements conditions.
If there are multiple answers, print any of them.
Examples
Input
4
3 3 2
1 2 0
Output
YES
1 3 2 0
Input
3
1 3
3 2
Output
NO
Note
In the first example it's easy to see that the sequence from output satisfies the given conditions:
* t_1 | t_2 = (01_2) | (11_2) = (11_2) = 3 = a_1 and t_1 \& t_2 = (01_2) \& (11_2) = (01_2) = 1 = b_1;
* t_2 | t_3 = (11_2) | (10_2) = (11_2) = 3 = a_2 and t_2 \& t_3 = (11_2) \& (10_2) = (10_2) = 2 = b_2;
* t_3 | t_4 = (10_2) | (00_2) = (10_2) = 2 = a_3 and t_3 \& t_4 = (10_2) \& (00_2) = (00_2) = 0 = b_3.
In the second example there is no such sequence. | instruction | 0 | 57,999 | 5 | 115,998 |
"Correct Solution:
```
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
for i in range(4):
ans=[-1]*n
ans[0]=i
flag=False
for j in range(1,n):
flag=False
for k in range(4):
if a[j-1]==(k|ans[j-1]) and b[j-1]==(k&ans[j-1]):
ans[j]=k
flag=True
if not flag:
break
if flag:
print("YES")
print(*ans)
exit()
print("NO")
``` | output | 1 | 57,999 | 5 | 115,999 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
When Masha came to math classes today, she saw two integer sequences of length n - 1 on the blackboard. Let's denote the elements of the first sequence as a_i (0 ≤ a_i ≤ 3), and the elements of the second sequence as b_i (0 ≤ b_i ≤ 3).
Masha became interested if or not there is an integer sequence of length n, which elements we will denote as t_i (0 ≤ t_i ≤ 3), so that for every i (1 ≤ i ≤ n - 1) the following is true:
* a_i = t_i | t_{i + 1} (where | denotes the [bitwise OR operation](https://en.wikipedia.org/wiki/Bitwise_operation#OR)) and
* b_i = t_i \& t_{i + 1} (where \& denotes the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND)).
The question appeared to be too difficult for Masha, so now she asked you to check whether such a sequence t_i of length n exists. If it exists, find such a sequence. If there are multiple such sequences, find any of them.
Input
The first line contains a single integer n (2 ≤ n ≤ 10^5) — the length of the sequence t_i.
The second line contains n - 1 integers a_1, a_2, …, a_{n-1} (0 ≤ a_i ≤ 3) — the first sequence on the blackboard.
The third line contains n - 1 integers b_1, b_2, …, b_{n-1} (0 ≤ b_i ≤ 3) — the second sequence on the blackboard.
Output
In the first line print "YES" (without quotes), if there is a sequence t_i that satisfies the conditions from the statements, and "NO" (without quotes), if there is no such sequence.
If there is such a sequence, on the second line print n integers t_1, t_2, …, t_n (0 ≤ t_i ≤ 3) — the sequence that satisfies the statements conditions.
If there are multiple answers, print any of them.
Examples
Input
4
3 3 2
1 2 0
Output
YES
1 3 2 0
Input
3
1 3
3 2
Output
NO
Note
In the first example it's easy to see that the sequence from output satisfies the given conditions:
* t_1 | t_2 = (01_2) | (11_2) = (11_2) = 3 = a_1 and t_1 \& t_2 = (01_2) \& (11_2) = (01_2) = 1 = b_1;
* t_2 | t_3 = (11_2) | (10_2) = (11_2) = 3 = a_2 and t_2 \& t_3 = (11_2) \& (10_2) = (10_2) = 2 = b_2;
* t_3 | t_4 = (10_2) | (00_2) = (10_2) = 2 = a_3 and t_3 \& t_4 = (10_2) \& (00_2) = (00_2) = 0 = b_3.
In the second example there is no such sequence.
Submitted Solution:
```
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
mp = [[] for i in range(64)]
def getmp(a, b, t):
return mp[a + b*4 + t*16]
for i in range(4):
for j in range(4):
mp[(i | j) + (i & j) * 4 + i*16].append(j)
var = [0]
while len(var) > 0 and len(var) < n:
vv = var[-1]
i = len(var) - 1
p = getmp(a[i], b[i], vv)
if len(p) == 0:
appd = True
while len(var) > 1 and appd:
vv = var[-1]
del var[-1]
i = len(var) - 1
p = getmp(a[i], b[i], var[-1])
for t in p:
if vv < t:
p.append(t)
appd = False
break
if len(var) == 1:
if var[0] == 3:
var = []
else:
var[0] += 1
else:
var.append(p[0])
if len(var) > 0:
print('YES')
print(' '.join(map(str, var)))
else:
print('NO')
``` | instruction | 0 | 58,000 | 5 | 116,000 |
Yes | output | 1 | 58,000 | 5 | 116,001 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
When Masha came to math classes today, she saw two integer sequences of length n - 1 on the blackboard. Let's denote the elements of the first sequence as a_i (0 ≤ a_i ≤ 3), and the elements of the second sequence as b_i (0 ≤ b_i ≤ 3).
Masha became interested if or not there is an integer sequence of length n, which elements we will denote as t_i (0 ≤ t_i ≤ 3), so that for every i (1 ≤ i ≤ n - 1) the following is true:
* a_i = t_i | t_{i + 1} (where | denotes the [bitwise OR operation](https://en.wikipedia.org/wiki/Bitwise_operation#OR)) and
* b_i = t_i \& t_{i + 1} (where \& denotes the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND)).
The question appeared to be too difficult for Masha, so now she asked you to check whether such a sequence t_i of length n exists. If it exists, find such a sequence. If there are multiple such sequences, find any of them.
Input
The first line contains a single integer n (2 ≤ n ≤ 10^5) — the length of the sequence t_i.
The second line contains n - 1 integers a_1, a_2, …, a_{n-1} (0 ≤ a_i ≤ 3) — the first sequence on the blackboard.
The third line contains n - 1 integers b_1, b_2, …, b_{n-1} (0 ≤ b_i ≤ 3) — the second sequence on the blackboard.
Output
In the first line print "YES" (without quotes), if there is a sequence t_i that satisfies the conditions from the statements, and "NO" (without quotes), if there is no such sequence.
If there is such a sequence, on the second line print n integers t_1, t_2, …, t_n (0 ≤ t_i ≤ 3) — the sequence that satisfies the statements conditions.
If there are multiple answers, print any of them.
Examples
Input
4
3 3 2
1 2 0
Output
YES
1 3 2 0
Input
3
1 3
3 2
Output
NO
Note
In the first example it's easy to see that the sequence from output satisfies the given conditions:
* t_1 | t_2 = (01_2) | (11_2) = (11_2) = 3 = a_1 and t_1 \& t_2 = (01_2) \& (11_2) = (01_2) = 1 = b_1;
* t_2 | t_3 = (11_2) | (10_2) = (11_2) = 3 = a_2 and t_2 \& t_3 = (11_2) \& (10_2) = (10_2) = 2 = b_2;
* t_3 | t_4 = (10_2) | (00_2) = (10_2) = 2 = a_3 and t_3 \& t_4 = (10_2) \& (00_2) = (00_2) = 0 = b_3.
In the second example there is no such sequence.
Submitted Solution:
```
import sys
from math import *
readints=lambda:map(int, input().strip('\n').split())
n=int(input())
a=list(readints())
b=list(readints())
for t0 in range(4):
ans=[t0]
fail=False
for i in range(1,n):
last=ans[-1]
for k in range(4):
if (last|k)==a[i-1] and (last&k)==b[i-1]:
ans.append(k)
break
if len(ans)!=i+1:
fail=True
break
if not fail:
print('YES')
print(*ans, sep=' ')
sys.exit(0)
print('NO')
``` | instruction | 0 | 58,001 | 5 | 116,002 |
Yes | output | 1 | 58,001 | 5 | 116,003 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
When Masha came to math classes today, she saw two integer sequences of length n - 1 on the blackboard. Let's denote the elements of the first sequence as a_i (0 ≤ a_i ≤ 3), and the elements of the second sequence as b_i (0 ≤ b_i ≤ 3).
Masha became interested if or not there is an integer sequence of length n, which elements we will denote as t_i (0 ≤ t_i ≤ 3), so that for every i (1 ≤ i ≤ n - 1) the following is true:
* a_i = t_i | t_{i + 1} (where | denotes the [bitwise OR operation](https://en.wikipedia.org/wiki/Bitwise_operation#OR)) and
* b_i = t_i \& t_{i + 1} (where \& denotes the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND)).
The question appeared to be too difficult for Masha, so now she asked you to check whether such a sequence t_i of length n exists. If it exists, find such a sequence. If there are multiple such sequences, find any of them.
Input
The first line contains a single integer n (2 ≤ n ≤ 10^5) — the length of the sequence t_i.
The second line contains n - 1 integers a_1, a_2, …, a_{n-1} (0 ≤ a_i ≤ 3) — the first sequence on the blackboard.
The third line contains n - 1 integers b_1, b_2, …, b_{n-1} (0 ≤ b_i ≤ 3) — the second sequence on the blackboard.
Output
In the first line print "YES" (without quotes), if there is a sequence t_i that satisfies the conditions from the statements, and "NO" (without quotes), if there is no such sequence.
If there is such a sequence, on the second line print n integers t_1, t_2, …, t_n (0 ≤ t_i ≤ 3) — the sequence that satisfies the statements conditions.
If there are multiple answers, print any of them.
Examples
Input
4
3 3 2
1 2 0
Output
YES
1 3 2 0
Input
3
1 3
3 2
Output
NO
Note
In the first example it's easy to see that the sequence from output satisfies the given conditions:
* t_1 | t_2 = (01_2) | (11_2) = (11_2) = 3 = a_1 and t_1 \& t_2 = (01_2) \& (11_2) = (01_2) = 1 = b_1;
* t_2 | t_3 = (11_2) | (10_2) = (11_2) = 3 = a_2 and t_2 \& t_3 = (11_2) \& (10_2) = (10_2) = 2 = b_2;
* t_3 | t_4 = (10_2) | (00_2) = (10_2) = 2 = a_3 and t_3 \& t_4 = (10_2) \& (00_2) = (00_2) = 0 = b_3.
In the second example there is no such sequence.
Submitted Solution:
```
def my(a, b, c):
for x, y in zip(a, b):
for z in range(4):
if c[-1] | z == x and c[-1] & z == y:
c += [z]
break
else:
return []
return c
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
for i in range(4):
t = my(a, b, [i])
if t:
print('YES')
print(*t)
break
else:
print('NO')
``` | instruction | 0 | 58,002 | 5 | 116,004 |
Yes | output | 1 | 58,002 | 5 | 116,005 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
When Masha came to math classes today, she saw two integer sequences of length n - 1 on the blackboard. Let's denote the elements of the first sequence as a_i (0 ≤ a_i ≤ 3), and the elements of the second sequence as b_i (0 ≤ b_i ≤ 3).
Masha became interested if or not there is an integer sequence of length n, which elements we will denote as t_i (0 ≤ t_i ≤ 3), so that for every i (1 ≤ i ≤ n - 1) the following is true:
* a_i = t_i | t_{i + 1} (where | denotes the [bitwise OR operation](https://en.wikipedia.org/wiki/Bitwise_operation#OR)) and
* b_i = t_i \& t_{i + 1} (where \& denotes the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND)).
The question appeared to be too difficult for Masha, so now she asked you to check whether such a sequence t_i of length n exists. If it exists, find such a sequence. If there are multiple such sequences, find any of them.
Input
The first line contains a single integer n (2 ≤ n ≤ 10^5) — the length of the sequence t_i.
The second line contains n - 1 integers a_1, a_2, …, a_{n-1} (0 ≤ a_i ≤ 3) — the first sequence on the blackboard.
The third line contains n - 1 integers b_1, b_2, …, b_{n-1} (0 ≤ b_i ≤ 3) — the second sequence on the blackboard.
Output
In the first line print "YES" (without quotes), if there is a sequence t_i that satisfies the conditions from the statements, and "NO" (without quotes), if there is no such sequence.
If there is such a sequence, on the second line print n integers t_1, t_2, …, t_n (0 ≤ t_i ≤ 3) — the sequence that satisfies the statements conditions.
If there are multiple answers, print any of them.
Examples
Input
4
3 3 2
1 2 0
Output
YES
1 3 2 0
Input
3
1 3
3 2
Output
NO
Note
In the first example it's easy to see that the sequence from output satisfies the given conditions:
* t_1 | t_2 = (01_2) | (11_2) = (11_2) = 3 = a_1 and t_1 \& t_2 = (01_2) \& (11_2) = (01_2) = 1 = b_1;
* t_2 | t_3 = (11_2) | (10_2) = (11_2) = 3 = a_2 and t_2 \& t_3 = (11_2) \& (10_2) = (10_2) = 2 = b_2;
* t_3 | t_4 = (10_2) | (00_2) = (10_2) = 2 = a_3 and t_3 \& t_4 = (10_2) \& (00_2) = (00_2) = 0 = b_3.
In the second example there is no such sequence.
Submitted Solution:
```
n = int(input())
arr = list(map(int, input().split()))
brr = list(map(int, input().split()))
trr = [0 for i in range(n)]
for j in range(4):
trr[0] = j
fl = True
for i in range(n - 1):
if arr[i] == brr[i]:
if trr[i] != arr[i]:
fl = False
break
trr[i + 1] = arr[i]
else:
if brr[i] == 3:
fl = False
break
if brr[i] == 2:
if arr[i] == 3:
if trr[i] == 2:
trr[i + 1] = 3
elif trr[i] == 3:
trr[i + 1] = 2
else:
fl = False
break
else:
fl = False
break
if brr[i] == 1:
if arr[i] == 3:
if trr[i] == 1:
trr[i + 1] = 3
elif trr[i] == 3:
trr[i + 1] = 1
else:
fl = False
break
else:
fl = False
break
if brr[i] == 0:
if arr[i] == 1:
if trr[i] == 0:
trr[i + 1] = 1
elif trr[i] == 1:
trr[i + 1] = 0
else:
fl = False
break
elif arr[i] == 2:
if trr[i] == 2:
trr[i + 1] = 0
elif trr[i] == 0:
trr[i + 1] = 2
else:
fl = False
break
else:
if trr[i] == 1:
trr[i + 1] = 2
elif trr[i] == 2:
trr[i + 1] = 1
elif trr[i] == 3:
trr[i + 1] = 0
else:
trr[i + 1] = 3
#print(trr)
if fl:
print('YES')
print(*trr)
break
else:
print('NO')
``` | instruction | 0 | 58,003 | 5 | 116,006 |
Yes | output | 1 | 58,003 | 5 | 116,007 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
When Masha came to math classes today, she saw two integer sequences of length n - 1 on the blackboard. Let's denote the elements of the first sequence as a_i (0 ≤ a_i ≤ 3), and the elements of the second sequence as b_i (0 ≤ b_i ≤ 3).
Masha became interested if or not there is an integer sequence of length n, which elements we will denote as t_i (0 ≤ t_i ≤ 3), so that for every i (1 ≤ i ≤ n - 1) the following is true:
* a_i = t_i | t_{i + 1} (where | denotes the [bitwise OR operation](https://en.wikipedia.org/wiki/Bitwise_operation#OR)) and
* b_i = t_i \& t_{i + 1} (where \& denotes the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND)).
The question appeared to be too difficult for Masha, so now she asked you to check whether such a sequence t_i of length n exists. If it exists, find such a sequence. If there are multiple such sequences, find any of them.
Input
The first line contains a single integer n (2 ≤ n ≤ 10^5) — the length of the sequence t_i.
The second line contains n - 1 integers a_1, a_2, …, a_{n-1} (0 ≤ a_i ≤ 3) — the first sequence on the blackboard.
The third line contains n - 1 integers b_1, b_2, …, b_{n-1} (0 ≤ b_i ≤ 3) — the second sequence on the blackboard.
Output
In the first line print "YES" (without quotes), if there is a sequence t_i that satisfies the conditions from the statements, and "NO" (without quotes), if there is no such sequence.
If there is such a sequence, on the second line print n integers t_1, t_2, …, t_n (0 ≤ t_i ≤ 3) — the sequence that satisfies the statements conditions.
If there are multiple answers, print any of them.
Examples
Input
4
3 3 2
1 2 0
Output
YES
1 3 2 0
Input
3
1 3
3 2
Output
NO
Note
In the first example it's easy to see that the sequence from output satisfies the given conditions:
* t_1 | t_2 = (01_2) | (11_2) = (11_2) = 3 = a_1 and t_1 \& t_2 = (01_2) \& (11_2) = (01_2) = 1 = b_1;
* t_2 | t_3 = (11_2) | (10_2) = (11_2) = 3 = a_2 and t_2 \& t_3 = (11_2) \& (10_2) = (10_2) = 2 = b_2;
* t_3 | t_4 = (10_2) | (00_2) = (10_2) = 2 = a_3 and t_3 \& t_4 = (10_2) \& (00_2) = (00_2) = 0 = b_3.
In the second example there is no such sequence.
Submitted Solution:
```
n = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [-1] * n * 2
for i in range(n-1):
if A[i] & 2 == 0:
C[i * 2] = 0
C[(i+1) * 2] = 0
if A[i] & 1 == 0:
C[i * 2 + 1] = 0
C[(i+1) * 2 + 1] = 0
f = True
for i in range(n-1):
if B[i] & 2 == 2:
if (C[i * 2] == 0) or (C[(i+1) * 2] == 0):
f = False
break
else:
C[i * 2] = 1
C[(i+1) * 2] = 1
if B[i] & 1 == 1:
if (C[i * 2 + 1] == 0) or (C[(i+1) * 2 + 1] == 0):
f = False
break
else:
C[i * 2 + 1] = 1
C[(i+1) * 2 + 1] = 1
R = [0] * n
for i in range(n-1):
if C[i*2] == -1:
if (A[i] & 2 & B[i] == 2):
C[i*2] = 1
if C[i*2 + 1] == -1:
if (A[i] & 1 & B[i] == 1):
C[i*2 + 1] = 1
if C[(n-1)*2] == -1:
if (A[n-2] & 2 & B[n-2]== 2):
C[(n-1)*2] = 1
if C[(n-1)*2 + 1] == -1:
if (A[n-2] & 1 & B[n-2]== 1):
C[(n-1)*2 + 1] = 1
if f:
print("YES")
for i in range(n):
if C[i * 2] == 1:
R[i] = 2
if C[i * 2 + 1] == 1:
R[i] = R[i] | 1
for i in range(n):
print(R[i], end=' ')
else:
print("NO")
``` | instruction | 0 | 58,004 | 5 | 116,008 |
No | output | 1 | 58,004 | 5 | 116,009 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
When Masha came to math classes today, she saw two integer sequences of length n - 1 on the blackboard. Let's denote the elements of the first sequence as a_i (0 ≤ a_i ≤ 3), and the elements of the second sequence as b_i (0 ≤ b_i ≤ 3).
Masha became interested if or not there is an integer sequence of length n, which elements we will denote as t_i (0 ≤ t_i ≤ 3), so that for every i (1 ≤ i ≤ n - 1) the following is true:
* a_i = t_i | t_{i + 1} (where | denotes the [bitwise OR operation](https://en.wikipedia.org/wiki/Bitwise_operation#OR)) and
* b_i = t_i \& t_{i + 1} (where \& denotes the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND)).
The question appeared to be too difficult for Masha, so now she asked you to check whether such a sequence t_i of length n exists. If it exists, find such a sequence. If there are multiple such sequences, find any of them.
Input
The first line contains a single integer n (2 ≤ n ≤ 10^5) — the length of the sequence t_i.
The second line contains n - 1 integers a_1, a_2, …, a_{n-1} (0 ≤ a_i ≤ 3) — the first sequence on the blackboard.
The third line contains n - 1 integers b_1, b_2, …, b_{n-1} (0 ≤ b_i ≤ 3) — the second sequence on the blackboard.
Output
In the first line print "YES" (without quotes), if there is a sequence t_i that satisfies the conditions from the statements, and "NO" (without quotes), if there is no such sequence.
If there is such a sequence, on the second line print n integers t_1, t_2, …, t_n (0 ≤ t_i ≤ 3) — the sequence that satisfies the statements conditions.
If there are multiple answers, print any of them.
Examples
Input
4
3 3 2
1 2 0
Output
YES
1 3 2 0
Input
3
1 3
3 2
Output
NO
Note
In the first example it's easy to see that the sequence from output satisfies the given conditions:
* t_1 | t_2 = (01_2) | (11_2) = (11_2) = 3 = a_1 and t_1 \& t_2 = (01_2) \& (11_2) = (01_2) = 1 = b_1;
* t_2 | t_3 = (11_2) | (10_2) = (11_2) = 3 = a_2 and t_2 \& t_3 = (11_2) \& (10_2) = (10_2) = 2 = b_2;
* t_3 | t_4 = (10_2) | (00_2) = (10_2) = 2 = a_3 and t_3 \& t_4 = (10_2) \& (00_2) = (00_2) = 0 = b_3.
In the second example there is no such sequence.
Submitted Solution:
```
n = int(input())
lst1 = [int(x) for x in input().split()]
lst2 = [int(x) for x in input().split()]
a = max(lst1[0], lst2[0])
f = False
for x in range(n - 1):
if lst1[x] * lst2[x] == 2 or lst1[x] < lst2[x]:
f = True
print("NO")
break
if not f:
for x in range(n - 2):
if lst2[x] != lst1[x + 1]:
f = True
print("NO")
break
if not f:
print("YES")
print(min(lst1[0], lst2[0]), a, end = ' ')
for x in range(1, n - 1):
print(lst2[x], end = ' ')
``` | instruction | 0 | 58,005 | 5 | 116,010 |
No | output | 1 | 58,005 | 5 | 116,011 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
When Masha came to math classes today, she saw two integer sequences of length n - 1 on the blackboard. Let's denote the elements of the first sequence as a_i (0 ≤ a_i ≤ 3), and the elements of the second sequence as b_i (0 ≤ b_i ≤ 3).
Masha became interested if or not there is an integer sequence of length n, which elements we will denote as t_i (0 ≤ t_i ≤ 3), so that for every i (1 ≤ i ≤ n - 1) the following is true:
* a_i = t_i | t_{i + 1} (where | denotes the [bitwise OR operation](https://en.wikipedia.org/wiki/Bitwise_operation#OR)) and
* b_i = t_i \& t_{i + 1} (where \& denotes the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND)).
The question appeared to be too difficult for Masha, so now she asked you to check whether such a sequence t_i of length n exists. If it exists, find such a sequence. If there are multiple such sequences, find any of them.
Input
The first line contains a single integer n (2 ≤ n ≤ 10^5) — the length of the sequence t_i.
The second line contains n - 1 integers a_1, a_2, …, a_{n-1} (0 ≤ a_i ≤ 3) — the first sequence on the blackboard.
The third line contains n - 1 integers b_1, b_2, …, b_{n-1} (0 ≤ b_i ≤ 3) — the second sequence on the blackboard.
Output
In the first line print "YES" (without quotes), if there is a sequence t_i that satisfies the conditions from the statements, and "NO" (without quotes), if there is no such sequence.
If there is such a sequence, on the second line print n integers t_1, t_2, …, t_n (0 ≤ t_i ≤ 3) — the sequence that satisfies the statements conditions.
If there are multiple answers, print any of them.
Examples
Input
4
3 3 2
1 2 0
Output
YES
1 3 2 0
Input
3
1 3
3 2
Output
NO
Note
In the first example it's easy to see that the sequence from output satisfies the given conditions:
* t_1 | t_2 = (01_2) | (11_2) = (11_2) = 3 = a_1 and t_1 \& t_2 = (01_2) \& (11_2) = (01_2) = 1 = b_1;
* t_2 | t_3 = (11_2) | (10_2) = (11_2) = 3 = a_2 and t_2 \& t_3 = (11_2) \& (10_2) = (10_2) = 2 = b_2;
* t_3 | t_4 = (10_2) | (00_2) = (10_2) = 2 = a_3 and t_3 \& t_4 = (10_2) \& (00_2) = (00_2) = 0 = b_3.
In the second example there is no such sequence.
Submitted Solution:
```
n = int(input())
keys = {(0, 0): [(0, 0)],
(0, 1): [(0, 1), (1, 0)],
(0, 2): [(0, 2), (2, 0)],
(0, 3): [(0, 3), (1, 2), (2, 1), (3, 0)],
(1, 1): [(1, 1)],
(1, 3): [(1, 3), (3, 1)],
(2, 2): [(2, 2)],
(2, 3): [(2, 3), (3, 2)],
(3, 3): [(3, 3)]}
b = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
f = False
arr = []
try:
if n > 3:
for key in keys[(a[0], b[0])]:
f = False
arr[0:2] = key
for i in range(n - 2):
prev = arr[-1]
for k in keys[(a[i + 1], b[i + 1])]:
if k[0] == prev:
arr[i + 1 : i + 3] = k
break
else:
f = True
break
if f:
break
else:
print('YES')
print(*arr)
break
else:
print('NO')
elif n == 3:
for key in keys[(a[0], b[0])]:
if f:
break
arr[0:2] = key
prev = arr[-1]
for k in keys[(a[1], b[1])]:
if k[0] == prev:
arr[1:3] = k
print('YES')
print(*arr)
f = True
break
if not f:
print('NO')
elif n == 2:
if keys[(a[0], b[0])]:
print('YES')
print(*keys[(a[0], b[0])][0])
else:
print('NO')
except:
print('NO')
``` | instruction | 0 | 58,006 | 5 | 116,012 |
No | output | 1 | 58,006 | 5 | 116,013 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
When Masha came to math classes today, she saw two integer sequences of length n - 1 on the blackboard. Let's denote the elements of the first sequence as a_i (0 ≤ a_i ≤ 3), and the elements of the second sequence as b_i (0 ≤ b_i ≤ 3).
Masha became interested if or not there is an integer sequence of length n, which elements we will denote as t_i (0 ≤ t_i ≤ 3), so that for every i (1 ≤ i ≤ n - 1) the following is true:
* a_i = t_i | t_{i + 1} (where | denotes the [bitwise OR operation](https://en.wikipedia.org/wiki/Bitwise_operation#OR)) and
* b_i = t_i \& t_{i + 1} (where \& denotes the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND)).
The question appeared to be too difficult for Masha, so now she asked you to check whether such a sequence t_i of length n exists. If it exists, find such a sequence. If there are multiple such sequences, find any of them.
Input
The first line contains a single integer n (2 ≤ n ≤ 10^5) — the length of the sequence t_i.
The second line contains n - 1 integers a_1, a_2, …, a_{n-1} (0 ≤ a_i ≤ 3) — the first sequence on the blackboard.
The third line contains n - 1 integers b_1, b_2, …, b_{n-1} (0 ≤ b_i ≤ 3) — the second sequence on the blackboard.
Output
In the first line print "YES" (without quotes), if there is a sequence t_i that satisfies the conditions from the statements, and "NO" (without quotes), if there is no such sequence.
If there is such a sequence, on the second line print n integers t_1, t_2, …, t_n (0 ≤ t_i ≤ 3) — the sequence that satisfies the statements conditions.
If there are multiple answers, print any of them.
Examples
Input
4
3 3 2
1 2 0
Output
YES
1 3 2 0
Input
3
1 3
3 2
Output
NO
Note
In the first example it's easy to see that the sequence from output satisfies the given conditions:
* t_1 | t_2 = (01_2) | (11_2) = (11_2) = 3 = a_1 and t_1 \& t_2 = (01_2) \& (11_2) = (01_2) = 1 = b_1;
* t_2 | t_3 = (11_2) | (10_2) = (11_2) = 3 = a_2 and t_2 \& t_3 = (11_2) \& (10_2) = (10_2) = 2 = b_2;
* t_3 | t_4 = (10_2) | (00_2) = (10_2) = 2 = a_3 and t_3 \& t_4 = (10_2) \& (00_2) = (00_2) = 0 = b_3.
In the second example there is no such sequence.
Submitted Solution:
```
n = int(input())
A = list(str(input()).split(' '))
for i in range(len(A)):
A[i] = int(A[i])
B = list(str(input()).split(' '))
for i in range(len(B)):
B[i] = int(B[i])
sum = 0
C = [0]*n
c = 0
d = 0
f = 16
for i in range(n-1):
for j in range(f):
if (A[i] == (c | d)) and (B[i] == (c & d)):
sum += 1
C[i] = c
C[i + 1] = d
c = d
d = 0
f = 4
break
else:
if f == 16 and d == 3:
d = 0
c += 1
elif d == 3 and c == 3:
break
else:
d += 1
if sum == 0:
print('NO')
elif sum == n-1:
for i in range(len(C)):
C[i] = str(C[i])
print('YES')
print(' '.join(C))
``` | instruction | 0 | 58,007 | 5 | 116,014 |
No | output | 1 | 58,007 | 5 | 116,015 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Karen has just arrived at school, and she has a math test today!
<image>
The test is about basic addition and subtraction. Unfortunately, the teachers were too busy writing tasks for Codeforces rounds, and had no time to make an actual test. So, they just put one question in the test that is worth all the points.
There are n integers written on a row. Karen must alternately add and subtract each pair of adjacent integers, and write down the sums or differences on the next row. She must repeat this process on the values on the next row, and so on, until only one integer remains. The first operation should be addition.
Note that, if she ended the previous row by adding the integers, she should start the next row by subtracting, and vice versa.
The teachers will simply look at the last integer, and then if it is correct, Karen gets a perfect score, otherwise, she gets a zero for the test.
Karen has studied well for this test, but she is scared that she might make a mistake somewhere and it will cause her final answer to be wrong. If the process is followed, what number can she expect to be written on the last row?
Since this number can be quite large, output only the non-negative remainder after dividing it by 109 + 7.
Input
The first line of input contains a single integer n (1 ≤ n ≤ 200000), the number of numbers written on the first row.
The next line contains n integers. Specifically, the i-th one among these is ai (1 ≤ ai ≤ 109), the i-th number on the first row.
Output
Output a single integer on a line by itself, the number on the final row after performing the process above.
Since this number can be quite large, print only the non-negative remainder after dividing it by 109 + 7.
Examples
Input
5
3 6 9 12 15
Output
36
Input
4
3 7 5 2
Output
1000000006
Note
In the first test case, the numbers written on the first row are 3, 6, 9, 12 and 15.
Karen performs the operations as follows:
<image>
The non-negative remainder after dividing the final number by 109 + 7 is still 36, so this is the correct output.
In the second test case, the numbers written on the first row are 3, 7, 5 and 2.
Karen performs the operations as follows:
<image>
The non-negative remainder after dividing the final number by 109 + 7 is 109 + 6, so this is the correct output.
Submitted Solution:
```
MOD=10**9+7
N=int(input())
if N%4==0:
K=N//2-1
elif N%4==1:
K=(N-1)//2
elif N%4==2:
K=N//2-1
else:
K=(N-3)//2
fact=[1]
invfact=[1]
for i in range(1,K+1):
temp=fact[i-1]*i
temp%=MOD
fact+=[temp]
temp=invfact[i-1]*pow(i,MOD-2,MOD)
temp%=MOD
invfact+=[temp]
def bino(a,b):
temp=fact[a]*invfact[a-b]*invfact[b]
temp%=MOD
return temp
A=list(map(int,input().strip().split(' ')))
a=[0]+A
#print(a,'a')
print(K)
ans=0
if N%4==0:
for r in range(K+1):
ans+=bino(K,r)*a[2*r+1]
ans-=bino(K,r)*a[2*r+2]
ans%=MOD
elif N%4==1:
ans=0
for r in range(K+1):
ans+=a[2*r+1]*bino(K,r)
ans%=MOD
elif N%4==2:
for r in range(K+1):
ans+=(a[2*r+1]+a[2*r+2])*bino(K,r)
ans%=MOD
elif N%4==3:
ans=a[1]-a[N]
for j in range(1,K+1):
ans+=(bino(K,j)-bino(K,j))*a[2*j+1]
ans%=MOD
for j in range(K+1):
ans+=2*bino(K,j)*a[2*j+2]
ans%=MOD
print(ans)
``` | instruction | 0 | 58,577 | 5 | 117,154 |
No | output | 1 | 58,577 | 5 | 117,155 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Karen has just arrived at school, and she has a math test today!
<image>
The test is about basic addition and subtraction. Unfortunately, the teachers were too busy writing tasks for Codeforces rounds, and had no time to make an actual test. So, they just put one question in the test that is worth all the points.
There are n integers written on a row. Karen must alternately add and subtract each pair of adjacent integers, and write down the sums or differences on the next row. She must repeat this process on the values on the next row, and so on, until only one integer remains. The first operation should be addition.
Note that, if she ended the previous row by adding the integers, she should start the next row by subtracting, and vice versa.
The teachers will simply look at the last integer, and then if it is correct, Karen gets a perfect score, otherwise, she gets a zero for the test.
Karen has studied well for this test, but she is scared that she might make a mistake somewhere and it will cause her final answer to be wrong. If the process is followed, what number can she expect to be written on the last row?
Since this number can be quite large, output only the non-negative remainder after dividing it by 109 + 7.
Input
The first line of input contains a single integer n (1 ≤ n ≤ 200000), the number of numbers written on the first row.
The next line contains n integers. Specifically, the i-th one among these is ai (1 ≤ ai ≤ 109), the i-th number on the first row.
Output
Output a single integer on a line by itself, the number on the final row after performing the process above.
Since this number can be quite large, print only the non-negative remainder after dividing it by 109 + 7.
Examples
Input
5
3 6 9 12 15
Output
36
Input
4
3 7 5 2
Output
1000000006
Note
In the first test case, the numbers written on the first row are 3, 6, 9, 12 and 15.
Karen performs the operations as follows:
<image>
The non-negative remainder after dividing the final number by 109 + 7 is still 36, so this is the correct output.
In the second test case, the numbers written on the first row are 3, 7, 5 and 2.
Karen performs the operations as follows:
<image>
The non-negative remainder after dividing the final number by 109 + 7 is 109 + 6, so this is the correct output.
Submitted Solution:
```
n = int(input())
string = input()
numbers = string.split(" ")
row = []
for x in numbers:
row.append(int(x))
item = 0
while len(row) != 1:
temp = []
for x in range(len(row) - 1):
item += 1
if item % 2 == 0:
new = row[x] + row[x + 1]
else:
new = row[x] - row[x + 1]
temp.append(new)
row = temp
print(int(row[0]) % (10 ** 9 + 7))
``` | instruction | 0 | 58,578 | 5 | 117,156 |
No | output | 1 | 58,578 | 5 | 117,157 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Karen has just arrived at school, and she has a math test today!
<image>
The test is about basic addition and subtraction. Unfortunately, the teachers were too busy writing tasks for Codeforces rounds, and had no time to make an actual test. So, they just put one question in the test that is worth all the points.
There are n integers written on a row. Karen must alternately add and subtract each pair of adjacent integers, and write down the sums or differences on the next row. She must repeat this process on the values on the next row, and so on, until only one integer remains. The first operation should be addition.
Note that, if she ended the previous row by adding the integers, she should start the next row by subtracting, and vice versa.
The teachers will simply look at the last integer, and then if it is correct, Karen gets a perfect score, otherwise, she gets a zero for the test.
Karen has studied well for this test, but she is scared that she might make a mistake somewhere and it will cause her final answer to be wrong. If the process is followed, what number can she expect to be written on the last row?
Since this number can be quite large, output only the non-negative remainder after dividing it by 109 + 7.
Input
The first line of input contains a single integer n (1 ≤ n ≤ 200000), the number of numbers written on the first row.
The next line contains n integers. Specifically, the i-th one among these is ai (1 ≤ ai ≤ 109), the i-th number on the first row.
Output
Output a single integer on a line by itself, the number on the final row after performing the process above.
Since this number can be quite large, print only the non-negative remainder after dividing it by 109 + 7.
Examples
Input
5
3 6 9 12 15
Output
36
Input
4
3 7 5 2
Output
1000000006
Note
In the first test case, the numbers written on the first row are 3, 6, 9, 12 and 15.
Karen performs the operations as follows:
<image>
The non-negative remainder after dividing the final number by 109 + 7 is still 36, so this is the correct output.
In the second test case, the numbers written on the first row are 3, 7, 5 and 2.
Karen performs the operations as follows:
<image>
The non-negative remainder after dividing the final number by 109 + 7 is 109 + 6, so this is the correct output.
Submitted Solution:
```
"""
5
3 6 9 12 15 should output 36
4
3 7 5 2 should output 1000000006
"""
from typing import List
MOD = 10 ** 9 + 7;
def mod_inv(n: int) -> int:
return pow(n, MOD - 2, MOD)
def tri_sum(row: List[int]) -> int:
pascal_row = [1]
for i in range(1, len(row)):
last = pascal_row[-1]
curr = (last * (len(row) - i) * mod_inv(i))
pascal_row.append(curr)
total = 0
for contrib, val in zip(pascal_row, row):
total = (total + contrib * val) % MOD
return total
row_len = int(input())
row = [int(i) for i in input().split()]
if len(row) != row_len:
raise ValueError(f"the lengths {row_len} and {len(row)} are different so uh yeah")
if row_len % 2 == 1:
row_len -= 1
new_row = []
for i in range(row_len):
new_row.append(row[i] + row[i + 1] if i % 2 == 0 else row[i] - row[i + 1])
row = new_row
alt_rows = [[], []]
for i, v in enumerate(row):
alt_rows[i % 2].append(v)
first = tri_sum(alt_rows[0])
second = tri_sum(alt_rows[1])
ans = (first + second if ((row_len - 1) * row_len // 2) % 2 == 1 else first - second) % MOD
print(ans)
``` | instruction | 0 | 58,579 | 5 | 117,158 |
No | output | 1 | 58,579 | 5 | 117,159 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Karen has just arrived at school, and she has a math test today!
<image>
The test is about basic addition and subtraction. Unfortunately, the teachers were too busy writing tasks for Codeforces rounds, and had no time to make an actual test. So, they just put one question in the test that is worth all the points.
There are n integers written on a row. Karen must alternately add and subtract each pair of adjacent integers, and write down the sums or differences on the next row. She must repeat this process on the values on the next row, and so on, until only one integer remains. The first operation should be addition.
Note that, if she ended the previous row by adding the integers, she should start the next row by subtracting, and vice versa.
The teachers will simply look at the last integer, and then if it is correct, Karen gets a perfect score, otherwise, she gets a zero for the test.
Karen has studied well for this test, but she is scared that she might make a mistake somewhere and it will cause her final answer to be wrong. If the process is followed, what number can she expect to be written on the last row?
Since this number can be quite large, output only the non-negative remainder after dividing it by 109 + 7.
Input
The first line of input contains a single integer n (1 ≤ n ≤ 200000), the number of numbers written on the first row.
The next line contains n integers. Specifically, the i-th one among these is ai (1 ≤ ai ≤ 109), the i-th number on the first row.
Output
Output a single integer on a line by itself, the number on the final row after performing the process above.
Since this number can be quite large, print only the non-negative remainder after dividing it by 109 + 7.
Examples
Input
5
3 6 9 12 15
Output
36
Input
4
3 7 5 2
Output
1000000006
Note
In the first test case, the numbers written on the first row are 3, 6, 9, 12 and 15.
Karen performs the operations as follows:
<image>
The non-negative remainder after dividing the final number by 109 + 7 is still 36, so this is the correct output.
In the second test case, the numbers written on the first row are 3, 7, 5 and 2.
Karen performs the operations as follows:
<image>
The non-negative remainder after dividing the final number by 109 + 7 is 109 + 6, so this is the correct output.
Submitted Solution:
```
from math import factorial
import sys
#Como 10^9+7 es primo entonces podemos calcular el
# inverso multiplicativo aplicando Fermat
def MultiplicativeModularInverse(a, mod):
p=mod-2
answer=1
while p:
if p%2==0:
a=a*a%mod
p=p/2
else:
answer=answer*a%mod
p=(p-1)/2
return answer
def CreateFact(n,mod):
cant=n+1
factorials=[1]*cant
for x in range(1,cant):
val=factorials[x-1]*x%mod
factorials[x]=val
inv_factorial=[1]*cant
inv_factorial[n]=pow(factorials[-1], mod - 2, mod)
for x in reversed(range(0,n)):
val=inv_factorial[x+1]*(x+1)%mod
inv_factorial[x]=val
return factorials,inv_factorial
def CalculateNPairsCoef(n,mod):
factorial,inv_factorial=CreateFact(n,mod)
coef=[1]*n
middle=int((n+1)/2)
last=n-1
for x in range(1,middle):
o=factorial[n-1]*inv_factorial[n-1-x]%mod*inv_factorial[x]%mod
coef[x]=o
coef[last-x]=o
return coef
def KarenAdTest():
n=int(sys.stdin.readline())
line =sys.stdin.readline().split()
i=0
while i<n:
x=int(line[i])
line[i]=x
i+=1
mod=1000000007
if n==1:
val=line[0]%mod
print(val)
return
if n==2:
val=(line[0]+line[1])%mod
print(val)
return
if n==3:
val=(line[0]+2*line[1]-line[2])%mod
print(val)
return
if n==4:
val=(line[0]-line[1]+line[2]-line[3])%mod
print(val)
return
if n==5:
val=(line[0]+2*line[2]+line[4])%mod
print(val)
return
#si el numero es mayor que 5 valos a calcular sus coeficientes finales
#Como es multiplo de 2 se calcula directo los coeficientes d la primera fila
#que son los d los n valores iniciles
coefi=[1]*n
if n%2==0:
m=int(n/2)
c=CalculateNPairsCoef(m,mod)
pos=0
if n%4==0:
for x in range(0,m):
coefi[pos]=c[x]
pos+=1
coefi[pos]=-c[x]
pos+=1
else:
for x in range(0,m):
coefi[pos]=c[x]
pos+=1
coefi[pos]=c[x]
pos+=1
#Como no es multiplo de dos se calculan los coeficientes d la 2da fila
else:
sr=n-1
m=int(sr/2)
c=CalculateNPairsCoef(m,mod)
co=[1]*n
pos=0
for x in range(0,m):
co[pos]=c[x]
pos+=1
co[pos]=c[x]
pos+=1
if n%4==1:
coefi=[0]*n
coefi[1]=1
for x in range(2,n,2):
coefi[x]=co[x-1]+co[x]
else:
for x in range(1,n):
coefi[x]=co[x-1]+co[x]
res=0
for x in range(0,n):
res+=coefi[x]*line[x]%mod
res=int(res%mod)
print(res)
KarenAdTest()
``` | instruction | 0 | 58,580 | 5 | 117,160 |
No | output | 1 | 58,580 | 5 | 117,161 |
Provide a correct Python 3 solution for this coding contest problem.
We have N integers. The i-th integer is A_i.
Find \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} (A_i \mbox{ XOR } A_j), modulo (10^9+7).
What is \mbox{ XOR }?
The XOR of integers A and B, A \mbox{ XOR } B, is defined as follows:
* When A \mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.
For example, 3 \mbox{ XOR } 5 = 6. (In base two: 011 \mbox{ XOR } 101 = 110.)
Constraints
* 2 \leq N \leq 3 \times 10^5
* 0 \leq A_i < 2^{60}
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
Output
Print the value \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} (A_i \mbox{ XOR } A_j), modulo (10^9+7).
Examples
Input
3
1 2 3
Output
6
Input
10
3 1 4 1 5 9 2 6 5 3
Output
237
Input
10
3 14 159 2653 58979 323846 2643383 27950288 419716939 9375105820
Output
103715602 | instruction | 0 | 58,682 | 5 | 117,364 |
"Correct Solution:
```
N=int(input())
bin_a="".join(["{:060b}".format(a) for a in map(int, input().split())])
mod=10**9+7
xor=0
for d in range(60):
ones=bin_a[59-d::60].count('1')
xor+=2**d*ones*(N-ones)
print(xor%mod)
``` | output | 1 | 58,682 | 5 | 117,365 |
Provide a correct Python 3 solution for this coding contest problem.
We have N integers. The i-th integer is A_i.
Find \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} (A_i \mbox{ XOR } A_j), modulo (10^9+7).
What is \mbox{ XOR }?
The XOR of integers A and B, A \mbox{ XOR } B, is defined as follows:
* When A \mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.
For example, 3 \mbox{ XOR } 5 = 6. (In base two: 011 \mbox{ XOR } 101 = 110.)
Constraints
* 2 \leq N \leq 3 \times 10^5
* 0 \leq A_i < 2^{60}
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
Output
Print the value \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} (A_i \mbox{ XOR } A_j), modulo (10^9+7).
Examples
Input
3
1 2 3
Output
6
Input
10
3 1 4 1 5 9 2 6 5 3
Output
237
Input
10
3 14 159 2653 58979 323846 2643383 27950288 419716939 9375105820
Output
103715602 | instruction | 0 | 58,683 | 5 | 117,366 |
"Correct Solution:
```
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
ans=0
for i in range(60):
on=0
off=0
for j in a:
if (j>>i)&1:
on+=1
else:
off+=1
ans+=(on*off)*(2**i)
ans%=mod
print(ans)
``` | output | 1 | 58,683 | 5 | 117,367 |
Provide a correct Python 3 solution for this coding contest problem.
We have N integers. The i-th integer is A_i.
Find \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} (A_i \mbox{ XOR } A_j), modulo (10^9+7).
What is \mbox{ XOR }?
The XOR of integers A and B, A \mbox{ XOR } B, is defined as follows:
* When A \mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.
For example, 3 \mbox{ XOR } 5 = 6. (In base two: 011 \mbox{ XOR } 101 = 110.)
Constraints
* 2 \leq N \leq 3 \times 10^5
* 0 \leq A_i < 2^{60}
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
Output
Print the value \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} (A_i \mbox{ XOR } A_j), modulo (10^9+7).
Examples
Input
3
1 2 3
Output
6
Input
10
3 1 4 1 5 9 2 6 5 3
Output
237
Input
10
3 14 159 2653 58979 323846 2643383 27950288 419716939 9375105820
Output
103715602 | instruction | 0 | 58,684 | 5 | 117,368 |
"Correct Solution:
```
N = int(input())
A = list(map(int, input().split()))
mod = 10**9 + 7
ans = 0
for i in range(60):
X = sum([1 for x in A if (x >> i) & 1])
ans += (1 << i) * X * (N - X)
ans %= mod
print(ans)
``` | output | 1 | 58,684 | 5 | 117,369 |
Provide a correct Python 3 solution for this coding contest problem.
We have N integers. The i-th integer is A_i.
Find \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} (A_i \mbox{ XOR } A_j), modulo (10^9+7).
What is \mbox{ XOR }?
The XOR of integers A and B, A \mbox{ XOR } B, is defined as follows:
* When A \mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.
For example, 3 \mbox{ XOR } 5 = 6. (In base two: 011 \mbox{ XOR } 101 = 110.)
Constraints
* 2 \leq N \leq 3 \times 10^5
* 0 \leq A_i < 2^{60}
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
Output
Print the value \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} (A_i \mbox{ XOR } A_j), modulo (10^9+7).
Examples
Input
3
1 2 3
Output
6
Input
10
3 1 4 1 5 9 2 6 5 3
Output
237
Input
10
3 14 159 2653 58979 323846 2643383 27950288 419716939 9375105820
Output
103715602 | instruction | 0 | 58,685 | 5 | 117,370 |
"Correct Solution:
```
MOD = 10**9+7
N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(60):
x = 0
for a in A:
if a >> i & 1:
x += 1
ans += x * (N-x) * (2**i)
ans %= MOD
print(ans)
``` | output | 1 | 58,685 | 5 | 117,371 |
Provide a correct Python 3 solution for this coding contest problem.
We have N integers. The i-th integer is A_i.
Find \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} (A_i \mbox{ XOR } A_j), modulo (10^9+7).
What is \mbox{ XOR }?
The XOR of integers A and B, A \mbox{ XOR } B, is defined as follows:
* When A \mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.
For example, 3 \mbox{ XOR } 5 = 6. (In base two: 011 \mbox{ XOR } 101 = 110.)
Constraints
* 2 \leq N \leq 3 \times 10^5
* 0 \leq A_i < 2^{60}
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
Output
Print the value \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} (A_i \mbox{ XOR } A_j), modulo (10^9+7).
Examples
Input
3
1 2 3
Output
6
Input
10
3 1 4 1 5 9 2 6 5 3
Output
237
Input
10
3 14 159 2653 58979 323846 2643383 27950288 419716939 9375105820
Output
103715602 | instruction | 0 | 58,686 | 5 | 117,372 |
"Correct Solution:
```
n = int(input())
xs = [int(x) for x in input().split()]
M = 10**9 + 7
r = 0
for i in range(61):
k = 0
for x in xs:
k += (x >> i) % 2
r = (r + ((n-k) * k % M) * pow(2, i) )% M
print(r)
``` | output | 1 | 58,686 | 5 | 117,373 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.