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. Right now you are to solve a very, very simple problem — to crack the safe. Four positive integers stand one by one on a circle protecting the safe. You know that to unlock this striking safe you have to make all four numbers equal to one. Operations are as follows: you may choose two adjacent numbers and increase both by one; you may choose two adjacent even numbers and divide both by two. Nothing else. Crack the safe! Input The single line of the input contains four space-separated integer positive numbers not greater than 109 each — four numbers on the circle in consecutive order. Output The output should contain "-1" (quotes for clarity) if the safe is secure, that is it's impossible to crack it. Otherwise, output should contain the sequence of operations (one operations per line) leading to unlocking the safe. You don't have to minimize the number of operations, but it should not exceed 1000. To make things clear, assume numbers stand on positions 1 through 4. Each operation is encoded by two symbols. If the following operation is dividing then first symbol is '/'; otherwise it's '+' (addition). The second symbol is the position of the first number in pair in consecutive order. (see samples for clarification). If there are several solutions, output any of them. Examples Input 1 1 1 1 Output Input 1 2 4 2 Output /2 /3 Input 3 3 1 1 Output +1 /1 /1 Input 2 1 2 4 Output /3 /4 Submitted Solution: ``` from sys import stdin input = stdin.buffer.readline ans = '' def f(a, b, c): global ans if (a & 1) & (b & 1) and a != b: ans += f'+{c}\n' a += 1 b += 1 while (a & 1 ^ 1) & (b & 1 ^ 1): ans += f'/{c}\n' a >>= 1 b >>= 1 return a, b a, b, c, d = map(int, input().split()) while a + b + c + d >= 6: a, b = f(a, b, 1) b, c = f(b, c, 2) c, d = f(c, d, 3) d, a = f(d, a, 4) if a == b == c == d == 1: print(ans) else: print(-1) ```
instruction
0
50,861
20
101,722
No
output
1
50,861
20
101,723
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
50,958
20
101,916
Tags: data structures, implementation Correct Solution: ``` from sys import stdin d,res,elem={},'','0101010101' for _ in range(int(stdin.readline())): c,x=map(str,stdin.readline().split()) if c!='?': x=[*x] x=[elem[int(y)] for i,y in enumerate(x)] x=''.join(x) x=x[x.find('1'):] if c=='+': if d.get(x)==None:d[x]=0 d[x]+=1 elif c=='-':d[x]-=1 else: if d.get(x)==None:res+='0'+'\n' else:res+=str(d[x])+'\n' print(res) ```
output
1
50,958
20
101,917
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
50,959
20
101,918
Tags: data structures, implementation Correct Solution: ``` import math,sys,bisect,heapq from collections import defaultdict,Counter,deque from itertools import groupby,accumulate #sys.setrecursionlimit(200000000) int1 = lambda x: int(x) - 1 input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__ ilele = lambda: map(int,input().split()) alele = lambda: list(map(int, input().split())) ilelec = lambda: map(int1,input().split()) alelec = lambda: list(map(int1, input().split())) def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] #MOD = 1000000000 + 7 def Y(c): print(["NO","YES"][c]) def y(c): print(["no","yes"][c]) def Yy(c): print(["No","Yes"][c]) class Tree: def __init__(self): self.children = ['0']*2 self.count = 0 class Main: def __init__(self): self.root = self.getNode() def getNode(self): return Tree() def insert(self,s): head = self.root n = len(s) for i in range(n): x = int(s[i]) % 2 if head.children[x] == '0': head.children[x] = self.getNode() head = head.children[x] head.count += 1 def fun(self,s): head = self.root n = len(s) c = 0 for i in range(n): x = int(s[i]) % 2 if head.children[x] == '0': return c head = head.children[x] if head.count >= 1: if all(int(j)%2 == 0 for j in s[i+1:]): c += head.count x = 0 while head.children[x] != '0': head = head.children[x] c += head.count return c def remove(self,s): head = self.root n = len(s) for i in range(n): x = int(s[i]) % 2 if head.children[x] == '0': head.children[x] = self.getNode() head = head.children[x] head.count -= 1 head.isEnd = False t = Main() N = int(input()) for i in range(N): S = input() if S[0] == '+': a = S[1:][::-1].strip() t.insert(a) elif S[0] == "-": a = S[1:][::-1].strip() t.remove(a) else: a = S[1:][::-1].strip() print(t.fun(a)) ```
output
1
50,959
20
101,919
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
50,960
20
101,920
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
50,960
20
101,921
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
50,961
20
101,922
Tags: data structures, implementation Correct Solution: ``` t=int(input()) T=str.maketrans('0123456789','0101010101') d={} for _ in ' '*t: a,b=input().split() b=int(b.translate(T)) if a=='?':print(d.get(b,0)) elif a=='+':d[b]=d.get(b,0)+1 else:d[b]-=1 ```
output
1
50,961
20
101,923
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
50,962
20
101,924
Tags: data structures, implementation Correct Solution: ``` import sys def solve(): d = dict() n = int(sys.stdin.readline().strip()) ans = "" for line in sys.stdin: op, i = line.strip().split(' ') m = ''.join(['1' if char in ['1', '3', '5', '7', '9'] else '0' for char in i]).zfill(18) 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
50,962
20
101,925
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
50,963
20
101,926
Tags: data structures, implementation Correct Solution: ``` from sys import * #def mask(a): # res1='' # while a>0: # p=(a%10)%2 # res1+=str(p) # a//=10 # res1+='0'*(18-len(res1)) # return res1[::-1] odd=set(["1","9","3","5","7"]) def mask(a): res="0"*(18-len(a)) for i in a: if i in odd: res+="1" else: res+="0" return res di=dict() t=int(stdin.readline()) for i in range(t): s=stdin.readline().split() if s[0]=='+': w=mask(s[1]) if di.get(w,-1)==-1: di[w]=1 else: di[w]+=1 if s[0]=='-': w=mask(s[1]) di[w]-=1 if s[0]=='?': w=mask(s[1]) if di.get(w,-1)==-1: print('0') else: print(di[w]) ```
output
1
50,963
20
101,927
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
50,964
20
101,928
Tags: data structures, implementation Correct Solution: ``` from sys import stdin d,res,elem={},'','0101010101' a=lambda:stdin.readline().split() for _ in range(int(stdin.readline())): c,x=map(str,a()) if c!='?': x=[*x] x=[elem[int(y)] for i,y in enumerate(x)] x=''.join(x) x=x[x.find('1'):] if c=='+': if d.get(x)==None:d[x]=0 d[x]+=1 elif c=='-':d[x]-=1 else: if d.get(x)==None:res+='0'+'\n' else:res+=str(d[x])+'\n' print(res) ```
output
1
50,964
20
101,929
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
50,965
20
101,930
Tags: data structures, implementation Correct Solution: ``` from sys import stdin, stdout from collections import defaultdict input() d = defaultdict(int) regex = str.maketrans("0123456789","0101010101") for line in stdin.readlines(): typ, val = line.split() if typ == "?": print(d[int(val,2)]) else: val = int(val.translate(regex), 2) if typ == "+": d[val]+=1 else: d[val]-=1 ```
output
1
50,965
20
101,931
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
50,966
20
101,932
Yes
output
1
50,966
20
101,933
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: ``` 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)]) ```
instruction
0
50,967
20
101,934
Yes
output
1
50,967
20
101,935
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, os, io from sys import stdin, stdout # input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def binaryToDecimal(n): num = n; dec_value = 0; base1 = 1; len1 = len(num); for i in range(len1 - 1, -1, -1): if (num[i] == '1'): dec_value += base1; base1 = base1 * 2; return dec_value; def convert(n): ss = [] for i in n: ss.append(str(int(i)&1)) return binaryToDecimal(ss) t = stdin.readline() # print(t) d = {} ab = [0]*(262145) for _ in range(int(t)): a, b = map(str, sys.stdin.readline().strip().split()) if(a == "+"): c = convert(b) ab[c]+=1 b = int(b) if(b not in d): d[b] = 0 d[b]+=1 elif(a == '-'): c = convert(b) ab[c]-=1 b = int(b) if(d[b] == 1): d.pop(b) else: d[b]-=1 else: b = binaryToDecimal(b) print(ab[b]) ```
instruction
0
50,968
20
101,936
Yes
output
1
50,968
20
101,937
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: ``` n = int(input()) d = {} def get_mask(num): res = '' for el in num: if (int(el) & 1): res += '1' else: res += '0' return '0' * (18 - len(num)) + res for _ in range(n): c, v = input().split(' ') if c == '?': v = '0' * (18 - len(v)) + v if v in d.keys(): print(d[v]) else: print(0) elif c == '+': v = get_mask(v) if v in d.keys(): d[v] += 1 else: d[v] = 1 else: v = get_mask(v) d[v] -= 1 ```
instruction
0
50,969
20
101,938
Yes
output
1
50,969
20
101,939
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: ``` # -*- coding: utf-8 -*- """ Created on Tue Sep 13 13:18:00 2016 @author: Felicia """ def match(ele,num): l1 = len(ele) l2 = len(num) l = max(l1,l2) if l1>l2: num = '0'*(l1-l2)+num elif l1<l2: ele = '0'*(l2-l1)+ele flag = True for i in range(l): if num[i]=='0': if ele[i] not in {'0','2','4','6','8'}: flag = False break elif num =='1': if ele[i] not in {'1','3','5','7','9'}: flag = False break return flag def comp(s,num): count = 0 for i in s: if match(i,num): count +=1 return count if __name__ == "__main__": n = int(input()) s = [] for i in range(n): c, num = input().split() if c == '+': s.append(num) elif c == '-': s.remove(num) else: print(comp(s,num)) ```
instruction
0
50,970
20
101,940
No
output
1
50,970
20
101,941
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: ``` inputList={} inputNum = int(input()) #print (inputNum) #iterate n times and do changes in each iteration for x in range(0,inputNum): inputStr=str(input()) firstValue = inputStr.split(' ')[0] secondValue = inputStr.split(' ')[1] # + case if firstValue=='+': plusVal = secondValue if plusVal in inputList: inputList[plusVal]+=1 else: inputList[plusVal]=1 # - case if firstValue=='-': minusVal = secondValue inputList[minusVal]-=1 # ? case if firstValue=='?': patStringVal = secondValue #print (patString) count=0 for x in inputList: patString = patStringVal if inputList[x]==0: continue else: strVal = str(x) ls=list() for digit in strVal: intVal = int(digit) if intVal%2==0: ls.append('0') else: ls.append('1') value=''.join(ls) diff = len(value)-len(patString) padValue =abs(diff) value1=value patString1=patString if diff < 0: padValue = padValue+len(value) value1 = value.zfill(padValue) elif diff > 0: padValue = padValue+len(patString) patString1 = patString.zfill(padValue) if patString1==value1: count+=inputList[x] print(value1) print(count) #print(inputList) '''for x in inputList: print('{}, {}', x, inputList[x])''' ```
instruction
0
50,971
20
101,942
No
output
1
50,971
20
101,943
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: ``` class trie: def __init__(self): self.nodes1,self.nodes2 = None,None self.count1,self.count2 = 0,0 def add(self,s,i): if i>=len(s): return md = int(s[i])%2 if md==0: if not self.nodes1: self.nodes1 = trie() self.count1 += 1 self.nodes1.add(s,i+1) else: if not self.nodes2: self.nodes2 = trie() self.count2 += 1 self.nodes2.add(s,i+1) def remove(self,s,i): if i>=len(s): return md = int(s[i])%2 if md==0: self.count1 -= 1 self.nodes1.remove(s,i+1) if self.count1==0: self.nodes1 = None else: self.count2 -= 1 self.nodes2.remove(s,i+1) if self.count2==0: self.nodes2 = None def search(self,s,i,mn): if i>=len(s): return mn md = int(s[i])%2 if md==0: if self.nodes1: return self.nodes1.search(s,i+1,min(mn,self.count1)) else: return 0 else: if self.nodes2: return self.nodes2.search(s,i+1,min(mn,self.count2)) else: return 0 t = int(input()) # tr = trie() from collections import defaultdict mp = defaultdict(int) while t>0: t-=1 c,s = input().split() # s = s.zfill(18) if c=='+': ss = [str(int(i)%2) for i in s] ss = ''.join(ss) mp[int(ss,2)]+=1 # tr.add(s,0) elif c=='-': ss = [str(int(i)%2) for i in s] ss = ''.join(ss) mp[int(ss,2)]-=1 # tr.remove(s,0) elif c=='?': # v = tr.search(s,0,10**6) # print(v) print(mp[int(ss,2)]) ```
instruction
0
50,972
20
101,944
No
output
1
50,972
20
101,945
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: ``` def match(n,s): for i in s[::-1]: if (i=='0' and (n%10)%2==0) or (i=='1' and (n%10)%2==1): n=n//10 else: return 0 return 1 t=int(input().strip()) c={} for __ in range(t): q=input().strip().split() if q[0]=='+': n=int(q[1]) if n in c: c[n]+=1 else: c[n]=1 elif q[0]=='-': n=int(q[1]) if c[n]==1: del c[n] else: c[n]-=1 else: ans=0 for i in c.keys(): ans+=(c[i]*match(i,q[1])) print(ans) ```
instruction
0
50,973
20
101,946
No
output
1
50,973
20
101,947
Provide tags and a correct Python 3 solution for this coding contest problem. — Thanks a lot for today. — I experienced so many great things. — You gave me memories like dreams... But I have to leave now... — One last request, can you... — Help me solve a Codeforces problem? — ...... — What? Chtholly has been thinking about a problem for days: If a number is palindrome and length of its decimal representation without leading zeros is even, we call it a zcy number. A number is palindrome means when written in decimal representation, it contains no leading zeros and reads the same forwards and backwards. For example 12321 and 1221 are palindromes and 123 and 12451 are not. Moreover, 1221 is zcy number and 12321 is not. Given integers k and p, calculate the sum of the k smallest zcy numbers and output this sum modulo p. Unfortunately, Willem isn't good at solving this kind of problems, so he asks you for help! Input The first line contains two integers k and p (1 ≤ k ≤ 105, 1 ≤ p ≤ 109). Output Output single integer — answer to the problem. Examples Input 2 100 Output 33 Input 5 30 Output 15 Note In the first example, the smallest zcy number is 11, and the second smallest zcy number is 22. In the second example, <image>.
instruction
0
51,016
20
102,032
Tags: brute force Correct Solution: ``` k, p = map(int, input().split()) numDigits = 2 n = 0 first = list("11") def Next(cur): for i in range(len(cur)//2, len(cur)): while (int(cur[i]) < 9): cur[i] = chr(ord(cur[i])+1) cur[-i-1] = cur[i] yield cur yield Next(cur) cur[i] = "0" cur[-i-1] = "0" cur.insert(0, "1") cur.append("1") cur[1:] = ["0"] * (len(cur)-1) cur[-1] = "1" yield cur yield Next(cur) a = Next(first) Sum = 11 for i in range(k-1): Sum += int("".join(next(a))) a = next(a) print (Sum%p) ```
output
1
51,016
20
102,033
Provide tags and a correct Python 3 solution for this coding contest problem. — Thanks a lot for today. — I experienced so many great things. — You gave me memories like dreams... But I have to leave now... — One last request, can you... — Help me solve a Codeforces problem? — ...... — What? Chtholly has been thinking about a problem for days: If a number is palindrome and length of its decimal representation without leading zeros is even, we call it a zcy number. A number is palindrome means when written in decimal representation, it contains no leading zeros and reads the same forwards and backwards. For example 12321 and 1221 are palindromes and 123 and 12451 are not. Moreover, 1221 is zcy number and 12321 is not. Given integers k and p, calculate the sum of the k smallest zcy numbers and output this sum modulo p. Unfortunately, Willem isn't good at solving this kind of problems, so he asks you for help! Input The first line contains two integers k and p (1 ≤ k ≤ 105, 1 ≤ p ≤ 109). Output Output single integer — answer to the problem. Examples Input 2 100 Output 33 Input 5 30 Output 15 Note In the first example, the smallest zcy number is 11, and the second smallest zcy number is 22. In the second example, <image>.
instruction
0
51,017
20
102,034
Tags: brute force Correct Solution: ``` import time start=time.time() l=[11,22,33,44,55,66,77,88,99] for i in range(1,10): for j in range(0,10): s=str(i)+str(j)+str(j)+str(i) num=int(s) l.append(num) for i in range(1,10): for j in range(0,10): for k in range(0,10): s=str(i)+str(j)+str(k)+str(k)+str(j)+str(i) num=int(s) l.append(num) for i in range(1,10): for j in range(0,10): for k in range(0,10): for m in range(0,10): s=str(i)+str(j)+str(k)+str(m)+str(m)+str(k)+str(j)+str(i) num=int(s) l.append(num) for i in range(1,10): for j in range(0,10): for k in range(0,10): for m in range(0,10): for n in range(0,10): s=str(i)+str(j)+str(k)+str(m)+str(n)+str(n)+str(m)+str(k)+str(j)+str(i) num=int(s) l.append(num) l.append(100000000001) k,p=list(map(int,input().split())) ans=sum(l[:k]) print(ans%p) ```
output
1
51,017
20
102,035
Provide tags and a correct Python 3 solution for this coding contest problem. — Thanks a lot for today. — I experienced so many great things. — You gave me memories like dreams... But I have to leave now... — One last request, can you... — Help me solve a Codeforces problem? — ...... — What? Chtholly has been thinking about a problem for days: If a number is palindrome and length of its decimal representation without leading zeros is even, we call it a zcy number. A number is palindrome means when written in decimal representation, it contains no leading zeros and reads the same forwards and backwards. For example 12321 and 1221 are palindromes and 123 and 12451 are not. Moreover, 1221 is zcy number and 12321 is not. Given integers k and p, calculate the sum of the k smallest zcy numbers and output this sum modulo p. Unfortunately, Willem isn't good at solving this kind of problems, so he asks you for help! Input The first line contains two integers k and p (1 ≤ k ≤ 105, 1 ≤ p ≤ 109). Output Output single integer — answer to the problem. Examples Input 2 100 Output 33 Input 5 30 Output 15 Note In the first example, the smallest zcy number is 11, and the second smallest zcy number is 22. In the second example, <image>.
instruction
0
51,018
20
102,036
Tags: brute force Correct Solution: ``` input1 = input("").split(" ") k = int(input1[0]) p = int(input1[1]) sumNumbers = 0 for i in range(1,k+1,1): num = int(str(i) + str(i)[::-1]) sumNumbers += num print(sumNumbers % p) ```
output
1
51,018
20
102,037
Provide tags and a correct Python 3 solution for this coding contest problem. — Thanks a lot for today. — I experienced so many great things. — You gave me memories like dreams... But I have to leave now... — One last request, can you... — Help me solve a Codeforces problem? — ...... — What? Chtholly has been thinking about a problem for days: If a number is palindrome and length of its decimal representation without leading zeros is even, we call it a zcy number. A number is palindrome means when written in decimal representation, it contains no leading zeros and reads the same forwards and backwards. For example 12321 and 1221 are palindromes and 123 and 12451 are not. Moreover, 1221 is zcy number and 12321 is not. Given integers k and p, calculate the sum of the k smallest zcy numbers and output this sum modulo p. Unfortunately, Willem isn't good at solving this kind of problems, so he asks you for help! Input The first line contains two integers k and p (1 ≤ k ≤ 105, 1 ≤ p ≤ 109). Output Output single integer — answer to the problem. Examples Input 2 100 Output 33 Input 5 30 Output 15 Note In the first example, the smallest zcy number is 11, and the second smallest zcy number is 22. In the second example, <image>.
instruction
0
51,019
20
102,038
Tags: brute force Correct Solution: ``` lf=[11,22,33,44,55,66,77,88,99] for i in range(1,5): lili=[int(str(i)+str(i)[::-1]) for i in range(10**(i),10**(i+1))] lf+=lili lf+=[10000000001] a,b=input().split() a=int(a) b=int(b) print(sum(lf[:a])%b) ```
output
1
51,019
20
102,039
Provide tags and a correct Python 3 solution for this coding contest problem. — Thanks a lot for today. — I experienced so many great things. — You gave me memories like dreams... But I have to leave now... — One last request, can you... — Help me solve a Codeforces problem? — ...... — What? Chtholly has been thinking about a problem for days: If a number is palindrome and length of its decimal representation without leading zeros is even, we call it a zcy number. A number is palindrome means when written in decimal representation, it contains no leading zeros and reads the same forwards and backwards. For example 12321 and 1221 are palindromes and 123 and 12451 are not. Moreover, 1221 is zcy number and 12321 is not. Given integers k and p, calculate the sum of the k smallest zcy numbers and output this sum modulo p. Unfortunately, Willem isn't good at solving this kind of problems, so he asks you for help! Input The first line contains two integers k and p (1 ≤ k ≤ 105, 1 ≤ p ≤ 109). Output Output single integer — answer to the problem. Examples Input 2 100 Output 33 Input 5 30 Output 15 Note In the first example, the smallest zcy number is 11, and the second smallest zcy number is 22. In the second example, <image>.
instruction
0
51,020
20
102,040
Tags: brute force Correct Solution: ``` a_b=input().split() a=int(a_b[0]) b=int(a_b[1]) sum=0 s=0 if a<=9: for i in range(1,a+1): s+=int(str(i)+str(i)) print(s%b) elif a<=99: sum=9 s=495 for i in range(1,10): for k in range(10): sum+=1 s+=int(str(i)+str(k)+str(k)+str(i)) if sum==a: print(s%b) break elif a<=999: sum=99 s=495495 for i in range(1,10): for k in range(10): for j in range(10): sum+=1 s+=int(str(i)+str(k)+str(j)+str(j)+str(k)+str(i)) if sum==a: print(s%b) break elif a<=9999: sum=999 s=495495495 for i in range(1, 10): for k in range(10): for j in range(10): for l in range(10): sum+=1 s += int(str(i) + str(k) + str(j) +str(l)+str(l)+ str(j) + str(k) + str(i)) if sum == a: print(s % b) break elif a <= 99999: sum = 9999 s=495495495495 for i in range(1, 10): for k in range(10): for j in range(10): for l in range(10): for m in range(10): sum += 1 s += int(str(i) + str(k) + str(j) + str(l) +str(m)+str(m)+ str(l) + str(j) + str(k) + str(i)) if sum == a: print(s % b) break elif a==100000 and b>a: print(495495496) elif a==100000: print(495495496%b) elif a <= 999999: sum = 99999 s=495495495495495 for i in range(1, 10): for k in range(10): for j in range(10): for l in range(10): for m in range(10): for n in range(10): sum += 1 s += int(str(i) + str(k) + str(j) + str(l) +str(m)+str(n)+str(n)+str(m)+ str(l) + str(j) + str(k) + str(i)) if sum == a: print(s % b) break ```
output
1
51,020
20
102,041
Provide tags and a correct Python 3 solution for this coding contest problem. — Thanks a lot for today. — I experienced so many great things. — You gave me memories like dreams... But I have to leave now... — One last request, can you... — Help me solve a Codeforces problem? — ...... — What? Chtholly has been thinking about a problem for days: If a number is palindrome and length of its decimal representation without leading zeros is even, we call it a zcy number. A number is palindrome means when written in decimal representation, it contains no leading zeros and reads the same forwards and backwards. For example 12321 and 1221 are palindromes and 123 and 12451 are not. Moreover, 1221 is zcy number and 12321 is not. Given integers k and p, calculate the sum of the k smallest zcy numbers and output this sum modulo p. Unfortunately, Willem isn't good at solving this kind of problems, so he asks you for help! Input The first line contains two integers k and p (1 ≤ k ≤ 105, 1 ≤ p ≤ 109). Output Output single integer — answer to the problem. Examples Input 2 100 Output 33 Input 5 30 Output 15 Note In the first example, the smallest zcy number is 11, and the second smallest zcy number is 22. In the second example, <image>.
instruction
0
51,021
20
102,042
Tags: brute force Correct Solution: ``` k,p = map(int,input().split()) i = 1 l = [] n = k while k!=0: s = "" s = str(i) s += s[::-1] l.append(s) i+=1 k-=1 ans = 0 for i in range(0,n): ans += int(l[i]) print(ans%p) ```
output
1
51,021
20
102,043
Provide tags and a correct Python 3 solution for this coding contest problem. — Thanks a lot for today. — I experienced so many great things. — You gave me memories like dreams... But I have to leave now... — One last request, can you... — Help me solve a Codeforces problem? — ...... — What? Chtholly has been thinking about a problem for days: If a number is palindrome and length of its decimal representation without leading zeros is even, we call it a zcy number. A number is palindrome means when written in decimal representation, it contains no leading zeros and reads the same forwards and backwards. For example 12321 and 1221 are palindromes and 123 and 12451 are not. Moreover, 1221 is zcy number and 12321 is not. Given integers k and p, calculate the sum of the k smallest zcy numbers and output this sum modulo p. Unfortunately, Willem isn't good at solving this kind of problems, so he asks you for help! Input The first line contains two integers k and p (1 ≤ k ≤ 105, 1 ≤ p ≤ 109). Output Output single integer — answer to the problem. Examples Input 2 100 Output 33 Input 5 30 Output 15 Note In the first example, the smallest zcy number is 11, and the second smallest zcy number is 22. In the second example, <image>.
instruction
0
51,022
20
102,044
Tags: brute force Correct Solution: ``` k,p=map(int,input().split()) x=0 import math for i in range(1,k+1): x+=int(str(i)+str(i)[::-1]) print(x%p) ```
output
1
51,022
20
102,045
Provide tags and a correct Python 3 solution for this coding contest problem. — Thanks a lot for today. — I experienced so many great things. — You gave me memories like dreams... But I have to leave now... — One last request, can you... — Help me solve a Codeforces problem? — ...... — What? Chtholly has been thinking about a problem for days: If a number is palindrome and length of its decimal representation without leading zeros is even, we call it a zcy number. A number is palindrome means when written in decimal representation, it contains no leading zeros and reads the same forwards and backwards. For example 12321 and 1221 are palindromes and 123 and 12451 are not. Moreover, 1221 is zcy number and 12321 is not. Given integers k and p, calculate the sum of the k smallest zcy numbers and output this sum modulo p. Unfortunately, Willem isn't good at solving this kind of problems, so he asks you for help! Input The first line contains two integers k and p (1 ≤ k ≤ 105, 1 ≤ p ≤ 109). Output Output single integer — answer to the problem. Examples Input 2 100 Output 33 Input 5 30 Output 15 Note In the first example, the smallest zcy number is 11, and the second smallest zcy number is 22. In the second example, <image>.
instruction
0
51,023
20
102,046
Tags: brute force Correct Solution: ``` maxk = 100001 n = 1 zcy = [] while len(zcy) <= maxk: zcy.append(int(str(n) + str(n)[::-1])) n += 1 s = input().strip().split() k = int(s[0]) p = int(s[1]) ans = 0 for i in range(k): ans = (ans + zcy[i]) % p print(ans) ```
output
1
51,023
20
102,047
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. — Thanks a lot for today. — I experienced so many great things. — You gave me memories like dreams... But I have to leave now... — One last request, can you... — Help me solve a Codeforces problem? — ...... — What? Chtholly has been thinking about a problem for days: If a number is palindrome and length of its decimal representation without leading zeros is even, we call it a zcy number. A number is palindrome means when written in decimal representation, it contains no leading zeros and reads the same forwards and backwards. For example 12321 and 1221 are palindromes and 123 and 12451 are not. Moreover, 1221 is zcy number and 12321 is not. Given integers k and p, calculate the sum of the k smallest zcy numbers and output this sum modulo p. Unfortunately, Willem isn't good at solving this kind of problems, so he asks you for help! Input The first line contains two integers k and p (1 ≤ k ≤ 105, 1 ≤ p ≤ 109). Output Output single integer — answer to the problem. Examples Input 2 100 Output 33 Input 5 30 Output 15 Note In the first example, the smallest zcy number is 11, and the second smallest zcy number is 22. In the second example, <image>. Submitted Solution: ``` n,m = map(int, input().split()) sum = 0 for i in range(n): sum += int(str(i+1)+str(i+1)[::-1]) print(sum % m) ```
instruction
0
51,024
20
102,048
Yes
output
1
51,024
20
102,049
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. — Thanks a lot for today. — I experienced so many great things. — You gave me memories like dreams... But I have to leave now... — One last request, can you... — Help me solve a Codeforces problem? — ...... — What? Chtholly has been thinking about a problem for days: If a number is palindrome and length of its decimal representation without leading zeros is even, we call it a zcy number. A number is palindrome means when written in decimal representation, it contains no leading zeros and reads the same forwards and backwards. For example 12321 and 1221 are palindromes and 123 and 12451 are not. Moreover, 1221 is zcy number and 12321 is not. Given integers k and p, calculate the sum of the k smallest zcy numbers and output this sum modulo p. Unfortunately, Willem isn't good at solving this kind of problems, so he asks you for help! Input The first line contains two integers k and p (1 ≤ k ≤ 105, 1 ≤ p ≤ 109). Output Output single integer — answer to the problem. Examples Input 2 100 Output 33 Input 5 30 Output 15 Note In the first example, the smallest zcy number is 11, and the second smallest zcy number is 22. In the second example, <image>. Submitted Solution: ``` import sys sys.setrecursionlimit(100000000) # def input(): return sys.stdin.readline()[:-1] def iin(): return int(input()) def impin(): return map(int, input().split()) def irrin(): return [int(x) for x in input().split()] def imrin(n): return [int(input()) for _ in range(n)] s = 0 k, p = impin() for i in range(1, k+1): s = (s+i*10**len(str(i))+int(str(i)[::-1]))%p print(s) ```
instruction
0
51,025
20
102,050
Yes
output
1
51,025
20
102,051
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. — Thanks a lot for today. — I experienced so many great things. — You gave me memories like dreams... But I have to leave now... — One last request, can you... — Help me solve a Codeforces problem? — ...... — What? Chtholly has been thinking about a problem for days: If a number is palindrome and length of its decimal representation without leading zeros is even, we call it a zcy number. A number is palindrome means when written in decimal representation, it contains no leading zeros and reads the same forwards and backwards. For example 12321 and 1221 are palindromes and 123 and 12451 are not. Moreover, 1221 is zcy number and 12321 is not. Given integers k and p, calculate the sum of the k smallest zcy numbers and output this sum modulo p. Unfortunately, Willem isn't good at solving this kind of problems, so he asks you for help! Input The first line contains two integers k and p (1 ≤ k ≤ 105, 1 ≤ p ≤ 109). Output Output single integer — answer to the problem. Examples Input 2 100 Output 33 Input 5 30 Output 15 Note In the first example, the smallest zcy number is 11, and the second smallest zcy number is 22. In the second example, <image>. Submitted Solution: ``` k, p = map(int, input().split()) s = 0 for i in range(k): zcy = str(1 + i) zcy += zcy[::-1] s += int(zcy) print(s%p) ```
instruction
0
51,026
20
102,052
Yes
output
1
51,026
20
102,053
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. — Thanks a lot for today. — I experienced so many great things. — You gave me memories like dreams... But I have to leave now... — One last request, can you... — Help me solve a Codeforces problem? — ...... — What? Chtholly has been thinking about a problem for days: If a number is palindrome and length of its decimal representation without leading zeros is even, we call it a zcy number. A number is palindrome means when written in decimal representation, it contains no leading zeros and reads the same forwards and backwards. For example 12321 and 1221 are palindromes and 123 and 12451 are not. Moreover, 1221 is zcy number and 12321 is not. Given integers k and p, calculate the sum of the k smallest zcy numbers and output this sum modulo p. Unfortunately, Willem isn't good at solving this kind of problems, so he asks you for help! Input The first line contains two integers k and p (1 ≤ k ≤ 105, 1 ≤ p ≤ 109). Output Output single integer — answer to the problem. Examples Input 2 100 Output 33 Input 5 30 Output 15 Note In the first example, the smallest zcy number is 11, and the second smallest zcy number is 22. In the second example, <image>. Submitted Solution: ``` k, p = [int(i) for i in input().split()] ans = 0 for i in range(1,k+1): tmp = str(i) n = len(tmp) rev = tmp[::-1] ans += (i * 10**(n) + int(rev)) % p print(ans % p) ```
instruction
0
51,027
20
102,054
Yes
output
1
51,027
20
102,055
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. — Thanks a lot for today. — I experienced so many great things. — You gave me memories like dreams... But I have to leave now... — One last request, can you... — Help me solve a Codeforces problem? — ...... — What? Chtholly has been thinking about a problem for days: If a number is palindrome and length of its decimal representation without leading zeros is even, we call it a zcy number. A number is palindrome means when written in decimal representation, it contains no leading zeros and reads the same forwards and backwards. For example 12321 and 1221 are palindromes and 123 and 12451 are not. Moreover, 1221 is zcy number and 12321 is not. Given integers k and p, calculate the sum of the k smallest zcy numbers and output this sum modulo p. Unfortunately, Willem isn't good at solving this kind of problems, so he asks you for help! Input The first line contains two integers k and p (1 ≤ k ≤ 105, 1 ≤ p ≤ 109). Output Output single integer — answer to the problem. Examples Input 2 100 Output 33 Input 5 30 Output 15 Note In the first example, the smallest zcy number is 11, and the second smallest zcy number is 22. In the second example, <image>. Submitted Solution: ``` def reverse(n): l0 = [] n0 = n for i in range(0,len(str(n))): l0.append(int(n)%10) n = int(n) - int(n)%10 n = int(n / 10) b = 0 for j in range(0,len(str(n0))): b = b + (int(l0[j]))*(10**(len(str(n0))-j-1)) return b def summon(n): l = [] a = 0 for i in range(1,n+1): a = i * (10 ** len(str(i)) )+ reverse(i) l.append(a) return l k,p = map(int,input().split()) l = [] l = summon(k) print(l) ini = 0 for q in range(k): ini = ini + l[q] print(ini) print(ini % p) ```
instruction
0
51,028
20
102,056
No
output
1
51,028
20
102,057
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. — Thanks a lot for today. — I experienced so many great things. — You gave me memories like dreams... But I have to leave now... — One last request, can you... — Help me solve a Codeforces problem? — ...... — What? Chtholly has been thinking about a problem for days: If a number is palindrome and length of its decimal representation without leading zeros is even, we call it a zcy number. A number is palindrome means when written in decimal representation, it contains no leading zeros and reads the same forwards and backwards. For example 12321 and 1221 are palindromes and 123 and 12451 are not. Moreover, 1221 is zcy number and 12321 is not. Given integers k and p, calculate the sum of the k smallest zcy numbers and output this sum modulo p. Unfortunately, Willem isn't good at solving this kind of problems, so he asks you for help! Input The first line contains two integers k and p (1 ≤ k ≤ 105, 1 ≤ p ≤ 109). Output Output single integer — answer to the problem. Examples Input 2 100 Output 33 Input 5 30 Output 15 Note In the first example, the smallest zcy number is 11, and the second smallest zcy number is 22. In the second example, <image>. Submitted Solution: ``` def modificar(a): c = [int(i) for i in a] tam = len(a)//2 esquerda = tam-1 direita = tam while esquerda!=-1: c[esquerda]+=1 c[direita]+=1 if c[esquerda] >= 10 and esquerda != 0: c[esquerda] = 0 c[direita] = 0 esquerda-=1 direita+=1 else: break if c[0] >= 10: c = [1] + [0]*(tam*4 - 2) + [1] return [str(i) for i in c] k,p = [int(i) for i in input().split()] a = ["1","1"] som = 0 som+=int("".join(a)) k-=1 while k != 0: a = modificar(a) som+=int("".join(a)) k-=1 print(som%p) ```
instruction
0
51,029
20
102,058
No
output
1
51,029
20
102,059
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. — Thanks a lot for today. — I experienced so many great things. — You gave me memories like dreams... But I have to leave now... — One last request, can you... — Help me solve a Codeforces problem? — ...... — What? Chtholly has been thinking about a problem for days: If a number is palindrome and length of its decimal representation without leading zeros is even, we call it a zcy number. A number is palindrome means when written in decimal representation, it contains no leading zeros and reads the same forwards and backwards. For example 12321 and 1221 are palindromes and 123 and 12451 are not. Moreover, 1221 is zcy number and 12321 is not. Given integers k and p, calculate the sum of the k smallest zcy numbers and output this sum modulo p. Unfortunately, Willem isn't good at solving this kind of problems, so he asks you for help! Input The first line contains two integers k and p (1 ≤ k ≤ 105, 1 ≤ p ≤ 109). Output Output single integer — answer to the problem. Examples Input 2 100 Output 33 Input 5 30 Output 15 Note In the first example, the smallest zcy number is 11, and the second smallest zcy number is 22. In the second example, <image>. Submitted Solution: ``` k, p = map(int, input().split()) ans = 0 for i in range(1,k+1): val = str(i) + str(i) ans = ans + (int(val))%p ans = ans % p print(ans) ```
instruction
0
51,030
20
102,060
No
output
1
51,030
20
102,061
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. — Thanks a lot for today. — I experienced so many great things. — You gave me memories like dreams... But I have to leave now... — One last request, can you... — Help me solve a Codeforces problem? — ...... — What? Chtholly has been thinking about a problem for days: If a number is palindrome and length of its decimal representation without leading zeros is even, we call it a zcy number. A number is palindrome means when written in decimal representation, it contains no leading zeros and reads the same forwards and backwards. For example 12321 and 1221 are palindromes and 123 and 12451 are not. Moreover, 1221 is zcy number and 12321 is not. Given integers k and p, calculate the sum of the k smallest zcy numbers and output this sum modulo p. Unfortunately, Willem isn't good at solving this kind of problems, so he asks you for help! Input The first line contains two integers k and p (1 ≤ k ≤ 105, 1 ≤ p ≤ 109). Output Output single integer — answer to the problem. Examples Input 2 100 Output 33 Input 5 30 Output 15 Note In the first example, the smallest zcy number is 11, and the second smallest zcy number is 22. In the second example, <image>. Submitted Solution: ``` # cook your dish here k,p = list(map(int,input().split())) l = [] t=0 while t<2*k: l.append(str(t)+str(t)[::-1]) t+=1 s = list(set([int(i) for i in l])) print(sum(s[:k+1])%p) ```
instruction
0
51,031
20
102,062
No
output
1
51,031
20
102,063
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A telephone number is a sequence of exactly 11 digits, where the first digit is 8. For example, the sequence 80011223388 is a telephone number, but the sequences 70011223388 and 80000011223388 are not. You are given a string s of length n, consisting of digits. In one operation you can delete any character from string s. For example, it is possible to obtain strings 112, 111 or 121 from string 1121. You need to determine whether there is such a sequence of operations (possibly empty), after which the string s becomes a telephone number. Input The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases. The first line of each test case contains one integer n (1 ≤ n ≤ 100) — the length of string s. The second line of each test case contains the string s (|s| = n) consisting of digits. Output For each test print one line. If there is a sequence of operations, after which s becomes a telephone number, print YES. Otherwise, print NO. Example Input 2 13 7818005553535 11 31415926535 Output YES NO Note In the first test case you need to delete the first and the third digits. Then the string 7818005553535 becomes 88005553535. Submitted Solution: ``` t=int(input()) for _ in range(t): n=int(input()) x=input() if(n<11): print("NO") elif(n==11): if(x[0]=='8'): print("YES") else: print("NO") else: if(x[0]=='8'): print("YES") else: f=0 for i in range(1,n-10): if(x[i]=='8'): print("YES") f=1 break if(f==0): print("NO") ```
instruction
0
51,386
20
102,772
Yes
output
1
51,386
20
102,773
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A telephone number is a sequence of exactly 11 digits, where the first digit is 8. For example, the sequence 80011223388 is a telephone number, but the sequences 70011223388 and 80000011223388 are not. You are given a string s of length n, consisting of digits. In one operation you can delete any character from string s. For example, it is possible to obtain strings 112, 111 or 121 from string 1121. You need to determine whether there is such a sequence of operations (possibly empty), after which the string s becomes a telephone number. Input The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases. The first line of each test case contains one integer n (1 ≤ n ≤ 100) — the length of string s. The second line of each test case contains the string s (|s| = n) consisting of digits. Output For each test print one line. If there is a sequence of operations, after which s becomes a telephone number, print YES. Otherwise, print NO. Example Input 2 13 7818005553535 11 31415926535 Output YES NO Note In the first test case you need to delete the first and the third digits. Then the string 7818005553535 becomes 88005553535. Submitted Solution: ``` t=int(input()) for i in range(t): x=int(input()) n=str(input()) if x<11: print("NO") else: n=n y=x-11 count=0 for i in range(y+1): if int(n[i])%8==0: count+=1 else: n=n if count>=1: print("YES") elif count<1 and x>=11: print("NO") ```
instruction
0
51,387
20
102,774
Yes
output
1
51,387
20
102,775
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A telephone number is a sequence of exactly 11 digits, where the first digit is 8. For example, the sequence 80011223388 is a telephone number, but the sequences 70011223388 and 80000011223388 are not. You are given a string s of length n, consisting of digits. In one operation you can delete any character from string s. For example, it is possible to obtain strings 112, 111 or 121 from string 1121. You need to determine whether there is such a sequence of operations (possibly empty), after which the string s becomes a telephone number. Input The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases. The first line of each test case contains one integer n (1 ≤ n ≤ 100) — the length of string s. The second line of each test case contains the string s (|s| = n) consisting of digits. Output For each test print one line. If there is a sequence of operations, after which s becomes a telephone number, print YES. Otherwise, print NO. Example Input 2 13 7818005553535 11 31415926535 Output YES NO Note In the first test case you need to delete the first and the third digits. Then the string 7818005553535 becomes 88005553535. Submitted Solution: ``` import time def convertToTelNumber(nums): res = "" inx8 = 0 for n in nums: if len(n) >= 11: inx8 = n.find("8") # print("indice", inx8) if inx8 >= 0: # print("ent") if inx8 + 11 <= len(n): res = "YES" else: res = "NO" else: res = "NO" else: res = "NO" print(res) return def solve(): cases = int(input()) lenNum = 0 numsList = [] for x in range(cases): lenNum = int(input()) phoneNum = input() numsList.append(phoneNum) convertToTelNumber(numsList) # print("%fs" % (time.time() - start_time)) solve() ```
instruction
0
51,389
20
102,778
Yes
output
1
51,389
20
102,779
Provide tags and a correct Python 3 solution for this coding contest problem. Bob is a competitive programmer. He wants to become red, and for that he needs a strict training regime. He went to the annual meeting of grandmasters and asked n of them how much effort they needed to reach red. "Oh, I just spent x_i hours solving problems", said the i-th of them. Bob wants to train his math skills, so for each answer he wrote down the number of minutes (60 ⋅ x_i), thanked the grandmasters and went home. Bob could write numbers with leading zeroes — for example, if some grandmaster answered that he had spent 2 hours, Bob could write 000120 instead of 120. Alice wanted to tease Bob and so she took the numbers Bob wrote down, and for each of them she did one of the following independently: * rearranged its digits, or * wrote a random number. This way, Alice generated n numbers, denoted y_1, ..., y_n. For each of the numbers, help Bob determine whether y_i can be a permutation of a number divisible by 60 (possibly with leading zeroes). Input The first line contains a single integer n (1 ≤ n ≤ 418) — the number of grandmasters Bob asked. Then n lines follow, the i-th of which contains a single integer y_i — the number that Alice wrote down. Each of these numbers has between 2 and 100 digits '0' through '9'. They can contain leading zeroes. Output Output n lines. For each i, output the following. If it is possible to rearrange the digits of y_i such that the resulting number is divisible by 60, output "red" (quotes for clarity). Otherwise, output "cyan". Example Input 6 603 006 205 228 1053 0000000000000000000000000000000000000000000000 Output red red cyan cyan cyan red Note In the first example, there is one rearrangement that yields a number divisible by 60, and that is 360. In the second example, there are two solutions. One is 060 and the second is 600. In the third example, there are 6 possible rearrangments: 025, 052, 205, 250, 502, 520. None of these numbers is divisible by 60. In the fourth example, there are 3 rearrangements: 228, 282, 822. In the fifth example, none of the 24 rearrangements result in a number divisible by 60. In the sixth example, note that 000...0 is a valid solution.
instruction
0
51,431
20
102,862
Tags: chinese remainder theorem, math Correct Solution: ``` for _ in range(int(input())): n=input() if set(n)=={'0'}: print("red") continue if '0' in n: c=0 eve=0 for i in n: c+=int(i) if int(i)%2==0 and int(i)!=0: eve+=1 if (c%3==0 and eve>0) or (c%3==0 and n.count('0')>1): print("red") else: print("cyan") else: print("cyan") ```
output
1
51,431
20
102,863
Provide tags and a correct Python 3 solution for this coding contest problem. Bob is a competitive programmer. He wants to become red, and for that he needs a strict training regime. He went to the annual meeting of grandmasters and asked n of them how much effort they needed to reach red. "Oh, I just spent x_i hours solving problems", said the i-th of them. Bob wants to train his math skills, so for each answer he wrote down the number of minutes (60 ⋅ x_i), thanked the grandmasters and went home. Bob could write numbers with leading zeroes — for example, if some grandmaster answered that he had spent 2 hours, Bob could write 000120 instead of 120. Alice wanted to tease Bob and so she took the numbers Bob wrote down, and for each of them she did one of the following independently: * rearranged its digits, or * wrote a random number. This way, Alice generated n numbers, denoted y_1, ..., y_n. For each of the numbers, help Bob determine whether y_i can be a permutation of a number divisible by 60 (possibly with leading zeroes). Input The first line contains a single integer n (1 ≤ n ≤ 418) — the number of grandmasters Bob asked. Then n lines follow, the i-th of which contains a single integer y_i — the number that Alice wrote down. Each of these numbers has between 2 and 100 digits '0' through '9'. They can contain leading zeroes. Output Output n lines. For each i, output the following. If it is possible to rearrange the digits of y_i such that the resulting number is divisible by 60, output "red" (quotes for clarity). Otherwise, output "cyan". Example Input 6 603 006 205 228 1053 0000000000000000000000000000000000000000000000 Output red red cyan cyan cyan red Note In the first example, there is one rearrangement that yields a number divisible by 60, and that is 360. In the second example, there are two solutions. One is 060 and the second is 600. In the third example, there are 6 possible rearrangments: 025, 052, 205, 250, 502, 520. None of these numbers is divisible by 60. In the fourth example, there are 3 rearrangements: 228, 282, 822. In the fifth example, none of the 24 rearrangements result in a number divisible by 60. In the sixth example, note that 000...0 is a valid solution.
instruction
0
51,432
20
102,864
Tags: chinese remainder theorem, math Correct Solution: ``` n = int(input()) for _ in range(n): cnt = [0] * 10 s = input() for c in s: i = ord(c) - ord('0') cnt[i] += 1 has_even = cnt[0] > 1 or cnt[2] != 0 or cnt[4] != 0 or cnt[8] != 0 or cnt[6] != 0 if cnt[0] == 0: print('cyan') continue if not has_even: print('cyan') continue total = 0 for i in range(10): total += cnt[i] * i if total % 3 == 0: print('red') else: print('cyan') ```
output
1
51,432
20
102,865
Provide tags and a correct Python 3 solution for this coding contest problem. Bob is a competitive programmer. He wants to become red, and for that he needs a strict training regime. He went to the annual meeting of grandmasters and asked n of them how much effort they needed to reach red. "Oh, I just spent x_i hours solving problems", said the i-th of them. Bob wants to train his math skills, so for each answer he wrote down the number of minutes (60 ⋅ x_i), thanked the grandmasters and went home. Bob could write numbers with leading zeroes — for example, if some grandmaster answered that he had spent 2 hours, Bob could write 000120 instead of 120. Alice wanted to tease Bob and so she took the numbers Bob wrote down, and for each of them she did one of the following independently: * rearranged its digits, or * wrote a random number. This way, Alice generated n numbers, denoted y_1, ..., y_n. For each of the numbers, help Bob determine whether y_i can be a permutation of a number divisible by 60 (possibly with leading zeroes). Input The first line contains a single integer n (1 ≤ n ≤ 418) — the number of grandmasters Bob asked. Then n lines follow, the i-th of which contains a single integer y_i — the number that Alice wrote down. Each of these numbers has between 2 and 100 digits '0' through '9'. They can contain leading zeroes. Output Output n lines. For each i, output the following. If it is possible to rearrange the digits of y_i such that the resulting number is divisible by 60, output "red" (quotes for clarity). Otherwise, output "cyan". Example Input 6 603 006 205 228 1053 0000000000000000000000000000000000000000000000 Output red red cyan cyan cyan red Note In the first example, there is one rearrangement that yields a number divisible by 60, and that is 360. In the second example, there are two solutions. One is 060 and the second is 600. In the third example, there are 6 possible rearrangments: 025, 052, 205, 250, 502, 520. None of these numbers is divisible by 60. In the fourth example, there are 3 rearrangements: 228, 282, 822. In the fifth example, none of the 24 rearrangements result in a number divisible by 60. In the sixth example, note that 000...0 is a valid solution.
instruction
0
51,433
20
102,866
Tags: chinese remainder theorem, math Correct Solution: ``` n = int(input()) for i in range(n): time = input() temp = time Sum = 0 Check = [False] * 10 DoubleZero = False for i in time: Sum += int(i) if (i == '0'): if (Check[0]): DoubleZero = True else: Check[0] = True elif (i == '2'): Check[2] = True elif (i == '4'): Check[4] = True elif (i == '6'): Check[6] = True elif (i == '8'): Check[8] = True if (Sum % 3 == 0 and Check[0] and (Check[2] or Check[4] or Check[6] or Check[8] or DoubleZero)): print("red") elif (Sum == 0): print("red") else: print("cyan") ```
output
1
51,433
20
102,867
Provide tags and a correct Python 3 solution for this coding contest problem. Bob is a competitive programmer. He wants to become red, and for that he needs a strict training regime. He went to the annual meeting of grandmasters and asked n of them how much effort they needed to reach red. "Oh, I just spent x_i hours solving problems", said the i-th of them. Bob wants to train his math skills, so for each answer he wrote down the number of minutes (60 ⋅ x_i), thanked the grandmasters and went home. Bob could write numbers with leading zeroes — for example, if some grandmaster answered that he had spent 2 hours, Bob could write 000120 instead of 120. Alice wanted to tease Bob and so she took the numbers Bob wrote down, and for each of them she did one of the following independently: * rearranged its digits, or * wrote a random number. This way, Alice generated n numbers, denoted y_1, ..., y_n. For each of the numbers, help Bob determine whether y_i can be a permutation of a number divisible by 60 (possibly with leading zeroes). Input The first line contains a single integer n (1 ≤ n ≤ 418) — the number of grandmasters Bob asked. Then n lines follow, the i-th of which contains a single integer y_i — the number that Alice wrote down. Each of these numbers has between 2 and 100 digits '0' through '9'. They can contain leading zeroes. Output Output n lines. For each i, output the following. If it is possible to rearrange the digits of y_i such that the resulting number is divisible by 60, output "red" (quotes for clarity). Otherwise, output "cyan". Example Input 6 603 006 205 228 1053 0000000000000000000000000000000000000000000000 Output red red cyan cyan cyan red Note In the first example, there is one rearrangement that yields a number divisible by 60, and that is 360. In the second example, there are two solutions. One is 060 and the second is 600. In the third example, there are 6 possible rearrangments: 025, 052, 205, 250, 502, 520. None of these numbers is divisible by 60. In the fourth example, there are 3 rearrangements: 228, 282, 822. In the fifth example, none of the 24 rearrangements result in a number divisible by 60. In the sixth example, note that 000...0 is a valid solution.
instruction
0
51,434
20
102,868
Tags: chinese remainder theorem, math Correct Solution: ``` def getLine(): return list(map(int,input().split())) t = int(input()) for _ in range(t): n = input() s = 0 b = False e = False for i in n: j = int(i) s+=j if j == 0 and not b:b = True elif j == 0 and b:e = True elif j%2 == 0:e = True if b and s%3 == 0 and e:print("red") else : print("cyan") ```
output
1
51,434
20
102,869
Provide tags and a correct Python 3 solution for this coding contest problem. Bob is a competitive programmer. He wants to become red, and for that he needs a strict training regime. He went to the annual meeting of grandmasters and asked n of them how much effort they needed to reach red. "Oh, I just spent x_i hours solving problems", said the i-th of them. Bob wants to train his math skills, so for each answer he wrote down the number of minutes (60 ⋅ x_i), thanked the grandmasters and went home. Bob could write numbers with leading zeroes — for example, if some grandmaster answered that he had spent 2 hours, Bob could write 000120 instead of 120. Alice wanted to tease Bob and so she took the numbers Bob wrote down, and for each of them she did one of the following independently: * rearranged its digits, or * wrote a random number. This way, Alice generated n numbers, denoted y_1, ..., y_n. For each of the numbers, help Bob determine whether y_i can be a permutation of a number divisible by 60 (possibly with leading zeroes). Input The first line contains a single integer n (1 ≤ n ≤ 418) — the number of grandmasters Bob asked. Then n lines follow, the i-th of which contains a single integer y_i — the number that Alice wrote down. Each of these numbers has between 2 and 100 digits '0' through '9'. They can contain leading zeroes. Output Output n lines. For each i, output the following. If it is possible to rearrange the digits of y_i such that the resulting number is divisible by 60, output "red" (quotes for clarity). Otherwise, output "cyan". Example Input 6 603 006 205 228 1053 0000000000000000000000000000000000000000000000 Output red red cyan cyan cyan red Note In the first example, there is one rearrangement that yields a number divisible by 60, and that is 360. In the second example, there are two solutions. One is 060 and the second is 600. In the third example, there are 6 possible rearrangments: 025, 052, 205, 250, 502, 520. None of these numbers is divisible by 60. In the fourth example, there are 3 rearrangements: 228, 282, 822. In the fifth example, none of the 24 rearrangements result in a number divisible by 60. In the sixth example, note that 000...0 is a valid solution.
instruction
0
51,435
20
102,870
Tags: chinese remainder theorem, math Correct Solution: ``` def check_3(num): sum=0 for char in num: sum=(sum+int(char))%3 if(sum==0): return 1 return 0 def check_2_10(num): b=0 c=0 count=0 for char in num: n=int(char) if((n!=0)and((n%2)==0)): b=1 if(n==0): count+=1 if((b==0) and (count>1)): return 1 if(count>0): c=1 return (b and c) N=int(input()) for i in range(N): num=input() if((check_3(num)) and (check_2_10(num))): print("red") else: print("cyan") ```
output
1
51,435
20
102,871
Provide tags and a correct Python 3 solution for this coding contest problem. Bob is a competitive programmer. He wants to become red, and for that he needs a strict training regime. He went to the annual meeting of grandmasters and asked n of them how much effort they needed to reach red. "Oh, I just spent x_i hours solving problems", said the i-th of them. Bob wants to train his math skills, so for each answer he wrote down the number of minutes (60 ⋅ x_i), thanked the grandmasters and went home. Bob could write numbers with leading zeroes — for example, if some grandmaster answered that he had spent 2 hours, Bob could write 000120 instead of 120. Alice wanted to tease Bob and so she took the numbers Bob wrote down, and for each of them she did one of the following independently: * rearranged its digits, or * wrote a random number. This way, Alice generated n numbers, denoted y_1, ..., y_n. For each of the numbers, help Bob determine whether y_i can be a permutation of a number divisible by 60 (possibly with leading zeroes). Input The first line contains a single integer n (1 ≤ n ≤ 418) — the number of grandmasters Bob asked. Then n lines follow, the i-th of which contains a single integer y_i — the number that Alice wrote down. Each of these numbers has between 2 and 100 digits '0' through '9'. They can contain leading zeroes. Output Output n lines. For each i, output the following. If it is possible to rearrange the digits of y_i such that the resulting number is divisible by 60, output "red" (quotes for clarity). Otherwise, output "cyan". Example Input 6 603 006 205 228 1053 0000000000000000000000000000000000000000000000 Output red red cyan cyan cyan red Note In the first example, there is one rearrangement that yields a number divisible by 60, and that is 360. In the second example, there are two solutions. One is 060 and the second is 600. In the third example, there are 6 possible rearrangments: 025, 052, 205, 250, 502, 520. None of these numbers is divisible by 60. In the fourth example, there are 3 rearrangements: 228, 282, 822. In the fifth example, none of the 24 rearrangements result in a number divisible by 60. In the sixth example, note that 000...0 is a valid solution.
instruction
0
51,436
20
102,872
Tags: chinese remainder theorem, math Correct Solution: ``` n=int(input()) for i in range(n): a=str(input()) a2=0 a0=0 s=0 if len(a)<=2: if a=="00" or a=="00" or a=="06" or a=="60": print("red") else: print("cyan") else: for j in range(len(a)): if a[j]=="0": a0+=1 if a[j]=="2" or a[j]=="4" or a[j]=="6" or a[j]=="8": a2+=1 s+=int(a[j]) if s%3==0 and (a0>=2 or (a0>=1 and a2>=1)): print("red") else: print("cyan") ```
output
1
51,436
20
102,873
Provide tags and a correct Python 3 solution for this coding contest problem. Bob is a competitive programmer. He wants to become red, and for that he needs a strict training regime. He went to the annual meeting of grandmasters and asked n of them how much effort they needed to reach red. "Oh, I just spent x_i hours solving problems", said the i-th of them. Bob wants to train his math skills, so for each answer he wrote down the number of minutes (60 ⋅ x_i), thanked the grandmasters and went home. Bob could write numbers with leading zeroes — for example, if some grandmaster answered that he had spent 2 hours, Bob could write 000120 instead of 120. Alice wanted to tease Bob and so she took the numbers Bob wrote down, and for each of them she did one of the following independently: * rearranged its digits, or * wrote a random number. This way, Alice generated n numbers, denoted y_1, ..., y_n. For each of the numbers, help Bob determine whether y_i can be a permutation of a number divisible by 60 (possibly with leading zeroes). Input The first line contains a single integer n (1 ≤ n ≤ 418) — the number of grandmasters Bob asked. Then n lines follow, the i-th of which contains a single integer y_i — the number that Alice wrote down. Each of these numbers has between 2 and 100 digits '0' through '9'. They can contain leading zeroes. Output Output n lines. For each i, output the following. If it is possible to rearrange the digits of y_i such that the resulting number is divisible by 60, output "red" (quotes for clarity). Otherwise, output "cyan". Example Input 6 603 006 205 228 1053 0000000000000000000000000000000000000000000000 Output red red cyan cyan cyan red Note In the first example, there is one rearrangement that yields a number divisible by 60, and that is 360. In the second example, there are two solutions. One is 060 and the second is 600. In the third example, there are 6 possible rearrangments: 025, 052, 205, 250, 502, 520. None of these numbers is divisible by 60. In the fourth example, there are 3 rearrangements: 228, 282, 822. In the fifth example, none of the 24 rearrangements result in a number divisible by 60. In the sixth example, note that 000...0 is a valid solution.
instruction
0
51,437
20
102,874
Tags: chinese remainder theorem, math Correct Solution: ``` N = int(input()) for _ in range(N): num = list(map(int,list(input()))) ln = len(num) zero_bol = 0 dive_bol = False two_bol = False if ln==1 and num[0]==0:print('red');continue for i in range(ln): if num[i]%2==0: if num[i]!=0: two_bol = True elif zero_bol: two_bol = True if num[i]==0: zero_bol = True if sum(num)%3==0:dive_bol = True if two_bol and zero_bol and dive_bol: print('red') else: print('cyan') ```
output
1
51,437
20
102,875
Provide tags and a correct Python 3 solution for this coding contest problem. Bob is a competitive programmer. He wants to become red, and for that he needs a strict training regime. He went to the annual meeting of grandmasters and asked n of them how much effort they needed to reach red. "Oh, I just spent x_i hours solving problems", said the i-th of them. Bob wants to train his math skills, so for each answer he wrote down the number of minutes (60 ⋅ x_i), thanked the grandmasters and went home. Bob could write numbers with leading zeroes — for example, if some grandmaster answered that he had spent 2 hours, Bob could write 000120 instead of 120. Alice wanted to tease Bob and so she took the numbers Bob wrote down, and for each of them she did one of the following independently: * rearranged its digits, or * wrote a random number. This way, Alice generated n numbers, denoted y_1, ..., y_n. For each of the numbers, help Bob determine whether y_i can be a permutation of a number divisible by 60 (possibly with leading zeroes). Input The first line contains a single integer n (1 ≤ n ≤ 418) — the number of grandmasters Bob asked. Then n lines follow, the i-th of which contains a single integer y_i — the number that Alice wrote down. Each of these numbers has between 2 and 100 digits '0' through '9'. They can contain leading zeroes. Output Output n lines. For each i, output the following. If it is possible to rearrange the digits of y_i such that the resulting number is divisible by 60, output "red" (quotes for clarity). Otherwise, output "cyan". Example Input 6 603 006 205 228 1053 0000000000000000000000000000000000000000000000 Output red red cyan cyan cyan red Note In the first example, there is one rearrangement that yields a number divisible by 60, and that is 360. In the second example, there are two solutions. One is 060 and the second is 600. In the third example, there are 6 possible rearrangments: 025, 052, 205, 250, 502, 520. None of these numbers is divisible by 60. In the fourth example, there are 3 rearrangements: 228, 282, 822. In the fifth example, none of the 24 rearrangements result in a number divisible by 60. In the sixth example, note that 000...0 is a valid solution.
instruction
0
51,438
20
102,876
Tags: chinese remainder theorem, math Correct Solution: ``` n = int(input()) for i in range(n): a = list(map(int, list(input()))) c = a.count(0) + a.count(2) + a.count(4) + a.count(6) + a.count(8) if sum(a) % 3 == 0 and (a.count(0) >= 1) and c > 1: print('red') elif a.count(0) == len(a): print('red') else: print('cyan') ```
output
1
51,438
20
102,877
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Bob is a competitive programmer. He wants to become red, and for that he needs a strict training regime. He went to the annual meeting of grandmasters and asked n of them how much effort they needed to reach red. "Oh, I just spent x_i hours solving problems", said the i-th of them. Bob wants to train his math skills, so for each answer he wrote down the number of minutes (60 ⋅ x_i), thanked the grandmasters and went home. Bob could write numbers with leading zeroes — for example, if some grandmaster answered that he had spent 2 hours, Bob could write 000120 instead of 120. Alice wanted to tease Bob and so she took the numbers Bob wrote down, and for each of them she did one of the following independently: * rearranged its digits, or * wrote a random number. This way, Alice generated n numbers, denoted y_1, ..., y_n. For each of the numbers, help Bob determine whether y_i can be a permutation of a number divisible by 60 (possibly with leading zeroes). Input The first line contains a single integer n (1 ≤ n ≤ 418) — the number of grandmasters Bob asked. Then n lines follow, the i-th of which contains a single integer y_i — the number that Alice wrote down. Each of these numbers has between 2 and 100 digits '0' through '9'. They can contain leading zeroes. Output Output n lines. For each i, output the following. If it is possible to rearrange the digits of y_i such that the resulting number is divisible by 60, output "red" (quotes for clarity). Otherwise, output "cyan". Example Input 6 603 006 205 228 1053 0000000000000000000000000000000000000000000000 Output red red cyan cyan cyan red Note In the first example, there is one rearrangement that yields a number divisible by 60, and that is 360. In the second example, there are two solutions. One is 060 and the second is 600. In the third example, there are 6 possible rearrangments: 025, 052, 205, 250, 502, 520. None of these numbers is divisible by 60. In the fourth example, there are 3 rearrangements: 228, 282, 822. In the fifth example, none of the 24 rearrangements result in a number divisible by 60. In the sixth example, note that 000...0 is a valid solution. Submitted Solution: ``` tests = int(input()) while tests: tests -= 1 n = input() l = [int(x) for x in n] s = sum(l) l1 = [x for x in l if x % 2 == 0] if '0' in n and s % 3 == 0 and len(l1) >= 2: print('red') else: print('cyan') ```
instruction
0
51,439
20
102,878
Yes
output
1
51,439
20
102,879
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Bob is a competitive programmer. He wants to become red, and for that he needs a strict training regime. He went to the annual meeting of grandmasters and asked n of them how much effort they needed to reach red. "Oh, I just spent x_i hours solving problems", said the i-th of them. Bob wants to train his math skills, so for each answer he wrote down the number of minutes (60 ⋅ x_i), thanked the grandmasters and went home. Bob could write numbers with leading zeroes — for example, if some grandmaster answered that he had spent 2 hours, Bob could write 000120 instead of 120. Alice wanted to tease Bob and so she took the numbers Bob wrote down, and for each of them she did one of the following independently: * rearranged its digits, or * wrote a random number. This way, Alice generated n numbers, denoted y_1, ..., y_n. For each of the numbers, help Bob determine whether y_i can be a permutation of a number divisible by 60 (possibly with leading zeroes). Input The first line contains a single integer n (1 ≤ n ≤ 418) — the number of grandmasters Bob asked. Then n lines follow, the i-th of which contains a single integer y_i — the number that Alice wrote down. Each of these numbers has between 2 and 100 digits '0' through '9'. They can contain leading zeroes. Output Output n lines. For each i, output the following. If it is possible to rearrange the digits of y_i such that the resulting number is divisible by 60, output "red" (quotes for clarity). Otherwise, output "cyan". Example Input 6 603 006 205 228 1053 0000000000000000000000000000000000000000000000 Output red red cyan cyan cyan red Note In the first example, there is one rearrangement that yields a number divisible by 60, and that is 360. In the second example, there are two solutions. One is 060 and the second is 600. In the third example, there are 6 possible rearrangments: 025, 052, 205, 250, 502, 520. None of these numbers is divisible by 60. In the fourth example, there are 3 rearrangements: 228, 282, 822. In the fifth example, none of the 24 rearrangements result in a number divisible by 60. In the sixth example, note that 000...0 is a valid solution. Submitted Solution: ``` for _ in range(int(input())): no = input() flag = False new = False j = 0 for i in str(no): if int(i)%2==0: if j == 0 and int(i)==0: pass j+=1 else: flag = True if str(no).count('0')>=1: new = True #print(new) if flag and new and sum(map(int,str(no)))%3==0: print('red') else: print('cyan') ```
instruction
0
51,440
20
102,880
Yes
output
1
51,440
20
102,881
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Bob is a competitive programmer. He wants to become red, and for that he needs a strict training regime. He went to the annual meeting of grandmasters and asked n of them how much effort they needed to reach red. "Oh, I just spent x_i hours solving problems", said the i-th of them. Bob wants to train his math skills, so for each answer he wrote down the number of minutes (60 ⋅ x_i), thanked the grandmasters and went home. Bob could write numbers with leading zeroes — for example, if some grandmaster answered that he had spent 2 hours, Bob could write 000120 instead of 120. Alice wanted to tease Bob and so she took the numbers Bob wrote down, and for each of them she did one of the following independently: * rearranged its digits, or * wrote a random number. This way, Alice generated n numbers, denoted y_1, ..., y_n. For each of the numbers, help Bob determine whether y_i can be a permutation of a number divisible by 60 (possibly with leading zeroes). Input The first line contains a single integer n (1 ≤ n ≤ 418) — the number of grandmasters Bob asked. Then n lines follow, the i-th of which contains a single integer y_i — the number that Alice wrote down. Each of these numbers has between 2 and 100 digits '0' through '9'. They can contain leading zeroes. Output Output n lines. For each i, output the following. If it is possible to rearrange the digits of y_i such that the resulting number is divisible by 60, output "red" (quotes for clarity). Otherwise, output "cyan". Example Input 6 603 006 205 228 1053 0000000000000000000000000000000000000000000000 Output red red cyan cyan cyan red Note In the first example, there is one rearrangement that yields a number divisible by 60, and that is 360. In the second example, there are two solutions. One is 060 and the second is 600. In the third example, there are 6 possible rearrangments: 025, 052, 205, 250, 502, 520. None of these numbers is divisible by 60. In the fourth example, there are 3 rearrangements: 228, 282, 822. In the fifth example, none of the 24 rearrangements result in a number divisible by 60. In the sixth example, note that 000...0 is a valid solution. Submitted Solution: ``` for ii in range(int(input())): n=str(input()) n0=0 nE=0 su=0 for x in n: if(x=='0'): n0+=1 nE+=1 elif(int(x) & 1 == 0): nE+=1 su+=int(x) if(su%3==0): if(su==0): print("red") elif((n0==nE and n0>=2) or (n0<nE and n0>=1)): print("red") else: print("cyan") else: print("cyan") ```
instruction
0
51,441
20
102,882
Yes
output
1
51,441
20
102,883
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Bob is a competitive programmer. He wants to become red, and for that he needs a strict training regime. He went to the annual meeting of grandmasters and asked n of them how much effort they needed to reach red. "Oh, I just spent x_i hours solving problems", said the i-th of them. Bob wants to train his math skills, so for each answer he wrote down the number of minutes (60 ⋅ x_i), thanked the grandmasters and went home. Bob could write numbers with leading zeroes — for example, if some grandmaster answered that he had spent 2 hours, Bob could write 000120 instead of 120. Alice wanted to tease Bob and so she took the numbers Bob wrote down, and for each of them she did one of the following independently: * rearranged its digits, or * wrote a random number. This way, Alice generated n numbers, denoted y_1, ..., y_n. For each of the numbers, help Bob determine whether y_i can be a permutation of a number divisible by 60 (possibly with leading zeroes). Input The first line contains a single integer n (1 ≤ n ≤ 418) — the number of grandmasters Bob asked. Then n lines follow, the i-th of which contains a single integer y_i — the number that Alice wrote down. Each of these numbers has between 2 and 100 digits '0' through '9'. They can contain leading zeroes. Output Output n lines. For each i, output the following. If it is possible to rearrange the digits of y_i such that the resulting number is divisible by 60, output "red" (quotes for clarity). Otherwise, output "cyan". Example Input 6 603 006 205 228 1053 0000000000000000000000000000000000000000000000 Output red red cyan cyan cyan red Note In the first example, there is one rearrangement that yields a number divisible by 60, and that is 360. In the second example, there are two solutions. One is 060 and the second is 600. In the third example, there are 6 possible rearrangments: 025, 052, 205, 250, 502, 520. None of these numbers is divisible by 60. In the fourth example, there are 3 rearrangements: 228, 282, 822. In the fifth example, none of the 24 rearrangements result in a number divisible by 60. In the sixth example, note that 000...0 is a valid solution. Submitted Solution: ``` for _ in" "*int(input()):s = input();print("cryeadn"[s.count('0')and sum(map(int,s))%3<1 and sum(int(c)%2<1for c in s)>1::2]) ```
instruction
0
51,442
20
102,884
Yes
output
1
51,442
20
102,885
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Bob is a competitive programmer. He wants to become red, and for that he needs a strict training regime. He went to the annual meeting of grandmasters and asked n of them how much effort they needed to reach red. "Oh, I just spent x_i hours solving problems", said the i-th of them. Bob wants to train his math skills, so for each answer he wrote down the number of minutes (60 ⋅ x_i), thanked the grandmasters and went home. Bob could write numbers with leading zeroes — for example, if some grandmaster answered that he had spent 2 hours, Bob could write 000120 instead of 120. Alice wanted to tease Bob and so she took the numbers Bob wrote down, and for each of them she did one of the following independently: * rearranged its digits, or * wrote a random number. This way, Alice generated n numbers, denoted y_1, ..., y_n. For each of the numbers, help Bob determine whether y_i can be a permutation of a number divisible by 60 (possibly with leading zeroes). Input The first line contains a single integer n (1 ≤ n ≤ 418) — the number of grandmasters Bob asked. Then n lines follow, the i-th of which contains a single integer y_i — the number that Alice wrote down. Each of these numbers has between 2 and 100 digits '0' through '9'. They can contain leading zeroes. Output Output n lines. For each i, output the following. If it is possible to rearrange the digits of y_i such that the resulting number is divisible by 60, output "red" (quotes for clarity). Otherwise, output "cyan". Example Input 6 603 006 205 228 1053 0000000000000000000000000000000000000000000000 Output red red cyan cyan cyan red Note In the first example, there is one rearrangement that yields a number divisible by 60, and that is 360. In the second example, there are two solutions. One is 060 and the second is 600. In the third example, there are 6 possible rearrangments: 025, 052, 205, 250, 502, 520. None of these numbers is divisible by 60. In the fourth example, there are 3 rearrangements: 228, 282, 822. In the fifth example, none of the 24 rearrangements result in a number divisible by 60. In the sixth example, note that 000...0 is a valid solution. Submitted Solution: ``` import math from collections import defaultdict, Counter, deque INF = float('inf') def gcd(a, b): while b: a, b = b, a%b return a def primeFactor(n): if n % 2 == 0: return 2 i = 3 while (i ** 2) <= n: if n % i == 0: return i i += 1 return n def main(): n = input() ans = [sorted(str(i * 60)) for i in range(11)] n2 = '' cnt = 0 for i in range(len(n)): if n[i] == '0' and cnt < 1: n2 += n[i] cnt += 1 elif int(n[i]) > 6: n2 += str(int(n[i]) - 6) elif n[i] != '0': n2 += n[i] # print("#",n2) n2 = sorted(n2) if n2 in ans: print("red") else: print("cyan") if __name__ == "__main__": t = int(input()) # t = 1 for _ in range(t): main() ```
instruction
0
51,443
20
102,886
No
output
1
51,443
20
102,887
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Bob is a competitive programmer. He wants to become red, and for that he needs a strict training regime. He went to the annual meeting of grandmasters and asked n of them how much effort they needed to reach red. "Oh, I just spent x_i hours solving problems", said the i-th of them. Bob wants to train his math skills, so for each answer he wrote down the number of minutes (60 ⋅ x_i), thanked the grandmasters and went home. Bob could write numbers with leading zeroes — for example, if some grandmaster answered that he had spent 2 hours, Bob could write 000120 instead of 120. Alice wanted to tease Bob and so she took the numbers Bob wrote down, and for each of them she did one of the following independently: * rearranged its digits, or * wrote a random number. This way, Alice generated n numbers, denoted y_1, ..., y_n. For each of the numbers, help Bob determine whether y_i can be a permutation of a number divisible by 60 (possibly with leading zeroes). Input The first line contains a single integer n (1 ≤ n ≤ 418) — the number of grandmasters Bob asked. Then n lines follow, the i-th of which contains a single integer y_i — the number that Alice wrote down. Each of these numbers has between 2 and 100 digits '0' through '9'. They can contain leading zeroes. Output Output n lines. For each i, output the following. If it is possible to rearrange the digits of y_i such that the resulting number is divisible by 60, output "red" (quotes for clarity). Otherwise, output "cyan". Example Input 6 603 006 205 228 1053 0000000000000000000000000000000000000000000000 Output red red cyan cyan cyan red Note In the first example, there is one rearrangement that yields a number divisible by 60, and that is 360. In the second example, there are two solutions. One is 060 and the second is 600. In the third example, there are 6 possible rearrangments: 025, 052, 205, 250, 502, 520. None of these numbers is divisible by 60. In the fourth example, there are 3 rearrangements: 228, 282, 822. In the fifth example, none of the 24 rearrangements result in a number divisible by 60. In the sixth example, note that 000...0 is a valid solution. Submitted Solution: ``` n = int(input()) for i in range(0, n): y = input() con0 = False # Условие, что есть хотя бы 1 нуль con3 = False # Условие, что число может быть кратно трём con20 = False # Улсовие, что число может быть кратно 20 numSum = 0 for char in y: numSum += int(char) if char == '0': con0 = True if int(char) % 2 == 0: con20 = True if numSum % 3 == 0: con3 = True if con0 and con3 and con20: print('red') else: print('cyan') ```
instruction
0
51,444
20
102,888
No
output
1
51,444
20
102,889