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.
Jeff got 2n real numbers a1, a2, ..., a2n as a birthday present. The boy hates non-integer numbers, so he decided to slightly "adjust" the numbers he's got. Namely, Jeff consecutively executes n operations, each of them goes as follows:
* choose indexes i and j (i ≠ j) that haven't been chosen yet;
* round element ai to the nearest integer that isn't more than ai (assign to ai: ⌊ ai ⌋);
* round element aj to the nearest integer that isn't less than aj (assign to aj: ⌈ aj ⌉).
Nevertheless, Jeff doesn't want to hurt the feelings of the person who gave him the sequence. That's why the boy wants to perform the operations so as to make the absolute value of the difference between the sum of elements before performing the operations and the sum of elements after performing the operations as small as possible. Help Jeff find the minimum absolute value of the difference.
Input
The first line contains integer n (1 ≤ n ≤ 2000). The next line contains 2n real numbers a1, a2, ..., a2n (0 ≤ ai ≤ 10000), given with exactly three digits after the decimal point. The numbers are separated by spaces.
Output
In a single line print a single real number — the required difference with exactly three digits after the decimal point.
Examples
Input
3
0.000 0.500 0.750 1.000 2.000 3.000
Output
0.250
Input
3
4469.000 6526.000 4864.000 9356.383 7490.000 995.896
Output
0.279
Note
In the first test case you need to perform the operations as follows: (i = 1, j = 4), (i = 2, j = 3), (i = 5, j = 6). In this case, the difference will equal |(0 + 0.5 + 0.75 + 1 + 2 + 3) - (0 + 0 + 1 + 1 + 2 + 3)| = 0.25.
Submitted Solution:
```
n = int(input())
As = list(map(float, input().split()))
B = list(x - int(x) for x in As if x - int(x) > 0.000)
l = len(B)
S = sum(x for x in B)
l = l if l % 2 == 0 else l + 1
ans = 1e10
for i in range(int(l/2), n + 1):
ans = min(ans, abs(i - S))
print("%.3f", ans)
``` | instruction | 0 | 76,199 | 5 | 152,398 |
No | output | 1 | 76,199 | 5 | 152,399 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Jeff got 2n real numbers a1, a2, ..., a2n as a birthday present. The boy hates non-integer numbers, so he decided to slightly "adjust" the numbers he's got. Namely, Jeff consecutively executes n operations, each of them goes as follows:
* choose indexes i and j (i ≠ j) that haven't been chosen yet;
* round element ai to the nearest integer that isn't more than ai (assign to ai: ⌊ ai ⌋);
* round element aj to the nearest integer that isn't less than aj (assign to aj: ⌈ aj ⌉).
Nevertheless, Jeff doesn't want to hurt the feelings of the person who gave him the sequence. That's why the boy wants to perform the operations so as to make the absolute value of the difference between the sum of elements before performing the operations and the sum of elements after performing the operations as small as possible. Help Jeff find the minimum absolute value of the difference.
Input
The first line contains integer n (1 ≤ n ≤ 2000). The next line contains 2n real numbers a1, a2, ..., a2n (0 ≤ ai ≤ 10000), given with exactly three digits after the decimal point. The numbers are separated by spaces.
Output
In a single line print a single real number — the required difference with exactly three digits after the decimal point.
Examples
Input
3
0.000 0.500 0.750 1.000 2.000 3.000
Output
0.250
Input
3
4469.000 6526.000 4864.000 9356.383 7490.000 995.896
Output
0.279
Note
In the first test case you need to perform the operations as follows: (i = 1, j = 4), (i = 2, j = 3), (i = 5, j = 6). In this case, the difference will equal |(0 + 0.5 + 0.75 + 1 + 2 + 3) - (0 + 0 + 1 + 1 + 2 + 3)| = 0.25.
Submitted Solution:
```
N=int(input())
n=N//2
A=list(map(float,input().strip().split(' ')))
z=0
for i in range(len(A)):
A[i]=A[i]-int(A[i])
if A[i]==0:
z+=1
ANS=sum(A)
ans=10**10
for j in range(n-z,n+1):
ans=min(ans,abs(ANS-j))
print("%.3f"%ans)
``` | instruction | 0 | 76,200 | 5 | 152,400 |
No | output | 1 | 76,200 | 5 | 152,401 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence relation
F1 = 1; F2 = 1; Fn = Fn - 1 + Fn - 2 (n > 2).
DZY loves Fibonacci numbers very much. Today DZY gives you an array consisting of n integers: a1, a2, ..., an. Moreover, there are m queries, each query has one of the two types:
1. Format of the query "1 l r". In reply to the query, you need to add Fi - l + 1 to each element ai, where l ≤ i ≤ r.
2. Format of the query "2 l r". In reply to the query you should output the value of <image> modulo 1000000009 (109 + 9).
Help DZY reply to all the queries.
Input
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 300000). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — initial array a.
Then, m lines follow. A single line describes a single query in the format given in the statement. It is guaranteed that for each query inequality 1 ≤ l ≤ r ≤ n holds.
Output
For each query of the second type, print the value of the sum on a single line.
Examples
Input
4 4
1 2 3 4
1 1 4
2 1 4
1 2 4
2 1 3
Output
17
12
Note
After the first query, a = [2, 3, 5, 7].
For the second query, sum = 2 + 3 + 5 + 7 = 17.
After the third query, a = [2, 4, 6, 9].
For the fourth query, sum = 2 + 4 + 6 = 12.
Submitted Solution:
```
a,b = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]
def fibo(n):
k = ((1 + 5**0.5)/2)**(n) #% 1000000009)
h = ((1 - 5**0.5)/2)**(n)# % 1000000009)
f = (1/(5**0.5))# % (1000000009)
return int(f*(k - h))
for i in range(b):
j = [int(x) for x in input().split()]
if j[0] == 1 :
for i in range(j[1] - 1 , j[2] ):
arr[i] = arr[i] + int(fibo((i+ 1) - j[1] + 1 ))
if j[0] == 2:
print(sum(arr[j[1] - 1 : j[2] ]) % 1000000009)
``` | instruction | 0 | 76,231 | 5 | 152,462 |
No | output | 1 | 76,231 | 5 | 152,463 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence relation
F1 = 1; F2 = 1; Fn = Fn - 1 + Fn - 2 (n > 2).
DZY loves Fibonacci numbers very much. Today DZY gives you an array consisting of n integers: a1, a2, ..., an. Moreover, there are m queries, each query has one of the two types:
1. Format of the query "1 l r". In reply to the query, you need to add Fi - l + 1 to each element ai, where l ≤ i ≤ r.
2. Format of the query "2 l r". In reply to the query you should output the value of <image> modulo 1000000009 (109 + 9).
Help DZY reply to all the queries.
Input
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 300000). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — initial array a.
Then, m lines follow. A single line describes a single query in the format given in the statement. It is guaranteed that for each query inequality 1 ≤ l ≤ r ≤ n holds.
Output
For each query of the second type, print the value of the sum on a single line.
Examples
Input
4 4
1 2 3 4
1 1 4
2 1 4
1 2 4
2 1 3
Output
17
12
Note
After the first query, a = [2, 3, 5, 7].
For the second query, sum = 2 + 3 + 5 + 7 = 17.
After the third query, a = [2, 4, 6, 9].
For the fourth query, sum = 2 + 4 + 6 = 12.
Submitted Solution:
```
def push(v,l,r):
# print(v,l,r)
ans=0
for k in mark[v]:
ans+=fib[r-k+3]-fib[l-k+2]
if l!=r:
mark[v*2+1].append(k)
mark[v*2+2].append(k)
seg[v]=(seg[v]+ans)%1000000007
mark[v]=[]
def build(v,l,r):
if l>r:
return
if l==r:
seg[v]=ar[l]%1000000007
else:
tm=(l+r)//2
build(v*2+1,l,tm)
build(v*2+2,tm+1,r)
seg[v]=(seg[2*v+1]+seg[2*v+2])%1000000007
def update(v,l,r,c1,c2):
push(v,l,r)
if l>r or l>c2 or r<c1:
return
if l>=c1 and r<=c2:
mark[v].append(c1)
push(v,l,r)
return
mid=(l+r)//2
update(2*v+1,l,mid,c1,c2)
update(2*v+2,mid+1,r,c1,c2)
seg[v]=(seg[2*v+1]+seg[2*v+2])%1000000007
def get(v,l,r,c1,c2):
push(v,l,r)
if l>r or r<c1 or l>c2:
return 0
if l>=c1 and r<=c2:
return seg[v]
mid=(l+r)//2
return (get(2*v+1,l,mid,c1,c2)+get(2*v+2,mid+1,r,c1,c2))%1000000007
n,m=[int(k) for k in input().split()]
ar=[int(k) for k in input().split()]
fib=[1 for k in range(n+4)]
seg=[0 for k in range(4*n)]
mark=[[] for k in range(4*n)]
for k in range(3,n+4):
fib[k]=(fib[k-1]+fib[k-2])%1000000007
build(0,0,n-1)
# print(ar)
# print(seg)
for p in range(m):
typ,l,r=[int(k) for k in input().split()]
if typ==1:
update(0,0,n-1,l-1,r-1)
# print(seg,mark)
else:
print(get(0,0,n-1,l-1,r-1))
# print(seg,mark)
``` | instruction | 0 | 76,232 | 5 | 152,464 |
No | output | 1 | 76,232 | 5 | 152,465 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence relation
F1 = 1; F2 = 1; Fn = Fn - 1 + Fn - 2 (n > 2).
DZY loves Fibonacci numbers very much. Today DZY gives you an array consisting of n integers: a1, a2, ..., an. Moreover, there are m queries, each query has one of the two types:
1. Format of the query "1 l r". In reply to the query, you need to add Fi - l + 1 to each element ai, where l ≤ i ≤ r.
2. Format of the query "2 l r". In reply to the query you should output the value of <image> modulo 1000000009 (109 + 9).
Help DZY reply to all the queries.
Input
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 300000). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — initial array a.
Then, m lines follow. A single line describes a single query in the format given in the statement. It is guaranteed that for each query inequality 1 ≤ l ≤ r ≤ n holds.
Output
For each query of the second type, print the value of the sum on a single line.
Examples
Input
4 4
1 2 3 4
1 1 4
2 1 4
1 2 4
2 1 3
Output
17
12
Note
After the first query, a = [2, 3, 5, 7].
For the second query, sum = 2 + 3 + 5 + 7 = 17.
After the third query, a = [2, 4, 6, 9].
For the fourth query, sum = 2 + 4 + 6 = 12.
Submitted Solution:
```
a,b = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]
def fibo(n):
k = (((1 + 5**0.5)/2)**(n) - ((1 - 5**0.5)/2)**(n))//(5**0.5)
return int(k)
for i in range(b):
j = [int(x) for x in input().split()]
if j[0] == 1 :
for i in range(j[1] - 1 , j[2] ):
arr[i] = arr[i] + int(fibo((i+ 1) - j[1] + 1 ))
if j[0] == 2:
print(sum(arr[j[1] - 1 : j[2] ]) % 1000000009)
``` | instruction | 0 | 76,233 | 5 | 152,466 |
No | output | 1 | 76,233 | 5 | 152,467 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence relation
F1 = 1; F2 = 1; Fn = Fn - 1 + Fn - 2 (n > 2).
DZY loves Fibonacci numbers very much. Today DZY gives you an array consisting of n integers: a1, a2, ..., an. Moreover, there are m queries, each query has one of the two types:
1. Format of the query "1 l r". In reply to the query, you need to add Fi - l + 1 to each element ai, where l ≤ i ≤ r.
2. Format of the query "2 l r". In reply to the query you should output the value of <image> modulo 1000000009 (109 + 9).
Help DZY reply to all the queries.
Input
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 300000). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — initial array a.
Then, m lines follow. A single line describes a single query in the format given in the statement. It is guaranteed that for each query inequality 1 ≤ l ≤ r ≤ n holds.
Output
For each query of the second type, print the value of the sum on a single line.
Examples
Input
4 4
1 2 3 4
1 1 4
2 1 4
1 2 4
2 1 3
Output
17
12
Note
After the first query, a = [2, 3, 5, 7].
For the second query, sum = 2 + 3 + 5 + 7 = 17.
After the third query, a = [2, 4, 6, 9].
For the fourth query, sum = 2 + 4 + 6 = 12.
Submitted Solution:
```
def push(v,l,r):
# print(v,l,r)
ans=0
for k in mark[v]:
ans+=fib[r-k+3]-fib[l-k+2]
if l!=r:
mark[v*2+1].append(k)
mark[v*2+2].append(k)
seg[v]+=ans
mark[v]=[]
def build(v,l,r):
if l>r:
return
if l==r:
seg[v]=ar[l]
else:
tm=(l+r)//2
build(v*2+1,l,tm)
build(v*2+2,tm+1,r)
seg[v]=seg[2*v+1]+seg[2*v+2]
def update(v,l,r,c1,c2):
push(v,l,r)
if l>r or l>c2 or r<c1:
return
if l>=c1 and r<=c2:
mark[v].append(c1)
push(v,l,r)
return
mid=(l+r)//2
update(2*v+1,l,mid,c1,c2)
update(2*v+2,mid+1,r,c1,c2)
seg[v]=seg[2*v+1]+seg[2*v+2]
def get(v,l,r,c1,c2):
push(v,l,r)
if l>r or r<c1 or l>c2:
return 0
if l>=c1 and r<=c2:
return seg[v]
mid=(l+r)//2
return get(2*v+1,l,mid,c1,c2)+get(2*v+2,mid+1,r,c1,c2)
n,m=[int(k) for k in input().split()]
ar=[int(k) for k in input().split()]
fib=[1 for k in range(n+4)]
seg=[0 for k in range(4*n)]
mark=[[] for k in range(4*n)]
for k in range(3,n+4):
fib[k]=fib[k-1]+fib[k-2]
build(0,0,n-1)
# print(ar)
# print(seg)
for p in range(m):
typ,l,r=[int(k) for k in input().split()]
if typ==1:
update(0,0,n-1,l-1,r-1)
# print(seg,mark)
else:
print(get(0,0,n-1,l-1,r-1))
# print(seg,mark)
``` | instruction | 0 | 76,234 | 5 | 152,468 |
No | output | 1 | 76,234 | 5 | 152,469 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Author has gone out of the stories about Vasiliy, so here is just a formal task description.
You are given q queries and a multiset A, initially containing only integer 0. There are three types of queries:
1. "+ x" — add integer x to multiset A.
2. "- x" — erase one occurrence of integer x from multiset A. It's guaranteed that at least one x is present in the multiset A before this query.
3. "? x" — you are given integer x and need to compute the value <image>, i.e. the maximum value of bitwise exclusive OR (also know as XOR) of integer x and some integer y from the multiset A.
Multiset is a set, where equal elements are allowed.
Input
The first line of the input contains a single integer q (1 ≤ q ≤ 200 000) — the number of queries Vasiliy has to perform.
Each of the following q lines of the input contains one of three characters '+', '-' or '?' and an integer xi (1 ≤ xi ≤ 109). It's guaranteed that there is at least one query of the third type.
Note, that the integer 0 will always be present in the set A.
Output
For each query of the type '?' print one integer — the maximum value of bitwise exclusive OR (XOR) of integer xi and some integer from the multiset A.
Example
Input
10
+ 8
+ 9
+ 11
+ 6
+ 1
? 3
- 8
? 3
? 8
? 11
Output
11
10
14
13
Note
After first five operations multiset A contains integers 0, 8, 9, 11, 6 and 1.
The answer for the sixth query is integer <image> — maximum among integers <image>, <image>, <image>, <image> and <image>.
Submitted Solution:
```
class Node:
def __init__(self, value):
self.parent = None
self.val = value
self.zero = None
self.one = None
self.marker = 0
self.max_len = 0
root = Node(-1)
def add(n):
#print("Add", n)
curr_node = root
bitstr = bin(n)[2:].zfill(32) # 32-bit string
for bit in bitstr:
if bit == "1":
if curr_node.one == None:
curr_node.one = Node(1)
curr_node.one.parent = curr_node
curr_node = curr_node.one
else:
if curr_node.zero == None:
curr_node.zero = Node(0)
curr_node.zero.parent = curr_node
curr_node = curr_node.zero
curr_node.marker += 1
def remove(n):
#print("Remove", n)
curr_node = root
bitstr = bin(n)[2:].zfill(32)
for bit in bitstr:
if bit == "1":
curr_node = curr_node.one
else:
curr_node = curr_node.zero
curr_node.marker -= 1
if curr_node.marker == 0:
while curr_node.parent != None:
if curr_node.one is None and curr_node.zero is None:
if curr_node.val == 1:
curr_node.parent.one = None
else:
curr_node.parent.zero = None
curr_node = curr_node.parent
def query(n):
#print("Query", n)
bitstr = bin(n)[2:].zfill(32)
curr_node = root
result = []
for bit in bitstr:
b = int(bit)
looking_for = 1-b
zero_present = curr_node.zero != None
one_present = curr_node.one != None
if looking_for == 0 and zero_present:
curr_node = curr_node.zero
result.append("1")
elif looking_for == 1 and one_present:
curr_node = curr_node.one
result.append("1")
elif looking_for == 0 and one_present:
curr_node = curr_node.one
result.append("0")
else:
curr_node = curr_node.zero
result.append("0")
print(int("".join(result), 2))
# Parse input
num_q = int(input())
for _ in range(num_q):
expr = input()
symbol = expr[0]
num = int(expr[2:])
add(0) # 0 is always in the set
if symbol == "+":
add(num)
elif symbol == "-":
remove(num)
elif symbol == "?":
query(num)
``` | instruction | 0 | 76,342 | 5 | 152,684 |
Yes | output | 1 | 76,342 | 5 | 152,685 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Author has gone out of the stories about Vasiliy, so here is just a formal task description.
You are given q queries and a multiset A, initially containing only integer 0. There are three types of queries:
1. "+ x" — add integer x to multiset A.
2. "- x" — erase one occurrence of integer x from multiset A. It's guaranteed that at least one x is present in the multiset A before this query.
3. "? x" — you are given integer x and need to compute the value <image>, i.e. the maximum value of bitwise exclusive OR (also know as XOR) of integer x and some integer y from the multiset A.
Multiset is a set, where equal elements are allowed.
Input
The first line of the input contains a single integer q (1 ≤ q ≤ 200 000) — the number of queries Vasiliy has to perform.
Each of the following q lines of the input contains one of three characters '+', '-' or '?' and an integer xi (1 ≤ xi ≤ 109). It's guaranteed that there is at least one query of the third type.
Note, that the integer 0 will always be present in the set A.
Output
For each query of the type '?' print one integer — the maximum value of bitwise exclusive OR (XOR) of integer xi and some integer from the multiset A.
Example
Input
10
+ 8
+ 9
+ 11
+ 6
+ 1
? 3
- 8
? 3
? 8
? 11
Output
11
10
14
13
Note
After first five operations multiset A contains integers 0, 8, 9, 11, 6 and 1.
The answer for the sixth query is integer <image> — maximum among integers <image>, <image>, <image>, <image> and <image>.
Submitted Solution:
```
#Bhargey Mehta (Sophomore)
#DA-IICT, Gandhinagar
import sys, math, queue
#sys.stdin = open("input.txt", "r")
MOD = 10**9+7
def getBin(x):
num = [-1 for i in range(32)]
for i in range(1, 33):
num[-i] = x&1
x = x>>1
return num
t = [-1, -1]
def add(x, trie, i):
if i == len(x): return
if trie[x[i]] == -1:
trie[x[i]] = [-1, -1]
add(x, trie[x[i]], i+1)
def query(x, trie, i, ans):
if i == len(x): return ans
if x[i] == 1:
if trie[0] == -1:
return query(x, trie[1], i+1, ans<<1)
else:
return query(x, trie[0], i+1, (ans<<1)+1)
else:
if trie[1] == -1:
return query(x, trie[0], i+1, ans<<1)
else:
return query(x, trie[1], i+1, (ans<<1)+1)
def delete(x, trie, i):
if i == len(x): return
delete(x, trie[x[i]], i+1)
if trie[x[i]] == [-1, -1]:
trie[x[i]] = -1
n = int(input())
add(getBin(0), t, 0)
f = {0: 1}
for _ in range(n):
q, x = input().split()
x = int(x)
if q == '+':
if x in f: f[x] += 1
else:
f[x] = 1
add(getBin(x), t, 0)
elif q == '?':
print(query(getBin(x), t, 0, 0))
else:
if f[x] == 1:
del f[x]
delete(getBin(x), t, 0)
else: f[x] -= 1
``` | instruction | 0 | 76,343 | 5 | 152,686 |
Yes | output | 1 | 76,343 | 5 | 152,687 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Author has gone out of the stories about Vasiliy, so here is just a formal task description.
You are given q queries and a multiset A, initially containing only integer 0. There are three types of queries:
1. "+ x" — add integer x to multiset A.
2. "- x" — erase one occurrence of integer x from multiset A. It's guaranteed that at least one x is present in the multiset A before this query.
3. "? x" — you are given integer x and need to compute the value <image>, i.e. the maximum value of bitwise exclusive OR (also know as XOR) of integer x and some integer y from the multiset A.
Multiset is a set, where equal elements are allowed.
Input
The first line of the input contains a single integer q (1 ≤ q ≤ 200 000) — the number of queries Vasiliy has to perform.
Each of the following q lines of the input contains one of three characters '+', '-' or '?' and an integer xi (1 ≤ xi ≤ 109). It's guaranteed that there is at least one query of the third type.
Note, that the integer 0 will always be present in the set A.
Output
For each query of the type '?' print one integer — the maximum value of bitwise exclusive OR (XOR) of integer xi and some integer from the multiset A.
Example
Input
10
+ 8
+ 9
+ 11
+ 6
+ 1
? 3
- 8
? 3
? 8
? 11
Output
11
10
14
13
Note
After first five operations multiset A contains integers 0, 8, 9, 11, 6 and 1.
The answer for the sixth query is integer <image> — maximum among integers <image>, <image>, <image>, <image> and <image>.
Submitted Solution:
```
# by the authority of GOD author: manhar singh sachdev #
import os,sys
from io import BytesIO,IOBase
class Node:
def __init__(self,val=None):
self.val = val
self.zero = None
self.one = None
self.isend = 0
self.onpath = 0
def __str__(self):
return f'{self.val} {self.zero} {self.one} {self.isend}'
class Trie:
def __init__(self,node):
self.root = node
def add(self, num):
curr = self.root
for bit in num:
if bit == '1':
if not curr.one:
curr.one = Node('1')
curr = curr.one
else:
if not curr.zero:
curr.zero = Node('0')
curr = curr.zero
curr.onpath += 1
curr.isend += 1
def findmaxxor(self,num):
curr,val = self.root,0
for i in num:
if not curr:
val *= 2
continue
z = '0' if i == '1' else '1'
if z == '1':
if curr.one:
curr = curr.one
val = val*2+1
else:
curr = curr.zero
val *= 2
else:
if curr.zero:
curr = curr.zero
val = val*2+1
else:
curr = curr.one
val *= 2
return val
def __delitem__(self, num):
curr = self.root
for bit in num:
if bit == '1':
if curr.one.onpath == 1:
curr.one = None
break
curr = curr.one
else:
if curr.zero.onpath == 1:
curr.zero = None
break
curr = curr.zero
curr.onpath -= 1
else:
curr.isend -= 1
def main():
z = Trie(Node())
z.add('0'*30)
for _ in range(int(input())):
r = input().split()
x = bin(int(r[1]))[2:].zfill(30)
if r[0] == '+':
z.add(x)
elif r[0] == '-':
del z[x]
else:
print(z.findmaxxor(x))
# Fast IO Region
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")
if __name__ == "__main__":
main()
``` | instruction | 0 | 76,344 | 5 | 152,688 |
Yes | output | 1 | 76,344 | 5 | 152,689 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Author has gone out of the stories about Vasiliy, so here is just a formal task description.
You are given q queries and a multiset A, initially containing only integer 0. There are three types of queries:
1. "+ x" — add integer x to multiset A.
2. "- x" — erase one occurrence of integer x from multiset A. It's guaranteed that at least one x is present in the multiset A before this query.
3. "? x" — you are given integer x and need to compute the value <image>, i.e. the maximum value of bitwise exclusive OR (also know as XOR) of integer x and some integer y from the multiset A.
Multiset is a set, where equal elements are allowed.
Input
The first line of the input contains a single integer q (1 ≤ q ≤ 200 000) — the number of queries Vasiliy has to perform.
Each of the following q lines of the input contains one of three characters '+', '-' or '?' and an integer xi (1 ≤ xi ≤ 109). It's guaranteed that there is at least one query of the third type.
Note, that the integer 0 will always be present in the set A.
Output
For each query of the type '?' print one integer — the maximum value of bitwise exclusive OR (XOR) of integer xi and some integer from the multiset A.
Example
Input
10
+ 8
+ 9
+ 11
+ 6
+ 1
? 3
- 8
? 3
? 8
? 11
Output
11
10
14
13
Note
After first five operations multiset A contains integers 0, 8, 9, 11, 6 and 1.
The answer for the sixth query is integer <image> — maximum among integers <image>, <image>, <image>, <image> and <image>.
Submitted Solution:
```
def num_to_bitstring(n):
'''converts num to bitstring of length 30'''
b = bin(n)
assert b[:2] == "0b"
b = b[2:]
return "0" * (30 - len(b)) + b
class Node:
def __init__(self, val = 0):
self.value = val #number of occurances
self.left = None
self.right = None
def add(self):
self.value = self.value + 1
class Trie:
def __init__(self):
self.head = Node(1)
def add(self, s):
current = self.head
for b in s:
if b == "0":
if current.left == None:
current.left = Node()
current = current.left
else:
current = current.left
elif b == "1":
if current.right == None:
current.right = Node()
current = current.right
else:
current = current.right
current.value = current.value + 1
def subtract(self, s):
current = self.head
last_branch = None
#have a last valid, if after going to a leaf it turns out 1 -> 0, we need to trim a branch, so take last valid set either left or right to None
for b in s:
if (current.left != None) and (current.right != None):
if b == "0":
last_branch = (current, "0")
elif b == "1":
last_branch = (current, "1")
if b == "0":
current = current.left
elif b == "1":
current = current.right
current.value = current.value - 1
if current.value == 0:
if last_branch[1] == "0":
last_branch[0].left = None
elif last_branch[1] == "1":
last_branch[0].right = None
def xor(self, s):
sum = 0
i = 29
current = self.head
for b in s:
if b == "0":
if current.right != None:
current = current.right
sum += 2 ** i
else:
current = current.left
else:
if current.left != None:
current = current.left
sum += 2 ** i
else:
current = current.right
i -= 1
return sum
def main():
t = Trie()
s = num_to_bitstring(0)
t.add(s)
q = int(input())
for a0 in range(q):
query = input()
s = num_to_bitstring(int(query[2:]))
if query[0] == "+":
t.add(s)
elif query[0] == "-":
t.subtract(s)
elif query[0] == "?":
print(t.xor(s))
main()
``` | instruction | 0 | 76,345 | 5 | 152,690 |
Yes | output | 1 | 76,345 | 5 | 152,691 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Author has gone out of the stories about Vasiliy, so here is just a formal task description.
You are given q queries and a multiset A, initially containing only integer 0. There are three types of queries:
1. "+ x" — add integer x to multiset A.
2. "- x" — erase one occurrence of integer x from multiset A. It's guaranteed that at least one x is present in the multiset A before this query.
3. "? x" — you are given integer x and need to compute the value <image>, i.e. the maximum value of bitwise exclusive OR (also know as XOR) of integer x and some integer y from the multiset A.
Multiset is a set, where equal elements are allowed.
Input
The first line of the input contains a single integer q (1 ≤ q ≤ 200 000) — the number of queries Vasiliy has to perform.
Each of the following q lines of the input contains one of three characters '+', '-' or '?' and an integer xi (1 ≤ xi ≤ 109). It's guaranteed that there is at least one query of the third type.
Note, that the integer 0 will always be present in the set A.
Output
For each query of the type '?' print one integer — the maximum value of bitwise exclusive OR (XOR) of integer xi and some integer from the multiset A.
Example
Input
10
+ 8
+ 9
+ 11
+ 6
+ 1
? 3
- 8
? 3
? 8
? 11
Output
11
10
14
13
Note
After first five operations multiset A contains integers 0, 8, 9, 11, 6 and 1.
The answer for the sixth query is integer <image> — maximum among integers <image>, <image>, <image>, <image> and <image>.
Submitted Solution:
```
N = 6
n = int(input())
D = [{0:1} for x in range(N)]
X = [0 for x in range(N)]
ans = ''
for i in range(n):
s = input().split()
c = s[0]
x = int(s[1])
if (c == '+'):
for j in range(N):
if (D[j].get(x) == None):
D[j][x] = 1
else:
D[j][x] += 1
x >>= 1
elif (c == '-'):
for j in range(N):
if (D[j][x] == 1):
D[j].pop(x)
else:
D[j][x] -= 1
x >>= 1
elif (c == '?'):
y = 0
z = 0
for j in range(N):
X[j] = x % 2
x //= 2
for j in range(N - 1, -1, -1):
if X[j] == 0:
if (D[j].get(2 * y + 1) == None):
y = 2 * y
z = 2 * z
else:
y = 2 * y + 1
z = 2 * z + 1
else:
if (D[j].get(2 * y) == None):
y = 2 * y + 1
z = 2 * z
else:
y = 2 * y
z = 2 * z + 1
ans += str(z) + '\n'
print(ans)
``` | instruction | 0 | 76,346 | 5 | 152,692 |
No | output | 1 | 76,346 | 5 | 152,693 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Author has gone out of the stories about Vasiliy, so here is just a formal task description.
You are given q queries and a multiset A, initially containing only integer 0. There are three types of queries:
1. "+ x" — add integer x to multiset A.
2. "- x" — erase one occurrence of integer x from multiset A. It's guaranteed that at least one x is present in the multiset A before this query.
3. "? x" — you are given integer x and need to compute the value <image>, i.e. the maximum value of bitwise exclusive OR (also know as XOR) of integer x and some integer y from the multiset A.
Multiset is a set, where equal elements are allowed.
Input
The first line of the input contains a single integer q (1 ≤ q ≤ 200 000) — the number of queries Vasiliy has to perform.
Each of the following q lines of the input contains one of three characters '+', '-' or '?' and an integer xi (1 ≤ xi ≤ 109). It's guaranteed that there is at least one query of the third type.
Note, that the integer 0 will always be present in the set A.
Output
For each query of the type '?' print one integer — the maximum value of bitwise exclusive OR (XOR) of integer xi and some integer from the multiset A.
Example
Input
10
+ 8
+ 9
+ 11
+ 6
+ 1
? 3
- 8
? 3
? 8
? 11
Output
11
10
14
13
Note
After first five operations multiset A contains integers 0, 8, 9, 11, 6 and 1.
The answer for the sixth query is integer <image> — maximum among integers <image>, <image>, <image>, <image> and <image>.
Submitted Solution:
```
#------------------------------warmup----------------------------
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
#-------------------game starts now----------------------------------------------------
# ------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase
class Trie:
class Node:
def __init__(self, char: bool = False):
self.char = char
self.children = []
self.words = 0
def __init__(self):
self.root = Trie.Node()
def add(self, word):
node = self.root
for char in word:
found_in_child = False
for child in node.children:
if child.char == char:
node = child
found_in_child = True
break
if not found_in_child:
new_node = Trie.Node(char)
node.children.append(new_node)
node = new_node
node.words += 1
def remove(self, word):
node = self.root
nodelist = [node]
for char in word:
for child in node.children:
if child.char == char:
node = child
nodelist.append(node)
break
node.words -= 1
if not node.children and not node.words:
for i in range(len(nodelist)-2, -1, -1):
nodelist[i].children.remove(nodelist[i+1])
if nodelist[i].children or nodelist[i].words:
break
def query(self, prefix, root=None):
if not root: root = self.root
node = root
if not root.children:
return 0
prefix = [prefix]
for char in prefix:
char_not_found = True
for child in node.children:
if child.char == char:
char_not_found = False
node = child
break
if char_not_found:
return 0
return node
#------------------------iye ha corona zindegi----------------------------------
n=int(input())
t=Trie()
for i in range(n):
a,b=map(str,input().split())
b=int(b)
b=bin(b).replace("0b","")
b="0"*(32-len(b))+b
#print(b)
if a=='+':
t.add(b)
elif a=='-':
t.remove(b)
else:
ans=0
start=t.root
i=32
for j in b:
i-=1
tt=1-int(j)
tt=str(tt)
q=t.query(tt,start)
if q==0:
start=t.query(str(1-int(tt)),start)
#print(start)
else:
start=q
ans+=2**i
print(ans)
``` | instruction | 0 | 76,347 | 5 | 152,694 |
No | output | 1 | 76,347 | 5 | 152,695 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Author has gone out of the stories about Vasiliy, so here is just a formal task description.
You are given q queries and a multiset A, initially containing only integer 0. There are three types of queries:
1. "+ x" — add integer x to multiset A.
2. "- x" — erase one occurrence of integer x from multiset A. It's guaranteed that at least one x is present in the multiset A before this query.
3. "? x" — you are given integer x and need to compute the value <image>, i.e. the maximum value of bitwise exclusive OR (also know as XOR) of integer x and some integer y from the multiset A.
Multiset is a set, where equal elements are allowed.
Input
The first line of the input contains a single integer q (1 ≤ q ≤ 200 000) — the number of queries Vasiliy has to perform.
Each of the following q lines of the input contains one of three characters '+', '-' or '?' and an integer xi (1 ≤ xi ≤ 109). It's guaranteed that there is at least one query of the third type.
Note, that the integer 0 will always be present in the set A.
Output
For each query of the type '?' print one integer — the maximum value of bitwise exclusive OR (XOR) of integer xi and some integer from the multiset A.
Example
Input
10
+ 8
+ 9
+ 11
+ 6
+ 1
? 3
- 8
? 3
? 8
? 11
Output
11
10
14
13
Note
After first five operations multiset A contains integers 0, 8, 9, 11, 6 and 1.
The answer for the sixth query is integer <image> — maximum among integers <image>, <image>, <image>, <image> and <image>.
Submitted Solution:
```
trie = [[-1, -1]]
counts = [0]
trie_size = 1
def insert(x):
global trie, counts, trie_size
node = 0
out = []
for i in range(30, -1, -1):
b = 0 if (x & (1 << i)) == 0 else 1
out.append(str(b))
if trie[node][b] == -1:
trie[node][b] = trie_size
trie.append([-1, -1])
counts.append(0)
trie_size += 1
counts[node] += 1
node = trie[node][b]
counts[node] += 1
# print('+', ''.join(out))
def remove(x):
global trie, counts, trie_size
node = 0
for i in range(30, -1, -1):
counts[node] -= 1
b = 0 if (x & (1 << i)) == 0 else 1
node = trie[node][b]
counts[node] -= 1
def query(x):
global trie, counts, trie_size
node = 0
ans = 0
out = []
path = []
for i in range(30, -1, -1):
b = 0 if (x & (1 << i)) == 0 else 1
out.append(str(b))
if trie[node][1 - b] == -1 or counts[trie[node][1 - b]] == 0:
node = trie[node][b]
ans |= (1 << i) * b
path.append(str(b))
else:
node = trie[node][1 - b]
ans |= (1 << i) * (1 - b)
path.append(str(1-b))
# print(''.join(out))
# print('path', ''.join(path))
return ans ^ x
def main():
q = int(input())
for _ in range(q):
# print(trie)
# print(counts)
a, b = input().split()
b = int(b)
if a == '+':
insert(b)
elif a == '-':
remove(b)
else:
print(query(b))
main()
``` | instruction | 0 | 76,348 | 5 | 152,696 |
No | output | 1 | 76,348 | 5 | 152,697 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Author has gone out of the stories about Vasiliy, so here is just a formal task description.
You are given q queries and a multiset A, initially containing only integer 0. There are three types of queries:
1. "+ x" — add integer x to multiset A.
2. "- x" — erase one occurrence of integer x from multiset A. It's guaranteed that at least one x is present in the multiset A before this query.
3. "? x" — you are given integer x and need to compute the value <image>, i.e. the maximum value of bitwise exclusive OR (also know as XOR) of integer x and some integer y from the multiset A.
Multiset is a set, where equal elements are allowed.
Input
The first line of the input contains a single integer q (1 ≤ q ≤ 200 000) — the number of queries Vasiliy has to perform.
Each of the following q lines of the input contains one of three characters '+', '-' or '?' and an integer xi (1 ≤ xi ≤ 109). It's guaranteed that there is at least one query of the third type.
Note, that the integer 0 will always be present in the set A.
Output
For each query of the type '?' print one integer — the maximum value of bitwise exclusive OR (XOR) of integer xi and some integer from the multiset A.
Example
Input
10
+ 8
+ 9
+ 11
+ 6
+ 1
? 3
- 8
? 3
? 8
? 11
Output
11
10
14
13
Note
After first five operations multiset A contains integers 0, 8, 9, 11, 6 and 1.
The answer for the sixth query is integer <image> — maximum among integers <image>, <image>, <image>, <image> and <image>.
Submitted Solution:
```
# -*- coding: utf-8 -*-
import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
from typing import List
"""
created by shhuan at 2020/1/7 22:34
"""
class Node:
def __init__(self, val):
self.val = val
self.left = None
self.right = None
tree = Node(0)
def binval(val):
u = bin(val)[2:]
return '0' * (32 - len(u)) + u
def insert(val):
u = binval(val)
t = tree
for v in u:
if v == '1':
if not t.left:
t.left = Node(1)
t = t.left
else:
if not t.right:
t.right = Node(0)
t = t.right
def remove(val):
u = binval(val)
t = tree
for v in u[:-1]:
t = t.left if v == '1' else t.right
if u[-1] == '1':
t.left = None
else:
t.right = None
def search(val):
u = binval(((1 << 32) - 1) ^ val)
x = ''
t = tree
for v in u:
if v == '1':
if t.left:
x += '1'
t = t.left
else:
x += '0'
t = t.right
else:
if t.right:
x += '0'
t = t.right
else:
x += '1'
t = t.left
return int(x, 2) ^ val
insert(0)
q = int(input())
wc = collections.defaultdict(int)
bwc = collections.defaultdict(set)
ans = []
for qi in range(q):
a, b = input().split()
v = int(b)
if a == '+':
wc[v] += 1
if wc[v] == 1:
insert(v)
elif a == '-':
wc[v] -= 1
if wc[v] == 0:
remove(v)
else:
ans.append(search(v))
print('\n'.join(map(str, ans)))
``` | instruction | 0 | 76,349 | 5 | 152,698 |
No | output | 1 | 76,349 | 5 | 152,699 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a sequence of integers a1, a2, ..., an. Let <image>, and <image> for 1 ≤ i < n. Here, <image> denotes the modulus operation. Find the maximum value of f(x, 1) over all nonnegative integers x.
Input
The first line contains a single integer n (1 ≤ n ≤ 200000) — the length of the sequence.
The second lines contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1013) — the elements of the sequence.
Output
Output a single integer — the maximum value of f(x, 1) over all nonnegative integers x.
Examples
Input
2
10 5
Output
13
Input
5
5 4 3 2 1
Output
6
Input
4
5 10 5 10
Output
16
Note
In the first example you can choose, for example, x = 19.
In the second example you can choose, for example, x = 3 or x = 2.
Submitted Solution:
```
n = int(input())
a = list(map(int, input().split()))
def f(x,i):
tmp=x%a[i]
if i==n-1:return tmp
return tmp + f(tmp, i+1)
first,last=0,a[0]-1
while first<last:
mfirst,mlast=f(first,0),f(last,0)
if(mfirst<mlast): first += (last-first+1)//2
else: last -= (last-first+1)//2
print(max(mfirst,mlast))
``` | instruction | 0 | 76,415 | 5 | 152,830 |
No | output | 1 | 76,415 | 5 | 152,831 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a sequence of integers a1, a2, ..., an. Let <image>, and <image> for 1 ≤ i < n. Here, <image> denotes the modulus operation. Find the maximum value of f(x, 1) over all nonnegative integers x.
Input
The first line contains a single integer n (1 ≤ n ≤ 200000) — the length of the sequence.
The second lines contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1013) — the elements of the sequence.
Output
Output a single integer — the maximum value of f(x, 1) over all nonnegative integers x.
Examples
Input
2
10 5
Output
13
Input
5
5 4 3 2 1
Output
6
Input
4
5 10 5 10
Output
16
Note
In the first example you can choose, for example, x = 19.
In the second example you can choose, for example, x = 3 or x = 2.
Submitted Solution:
```
n=int(input())
a=list(map(int, input().split()))
def f(x,i):
tmp=x%a[i]
if i==n-1:return tmp
return tmp + f(tmp, i+1)
first,last=0,a[0]-1
while first<last:
mfirst,mlast=f(first,0),f(last,0)
if(mfirst<mlast): first += max((last-first-1)//2,1)
else: last -= (last-first+1)//2
print(max(mfirst,mlast))
``` | instruction | 0 | 76,416 | 5 | 152,832 |
No | output | 1 | 76,416 | 5 | 152,833 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a sequence of integers a1, a2, ..., an. Let <image>, and <image> for 1 ≤ i < n. Here, <image> denotes the modulus operation. Find the maximum value of f(x, 1) over all nonnegative integers x.
Input
The first line contains a single integer n (1 ≤ n ≤ 200000) — the length of the sequence.
The second lines contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1013) — the elements of the sequence.
Output
Output a single integer — the maximum value of f(x, 1) over all nonnegative integers x.
Examples
Input
2
10 5
Output
13
Input
5
5 4 3 2 1
Output
6
Input
4
5 10 5 10
Output
16
Note
In the first example you can choose, for example, x = 19.
In the second example you can choose, for example, x = 3 or x = 2.
Submitted Solution:
```
n=int(input("insert n \n"))
list_a=[int(z) for z in input().split()]
list_out=[int(z) for z in range(0,n)]
x=19
for i in range(0,n-1):
list_out[i]=(x%list_a[i] + ((x%list_a[i])%list_a[i+1]))
print(max(list_out))
``` | instruction | 0 | 76,417 | 5 | 152,834 |
No | output | 1 | 76,417 | 5 | 152,835 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a sequence of integers a1, a2, ..., an. Let <image>, and <image> for 1 ≤ i < n. Here, <image> denotes the modulus operation. Find the maximum value of f(x, 1) over all nonnegative integers x.
Input
The first line contains a single integer n (1 ≤ n ≤ 200000) — the length of the sequence.
The second lines contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1013) — the elements of the sequence.
Output
Output a single integer — the maximum value of f(x, 1) over all nonnegative integers x.
Examples
Input
2
10 5
Output
13
Input
5
5 4 3 2 1
Output
6
Input
4
5 10 5 10
Output
16
Note
In the first example you can choose, for example, x = 19.
In the second example you can choose, for example, x = 3 or x = 2.
Submitted Solution:
```
import math
n=int(input())
list_a=[int(z) for z in input().split()]
list_out=[int(z) for z in range(0,n)]
_max=0
for i in range(0,n-1):
for x in range(0,200000):
list_out[i]= int(math.fmod(x,list_a[i]) + math.fmod( math.fmod(x,list_a[i]),list_a[i+1]))
if list_out[i] > _max:
_max=list_out[i]
print(_max,'\n')
``` | instruction | 0 | 76,418 | 5 | 152,836 |
No | output | 1 | 76,418 | 5 | 152,837 |
Provide a correct Python 3 solution for this coding contest problem.
You will turn on the air conditioner if, and only if, the temperature of the room is 30 degrees Celsius or above.
The current temperature of the room is X degrees Celsius. Will you turn on the air conditioner?
Constraints
* -40 \leq X \leq 40
* X is an integer.
Input
Input is given from Standard Input in the following format:
X
Output
Print `Yes` if you will turn on the air conditioner; print `No` otherwise.
Examples
Input
25
Output
No
Input
30
Output
Yes | instruction | 0 | 76,457 | 5 | 152,914 |
"Correct Solution:
```
temp = int(input())
print("Yes" if temp>= 30 else "No")
``` | output | 1 | 76,457 | 5 | 152,915 |
Provide a correct Python 3 solution for this coding contest problem.
You will turn on the air conditioner if, and only if, the temperature of the room is 30 degrees Celsius or above.
The current temperature of the room is X degrees Celsius. Will you turn on the air conditioner?
Constraints
* -40 \leq X \leq 40
* X is an integer.
Input
Input is given from Standard Input in the following format:
X
Output
Print `Yes` if you will turn on the air conditioner; print `No` otherwise.
Examples
Input
25
Output
No
Input
30
Output
Yes | instruction | 0 | 76,458 | 5 | 152,916 |
"Correct Solution:
```
X = int(input())
print("Yes") if X>=30 else print("No")
``` | output | 1 | 76,458 | 5 | 152,917 |
Provide a correct Python 3 solution for this coding contest problem.
You will turn on the air conditioner if, and only if, the temperature of the room is 30 degrees Celsius or above.
The current temperature of the room is X degrees Celsius. Will you turn on the air conditioner?
Constraints
* -40 \leq X \leq 40
* X is an integer.
Input
Input is given from Standard Input in the following format:
X
Output
Print `Yes` if you will turn on the air conditioner; print `No` otherwise.
Examples
Input
25
Output
No
Input
30
Output
Yes | instruction | 0 | 76,459 | 5 | 152,918 |
"Correct Solution:
```
if(int(input())) >= 30:
print('Yes')
else:
print('No')
``` | output | 1 | 76,459 | 5 | 152,919 |
Provide a correct Python 3 solution for this coding contest problem.
You will turn on the air conditioner if, and only if, the temperature of the room is 30 degrees Celsius or above.
The current temperature of the room is X degrees Celsius. Will you turn on the air conditioner?
Constraints
* -40 \leq X \leq 40
* X is an integer.
Input
Input is given from Standard Input in the following format:
X
Output
Print `Yes` if you will turn on the air conditioner; print `No` otherwise.
Examples
Input
25
Output
No
Input
30
Output
Yes | instruction | 0 | 76,460 | 5 | 152,920 |
"Correct Solution:
```
a=int(input())
print(a<30 and 'No' or 'Yes')
``` | output | 1 | 76,460 | 5 | 152,921 |
Provide a correct Python 3 solution for this coding contest problem.
You will turn on the air conditioner if, and only if, the temperature of the room is 30 degrees Celsius or above.
The current temperature of the room is X degrees Celsius. Will you turn on the air conditioner?
Constraints
* -40 \leq X \leq 40
* X is an integer.
Input
Input is given from Standard Input in the following format:
X
Output
Print `Yes` if you will turn on the air conditioner; print `No` otherwise.
Examples
Input
25
Output
No
Input
30
Output
Yes | instruction | 0 | 76,461 | 5 | 152,922 |
"Correct Solution:
```
print(['No','Yes'][int(input())>=30])
``` | output | 1 | 76,461 | 5 | 152,923 |
Provide a correct Python 3 solution for this coding contest problem.
You will turn on the air conditioner if, and only if, the temperature of the room is 30 degrees Celsius or above.
The current temperature of the room is X degrees Celsius. Will you turn on the air conditioner?
Constraints
* -40 \leq X \leq 40
* X is an integer.
Input
Input is given from Standard Input in the following format:
X
Output
Print `Yes` if you will turn on the air conditioner; print `No` otherwise.
Examples
Input
25
Output
No
Input
30
Output
Yes | instruction | 0 | 76,462 | 5 | 152,924 |
"Correct Solution:
```
temp = int(input())
print("Yes") if temp>=30 else print("No")
``` | output | 1 | 76,462 | 5 | 152,925 |
Provide a correct Python 3 solution for this coding contest problem.
You will turn on the air conditioner if, and only if, the temperature of the room is 30 degrees Celsius or above.
The current temperature of the room is X degrees Celsius. Will you turn on the air conditioner?
Constraints
* -40 \leq X \leq 40
* X is an integer.
Input
Input is given from Standard Input in the following format:
X
Output
Print `Yes` if you will turn on the air conditioner; print `No` otherwise.
Examples
Input
25
Output
No
Input
30
Output
Yes | instruction | 0 | 76,463 | 5 | 152,926 |
"Correct Solution:
```
T = int(input())
print("Yes" if T >= 30 else "No")
``` | output | 1 | 76,463 | 5 | 152,927 |
Provide a correct Python 3 solution for this coding contest problem.
You will turn on the air conditioner if, and only if, the temperature of the room is 30 degrees Celsius or above.
The current temperature of the room is X degrees Celsius. Will you turn on the air conditioner?
Constraints
* -40 \leq X \leq 40
* X is an integer.
Input
Input is given from Standard Input in the following format:
X
Output
Print `Yes` if you will turn on the air conditioner; print `No` otherwise.
Examples
Input
25
Output
No
Input
30
Output
Yes | instruction | 0 | 76,464 | 5 | 152,928 |
"Correct Solution:
```
x = int(input())
YesNo = "Yes" if x>=30 else "No"
print(YesNo)
``` | output | 1 | 76,464 | 5 | 152,929 |
Provide a correct Python 3 solution for this coding contest problem.
Find the number of sequences of length K consisting of positive integers such that the product of any two adjacent elements is at most N, modulo 10^9+7.
Constraints
* 1\leq N\leq 10^9
* ~~1~~ 2\leq K\leq 100 (fixed at 21:33 JST)
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N K
Output
Print the number of sequences, modulo 10^9+7.
Examples
Input
3 2
Output
5
Input
10 3
Output
147
Input
314159265 35
Output
457397712 | instruction | 0 | 76,505 | 5 | 153,010 |
"Correct Solution:
```
MOD = pow(10, 9) + 7
def main():
n, k = map(int, input().split())
dyaku = set([1, n])
i = 2
while i*i<=n:
if n // i not in dyaku:
dyaku.add(i)
dyaku.add(n//i)
i += 1
reyaku = [0] + list(sorted(dyaku))
ddyaku = {s: i+1 for i, s in enumerate(sorted(dyaku))}
dp = [[0 for _ in range(k)] for _ in range(len(dyaku) + 1)]
for i in range(1, len(dyaku)+1):
dp[i][1] = (((reyaku[i] - reyaku[i-1]) * (n // reyaku[i])) % MOD + dp[i-1][1]) % MOD
for i in range(2, k):
for j in range(1, len(dyaku)+1):
dp[j][i] = (((reyaku[j] - reyaku[j-1]) * dp[ddyaku[n//reyaku[j]]][i-1]) % MOD + dp[j-1][i]) % MOD
print(dp[-1][-1])
if __name__ == '__main__':
main()
``` | output | 1 | 76,505 | 5 | 153,011 |
Provide a correct Python 3 solution for this coding contest problem.
Find the number of sequences of length K consisting of positive integers such that the product of any two adjacent elements is at most N, modulo 10^9+7.
Constraints
* 1\leq N\leq 10^9
* ~~1~~ 2\leq K\leq 100 (fixed at 21:33 JST)
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N K
Output
Print the number of sequences, modulo 10^9+7.
Examples
Input
3 2
Output
5
Input
10 3
Output
147
Input
314159265 35
Output
457397712 | instruction | 0 | 76,506 | 5 | 153,012 |
"Correct Solution:
```
import os
import sys
from collections import defaultdict
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
N, K = list(map(int, sys.stdin.readline().split()))
# ある程度数をまとめられるのでまとめておく
nexts = []
n = N
while True:
p = int(N // (int(N // n) + 1))
nexts.append(n)
if p <= 0:
break
n = p
# dp[k][i]: i に続く k 文字のパターン数
dp = defaultdict(lambda: defaultdict(int))
prev = 0
for n, m in zip(nexts, reversed(nexts)):
dp[0][m] = m
for k in range(1, K):
dp[k][0] = 0
prev = 0
for n, m in zip(nexts, reversed(nexts)):
dp[k][m] = (dp[k][prev] + dp[k-1][n] * (m-prev)) % MOD
prev = m
print(dp[K - 1][N])
``` | output | 1 | 76,506 | 5 | 153,013 |
Provide a correct Python 3 solution for this coding contest problem.
Find the number of sequences of length K consisting of positive integers such that the product of any two adjacent elements is at most N, modulo 10^9+7.
Constraints
* 1\leq N\leq 10^9
* ~~1~~ 2\leq K\leq 100 (fixed at 21:33 JST)
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N K
Output
Print the number of sequences, modulo 10^9+7.
Examples
Input
3 2
Output
5
Input
10 3
Output
147
Input
314159265 35
Output
457397712 | instruction | 0 | 76,507 | 5 | 153,014 |
"Correct Solution:
```
import math
n, k = map(int, input().split())
mod = 1000000007
n1 = int(math.sqrt(n))
if n1 * n1 == n:
n2 = n1 - 1
else:
n2 = n1
num = [n]
for i in range(1, n2):
num.append(n // (i + 1))
num[i - 1] -= num[i]
num[-1] -= n1
dp1 = [1 for i in range(n1)]
dp2 = [num[i] for i in range(n2)]
for _ in range(k - 1):
l = sum(dp1) % mod
newdp1 = [l for i in range(n1)]
newdp2 = [0 for i in range(n2)]
dp1sum = 0
for j in range(0, n2):
dp1sum = (dp1sum + dp1[j]) % mod
newdp2[j] = (newdp2[j] + dp1sum * num[j]) % mod
dp2sum = 0
for j in range(n2 - 1, -1, -1):
dp2sum = (dp2sum + dp2[j]) % mod
newdp1[j] = (newdp1[j] + dp2sum) % mod
dp1 = newdp1
dp2 = newdp2
print((sum(dp1) + sum(dp2)) % mod)
``` | output | 1 | 76,507 | 5 | 153,015 |
Provide a correct Python 3 solution for this coding contest problem.
Find the number of sequences of length K consisting of positive integers such that the product of any two adjacent elements is at most N, modulo 10^9+7.
Constraints
* 1\leq N\leq 10^9
* ~~1~~ 2\leq K\leq 100 (fixed at 21:33 JST)
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N K
Output
Print the number of sequences, modulo 10^9+7.
Examples
Input
3 2
Output
5
Input
10 3
Output
147
Input
314159265 35
Output
457397712 | instruction | 0 | 76,508 | 5 | 153,016 |
"Correct Solution:
```
from itertools import accumulate
N,K = map(int, input().split())
mod = 10**9+7
sqt = int(N**0.5)
cnt = [N // i-N // (i+1) for i in range(1, N//sqt)] + [1]*sqt
x = cnt
for _ in range(K):
x = [(i*j)%mod for i, j in zip(accumulate(reversed(x)), cnt)]
print(x[-1])
``` | output | 1 | 76,508 | 5 | 153,017 |
Provide a correct Python 3 solution for this coding contest problem.
Find the number of sequences of length K consisting of positive integers such that the product of any two adjacent elements is at most N, modulo 10^9+7.
Constraints
* 1\leq N\leq 10^9
* ~~1~~ 2\leq K\leq 100 (fixed at 21:33 JST)
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N K
Output
Print the number of sequences, modulo 10^9+7.
Examples
Input
3 2
Output
5
Input
10 3
Output
147
Input
314159265 35
Output
457397712 | instruction | 0 | 76,510 | 5 | 153,020 |
"Correct Solution:
```
import sys; input = sys.stdin.buffer.readline
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")
def getlist():
return list(map(int, input().split()))
#処理内容
def main():
N, K = getlist()
preList = []
preList2 = []
for i in range(1, N + 1):
if i ** 2 == N:
preList.append(1)
break
elif i ** 2 > N:
break
else:
if i == int(N // i):
preList.append(1)
break
else:
preList.append(int(N // i) - int(N // (i + 1)))
preList2.append(1)
start = list(reversed(preList + preList2))
M = len(start)
DP = [[0] * M for i in range(K)]
DP[0] = start
#DP
for i in range(1, K):
Csum = [0] * (M + 1)
for j in range(M):
Csum[j + 1] += Csum[j] + DP[i - 1][j]
for j in range(M):
DP[i][j] = Csum[M - j] * DP[0][j]
DP[i][j] %= con
# print(start)
# print(DP)
print(sum(DP[K - 1]) % con)
if __name__ == '__main__':
main()
``` | output | 1 | 76,510 | 5 | 153,021 |
Provide a correct Python 3 solution for this coding contest problem.
Find the number of sequences of length K consisting of positive integers such that the product of any two adjacent elements is at most N, modulo 10^9+7.
Constraints
* 1\leq N\leq 10^9
* ~~1~~ 2\leq K\leq 100 (fixed at 21:33 JST)
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N K
Output
Print the number of sequences, modulo 10^9+7.
Examples
Input
3 2
Output
5
Input
10 3
Output
147
Input
314159265 35
Output
457397712 | instruction | 0 | 76,511 | 5 | 153,022 |
"Correct Solution:
```
from itertools import accumulate
def BC132_F():
n, k = list(map(int, input().split(' ')))
mod = 10**9 + 7
sqt = int(n**0.5)
cnt = [n // i - n // (i + 1) for i in range(1, n // sqt)] + [1] * sqt
x = cnt
for _ in range(k):
x = [(i * j) % mod for i, j in zip(accumulate(reversed(x)), cnt)]
return x[-1]
print(BC132_F())
``` | output | 1 | 76,511 | 5 | 153,023 |
Provide a correct Python 3 solution for this coding contest problem.
Find the number of sequences of length K consisting of positive integers such that the product of any two adjacent elements is at most N, modulo 10^9+7.
Constraints
* 1\leq N\leq 10^9
* ~~1~~ 2\leq K\leq 100 (fixed at 21:33 JST)
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N K
Output
Print the number of sequences, modulo 10^9+7.
Examples
Input
3 2
Output
5
Input
10 3
Output
147
Input
314159265 35
Output
457397712 | instruction | 0 | 76,512 | 5 | 153,024 |
"Correct Solution:
```
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
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 pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)
def main():
n,k = LI()
l = []
sq = int(n ** 0.5) + 1
for i in range(1,sq+1):
l.append((i,n//i,1))
t = sq
# print(sq,l)
for j,i,_ in l[::-1]:
# print(j,i,_)
if t >= i:
continue
c = i - t
l.append((i,j,c))
t = i
# print(l)
ll = len(l)
dp = [[0] * ll for _ in range(k+1)]
dp[0][0] = 1
l.append((inf,0,0))
for i in range(k):
dpi = dp[i]
np = dp[i+1]
m = 0
c = 0
for j in range(ll-1,-1,-1):
t = l[j][1]
tc = l[j][2]
while l[m][0] <= t:
c += dpi[m]
c %= mod
m += 1
np[j] = c * tc % mod
# print(dp)
return sum(dp[-1]) % mod
print(main())
``` | output | 1 | 76,512 | 5 | 153,025 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Find the number of sequences of length K consisting of positive integers such that the product of any two adjacent elements is at most N, modulo 10^9+7.
Constraints
* 1\leq N\leq 10^9
* ~~1~~ 2\leq K\leq 100 (fixed at 21:33 JST)
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N K
Output
Print the number of sequences, modulo 10^9+7.
Examples
Input
3 2
Output
5
Input
10 3
Output
147
Input
314159265 35
Output
457397712
Submitted Solution:
```
import math
MOD = 10**9 + 7
def main():
N, K = map(int, input().split())
R = int(math.sqrt(N))
if N // R == R:
M = R * 2 - 1
else:
M = R * 2
mapping = [0] * (M+1)
for i in range(1, R+1):
mapping[i] = i
mapping[-i] = N//i
cnt = [0] * (M+1)
for i in range(1, M+1):
cnt[i] = mapping[i] - mapping[i-1]
dp = [[0] * (M+1) for _ in range(K+1)]
dp[0] = list(cnt)
for i in range(M):
dp[0][i+1] += dp[0][i]
for i in range(K-1):
for j in range(1, M+1):
if j <= R:
idx = -j
else:
idx = M - j + 1
dp[i+1][j] = dp[i][idx]
for j in range(M):
dp[i+1][j+1] = (dp[i+1][j] + dp[i+1][j+1] * cnt[j+1]) % MOD
print(dp[K-1][M])
if __name__ == "__main__":
main()
``` | instruction | 0 | 76,513 | 5 | 153,026 |
Yes | output | 1 | 76,513 | 5 | 153,027 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Find the number of sequences of length K consisting of positive integers such that the product of any two adjacent elements is at most N, modulo 10^9+7.
Constraints
* 1\leq N\leq 10^9
* ~~1~~ 2\leq K\leq 100 (fixed at 21:33 JST)
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N K
Output
Print the number of sequences, modulo 10^9+7.
Examples
Input
3 2
Output
5
Input
10 3
Output
147
Input
314159265 35
Output
457397712
Submitted Solution:
```
N, K = map(int, input().split())
mod = 10**9+7
n = 1
A = []
while True:
A.append(N//n)
if N//(n+1) < n+1: break
n += 1
A.append(n)
L = 2*n
dp = [[0]*L for _ in range(K)]
for l in range(n):
dp[0][l] = 1
i = 0
for l in reversed(range(n, L)):
dp[0][l] = A[i] - A[i+1]
i += 1
for k in range(1, K):
s = 0
for l in reversed(range(L)):
s = (s+dp[k-1][L-l-1]) % mod
dp[k][l] = s * dp[0][l] % mod
ans = 0
for l in range(L):
ans = (ans + dp[K-1][l]) % mod
print(ans)
``` | instruction | 0 | 76,514 | 5 | 153,028 |
Yes | output | 1 | 76,514 | 5 | 153,029 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Find the number of sequences of length K consisting of positive integers such that the product of any two adjacent elements is at most N, modulo 10^9+7.
Constraints
* 1\leq N\leq 10^9
* ~~1~~ 2\leq K\leq 100 (fixed at 21:33 JST)
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N K
Output
Print the number of sequences, modulo 10^9+7.
Examples
Input
3 2
Output
5
Input
10 3
Output
147
Input
314159265 35
Output
457397712
Submitted Solution:
```
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
mod = 10 ** 9 + 7
h = 1
t = set()
while h * h <= N:
t.add(N // h)
t.add(h)
h += 1
t = sorted(t)
#print(len(t))
tt = []
for x in t:
tt.append(N // x)
dp = [[0] * len(t) for _ in range(K + 1)]
dp[0][0] = 1
for i in range(K):
for j in range(len(t)):
k = len(t) - j - 1
dp[i + 1][k] += dp[i][j]
dp[i + 1][k] %= mod
#print(dp)
for k in range(len(t) - 1, 0, -1):
dp[i + 1][k - 1] += dp[i + 1][k]
dp[i + 1][k - 1] %= mod
rng = (t[k] - t[k - 1]) % mod
dp[i + 1][k] *= rng
dp[i + 1][k] %= mod
#print(dp)
res = 0
#print(dp)
for j in range(len(t)):
res += dp[-1][j]
res %= mod
print(res)
``` | instruction | 0 | 76,515 | 5 | 153,030 |
Yes | output | 1 | 76,515 | 5 | 153,031 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Find the number of sequences of length K consisting of positive integers such that the product of any two adjacent elements is at most N, modulo 10^9+7.
Constraints
* 1\leq N\leq 10^9
* ~~1~~ 2\leq K\leq 100 (fixed at 21:33 JST)
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N K
Output
Print the number of sequences, modulo 10^9+7.
Examples
Input
3 2
Output
5
Input
10 3
Output
147
Input
314159265 35
Output
457397712
Submitted Solution:
```
def f(n,k):
lim = int((n + 0.1) ** 0.5) + 1
ws = []
s = 0
for i in range(1, lim):
w = n // i - n // (i + 1)
ws.append(w)
s += w
ws += [1] * (n - s)
m = len(ws)
dp0 = ws[::-1]
dp1 = [0] * m
for _ in range(k - 1):
s = 0
for j in range(m):
s += dp0[j]
dp1[m - j - 1] = (s * ws[j]) % md
dp0 = dp1[:]
print(sum(dp0) % md)
md=10**9+7
n,k=map(int,input().split())
f(n,k)
``` | instruction | 0 | 76,516 | 5 | 153,032 |
Yes | output | 1 | 76,516 | 5 | 153,033 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Find the number of sequences of length K consisting of positive integers such that the product of any two adjacent elements is at most N, modulo 10^9+7.
Constraints
* 1\leq N\leq 10^9
* ~~1~~ 2\leq K\leq 100 (fixed at 21:33 JST)
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N K
Output
Print the number of sequences, modulo 10^9+7.
Examples
Input
3 2
Output
5
Input
10 3
Output
147
Input
314159265 35
Output
457397712
Submitted Solution:
```
n, k = list(map(int, input().split()))
mod = 10 ** 9 + 7
m = n ** 0.5
cnt = [n // i - n // (i + 1) for i in range(1, int(m) + 1)]
cnt = (cnt + [1 for _ in range(n - sum(cnt))])[::-1]
nxt = cnt[:]
for _ in range(k - 1):
cnt = [sum([x * nxt[i] % mod for x in cnt[:(len(cnt) - i)]]) for i in range(len(cnt))]
print(sum(cnt) % mod)
``` | instruction | 0 | 76,517 | 5 | 153,034 |
No | output | 1 | 76,517 | 5 | 153,035 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Find the number of sequences of length K consisting of positive integers such that the product of any two adjacent elements is at most N, modulo 10^9+7.
Constraints
* 1\leq N\leq 10^9
* ~~1~~ 2\leq K\leq 100 (fixed at 21:33 JST)
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N K
Output
Print the number of sequences, modulo 10^9+7.
Examples
Input
3 2
Output
5
Input
10 3
Output
147
Input
314159265 35
Output
457397712
Submitted Solution:
```
from bisect import bisect_left
n,k=map(int,input().split())
d=[1]
t=[1]
for i in range(2,int(n**0.5)+2):
if n//d[-1]!=n//i:
d.append(i)
t.append(1)
else:
t[-1]+=1
dd=[]
for i in range(d[-1],0,-1):
if n//i<=d[-1]:continue
dd.append(n//i)
x=d+dd
for i in range(len(t),len(x)):
t.append(x[i]-x[i-1])
di=[0]*len(x)
mod=10**9+7
for i in range(len(x)):di[i]=bisect_left(x,n//x[i])
n=len(x)
dp=[n*[0]for _ in range(k)]
dp[0]=t[:]
for i in range(1,k):
for j in range(1,n):
dp[i-1][j]+=dp[i-1][j-1]
dp[i-1][j]%=mod
for j in range(n):dp[i][j]=dp[i-1][di[j]]*t[j]%mod
print(sum(dp[-1])%mod)
``` | instruction | 0 | 76,518 | 5 | 153,036 |
No | output | 1 | 76,518 | 5 | 153,037 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Find the number of sequences of length K consisting of positive integers such that the product of any two adjacent elements is at most N, modulo 10^9+7.
Constraints
* 1\leq N\leq 10^9
* ~~1~~ 2\leq K\leq 100 (fixed at 21:33 JST)
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N K
Output
Print the number of sequences, modulo 10^9+7.
Examples
Input
3 2
Output
5
Input
10 3
Output
147
Input
314159265 35
Output
457397712
Submitted Solution:
```
hoge = input().split()
N = int(hoge[0])
K = int(hoge[1])
if K == 2:
print(int((N*K-1) % (1e9 + 7)))
else:
hage = round(N / 2 - 0.5 + 0.01)
print(int((pow(K,K) * hage + (hage-1)*K) % (1e9 + 7)))
``` | instruction | 0 | 76,519 | 5 | 153,038 |
No | output | 1 | 76,519 | 5 | 153,039 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Find the number of sequences of length K consisting of positive integers such that the product of any two adjacent elements is at most N, modulo 10^9+7.
Constraints
* 1\leq N\leq 10^9
* ~~1~~ 2\leq K\leq 100 (fixed at 21:33 JST)
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N K
Output
Print the number of sequences, modulo 10^9+7.
Examples
Input
3 2
Output
5
Input
10 3
Output
147
Input
314159265 35
Output
457397712
Submitted Solution:
```
import math
N,K=map(int,input().split())
rt=math.floor(math.sqrt(N))
l = rt*2-1 if rt*rt+rt>N else rt*2
m = [[0,0] for i in range(l)]
for i in range(rt):
m[i][0]=i+1
m[l-1-i][0]=math.floor(N/(i+1))
m[0][1]=1
for i in range(1,l):
m[i][1]=m[i][0]-m[i-1][0]
mn=[m[i][1] for i in range(l)]
mn1=[0]*l
for k in range(1,K):
y=0
for i in range(0,l):
y+=mn[i]
mn1[l-1-i]=y*m[l-1-i][1]%1000000007
mn,mn1=mn1,mn
print(sum(mn)%1000000007)
``` | instruction | 0 | 76,520 | 5 | 153,040 |
No | output | 1 | 76,520 | 5 | 153,041 |
Provide a correct Python 3 solution for this coding contest problem.
Description
Since the cubic equation: ax ^ 3 + bx ^ 2 + cx + d = 0 is given, please check the number of positive real roots and the number of negative real roots, respectively.
The number of roots shall be counted including the multiple roots.
Input
The input consists of multiple test cases, and the number is recorded on the first line.
From the second line onward, the coefficients of the cubic equation are written in the form of a b c d. a is not 0, and each number is an integer value from -100 to 100.
Output
For a given cubic equation, output the number of positive real roots and the number of negative real roots separated by a space.
Example
Input
2
1 3 3 1
-10 0 0 0
Output
0 3
0 0 | instruction | 0 | 76,644 | 5 | 153,288 |
"Correct Solution:
```
n=int(input())
def f(a,b,c,d):
return lambda x:a*x**3+b*x**2+c*x+d
for i in range(n):
a,b,c,d=map(int,input().split())
fx=f(a,b,c,d)
D=b**2-3*a*c
if D<=0 :
if d==0:
pl=mi=0
elif (a>0 and d<0) or (a<0 and d>0):
pl,mi=1,0
elif (a<0 and d<0) or (a>0 and d>0):
pl,mi=0,1
else:
if a>0:
al=(-b-D**0.5)/(3*a)
be=(-b+D**0.5)/(3*a)
if (fx(al)<0 or fx(be)>0) and d==0:
pl=mi=0
elif ((fx(al)<0 or fx(be)>0) and d>0) or (fx(be)==0 and d==0 and be==0):
pl,mi=0,1
elif (fx(al)==0 or (fx(al)>0 and fx(be)<0)) and d==0 and be<0:
pl,mi=0,2
elif (fx(al)==0 or fx(be)==0 or (fx(al)>0 and fx(be)<0)) and d>0 and be<0:
pl,mi=0,3
elif ((fx(al)<0 or fx(be)>0) and d<0) or (fx(al)==0 and d==0 and al==0):
pl,mi=1,0
elif fx(al)>0 and fx(be)<0 and d==0 and al<0 and be>0:
pl=mi=1
elif (fx(al)==0 or (fx(al)>0 and fx(be)<0)) and d<0 and al<0:
pl,mi=1,2
elif (fx(be)==0 or (fx(al)>0 and fx(be)<0)) and d==0 and al>0:
pl,mi=2,0
elif (fx(be)==0 or (fx(al)>0 and fx(be)<0)) and d>0 and be>0:
pl,mi=2,1
elif ((fx(al)==0 and al>0) or fx(be)==0 or (fx(al)>0 and fx(be)<0 and al>0)) and d<0:
pl,mi=3,0
else:
al=(-b+D**0.5)/(3*a)
be=(-b-D**0.5)/(3*a)
if (fx(al)>0 or fx(be)<0) and d==0:
pl=mi=0
elif ((fx(al)>0 or fx(be)<0) and d<0) or (fx(be)==0 and d==0 and be==0):
pl,mi=0,1
elif (fx(al)==0 or (fx(al)<0 and fx(be)>0)) and d==0 and be<0:
pl,mi=0,2
elif (fx(al)==0 or fx(be)==0 or (fx(al)<0 and fx(be)>0)) and d<0 and be<0:
pl,mi=0,3
elif ((fx(al)>0 or fx(be)<0) and d>0) or (fx(al)==0 and d==0 and al==0):
pl,mi=1,0
elif fx(al)<0 and fx(be)>0 and d==0 and al<0 and be>0:
pl=mi=1
elif (fx(al)==0 or (fx(al)<0 and fx(be)>0)) and d>0 and al<0:
pl,mi=1,2
elif (fx(be)==0 or (fx(al)<0 and fx(be)>0)) and d==0 and al>0:
pl,mi=2,0
elif (fx(be)==0 or (fx(al)<0 and fx(be)>0)) and d<0 and be>0:
pl,mi=2,1
elif (fx(al)==0 or fx(be)==0 or (fx(al)<0 and fx(be)>0)) and d>0 and al>0:
pl,mi=3,0
print(pl,mi)
``` | output | 1 | 76,644 | 5 | 153,289 |
Provide a correct Python 3 solution for this coding contest problem.
Example
Input
2 1
WE
Output
1 2 | instruction | 0 | 76,649 | 5 | 153,298 |
"Correct 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**10
mod = 998244353
dd = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)]
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 main():
n,m = LI()
a = [S() for _ in range(m)]
b = [0] * (n+1)
c = [0] * (n+1)
for i in range(n):
for j in range(m):
if a[j][i] == 'W':
b[i] += 1
else:
c[i] += 1
for i in range(n):
c[i+1] += c[i]
for i in range(n-2,-1,-1):
b[i] += b[i+1]
m = b[0]
r = 0
for i in range(n):
tm = b[i+1] + c[i]
if m > tm:
r = i + 1
m = tm
return '{} {}'.format(r,r+1)
print(main())
``` | output | 1 | 76,649 | 5 | 153,299 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two arrays a_0, a_1, …, a_{n - 1} and b_0, b_1, …, b_{m-1}, and an integer c.
Compute the following sum:
$$$∑_{i=0}^{n-1} ∑_{j=0}^{m-1} a_i b_j c^{i^2\,j^3}$$$
Since it's value can be really large, print it modulo 490019.
Input
First line contains three integers n, m and c (1 ≤ n, m ≤ 100 000, 1 ≤ c < 490019).
Next line contains exactly n integers a_i and defines the array a (0 ≤ a_i ≤ 1000).
Last line contains exactly m integers b_i and defines the array b (0 ≤ b_i ≤ 1000).
Output
Print one integer — value of the sum modulo 490019.
Examples
Input
2 2 3
0 1
0 1
Output
3
Input
3 4 1
1 1 1
1 1 1 1
Output
12
Input
2 3 3
1 2
3 4 5
Output
65652
Note
In the first example, the only non-zero summand corresponds to i = 1, j = 1 and is equal to 1 ⋅ 1 ⋅ 3^1 = 3.
In the second example, all summands are equal to 1.
Submitted Solution:
```
a = input().split(" ")
n = int(a[0])
m = int(a[1])
c = int(a[2])
a = input().split(' ')
b = input().split(' ')
a = [int(i) for i in a]
b = [int(i) for i in b]
if n > m:
n, m = m, n
a, b = b, a
sum = 0
ij = [(j**3 * i**2)%490019 for j in range(m) for i in range(n)]
for i in range(n):
sum_1 = 0
for j in range(m):
sum_1 += (b[j]*pow(c, ij[j*n + i], 490019))
sum += sum_1 * a[i]
sum %= 490019
print(sum)
``` | instruction | 0 | 76,716 | 5 | 153,432 |
No | output | 1 | 76,716 | 5 | 153,433 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two arrays a_0, a_1, …, a_{n - 1} and b_0, b_1, …, b_{m-1}, and an integer c.
Compute the following sum:
$$$∑_{i=0}^{n-1} ∑_{j=0}^{m-1} a_i b_j c^{i^2\,j^3}$$$
Since it's value can be really large, print it modulo 490019.
Input
First line contains three integers n, m and c (1 ≤ n, m ≤ 100 000, 1 ≤ c < 490019).
Next line contains exactly n integers a_i and defines the array a (0 ≤ a_i ≤ 1000).
Last line contains exactly m integers b_i and defines the array b (0 ≤ b_i ≤ 1000).
Output
Print one integer — value of the sum modulo 490019.
Examples
Input
2 2 3
0 1
0 1
Output
3
Input
3 4 1
1 1 1
1 1 1 1
Output
12
Input
2 3 3
1 2
3 4 5
Output
65652
Note
In the first example, the only non-zero summand corresponds to i = 1, j = 1 and is equal to 1 ⋅ 1 ⋅ 3^1 = 3.
In the second example, all summands are equal to 1.
Submitted Solution:
```
print("hello icpc")
``` | instruction | 0 | 76,717 | 5 | 153,434 |
No | output | 1 | 76,717 | 5 | 153,435 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two arrays a_0, a_1, …, a_{n - 1} and b_0, b_1, …, b_{m-1}, and an integer c.
Compute the following sum:
$$$∑_{i=0}^{n-1} ∑_{j=0}^{m-1} a_i b_j c^{i^2\,j^3}$$$
Since it's value can be really large, print it modulo 490019.
Input
First line contains three integers n, m and c (1 ≤ n, m ≤ 100 000, 1 ≤ c < 490019).
Next line contains exactly n integers a_i and defines the array a (0 ≤ a_i ≤ 1000).
Last line contains exactly m integers b_i and defines the array b (0 ≤ b_i ≤ 1000).
Output
Print one integer — value of the sum modulo 490019.
Examples
Input
2 2 3
0 1
0 1
Output
3
Input
3 4 1
1 1 1
1 1 1 1
Output
12
Input
2 3 3
1 2
3 4 5
Output
65652
Note
In the first example, the only non-zero summand corresponds to i = 1, j = 1 and is equal to 1 ⋅ 1 ⋅ 3^1 = 3.
In the second example, all summands are equal to 1.
Submitted Solution:
```
n, m, c = map(int, input().split(' '))
a = input().split()
for i in range(len(a)):
a[i] = int(a[i])
b = input().split()
for i in range(len(b)):
b[i] = int(b[i])
su = 0
for i in range(0,n):
for j in range(0,m):
su = (su + (a[i] * b[j] * c % 490019) ** (i*i*j*j*j % 490019)) % 490019
print(su)
``` | instruction | 0 | 76,718 | 5 | 153,436 |
No | output | 1 | 76,718 | 5 | 153,437 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two arrays a_0, a_1, …, a_{n - 1} and b_0, b_1, …, b_{m-1}, and an integer c.
Compute the following sum:
$$$∑_{i=0}^{n-1} ∑_{j=0}^{m-1} a_i b_j c^{i^2\,j^3}$$$
Since it's value can be really large, print it modulo 490019.
Input
First line contains three integers n, m and c (1 ≤ n, m ≤ 100 000, 1 ≤ c < 490019).
Next line contains exactly n integers a_i and defines the array a (0 ≤ a_i ≤ 1000).
Last line contains exactly m integers b_i and defines the array b (0 ≤ b_i ≤ 1000).
Output
Print one integer — value of the sum modulo 490019.
Examples
Input
2 2 3
0 1
0 1
Output
3
Input
3 4 1
1 1 1
1 1 1 1
Output
12
Input
2 3 3
1 2
3 4 5
Output
65652
Note
In the first example, the only non-zero summand corresponds to i = 1, j = 1 and is equal to 1 ⋅ 1 ⋅ 3^1 = 3.
In the second example, all summands are equal to 1.
Submitted Solution:
```
import math
n, m, c = input().split(' ')
n = int(n)
m = int(m)
c = int(c)
a = input().split(' ')
b = input().split(' ')
k = 0
for i in range(0, n):
for j in range(0, m):
power = math.pow(i, 2) * math.pow(j, 3)
k += int(a[i]) * int(b[j]) * math.pow(c, power)
print(k)
``` | instruction | 0 | 76,719 | 5 | 153,438 |
No | output | 1 | 76,719 | 5 | 153,439 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given a positive integer m, we say that a sequence x_1, x_2, ..., x_n of positive integers is m-cute if for every index i such that 2 ≤ i ≤ n it holds that x_i = x_{i - 1} + x_{i - 2} + ... + x_1 + r_i for some positive integer r_i satisfying 1 ≤ r_i ≤ m.
You will be given q queries consisting of three positive integers a, b and m. For each query you must determine whether or not there exists an m-cute sequence whose first term is a and whose last term is b. If such a sequence exists, you must additionally find an example of it.
Input
The first line contains an integer number q (1 ≤ q ≤ 10^3) — the number of queries.
Each of the following q lines contains three integers a, b, and m (1 ≤ a, b, m ≤ 10^{14}, a ≤ b), describing a single query.
Output
For each query, if no m-cute sequence whose first term is a and whose last term is b exists, print -1.
Otherwise print an integer k (1 ≤ k ≤ 50), followed by k integers x_1, x_2, ..., x_k (1 ≤ x_i ≤ 10^{14}). These integers must satisfy x_1 = a, x_k = b, and that the sequence x_1, x_2, ..., x_k is m-cute.
It can be shown that under the problem constraints, for each query either no m-cute sequence exists, or there exists one with at most 50 terms.
If there are multiple possible sequences, you may print any of them.
Example
Input
2
5 26 2
3 9 1
Output
4 5 6 13 26
-1
Note
Consider the sample. In the first query, the sequence 5, 6, 13, 26 is valid since 6 = 5 + \bf{\color{blue} 1}, 13 = 6 + 5 + {\bf\color{blue} 2} and 26 = 13 + 6 + 5 + {\bf\color{blue} 2} have the bold values all between 1 and 2, so the sequence is 2-cute. Other valid sequences, such as 5, 7, 13, 26 are also accepted.
In the second query, the only possible 1-cute sequence starting at 3 is 3, 4, 8, 16, ..., which does not contain 9.
Submitted Solution:
```
from itertools import count
#from hypothesis import given
#from hypothesis.strategies import integers
#
#
#ABM = integers(min_value=1, max_value=int(1e14))
def debug(*args, **kwargs):
import sys
#print(*args, *('{}: {}'.format(k, v) for k, v in kwargs.items()), sep='; ', file=sys.stderr)
def solve(a, b, m):
if a == b:
return [a]
debug(a=a,b=b,m=m)
for k in count(2):
lo = 2**(k-2)*a + 2**(k-2)
hi = 2**(k-2)*a + 2**(k-2)*m
debug(k=k, lo=lo, hi=hi)
if lo > b:
break
if b <= hi:
ans = [a] + [2**(i-1)*a + 2**(i-1) for i in range(1, k)]
debug("got one", start=ans)
if m == 1:
return ans
for i in range(1, k - 1):
deficit = b - ans[-1]
quot = min(deficit // 2**(k - 2 - i), m - 1)
ans[i] += quot
for j in range(i + 1, k):
ans[j] += 2**(j - i - 1)*quot
ans[-1] = b
return ans
return None
def check(a, b, m, ans):
assert ans[-1] == b
for i in range(1, len(ans)):
assert 1 <= ans[i] - sum(ans[:i]) <= m
#@given(ABM, ABM, ABM)
def test_solve(a, b, m):
if a > b:
a, b = b, a
ans = solve(a, b, m)
if ans is None:
return
check(a, b, m, ans)
def main():
q = int(input())
for _ in range(q):
a, b, m = map(int, input().split())
ans = solve(a, b, m)
debug(a=a, b=b, m=m, ans=ans)
if ans:
check(a, b, m, ans)
print(len(ans), *ans)
else:
print(-1)
if __name__ == "__main__":
main()
``` | instruction | 0 | 76,776 | 5 | 153,552 |
Yes | output | 1 | 76,776 | 5 | 153,553 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given a positive integer m, we say that a sequence x_1, x_2, ..., x_n of positive integers is m-cute if for every index i such that 2 ≤ i ≤ n it holds that x_i = x_{i - 1} + x_{i - 2} + ... + x_1 + r_i for some positive integer r_i satisfying 1 ≤ r_i ≤ m.
You will be given q queries consisting of three positive integers a, b and m. For each query you must determine whether or not there exists an m-cute sequence whose first term is a and whose last term is b. If such a sequence exists, you must additionally find an example of it.
Input
The first line contains an integer number q (1 ≤ q ≤ 10^3) — the number of queries.
Each of the following q lines contains three integers a, b, and m (1 ≤ a, b, m ≤ 10^{14}, a ≤ b), describing a single query.
Output
For each query, if no m-cute sequence whose first term is a and whose last term is b exists, print -1.
Otherwise print an integer k (1 ≤ k ≤ 50), followed by k integers x_1, x_2, ..., x_k (1 ≤ x_i ≤ 10^{14}). These integers must satisfy x_1 = a, x_k = b, and that the sequence x_1, x_2, ..., x_k is m-cute.
It can be shown that under the problem constraints, for each query either no m-cute sequence exists, or there exists one with at most 50 terms.
If there are multiple possible sequences, you may print any of them.
Example
Input
2
5 26 2
3 9 1
Output
4 5 6 13 26
-1
Note
Consider the sample. In the first query, the sequence 5, 6, 13, 26 is valid since 6 = 5 + \bf{\color{blue} 1}, 13 = 6 + 5 + {\bf\color{blue} 2} and 26 = 13 + 6 + 5 + {\bf\color{blue} 2} have the bold values all between 1 and 2, so the sequence is 2-cute. Other valid sequences, such as 5, 7, 13, 26 are also accepted.
In the second query, the only possible 1-cute sequence starting at 3 is 3, 4, 8, 16, ..., which does not contain 9.
Submitted Solution:
```
q = int(input())
for _ in range(q):
a, b, m = map(int, input().split())
if a == b:
print(1, a)
continue
a1 = a + 1
am = a + m
for i in range(49):
if a1 <= b <= am:
n = i + 2
s = 0
ans = [a, *[0] * (n - 1)]
for j in range(1, n):
s += ans[j - 1]
ans[j] = s + 1
diff = b - ans[-1]
sr = 0
ss = 0
for j in range(1, n):
p = int(max(1, 2 ** (n - 2 - j)))
r = min(diff // p, m - 1)
ss = sr + r
sr += ss
ans[j] += ss
diff -= r * p
print(n, ' '.join(map(str, ans)))
break
a1 *= 2
am *= 2
else:
print(-1)
``` | instruction | 0 | 76,777 | 5 | 153,554 |
Yes | output | 1 | 76,777 | 5 | 153,555 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given a positive integer m, we say that a sequence x_1, x_2, ..., x_n of positive integers is m-cute if for every index i such that 2 ≤ i ≤ n it holds that x_i = x_{i - 1} + x_{i - 2} + ... + x_1 + r_i for some positive integer r_i satisfying 1 ≤ r_i ≤ m.
You will be given q queries consisting of three positive integers a, b and m. For each query you must determine whether or not there exists an m-cute sequence whose first term is a and whose last term is b. If such a sequence exists, you must additionally find an example of it.
Input
The first line contains an integer number q (1 ≤ q ≤ 10^3) — the number of queries.
Each of the following q lines contains three integers a, b, and m (1 ≤ a, b, m ≤ 10^{14}, a ≤ b), describing a single query.
Output
For each query, if no m-cute sequence whose first term is a and whose last term is b exists, print -1.
Otherwise print an integer k (1 ≤ k ≤ 50), followed by k integers x_1, x_2, ..., x_k (1 ≤ x_i ≤ 10^{14}). These integers must satisfy x_1 = a, x_k = b, and that the sequence x_1, x_2, ..., x_k is m-cute.
It can be shown that under the problem constraints, for each query either no m-cute sequence exists, or there exists one with at most 50 terms.
If there are multiple possible sequences, you may print any of them.
Example
Input
2
5 26 2
3 9 1
Output
4 5 6 13 26
-1
Note
Consider the sample. In the first query, the sequence 5, 6, 13, 26 is valid since 6 = 5 + \bf{\color{blue} 1}, 13 = 6 + 5 + {\bf\color{blue} 2} and 26 = 13 + 6 + 5 + {\bf\color{blue} 2} have the bold values all between 1 and 2, so the sequence is 2-cute. Other valid sequences, such as 5, 7, 13, 26 are also accepted.
In the second query, the only possible 1-cute sequence starting at 3 is 3, 4, 8, 16, ..., which does not contain 9.
Submitted Solution:
```
def get_r_list(a, b, m):
k = 2
two_power_k = 1
isMatch = False
if a == b:
return 1, []
while True:
if b <= two_power_k * (a + 1):
isMatch = True
break
if k == 50:
break
k += 1
two_power_k *= 2
isDone = False
if isMatch and b < two_power_k * (a + 1):
k -= 1
two_power_k = int(two_power_k / 2)
gap = b - two_power_k * (a + 1)
two_power_k = int(two_power_k / 2) # 2^k-3
r_list = []
if b == two_power_k * (a + 1) * 2:
isDone = True
for i in range(1, k - 1):
r_list.append(0)
while two_power_k != 0:
# print("two: ", end="")
# print(two_power_k)
if gap >= two_power_k:
index_r = 0
gap_divide = int(gap / two_power_k)
if gap_divide > m - 1:
index_r = m - 1
else:
index_r = gap_divide
gap = gap - two_power_k * index_r
r_list.append(index_r)
two_power_k = int(two_power_k / 2)
else:
two_power_k = int(two_power_k / 2)
r_list.append(0)
if gap == 0:
isDone = True
r_list.append(0)
else:
if gap <= m - 1:
isDone = True
r_list.append(gap)
else:
isDone = False
if isDone:
return k, r_list
else:
return -1, r_list
# print(k)
# print(r_list)
def cute_sequence(a, b, m):
k, r_list = get_r_list(a, b, m)
if k == -1:
print(k)
return
if k == 1:
print(1, end=" ")
print(b)
return
sequence_list = []
sequence_list.append(a)
sequence_list.append(a + r_list[0] + 1)
for i in range(2, k):
next_a = 2 * sequence_list[i - 1] + r_list[i - 1] - r_list[i - 2]
sequence_list.append(next_a)
print(k, end=" ")
for ele in sequence_list:
print(ele, end=" ")
print()
return
N = int(input())
for _ in range(N):
a, b, m = input().split()
a = int(a)
b = int(b)
m = int(m)
cute_sequence(a, b, m)
``` | instruction | 0 | 76,778 | 5 | 153,556 |
Yes | output | 1 | 76,778 | 5 | 153,557 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.