message stringlengths 2 59.7k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 37 108k | cluster float64 20 20 | __index_level_0__ int64 74 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a function f written in some basic language. The function accepts an integer value, which is immediately written into some variable x. x is an integer variable and can be assigned values from 0 to 2^{32}-1. The function contains three types of commands:
* for n β for loop;
* end β every command between "for n" and corresponding "end" is executed n times;
* add β adds 1 to x.
After the execution of these commands, value of x is returned.
Every "for n" is matched with "end", thus the function is guaranteed to be valid. "for n" can be immediately followed by "end"."add" command can be outside of any for loops.
Notice that "add" commands might overflow the value of x! It means that the value of x becomes greater than 2^{32}-1 after some "add" command.
Now you run f(0) and wonder if the resulting value of x is correct or some overflow made it incorrect.
If overflow happened then output "OVERFLOW!!!", otherwise print the resulting value of x.
Input
The first line contains a single integer l (1 β€ l β€ 10^5) β the number of lines in the function.
Each of the next l lines contains a single command of one of three types:
* for n (1 β€ n β€ 100) β for loop;
* end β every command between "for n" and corresponding "end" is executed n times;
* add β adds 1 to x.
Output
If overflow happened during execution of f(0), then output "OVERFLOW!!!", otherwise print the resulting value of x.
Examples
Input
9
add
for 43
end
for 10
for 15
add
end
add
end
Output
161
Input
2
for 62
end
Output
0
Input
11
for 100
for 100
for 100
for 100
for 100
add
end
end
end
end
end
Output
OVERFLOW!!!
Note
In the first example the first "add" is executed 1 time, the second "add" is executed 150 times and the last "add" is executed 10 times. Note that "for n" can be immediately followed by "end" and that "add" can be outside of any for loops.
In the second example there are no commands "add", thus the returning value is 0.
In the third example "add" command is executed too many times, which causes x to go over 2^{32}-1.
Submitted Solution:
```
l = int(input())
stack = [1]
flag = False
x = 0
INF = (2**32) - 1
for i in range(l):
cmd = input()
if cmd[0] == "f":
t = stack[-1] *int(cmd.split()[1])
if t > INF: t = INF + 1
stack.append(t)
if cmd[0] == "e":
stack.pop()
if cmd[0] == "a":
x += stack[-1]
if x > INF:
flag = True
if flag == True:
print("OVERFLOW!!!")
else:
print(x)
``` | instruction | 0 | 107,103 | 20 | 214,206 |
Yes | output | 1 | 107,103 | 20 | 214,207 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a function f written in some basic language. The function accepts an integer value, which is immediately written into some variable x. x is an integer variable and can be assigned values from 0 to 2^{32}-1. The function contains three types of commands:
* for n β for loop;
* end β every command between "for n" and corresponding "end" is executed n times;
* add β adds 1 to x.
After the execution of these commands, value of x is returned.
Every "for n" is matched with "end", thus the function is guaranteed to be valid. "for n" can be immediately followed by "end"."add" command can be outside of any for loops.
Notice that "add" commands might overflow the value of x! It means that the value of x becomes greater than 2^{32}-1 after some "add" command.
Now you run f(0) and wonder if the resulting value of x is correct or some overflow made it incorrect.
If overflow happened then output "OVERFLOW!!!", otherwise print the resulting value of x.
Input
The first line contains a single integer l (1 β€ l β€ 10^5) β the number of lines in the function.
Each of the next l lines contains a single command of one of three types:
* for n (1 β€ n β€ 100) β for loop;
* end β every command between "for n" and corresponding "end" is executed n times;
* add β adds 1 to x.
Output
If overflow happened during execution of f(0), then output "OVERFLOW!!!", otherwise print the resulting value of x.
Examples
Input
9
add
for 43
end
for 10
for 15
add
end
add
end
Output
161
Input
2
for 62
end
Output
0
Input
11
for 100
for 100
for 100
for 100
for 100
add
end
end
end
end
end
Output
OVERFLOW!!!
Note
In the first example the first "add" is executed 1 time, the second "add" is executed 150 times and the last "add" is executed 10 times. Note that "for n" can be immediately followed by "end" and that "add" can be outside of any for loops.
In the second example there are no commands "add", thus the returning value is 0.
In the third example "add" command is executed too many times, which causes x to go over 2^{32}-1.
Submitted Solution:
```
from sys import stdin
def solve():
#stdin = open("B. Catch Overflow.txt")
x = 0
max_x = 2**32 - 1
loop = 1
pre_fors = []
mult = []
flag = 0
for _ in range(int(stdin.readline())):
command = [k for k in stdin.readline().split()]
if command[0] == "add":
if flag:
x = max_x + 10
break
x += loop
elif command[0] == "for":
k = int(command[1])
if flag or loop*k > max_x:
mult.append(k)
flag = 1
else:
loop *= k
pre_fors.append(k)
else:
if flag:
mult.pop()
if not mult:
flag = 0
else:
k = pre_fors.pop()
loop //= k
print ("OVERFLOW!!!" if x > max_x else x)
if __name__ == "__main__":
solve()
``` | instruction | 0 | 107,104 | 20 | 214,208 |
Yes | output | 1 | 107,104 | 20 | 214,209 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a function f written in some basic language. The function accepts an integer value, which is immediately written into some variable x. x is an integer variable and can be assigned values from 0 to 2^{32}-1. The function contains three types of commands:
* for n β for loop;
* end β every command between "for n" and corresponding "end" is executed n times;
* add β adds 1 to x.
After the execution of these commands, value of x is returned.
Every "for n" is matched with "end", thus the function is guaranteed to be valid. "for n" can be immediately followed by "end"."add" command can be outside of any for loops.
Notice that "add" commands might overflow the value of x! It means that the value of x becomes greater than 2^{32}-1 after some "add" command.
Now you run f(0) and wonder if the resulting value of x is correct or some overflow made it incorrect.
If overflow happened then output "OVERFLOW!!!", otherwise print the resulting value of x.
Input
The first line contains a single integer l (1 β€ l β€ 10^5) β the number of lines in the function.
Each of the next l lines contains a single command of one of three types:
* for n (1 β€ n β€ 100) β for loop;
* end β every command between "for n" and corresponding "end" is executed n times;
* add β adds 1 to x.
Output
If overflow happened during execution of f(0), then output "OVERFLOW!!!", otherwise print the resulting value of x.
Examples
Input
9
add
for 43
end
for 10
for 15
add
end
add
end
Output
161
Input
2
for 62
end
Output
0
Input
11
for 100
for 100
for 100
for 100
for 100
add
end
end
end
end
end
Output
OVERFLOW!!!
Note
In the first example the first "add" is executed 1 time, the second "add" is executed 150 times and the last "add" is executed 10 times. Note that "for n" can be immediately followed by "end" and that "add" can be outside of any for loops.
In the second example there are no commands "add", thus the returning value is 0.
In the third example "add" command is executed too many times, which causes x to go over 2^{32}-1.
Submitted Solution:
```
n = int(input())
mx = 2 ** 32
x, flag = 0, 0
buf = []
pr = [1]
for i in range(n) :
inp = input().split()
if flag == 1 :
continue
if inp[0] == "add" :
if x + pr[0] >= mx or len(pr) > 1:
print("OVERFLOW!!!")
flag = 1
x += pr[0]
elif inp[0] == "for" :
ch = int(inp[1])
if pr[-1] * ch >= mx :
pr.append(1)
pr[-1] *= ch
buf.append(ch)
else :
pr[-1] /= buf[-1]
if pr[-1] == 1 and len(pr) > 1 :
pr.pop()
buf.pop()
if flag == 0 :
print(int(x))
``` | instruction | 0 | 107,105 | 20 | 214,210 |
Yes | output | 1 | 107,105 | 20 | 214,211 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a function f written in some basic language. The function accepts an integer value, which is immediately written into some variable x. x is an integer variable and can be assigned values from 0 to 2^{32}-1. The function contains three types of commands:
* for n β for loop;
* end β every command between "for n" and corresponding "end" is executed n times;
* add β adds 1 to x.
After the execution of these commands, value of x is returned.
Every "for n" is matched with "end", thus the function is guaranteed to be valid. "for n" can be immediately followed by "end"."add" command can be outside of any for loops.
Notice that "add" commands might overflow the value of x! It means that the value of x becomes greater than 2^{32}-1 after some "add" command.
Now you run f(0) and wonder if the resulting value of x is correct or some overflow made it incorrect.
If overflow happened then output "OVERFLOW!!!", otherwise print the resulting value of x.
Input
The first line contains a single integer l (1 β€ l β€ 10^5) β the number of lines in the function.
Each of the next l lines contains a single command of one of three types:
* for n (1 β€ n β€ 100) β for loop;
* end β every command between "for n" and corresponding "end" is executed n times;
* add β adds 1 to x.
Output
If overflow happened during execution of f(0), then output "OVERFLOW!!!", otherwise print the resulting value of x.
Examples
Input
9
add
for 43
end
for 10
for 15
add
end
add
end
Output
161
Input
2
for 62
end
Output
0
Input
11
for 100
for 100
for 100
for 100
for 100
add
end
end
end
end
end
Output
OVERFLOW!!!
Note
In the first example the first "add" is executed 1 time, the second "add" is executed 150 times and the last "add" is executed 10 times. Note that "for n" can be immediately followed by "end" and that "add" can be outside of any for loops.
In the second example there are no commands "add", thus the returning value is 0.
In the third example "add" command is executed too many times, which causes x to go over 2^{32}-1.
Submitted Solution:
```
l = int(input())
ans = 0
nest = 0
F = []
m = 1
for _ in range(l):
com = input()
if com == "add":
ans += m
if ans >= 2**32:
ans = "OVERFLOW!!!"
break
elif com == "end":
m //= F.pop()
else:
if m > 2**40:
a = 1
else:
a = int(com.split()[1])
F.append(a)
m *= a
print(ans)
``` | instruction | 0 | 107,106 | 20 | 214,212 |
Yes | output | 1 | 107,106 | 20 | 214,213 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a function f written in some basic language. The function accepts an integer value, which is immediately written into some variable x. x is an integer variable and can be assigned values from 0 to 2^{32}-1. The function contains three types of commands:
* for n β for loop;
* end β every command between "for n" and corresponding "end" is executed n times;
* add β adds 1 to x.
After the execution of these commands, value of x is returned.
Every "for n" is matched with "end", thus the function is guaranteed to be valid. "for n" can be immediately followed by "end"."add" command can be outside of any for loops.
Notice that "add" commands might overflow the value of x! It means that the value of x becomes greater than 2^{32}-1 after some "add" command.
Now you run f(0) and wonder if the resulting value of x is correct or some overflow made it incorrect.
If overflow happened then output "OVERFLOW!!!", otherwise print the resulting value of x.
Input
The first line contains a single integer l (1 β€ l β€ 10^5) β the number of lines in the function.
Each of the next l lines contains a single command of one of three types:
* for n (1 β€ n β€ 100) β for loop;
* end β every command between "for n" and corresponding "end" is executed n times;
* add β adds 1 to x.
Output
If overflow happened during execution of f(0), then output "OVERFLOW!!!", otherwise print the resulting value of x.
Examples
Input
9
add
for 43
end
for 10
for 15
add
end
add
end
Output
161
Input
2
for 62
end
Output
0
Input
11
for 100
for 100
for 100
for 100
for 100
add
end
end
end
end
end
Output
OVERFLOW!!!
Note
In the first example the first "add" is executed 1 time, the second "add" is executed 150 times and the last "add" is executed 10 times. Note that "for n" can be immediately followed by "end" and that "add" can be outside of any for loops.
In the second example there are no commands "add", thus the returning value is 0.
In the third example "add" command is executed too many times, which causes x to go over 2^{32}-1.
Submitted Solution:
```
def find_result(commands_array):
total_result = 0
sub_results_stack = [0]
commands_stack = []
remaining_space = 2 ** 32 - 1
for command in commands_array:
if command == "add":
sub_results_stack[-1] += 1
if sub_results_stack[-1] >= remaining_space:
return "OVERFLOW!!!"
elif "for" in command:
commands_stack.append(int(command.split(" ")[1]))
sub_results_stack.append(0)
elif command == "end":
sub_results_stack[-1] *= commands_stack.pop()
if len(commands_stack) > 0:
temp_sub_result = sub_results_stack.pop()
sub_results_stack[-1] += temp_sub_result
if sub_results_stack[-1] >= remaining_space:
return "OVERFLOW!!!"
if len(commands_stack) == 0:
remaining_space -= sub_results_stack[-1]
total_result += sub_results_stack.pop()
if len(sub_results_stack) == 0:
sub_results_stack.append(0)
return total_result
number_of_commands = int(input())
input_commands_array = []
for command in range(number_of_commands):
input_commands_array.append(input())
print(find_result(input_commands_array))
``` | instruction | 0 | 107,107 | 20 | 214,214 |
No | output | 1 | 107,107 | 20 | 214,215 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a function f written in some basic language. The function accepts an integer value, which is immediately written into some variable x. x is an integer variable and can be assigned values from 0 to 2^{32}-1. The function contains three types of commands:
* for n β for loop;
* end β every command between "for n" and corresponding "end" is executed n times;
* add β adds 1 to x.
After the execution of these commands, value of x is returned.
Every "for n" is matched with "end", thus the function is guaranteed to be valid. "for n" can be immediately followed by "end"."add" command can be outside of any for loops.
Notice that "add" commands might overflow the value of x! It means that the value of x becomes greater than 2^{32}-1 after some "add" command.
Now you run f(0) and wonder if the resulting value of x is correct or some overflow made it incorrect.
If overflow happened then output "OVERFLOW!!!", otherwise print the resulting value of x.
Input
The first line contains a single integer l (1 β€ l β€ 10^5) β the number of lines in the function.
Each of the next l lines contains a single command of one of three types:
* for n (1 β€ n β€ 100) β for loop;
* end β every command between "for n" and corresponding "end" is executed n times;
* add β adds 1 to x.
Output
If overflow happened during execution of f(0), then output "OVERFLOW!!!", otherwise print the resulting value of x.
Examples
Input
9
add
for 43
end
for 10
for 15
add
end
add
end
Output
161
Input
2
for 62
end
Output
0
Input
11
for 100
for 100
for 100
for 100
for 100
add
end
end
end
end
end
Output
OVERFLOW!!!
Note
In the first example the first "add" is executed 1 time, the second "add" is executed 150 times and the last "add" is executed 10 times. Note that "for n" can be immediately followed by "end" and that "add" can be outside of any for loops.
In the second example there are no commands "add", thus the returning value is 0.
In the third example "add" command is executed too many times, which causes x to go over 2^{32}-1.
Submitted Solution:
```
# -*- coding: utf-8 -*-
# @Author: apikdech
# @Date: 07:09:18 06-06-2019
# @Last Modified by: apikdech
# @Last Modified time: 07:28:40 06-06-2019
INF = 2**32
x = 0
ok = 1
tmp = 0
st = []
for _ in range(int(input())):
s = input()
if (s[0] == 'f'):
s = s.split()
st.append(int(s[1]))
if (s[0] == 'a'):
if (len(st) == 0):
x += 1
else:
tmp += 1
if (s[0] == 'e'):
tmp *= st.pop()
if (len(st) == 0):
x += tmp
if (x >= INF):
ok = 0
if (ok == 0):
print("OVERFLOW!!!")
else:
print(x)
``` | instruction | 0 | 107,108 | 20 | 214,216 |
No | output | 1 | 107,108 | 20 | 214,217 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a function f written in some basic language. The function accepts an integer value, which is immediately written into some variable x. x is an integer variable and can be assigned values from 0 to 2^{32}-1. The function contains three types of commands:
* for n β for loop;
* end β every command between "for n" and corresponding "end" is executed n times;
* add β adds 1 to x.
After the execution of these commands, value of x is returned.
Every "for n" is matched with "end", thus the function is guaranteed to be valid. "for n" can be immediately followed by "end"."add" command can be outside of any for loops.
Notice that "add" commands might overflow the value of x! It means that the value of x becomes greater than 2^{32}-1 after some "add" command.
Now you run f(0) and wonder if the resulting value of x is correct or some overflow made it incorrect.
If overflow happened then output "OVERFLOW!!!", otherwise print the resulting value of x.
Input
The first line contains a single integer l (1 β€ l β€ 10^5) β the number of lines in the function.
Each of the next l lines contains a single command of one of three types:
* for n (1 β€ n β€ 100) β for loop;
* end β every command between "for n" and corresponding "end" is executed n times;
* add β adds 1 to x.
Output
If overflow happened during execution of f(0), then output "OVERFLOW!!!", otherwise print the resulting value of x.
Examples
Input
9
add
for 43
end
for 10
for 15
add
end
add
end
Output
161
Input
2
for 62
end
Output
0
Input
11
for 100
for 100
for 100
for 100
for 100
add
end
end
end
end
end
Output
OVERFLOW!!!
Note
In the first example the first "add" is executed 1 time, the second "add" is executed 150 times and the last "add" is executed 10 times. Note that "for n" can be immediately followed by "end" and that "add" can be outside of any for loops.
In the second example there are no commands "add", thus the returning value is 0.
In the third example "add" command is executed too many times, which causes x to go over 2^{32}-1.
Submitted Solution:
```
def for_(in_, n):
return in_*n
def add_(in_):
return in_+1
n = int(input())
limit = 2 ** 32 -1
out = 0
eq = "0"
depth = 0
for i in range(n):
elms = input().split(" ")
if elms[0] == "for":
n = int(elms[1])
eq += "+ %d * ( 0" % n
depth += 1
elif elms[0] == "add":
eq += "+1"
#print("add", out)
else: # end
assert elms[0] == "end", elms[0]
eq += ") "
depth -= 1
if depth == 0:
#print(i, "depth", depth, "eval", eq)
try:
out += eval(eq)
eq = "0"
except:
if "+1" not in eq:
out = out
eq = "0"
else:
out = "OVERFLOW!!!"
break
if limit < out:
out = "OVERFLOW!!!"
break
print(out)
``` | instruction | 0 | 107,109 | 20 | 214,218 |
No | output | 1 | 107,109 | 20 | 214,219 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a function f written in some basic language. The function accepts an integer value, which is immediately written into some variable x. x is an integer variable and can be assigned values from 0 to 2^{32}-1. The function contains three types of commands:
* for n β for loop;
* end β every command between "for n" and corresponding "end" is executed n times;
* add β adds 1 to x.
After the execution of these commands, value of x is returned.
Every "for n" is matched with "end", thus the function is guaranteed to be valid. "for n" can be immediately followed by "end"."add" command can be outside of any for loops.
Notice that "add" commands might overflow the value of x! It means that the value of x becomes greater than 2^{32}-1 after some "add" command.
Now you run f(0) and wonder if the resulting value of x is correct or some overflow made it incorrect.
If overflow happened then output "OVERFLOW!!!", otherwise print the resulting value of x.
Input
The first line contains a single integer l (1 β€ l β€ 10^5) β the number of lines in the function.
Each of the next l lines contains a single command of one of three types:
* for n (1 β€ n β€ 100) β for loop;
* end β every command between "for n" and corresponding "end" is executed n times;
* add β adds 1 to x.
Output
If overflow happened during execution of f(0), then output "OVERFLOW!!!", otherwise print the resulting value of x.
Examples
Input
9
add
for 43
end
for 10
for 15
add
end
add
end
Output
161
Input
2
for 62
end
Output
0
Input
11
for 100
for 100
for 100
for 100
for 100
add
end
end
end
end
end
Output
OVERFLOW!!!
Note
In the first example the first "add" is executed 1 time, the second "add" is executed 150 times and the last "add" is executed 10 times. Note that "for n" can be immediately followed by "end" and that "add" can be outside of any for loops.
In the second example there are no commands "add", thus the returning value is 0.
In the third example "add" command is executed too many times, which causes x to go over 2^{32}-1.
Submitted Solution:
```
import sys
t = int(sys.stdin.readline())
n = 0
f = {}
f[0] = 1
m = 2**32 - 1
key = 0
if t < 100000:
for i in range(t):
s = list(sys.stdin.readline().split())
if s[0] == 'add':
n += f[key]
if n > m:
n = 'OVERFLOW!!!'
break
elif s[0] == 'for':
num = int(s[1])
key += 1
f[key] = f[key-1] * num
else:
del f[key]
key -= 1
else:
p = 1
for i in range(t):
s = list(sys.stdin.readline().split())
if s[0] == 'add':
n += 1
## n += f[key]
if n > m:
n = 'OVERFLOW!!!'
break
elif s[0] == 'for':
num = int(s[1])
## p *= num
key += 1
f[key] = num
else:
## p = p // f[key]
del f[key]
key -= 1
print(n)
``` | instruction | 0 | 107,110 | 20 | 214,220 |
No | output | 1 | 107,110 | 20 | 214,221 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a list of numbers from 1 to n written from left to right on the blackboard.
You perform an algorithm consisting of several steps (steps are 1-indexed). On the i-th step you wipe the i-th number (considering only remaining numbers). You wipe the whole number (not one digit).
<image>
When there are less than i numbers remaining, you stop your algorithm.
Now you wonder: what is the value of the x-th remaining number after the algorithm is stopped?
Input
The first line contains one integer T (1 β€ T β€ 100) β the number of queries. The next T lines contain queries β one per line. All queries are independent.
Each line contains two space-separated integers n and x (1 β€ x < n β€ 10^{9}) β the length of the list and the position we wonder about. It's guaranteed that after the algorithm ends, the list will still contain at least x numbers.
Output
Print T integers (one per query) β the values of the x-th number after performing the algorithm for the corresponding queries.
Example
Input
3
3 1
4 2
69 6
Output
2
4
12 | instruction | 0 | 107,111 | 20 | 214,222 |
Tags: math
Correct Solution:
```
a=int(input())
for number in range(0,a):
n,x= map(int,input().split())
print(x*2)
``` | output | 1 | 107,111 | 20 | 214,223 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a list of numbers from 1 to n written from left to right on the blackboard.
You perform an algorithm consisting of several steps (steps are 1-indexed). On the i-th step you wipe the i-th number (considering only remaining numbers). You wipe the whole number (not one digit).
<image>
When there are less than i numbers remaining, you stop your algorithm.
Now you wonder: what is the value of the x-th remaining number after the algorithm is stopped?
Input
The first line contains one integer T (1 β€ T β€ 100) β the number of queries. The next T lines contain queries β one per line. All queries are independent.
Each line contains two space-separated integers n and x (1 β€ x < n β€ 10^{9}) β the length of the list and the position we wonder about. It's guaranteed that after the algorithm ends, the list will still contain at least x numbers.
Output
Print T integers (one per query) β the values of the x-th number after performing the algorithm for the corresponding queries.
Example
Input
3
3 1
4 2
69 6
Output
2
4
12 | instruction | 0 | 107,112 | 20 | 214,224 |
Tags: math
Correct Solution:
```
q=int(input())
for i in range(q):
w,e=map(int,input().split())
print(e*2)
``` | output | 1 | 107,112 | 20 | 214,225 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a list of numbers from 1 to n written from left to right on the blackboard.
You perform an algorithm consisting of several steps (steps are 1-indexed). On the i-th step you wipe the i-th number (considering only remaining numbers). You wipe the whole number (not one digit).
<image>
When there are less than i numbers remaining, you stop your algorithm.
Now you wonder: what is the value of the x-th remaining number after the algorithm is stopped?
Input
The first line contains one integer T (1 β€ T β€ 100) β the number of queries. The next T lines contain queries β one per line. All queries are independent.
Each line contains two space-separated integers n and x (1 β€ x < n β€ 10^{9}) β the length of the list and the position we wonder about. It's guaranteed that after the algorithm ends, the list will still contain at least x numbers.
Output
Print T integers (one per query) β the values of the x-th number after performing the algorithm for the corresponding queries.
Example
Input
3
3 1
4 2
69 6
Output
2
4
12 | instruction | 0 | 107,113 | 20 | 214,226 |
Tags: math
Correct Solution:
```
for i in range(int(input())):
x = list(map(int, input().split(" ")))
print(x[1]*2)
#Ψ§Ϊ©Ψ³ΩΎΨͺ Ψ΄Ω
#Ψ¨Ω ΩΩΩ /Ω
/Ψ§ΫΩ Ω
Ψ§Ϋ Ψ³ΩΫΫΨͺ ΩΩΩ
``` | output | 1 | 107,113 | 20 | 214,227 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a list of numbers from 1 to n written from left to right on the blackboard.
You perform an algorithm consisting of several steps (steps are 1-indexed). On the i-th step you wipe the i-th number (considering only remaining numbers). You wipe the whole number (not one digit).
<image>
When there are less than i numbers remaining, you stop your algorithm.
Now you wonder: what is the value of the x-th remaining number after the algorithm is stopped?
Input
The first line contains one integer T (1 β€ T β€ 100) β the number of queries. The next T lines contain queries β one per line. All queries are independent.
Each line contains two space-separated integers n and x (1 β€ x < n β€ 10^{9}) β the length of the list and the position we wonder about. It's guaranteed that after the algorithm ends, the list will still contain at least x numbers.
Output
Print T integers (one per query) β the values of the x-th number after performing the algorithm for the corresponding queries.
Example
Input
3
3 1
4 2
69 6
Output
2
4
12 | instruction | 0 | 107,114 | 20 | 214,228 |
Tags: math
Correct Solution:
```
"""609C"""
# import math
# import sys
def main():
n, d = map(int, input().split())
print(2*d)
return
# main()
def test():
t= int(input())
while t:
main()
t-=1
test()
``` | output | 1 | 107,114 | 20 | 214,229 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a list of numbers from 1 to n written from left to right on the blackboard.
You perform an algorithm consisting of several steps (steps are 1-indexed). On the i-th step you wipe the i-th number (considering only remaining numbers). You wipe the whole number (not one digit).
<image>
When there are less than i numbers remaining, you stop your algorithm.
Now you wonder: what is the value of the x-th remaining number after the algorithm is stopped?
Input
The first line contains one integer T (1 β€ T β€ 100) β the number of queries. The next T lines contain queries β one per line. All queries are independent.
Each line contains two space-separated integers n and x (1 β€ x < n β€ 10^{9}) β the length of the list and the position we wonder about. It's guaranteed that after the algorithm ends, the list will still contain at least x numbers.
Output
Print T integers (one per query) β the values of the x-th number after performing the algorithm for the corresponding queries.
Example
Input
3
3 1
4 2
69 6
Output
2
4
12 | instruction | 0 | 107,115 | 20 | 214,230 |
Tags: math
Correct Solution:
```
n = int(input())
for i in range(0, n):
n , x = map(int,input().split())
if x * 2 < n:
print(x*2)
else:
print(n)
``` | output | 1 | 107,115 | 20 | 214,231 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a list of numbers from 1 to n written from left to right on the blackboard.
You perform an algorithm consisting of several steps (steps are 1-indexed). On the i-th step you wipe the i-th number (considering only remaining numbers). You wipe the whole number (not one digit).
<image>
When there are less than i numbers remaining, you stop your algorithm.
Now you wonder: what is the value of the x-th remaining number after the algorithm is stopped?
Input
The first line contains one integer T (1 β€ T β€ 100) β the number of queries. The next T lines contain queries β one per line. All queries are independent.
Each line contains two space-separated integers n and x (1 β€ x < n β€ 10^{9}) β the length of the list and the position we wonder about. It's guaranteed that after the algorithm ends, the list will still contain at least x numbers.
Output
Print T integers (one per query) β the values of the x-th number after performing the algorithm for the corresponding queries.
Example
Input
3
3 1
4 2
69 6
Output
2
4
12 | instruction | 0 | 107,116 | 20 | 214,232 |
Tags: math
Correct Solution:
```
tc = int(input())
while (tc > 0):
tc -= 1
a, b = [int(x) for x in input().split()]
print(b * 2)
``` | output | 1 | 107,116 | 20 | 214,233 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a list of numbers from 1 to n written from left to right on the blackboard.
You perform an algorithm consisting of several steps (steps are 1-indexed). On the i-th step you wipe the i-th number (considering only remaining numbers). You wipe the whole number (not one digit).
<image>
When there are less than i numbers remaining, you stop your algorithm.
Now you wonder: what is the value of the x-th remaining number after the algorithm is stopped?
Input
The first line contains one integer T (1 β€ T β€ 100) β the number of queries. The next T lines contain queries β one per line. All queries are independent.
Each line contains two space-separated integers n and x (1 β€ x < n β€ 10^{9}) β the length of the list and the position we wonder about. It's guaranteed that after the algorithm ends, the list will still contain at least x numbers.
Output
Print T integers (one per query) β the values of the x-th number after performing the algorithm for the corresponding queries.
Example
Input
3
3 1
4 2
69 6
Output
2
4
12 | instruction | 0 | 107,117 | 20 | 214,234 |
Tags: math
Correct Solution:
```
#!/usr/bin/env python
# coding: utf-8
# In[9]:
req_num = input()
req_list = []
for i in range(int(req_num)):
req_list.append([int(j) for j in input().split()])
# In[12]:
for i in req_list:
print(i[1]*2)
``` | output | 1 | 107,117 | 20 | 214,235 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a list of numbers from 1 to n written from left to right on the blackboard.
You perform an algorithm consisting of several steps (steps are 1-indexed). On the i-th step you wipe the i-th number (considering only remaining numbers). You wipe the whole number (not one digit).
<image>
When there are less than i numbers remaining, you stop your algorithm.
Now you wonder: what is the value of the x-th remaining number after the algorithm is stopped?
Input
The first line contains one integer T (1 β€ T β€ 100) β the number of queries. The next T lines contain queries β one per line. All queries are independent.
Each line contains two space-separated integers n and x (1 β€ x < n β€ 10^{9}) β the length of the list and the position we wonder about. It's guaranteed that after the algorithm ends, the list will still contain at least x numbers.
Output
Print T integers (one per query) β the values of the x-th number after performing the algorithm for the corresponding queries.
Example
Input
3
3 1
4 2
69 6
Output
2
4
12 | instruction | 0 | 107,118 | 20 | 214,236 |
Tags: math
Correct Solution:
```
TestCase = int(input())
while( TestCase > 0 ):
[n,x] = list( map( int,input().split() ) )
print(2*x)
TestCase -= 1
``` | output | 1 | 107,118 | 20 | 214,237 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You know that the Martians use a number system with base k. Digit b (0 β€ b < k) is considered lucky, as the first contact between the Martians and the Earthlings occurred in year b (by Martian chronology).
A digital root d(x) of number x is a number that consists of a single digit, resulting after cascading summing of all digits of number x. Word "cascading" means that if the first summing gives us a number that consists of several digits, then we sum up all digits again, and again, until we get a one digit number.
For example, d(35047) = d((3 + 5 + 0 + 4)7) = d(157) = d((1 + 5)7) = d(67) = 67. In this sample the calculations are performed in the 7-base notation.
If a number's digital root equals b, the Martians also call this number lucky.
You have string s, which consists of n digits in the k-base notation system. Your task is to find, how many distinct substrings of the given string are lucky numbers. Leading zeroes are permitted in the numbers.
Note that substring s[i... j] of the string s = a1a2... an (1 β€ i β€ j β€ n) is the string aiai + 1... aj. Two substrings s[i1... j1] and s[i2... j2] of the string s are different if either i1 β i2 or j1 β j2.
Input
The first line contains three integers k, b and n (2 β€ k β€ 109, 0 β€ b < k, 1 β€ n β€ 105).
The second line contains string s as a sequence of n integers, representing digits in the k-base notation: the i-th integer equals ai (0 β€ ai < k) β the i-th digit of string s. The numbers in the lines are space-separated.
Output
Print a single integer β the number of substrings that are lucky numbers.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
10 5 6
3 2 0 5 6 1
Output
5
Input
7 6 4
3 5 0 4
Output
1
Input
257 0 3
0 0 256
Output
3
Note
In the first sample the following substrings have the sought digital root: s[1... 2] = "3 2", s[1... 3] = "3 2 0", s[3... 4] = "0 5", s[4... 4] = "5" and s[2... 6] = "2 0 5 6 1". | instruction | 0 | 107,269 | 20 | 214,538 |
Tags: math, number theory
Correct Solution:
```
Line1 = list(map(int,input().split()))
List = list(map(int,input().split()))
def MartianLuck(k,b,n,digit_list):
if b == 0:
return Zero(n,digit_list)
Subarray = dict()
Subarray[0]=1
LuckyNumbersCounter = 0
ActualNumber = 0
for Digit in digit_list :
ActualNumber = (ActualNumber + Digit) % (k-1)
Diference = (ActualNumber - b) % (k-1)
LuckyNumbersCounter += Subarray.get(Diference,0)
Subarray[ActualNumber] = Subarray.get(ActualNumber,0) + 1
if b == k-1:
return LuckyNumbersCounter - Zero(n,digit_list)
return LuckyNumbersCounter
def Zero(n,digit_list):
Digit_index = 0
LuckyZeroNumbersCounter =0
while Digit_index < n:
count = 0
while Digit_index + count <n and digit_list[Digit_index + count] == 0:
count += 1
LuckyZeroNumbersCounter += count*(count +1) //2
Digit_index += count + 1
return LuckyZeroNumbersCounter
print(MartianLuck(Line1[0],Line1[1],Line1[2],List))
``` | output | 1 | 107,269 | 20 | 214,539 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You know that the Martians use a number system with base k. Digit b (0 β€ b < k) is considered lucky, as the first contact between the Martians and the Earthlings occurred in year b (by Martian chronology).
A digital root d(x) of number x is a number that consists of a single digit, resulting after cascading summing of all digits of number x. Word "cascading" means that if the first summing gives us a number that consists of several digits, then we sum up all digits again, and again, until we get a one digit number.
For example, d(35047) = d((3 + 5 + 0 + 4)7) = d(157) = d((1 + 5)7) = d(67) = 67. In this sample the calculations are performed in the 7-base notation.
If a number's digital root equals b, the Martians also call this number lucky.
You have string s, which consists of n digits in the k-base notation system. Your task is to find, how many distinct substrings of the given string are lucky numbers. Leading zeroes are permitted in the numbers.
Note that substring s[i... j] of the string s = a1a2... an (1 β€ i β€ j β€ n) is the string aiai + 1... aj. Two substrings s[i1... j1] and s[i2... j2] of the string s are different if either i1 β i2 or j1 β j2.
Input
The first line contains three integers k, b and n (2 β€ k β€ 109, 0 β€ b < k, 1 β€ n β€ 105).
The second line contains string s as a sequence of n integers, representing digits in the k-base notation: the i-th integer equals ai (0 β€ ai < k) β the i-th digit of string s. The numbers in the lines are space-separated.
Output
Print a single integer β the number of substrings that are lucky numbers.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
10 5 6
3 2 0 5 6 1
Output
5
Input
7 6 4
3 5 0 4
Output
1
Input
257 0 3
0 0 256
Output
3
Note
In the first sample the following substrings have the sought digital root: s[1... 2] = "3 2", s[1... 3] = "3 2 0", s[3... 4] = "0 5", s[4... 4] = "5" and s[2... 6] = "2 0 5 6 1". | instruction | 0 | 107,270 | 20 | 214,540 |
Tags: math, number theory
Correct Solution:
```
k, b, n = map(int, input().split())
digits = list(map(int, input().split()))
def ans0():
j = -1
answer = 0
for i in range(n):
if digits[i] != 0 or i < j:
continue
j = i
while j < n and digits[j] == 0:
j += 1
r = j - i
answer += r * (r + 1) // 2
return answer
if b == 0:
print(ans0())
else:
count = dict()
count[0] = 1
pref_sum = 0
answer = 0
if b == k - 1:
b = 0
answer -= ans0()
for d in digits:
pref_sum = (pref_sum + d) % (k - 1)
need = (pref_sum - b) % (k - 1)
answer += count.get(need, 0)
count[pref_sum] = count.get(pref_sum, 0) + 1
print(answer)
``` | output | 1 | 107,270 | 20 | 214,541 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You know that the Martians use a number system with base k. Digit b (0 β€ b < k) is considered lucky, as the first contact between the Martians and the Earthlings occurred in year b (by Martian chronology).
A digital root d(x) of number x is a number that consists of a single digit, resulting after cascading summing of all digits of number x. Word "cascading" means that if the first summing gives us a number that consists of several digits, then we sum up all digits again, and again, until we get a one digit number.
For example, d(35047) = d((3 + 5 + 0 + 4)7) = d(157) = d((1 + 5)7) = d(67) = 67. In this sample the calculations are performed in the 7-base notation.
If a number's digital root equals b, the Martians also call this number lucky.
You have string s, which consists of n digits in the k-base notation system. Your task is to find, how many distinct substrings of the given string are lucky numbers. Leading zeroes are permitted in the numbers.
Note that substring s[i... j] of the string s = a1a2... an (1 β€ i β€ j β€ n) is the string aiai + 1... aj. Two substrings s[i1... j1] and s[i2... j2] of the string s are different if either i1 β i2 or j1 β j2.
Input
The first line contains three integers k, b and n (2 β€ k β€ 109, 0 β€ b < k, 1 β€ n β€ 105).
The second line contains string s as a sequence of n integers, representing digits in the k-base notation: the i-th integer equals ai (0 β€ ai < k) β the i-th digit of string s. The numbers in the lines are space-separated.
Output
Print a single integer β the number of substrings that are lucky numbers.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
10 5 6
3 2 0 5 6 1
Output
5
Input
7 6 4
3 5 0 4
Output
1
Input
257 0 3
0 0 256
Output
3
Note
In the first sample the following substrings have the sought digital root: s[1... 2] = "3 2", s[1... 3] = "3 2 0", s[3... 4] = "0 5", s[4... 4] = "5" and s[2... 6] = "2 0 5 6 1".
Submitted Solution:
```
Line1 = list(map(int,input().split()))
List = list(map(int,input().split()))
def MartianLuck2(k,b,n,digit_list):
reminder = b % (k-1)
LuckyNumbersCounter = 0
ActualNumber = 0
Count = 0
while Count < n :
for digit_index in range(Count,n):
ActualNumber = (ActualNumber + digit_list[digit_index]) % (k-1)
if b == 0:
if ActualNumber == 0:
LuckyNumbersCounter += 1
elif (ActualNumber == reminder and not ((digit_index - Count) == 0 and ActualNumber == 0)):
LuckyNumbersCounter +=1
ActualNumber = 0
Count +=1
return LuckyNumbersCounter
print(MartianLuck2(Line1[0],Line1[1],Line1[2],List))
``` | instruction | 0 | 107,271 | 20 | 214,542 |
No | output | 1 | 107,271 | 20 | 214,543 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You know that the Martians use a number system with base k. Digit b (0 β€ b < k) is considered lucky, as the first contact between the Martians and the Earthlings occurred in year b (by Martian chronology).
A digital root d(x) of number x is a number that consists of a single digit, resulting after cascading summing of all digits of number x. Word "cascading" means that if the first summing gives us a number that consists of several digits, then we sum up all digits again, and again, until we get a one digit number.
For example, d(35047) = d((3 + 5 + 0 + 4)7) = d(157) = d((1 + 5)7) = d(67) = 67. In this sample the calculations are performed in the 7-base notation.
If a number's digital root equals b, the Martians also call this number lucky.
You have string s, which consists of n digits in the k-base notation system. Your task is to find, how many distinct substrings of the given string are lucky numbers. Leading zeroes are permitted in the numbers.
Note that substring s[i... j] of the string s = a1a2... an (1 β€ i β€ j β€ n) is the string aiai + 1... aj. Two substrings s[i1... j1] and s[i2... j2] of the string s are different if either i1 β i2 or j1 β j2.
Input
The first line contains three integers k, b and n (2 β€ k β€ 109, 0 β€ b < k, 1 β€ n β€ 105).
The second line contains string s as a sequence of n integers, representing digits in the k-base notation: the i-th integer equals ai (0 β€ ai < k) β the i-th digit of string s. The numbers in the lines are space-separated.
Output
Print a single integer β the number of substrings that are lucky numbers.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
10 5 6
3 2 0 5 6 1
Output
5
Input
7 6 4
3 5 0 4
Output
1
Input
257 0 3
0 0 256
Output
3
Note
In the first sample the following substrings have the sought digital root: s[1... 2] = "3 2", s[1... 3] = "3 2 0", s[3... 4] = "0 5", s[4... 4] = "5" and s[2... 6] = "2 0 5 6 1".
Submitted Solution:
```
k, b, n = map(int, input().split())
digits = list(map(int, input().split()))
def conv(t):
if t == 0:
return k - 1
return t
if b == 0:
j = -1
answer = 0
for i in range(n):
if digits[i] != 0 or i < j:
continue
j = i
while j < n and digits[j] == 0:
j += 1
r = j - i
answer += r * (r + 1) // 2
print(answer)
else:
count = dict()
count[0] = 1
pref_sum = 0
answer = 0
while len(digits) > 0 and digits[0] == 0:
digits.pop(0)
zeroes = 0
for d in digits:
pref_sum = (pref_sum + d) % (k - 1)
real_val = conv(pref_sum)
need = (real_val - b) % (k - 1)
# print(pref_sum, need)
answer += count.get(need, 0)
if need == 0:
answer -= zeroes
if d == 0:
zeroes += 1
count[pref_sum] = count.get(pref_sum, 0) + 1
print(answer)
``` | instruction | 0 | 107,272 | 20 | 214,544 |
No | output | 1 | 107,272 | 20 | 214,545 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You know that the Martians use a number system with base k. Digit b (0 β€ b < k) is considered lucky, as the first contact between the Martians and the Earthlings occurred in year b (by Martian chronology).
A digital root d(x) of number x is a number that consists of a single digit, resulting after cascading summing of all digits of number x. Word "cascading" means that if the first summing gives us a number that consists of several digits, then we sum up all digits again, and again, until we get a one digit number.
For example, d(35047) = d((3 + 5 + 0 + 4)7) = d(157) = d((1 + 5)7) = d(67) = 67. In this sample the calculations are performed in the 7-base notation.
If a number's digital root equals b, the Martians also call this number lucky.
You have string s, which consists of n digits in the k-base notation system. Your task is to find, how many distinct substrings of the given string are lucky numbers. Leading zeroes are permitted in the numbers.
Note that substring s[i... j] of the string s = a1a2... an (1 β€ i β€ j β€ n) is the string aiai + 1... aj. Two substrings s[i1... j1] and s[i2... j2] of the string s are different if either i1 β i2 or j1 β j2.
Input
The first line contains three integers k, b and n (2 β€ k β€ 109, 0 β€ b < k, 1 β€ n β€ 105).
The second line contains string s as a sequence of n integers, representing digits in the k-base notation: the i-th integer equals ai (0 β€ ai < k) β the i-th digit of string s. The numbers in the lines are space-separated.
Output
Print a single integer β the number of substrings that are lucky numbers.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
10 5 6
3 2 0 5 6 1
Output
5
Input
7 6 4
3 5 0 4
Output
1
Input
257 0 3
0 0 256
Output
3
Note
In the first sample the following substrings have the sought digital root: s[1... 2] = "3 2", s[1... 3] = "3 2 0", s[3... 4] = "0 5", s[4... 4] = "5" and s[2... 6] = "2 0 5 6 1".
Submitted Solution:
```
Line1 = list(map(int,input().split()))
List = list(input().split())
def MartianLuck(k,b,n,digit_list):
LuckyNumbersCounter = 0
ActualNumber = ""
Count = 0
while Count < n :
for digit_index in range(Count,n):
ActualNumber += digit_list[digit_index]
if int(ActualNumber) % (k-1) == b :
LuckyNumbersCounter +=1
ActualNumber = ""
Count +=1
return LuckyNumbersCounter
print(MartianLuck(Line1[0],Line1[1],Line1[2],List))
``` | instruction | 0 | 107,273 | 20 | 214,546 |
No | output | 1 | 107,273 | 20 | 214,547 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You know that the Martians use a number system with base k. Digit b (0 β€ b < k) is considered lucky, as the first contact between the Martians and the Earthlings occurred in year b (by Martian chronology).
A digital root d(x) of number x is a number that consists of a single digit, resulting after cascading summing of all digits of number x. Word "cascading" means that if the first summing gives us a number that consists of several digits, then we sum up all digits again, and again, until we get a one digit number.
For example, d(35047) = d((3 + 5 + 0 + 4)7) = d(157) = d((1 + 5)7) = d(67) = 67. In this sample the calculations are performed in the 7-base notation.
If a number's digital root equals b, the Martians also call this number lucky.
You have string s, which consists of n digits in the k-base notation system. Your task is to find, how many distinct substrings of the given string are lucky numbers. Leading zeroes are permitted in the numbers.
Note that substring s[i... j] of the string s = a1a2... an (1 β€ i β€ j β€ n) is the string aiai + 1... aj. Two substrings s[i1... j1] and s[i2... j2] of the string s are different if either i1 β i2 or j1 β j2.
Input
The first line contains three integers k, b and n (2 β€ k β€ 109, 0 β€ b < k, 1 β€ n β€ 105).
The second line contains string s as a sequence of n integers, representing digits in the k-base notation: the i-th integer equals ai (0 β€ ai < k) β the i-th digit of string s. The numbers in the lines are space-separated.
Output
Print a single integer β the number of substrings that are lucky numbers.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
10 5 6
3 2 0 5 6 1
Output
5
Input
7 6 4
3 5 0 4
Output
1
Input
257 0 3
0 0 256
Output
3
Note
In the first sample the following substrings have the sought digital root: s[1... 2] = "3 2", s[1... 3] = "3 2 0", s[3... 4] = "0 5", s[4... 4] = "5" and s[2... 6] = "2 0 5 6 1".
Submitted Solution:
```
Line1 = list(map(int,input().split()))
List = list(map(int,input().split()))
def MartianLuck2(k,b,n,digit_list):
Subarray = dict()
Subarray[0]=1
reminder = b % (k-1)
LuckyNumbersCounter = 0
ActualNumber = 0
Digit_index = 0
while Digit_index < n :
if b == 0:
count = 0
while digit_list[Digit_index + count] == 0:
count += 1
LuckyNumbersCounter += count*(count +1) //2
Digit_index += count
else:
ActualNumber = (ActualNumber + digit_list[Digit_index]) % (k-1)
Diference = (ActualNumber - b) % (k-1)
if b == k-1 and digit_list[Digit_index]==0 and Diference == 0 and LuckyNumbersCounter > 0:
LuckyNumbersCounter+=1
elif not (b==k-1 and digit_list[Digit_index]==0):
LuckyNumbersCounter += Subarray.get(Diference,0)
Subarray[ActualNumber] = Subarray.get(ActualNumber,0) + 1
Digit_index +=1
return LuckyNumbersCounter
print(MartianLuck2(Line1[0],Line1[1],Line1[2],List))
``` | instruction | 0 | 107,274 | 20 | 214,548 |
No | output | 1 | 107,274 | 20 | 214,549 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The "Bulls and Cows" game needs two people to play. The thinker thinks of a number and the guesser tries to guess it.
The thinker thinks of a four-digit number in the decimal system. All the digits in the number are different and the number may have a leading zero. It can't have more than one leading zero, because all it's digits should be different. The guesser tries to guess the number. He makes a series of guesses, trying experimental numbers and receives answers from the first person in the format "x bulls y cows". x represents the number of digits in the experimental number that occupy the same positions as in the sought number. y represents the number of digits of the experimental number that present in the sought number, but occupy different positions. Naturally, the experimental numbers, as well as the sought number, are represented by four-digit numbers where all digits are different and a leading zero can be present.
For example, let's suppose that the thinker thought of the number 0123. Then the guessers' experimental number 1263 will receive a reply "1 bull 2 cows" (3 occupies the same positions in both numbers and 1 and 2 are present in both numbers but they occupy different positions). Also, the answer to number 8103 will be "2 bulls 1 cow" (analogically, 1 and 3 occupy the same positions and 0 occupies a different one).
When the guesser is answered "4 bulls 0 cows", the game is over.
Now the guesser has already made several guesses and wants to know whether his next guess can possibly be the last one.
Input
The first input line contains an integer n (1 β€ n β€ 10) which represents the number of already made guesses. Then follow n lines in the form of "ai bi ci", where ai is the i-th experimental number, bi is the number of bulls, ci is the number of cows (1 β€ i β€ n, 0 β€ bi, ci, bi + ci β€ 4). The experimental numbers are correct, i.e., each of them contains exactly four digits, in each of them all the four digits are different, and there can be a leading zero. All the experimental numbers are different. As the guesser hasn't guessed the number yet, the answer "4 bulls 0 cows" is not present.
Output
If the input data is enough to determine the sought number, print the number with four digits on a single line. If it has less than four digits, add leading zero. If the data is not enough, print "Need more data" without the quotes. If the thinker happens to have made a mistake in his replies, print "Incorrect data" without the quotes.
Examples
Input
2
1263 1 2
8103 2 1
Output
Need more data
Input
2
1234 2 2
1256 0 2
Output
2134
Input
2
0123 1 1
4567 1 2
Output
Incorrect data | instruction | 0 | 107,423 | 20 | 214,846 |
Tags: brute force, implementation
Correct Solution:
```
import sys
def solve():
n, = rv()
works = 0
lastworks = -1
guesses = list()
for i in range(n):
a, b, c, = rv()
acopy = a
charcount = [0] * 10
for x in range(4):
charcount[acopy % 10] += 1
acopy //= 10
guesses.append((tolist(a), b, c, charcount))
for i in range(1, 10000):
if different(i):
l = tolist(i)
icopy = i
charcount = [0] * 10
for x in range(4):
charcount[icopy % 10] += 1
icopy //= 10
count = 0
for guess in guesses:
bulls, cows = 0, 0
for j in range(4):
if l[j] == guess[0][j]: bulls += 1
for j in range(10):
if charcount[j] > 0 and guess[3][j] > 0: cows+=1
cows -= bulls
if bulls == guess[1] and cows == guess[2]:
count += 1
if count == n:
works += 1
lastworks = l
if works == 0:
print("Incorrect data")
elif works == 1:
print(''.join(map(str, lastworks)))
else:
print("Need more data")
def tolist(i):
il = list()
while i > 0:
il.append(i % 10)
i //= 10
while len(il) < 4: il.append(0)
return il[::-1]
def different(i):
count = [0] * 10
for x in range(4):
count[i % 10] += 1
i //= 10
for val in count:
if val > 1: return False
return True
def prt(l): return print(''.join(l))
def rv(): return map(int, input().split())
def rl(n): return [list(map(int, input().split())) for _ in range(n)]
if sys.hexversion == 50594544 : sys.stdin = open("test.txt")
solve()
# Made By Mostafa_Khaled
``` | output | 1 | 107,423 | 20 | 214,847 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The "Bulls and Cows" game needs two people to play. The thinker thinks of a number and the guesser tries to guess it.
The thinker thinks of a four-digit number in the decimal system. All the digits in the number are different and the number may have a leading zero. It can't have more than one leading zero, because all it's digits should be different. The guesser tries to guess the number. He makes a series of guesses, trying experimental numbers and receives answers from the first person in the format "x bulls y cows". x represents the number of digits in the experimental number that occupy the same positions as in the sought number. y represents the number of digits of the experimental number that present in the sought number, but occupy different positions. Naturally, the experimental numbers, as well as the sought number, are represented by four-digit numbers where all digits are different and a leading zero can be present.
For example, let's suppose that the thinker thought of the number 0123. Then the guessers' experimental number 1263 will receive a reply "1 bull 2 cows" (3 occupies the same positions in both numbers and 1 and 2 are present in both numbers but they occupy different positions). Also, the answer to number 8103 will be "2 bulls 1 cow" (analogically, 1 and 3 occupy the same positions and 0 occupies a different one).
When the guesser is answered "4 bulls 0 cows", the game is over.
Now the guesser has already made several guesses and wants to know whether his next guess can possibly be the last one.
Input
The first input line contains an integer n (1 β€ n β€ 10) which represents the number of already made guesses. Then follow n lines in the form of "ai bi ci", where ai is the i-th experimental number, bi is the number of bulls, ci is the number of cows (1 β€ i β€ n, 0 β€ bi, ci, bi + ci β€ 4). The experimental numbers are correct, i.e., each of them contains exactly four digits, in each of them all the four digits are different, and there can be a leading zero. All the experimental numbers are different. As the guesser hasn't guessed the number yet, the answer "4 bulls 0 cows" is not present.
Output
If the input data is enough to determine the sought number, print the number with four digits on a single line. If it has less than four digits, add leading zero. If the data is not enough, print "Need more data" without the quotes. If the thinker happens to have made a mistake in his replies, print "Incorrect data" without the quotes.
Examples
Input
2
1263 1 2
8103 2 1
Output
Need more data
Input
2
1234 2 2
1256 0 2
Output
2134
Input
2
0123 1 1
4567 1 2
Output
Incorrect data | instruction | 0 | 107,424 | 20 | 214,848 |
Tags: brute force, implementation
Correct Solution:
```
#------------------------template--------------------------#
import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import*
from io import BytesIO, IOBase
def vsInput():
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
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")
ALPHA='abcdefghijklmnopqrstuvwxyz'
MOD=1000000007
def value():return tuple(map(int,input().split()))
def array():return [int(i) for i in input().split()]
def Int():return int(input())
def Str():return input()
def arrayS():return [i for i in input().split()]
#-------------------------code---------------------------#
# vsInput()
numbers=set()
for i in range(10):
for j in range(10):
for k in range(10):
for l in range(10):
if(i!=j and i!=k and i!=l and j!=k and j!=l and k!=l):
numbers.add(str(i)+str(j)+str(k)+str(l))
def count():
possible=set()
for num in numbers:
cow=0
bulls=0
for i in range(4):
for j in range(4):
if(num[i]==n[j]):
bulls+=1
break
if(num[i]==n[i]): cow+=1
if(cow==x and bulls-cow==y):
possible.add(num)
return possible
for _ in range(Int()):
n,x,y=input().split()
x=int(x)
y=int(y)
numbers=count()
# print(numbers)
if(len(numbers)==1): print(list(numbers)[0])
elif(len(numbers)>1): print('Need more data')
else: print('Incorrect data')
``` | output | 1 | 107,424 | 20 | 214,849 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The "Bulls and Cows" game needs two people to play. The thinker thinks of a number and the guesser tries to guess it.
The thinker thinks of a four-digit number in the decimal system. All the digits in the number are different and the number may have a leading zero. It can't have more than one leading zero, because all it's digits should be different. The guesser tries to guess the number. He makes a series of guesses, trying experimental numbers and receives answers from the first person in the format "x bulls y cows". x represents the number of digits in the experimental number that occupy the same positions as in the sought number. y represents the number of digits of the experimental number that present in the sought number, but occupy different positions. Naturally, the experimental numbers, as well as the sought number, are represented by four-digit numbers where all digits are different and a leading zero can be present.
For example, let's suppose that the thinker thought of the number 0123. Then the guessers' experimental number 1263 will receive a reply "1 bull 2 cows" (3 occupies the same positions in both numbers and 1 and 2 are present in both numbers but they occupy different positions). Also, the answer to number 8103 will be "2 bulls 1 cow" (analogically, 1 and 3 occupy the same positions and 0 occupies a different one).
When the guesser is answered "4 bulls 0 cows", the game is over.
Now the guesser has already made several guesses and wants to know whether his next guess can possibly be the last one.
Input
The first input line contains an integer n (1 β€ n β€ 10) which represents the number of already made guesses. Then follow n lines in the form of "ai bi ci", where ai is the i-th experimental number, bi is the number of bulls, ci is the number of cows (1 β€ i β€ n, 0 β€ bi, ci, bi + ci β€ 4). The experimental numbers are correct, i.e., each of them contains exactly four digits, in each of them all the four digits are different, and there can be a leading zero. All the experimental numbers are different. As the guesser hasn't guessed the number yet, the answer "4 bulls 0 cows" is not present.
Output
If the input data is enough to determine the sought number, print the number with four digits on a single line. If it has less than four digits, add leading zero. If the data is not enough, print "Need more data" without the quotes. If the thinker happens to have made a mistake in his replies, print "Incorrect data" without the quotes.
Examples
Input
2
1263 1 2
8103 2 1
Output
Need more data
Input
2
1234 2 2
1256 0 2
Output
2134
Input
2
0123 1 1
4567 1 2
Output
Incorrect data | instruction | 0 | 107,425 | 20 | 214,850 |
Tags: brute force, implementation
Correct Solution:
```
import sys
def tolist(i):
listx = list()
while i > 0:
listx.append(i % 10)
i //= 10
while len(listx) < 4: listx.append(0)
return listx[::-1]
def diff(i):
count = [0] * 10
for x in range(4):
count[i % 10] += 1
i //= 10
for val in count:
if val > 1: return False
return True
n, = map(int, input().split())
works = 0
lastworks = -1
guesses = list()
for i in range(n):
a, b, c, = map(int, input().split())
acopy = a
charcount = [0] * 10
for x in range(4):
charcount[acopy % 10] += 1
acopy //= 10
guesses.append((tolist(a), b, c, charcount))
for i in range(1, 10000):
if diff(i):
l = tolist(i)
icopy = i
charcount = [0] * 10
for x in range(4):
charcount[icopy % 10] += 1
icopy //= 10
count = 0
for guess in guesses:
bulls, cows = 0, 0
for j in range(4):
if l[j] == guess[0][j]: bulls += 1
for j in range(10):
if charcount[j] > 0 and guess[3][j] > 0: cows+=1
cows -= bulls
if bulls == guess[1] and cows == guess[2]:
count += 1
if count == n:
works += 1
lastworks = l
if works == 0:
print("Incorrect data")
elif works == 1:
print(''.join(map(str, lastworks)))
else:
print("Need more data")
``` | output | 1 | 107,425 | 20 | 214,851 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The "Bulls and Cows" game needs two people to play. The thinker thinks of a number and the guesser tries to guess it.
The thinker thinks of a four-digit number in the decimal system. All the digits in the number are different and the number may have a leading zero. It can't have more than one leading zero, because all it's digits should be different. The guesser tries to guess the number. He makes a series of guesses, trying experimental numbers and receives answers from the first person in the format "x bulls y cows". x represents the number of digits in the experimental number that occupy the same positions as in the sought number. y represents the number of digits of the experimental number that present in the sought number, but occupy different positions. Naturally, the experimental numbers, as well as the sought number, are represented by four-digit numbers where all digits are different and a leading zero can be present.
For example, let's suppose that the thinker thought of the number 0123. Then the guessers' experimental number 1263 will receive a reply "1 bull 2 cows" (3 occupies the same positions in both numbers and 1 and 2 are present in both numbers but they occupy different positions). Also, the answer to number 8103 will be "2 bulls 1 cow" (analogically, 1 and 3 occupy the same positions and 0 occupies a different one).
When the guesser is answered "4 bulls 0 cows", the game is over.
Now the guesser has already made several guesses and wants to know whether his next guess can possibly be the last one.
Input
The first input line contains an integer n (1 β€ n β€ 10) which represents the number of already made guesses. Then follow n lines in the form of "ai bi ci", where ai is the i-th experimental number, bi is the number of bulls, ci is the number of cows (1 β€ i β€ n, 0 β€ bi, ci, bi + ci β€ 4). The experimental numbers are correct, i.e., each of them contains exactly four digits, in each of them all the four digits are different, and there can be a leading zero. All the experimental numbers are different. As the guesser hasn't guessed the number yet, the answer "4 bulls 0 cows" is not present.
Output
If the input data is enough to determine the sought number, print the number with four digits on a single line. If it has less than four digits, add leading zero. If the data is not enough, print "Need more data" without the quotes. If the thinker happens to have made a mistake in his replies, print "Incorrect data" without the quotes.
Examples
Input
2
1263 1 2
8103 2 1
Output
Need more data
Input
2
1234 2 2
1256 0 2
Output
2134
Input
2
0123 1 1
4567 1 2
Output
Incorrect data | instruction | 0 | 107,426 | 20 | 214,852 |
Tags: brute force, implementation
Correct Solution:
```
import sys
def solve():
n, = rv()
works = 0
lastworks = -1
guesses = list()
for i in range(n):
a, b, c, = rv()
acopy = a
charcount = [0] * 10
for x in range(4):
charcount[acopy % 10] += 1
acopy //= 10
guesses.append((tolist(a), b, c, charcount))
for i in range(1, 10000):
if different(i):
l = tolist(i)
icopy = i
charcount = [0] * 10
for x in range(4):
charcount[icopy % 10] += 1
icopy //= 10
count = 0
for guess in guesses:
bulls, cows = 0, 0
for j in range(4):
if l[j] == guess[0][j]: bulls += 1
for j in range(10):
if charcount[j] > 0 and guess[3][j] > 0: cows+=1
cows -= bulls
if bulls == guess[1] and cows == guess[2]:
count += 1
if count == n:
works += 1
lastworks = l
if works == 0:
print("Incorrect data")
elif works == 1:
print(''.join(map(str, lastworks)))
else:
print("Need more data")
def tolist(i):
il = list()
while i > 0:
il.append(i % 10)
i //= 10
while len(il) < 4: il.append(0)
return il[::-1]
def different(i):
count = [0] * 10
for x in range(4):
count[i % 10] += 1
i //= 10
for val in count:
if val > 1: return False
return True
def prt(l): return print(''.join(l))
def rv(): return map(int, input().split())
def rl(n): return [list(map(int, input().split())) for _ in range(n)]
if sys.hexversion == 50594544 : sys.stdin = open("test.txt")
solve()
``` | output | 1 | 107,426 | 20 | 214,853 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The "Bulls and Cows" game needs two people to play. The thinker thinks of a number and the guesser tries to guess it.
The thinker thinks of a four-digit number in the decimal system. All the digits in the number are different and the number may have a leading zero. It can't have more than one leading zero, because all it's digits should be different. The guesser tries to guess the number. He makes a series of guesses, trying experimental numbers and receives answers from the first person in the format "x bulls y cows". x represents the number of digits in the experimental number that occupy the same positions as in the sought number. y represents the number of digits of the experimental number that present in the sought number, but occupy different positions. Naturally, the experimental numbers, as well as the sought number, are represented by four-digit numbers where all digits are different and a leading zero can be present.
For example, let's suppose that the thinker thought of the number 0123. Then the guessers' experimental number 1263 will receive a reply "1 bull 2 cows" (3 occupies the same positions in both numbers and 1 and 2 are present in both numbers but they occupy different positions). Also, the answer to number 8103 will be "2 bulls 1 cow" (analogically, 1 and 3 occupy the same positions and 0 occupies a different one).
When the guesser is answered "4 bulls 0 cows", the game is over.
Now the guesser has already made several guesses and wants to know whether his next guess can possibly be the last one.
Input
The first input line contains an integer n (1 β€ n β€ 10) which represents the number of already made guesses. Then follow n lines in the form of "ai bi ci", where ai is the i-th experimental number, bi is the number of bulls, ci is the number of cows (1 β€ i β€ n, 0 β€ bi, ci, bi + ci β€ 4). The experimental numbers are correct, i.e., each of them contains exactly four digits, in each of them all the four digits are different, and there can be a leading zero. All the experimental numbers are different. As the guesser hasn't guessed the number yet, the answer "4 bulls 0 cows" is not present.
Output
If the input data is enough to determine the sought number, print the number with four digits on a single line. If it has less than four digits, add leading zero. If the data is not enough, print "Need more data" without the quotes. If the thinker happens to have made a mistake in his replies, print "Incorrect data" without the quotes.
Examples
Input
2
1263 1 2
8103 2 1
Output
Need more data
Input
2
1234 2 2
1256 0 2
Output
2134
Input
2
0123 1 1
4567 1 2
Output
Incorrect data | instruction | 0 | 107,427 | 20 | 214,854 |
Tags: brute force, implementation
Correct Solution:
```
# cook your dish here
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
import copy
import time
starttime = time.time()
mod = int(pow(10, 9) + 7)
mod2 = 998244353
# from sys import stdin
# input = stdin.readline
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def L(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]
try:
# sys.setrecursionlimit(int(pow(10,7)))
sys.stdin = open("input.txt", "r")
# sys.stdout = open("../output.txt", "w")
except:
pass
def pmat(A):
for ele in A:
print(*ele,end="\n")
def seive():
prime=[1 for i in range(10**6+1)]
prime[0]=0
prime[1]=0
for i in range(10**6+1):
if(prime[i]):
for j in range(2*i,10**6+1,i):
prime[j]=0
return prime
# exit()
S=set()
for term in range(L()[0]):
a,b,c=sl()
curr=set()
b=int(b)
c=int(c)
for i in range(10):
for j in range(10):
for k in range(10):
for l in range(10):
A=[i,j,k,l]
if len(set(A))!=4:
continue
tb,tc=0,0
for pos in range(4):
# print(A,a)
if A[pos]==int(a[pos]):
tb+=1
elif str(A[pos]) in a:
tc+=1
if tb==b and tc==c:
A=[str(ele) for ele in A]
curr.add("".join(A))
if term==0:
# print(curr)
S=curr
else:
# print(curr)
S&=curr
# print(S)
if len(S)==1:
for ele in S:
for x in ele:
print(x,end="")
print()
elif len(S)==0:
print("Incorrect data")
else:
print("Need more data")
endtime = time.time()
# print(f"Runtime of the program is {endtime - starttime}")
``` | output | 1 | 107,427 | 20 | 214,855 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The "Bulls and Cows" game needs two people to play. The thinker thinks of a number and the guesser tries to guess it.
The thinker thinks of a four-digit number in the decimal system. All the digits in the number are different and the number may have a leading zero. It can't have more than one leading zero, because all it's digits should be different. The guesser tries to guess the number. He makes a series of guesses, trying experimental numbers and receives answers from the first person in the format "x bulls y cows". x represents the number of digits in the experimental number that occupy the same positions as in the sought number. y represents the number of digits of the experimental number that present in the sought number, but occupy different positions. Naturally, the experimental numbers, as well as the sought number, are represented by four-digit numbers where all digits are different and a leading zero can be present.
For example, let's suppose that the thinker thought of the number 0123. Then the guessers' experimental number 1263 will receive a reply "1 bull 2 cows" (3 occupies the same positions in both numbers and 1 and 2 are present in both numbers but they occupy different positions). Also, the answer to number 8103 will be "2 bulls 1 cow" (analogically, 1 and 3 occupy the same positions and 0 occupies a different one).
When the guesser is answered "4 bulls 0 cows", the game is over.
Now the guesser has already made several guesses and wants to know whether his next guess can possibly be the last one.
Input
The first input line contains an integer n (1 β€ n β€ 10) which represents the number of already made guesses. Then follow n lines in the form of "ai bi ci", where ai is the i-th experimental number, bi is the number of bulls, ci is the number of cows (1 β€ i β€ n, 0 β€ bi, ci, bi + ci β€ 4). The experimental numbers are correct, i.e., each of them contains exactly four digits, in each of them all the four digits are different, and there can be a leading zero. All the experimental numbers are different. As the guesser hasn't guessed the number yet, the answer "4 bulls 0 cows" is not present.
Output
If the input data is enough to determine the sought number, print the number with four digits on a single line. If it has less than four digits, add leading zero. If the data is not enough, print "Need more data" without the quotes. If the thinker happens to have made a mistake in his replies, print "Incorrect data" without the quotes.
Examples
Input
2
1263 1 2
8103 2 1
Output
Need more data
Input
2
1234 2 2
1256 0 2
Output
2134
Input
2
0123 1 1
4567 1 2
Output
Incorrect data | instruction | 0 | 107,428 | 20 | 214,856 |
Tags: brute force, implementation
Correct Solution:
```
import sys
lines = sys.stdin.readlines()
n = int(lines[0].strip())
query = []
for i in range(1, n+1):
(a, b, c) = lines[i].strip().split(" ")
query.append((a, int(b), int(c)))
def compare(i):
digits = str(i)
digits = "0" *(4-len(digits)) + digits
if len(set(list(digits))) != 4: return False
for q in query:
(a, b, c) = q
m, n = 0, 0
for i in range(4):
if a[i] == digits[i]: m += 1
for l in a:
if l in digits: n += 1
n -= m
if m != b or n != c:
return False
return True
res = 0
count = 0
for i in range(123, 9877):
if compare(i): count += 1; res = i
if count >= 2: break
if count == 0: print("Incorrect data")
elif count == 1:
digits = str(res)
digits = "0" *(4-len(digits)) + digits
print(digits)
else: print("Need more data")
``` | output | 1 | 107,428 | 20 | 214,857 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The "Bulls and Cows" game needs two people to play. The thinker thinks of a number and the guesser tries to guess it.
The thinker thinks of a four-digit number in the decimal system. All the digits in the number are different and the number may have a leading zero. It can't have more than one leading zero, because all it's digits should be different. The guesser tries to guess the number. He makes a series of guesses, trying experimental numbers and receives answers from the first person in the format "x bulls y cows". x represents the number of digits in the experimental number that occupy the same positions as in the sought number. y represents the number of digits of the experimental number that present in the sought number, but occupy different positions. Naturally, the experimental numbers, as well as the sought number, are represented by four-digit numbers where all digits are different and a leading zero can be present.
For example, let's suppose that the thinker thought of the number 0123. Then the guessers' experimental number 1263 will receive a reply "1 bull 2 cows" (3 occupies the same positions in both numbers and 1 and 2 are present in both numbers but they occupy different positions). Also, the answer to number 8103 will be "2 bulls 1 cow" (analogically, 1 and 3 occupy the same positions and 0 occupies a different one).
When the guesser is answered "4 bulls 0 cows", the game is over.
Now the guesser has already made several guesses and wants to know whether his next guess can possibly be the last one.
Input
The first input line contains an integer n (1 β€ n β€ 10) which represents the number of already made guesses. Then follow n lines in the form of "ai bi ci", where ai is the i-th experimental number, bi is the number of bulls, ci is the number of cows (1 β€ i β€ n, 0 β€ bi, ci, bi + ci β€ 4). The experimental numbers are correct, i.e., each of them contains exactly four digits, in each of them all the four digits are different, and there can be a leading zero. All the experimental numbers are different. As the guesser hasn't guessed the number yet, the answer "4 bulls 0 cows" is not present.
Output
If the input data is enough to determine the sought number, print the number with four digits on a single line. If it has less than four digits, add leading zero. If the data is not enough, print "Need more data" without the quotes. If the thinker happens to have made a mistake in his replies, print "Incorrect data" without the quotes.
Examples
Input
2
1263 1 2
8103 2 1
Output
Need more data
Input
2
1234 2 2
1256 0 2
Output
2134
Input
2
0123 1 1
4567 1 2
Output
Incorrect data | instruction | 0 | 107,429 | 20 | 214,858 |
Tags: brute force, implementation
Correct Solution:
```
def filter(candidates, num, rp, wp):
ans = []
for cand in candidates:
crp = cwp = 0
for a, b in zip(cand, num):
if a == b:
crp += 1
elif a in num:
cwp += 1
if crp == rp and cwp == wp:
ans.append(cand)
return ans
def main():
n = int(input())
candidates = []
for i in range(123, 9877):
num = str(i).zfill(4)
if len(set(num)) == 4:
candidates.append(num)
for _ in range(n):
a, b, c = input().split()
candidates = filter(candidates, a, int(b), int(c))
if not candidates:
print('Incorrect data')
return
print(candidates[0] if len(candidates) == 1 else 'Need more data')
if __name__ == "__main__":
main()
``` | output | 1 | 107,429 | 20 | 214,859 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The "Bulls and Cows" game needs two people to play. The thinker thinks of a number and the guesser tries to guess it.
The thinker thinks of a four-digit number in the decimal system. All the digits in the number are different and the number may have a leading zero. It can't have more than one leading zero, because all it's digits should be different. The guesser tries to guess the number. He makes a series of guesses, trying experimental numbers and receives answers from the first person in the format "x bulls y cows". x represents the number of digits in the experimental number that occupy the same positions as in the sought number. y represents the number of digits of the experimental number that present in the sought number, but occupy different positions. Naturally, the experimental numbers, as well as the sought number, are represented by four-digit numbers where all digits are different and a leading zero can be present.
For example, let's suppose that the thinker thought of the number 0123. Then the guessers' experimental number 1263 will receive a reply "1 bull 2 cows" (3 occupies the same positions in both numbers and 1 and 2 are present in both numbers but they occupy different positions). Also, the answer to number 8103 will be "2 bulls 1 cow" (analogically, 1 and 3 occupy the same positions and 0 occupies a different one).
When the guesser is answered "4 bulls 0 cows", the game is over.
Now the guesser has already made several guesses and wants to know whether his next guess can possibly be the last one.
Input
The first input line contains an integer n (1 β€ n β€ 10) which represents the number of already made guesses. Then follow n lines in the form of "ai bi ci", where ai is the i-th experimental number, bi is the number of bulls, ci is the number of cows (1 β€ i β€ n, 0 β€ bi, ci, bi + ci β€ 4). The experimental numbers are correct, i.e., each of them contains exactly four digits, in each of them all the four digits are different, and there can be a leading zero. All the experimental numbers are different. As the guesser hasn't guessed the number yet, the answer "4 bulls 0 cows" is not present.
Output
If the input data is enough to determine the sought number, print the number with four digits on a single line. If it has less than four digits, add leading zero. If the data is not enough, print "Need more data" without the quotes. If the thinker happens to have made a mistake in his replies, print "Incorrect data" without the quotes.
Examples
Input
2
1263 1 2
8103 2 1
Output
Need more data
Input
2
1234 2 2
1256 0 2
Output
2134
Input
2
0123 1 1
4567 1 2
Output
Incorrect data | instruction | 0 | 107,430 | 20 | 214,860 |
Tags: brute force, implementation
Correct Solution:
```
n=int(input())
array=[str(t).zfill(4) for t in range(10000) if len(set(str(t).zfill(4)))==4]
# print (array)
for _ in range(n):
a,b,c=input().split()
b=int(b)
c=int(c)
# for u in array:
# print (u, set(u).intersection(set(a)))
array=[u for u in array if len(set(u).intersection(set(a)))==b+c and sum(u[i]==a[i] for i in range(4))==b]
# print (array)
if len(array)>1:print("Need more data")
elif len(array)==1:print(array[0])
else:print("Incorrect data")
``` | output | 1 | 107,430 | 20 | 214,861 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multiset with integers. Friends give her t queries, each of one of the following type:
1. + ai β add non-negative integer ai to the multiset. Note, that she has a multiset, thus there may be many occurrences of the same integer.
2. - ai β delete a single occurrence of non-negative integer ai from the multiset. It's guaranteed, that there is at least one ai in the multiset.
3. ? s β count the number of integers in the multiset (with repetitions) that match some pattern s consisting of 0 and 1. In the pattern, 0 stands for the even digits, while 1 stands for the odd. Integer x matches the pattern s, if the parity of the i-th from the right digit in decimal notation matches the i-th from the right digit of the pattern. If the pattern is shorter than this integer, it's supplemented with 0-s from the left. Similarly, if the integer is shorter than the pattern its decimal notation is supplemented with the 0-s from the left.
For example, if the pattern is s = 010, than integers 92, 2212, 50 and 414 match the pattern, while integers 3, 110, 25 and 1030 do not.
Input
The first line of the input contains an integer t (1 β€ t β€ 100 000) β the number of operation Sonya has to perform.
Next t lines provide the descriptions of the queries in order they appear in the input file. The i-th row starts with a character ci β the type of the corresponding operation. If ci is equal to '+' or '-' then it's followed by a space and an integer ai (0 β€ ai < 1018) given without leading zeroes (unless it's 0). If ci equals '?' then it's followed by a space and a sequence of zeroes and onse, giving the pattern of length no more than 18.
It's guaranteed that there will be at least one query of type '?'.
It's guaranteed that any time some integer is removed from the multiset, there will be at least one occurrence of this integer in it.
Output
For each query of the third type print the number of integers matching the given pattern. Each integer is counted as many times, as it appears in the multiset at this moment of time.
Examples
Input
12
+ 1
+ 241
? 1
+ 361
- 241
? 0101
+ 101
? 101
- 101
? 101
+ 4000
? 0
Output
2
1
2
1
1
Input
4
+ 200
+ 200
- 200
? 0
Output
1
Note
Consider the integers matching the patterns from the queries of the third type. Queries are numbered in the order they appear in the input.
1. 1 and 241.
2. 361.
3. 101 and 361.
4. 361.
5. 4000. | instruction | 0 | 107,471 | 20 | 214,942 |
Tags: data structures, implementation
Correct Solution:
```
#!/usr/local/env python3
# -*- encoding: utf-8 -*-
import sys
import re
def mask2(s):
m = int("0", 2)
while len(s) > 0:
m *= 2
m += int(s[0]) % 2
s = s[1:]
return m
def mask(s):
return int(re.sub("[02468]", "0", re.sub("[13579]", "1", s)), 2)
def solve():
d = dict()
n = int(sys.stdin.readline().strip())
ans = ""
for line in sys.stdin:
op, i = line.strip().split(' ')
m = mask(i)
if op == '+':
d.setdefault(m, 0)
d[m] += 1
if op == '-':
d[m] -= 1
if op == '?':
ans += "{:d}\n".format(d.get(m, 0))
return ans
if __name__ == "__main__":
ans = solve()
print(ans)
``` | output | 1 | 107,471 | 20 | 214,943 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multiset with integers. Friends give her t queries, each of one of the following type:
1. + ai β add non-negative integer ai to the multiset. Note, that she has a multiset, thus there may be many occurrences of the same integer.
2. - ai β delete a single occurrence of non-negative integer ai from the multiset. It's guaranteed, that there is at least one ai in the multiset.
3. ? s β count the number of integers in the multiset (with repetitions) that match some pattern s consisting of 0 and 1. In the pattern, 0 stands for the even digits, while 1 stands for the odd. Integer x matches the pattern s, if the parity of the i-th from the right digit in decimal notation matches the i-th from the right digit of the pattern. If the pattern is shorter than this integer, it's supplemented with 0-s from the left. Similarly, if the integer is shorter than the pattern its decimal notation is supplemented with the 0-s from the left.
For example, if the pattern is s = 010, than integers 92, 2212, 50 and 414 match the pattern, while integers 3, 110, 25 and 1030 do not.
Input
The first line of the input contains an integer t (1 β€ t β€ 100 000) β the number of operation Sonya has to perform.
Next t lines provide the descriptions of the queries in order they appear in the input file. The i-th row starts with a character ci β the type of the corresponding operation. If ci is equal to '+' or '-' then it's followed by a space and an integer ai (0 β€ ai < 1018) given without leading zeroes (unless it's 0). If ci equals '?' then it's followed by a space and a sequence of zeroes and onse, giving the pattern of length no more than 18.
It's guaranteed that there will be at least one query of type '?'.
It's guaranteed that any time some integer is removed from the multiset, there will be at least one occurrence of this integer in it.
Output
For each query of the third type print the number of integers matching the given pattern. Each integer is counted as many times, as it appears in the multiset at this moment of time.
Examples
Input
12
+ 1
+ 241
? 1
+ 361
- 241
? 0101
+ 101
? 101
- 101
? 101
+ 4000
? 0
Output
2
1
2
1
1
Input
4
+ 200
+ 200
- 200
? 0
Output
1
Note
Consider the integers matching the patterns from the queries of the third type. Queries are numbered in the order they appear in the input.
1. 1 and 241.
2. 361.
3. 101 and 361.
4. 361.
5. 4000. | instruction | 0 | 107,472 | 20 | 214,944 |
Tags: data structures, implementation
Correct Solution:
```
from sys import stdin, stdout
quests = int(stdin.readline().rstrip())
multi_set = {}
p = str.maketrans('0123456789', '0101010101')
for i in range(quests):
quest, core = stdin.readline().rstrip().split()
pattern = int(core.translate(p))
if quest == '+':
if pattern in multi_set.keys(): multi_set[pattern] += 1
else: multi_set[pattern] = 1
elif quest == '-': multi_set[pattern] -= 1
else:
if pattern in multi_set: stdout.write(str(multi_set[pattern])+'\n')
else: stdout.write('0\n')
``` | output | 1 | 107,472 | 20 | 214,945 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multiset with integers. Friends give her t queries, each of one of the following type:
1. + ai β add non-negative integer ai to the multiset. Note, that she has a multiset, thus there may be many occurrences of the same integer.
2. - ai β delete a single occurrence of non-negative integer ai from the multiset. It's guaranteed, that there is at least one ai in the multiset.
3. ? s β count the number of integers in the multiset (with repetitions) that match some pattern s consisting of 0 and 1. In the pattern, 0 stands for the even digits, while 1 stands for the odd. Integer x matches the pattern s, if the parity of the i-th from the right digit in decimal notation matches the i-th from the right digit of the pattern. If the pattern is shorter than this integer, it's supplemented with 0-s from the left. Similarly, if the integer is shorter than the pattern its decimal notation is supplemented with the 0-s from the left.
For example, if the pattern is s = 010, than integers 92, 2212, 50 and 414 match the pattern, while integers 3, 110, 25 and 1030 do not.
Input
The first line of the input contains an integer t (1 β€ t β€ 100 000) β the number of operation Sonya has to perform.
Next t lines provide the descriptions of the queries in order they appear in the input file. The i-th row starts with a character ci β the type of the corresponding operation. If ci is equal to '+' or '-' then it's followed by a space and an integer ai (0 β€ ai < 1018) given without leading zeroes (unless it's 0). If ci equals '?' then it's followed by a space and a sequence of zeroes and onse, giving the pattern of length no more than 18.
It's guaranteed that there will be at least one query of type '?'.
It's guaranteed that any time some integer is removed from the multiset, there will be at least one occurrence of this integer in it.
Output
For each query of the third type print the number of integers matching the given pattern. Each integer is counted as many times, as it appears in the multiset at this moment of time.
Examples
Input
12
+ 1
+ 241
? 1
+ 361
- 241
? 0101
+ 101
? 101
- 101
? 101
+ 4000
? 0
Output
2
1
2
1
1
Input
4
+ 200
+ 200
- 200
? 0
Output
1
Note
Consider the integers matching the patterns from the queries of the third type. Queries are numbered in the order they appear in the input.
1. 1 and 241.
2. 361.
3. 101 and 361.
4. 361.
5. 4000. | instruction | 0 | 107,473 | 20 | 214,946 |
Tags: data structures, implementation
Correct Solution:
```
t = int(input())
trantab = str.maketrans('0123456789', '0101010101')
a = {}
for i in range(t):
string = input()
oper, number = string.split()
pattern = int(number.translate(trantab))
if oper == '+':
a[pattern] = a.get(pattern, 0) + 1
elif oper == '-':
a[pattern] -= 1
if not a[pattern]:
del a[pattern]
else:
if pattern in a:
print(a[pattern])
else:
print(0)
``` | output | 1 | 107,473 | 20 | 214,947 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multiset with integers. Friends give her t queries, each of one of the following type:
1. + ai β add non-negative integer ai to the multiset. Note, that she has a multiset, thus there may be many occurrences of the same integer.
2. - ai β delete a single occurrence of non-negative integer ai from the multiset. It's guaranteed, that there is at least one ai in the multiset.
3. ? s β count the number of integers in the multiset (with repetitions) that match some pattern s consisting of 0 and 1. In the pattern, 0 stands for the even digits, while 1 stands for the odd. Integer x matches the pattern s, if the parity of the i-th from the right digit in decimal notation matches the i-th from the right digit of the pattern. If the pattern is shorter than this integer, it's supplemented with 0-s from the left. Similarly, if the integer is shorter than the pattern its decimal notation is supplemented with the 0-s from the left.
For example, if the pattern is s = 010, than integers 92, 2212, 50 and 414 match the pattern, while integers 3, 110, 25 and 1030 do not.
Input
The first line of the input contains an integer t (1 β€ t β€ 100 000) β the number of operation Sonya has to perform.
Next t lines provide the descriptions of the queries in order they appear in the input file. The i-th row starts with a character ci β the type of the corresponding operation. If ci is equal to '+' or '-' then it's followed by a space and an integer ai (0 β€ ai < 1018) given without leading zeroes (unless it's 0). If ci equals '?' then it's followed by a space and a sequence of zeroes and onse, giving the pattern of length no more than 18.
It's guaranteed that there will be at least one query of type '?'.
It's guaranteed that any time some integer is removed from the multiset, there will be at least one occurrence of this integer in it.
Output
For each query of the third type print the number of integers matching the given pattern. Each integer is counted as many times, as it appears in the multiset at this moment of time.
Examples
Input
12
+ 1
+ 241
? 1
+ 361
- 241
? 0101
+ 101
? 101
- 101
? 101
+ 4000
? 0
Output
2
1
2
1
1
Input
4
+ 200
+ 200
- 200
? 0
Output
1
Note
Consider the integers matching the patterns from the queries of the third type. Queries are numbered in the order they appear in the input.
1. 1 and 241.
2. 361.
3. 101 and 361.
4. 361.
5. 4000. | instruction | 0 | 107,474 | 20 | 214,948 |
Tags: data structures, implementation
Correct Solution:
```
# Description of the problem can be found at http://codeforces.com/problemset/problem/713/A
from collections import defaultdict
from sys import stdin
from sys import stdout
n = int(stdin.readline())
d = defaultdict(int)
for _ in range(n):
s, x = stdin.readline().split()
y = "".join(["1" if c in ["1", "3", "5", "7", "9"] else "0" for c in x]).zfill(18)
if s == "+":
d[y] += 1
elif s == "-":
d[y] -= 1
else:
stdout.write(str(d[y]) + '\n')
``` | output | 1 | 107,474 | 20 | 214,949 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multiset with integers. Friends give her t queries, each of one of the following type:
1. + ai β add non-negative integer ai to the multiset. Note, that she has a multiset, thus there may be many occurrences of the same integer.
2. - ai β delete a single occurrence of non-negative integer ai from the multiset. It's guaranteed, that there is at least one ai in the multiset.
3. ? s β count the number of integers in the multiset (with repetitions) that match some pattern s consisting of 0 and 1. In the pattern, 0 stands for the even digits, while 1 stands for the odd. Integer x matches the pattern s, if the parity of the i-th from the right digit in decimal notation matches the i-th from the right digit of the pattern. If the pattern is shorter than this integer, it's supplemented with 0-s from the left. Similarly, if the integer is shorter than the pattern its decimal notation is supplemented with the 0-s from the left.
For example, if the pattern is s = 010, than integers 92, 2212, 50 and 414 match the pattern, while integers 3, 110, 25 and 1030 do not.
Input
The first line of the input contains an integer t (1 β€ t β€ 100 000) β the number of operation Sonya has to perform.
Next t lines provide the descriptions of the queries in order they appear in the input file. The i-th row starts with a character ci β the type of the corresponding operation. If ci is equal to '+' or '-' then it's followed by a space and an integer ai (0 β€ ai < 1018) given without leading zeroes (unless it's 0). If ci equals '?' then it's followed by a space and a sequence of zeroes and onse, giving the pattern of length no more than 18.
It's guaranteed that there will be at least one query of type '?'.
It's guaranteed that any time some integer is removed from the multiset, there will be at least one occurrence of this integer in it.
Output
For each query of the third type print the number of integers matching the given pattern. Each integer is counted as many times, as it appears in the multiset at this moment of time.
Examples
Input
12
+ 1
+ 241
? 1
+ 361
- 241
? 0101
+ 101
? 101
- 101
? 101
+ 4000
? 0
Output
2
1
2
1
1
Input
4
+ 200
+ 200
- 200
? 0
Output
1
Note
Consider the integers matching the patterns from the queries of the third type. Queries are numbered in the order they appear in the input.
1. 1 and 241.
2. 361.
3. 101 and 361.
4. 361.
5. 4000. | instruction | 0 | 107,475 | 20 | 214,950 |
Tags: data structures, implementation
Correct Solution:
```
num = int(input())
multiset = [0] * 2 ** 18
t = str.maketrans('0123456789', '0101010101')
while num:
opr = input().split()
if opr[0] == '+':
multiset[int(opr[1].translate(t), 2)] += 1
elif opr[0] == '-':
multiset[int(opr[1].translate(t), 2)] -= 1
elif opr[0] == '?':
print(multiset[int(opr[1], 2)])
num -= 1
``` | output | 1 | 107,475 | 20 | 214,951 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multiset with integers. Friends give her t queries, each of one of the following type:
1. + ai β add non-negative integer ai to the multiset. Note, that she has a multiset, thus there may be many occurrences of the same integer.
2. - ai β delete a single occurrence of non-negative integer ai from the multiset. It's guaranteed, that there is at least one ai in the multiset.
3. ? s β count the number of integers in the multiset (with repetitions) that match some pattern s consisting of 0 and 1. In the pattern, 0 stands for the even digits, while 1 stands for the odd. Integer x matches the pattern s, if the parity of the i-th from the right digit in decimal notation matches the i-th from the right digit of the pattern. If the pattern is shorter than this integer, it's supplemented with 0-s from the left. Similarly, if the integer is shorter than the pattern its decimal notation is supplemented with the 0-s from the left.
For example, if the pattern is s = 010, than integers 92, 2212, 50 and 414 match the pattern, while integers 3, 110, 25 and 1030 do not.
Input
The first line of the input contains an integer t (1 β€ t β€ 100 000) β the number of operation Sonya has to perform.
Next t lines provide the descriptions of the queries in order they appear in the input file. The i-th row starts with a character ci β the type of the corresponding operation. If ci is equal to '+' or '-' then it's followed by a space and an integer ai (0 β€ ai < 1018) given without leading zeroes (unless it's 0). If ci equals '?' then it's followed by a space and a sequence of zeroes and onse, giving the pattern of length no more than 18.
It's guaranteed that there will be at least one query of type '?'.
It's guaranteed that any time some integer is removed from the multiset, there will be at least one occurrence of this integer in it.
Output
For each query of the third type print the number of integers matching the given pattern. Each integer is counted as many times, as it appears in the multiset at this moment of time.
Examples
Input
12
+ 1
+ 241
? 1
+ 361
- 241
? 0101
+ 101
? 101
- 101
? 101
+ 4000
? 0
Output
2
1
2
1
1
Input
4
+ 200
+ 200
- 200
? 0
Output
1
Note
Consider the integers matching the patterns from the queries of the third type. Queries are numbered in the order they appear in the input.
1. 1 and 241.
2. 361.
3. 101 and 361.
4. 361.
5. 4000. | instruction | 0 | 107,476 | 20 | 214,952 |
Tags: data structures, implementation
Correct Solution:
```
n = int(input())
ans = [0] * 2 ** 18
trantab = str.maketrans('0123456789', '0101010101')
for i in range(n):
ch, s = map(str, input().split())
if ch == '+':
ans[int(s.translate(trantab), 2)] += 1
elif ch == '-':
ans[int(s.translate(trantab), 2)] -= 1
else:
print(ans[int(s.translate(trantab), 2)])
``` | output | 1 | 107,476 | 20 | 214,953 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multiset with integers. Friends give her t queries, each of one of the following type:
1. + ai β add non-negative integer ai to the multiset. Note, that she has a multiset, thus there may be many occurrences of the same integer.
2. - ai β delete a single occurrence of non-negative integer ai from the multiset. It's guaranteed, that there is at least one ai in the multiset.
3. ? s β count the number of integers in the multiset (with repetitions) that match some pattern s consisting of 0 and 1. In the pattern, 0 stands for the even digits, while 1 stands for the odd. Integer x matches the pattern s, if the parity of the i-th from the right digit in decimal notation matches the i-th from the right digit of the pattern. If the pattern is shorter than this integer, it's supplemented with 0-s from the left. Similarly, if the integer is shorter than the pattern its decimal notation is supplemented with the 0-s from the left.
For example, if the pattern is s = 010, than integers 92, 2212, 50 and 414 match the pattern, while integers 3, 110, 25 and 1030 do not.
Input
The first line of the input contains an integer t (1 β€ t β€ 100 000) β the number of operation Sonya has to perform.
Next t lines provide the descriptions of the queries in order they appear in the input file. The i-th row starts with a character ci β the type of the corresponding operation. If ci is equal to '+' or '-' then it's followed by a space and an integer ai (0 β€ ai < 1018) given without leading zeroes (unless it's 0). If ci equals '?' then it's followed by a space and a sequence of zeroes and onse, giving the pattern of length no more than 18.
It's guaranteed that there will be at least one query of type '?'.
It's guaranteed that any time some integer is removed from the multiset, there will be at least one occurrence of this integer in it.
Output
For each query of the third type print the number of integers matching the given pattern. Each integer is counted as many times, as it appears in the multiset at this moment of time.
Examples
Input
12
+ 1
+ 241
? 1
+ 361
- 241
? 0101
+ 101
? 101
- 101
? 101
+ 4000
? 0
Output
2
1
2
1
1
Input
4
+ 200
+ 200
- 200
? 0
Output
1
Note
Consider the integers matching the patterns from the queries of the third type. Queries are numbered in the order they appear in the input.
1. 1 and 241.
2. 361.
3. 101 and 361.
4. 361.
5. 4000. | instruction | 0 | 107,477 | 20 | 214,954 |
Tags: data structures, implementation
Correct Solution:
```
# Problem : C. Sonya and Queries
# Contest : Codeforces Round #371 (Div. 2)
# URL : https://codeforces.com/contest/714/problem/C
# Memory Limit : 256 MB
# Time Limit : 1000 ms
# Powered by CP Editor (https://github.com/cpeditor/cpeditor)
"""
// Author : snape_here - Susanta Mukherjee
"""
from __future__ import division, print_function
import os,sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
from __builtin__ import xrange as range
from future_builtins import ascii, filter, hex, map, oct, zip
def ii(): return int(input())
def si(): return input()
def mi(): return map(str,input().split())
def li(): return list(mi())
def read():
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
def gcd(x, y):
while y:
x, y = y, x % y
return x
mod=1000000007
import math
def main():
t=ii()
di={}
for _ in range(t):
c,a=mi()
s=""
for i in range(len(a)):
s+=str(int(a[i])%2)
d=18-len(a)
s=d*'0'+s
if c=='+':
if s in di:
di[s]+=1
else:
di[s]=1
elif c=='-':
di[s]-=1
else:
d=18-len(a)
a=d*'0'+a
if a in di:
print(di[a])
else:
print(0)
# region fastio
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")
def print(*args, **kwargs):
"""Prints the values to a stream, or to sys.stdout by default."""
sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
at_start = True
for x in args:
if not at_start:
file.write(sep)
file.write(str(x))
at_start = False
file.write(kwargs.pop("end", "\n"))
if kwargs.pop("flush", False):
file.flush()
if sys.version_info[0] < 3:
sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# endregion
if __name__ == "__main__":
#read()
main()
``` | output | 1 | 107,477 | 20 | 214,955 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multiset with integers. Friends give her t queries, each of one of the following type:
1. + ai β add non-negative integer ai to the multiset. Note, that she has a multiset, thus there may be many occurrences of the same integer.
2. - ai β delete a single occurrence of non-negative integer ai from the multiset. It's guaranteed, that there is at least one ai in the multiset.
3. ? s β count the number of integers in the multiset (with repetitions) that match some pattern s consisting of 0 and 1. In the pattern, 0 stands for the even digits, while 1 stands for the odd. Integer x matches the pattern s, if the parity of the i-th from the right digit in decimal notation matches the i-th from the right digit of the pattern. If the pattern is shorter than this integer, it's supplemented with 0-s from the left. Similarly, if the integer is shorter than the pattern its decimal notation is supplemented with the 0-s from the left.
For example, if the pattern is s = 010, than integers 92, 2212, 50 and 414 match the pattern, while integers 3, 110, 25 and 1030 do not.
Input
The first line of the input contains an integer t (1 β€ t β€ 100 000) β the number of operation Sonya has to perform.
Next t lines provide the descriptions of the queries in order they appear in the input file. The i-th row starts with a character ci β the type of the corresponding operation. If ci is equal to '+' or '-' then it's followed by a space and an integer ai (0 β€ ai < 1018) given without leading zeroes (unless it's 0). If ci equals '?' then it's followed by a space and a sequence of zeroes and onse, giving the pattern of length no more than 18.
It's guaranteed that there will be at least one query of type '?'.
It's guaranteed that any time some integer is removed from the multiset, there will be at least one occurrence of this integer in it.
Output
For each query of the third type print the number of integers matching the given pattern. Each integer is counted as many times, as it appears in the multiset at this moment of time.
Examples
Input
12
+ 1
+ 241
? 1
+ 361
- 241
? 0101
+ 101
? 101
- 101
? 101
+ 4000
? 0
Output
2
1
2
1
1
Input
4
+ 200
+ 200
- 200
? 0
Output
1
Note
Consider the integers matching the patterns from the queries of the third type. Queries are numbered in the order they appear in the input.
1. 1 and 241.
2. 361.
3. 101 and 361.
4. 361.
5. 4000. | instruction | 0 | 107,478 | 20 | 214,956 |
Tags: data structures, implementation
Correct Solution:
```
import sys
import math
import collections
import heapq
input=sys.stdin.readline
d={}
t=int(input())
for w in range(t):
x,y=(i for i in input().split())
y=list(y)
k=len(y)
for i in range(k):
if(int(y[i])%2==0):
y[i]='0'
else:
y[i]='1'
y=''.join(y)
if(k<30):
y='0'*(30-k)+y
if(x=='+'):
if(y in d):
d[y]+=1
else:
d[y]=1
elif(x=='-'):
d[y]-=1
else:
if(y in d):
print(d[y])
else:
print(0)
``` | output | 1 | 107,478 | 20 | 214,957 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multiset with integers. Friends give her t queries, each of one of the following type:
1. + ai β add non-negative integer ai to the multiset. Note, that she has a multiset, thus there may be many occurrences of the same integer.
2. - ai β delete a single occurrence of non-negative integer ai from the multiset. It's guaranteed, that there is at least one ai in the multiset.
3. ? s β count the number of integers in the multiset (with repetitions) that match some pattern s consisting of 0 and 1. In the pattern, 0 stands for the even digits, while 1 stands for the odd. Integer x matches the pattern s, if the parity of the i-th from the right digit in decimal notation matches the i-th from the right digit of the pattern. If the pattern is shorter than this integer, it's supplemented with 0-s from the left. Similarly, if the integer is shorter than the pattern its decimal notation is supplemented with the 0-s from the left.
For example, if the pattern is s = 010, than integers 92, 2212, 50 and 414 match the pattern, while integers 3, 110, 25 and 1030 do not.
Input
The first line of the input contains an integer t (1 β€ t β€ 100 000) β the number of operation Sonya has to perform.
Next t lines provide the descriptions of the queries in order they appear in the input file. The i-th row starts with a character ci β the type of the corresponding operation. If ci is equal to '+' or '-' then it's followed by a space and an integer ai (0 β€ ai < 1018) given without leading zeroes (unless it's 0). If ci equals '?' then it's followed by a space and a sequence of zeroes and onse, giving the pattern of length no more than 18.
It's guaranteed that there will be at least one query of type '?'.
It's guaranteed that any time some integer is removed from the multiset, there will be at least one occurrence of this integer in it.
Output
For each query of the third type print the number of integers matching the given pattern. Each integer is counted as many times, as it appears in the multiset at this moment of time.
Examples
Input
12
+ 1
+ 241
? 1
+ 361
- 241
? 0101
+ 101
? 101
- 101
? 101
+ 4000
? 0
Output
2
1
2
1
1
Input
4
+ 200
+ 200
- 200
? 0
Output
1
Note
Consider the integers matching the patterns from the queries of the third type. Queries are numbered in the order they appear in the input.
1. 1 and 241.
2. 361.
3. 101 and 361.
4. 361.
5. 4000.
Submitted Solution:
```
from collections import defaultdict
from sys import stdin
from sys import stdout
def main():
n = int(stdin.readline())
d = defaultdict(int)
for i in range(n):
s, x = stdin.readline().split()
y = ''.join(['1' if c in ['1', '3', '5', '7', '9'] else '0' for c in x]).zfill(18)
if s == '+': d[y] += 1
elif s == '-': d[y] -= 1
else: stdout.write(str(d[y]) + '\n')
if __name__ == '__main__':
main()
``` | instruction | 0 | 107,479 | 20 | 214,958 |
Yes | output | 1 | 107,479 | 20 | 214,959 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multiset with integers. Friends give her t queries, each of one of the following type:
1. + ai β add non-negative integer ai to the multiset. Note, that she has a multiset, thus there may be many occurrences of the same integer.
2. - ai β delete a single occurrence of non-negative integer ai from the multiset. It's guaranteed, that there is at least one ai in the multiset.
3. ? s β count the number of integers in the multiset (with repetitions) that match some pattern s consisting of 0 and 1. In the pattern, 0 stands for the even digits, while 1 stands for the odd. Integer x matches the pattern s, if the parity of the i-th from the right digit in decimal notation matches the i-th from the right digit of the pattern. If the pattern is shorter than this integer, it's supplemented with 0-s from the left. Similarly, if the integer is shorter than the pattern its decimal notation is supplemented with the 0-s from the left.
For example, if the pattern is s = 010, than integers 92, 2212, 50 and 414 match the pattern, while integers 3, 110, 25 and 1030 do not.
Input
The first line of the input contains an integer t (1 β€ t β€ 100 000) β the number of operation Sonya has to perform.
Next t lines provide the descriptions of the queries in order they appear in the input file. The i-th row starts with a character ci β the type of the corresponding operation. If ci is equal to '+' or '-' then it's followed by a space and an integer ai (0 β€ ai < 1018) given without leading zeroes (unless it's 0). If ci equals '?' then it's followed by a space and a sequence of zeroes and onse, giving the pattern of length no more than 18.
It's guaranteed that there will be at least one query of type '?'.
It's guaranteed that any time some integer is removed from the multiset, there will be at least one occurrence of this integer in it.
Output
For each query of the third type print the number of integers matching the given pattern. Each integer is counted as many times, as it appears in the multiset at this moment of time.
Examples
Input
12
+ 1
+ 241
? 1
+ 361
- 241
? 0101
+ 101
? 101
- 101
? 101
+ 4000
? 0
Output
2
1
2
1
1
Input
4
+ 200
+ 200
- 200
? 0
Output
1
Note
Consider the integers matching the patterns from the queries of the third type. Queries are numbered in the order they appear in the input.
1. 1 and 241.
2. 361.
3. 101 and 361.
4. 361.
5. 4000.
Submitted Solution:
```
from sys import stdin
input()
cnt=[0]*2**18
t=str.maketrans("0123456789","0101010101")
for ch,s in map(str.split,stdin):
if ch=='?' :
print(cnt[int(s,2)])
else :
cnt[int(s.translate(t),2)]+= (1 if ch=='+' else -1 )
# Made By Mostafa_Khaled
``` | instruction | 0 | 107,480 | 20 | 214,960 |
Yes | output | 1 | 107,480 | 20 | 214,961 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multiset with integers. Friends give her t queries, each of one of the following type:
1. + ai β add non-negative integer ai to the multiset. Note, that she has a multiset, thus there may be many occurrences of the same integer.
2. - ai β delete a single occurrence of non-negative integer ai from the multiset. It's guaranteed, that there is at least one ai in the multiset.
3. ? s β count the number of integers in the multiset (with repetitions) that match some pattern s consisting of 0 and 1. In the pattern, 0 stands for the even digits, while 1 stands for the odd. Integer x matches the pattern s, if the parity of the i-th from the right digit in decimal notation matches the i-th from the right digit of the pattern. If the pattern is shorter than this integer, it's supplemented with 0-s from the left. Similarly, if the integer is shorter than the pattern its decimal notation is supplemented with the 0-s from the left.
For example, if the pattern is s = 010, than integers 92, 2212, 50 and 414 match the pattern, while integers 3, 110, 25 and 1030 do not.
Input
The first line of the input contains an integer t (1 β€ t β€ 100 000) β the number of operation Sonya has to perform.
Next t lines provide the descriptions of the queries in order they appear in the input file. The i-th row starts with a character ci β the type of the corresponding operation. If ci is equal to '+' or '-' then it's followed by a space and an integer ai (0 β€ ai < 1018) given without leading zeroes (unless it's 0). If ci equals '?' then it's followed by a space and a sequence of zeroes and onse, giving the pattern of length no more than 18.
It's guaranteed that there will be at least one query of type '?'.
It's guaranteed that any time some integer is removed from the multiset, there will be at least one occurrence of this integer in it.
Output
For each query of the third type print the number of integers matching the given pattern. Each integer is counted as many times, as it appears in the multiset at this moment of time.
Examples
Input
12
+ 1
+ 241
? 1
+ 361
- 241
? 0101
+ 101
? 101
- 101
? 101
+ 4000
? 0
Output
2
1
2
1
1
Input
4
+ 200
+ 200
- 200
? 0
Output
1
Note
Consider the integers matching the patterns from the queries of the third type. Queries are numbered in the order they appear in the input.
1. 1 and 241.
2. 361.
3. 101 and 361.
4. 361.
5. 4000.
Submitted Solution:
```
import sys
from collections import Counter
from sys import stdin
input()
c = [0]*2**18
deg = [0]*18
for i in range(18):
deg[i] = 2**i
t=str.maketrans("0123456789","0101010101")
for ch,n in map(str.split,stdin):
if ch == '?':
print(c[int(n, 2)])
n = n.translate(t)
if ch == '+':
c[int(n,2)] += 1
if ch == '-':
c[int(n,2)] -= 1
``` | instruction | 0 | 107,481 | 20 | 214,962 |
Yes | output | 1 | 107,481 | 20 | 214,963 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multiset with integers. Friends give her t queries, each of one of the following type:
1. + ai β add non-negative integer ai to the multiset. Note, that she has a multiset, thus there may be many occurrences of the same integer.
2. - ai β delete a single occurrence of non-negative integer ai from the multiset. It's guaranteed, that there is at least one ai in the multiset.
3. ? s β count the number of integers in the multiset (with repetitions) that match some pattern s consisting of 0 and 1. In the pattern, 0 stands for the even digits, while 1 stands for the odd. Integer x matches the pattern s, if the parity of the i-th from the right digit in decimal notation matches the i-th from the right digit of the pattern. If the pattern is shorter than this integer, it's supplemented with 0-s from the left. Similarly, if the integer is shorter than the pattern its decimal notation is supplemented with the 0-s from the left.
For example, if the pattern is s = 010, than integers 92, 2212, 50 and 414 match the pattern, while integers 3, 110, 25 and 1030 do not.
Input
The first line of the input contains an integer t (1 β€ t β€ 100 000) β the number of operation Sonya has to perform.
Next t lines provide the descriptions of the queries in order they appear in the input file. The i-th row starts with a character ci β the type of the corresponding operation. If ci is equal to '+' or '-' then it's followed by a space and an integer ai (0 β€ ai < 1018) given without leading zeroes (unless it's 0). If ci equals '?' then it's followed by a space and a sequence of zeroes and onse, giving the pattern of length no more than 18.
It's guaranteed that there will be at least one query of type '?'.
It's guaranteed that any time some integer is removed from the multiset, there will be at least one occurrence of this integer in it.
Output
For each query of the third type print the number of integers matching the given pattern. Each integer is counted as many times, as it appears in the multiset at this moment of time.
Examples
Input
12
+ 1
+ 241
? 1
+ 361
- 241
? 0101
+ 101
? 101
- 101
? 101
+ 4000
? 0
Output
2
1
2
1
1
Input
4
+ 200
+ 200
- 200
? 0
Output
1
Note
Consider the integers matching the patterns from the queries of the third type. Queries are numbered in the order they appear in the input.
1. 1 and 241.
2. 361.
3. 101 and 361.
4. 361.
5. 4000.
Submitted Solution:
```
from __future__ import division, print_function
import sys
if sys.version_info[0] < 3:
from __builtin__ import xrange as range
from future_builtins import ascii, filter, hex, map, oct, zip
import os, sys, bisect, copy
from collections import defaultdict, Counter, deque
#from functools import lru_cache #use @lru_cache(None)
if os.path.exists('in.txt'): sys.stdin=open('in.txt','r')
if os.path.exists('out.txt'): sys.stdout=open('out.txt', 'w')
#
def input(): return sys.stdin.readline()
def mapi(arg=0): return map(int if arg==0 else str,input().split())
#------------------------------------------------------------------
mp = defaultdict(int)
def key(x):
res = 0
for i in range(len(x)):
res = 2*res+int(x[i])%2
return res
for _ in range(int(input())):
a = input().strip().split()
#print(*a)
if a[0]=="+":
mp[key(a[1])]+=1
#print(mp[a[1]])
elif a[0]=="-":
mp[key(a[1])]-=1
pass
else:
print(mp[key(a[1])])
``` | instruction | 0 | 107,482 | 20 | 214,964 |
Yes | output | 1 | 107,482 | 20 | 214,965 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multiset with integers. Friends give her t queries, each of one of the following type:
1. + ai β add non-negative integer ai to the multiset. Note, that she has a multiset, thus there may be many occurrences of the same integer.
2. - ai β delete a single occurrence of non-negative integer ai from the multiset. It's guaranteed, that there is at least one ai in the multiset.
3. ? s β count the number of integers in the multiset (with repetitions) that match some pattern s consisting of 0 and 1. In the pattern, 0 stands for the even digits, while 1 stands for the odd. Integer x matches the pattern s, if the parity of the i-th from the right digit in decimal notation matches the i-th from the right digit of the pattern. If the pattern is shorter than this integer, it's supplemented with 0-s from the left. Similarly, if the integer is shorter than the pattern its decimal notation is supplemented with the 0-s from the left.
For example, if the pattern is s = 010, than integers 92, 2212, 50 and 414 match the pattern, while integers 3, 110, 25 and 1030 do not.
Input
The first line of the input contains an integer t (1 β€ t β€ 100 000) β the number of operation Sonya has to perform.
Next t lines provide the descriptions of the queries in order they appear in the input file. The i-th row starts with a character ci β the type of the corresponding operation. If ci is equal to '+' or '-' then it's followed by a space and an integer ai (0 β€ ai < 1018) given without leading zeroes (unless it's 0). If ci equals '?' then it's followed by a space and a sequence of zeroes and onse, giving the pattern of length no more than 18.
It's guaranteed that there will be at least one query of type '?'.
It's guaranteed that any time some integer is removed from the multiset, there will be at least one occurrence of this integer in it.
Output
For each query of the third type print the number of integers matching the given pattern. Each integer is counted as many times, as it appears in the multiset at this moment of time.
Examples
Input
12
+ 1
+ 241
? 1
+ 361
- 241
? 0101
+ 101
? 101
- 101
? 101
+ 4000
? 0
Output
2
1
2
1
1
Input
4
+ 200
+ 200
- 200
? 0
Output
1
Note
Consider the integers matching the patterns from the queries of the third type. Queries are numbered in the order they appear in the input.
1. 1 and 241.
2. 361.
3. 101 and 361.
4. 361.
5. 4000.
Submitted Solution:
```
from sys import stdin, stdout
quests = int(stdin.readline().rstrip())
multi_set = {}
for i in range(quests):
quest, core = stdin.readline().rstrip().split()
pattern = ''
for i in core: pattern += str(int(i)%2)
if quest == '+':
if pattern in multi_set: multi_set[pattern] += 1
else: multi_set[pattern] = 1
elif quest == '-': multi_set[pattern] -= 1
else:
if pattern in multi_set: stdout.write(str(multi_set[pattern])+'\n')
else: stdout.write('0\n')
``` | instruction | 0 | 107,483 | 20 | 214,966 |
No | output | 1 | 107,483 | 20 | 214,967 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multiset with integers. Friends give her t queries, each of one of the following type:
1. + ai β add non-negative integer ai to the multiset. Note, that she has a multiset, thus there may be many occurrences of the same integer.
2. - ai β delete a single occurrence of non-negative integer ai from the multiset. It's guaranteed, that there is at least one ai in the multiset.
3. ? s β count the number of integers in the multiset (with repetitions) that match some pattern s consisting of 0 and 1. In the pattern, 0 stands for the even digits, while 1 stands for the odd. Integer x matches the pattern s, if the parity of the i-th from the right digit in decimal notation matches the i-th from the right digit of the pattern. If the pattern is shorter than this integer, it's supplemented with 0-s from the left. Similarly, if the integer is shorter than the pattern its decimal notation is supplemented with the 0-s from the left.
For example, if the pattern is s = 010, than integers 92, 2212, 50 and 414 match the pattern, while integers 3, 110, 25 and 1030 do not.
Input
The first line of the input contains an integer t (1 β€ t β€ 100 000) β the number of operation Sonya has to perform.
Next t lines provide the descriptions of the queries in order they appear in the input file. The i-th row starts with a character ci β the type of the corresponding operation. If ci is equal to '+' or '-' then it's followed by a space and an integer ai (0 β€ ai < 1018) given without leading zeroes (unless it's 0). If ci equals '?' then it's followed by a space and a sequence of zeroes and onse, giving the pattern of length no more than 18.
It's guaranteed that there will be at least one query of type '?'.
It's guaranteed that any time some integer is removed from the multiset, there will be at least one occurrence of this integer in it.
Output
For each query of the third type print the number of integers matching the given pattern. Each integer is counted as many times, as it appears in the multiset at this moment of time.
Examples
Input
12
+ 1
+ 241
? 1
+ 361
- 241
? 0101
+ 101
? 101
- 101
? 101
+ 4000
? 0
Output
2
1
2
1
1
Input
4
+ 200
+ 200
- 200
? 0
Output
1
Note
Consider the integers matching the patterns from the queries of the third type. Queries are numbered in the order they appear in the input.
1. 1 and 241.
2. 361.
3. 101 and 361.
4. 361.
5. 4000.
Submitted Solution:
```
t = int(input())
trantab = str.maketrans('0123456789', '0101010101')
a = {}
for i in range(t):
string = input()
oper = string[0]
number = string[2:]
if oper == '+':
a[number] = a.get(number, 0) + 1
elif oper == '-':
a[number] -= 1
else:
count = 0
for a_i in a:
max_length = max(len(number), len(a_i))
if a_i.translate(trantab).rjust(max_length, '0') == number.rjust(max_length, '0'):
count += 1
print(count)
``` | instruction | 0 | 107,484 | 20 | 214,968 |
No | output | 1 | 107,484 | 20 | 214,969 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multiset with integers. Friends give her t queries, each of one of the following type:
1. + ai β add non-negative integer ai to the multiset. Note, that she has a multiset, thus there may be many occurrences of the same integer.
2. - ai β delete a single occurrence of non-negative integer ai from the multiset. It's guaranteed, that there is at least one ai in the multiset.
3. ? s β count the number of integers in the multiset (with repetitions) that match some pattern s consisting of 0 and 1. In the pattern, 0 stands for the even digits, while 1 stands for the odd. Integer x matches the pattern s, if the parity of the i-th from the right digit in decimal notation matches the i-th from the right digit of the pattern. If the pattern is shorter than this integer, it's supplemented with 0-s from the left. Similarly, if the integer is shorter than the pattern its decimal notation is supplemented with the 0-s from the left.
For example, if the pattern is s = 010, than integers 92, 2212, 50 and 414 match the pattern, while integers 3, 110, 25 and 1030 do not.
Input
The first line of the input contains an integer t (1 β€ t β€ 100 000) β the number of operation Sonya has to perform.
Next t lines provide the descriptions of the queries in order they appear in the input file. The i-th row starts with a character ci β the type of the corresponding operation. If ci is equal to '+' or '-' then it's followed by a space and an integer ai (0 β€ ai < 1018) given without leading zeroes (unless it's 0). If ci equals '?' then it's followed by a space and a sequence of zeroes and onse, giving the pattern of length no more than 18.
It's guaranteed that there will be at least one query of type '?'.
It's guaranteed that any time some integer is removed from the multiset, there will be at least one occurrence of this integer in it.
Output
For each query of the third type print the number of integers matching the given pattern. Each integer is counted as many times, as it appears in the multiset at this moment of time.
Examples
Input
12
+ 1
+ 241
? 1
+ 361
- 241
? 0101
+ 101
? 101
- 101
? 101
+ 4000
? 0
Output
2
1
2
1
1
Input
4
+ 200
+ 200
- 200
? 0
Output
1
Note
Consider the integers matching the patterns from the queries of the third type. Queries are numbered in the order they appear in the input.
1. 1 and 241.
2. 361.
3. 101 and 361.
4. 361.
5. 4000.
Submitted Solution:
```
t = int(input())
a = []
for i in range(t):
string = input()
number = string[2:]
if string[0] == '+':
a.append(number)
elif string[0] == '-':
a.remove(number)
else:
count = 0
for a_i in a:
for i, j in zip(a_i[::-1], number[::-1]):
if not int(i) % 2 == int(j) % 2:
break
count += 1
print(count)
``` | instruction | 0 | 107,485 | 20 | 214,970 |
No | output | 1 | 107,485 | 20 | 214,971 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multiset with integers. Friends give her t queries, each of one of the following type:
1. + ai β add non-negative integer ai to the multiset. Note, that she has a multiset, thus there may be many occurrences of the same integer.
2. - ai β delete a single occurrence of non-negative integer ai from the multiset. It's guaranteed, that there is at least one ai in the multiset.
3. ? s β count the number of integers in the multiset (with repetitions) that match some pattern s consisting of 0 and 1. In the pattern, 0 stands for the even digits, while 1 stands for the odd. Integer x matches the pattern s, if the parity of the i-th from the right digit in decimal notation matches the i-th from the right digit of the pattern. If the pattern is shorter than this integer, it's supplemented with 0-s from the left. Similarly, if the integer is shorter than the pattern its decimal notation is supplemented with the 0-s from the left.
For example, if the pattern is s = 010, than integers 92, 2212, 50 and 414 match the pattern, while integers 3, 110, 25 and 1030 do not.
Input
The first line of the input contains an integer t (1 β€ t β€ 100 000) β the number of operation Sonya has to perform.
Next t lines provide the descriptions of the queries in order they appear in the input file. The i-th row starts with a character ci β the type of the corresponding operation. If ci is equal to '+' or '-' then it's followed by a space and an integer ai (0 β€ ai < 1018) given without leading zeroes (unless it's 0). If ci equals '?' then it's followed by a space and a sequence of zeroes and onse, giving the pattern of length no more than 18.
It's guaranteed that there will be at least one query of type '?'.
It's guaranteed that any time some integer is removed from the multiset, there will be at least one occurrence of this integer in it.
Output
For each query of the third type print the number of integers matching the given pattern. Each integer is counted as many times, as it appears in the multiset at this moment of time.
Examples
Input
12
+ 1
+ 241
? 1
+ 361
- 241
? 0101
+ 101
? 101
- 101
? 101
+ 4000
? 0
Output
2
1
2
1
1
Input
4
+ 200
+ 200
- 200
? 0
Output
1
Note
Consider the integers matching the patterns from the queries of the third type. Queries are numbered in the order they appear in the input.
1. 1 and 241.
2. 361.
3. 101 and 361.
4. 361.
5. 4000.
Submitted Solution:
```
import sys
from collections import Counter
t = int(input())
c = Counter()
for i in range(t):
ch, n = sys.stdin.readline().split()
n = list(n)
n.reverse()
val = 0
for i in range(len(n)):
if (ord(n[i])-ord('0')) % 2 == 0:
val = val * 2
else:
val = val * 2 + 1
if ch == '?':
print(c[val])
if ch == '+':
c[val] += 1
if ch == '-':
c[val] -= 1
``` | instruction | 0 | 107,486 | 20 | 214,972 |
No | output | 1 | 107,486 | 20 | 214,973 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Apart from having lots of holidays throughout the year, residents of Berland also have whole lucky years. Year is considered lucky if it has no more than 1 non-zero digit in its number. So years 100, 40000, 5 are lucky and 12, 3001 and 12345 are not.
You are given current year in Berland. Your task is to find how long will residents of Berland wait till the next lucky year.
Input
The first line contains integer number n (1 β€ n β€ 109) β current year in Berland.
Output
Output amount of years from the current year to the next lucky one.
Examples
Input
4
Output
1
Input
201
Output
99
Input
4000
Output
1000
Note
In the first example next lucky year is 5. In the second one β 300. In the third β 5000. | instruction | 0 | 108,319 | 20 | 216,638 |
Tags: implementation
Correct Solution:
```
from math import *
a=input()
if len(a)==1:
print("1")
exit(0)
elif len(a)-a.count("0")==1:
print(10**a.count("0"))
exit(0)
else:
b=len(a)-1
a=int(a)
c=a/(10**b)
c=ceil(c)
c*=(10**b)
print(c-a)
``` | output | 1 | 108,319 | 20 | 216,639 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.