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
Provide tags and a correct Python 3 solution for this coding contest problem. Let's call the roundness of the number the number of zeros to which it ends. You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible. Input The first line contains two integer numbers n and k (1 ≀ n ≀ 200, 1 ≀ k ≀ n). The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≀ ai ≀ 1018). Output Print maximal roundness of product of the chosen subset of length k. Examples Input 3 2 50 4 20 Output 3 Input 5 3 15 16 3 25 9 Output 3 Input 3 3 9 77 13 Output 0 Note In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] β€” product 80, roundness 1, [50, 20] β€” product 1000, roundness 3. In the second example subset [15, 16, 25] has product 6000, roundness 3. In the third example all subsets has product with roundness 0.
instruction
0
78,807
20
157,614
Tags: dp, math Correct Solution: ``` import sys from decimal import Decimal def calc(c): d = 0 p = 0 while c % 2 == 0: c /= 2 d += 1 while c % 5 == 0: c /= 5 p += 1 return d, p def main(): n, k = map(int, sys.stdin.readline().split()) a = list(map(int, sys.stdin.readline().split())) dp = [[-1] * 5050 for i in range(k+1)] for i in range(n): d, p = calc(Decimal(a[i])) for i in range(k - 2, -1, -1): for j in range(5000): if dp[i][j] != -1: dp[i + 1][j + p] = max(dp[i + 1][j + p], dp[i][j] + d) dp[0][p] = max(dp[0][p], d) ans = 0 for j in range(5050): if dp[k-1][j] != -1: ans = max(ans, min(j, dp[k-1][j])) print(ans) main() ```
output
1
78,807
20
157,615
Provide a correct Python 3 solution for this coding contest problem. Your task is to write a program which reads an expression and evaluates it. * The expression consists of numerical values, operators and parentheses, and the ends with '='. * The operators includes +, - , *, / where respectively represents, addition, subtraction, multiplication and division. * Precedence of the operators is based on usual laws. That is one should perform all multiplication and division first, then addition and subtraction. When two operators have the same precedence, they are applied from left to right. * You may assume that there is no division by zero. * All calculation is performed as integers, and after the decimal point should be truncated * Length of the expression will not exceed 100. * -1 Γ— 109 ≀ intermediate results of computation ≀ 109 Input The input is a sequence of datasets. The first line contains an integer n which represents the number of datasets. There will be n lines where each line contains an expression. Output For each datasets, prints the result of calculation. Example Input 2 4-2*3= 4*(8+4+3)= Output -2 60
instruction
0
79,026
20
158,052
"Correct Solution: ``` def ReversePolishNotation(string): priority = {"(": 0, ")": 0, "+": 1, "-": 1, "*": 2, "/": 2} stack = [] signStack = [] isContinue = False for item in string[:-1]: if str.isdigit(item): if not isContinue: stack.append(item) isContinue = True else: stack[-1] += item continue elif item == "(": signStack.append(item) elif item == ")": while signStack[-1] != "(": stack.append(signStack.pop()) signStack.pop() else: while len(signStack) != 0 and priority[item] <= priority[signStack[-1]]: stack.append(signStack.pop()) signStack.append(item) isContinue = False while len(signStack) != 0: stack.append(signStack.pop()) return stack def Calculate(formulaList): signs = ["+", "-", "*", "/"] stack = [] for item in formulaList: if item not in signs: stack.append(item) else: num1 = int(stack.pop()) num2 = int(stack.pop()) if item == "+": result = num2 + num1 elif item == "-": result = num2 - num1 elif item == "*": result = num2 * num1 else: result = int(num2 / num1) stack.append(result) return int(stack[0]) inputCount = int(input()) for lp in range(inputCount): formula = input() rpn = ReversePolishNotation(formula) answer = Calculate(rpn) print(answer) ```
output
1
79,026
20
158,053
Provide a correct Python 3 solution for this coding contest problem. Your task is to write a program which reads an expression and evaluates it. * The expression consists of numerical values, operators and parentheses, and the ends with '='. * The operators includes +, - , *, / where respectively represents, addition, subtraction, multiplication and division. * Precedence of the operators is based on usual laws. That is one should perform all multiplication and division first, then addition and subtraction. When two operators have the same precedence, they are applied from left to right. * You may assume that there is no division by zero. * All calculation is performed as integers, and after the decimal point should be truncated * Length of the expression will not exceed 100. * -1 Γ— 109 ≀ intermediate results of computation ≀ 109 Input The input is a sequence of datasets. The first line contains an integer n which represents the number of datasets. There will be n lines where each line contains an expression. Output For each datasets, prints the result of calculation. Example Input 2 4-2*3= 4*(8+4+3)= Output -2 60
instruction
0
79,027
20
158,054
"Correct Solution: ``` import re class Num: def __init__(self, x): self.x = x def __str__(self): return str(self.x) def __add__(self, other): return Num(self.x + other.x) def __sub__(self, other): return Num(self.x - other.x) def __truediv__(self, other): return Num(int(self.x / other.x)) def __mul__(self, other): return Num(self.x * other.x) def __neg__(self): return Num(-self.x) n = int(input()) for _ in range(n): expr = input()[0:-1] expr = re.sub(r'(\d+)', r'Num(\1)', expr) print(eval(expr)) ```
output
1
79,027
20
158,055
Provide tags and a correct Python 3 solution for this coding contest problem. At a break Vanya came to the class and saw an array of n k-bit integers a_1, a_2, …, a_n on the board. An integer x is called a k-bit integer if 0 ≀ x ≀ 2^k - 1. Of course, Vanya was not able to resist and started changing the numbers written on the board. To ensure that no one will note anything, Vanya allowed himself to make only one type of changes: choose an index of the array i (1 ≀ i ≀ n) and replace the number a_i with the number \overline{a_i}. We define \overline{x} for a k-bit integer x as the k-bit integer such that all its k bits differ from the corresponding bits of x. Vanya does not like the number 0. Therefore, he likes such segments [l, r] (1 ≀ l ≀ r ≀ n) such that a_l βŠ• a_{l+1} βŠ• … βŠ• a_r β‰  0, where βŠ• denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). Determine the maximum number of segments he likes Vanya can get applying zero or more operations described above. Input The first line of the input contains two integers n and k (1 ≀ n ≀ 200 000, 1 ≀ k ≀ 30). The next line contains n integers a_1, a_2, …, a_n (0 ≀ a_i ≀ 2^k - 1), separated by spaces β€” the array of k-bit integers. Output Print one integer β€” the maximum possible number of segments with XOR not equal to 0 that can be obtained by making several (possibly 0) operations described in the statement. Examples Input 3 2 1 3 0 Output 5 Input 6 3 1 4 4 7 3 4 Output 19 Note In the first example if Vasya does not perform any operations, he gets an array that has 5 segments that Vanya likes. If he performs the operation with i = 2, he gets an array [1, 0, 0], because \overline{3} = 0 when k = 2. This array has 3 segments that Vanya likes. Also, to get an array with 5 segments that Vanya likes, he can perform two operations with i = 3 and with i = 2. He then gets an array [1, 0, 3]. It can be proven that he can't obtain 6 or more segments that he likes. In the second example, to get 19 segments that Vanya likes, he can perform 4 operations with i = 3, i = 4, i = 5, i = 6 and get an array [1, 4, 3, 0, 4, 3].
instruction
0
79,135
20
158,270
Tags: greedy, implementation Correct Solution: ``` n,k=list(map(int,input().split())) arr=list(map(int,input().split())) newarr=[0] for num in arr: newarr+=[newarr[-1]^num] dic={} for num in newarr: x=(min(num,2**k-1-num),max(num,2**k-1-num)) if x in dic: dic[x]+=1 else: dic[x]=1 ans=0 for elem in dic: m=dic[elem] half=m//2 ans+=half*(half-1)/2 half=m-half ans+=half*(half-1)/2 ans=n*(n+1)/2-ans print(int(ans)) ```
output
1
79,135
20
158,271
Provide tags and a correct Python 3 solution for this coding contest problem. At a break Vanya came to the class and saw an array of n k-bit integers a_1, a_2, …, a_n on the board. An integer x is called a k-bit integer if 0 ≀ x ≀ 2^k - 1. Of course, Vanya was not able to resist and started changing the numbers written on the board. To ensure that no one will note anything, Vanya allowed himself to make only one type of changes: choose an index of the array i (1 ≀ i ≀ n) and replace the number a_i with the number \overline{a_i}. We define \overline{x} for a k-bit integer x as the k-bit integer such that all its k bits differ from the corresponding bits of x. Vanya does not like the number 0. Therefore, he likes such segments [l, r] (1 ≀ l ≀ r ≀ n) such that a_l βŠ• a_{l+1} βŠ• … βŠ• a_r β‰  0, where βŠ• denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). Determine the maximum number of segments he likes Vanya can get applying zero or more operations described above. Input The first line of the input contains two integers n and k (1 ≀ n ≀ 200 000, 1 ≀ k ≀ 30). The next line contains n integers a_1, a_2, …, a_n (0 ≀ a_i ≀ 2^k - 1), separated by spaces β€” the array of k-bit integers. Output Print one integer β€” the maximum possible number of segments with XOR not equal to 0 that can be obtained by making several (possibly 0) operations described in the statement. Examples Input 3 2 1 3 0 Output 5 Input 6 3 1 4 4 7 3 4 Output 19 Note In the first example if Vasya does not perform any operations, he gets an array that has 5 segments that Vanya likes. If he performs the operation with i = 2, he gets an array [1, 0, 0], because \overline{3} = 0 when k = 2. This array has 3 segments that Vanya likes. Also, to get an array with 5 segments that Vanya likes, he can perform two operations with i = 3 and with i = 2. He then gets an array [1, 0, 3]. It can be proven that he can't obtain 6 or more segments that he likes. In the second example, to get 19 segments that Vanya likes, he can perform 4 operations with i = 3, i = 4, i = 5, i = 6 and get an array [1, 4, 3, 0, 4, 3].
instruction
0
79,136
20
158,272
Tags: greedy, implementation Correct Solution: ``` '''input 3 2 1 3 0 ''' def solve(): n,k = list(map(int,input().split())) flipVal = (1<<k)-1 l = list(map(int,input().split())) D = {} D[0]=1 for i in range(1,n): l[i]^=l[i-1] for i in range(0,n): l[i]=min(l[i],l[i]^flipVal) if l[i] in D: D[l[i]]+=1 else: D[l[i]]=1 #print(l) total = n*(n+1)//2 bad = 0 for i in D: temp = D[i] tot = temp//2 bad+= tot*(tot-1)//2 tot = temp - tot bad+= tot*(tot-1)//2 print(total-bad) return t = 1 #t = int(input()) while t>0: t-=1 solve() ```
output
1
79,136
20
158,273
Provide tags and a correct Python 3 solution for this coding contest problem. At a break Vanya came to the class and saw an array of n k-bit integers a_1, a_2, …, a_n on the board. An integer x is called a k-bit integer if 0 ≀ x ≀ 2^k - 1. Of course, Vanya was not able to resist and started changing the numbers written on the board. To ensure that no one will note anything, Vanya allowed himself to make only one type of changes: choose an index of the array i (1 ≀ i ≀ n) and replace the number a_i with the number \overline{a_i}. We define \overline{x} for a k-bit integer x as the k-bit integer such that all its k bits differ from the corresponding bits of x. Vanya does not like the number 0. Therefore, he likes such segments [l, r] (1 ≀ l ≀ r ≀ n) such that a_l βŠ• a_{l+1} βŠ• … βŠ• a_r β‰  0, where βŠ• denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). Determine the maximum number of segments he likes Vanya can get applying zero or more operations described above. Input The first line of the input contains two integers n and k (1 ≀ n ≀ 200 000, 1 ≀ k ≀ 30). The next line contains n integers a_1, a_2, …, a_n (0 ≀ a_i ≀ 2^k - 1), separated by spaces β€” the array of k-bit integers. Output Print one integer β€” the maximum possible number of segments with XOR not equal to 0 that can be obtained by making several (possibly 0) operations described in the statement. Examples Input 3 2 1 3 0 Output 5 Input 6 3 1 4 4 7 3 4 Output 19 Note In the first example if Vasya does not perform any operations, he gets an array that has 5 segments that Vanya likes. If he performs the operation with i = 2, he gets an array [1, 0, 0], because \overline{3} = 0 when k = 2. This array has 3 segments that Vanya likes. Also, to get an array with 5 segments that Vanya likes, he can perform two operations with i = 3 and with i = 2. He then gets an array [1, 0, 3]. It can be proven that he can't obtain 6 or more segments that he likes. In the second example, to get 19 segments that Vanya likes, he can perform 4 operations with i = 3, i = 4, i = 5, i = 6 and get an array [1, 4, 3, 0, 4, 3].
instruction
0
79,137
20
158,274
Tags: greedy, implementation Correct Solution: ``` from collections import defaultdict n,k=map(int,input().split()) arr=list(map(int,input().split())) xors=defaultdict(int) xors[0]=1 comp=(1<<k)-1 xor=0 ans=n*(n+1)//2 for a in arr: xor^=a if(xors[xor]>xors[comp^xor]): xor^=comp ans-=xors[xor] xors[xor]+=1 print(ans) ```
output
1
79,137
20
158,275
Provide tags and a correct Python 3 solution for this coding contest problem. At a break Vanya came to the class and saw an array of n k-bit integers a_1, a_2, …, a_n on the board. An integer x is called a k-bit integer if 0 ≀ x ≀ 2^k - 1. Of course, Vanya was not able to resist and started changing the numbers written on the board. To ensure that no one will note anything, Vanya allowed himself to make only one type of changes: choose an index of the array i (1 ≀ i ≀ n) and replace the number a_i with the number \overline{a_i}. We define \overline{x} for a k-bit integer x as the k-bit integer such that all its k bits differ from the corresponding bits of x. Vanya does not like the number 0. Therefore, he likes such segments [l, r] (1 ≀ l ≀ r ≀ n) such that a_l βŠ• a_{l+1} βŠ• … βŠ• a_r β‰  0, where βŠ• denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). Determine the maximum number of segments he likes Vanya can get applying zero or more operations described above. Input The first line of the input contains two integers n and k (1 ≀ n ≀ 200 000, 1 ≀ k ≀ 30). The next line contains n integers a_1, a_2, …, a_n (0 ≀ a_i ≀ 2^k - 1), separated by spaces β€” the array of k-bit integers. Output Print one integer β€” the maximum possible number of segments with XOR not equal to 0 that can be obtained by making several (possibly 0) operations described in the statement. Examples Input 3 2 1 3 0 Output 5 Input 6 3 1 4 4 7 3 4 Output 19 Note In the first example if Vasya does not perform any operations, he gets an array that has 5 segments that Vanya likes. If he performs the operation with i = 2, he gets an array [1, 0, 0], because \overline{3} = 0 when k = 2. This array has 3 segments that Vanya likes. Also, to get an array with 5 segments that Vanya likes, he can perform two operations with i = 3 and with i = 2. He then gets an array [1, 0, 3]. It can be proven that he can't obtain 6 or more segments that he likes. In the second example, to get 19 segments that Vanya likes, he can perform 4 operations with i = 3, i = 4, i = 5, i = 6 and get an array [1, 4, 3, 0, 4, 3].
instruction
0
79,138
20
158,276
Tags: greedy, implementation Correct Solution: ``` from math import * #n,k=map(int,input().split()) #A = list(map(int,input().split())) n,k = map(int,input().split()) ans = [0] * n #^xor lul = 2**k - 1 A = list(map(int,input().split())) ans[0] = A[0] for j in range(1, n): ans[j] = ans[j-1]^A[j] #print(ans) d = dict() for j in range(n): if ans[j] in d: d[ans[j]]+=1; else: d[ans[j]] = 1 #print(d) ans =0 def huy(n): return n*(n-1)//2 for j in d: now = d[j] #print(d[j],j) xor = lul^j cur = now if xor in d : now2 = d[xor] #print(now,xor) cur += now2 ans += huy(cur//2+cur%2) ans+=huy(cur//2) if j ==0: ans+=2*(cur//2) else: if(j==0 or xor ==0): ans+= 2*(cur//2) ans += 2*huy(cur // 2 + cur % 2) ans += 2*huy(cur // 2) print(huy(n+1) - ans//2) ```
output
1
79,138
20
158,277
Provide tags and a correct Python 3 solution for this coding contest problem. At a break Vanya came to the class and saw an array of n k-bit integers a_1, a_2, …, a_n on the board. An integer x is called a k-bit integer if 0 ≀ x ≀ 2^k - 1. Of course, Vanya was not able to resist and started changing the numbers written on the board. To ensure that no one will note anything, Vanya allowed himself to make only one type of changes: choose an index of the array i (1 ≀ i ≀ n) and replace the number a_i with the number \overline{a_i}. We define \overline{x} for a k-bit integer x as the k-bit integer such that all its k bits differ from the corresponding bits of x. Vanya does not like the number 0. Therefore, he likes such segments [l, r] (1 ≀ l ≀ r ≀ n) such that a_l βŠ• a_{l+1} βŠ• … βŠ• a_r β‰  0, where βŠ• denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). Determine the maximum number of segments he likes Vanya can get applying zero or more operations described above. Input The first line of the input contains two integers n and k (1 ≀ n ≀ 200 000, 1 ≀ k ≀ 30). The next line contains n integers a_1, a_2, …, a_n (0 ≀ a_i ≀ 2^k - 1), separated by spaces β€” the array of k-bit integers. Output Print one integer β€” the maximum possible number of segments with XOR not equal to 0 that can be obtained by making several (possibly 0) operations described in the statement. Examples Input 3 2 1 3 0 Output 5 Input 6 3 1 4 4 7 3 4 Output 19 Note In the first example if Vasya does not perform any operations, he gets an array that has 5 segments that Vanya likes. If he performs the operation with i = 2, he gets an array [1, 0, 0], because \overline{3} = 0 when k = 2. This array has 3 segments that Vanya likes. Also, to get an array with 5 segments that Vanya likes, he can perform two operations with i = 3 and with i = 2. He then gets an array [1, 0, 3]. It can be proven that he can't obtain 6 or more segments that he likes. In the second example, to get 19 segments that Vanya likes, he can perform 4 operations with i = 3, i = 4, i = 5, i = 6 and get an array [1, 4, 3, 0, 4, 3].
instruction
0
79,139
20
158,278
Tags: greedy, implementation Correct Solution: ``` def add(num): if(num<=1): return 0 return (num*(num-1))//2 n,k=map(int,input().split()) a=list(map(int,input().split())) pre=[a[0]] base=(2**(k))-1 hb=2**(k-1) for i in range(1,n): pre.append(a[i]^pre[-1]) cnt=dict() cnt[0]=[0,0] for i in range(n): if(pre[i]>=hb): if(base-pre[i] not in cnt): cnt[base-pre[i]]=[0,0] cnt[base-pre[i]][1]+=1 else: if(pre[i] not in cnt): cnt[pre[i]]=[0,0] cnt[pre[i]][0]+=1 cnt1=0 #print(pre) #print(cnt) for i in cnt.values(): sum1=i[0]+i[1] cnt1+=add(sum1//2) cnt1+=add((sum1+1)//2) cnt1+=sum(cnt[0])//2 #print(cnt1) print((n*(n+1))//2 - cnt1) ```
output
1
79,139
20
158,279
Provide tags and a correct Python 3 solution for this coding contest problem. At a break Vanya came to the class and saw an array of n k-bit integers a_1, a_2, …, a_n on the board. An integer x is called a k-bit integer if 0 ≀ x ≀ 2^k - 1. Of course, Vanya was not able to resist and started changing the numbers written on the board. To ensure that no one will note anything, Vanya allowed himself to make only one type of changes: choose an index of the array i (1 ≀ i ≀ n) and replace the number a_i with the number \overline{a_i}. We define \overline{x} for a k-bit integer x as the k-bit integer such that all its k bits differ from the corresponding bits of x. Vanya does not like the number 0. Therefore, he likes such segments [l, r] (1 ≀ l ≀ r ≀ n) such that a_l βŠ• a_{l+1} βŠ• … βŠ• a_r β‰  0, where βŠ• denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). Determine the maximum number of segments he likes Vanya can get applying zero or more operations described above. Input The first line of the input contains two integers n and k (1 ≀ n ≀ 200 000, 1 ≀ k ≀ 30). The next line contains n integers a_1, a_2, …, a_n (0 ≀ a_i ≀ 2^k - 1), separated by spaces β€” the array of k-bit integers. Output Print one integer β€” the maximum possible number of segments with XOR not equal to 0 that can be obtained by making several (possibly 0) operations described in the statement. Examples Input 3 2 1 3 0 Output 5 Input 6 3 1 4 4 7 3 4 Output 19 Note In the first example if Vasya does not perform any operations, he gets an array that has 5 segments that Vanya likes. If he performs the operation with i = 2, he gets an array [1, 0, 0], because \overline{3} = 0 when k = 2. This array has 3 segments that Vanya likes. Also, to get an array with 5 segments that Vanya likes, he can perform two operations with i = 3 and with i = 2. He then gets an array [1, 0, 3]. It can be proven that he can't obtain 6 or more segments that he likes. In the second example, to get 19 segments that Vanya likes, he can perform 4 operations with i = 3, i = 4, i = 5, i = 6 and get an array [1, 4, 3, 0, 4, 3].
instruction
0
79,140
20
158,280
Tags: greedy, implementation Correct Solution: ``` from sys import stdin, stdout, setrecursionlimit input = stdin.readline # import string # characters = string.ascii_lowercase # digits = string.digits # setrecursionlimit(int(1e6)) # dir = [-1,0,1,0,-1] # moves = 'NESW' inf = float('inf') from functools import cmp_to_key from collections import defaultdict as dd from collections import Counter, deque from heapq import * import math from math import floor, ceil, sqrt def geti(): return map(int, input().strip().split()) def getl(): return list(map(int, input().strip().split())) def getis(): return map(str, input().strip().split()) def getls(): return list(map(str, input().strip().split())) def gets(): return input().strip() def geta(): return int(input()) def print_s(s): stdout.write(s+'\n') def solve(): n, k = geti() a = getl() total = n*(n+1)//2 occur = dd(int) occur[0] = 1 ans = 0 def flip(num): now = ['0']*k # print(bin(num)) for i in range(k): if num&1<<i == 0: now[i] = '1' # print(now) return int(''.join(now[::-1]), 2) xor = 0 for i in a: # print(i, flip(i)) temp = flip(i) xor ^= i temp1 = occur[xor] xor ^= i xor ^= temp temp2 = occur[xor] if temp1 <= temp2: ans += temp1 xor ^= i xor ^= temp occur[xor] += 1 else: occur[xor] += 1 ans += temp2 print(total - ans) if __name__=='__main__': solve() ```
output
1
79,140
20
158,281
Provide tags and a correct Python 3 solution for this coding contest problem. At a break Vanya came to the class and saw an array of n k-bit integers a_1, a_2, …, a_n on the board. An integer x is called a k-bit integer if 0 ≀ x ≀ 2^k - 1. Of course, Vanya was not able to resist and started changing the numbers written on the board. To ensure that no one will note anything, Vanya allowed himself to make only one type of changes: choose an index of the array i (1 ≀ i ≀ n) and replace the number a_i with the number \overline{a_i}. We define \overline{x} for a k-bit integer x as the k-bit integer such that all its k bits differ from the corresponding bits of x. Vanya does not like the number 0. Therefore, he likes such segments [l, r] (1 ≀ l ≀ r ≀ n) such that a_l βŠ• a_{l+1} βŠ• … βŠ• a_r β‰  0, where βŠ• denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). Determine the maximum number of segments he likes Vanya can get applying zero or more operations described above. Input The first line of the input contains two integers n and k (1 ≀ n ≀ 200 000, 1 ≀ k ≀ 30). The next line contains n integers a_1, a_2, …, a_n (0 ≀ a_i ≀ 2^k - 1), separated by spaces β€” the array of k-bit integers. Output Print one integer β€” the maximum possible number of segments with XOR not equal to 0 that can be obtained by making several (possibly 0) operations described in the statement. Examples Input 3 2 1 3 0 Output 5 Input 6 3 1 4 4 7 3 4 Output 19 Note In the first example if Vasya does not perform any operations, he gets an array that has 5 segments that Vanya likes. If he performs the operation with i = 2, he gets an array [1, 0, 0], because \overline{3} = 0 when k = 2. This array has 3 segments that Vanya likes. Also, to get an array with 5 segments that Vanya likes, he can perform two operations with i = 3 and with i = 2. He then gets an array [1, 0, 3]. It can be proven that he can't obtain 6 or more segments that he likes. In the second example, to get 19 segments that Vanya likes, he can perform 4 operations with i = 3, i = 4, i = 5, i = 6 and get an array [1, 4, 3, 0, 4, 3].
instruction
0
79,141
20
158,282
Tags: greedy, implementation Correct Solution: ``` # https://codeforces.com/contest/1054/problem/D n, k = map(int, input().split()) a = list(map(int, input().split())) p = [0] * (n+1) base = (1<<k)-1 def kC2(k): return (k-1) * k// 2 d = {} for i in range(1, n+1): p[i] = p[i-1] ^ a[i-1] p[i] = min(p[i] , p[i] ^ base) if p[i] not in d: d[p[i]] = 0 d[p[i]] += 1 if 0 not in d: d[0] = 0 d[0] += 1 ans = n * (n+1) // 2 minus = 0 for k, v in d.items(): minus += kC2(v // 2) + kC2(v - v // 2) print(ans - minus) #6 3 #1 4 4 7 3 4 ```
output
1
79,141
20
158,283
Provide tags and a correct Python 3 solution for this coding contest problem. At a break Vanya came to the class and saw an array of n k-bit integers a_1, a_2, …, a_n on the board. An integer x is called a k-bit integer if 0 ≀ x ≀ 2^k - 1. Of course, Vanya was not able to resist and started changing the numbers written on the board. To ensure that no one will note anything, Vanya allowed himself to make only one type of changes: choose an index of the array i (1 ≀ i ≀ n) and replace the number a_i with the number \overline{a_i}. We define \overline{x} for a k-bit integer x as the k-bit integer such that all its k bits differ from the corresponding bits of x. Vanya does not like the number 0. Therefore, he likes such segments [l, r] (1 ≀ l ≀ r ≀ n) such that a_l βŠ• a_{l+1} βŠ• … βŠ• a_r β‰  0, where βŠ• denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). Determine the maximum number of segments he likes Vanya can get applying zero or more operations described above. Input The first line of the input contains two integers n and k (1 ≀ n ≀ 200 000, 1 ≀ k ≀ 30). The next line contains n integers a_1, a_2, …, a_n (0 ≀ a_i ≀ 2^k - 1), separated by spaces β€” the array of k-bit integers. Output Print one integer β€” the maximum possible number of segments with XOR not equal to 0 that can be obtained by making several (possibly 0) operations described in the statement. Examples Input 3 2 1 3 0 Output 5 Input 6 3 1 4 4 7 3 4 Output 19 Note In the first example if Vasya does not perform any operations, he gets an array that has 5 segments that Vanya likes. If he performs the operation with i = 2, he gets an array [1, 0, 0], because \overline{3} = 0 when k = 2. This array has 3 segments that Vanya likes. Also, to get an array with 5 segments that Vanya likes, he can perform two operations with i = 3 and with i = 2. He then gets an array [1, 0, 3]. It can be proven that he can't obtain 6 or more segments that he likes. In the second example, to get 19 segments that Vanya likes, he can perform 4 operations with i = 3, i = 4, i = 5, i = 6 and get an array [1, 4, 3, 0, 4, 3].
instruction
0
79,142
20
158,284
Tags: greedy, implementation Correct Solution: ``` from collections import defaultdict n, k = map(int, input().split()) a = [0] + list(map(int, input().split())) h = defaultdict(int) for i in range(n): a[i + 1] ^= a[i] for i in range(n + 1): h[min(a[i] ^ ((1 << k) - 1), a[i])] += 1 ans = 0 for x, t in h.items(): a = t // 2 b = t - a ans += a * (a - 1) // 2 + b * (b - 1) // 2 ans = (n * (n + 1)) // 2 - ans print(ans) ```
output
1
79,142
20
158,285
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. At a break Vanya came to the class and saw an array of n k-bit integers a_1, a_2, …, a_n on the board. An integer x is called a k-bit integer if 0 ≀ x ≀ 2^k - 1. Of course, Vanya was not able to resist and started changing the numbers written on the board. To ensure that no one will note anything, Vanya allowed himself to make only one type of changes: choose an index of the array i (1 ≀ i ≀ n) and replace the number a_i with the number \overline{a_i}. We define \overline{x} for a k-bit integer x as the k-bit integer such that all its k bits differ from the corresponding bits of x. Vanya does not like the number 0. Therefore, he likes such segments [l, r] (1 ≀ l ≀ r ≀ n) such that a_l βŠ• a_{l+1} βŠ• … βŠ• a_r β‰  0, where βŠ• denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). Determine the maximum number of segments he likes Vanya can get applying zero or more operations described above. Input The first line of the input contains two integers n and k (1 ≀ n ≀ 200 000, 1 ≀ k ≀ 30). The next line contains n integers a_1, a_2, …, a_n (0 ≀ a_i ≀ 2^k - 1), separated by spaces β€” the array of k-bit integers. Output Print one integer β€” the maximum possible number of segments with XOR not equal to 0 that can be obtained by making several (possibly 0) operations described in the statement. Examples Input 3 2 1 3 0 Output 5 Input 6 3 1 4 4 7 3 4 Output 19 Note In the first example if Vasya does not perform any operations, he gets an array that has 5 segments that Vanya likes. If he performs the operation with i = 2, he gets an array [1, 0, 0], because \overline{3} = 0 when k = 2. This array has 3 segments that Vanya likes. Also, to get an array with 5 segments that Vanya likes, he can perform two operations with i = 3 and with i = 2. He then gets an array [1, 0, 3]. It can be proven that he can't obtain 6 or more segments that he likes. In the second example, to get 19 segments that Vanya likes, he can perform 4 operations with i = 3, i = 4, i = 5, i = 6 and get an array [1, 4, 3, 0, 4, 3]. Submitted Solution: ``` n, k = [int(i) for i in input().split()] d = dict() d[0] = 1 x = 0 for i in [int(i) for i in input().split()]: x ^= i v = min(x, (1 << k) - x - 1) if v not in d.keys(): d[v] = 0 d[v] += 1 ans = 0 for k, v in d.items(): c1 = v // 2 c2 = v - c1 ans += c1 * (c1 - 1) // 2 + c2 * (c2 - 1) // 2 print(n * (n - 1) // 2 + n - ans) ```
instruction
0
79,143
20
158,286
Yes
output
1
79,143
20
158,287
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. At a break Vanya came to the class and saw an array of n k-bit integers a_1, a_2, …, a_n on the board. An integer x is called a k-bit integer if 0 ≀ x ≀ 2^k - 1. Of course, Vanya was not able to resist and started changing the numbers written on the board. To ensure that no one will note anything, Vanya allowed himself to make only one type of changes: choose an index of the array i (1 ≀ i ≀ n) and replace the number a_i with the number \overline{a_i}. We define \overline{x} for a k-bit integer x as the k-bit integer such that all its k bits differ from the corresponding bits of x. Vanya does not like the number 0. Therefore, he likes such segments [l, r] (1 ≀ l ≀ r ≀ n) such that a_l βŠ• a_{l+1} βŠ• … βŠ• a_r β‰  0, where βŠ• denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). Determine the maximum number of segments he likes Vanya can get applying zero or more operations described above. Input The first line of the input contains two integers n and k (1 ≀ n ≀ 200 000, 1 ≀ k ≀ 30). The next line contains n integers a_1, a_2, …, a_n (0 ≀ a_i ≀ 2^k - 1), separated by spaces β€” the array of k-bit integers. Output Print one integer β€” the maximum possible number of segments with XOR not equal to 0 that can be obtained by making several (possibly 0) operations described in the statement. Examples Input 3 2 1 3 0 Output 5 Input 6 3 1 4 4 7 3 4 Output 19 Note In the first example if Vasya does not perform any operations, he gets an array that has 5 segments that Vanya likes. If he performs the operation with i = 2, he gets an array [1, 0, 0], because \overline{3} = 0 when k = 2. This array has 3 segments that Vanya likes. Also, to get an array with 5 segments that Vanya likes, he can perform two operations with i = 3 and with i = 2. He then gets an array [1, 0, 3]. It can be proven that he can't obtain 6 or more segments that he likes. In the second example, to get 19 segments that Vanya likes, he can perform 4 operations with i = 3, i = 4, i = 5, i = 6 and get an array [1, 4, 3, 0, 4, 3]. Submitted Solution: ``` #Code by Sounak, IIESTS #------------------------------warmup---------------------------- import os import sys import math from io import BytesIO, IOBase from fractions import Fraction import collections from itertools import permutations from collections import defaultdict from collections import deque import threading #sys.setrecursionlimit(300000) #threading.stack_size(10**8) BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") #------------------------------------------------------------------------- #mod = 9223372036854775807 class SegmentTree: def __init__(self, data, default=-10**6, func=lambda a, b: max(a,b)): """initialize the segment tree with data""" self._default = default self._func = func self._len = len(data) self._size = _size = 1 << (self._len - 1).bit_length() self.data = [default] * (2 * _size) self.data[_size:_size + self._len] = data for i in reversed(range(_size)): self.data[i] = func(self.data[i + i], self.data[i + i + 1]) def __delitem__(self, idx): self[idx] = self._default def __getitem__(self, idx): return self.data[idx + self._size] def __setitem__(self, idx, value): idx += self._size self.data[idx] = value idx >>= 1 while idx: self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1]) idx >>= 1 def __len__(self): return self._len def query(self, start, stop): if start == stop: return self.__getitem__(start) stop += 1 start += self._size stop += self._size res = self._default while start < stop: if start & 1: res = self._func(res, self.data[start]) start += 1 if stop & 1: stop -= 1 res = self._func(res, self.data[stop]) start >>= 1 stop >>= 1 return res def __repr__(self): return "SegmentTree({0})".format(self.data) class SegmentTree1: def __init__(self, data, default=10**6, func=lambda a, b: min(a,b)): """initialize the segment tree with data""" self._default = default self._func = func self._len = len(data) self._size = _size = 1 << (self._len - 1).bit_length() self.data = [default] * (2 * _size) self.data[_size:_size + self._len] = data for i in reversed(range(_size)): self.data[i] = func(self.data[i + i], self.data[i + i + 1]) def __delitem__(self, idx): self[idx] = self._default def __getitem__(self, idx): return self.data[idx + self._size] def __setitem__(self, idx, value): idx += self._size self.data[idx] = value idx >>= 1 while idx: self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1]) idx >>= 1 def __len__(self): return self._len def query(self, start, stop): if start == stop: return self.__getitem__(start) stop += 1 start += self._size stop += self._size res = self._default while start < stop: if start & 1: res = self._func(res, self.data[start]) start += 1 if stop & 1: stop -= 1 res = self._func(res, self.data[stop]) start >>= 1 stop >>= 1 return res def __repr__(self): return "SegmentTree({0})".format(self.data) MOD=10**9+7 class Factorial: def __init__(self, MOD): self.MOD = MOD self.factorials = [1, 1] self.invModulos = [0, 1] self.invFactorial_ = [1, 1] def calc(self, n): if n <= -1: print("Invalid argument to calculate n!") print("n must be non-negative value. But the argument was " + str(n)) exit() if n < len(self.factorials): return self.factorials[n] nextArr = [0] * (n + 1 - len(self.factorials)) initialI = len(self.factorials) prev = self.factorials[-1] m = self.MOD for i in range(initialI, n + 1): prev = nextArr[i - initialI] = prev * i % m self.factorials += nextArr return self.factorials[n] def inv(self, n): if n <= -1: print("Invalid argument to calculate n^(-1)") print("n must be non-negative value. But the argument was " + str(n)) exit() p = self.MOD pi = n % p if pi < len(self.invModulos): return self.invModulos[pi] nextArr = [0] * (n + 1 - len(self.invModulos)) initialI = len(self.invModulos) for i in range(initialI, min(p, n + 1)): next = -self.invModulos[p % i] * (p // i) % p self.invModulos.append(next) return self.invModulos[pi] def invFactorial(self, n): if n <= -1: print("Invalid argument to calculate (n^(-1))!") print("n must be non-negative value. But the argument was " + str(n)) exit() if n < len(self.invFactorial_): return self.invFactorial_[n] self.inv(n) # To make sure already calculated n^-1 nextArr = [0] * (n + 1 - len(self.invFactorial_)) initialI = len(self.invFactorial_) prev = self.invFactorial_[-1] p = self.MOD for i in range(initialI, n + 1): prev = nextArr[i - initialI] = (prev * self.invModulos[i % p]) % p self.invFactorial_ += nextArr return self.invFactorial_[n] class Combination: def __init__(self, MOD): self.MOD = MOD self.factorial = Factorial(MOD) def ncr(self, n, k): if k < 0 or n < k: return 0 k = min(k, n - k) f = self.factorial return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD mod=10**9+7 omod=998244353 #------------------------------------------------------------------------- prime = [True for i in range(200001)] pp=[0]*200001 def SieveOfEratosthenes(n=200000): # Create a boolean array "prime[0..n]" and initialize # all entries it as true. A value in prime[i] will # finally be false if i is Not a prime, else true. p = 2 while (p * p <= n): # If prime[p] is not changed, then it is a prime if (prime[p] == True): # Update all multiples of p for i in range(p * p, n+1, p): prime[i] = False p += 1 #---------------------------------running code------------------------------------------ n,k = map(int,input().split()) arr = list(map(int,input().split())) xors = defaultdict(int) xors[0]=1 comp = (1<<k)-1 ans = n*(n+1)//2 xor = 0 for a in arr: xor^=a if xors[xor]>xors[comp^xor]: xor^=comp ans-=xors[xor] xors[xor]+=1 print(ans) ```
instruction
0
79,144
20
158,288
Yes
output
1
79,144
20
158,289
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. At a break Vanya came to the class and saw an array of n k-bit integers a_1, a_2, …, a_n on the board. An integer x is called a k-bit integer if 0 ≀ x ≀ 2^k - 1. Of course, Vanya was not able to resist and started changing the numbers written on the board. To ensure that no one will note anything, Vanya allowed himself to make only one type of changes: choose an index of the array i (1 ≀ i ≀ n) and replace the number a_i with the number \overline{a_i}. We define \overline{x} for a k-bit integer x as the k-bit integer such that all its k bits differ from the corresponding bits of x. Vanya does not like the number 0. Therefore, he likes such segments [l, r] (1 ≀ l ≀ r ≀ n) such that a_l βŠ• a_{l+1} βŠ• … βŠ• a_r β‰  0, where βŠ• denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). Determine the maximum number of segments he likes Vanya can get applying zero or more operations described above. Input The first line of the input contains two integers n and k (1 ≀ n ≀ 200 000, 1 ≀ k ≀ 30). The next line contains n integers a_1, a_2, …, a_n (0 ≀ a_i ≀ 2^k - 1), separated by spaces β€” the array of k-bit integers. Output Print one integer β€” the maximum possible number of segments with XOR not equal to 0 that can be obtained by making several (possibly 0) operations described in the statement. Examples Input 3 2 1 3 0 Output 5 Input 6 3 1 4 4 7 3 4 Output 19 Note In the first example if Vasya does not perform any operations, he gets an array that has 5 segments that Vanya likes. If he performs the operation with i = 2, he gets an array [1, 0, 0], because \overline{3} = 0 when k = 2. This array has 3 segments that Vanya likes. Also, to get an array with 5 segments that Vanya likes, he can perform two operations with i = 3 and with i = 2. He then gets an array [1, 0, 3]. It can be proven that he can't obtain 6 or more segments that he likes. In the second example, to get 19 segments that Vanya likes, he can perform 4 operations with i = 3, i = 4, i = 5, i = 6 and get an array [1, 4, 3, 0, 4, 3]. Submitted Solution: ``` [n, k] = [int(t) for t in input().split(' ')] a = [int(t) for t in input().split(' ')] mask = (1 << k) - 1 def c2(n): return (n * (n - 1)) // 2 count = {} count[0] = 1 p = 0 for i in a: p = p ^ i p = min(p, p ^ mask) count[p] = count.get(p, 0) + 1 res = 0 for [_, cnt] in count.items(): k = cnt // 2 res += c2(k) + c2(cnt - k) print(c2(n + 1) - res) ```
instruction
0
79,145
20
158,290
Yes
output
1
79,145
20
158,291
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. At a break Vanya came to the class and saw an array of n k-bit integers a_1, a_2, …, a_n on the board. An integer x is called a k-bit integer if 0 ≀ x ≀ 2^k - 1. Of course, Vanya was not able to resist and started changing the numbers written on the board. To ensure that no one will note anything, Vanya allowed himself to make only one type of changes: choose an index of the array i (1 ≀ i ≀ n) and replace the number a_i with the number \overline{a_i}. We define \overline{x} for a k-bit integer x as the k-bit integer such that all its k bits differ from the corresponding bits of x. Vanya does not like the number 0. Therefore, he likes such segments [l, r] (1 ≀ l ≀ r ≀ n) such that a_l βŠ• a_{l+1} βŠ• … βŠ• a_r β‰  0, where βŠ• denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). Determine the maximum number of segments he likes Vanya can get applying zero or more operations described above. Input The first line of the input contains two integers n and k (1 ≀ n ≀ 200 000, 1 ≀ k ≀ 30). The next line contains n integers a_1, a_2, …, a_n (0 ≀ a_i ≀ 2^k - 1), separated by spaces β€” the array of k-bit integers. Output Print one integer β€” the maximum possible number of segments with XOR not equal to 0 that can be obtained by making several (possibly 0) operations described in the statement. Examples Input 3 2 1 3 0 Output 5 Input 6 3 1 4 4 7 3 4 Output 19 Note In the first example if Vasya does not perform any operations, he gets an array that has 5 segments that Vanya likes. If he performs the operation with i = 2, he gets an array [1, 0, 0], because \overline{3} = 0 when k = 2. This array has 3 segments that Vanya likes. Also, to get an array with 5 segments that Vanya likes, he can perform two operations with i = 3 and with i = 2. He then gets an array [1, 0, 3]. It can be proven that he can't obtain 6 or more segments that he likes. In the second example, to get 19 segments that Vanya likes, he can perform 4 operations with i = 3, i = 4, i = 5, i = 6 and get an array [1, 4, 3, 0, 4, 3]. Submitted Solution: ``` n,k=map(int,input().split()) a=list(map(int,input().split())) running=[0] for i in range(n): running.append(running[-1]^a[i]) for i in range(n+1): if running[i]>=2**(k-1): running[i]=2**k-1-running[i] running.sort() streaks=[] curr=1 for i in range(n): if running[i]==running[i+1]: curr+=1 else: streaks.append(curr) curr=1 streaks.append(curr) bad=0 for guy in streaks: if guy%2==0: bad+=(guy//2)*(guy//2-1) else: bad+=(guy//2)**2 print((n*(n+1))//2-bad) ```
instruction
0
79,146
20
158,292
Yes
output
1
79,146
20
158,293
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. At a break Vanya came to the class and saw an array of n k-bit integers a_1, a_2, …, a_n on the board. An integer x is called a k-bit integer if 0 ≀ x ≀ 2^k - 1. Of course, Vanya was not able to resist and started changing the numbers written on the board. To ensure that no one will note anything, Vanya allowed himself to make only one type of changes: choose an index of the array i (1 ≀ i ≀ n) and replace the number a_i with the number \overline{a_i}. We define \overline{x} for a k-bit integer x as the k-bit integer such that all its k bits differ from the corresponding bits of x. Vanya does not like the number 0. Therefore, he likes such segments [l, r] (1 ≀ l ≀ r ≀ n) such that a_l βŠ• a_{l+1} βŠ• … βŠ• a_r β‰  0, where βŠ• denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). Determine the maximum number of segments he likes Vanya can get applying zero or more operations described above. Input The first line of the input contains two integers n and k (1 ≀ n ≀ 200 000, 1 ≀ k ≀ 30). The next line contains n integers a_1, a_2, …, a_n (0 ≀ a_i ≀ 2^k - 1), separated by spaces β€” the array of k-bit integers. Output Print one integer β€” the maximum possible number of segments with XOR not equal to 0 that can be obtained by making several (possibly 0) operations described in the statement. Examples Input 3 2 1 3 0 Output 5 Input 6 3 1 4 4 7 3 4 Output 19 Note In the first example if Vasya does not perform any operations, he gets an array that has 5 segments that Vanya likes. If he performs the operation with i = 2, he gets an array [1, 0, 0], because \overline{3} = 0 when k = 2. This array has 3 segments that Vanya likes. Also, to get an array with 5 segments that Vanya likes, he can perform two operations with i = 3 and with i = 2. He then gets an array [1, 0, 3]. It can be proven that he can't obtain 6 or more segments that he likes. In the second example, to get 19 segments that Vanya likes, he can perform 4 operations with i = 3, i = 4, i = 5, i = 6 and get an array [1, 4, 3, 0, 4, 3]. Submitted Solution: ``` from math import * #n,k=map(int,input().split()) #A = list(map(int,input().split())) n,k = map(int,input().split()) ans = [0] * n #^xor lul = 2**k - 1 A = list(map(int,input().split())) ans[0] = A[0] for j in range(1, n): ans[j] = ans[j-1]^A[j] #print(ans) d = dict() for j in range(n): if ans[j] in d: d[ans[j]]+=1; else: d[ans[j]] = 1 #print(d) ans =0 def huy(n): return n*(n-1)//2 for j in d: now = d[j] #print(d[j],j) xor = lul^j cur = now if xor in d : now2 = d[xor] #print(now,xor) cur += now2 #print(cur) ans += huy(cur//2+cur%2) ans+=huy(cur//2) print(huy(n+1) - ans//2) ```
instruction
0
79,147
20
158,294
No
output
1
79,147
20
158,295
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. At a break Vanya came to the class and saw an array of n k-bit integers a_1, a_2, …, a_n on the board. An integer x is called a k-bit integer if 0 ≀ x ≀ 2^k - 1. Of course, Vanya was not able to resist and started changing the numbers written on the board. To ensure that no one will note anything, Vanya allowed himself to make only one type of changes: choose an index of the array i (1 ≀ i ≀ n) and replace the number a_i with the number \overline{a_i}. We define \overline{x} for a k-bit integer x as the k-bit integer such that all its k bits differ from the corresponding bits of x. Vanya does not like the number 0. Therefore, he likes such segments [l, r] (1 ≀ l ≀ r ≀ n) such that a_l βŠ• a_{l+1} βŠ• … βŠ• a_r β‰  0, where βŠ• denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). Determine the maximum number of segments he likes Vanya can get applying zero or more operations described above. Input The first line of the input contains two integers n and k (1 ≀ n ≀ 200 000, 1 ≀ k ≀ 30). The next line contains n integers a_1, a_2, …, a_n (0 ≀ a_i ≀ 2^k - 1), separated by spaces β€” the array of k-bit integers. Output Print one integer β€” the maximum possible number of segments with XOR not equal to 0 that can be obtained by making several (possibly 0) operations described in the statement. Examples Input 3 2 1 3 0 Output 5 Input 6 3 1 4 4 7 3 4 Output 19 Note In the first example if Vasya does not perform any operations, he gets an array that has 5 segments that Vanya likes. If he performs the operation with i = 2, he gets an array [1, 0, 0], because \overline{3} = 0 when k = 2. This array has 3 segments that Vanya likes. Also, to get an array with 5 segments that Vanya likes, he can perform two operations with i = 3 and with i = 2. He then gets an array [1, 0, 3]. It can be proven that he can't obtain 6 or more segments that he likes. In the second example, to get 19 segments that Vanya likes, he can perform 4 operations with i = 3, i = 4, i = 5, i = 6 and get an array [1, 4, 3, 0, 4, 3]. Submitted Solution: ``` [n, k] = [int(t) for t in input().split(' ')] a = [int(t) for t in input().split(' ')] mask = (1 << k) - 1 p = [0] count = {} for i in a: pi = p[len(p) - 1] ^ i p.append(pi) for i in range(1, len(p)): pi = min(p[i], p[i] ^ mask) p[i] = pi count[pi] = count.get(pi, 0) + 1 res = 0 for [s, cnt] in count.items(): pairs_low = (cnt // 2) * (cnt // 2 - 1) // 2 pairs_high = (cnt - cnt // 2) * (cnt - cnt // 2 - 1) // 2 res += pairs_low + pairs_high print((n + 1) * n // 2 - res) ```
instruction
0
79,148
20
158,296
No
output
1
79,148
20
158,297
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. At a break Vanya came to the class and saw an array of n k-bit integers a_1, a_2, …, a_n on the board. An integer x is called a k-bit integer if 0 ≀ x ≀ 2^k - 1. Of course, Vanya was not able to resist and started changing the numbers written on the board. To ensure that no one will note anything, Vanya allowed himself to make only one type of changes: choose an index of the array i (1 ≀ i ≀ n) and replace the number a_i with the number \overline{a_i}. We define \overline{x} for a k-bit integer x as the k-bit integer such that all its k bits differ from the corresponding bits of x. Vanya does not like the number 0. Therefore, he likes such segments [l, r] (1 ≀ l ≀ r ≀ n) such that a_l βŠ• a_{l+1} βŠ• … βŠ• a_r β‰  0, where βŠ• denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). Determine the maximum number of segments he likes Vanya can get applying zero or more operations described above. Input The first line of the input contains two integers n and k (1 ≀ n ≀ 200 000, 1 ≀ k ≀ 30). The next line contains n integers a_1, a_2, …, a_n (0 ≀ a_i ≀ 2^k - 1), separated by spaces β€” the array of k-bit integers. Output Print one integer β€” the maximum possible number of segments with XOR not equal to 0 that can be obtained by making several (possibly 0) operations described in the statement. Examples Input 3 2 1 3 0 Output 5 Input 6 3 1 4 4 7 3 4 Output 19 Note In the first example if Vasya does not perform any operations, he gets an array that has 5 segments that Vanya likes. If he performs the operation with i = 2, he gets an array [1, 0, 0], because \overline{3} = 0 when k = 2. This array has 3 segments that Vanya likes. Also, to get an array with 5 segments that Vanya likes, he can perform two operations with i = 3 and with i = 2. He then gets an array [1, 0, 3]. It can be proven that he can't obtain 6 or more segments that he likes. In the second example, to get 19 segments that Vanya likes, he can perform 4 operations with i = 3, i = 4, i = 5, i = 6 and get an array [1, 4, 3, 0, 4, 3]. Submitted Solution: ``` [n, k] = [int(t) for t in input().split(' ')] a = [int(t) for t in input().split(' ')] mask = (1 << k) - 1 def c2(n): return (n * (n - 1)) // 2 count = {} p = 0 for i in a: p ^= min(i, i ^ mask) count[p] = count.get(p, 0) + 1 res = 0 for [_, cnt] in count.items(): k = cnt // 2 res += c2(k) + c2(cnt - k) print(c2(n + 1) - res) ```
instruction
0
79,149
20
158,298
No
output
1
79,149
20
158,299
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. At a break Vanya came to the class and saw an array of n k-bit integers a_1, a_2, …, a_n on the board. An integer x is called a k-bit integer if 0 ≀ x ≀ 2^k - 1. Of course, Vanya was not able to resist and started changing the numbers written on the board. To ensure that no one will note anything, Vanya allowed himself to make only one type of changes: choose an index of the array i (1 ≀ i ≀ n) and replace the number a_i with the number \overline{a_i}. We define \overline{x} for a k-bit integer x as the k-bit integer such that all its k bits differ from the corresponding bits of x. Vanya does not like the number 0. Therefore, he likes such segments [l, r] (1 ≀ l ≀ r ≀ n) such that a_l βŠ• a_{l+1} βŠ• … βŠ• a_r β‰  0, where βŠ• denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). Determine the maximum number of segments he likes Vanya can get applying zero or more operations described above. Input The first line of the input contains two integers n and k (1 ≀ n ≀ 200 000, 1 ≀ k ≀ 30). The next line contains n integers a_1, a_2, …, a_n (0 ≀ a_i ≀ 2^k - 1), separated by spaces β€” the array of k-bit integers. Output Print one integer β€” the maximum possible number of segments with XOR not equal to 0 that can be obtained by making several (possibly 0) operations described in the statement. Examples Input 3 2 1 3 0 Output 5 Input 6 3 1 4 4 7 3 4 Output 19 Note In the first example if Vasya does not perform any operations, he gets an array that has 5 segments that Vanya likes. If he performs the operation with i = 2, he gets an array [1, 0, 0], because \overline{3} = 0 when k = 2. This array has 3 segments that Vanya likes. Also, to get an array with 5 segments that Vanya likes, he can perform two operations with i = 3 and with i = 2. He then gets an array [1, 0, 3]. It can be proven that he can't obtain 6 or more segments that he likes. In the second example, to get 19 segments that Vanya likes, he can perform 4 operations with i = 3, i = 4, i = 5, i = 6 and get an array [1, 4, 3, 0, 4, 3]. Submitted Solution: ``` import collections if __name__ == '__main__': n,k = map(int, input().split()) a = list(map(int, input().split())) p = 0 d = collections.Counter() limit = 1 << (k-1) mask = (1 << k) - 1 for i in range(n): p ^= min(a[i], mask-a[i]) d[p] += 1 res = 0 for key in d: i = d[key] // 2 j = d[key] - i res += (i-1)*i//2 + (j-1)*j//2 res = n*(n+1)//2 - res print(res) ```
instruction
0
79,150
20
158,300
No
output
1
79,150
20
158,301
Provide tags and a correct Python 3 solution for this coding contest problem. The well-known Fibonacci sequence F_0, F_1, F_2,… is defined as follows: * F_0 = 0, F_1 = 1. * For each i β‰₯ 2: F_i = F_{i - 1} + F_{i - 2}. Given an increasing arithmetic sequence of positive integers with n elements: (a, a + d, a + 2β‹… d,…, a + (n - 1)β‹… d). You need to find another increasing arithmetic sequence of positive integers with n elements (b, b + e, b + 2β‹… e,…, b + (n - 1)β‹… e) such that: * 0 < b, e < 2^{64}, * for all 0≀ i < n, the decimal representation of a + i β‹… d appears as substring in the last 18 digits of the decimal representation of F_{b + i β‹… e} (if this number has less than 18 digits, then we consider all its digits). Input The first line contains three positive integers n, a, d (1 ≀ n, a, d, a + (n - 1) β‹… d < 10^6). Output If no such arithmetic sequence exists, print -1. Otherwise, print two integers b and e, separated by space in a single line (0 < b, e < 2^{64}). If there are many answers, you can output any of them. Examples Input 3 1 1 Output 2 1 Input 5 1 2 Output 19 5 Note In the first test case, we can choose (b, e) = (2, 1), because F_2 = 1, F_3 = 2, F_4 = 3. In the second test case, we can choose (b, e) = (19, 5) because: * F_{19} = 4181 contains 1; * F_{24} = 46368 contains 3; * F_{29} = 514229 contains 5; * F_{34} = 5702887 contains 7; * F_{39} = 63245986 contains 9.
instruction
0
79,267
20
158,534
Tags: constructive algorithms, number theory Correct Solution: ``` n, a, d = map(int, input().split()); pis = 12 * 1000000000; bas = 368131125; print((bas * a) % (1000000000) * pis + 1, (bas * d) % (1000000000) * pis); ```
output
1
79,267
20
158,535
Provide tags and a correct Python 3 solution for this coding contest problem. The well-known Fibonacci sequence F_0, F_1, F_2,… is defined as follows: * F_0 = 0, F_1 = 1. * For each i β‰₯ 2: F_i = F_{i - 1} + F_{i - 2}. Given an increasing arithmetic sequence of positive integers with n elements: (a, a + d, a + 2β‹… d,…, a + (n - 1)β‹… d). You need to find another increasing arithmetic sequence of positive integers with n elements (b, b + e, b + 2β‹… e,…, b + (n - 1)β‹… e) such that: * 0 < b, e < 2^{64}, * for all 0≀ i < n, the decimal representation of a + i β‹… d appears as substring in the last 18 digits of the decimal representation of F_{b + i β‹… e} (if this number has less than 18 digits, then we consider all its digits). Input The first line contains three positive integers n, a, d (1 ≀ n, a, d, a + (n - 1) β‹… d < 10^6). Output If no such arithmetic sequence exists, print -1. Otherwise, print two integers b and e, separated by space in a single line (0 < b, e < 2^{64}). If there are many answers, you can output any of them. Examples Input 3 1 1 Output 2 1 Input 5 1 2 Output 19 5 Note In the first test case, we can choose (b, e) = (2, 1), because F_2 = 1, F_3 = 2, F_4 = 3. In the second test case, we can choose (b, e) = (19, 5) because: * F_{19} = 4181 contains 1; * F_{24} = 46368 contains 3; * F_{29} = 514229 contains 5; * F_{34} = 5702887 contains 7; * F_{39} = 63245986 contains 9.
instruction
0
79,268
20
158,536
Tags: constructive algorithms, number theory Correct Solution: ``` val = 3337867500 n,a,d = map(int, input().split()) print(val * a, val * d) ```
output
1
79,268
20
158,537
Provide tags and a correct Python 3 solution for this coding contest problem. The well-known Fibonacci sequence F_0, F_1, F_2,… is defined as follows: * F_0 = 0, F_1 = 1. * For each i β‰₯ 2: F_i = F_{i - 1} + F_{i - 2}. Given an increasing arithmetic sequence of positive integers with n elements: (a, a + d, a + 2β‹… d,…, a + (n - 1)β‹… d). You need to find another increasing arithmetic sequence of positive integers with n elements (b, b + e, b + 2β‹… e,…, b + (n - 1)β‹… e) such that: * 0 < b, e < 2^{64}, * for all 0≀ i < n, the decimal representation of a + i β‹… d appears as substring in the last 18 digits of the decimal representation of F_{b + i β‹… e} (if this number has less than 18 digits, then we consider all its digits). Input The first line contains three positive integers n, a, d (1 ≀ n, a, d, a + (n - 1) β‹… d < 10^6). Output If no such arithmetic sequence exists, print -1. Otherwise, print two integers b and e, separated by space in a single line (0 < b, e < 2^{64}). If there are many answers, you can output any of them. Examples Input 3 1 1 Output 2 1 Input 5 1 2 Output 19 5 Note In the first test case, we can choose (b, e) = (2, 1), because F_2 = 1, F_3 = 2, F_4 = 3. In the second test case, we can choose (b, e) = (19, 5) because: * F_{19} = 4181 contains 1; * F_{24} = 46368 contains 3; * F_{29} = 514229 contains 5; * F_{34} = 5702887 contains 7; * F_{39} = 63245986 contains 9.
instruction
0
79,269
20
158,538
Tags: constructive algorithms, number theory Correct Solution: ``` v=708786750000 n,a,d=map(int,input().split()) print(v*a,v*d) ```
output
1
79,269
20
158,539
Provide tags and a correct Python 3 solution for this coding contest problem. The well-known Fibonacci sequence F_0, F_1, F_2,… is defined as follows: * F_0 = 0, F_1 = 1. * For each i β‰₯ 2: F_i = F_{i - 1} + F_{i - 2}. Given an increasing arithmetic sequence of positive integers with n elements: (a, a + d, a + 2β‹… d,…, a + (n - 1)β‹… d). You need to find another increasing arithmetic sequence of positive integers with n elements (b, b + e, b + 2β‹… e,…, b + (n - 1)β‹… e) such that: * 0 < b, e < 2^{64}, * for all 0≀ i < n, the decimal representation of a + i β‹… d appears as substring in the last 18 digits of the decimal representation of F_{b + i β‹… e} (if this number has less than 18 digits, then we consider all its digits). Input The first line contains three positive integers n, a, d (1 ≀ n, a, d, a + (n - 1) β‹… d < 10^6). Output If no such arithmetic sequence exists, print -1. Otherwise, print two integers b and e, separated by space in a single line (0 < b, e < 2^{64}). If there are many answers, you can output any of them. Examples Input 3 1 1 Output 2 1 Input 5 1 2 Output 19 5 Note In the first test case, we can choose (b, e) = (2, 1), because F_2 = 1, F_3 = 2, F_4 = 3. In the second test case, we can choose (b, e) = (19, 5) because: * F_{19} = 4181 contains 1; * F_{24} = 46368 contains 3; * F_{29} = 514229 contains 5; * F_{34} = 5702887 contains 7; * F_{39} = 63245986 contains 9.
instruction
0
79,270
20
158,540
Tags: constructive algorithms, number theory Correct Solution: ``` n,a,d = map(int,input().split()) it = 114945049 N = 12*(10**9) u = 125*a*it%(10**9) v = 125*d*it%(10**9) print(u*N+1,v*N) ```
output
1
79,270
20
158,541
Provide tags and a correct Python 3 solution for this coding contest problem. The well-known Fibonacci sequence F_0, F_1, F_2,… is defined as follows: * F_0 = 0, F_1 = 1. * For each i β‰₯ 2: F_i = F_{i - 1} + F_{i - 2}. Given an increasing arithmetic sequence of positive integers with n elements: (a, a + d, a + 2β‹… d,…, a + (n - 1)β‹… d). You need to find another increasing arithmetic sequence of positive integers with n elements (b, b + e, b + 2β‹… e,…, b + (n - 1)β‹… e) such that: * 0 < b, e < 2^{64}, * for all 0≀ i < n, the decimal representation of a + i β‹… d appears as substring in the last 18 digits of the decimal representation of F_{b + i β‹… e} (if this number has less than 18 digits, then we consider all its digits). Input The first line contains three positive integers n, a, d (1 ≀ n, a, d, a + (n - 1) β‹… d < 10^6). Output If no such arithmetic sequence exists, print -1. Otherwise, print two integers b and e, separated by space in a single line (0 < b, e < 2^{64}). If there are many answers, you can output any of them. Examples Input 3 1 1 Output 2 1 Input 5 1 2 Output 19 5 Note In the first test case, we can choose (b, e) = (2, 1), because F_2 = 1, F_3 = 2, F_4 = 3. In the second test case, we can choose (b, e) = (19, 5) because: * F_{19} = 4181 contains 1; * F_{24} = 46368 contains 3; * F_{29} = 514229 contains 5; * F_{34} = 5702887 contains 7; * F_{39} = 63245986 contains 9.
instruction
0
79,271
20
158,542
Tags: constructive algorithms, number theory Correct Solution: ``` n,a,d = map(int,input().split()) it = 614945049 N = 3*(10**9)//2 u = a*it%(10**9) v = d*it%(10**9) print(u*N+1,v*N) ```
output
1
79,271
20
158,543
Provide tags and a correct Python 3 solution for this coding contest problem. The well-known Fibonacci sequence F_0, F_1, F_2,… is defined as follows: * F_0 = 0, F_1 = 1. * For each i β‰₯ 2: F_i = F_{i - 1} + F_{i - 2}. Given an increasing arithmetic sequence of positive integers with n elements: (a, a + d, a + 2β‹… d,…, a + (n - 1)β‹… d). You need to find another increasing arithmetic sequence of positive integers with n elements (b, b + e, b + 2β‹… e,…, b + (n - 1)β‹… e) such that: * 0 < b, e < 2^{64}, * for all 0≀ i < n, the decimal representation of a + i β‹… d appears as substring in the last 18 digits of the decimal representation of F_{b + i β‹… e} (if this number has less than 18 digits, then we consider all its digits). Input The first line contains three positive integers n, a, d (1 ≀ n, a, d, a + (n - 1) β‹… d < 10^6). Output If no such arithmetic sequence exists, print -1. Otherwise, print two integers b and e, separated by space in a single line (0 < b, e < 2^{64}). If there are many answers, you can output any of them. Examples Input 3 1 1 Output 2 1 Input 5 1 2 Output 19 5 Note In the first test case, we can choose (b, e) = (2, 1), because F_2 = 1, F_3 = 2, F_4 = 3. In the second test case, we can choose (b, e) = (19, 5) because: * F_{19} = 4181 contains 1; * F_{24} = 46368 contains 3; * F_{29} = 514229 contains 5; * F_{34} = 5702887 contains 7; * F_{39} = 63245986 contains 9.
instruction
0
79,272
20
158,544
Tags: constructive algorithms, number theory Correct Solution: ``` _, a, d = map(int, input().split()) ten_k = 10 ** 9 n = 12 * ten_k # F(n + 1) === 673419592000000001 # t = 84177449 t_inv = 1114945049 u = 125 * a * t_inv % ten_k v = 125 * d * t_inv % ten_k b = u * n + 1 e = v * n print(b, e) ```
output
1
79,272
20
158,545
Provide tags and a correct Python 3 solution for this coding contest problem. The well-known Fibonacci sequence F_0, F_1, F_2,… is defined as follows: * F_0 = 0, F_1 = 1. * For each i β‰₯ 2: F_i = F_{i - 1} + F_{i - 2}. Given an increasing arithmetic sequence of positive integers with n elements: (a, a + d, a + 2β‹… d,…, a + (n - 1)β‹… d). You need to find another increasing arithmetic sequence of positive integers with n elements (b, b + e, b + 2β‹… e,…, b + (n - 1)β‹… e) such that: * 0 < b, e < 2^{64}, * for all 0≀ i < n, the decimal representation of a + i β‹… d appears as substring in the last 18 digits of the decimal representation of F_{b + i β‹… e} (if this number has less than 18 digits, then we consider all its digits). Input The first line contains three positive integers n, a, d (1 ≀ n, a, d, a + (n - 1) β‹… d < 10^6). Output If no such arithmetic sequence exists, print -1. Otherwise, print two integers b and e, separated by space in a single line (0 < b, e < 2^{64}). If there are many answers, you can output any of them. Examples Input 3 1 1 Output 2 1 Input 5 1 2 Output 19 5 Note In the first test case, we can choose (b, e) = (2, 1), because F_2 = 1, F_3 = 2, F_4 = 3. In the second test case, we can choose (b, e) = (19, 5) because: * F_{19} = 4181 contains 1; * F_{24} = 46368 contains 3; * F_{29} = 514229 contains 5; * F_{34} = 5702887 contains 7; * F_{39} = 63245986 contains 9.
instruction
0
79,273
20
158,546
Tags: constructive algorithms, number theory Correct Solution: ``` v,m=3337867500,15*10**9 n,a,d=map(int,input().split()) print(v*a%m,v*d%m) ```
output
1
79,273
20
158,547
Provide tags and a correct Python 3 solution for this coding contest problem. The well-known Fibonacci sequence F_0, F_1, F_2,… is defined as follows: * F_0 = 0, F_1 = 1. * For each i β‰₯ 2: F_i = F_{i - 1} + F_{i - 2}. Given an increasing arithmetic sequence of positive integers with n elements: (a, a + d, a + 2β‹… d,…, a + (n - 1)β‹… d). You need to find another increasing arithmetic sequence of positive integers with n elements (b, b + e, b + 2β‹… e,…, b + (n - 1)β‹… e) such that: * 0 < b, e < 2^{64}, * for all 0≀ i < n, the decimal representation of a + i β‹… d appears as substring in the last 18 digits of the decimal representation of F_{b + i β‹… e} (if this number has less than 18 digits, then we consider all its digits). Input The first line contains three positive integers n, a, d (1 ≀ n, a, d, a + (n - 1) β‹… d < 10^6). Output If no such arithmetic sequence exists, print -1. Otherwise, print two integers b and e, separated by space in a single line (0 < b, e < 2^{64}). If there are many answers, you can output any of them. Examples Input 3 1 1 Output 2 1 Input 5 1 2 Output 19 5 Note In the first test case, we can choose (b, e) = (2, 1), because F_2 = 1, F_3 = 2, F_4 = 3. In the second test case, we can choose (b, e) = (19, 5) because: * F_{19} = 4181 contains 1; * F_{24} = 46368 contains 3; * F_{29} = 514229 contains 5; * F_{34} = 5702887 contains 7; * F_{39} = 63245986 contains 9.
instruction
0
79,274
20
158,548
Tags: constructive algorithms, number theory Correct Solution: ``` value=3337867500; a,b,c=map(int,input().split()); print(value*b,value*c); ```
output
1
79,274
20
158,549
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The well-known Fibonacci sequence F_0, F_1, F_2,… is defined as follows: * F_0 = 0, F_1 = 1. * For each i β‰₯ 2: F_i = F_{i - 1} + F_{i - 2}. Given an increasing arithmetic sequence of positive integers with n elements: (a, a + d, a + 2β‹… d,…, a + (n - 1)β‹… d). You need to find another increasing arithmetic sequence of positive integers with n elements (b, b + e, b + 2β‹… e,…, b + (n - 1)β‹… e) such that: * 0 < b, e < 2^{64}, * for all 0≀ i < n, the decimal representation of a + i β‹… d appears as substring in the last 18 digits of the decimal representation of F_{b + i β‹… e} (if this number has less than 18 digits, then we consider all its digits). Input The first line contains three positive integers n, a, d (1 ≀ n, a, d, a + (n - 1) β‹… d < 10^6). Output If no such arithmetic sequence exists, print -1. Otherwise, print two integers b and e, separated by space in a single line (0 < b, e < 2^{64}). If there are many answers, you can output any of them. Examples Input 3 1 1 Output 2 1 Input 5 1 2 Output 19 5 Note In the first test case, we can choose (b, e) = (2, 1), because F_2 = 1, F_3 = 2, F_4 = 3. In the second test case, we can choose (b, e) = (19, 5) because: * F_{19} = 4181 contains 1; * F_{24} = 46368 contains 3; * F_{29} = 514229 contains 5; * F_{34} = 5702887 contains 7; * F_{39} = 63245986 contains 9. Submitted Solution: ``` c=9224175735*10**8 m=15*10**17 n,a,d=map(int,input().split()) print(c*a%m+1,c*d%m) ```
instruction
0
79,276
20
158,552
Yes
output
1
79,276
20
158,553
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The well-known Fibonacci sequence F_0, F_1, F_2,… is defined as follows: * F_0 = 0, F_1 = 1. * For each i β‰₯ 2: F_i = F_{i - 1} + F_{i - 2}. Given an increasing arithmetic sequence of positive integers with n elements: (a, a + d, a + 2β‹… d,…, a + (n - 1)β‹… d). You need to find another increasing arithmetic sequence of positive integers with n elements (b, b + e, b + 2β‹… e,…, b + (n - 1)β‹… e) such that: * 0 < b, e < 2^{64}, * for all 0≀ i < n, the decimal representation of a + i β‹… d appears as substring in the last 18 digits of the decimal representation of F_{b + i β‹… e} (if this number has less than 18 digits, then we consider all its digits). Input The first line contains three positive integers n, a, d (1 ≀ n, a, d, a + (n - 1) β‹… d < 10^6). Output If no such arithmetic sequence exists, print -1. Otherwise, print two integers b and e, separated by space in a single line (0 < b, e < 2^{64}). If there are many answers, you can output any of them. Examples Input 3 1 1 Output 2 1 Input 5 1 2 Output 19 5 Note In the first test case, we can choose (b, e) = (2, 1), because F_2 = 1, F_3 = 2, F_4 = 3. In the second test case, we can choose (b, e) = (19, 5) because: * F_{19} = 4181 contains 1; * F_{24} = 46368 contains 3; * F_{29} = 514229 contains 5; * F_{34} = 5702887 contains 7; * F_{39} = 63245986 contains 9. Submitted Solution: ``` cons = 3337867500 Inputs=list(int(x) for x in input().split()) n=Inputs[0] a=Inputs[1] d=Inputs[2] print(cons * a, cons * d) ```
instruction
0
79,277
20
158,554
Yes
output
1
79,277
20
158,555
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The well-known Fibonacci sequence F_0, F_1, F_2,… is defined as follows: * F_0 = 0, F_1 = 1. * For each i β‰₯ 2: F_i = F_{i - 1} + F_{i - 2}. Given an increasing arithmetic sequence of positive integers with n elements: (a, a + d, a + 2β‹… d,…, a + (n - 1)β‹… d). You need to find another increasing arithmetic sequence of positive integers with n elements (b, b + e, b + 2β‹… e,…, b + (n - 1)β‹… e) such that: * 0 < b, e < 2^{64}, * for all 0≀ i < n, the decimal representation of a + i β‹… d appears as substring in the last 18 digits of the decimal representation of F_{b + i β‹… e} (if this number has less than 18 digits, then we consider all its digits). Input The first line contains three positive integers n, a, d (1 ≀ n, a, d, a + (n - 1) β‹… d < 10^6). Output If no such arithmetic sequence exists, print -1. Otherwise, print two integers b and e, separated by space in a single line (0 < b, e < 2^{64}). If there are many answers, you can output any of them. Examples Input 3 1 1 Output 2 1 Input 5 1 2 Output 19 5 Note In the first test case, we can choose (b, e) = (2, 1), because F_2 = 1, F_3 = 2, F_4 = 3. In the second test case, we can choose (b, e) = (19, 5) because: * F_{19} = 4181 contains 1; * F_{24} = 46368 contains 3; * F_{29} = 514229 contains 5; * F_{34} = 5702887 contains 7; * F_{39} = 63245986 contains 9. Submitted Solution: ``` o,m,k=map(int,input().split()) print(368131125*m%10**9*12*10**9+1,368131125*k%10**9*12*10**9) ```
instruction
0
79,278
20
158,556
Yes
output
1
79,278
20
158,557
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The well-known Fibonacci sequence F_0, F_1, F_2,… is defined as follows: * F_0 = 0, F_1 = 1. * For each i β‰₯ 2: F_i = F_{i - 1} + F_{i - 2}. Given an increasing arithmetic sequence of positive integers with n elements: (a, a + d, a + 2β‹… d,…, a + (n - 1)β‹… d). You need to find another increasing arithmetic sequence of positive integers with n elements (b, b + e, b + 2β‹… e,…, b + (n - 1)β‹… e) such that: * 0 < b, e < 2^{64}, * for all 0≀ i < n, the decimal representation of a + i β‹… d appears as substring in the last 18 digits of the decimal representation of F_{b + i β‹… e} (if this number has less than 18 digits, then we consider all its digits). Input The first line contains three positive integers n, a, d (1 ≀ n, a, d, a + (n - 1) β‹… d < 10^6). Output If no such arithmetic sequence exists, print -1. Otherwise, print two integers b and e, separated by space in a single line (0 < b, e < 2^{64}). If there are many answers, you can output any of them. Examples Input 3 1 1 Output 2 1 Input 5 1 2 Output 19 5 Note In the first test case, we can choose (b, e) = (2, 1), because F_2 = 1, F_3 = 2, F_4 = 3. In the second test case, we can choose (b, e) = (19, 5) because: * F_{19} = 4181 contains 1; * F_{24} = 46368 contains 3; * F_{29} = 514229 contains 5; * F_{34} = 5702887 contains 7; * F_{39} = 63245986 contains 9. Submitted Solution: ``` v,m=3337867500,15*10**8 n,a,d=map(int,input().split()) print(v*a%m,v*d%m) ```
instruction
0
79,280
20
158,560
No
output
1
79,280
20
158,561
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The well-known Fibonacci sequence F_0, F_1, F_2,… is defined as follows: * F_0 = 0, F_1 = 1. * For each i β‰₯ 2: F_i = F_{i - 1} + F_{i - 2}. Given an increasing arithmetic sequence of positive integers with n elements: (a, a + d, a + 2β‹… d,…, a + (n - 1)β‹… d). You need to find another increasing arithmetic sequence of positive integers with n elements (b, b + e, b + 2β‹… e,…, b + (n - 1)β‹… e) such that: * 0 < b, e < 2^{64}, * for all 0≀ i < n, the decimal representation of a + i β‹… d appears as substring in the last 18 digits of the decimal representation of F_{b + i β‹… e} (if this number has less than 18 digits, then we consider all its digits). Input The first line contains three positive integers n, a, d (1 ≀ n, a, d, a + (n - 1) β‹… d < 10^6). Output If no such arithmetic sequence exists, print -1. Otherwise, print two integers b and e, separated by space in a single line (0 < b, e < 2^{64}). If there are many answers, you can output any of them. Examples Input 3 1 1 Output 2 1 Input 5 1 2 Output 19 5 Note In the first test case, we can choose (b, e) = (2, 1), because F_2 = 1, F_3 = 2, F_4 = 3. In the second test case, we can choose (b, e) = (19, 5) because: * F_{19} = 4181 contains 1; * F_{24} = 46368 contains 3; * F_{29} = 514229 contains 5; * F_{34} = 5702887 contains 7; * F_{39} = 63245986 contains 9. Submitted Solution: ``` val = 368131125%10**9*12*10**9 n, a, d = map(int, input().split()) print(val*a+1,val*d) ```
instruction
0
79,282
20
158,564
No
output
1
79,282
20
158,565
Provide tags and a correct Python 3 solution for this coding contest problem. Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits a and b. Vitaly calls a good number excellent, if the sum of its digits is a good number. For example, let's say that Vitaly's favourite digits are 1 and 3, then number 12 isn't good and numbers 13 or 311 are. Also, number 111 is excellent and number 11 isn't. Now Vitaly is wondering, how many excellent numbers of length exactly n are there. As this number can be rather large, he asks you to count the remainder after dividing it by 1000000007 (109 + 7). A number's length is the number of digits in its decimal representation without leading zeroes. Input The first line contains three integers: a, b, n (1 ≀ a < b ≀ 9, 1 ≀ n ≀ 106). Output Print a single integer β€” the answer to the problem modulo 1000000007 (109 + 7). Examples Input 1 3 3 Output 1 Input 2 3 10 Output 165
instruction
0
79,418
20
158,836
Tags: brute force, combinatorics Correct Solution: ``` a,b,n = map(int,input().split()) m =1000000007 fact = [1] for i in range(1,n+1): fact.append((fact[-1]*i)%m) ans = 0 for i in range(n+1): su = (a*i) + b*(n-i) coef = 1 while(su>0): if(su%10 != a and su%10!=b): coef = 0; su//=10 if coef: ans+=(fact[n]*pow((fact[i]*fact[n-i]),m-2,m)) ans= ans%m print(ans%m) ```
output
1
79,418
20
158,837
Provide tags and a correct Python 3 solution for this coding contest problem. Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits a and b. Vitaly calls a good number excellent, if the sum of its digits is a good number. For example, let's say that Vitaly's favourite digits are 1 and 3, then number 12 isn't good and numbers 13 or 311 are. Also, number 111 is excellent and number 11 isn't. Now Vitaly is wondering, how many excellent numbers of length exactly n are there. As this number can be rather large, he asks you to count the remainder after dividing it by 1000000007 (109 + 7). A number's length is the number of digits in its decimal representation without leading zeroes. Input The first line contains three integers: a, b, n (1 ≀ a < b ≀ 9, 1 ≀ n ≀ 106). Output Print a single integer β€” the answer to the problem modulo 1000000007 (109 + 7). Examples Input 1 3 3 Output 1 Input 2 3 10 Output 165
instruction
0
79,419
20
158,838
Tags: brute force, combinatorics Correct Solution: ``` MOD = int(1e9+7) def fast_power(b, e): res = 1 while e > 0: if e % 2 == 1: res = res * b % MOD b = b * b % MOD e //= 2 return res a, b, n = map(int, input().split()) s, res = set(), 0 for x in range(2, 1 << 8): z = 0 while x > 1: z = z * 10 + (a, b)[x & 1] x >>= 1 s.add(z) fact = [1] * (n+1) for i in range(1, n+1): fact[i] = fact[i-1] * i % MOD for x in range(n+1): if x * a + (n - x) * b in s: res = (res + fast_power(fact[x] * fact[n-x], MOD-2)) % MOD print(res * fact[n] % MOD) ```
output
1
79,419
20
158,839
Provide tags and a correct Python 3 solution for this coding contest problem. Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits a and b. Vitaly calls a good number excellent, if the sum of its digits is a good number. For example, let's say that Vitaly's favourite digits are 1 and 3, then number 12 isn't good and numbers 13 or 311 are. Also, number 111 is excellent and number 11 isn't. Now Vitaly is wondering, how many excellent numbers of length exactly n are there. As this number can be rather large, he asks you to count the remainder after dividing it by 1000000007 (109 + 7). A number's length is the number of digits in its decimal representation without leading zeroes. Input The first line contains three integers: a, b, n (1 ≀ a < b ≀ 9, 1 ≀ n ≀ 106). Output Print a single integer β€” the answer to the problem modulo 1000000007 (109 + 7). Examples Input 1 3 3 Output 1 Input 2 3 10 Output 165
instruction
0
79,420
20
158,840
Tags: brute force, combinatorics Correct Solution: ``` import sys import itertools as it import math as mt import collections as cc I=lambda:list(map(int,input().split())) a,b,n=I() fact=[1]*(n+1) mod=10**9+7 for i in range(1,n+1): fact[i]=fact[i-1]*i fact[i]%=mod def ch(n,a,b): f=1 while n: if n%10!=a and n%10!=b: f=0 break n//=10 return f ans=0 for i in range(n+1): x=i*a+(n-i)*b if ch(x,a,b): ans+=(fact[n]*(pow(fact[i],mod-2,mod)%mod)*pow(fact[n-i],mod-2,mod)) ans%=mod print(ans) ```
output
1
79,420
20
158,841
Provide tags and a correct Python 3 solution for this coding contest problem. Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits a and b. Vitaly calls a good number excellent, if the sum of its digits is a good number. For example, let's say that Vitaly's favourite digits are 1 and 3, then number 12 isn't good and numbers 13 or 311 are. Also, number 111 is excellent and number 11 isn't. Now Vitaly is wondering, how many excellent numbers of length exactly n are there. As this number can be rather large, he asks you to count the remainder after dividing it by 1000000007 (109 + 7). A number's length is the number of digits in its decimal representation without leading zeroes. Input The first line contains three integers: a, b, n (1 ≀ a < b ≀ 9, 1 ≀ n ≀ 106). Output Print a single integer β€” the answer to the problem modulo 1000000007 (109 + 7). Examples Input 1 3 3 Output 1 Input 2 3 10 Output 165
instruction
0
79,421
20
158,842
Tags: brute force, combinatorics Correct Solution: ``` a,b,n=map(int,input().split()) def ok(s): # print('sum',s) while s: if s%10!=a and s%10!=b: return False s=int(s/10) # print('ok') return True ans=0 p=int(1e9+7) A=[1] for i in range(1,n+1): A.append(int(i*A[i-1]%p)) for x in range(0,n+1): y=n-x # print(a,x,b,y,a*x+b*y) if ok(a*x+b*y): ans+=(A[n]*pow(A[x],p-2,p))%p*pow(A[y],p-2,p)%p ans%=p # input() print(int(ans)) ```
output
1
79,421
20
158,843
Provide tags and a correct Python 3 solution for this coding contest problem. Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits a and b. Vitaly calls a good number excellent, if the sum of its digits is a good number. For example, let's say that Vitaly's favourite digits are 1 and 3, then number 12 isn't good and numbers 13 or 311 are. Also, number 111 is excellent and number 11 isn't. Now Vitaly is wondering, how many excellent numbers of length exactly n are there. As this number can be rather large, he asks you to count the remainder after dividing it by 1000000007 (109 + 7). A number's length is the number of digits in its decimal representation without leading zeroes. Input The first line contains three integers: a, b, n (1 ≀ a < b ≀ 9, 1 ≀ n ≀ 106). Output Print a single integer β€” the answer to the problem modulo 1000000007 (109 + 7). Examples Input 1 3 3 Output 1 Input 2 3 10 Output 165
instruction
0
79,422
20
158,844
Tags: brute force, combinatorics Correct Solution: ``` def egcd(a, b): if a == 0: return (b, 0, 1) else: g, y, x = egcd(b % a, a) return (g, x - (b // a) * y, y) def modinv(a, m): g, x, y = egcd(a, m) return x % m a, b, n = map(int, input().split()) c = str(a) + str(b) f, mod, ans = [1], 1000000007, 0 for i in range(1, n + 1): f.append(f[-1] * i % mod) s = a * n for i in range(n + 1): if all(i in c for i in str(s)): ans += f[n] * modinv(f[i] * f[n - i], mod) % mod s += b - a print(ans % mod) ```
output
1
79,422
20
158,845
Provide tags and a correct Python 3 solution for this coding contest problem. Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits a and b. Vitaly calls a good number excellent, if the sum of its digits is a good number. For example, let's say that Vitaly's favourite digits are 1 and 3, then number 12 isn't good and numbers 13 or 311 are. Also, number 111 is excellent and number 11 isn't. Now Vitaly is wondering, how many excellent numbers of length exactly n are there. As this number can be rather large, he asks you to count the remainder after dividing it by 1000000007 (109 + 7). A number's length is the number of digits in its decimal representation without leading zeroes. Input The first line contains three integers: a, b, n (1 ≀ a < b ≀ 9, 1 ≀ n ≀ 106). Output Print a single integer β€” the answer to the problem modulo 1000000007 (109 + 7). Examples Input 1 3 3 Output 1 Input 2 3 10 Output 165
instruction
0
79,423
20
158,846
Tags: brute force, combinatorics Correct Solution: ``` fact = [1] mod = 10**9 + 7 def factorial(n): global mod global fact fact = [1] mod = 10**9 + 7 for i in range(1,n+1): fact.append(fact[-1] * i) fact[-1] %= mod def C(n,k): global mod return (((fact[n]*pow(fact[k],mod-2,mod))%mod)*pow(fact[n-k],mod-2,mod))%mod def good(x,a,b): while x > 0: if(x%10!=a and x%10!=b): return False x//=10 return True for _ in range(1): ans = 0 a,b,n = map(int,input().split()) factorial(n) for i in range(n+1): if(good(i*a+(n-i)*b,a,b)): ans += C(n,i) ans %= mod print(ans) ```
output
1
79,423
20
158,847
Provide tags and a correct Python 3 solution for this coding contest problem. Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits a and b. Vitaly calls a good number excellent, if the sum of its digits is a good number. For example, let's say that Vitaly's favourite digits are 1 and 3, then number 12 isn't good and numbers 13 or 311 are. Also, number 111 is excellent and number 11 isn't. Now Vitaly is wondering, how many excellent numbers of length exactly n are there. As this number can be rather large, he asks you to count the remainder after dividing it by 1000000007 (109 + 7). A number's length is the number of digits in its decimal representation without leading zeroes. Input The first line contains three integers: a, b, n (1 ≀ a < b ≀ 9, 1 ≀ n ≀ 106). Output Print a single integer β€” the answer to the problem modulo 1000000007 (109 + 7). Examples Input 1 3 3 Output 1 Input 2 3 10 Output 165
instruction
0
79,424
20
158,848
Tags: brute force, combinatorics Correct Solution: ``` #------------------------template--------------------------# import os import sys # from math import * from collections import * # from fractions import * # from heapq import* from bisect import * from io import BytesIO, IOBase def vsInput(): sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w') BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") ALPHA='abcdefghijklmnopqrstuvwxyz/' M=10**9+7 EPS=1e-6 def Ceil(a,b): return a//b+int(a%b>0) def value():return tuple(map(int,input().split())) def array():return [int(i) for i in input().split()] def Int():return int(input()) def Str():return input() def arrayS():return [i for i in input().split()] #-------------------------code---------------------------# # vsInput() def good(n): n=str(n) for i in n: if(int(i) not in (A,B)): return False return True A,B,N=value() ans=0 fact=[1] for i in range(1,N+1): fact.append((fact[-1]*i)%M) for a in range(N+1): b=N-a if(good(a*A+b*B)): here=pow(fact[a]*fact[b],M-2,M) ans=(ans+(fact[N]*here)%M)%M print(ans) ```
output
1
79,424
20
158,849
Provide tags and a correct Python 3 solution for this coding contest problem. Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits a and b. Vitaly calls a good number excellent, if the sum of its digits is a good number. For example, let's say that Vitaly's favourite digits are 1 and 3, then number 12 isn't good and numbers 13 or 311 are. Also, number 111 is excellent and number 11 isn't. Now Vitaly is wondering, how many excellent numbers of length exactly n are there. As this number can be rather large, he asks you to count the remainder after dividing it by 1000000007 (109 + 7). A number's length is the number of digits in its decimal representation without leading zeroes. Input The first line contains three integers: a, b, n (1 ≀ a < b ≀ 9, 1 ≀ n ≀ 106). Output Print a single integer β€” the answer to the problem modulo 1000000007 (109 + 7). Examples Input 1 3 3 Output 1 Input 2 3 10 Output 165
instruction
0
79,425
20
158,850
Tags: brute force, combinatorics Correct Solution: ``` a,b,n=map(int,input().split()) import sys input=sys.stdin.readline p=(10**9)+7 pri=p fac=[1 for i in range((10**6)+1)] for i in range(2,len(fac)): fac[i]=(fac[i-1]*(i%pri))%pri def modi(x): return (pow(x,p-2,p))%p; def ncr(n,r): x=(fac[n]*((modi(fac[r])%p)*(modi(fac[n-r])%p))%p)%p return x; ans=[] for i in range(n+1): total=i*a+((n-i)*b) s=str(total) if(s.count(str(a))+s.count(str(b))==len(s)): ans.append([i,n-i]) total=0 for i in range(len(ans)): total+=ncr(n,ans[i][0]) total%=pri print(total) ```
output
1
79,425
20
158,851
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits a and b. Vitaly calls a good number excellent, if the sum of its digits is a good number. For example, let's say that Vitaly's favourite digits are 1 and 3, then number 12 isn't good and numbers 13 or 311 are. Also, number 111 is excellent and number 11 isn't. Now Vitaly is wondering, how many excellent numbers of length exactly n are there. As this number can be rather large, he asks you to count the remainder after dividing it by 1000000007 (109 + 7). A number's length is the number of digits in its decimal representation without leading zeroes. Input The first line contains three integers: a, b, n (1 ≀ a < b ≀ 9, 1 ≀ n ≀ 106). Output Print a single integer β€” the answer to the problem modulo 1000000007 (109 + 7). Examples Input 1 3 3 Output 1 Input 2 3 10 Output 165 Submitted Solution: ``` import math from sys import stdin #stdin=open('input.txt','r') I=stdin.readline mod=1000000007 fact = [1 for i in range(1000000+5)] for i in range(2,len(fact)): fact[i]=fact[i-1]*i fact[i]%=mod a,b,n=map(int,I().split()) c1=chr(a+ord('0')) c2=chr(b+ord('0')) #byg=(math.factorial(1000000)) ans=0 for x in range(0,n+1): now=a*x+n*b-b*x flag=False for c in str(now): if(c!=c1 and c!=c2): flag=True break if(not flag): #print(x,now) now=fact[n] y=fact[x] z=fact[n-x] asd=pow(y*z,mod-2,mod) now*=asd now%=mod #now/=math.factorial(n-x) ans+=now ans%=mod print(int(ans)) ```
instruction
0
79,426
20
158,852
Yes
output
1
79,426
20
158,853
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits a and b. Vitaly calls a good number excellent, if the sum of its digits is a good number. For example, let's say that Vitaly's favourite digits are 1 and 3, then number 12 isn't good and numbers 13 or 311 are. Also, number 111 is excellent and number 11 isn't. Now Vitaly is wondering, how many excellent numbers of length exactly n are there. As this number can be rather large, he asks you to count the remainder after dividing it by 1000000007 (109 + 7). A number's length is the number of digits in its decimal representation without leading zeroes. Input The first line contains three integers: a, b, n (1 ≀ a < b ≀ 9, 1 ≀ n ≀ 106). Output Print a single integer β€” the answer to the problem modulo 1000000007 (109 + 7). Examples Input 1 3 3 Output 1 Input 2 3 10 Output 165 Submitted Solution: ``` def R(): return map(int, input().split()) def I(): return int(input()) def S(): return str(input()) def L(): return list(R()) from collections import Counter import math import sys from itertools import permutations import bisect mod=10**9+7 #print(bisect.bisect_right([1,2,3],2)) #print(bisect.bisect_left([1,2,3],2)) a,b,n=R() fact=[1]*(n+1) for i in range(1,n+1): fact[i]=fact[i-1]*i fact[i]%=mod def egcd(a, b): if a == 0: return (b, 0, 1) else: g, y, x = egcd(b % a, a) return (g, x - (b // a) * y, y) def modinv(a, m): g, x, y = egcd(a, m) if g != 1: raise Exception('modular inverse does not exist') else: return x % m def check(val,a,b): while val>0: if val%10!= a and val%10!=b: return False val//=10 return True ans=0 for i in range(n+1): if check(a*i+b*(n-i),a,b): ans+=fact[n]*modinv((fact[i]*fact[n-i])%mod,mod) ans%=mod print(ans) ```
instruction
0
79,427
20
158,854
Yes
output
1
79,427
20
158,855
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits a and b. Vitaly calls a good number excellent, if the sum of its digits is a good number. For example, let's say that Vitaly's favourite digits are 1 and 3, then number 12 isn't good and numbers 13 or 311 are. Also, number 111 is excellent and number 11 isn't. Now Vitaly is wondering, how many excellent numbers of length exactly n are there. As this number can be rather large, he asks you to count the remainder after dividing it by 1000000007 (109 + 7). A number's length is the number of digits in its decimal representation without leading zeroes. Input The first line contains three integers: a, b, n (1 ≀ a < b ≀ 9, 1 ≀ n ≀ 106). Output Print a single integer β€” the answer to the problem modulo 1000000007 (109 + 7). Examples Input 1 3 3 Output 1 Input 2 3 10 Output 165 Submitted Solution: ``` import sys import itertools as it import math as mt import collections as cc input=sys.stdin.buffer.readline I=lambda:list(map(int,input().split())) a,b,n=I() fact=[1]*(n+1) mod=10**9+7 for i in range(1,n+1): fact[i]=fact[i-1]*i fact[i]%=mod def ch(n,a,b): f=1 while n: if n%10!=a and n%10!=b: f=0 break n//=10 return f ans=0 for i in range(n+1): x=i*a+(n-i)*b if ch(x,a,b): ans+=(fact[n]*(pow(fact[i],mod-2,mod)%mod)*pow(fact[n-i],mod-2,mod)) ans%=mod print(ans) ```
instruction
0
79,428
20
158,856
Yes
output
1
79,428
20
158,857
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits a and b. Vitaly calls a good number excellent, if the sum of its digits is a good number. For example, let's say that Vitaly's favourite digits are 1 and 3, then number 12 isn't good and numbers 13 or 311 are. Also, number 111 is excellent and number 11 isn't. Now Vitaly is wondering, how many excellent numbers of length exactly n are there. As this number can be rather large, he asks you to count the remainder after dividing it by 1000000007 (109 + 7). A number's length is the number of digits in its decimal representation without leading zeroes. Input The first line contains three integers: a, b, n (1 ≀ a < b ≀ 9, 1 ≀ n ≀ 106). Output Print a single integer β€” the answer to the problem modulo 1000000007 (109 + 7). Examples Input 1 3 3 Output 1 Input 2 3 10 Output 165 Submitted Solution: ``` # -*- coding: utf-8 -*- import math import collections import bisect import heapq import time import random import itertools import sys from typing import List import functools import operator as op """ created by shhuan at 2020/1/13 21:43 """ MOD = 1000000007 MAXN = 10 ** 6 + 5 factorial = [0 for _ in range(MAXN)] factorial[0] = 1 for i in range(1, MAXN): factorial[i] = factorial[i - 1] * i % MOD def pow(a, b): if b == 0: return 1 c = b // 2 d = pow(a, c) if b % 2 == 0: return d * d % MOD return d * d * a % MOD def inverse(k): return pow(k, MOD-2) def ncr(n, k): k = min(k, n - k) return factorial[n] * inverse(factorial[k]) % MOD * inverse(factorial[n-k]) % MOD def dlen(val): s = 0 while val > 0: s += 1 val //= 10 return s def gen(index, nbit, pre, a, b): if index >= nbit: return [pre] return gen(index + 1, nbit, pre * 10 + a, a, b) + gen(index + 1, nbit, pre * 10 + b, a, b) def count(lo, hi, a, b, n, nnum): d = b - a ans = 0 for v in gen(0, n, 0, a, b): if v < lo or v > hi: continue u = v - a * nnum if u % d == 0: y = u // d x = nnum - y # print(x, y, countab(lo, hi, a, b, x, y, n)) # ans += countab(lo, hi, a, b, x, y, n) ans += ncr(nnum, x) # print(x, y, ncr(nnum, x)) ans %= MOD return ans def solve(N, A, B): lo, hi = N * A, N * B nl, nh = dlen(lo), dlen(hi) if nl == nh: return count(lo, hi, A, B, nl, N) else: return count(lo, 10 ** nl - 1, A, B, nl, N) + count(10 ** nl, hi, A, B, nh, N) def test(): N = 10 ** 6 A = random.randint(1, 5) B = random.randint(1, 4) + A t0 = time.time() print(solve(N, A, B)) print(time.time() - t0) # print(solve(10**6, 2, 3)) A, B, N = map(int, input().split()) print(solve(N, A, B)) ```
instruction
0
79,429
20
158,858
Yes
output
1
79,429
20
158,859
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits a and b. Vitaly calls a good number excellent, if the sum of its digits is a good number. For example, let's say that Vitaly's favourite digits are 1 and 3, then number 12 isn't good and numbers 13 or 311 are. Also, number 111 is excellent and number 11 isn't. Now Vitaly is wondering, how many excellent numbers of length exactly n are there. As this number can be rather large, he asks you to count the remainder after dividing it by 1000000007 (109 + 7). A number's length is the number of digits in its decimal representation without leading zeroes. Input The first line contains three integers: a, b, n (1 ≀ a < b ≀ 9, 1 ≀ n ≀ 106). Output Print a single integer β€” the answer to the problem modulo 1000000007 (109 + 7). Examples Input 1 3 3 Output 1 Input 2 3 10 Output 165 Submitted Solution: ``` def fastio(): import sys from io import StringIO from atexit import register global input sys.stdin = StringIO(sys.stdin.read()) input = lambda : sys.stdin.readline().rstrip('\r\n') sys.stdout = StringIO() register(lambda : sys.__stdout__.write(sys.stdout.getvalue())) fastio() MOD = 10**9 + 7 I = lambda:list(map(int,input().split())) a, b, n = I() ans = 0 f = [1]*(1000001) for i in range(1, 1000001): f[i] = f[i-1]*i%MOD for i in range(n + 1): s = list(set(str(i*a + (n-i)*b))) if len(s) > 2: continue if len(s) == 1 and s[0] != str(a) and s[0] != str(b): continue if len(s) == 2 and (s[0] != str(a) or s[1] != str(b)): continue ans = (ans + f[n]/(f[n-i]*f[i]))%MOD print(int(ans)) ```
instruction
0
79,430
20
158,860
No
output
1
79,430
20
158,861
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits a and b. Vitaly calls a good number excellent, if the sum of its digits is a good number. For example, let's say that Vitaly's favourite digits are 1 and 3, then number 12 isn't good and numbers 13 or 311 are. Also, number 111 is excellent and number 11 isn't. Now Vitaly is wondering, how many excellent numbers of length exactly n are there. As this number can be rather large, he asks you to count the remainder after dividing it by 1000000007 (109 + 7). A number's length is the number of digits in its decimal representation without leading zeroes. Input The first line contains three integers: a, b, n (1 ≀ a < b ≀ 9, 1 ≀ n ≀ 106). Output Print a single integer β€” the answer to the problem modulo 1000000007 (109 + 7). Examples Input 1 3 3 Output 1 Input 2 3 10 Output 165 Submitted Solution: ``` a,b,n=map(int,input().split()) def ok(s): # print('sum',s) while s: if s%10!=a and s%10!=b: return False s=int(s/10) return True ans=0 p=int(1e9+7) A=[1] for i in range(1,n+1): A.append(int(i*A[i-1]%p)) for x in range(0,n+1): y=n-x # print(a,x,b,y,a*x+b*y) if ok(a*x+b*y): ans+=(A[n]*pow(A[x],p-2,p))%p*pow(A[y],p-2,p)%p # input() print(int(ans)) ```
instruction
0
79,431
20
158,862
No
output
1
79,431
20
158,863
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits a and b. Vitaly calls a good number excellent, if the sum of its digits is a good number. For example, let's say that Vitaly's favourite digits are 1 and 3, then number 12 isn't good and numbers 13 or 311 are. Also, number 111 is excellent and number 11 isn't. Now Vitaly is wondering, how many excellent numbers of length exactly n are there. As this number can be rather large, he asks you to count the remainder after dividing it by 1000000007 (109 + 7). A number's length is the number of digits in its decimal representation without leading zeroes. Input The first line contains three integers: a, b, n (1 ≀ a < b ≀ 9, 1 ≀ n ≀ 106). Output Print a single integer β€” the answer to the problem modulo 1000000007 (109 + 7). Examples Input 1 3 3 Output 1 Input 2 3 10 Output 165 Submitted Solution: ``` # -*- coding: utf-8 -*- import math import collections import bisect import heapq import time import random import itertools import sys from typing import List import functools import operator as op """ created by shhuan at 2020/1/13 21:43 """ MOD = 1000000007 MAXN = 10 ** 6 + 5 factorial = [0 for _ in range(MAXN)] factorial[0] = 1 for i in range(1, MAXN): factorial[i] = factorial[i - 1] * i % MOD def pow(a, b): if b == 0: return 1 c = b // 2 d = pow(a, c) if b % 2 == 0: return d * d % MOD return d * d * b % MOD def inverse(k): return pow(k, MOD-2) def ncr(n, k): k = min(k, n - k) return (factorial[n] * inverse(factorial[k]) % MOD) * inverse(factorial[n-1]) % MOD def dlen(val): s = 0 while val > 0: s += 1 val //= 10 return s def gen(index, nbit, pre, a, b): if index >= nbit: return [pre] return gen(index + 1, nbit, pre * 10 + a, a, b) + gen(index + 1, nbit, pre * 10 + b, a, b) def count(lo, hi, a, b, n, nnum): d = b - a ans = 0 for v in gen(0, n, 0, a, b): if v < lo or v > hi: continue u = v - a * nnum if u % d == 0: y = u // d x = nnum - y # print(x, y, countab(lo, hi, a, b, x, y, n)) # ans += countab(lo, hi, a, b, x, y, n) ans += ncr(nnum, x) # print(x, y, ncr(nnum, x)) ans %= MOD return ans def solve(N, A, B): lo, hi = N * A, N * B nl, nh = dlen(lo), dlen(hi) if nl == nh: return count(lo, hi, A, B, nl, N) else: return count(lo, 10 ** nl - 1, A, B, nl, N) + count(10 ** nl, hi, A, B, nh, N) def test(): N = 10 ** 6 A = random.randint(1, 5) B = random.randint(1, 4) + A t0 = time.time() print(solve(N, A, B)) print(time.time() - t0) # print(solve(10**6, 2, 3)) A, B, N = map(int, input().split()) print(solve(N, A, B)) ```
instruction
0
79,432
20
158,864
No
output
1
79,432
20
158,865
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits a and b. Vitaly calls a good number excellent, if the sum of its digits is a good number. For example, let's say that Vitaly's favourite digits are 1 and 3, then number 12 isn't good and numbers 13 or 311 are. Also, number 111 is excellent and number 11 isn't. Now Vitaly is wondering, how many excellent numbers of length exactly n are there. As this number can be rather large, he asks you to count the remainder after dividing it by 1000000007 (109 + 7). A number's length is the number of digits in its decimal representation without leading zeroes. Input The first line contains three integers: a, b, n (1 ≀ a < b ≀ 9, 1 ≀ n ≀ 106). Output Print a single integer β€” the answer to the problem modulo 1000000007 (109 + 7). Examples Input 1 3 3 Output 1 Input 2 3 10 Output 165 Submitted Solution: ``` def check(v): while v > 0: z = v % 10; if z == a or z == b: v /= 10; else: return False; return True a, b, n = map(int, input().split()) mod = 1000000007 fact = [1]*(n+1) ans = 0 for i in range(2, n+1, 1): fact[i] = (i * fact[i-1]) % mod for i in range(n+1): s = a*i + b * (n - i) if check(s): ans += (fact[n] * pow((fact[i] * fact[n - i]) % mod, mod - 2, mod)) % mod; ans %= mod; print(ans); ```
instruction
0
79,433
20
158,866
No
output
1
79,433
20
158,867
Provide tags and a correct Python 3 solution for this coding contest problem. Igor has fallen in love with Tanya. Now Igor wants to show his feelings and write a number on the fence opposite to Tanya's house. Igor thinks that the larger the number is, the more chance to win Tanya's heart he has. Unfortunately, Igor could only get v liters of paint. He did the math and concluded that digit d requires ad liters of paint. Besides, Igor heard that Tanya doesn't like zeroes. That's why Igor won't use them in his number. Help Igor find the maximum number he can write on the fence. Input The first line contains a positive integer v (0 ≀ v ≀ 106). The second line contains nine positive integers a1, a2, ..., a9 (1 ≀ ai ≀ 105). Output Print the maximum number Igor can write on the fence. If he has too little paint for any digit (so, he cannot write anything), print -1. Examples Input 5 5 4 3 2 1 2 3 4 5 Output 55555 Input 2 9 11 1 12 5 8 9 10 6 Output 33 Input 0 1 1 1 1 1 1 1 1 1 Output -1
instruction
0
79,450
20
158,900
Tags: data structures, dp, greedy, implementation Correct Solution: ``` n=int(input()) Ar=[int(x) for x in input().split()] A=[] m=min(Ar) # print(m) for i in range(9): # print(i) if Ar[i]==m: A.append(i+1) # print(A) if m<=n: k=n//m p=list(str(A[-1])*(k)) # print(p) remain=n-(k*Ar[A[-1]-1]) # print(remain) # print(A[-1]) s=0 for i in range(9,A[-1],-1): # print(Ar[i-1],Ar[A[-1]-1]) while Ar[i-1]-Ar[A[-1]-1]<=remain: # print(remain) remain-=(Ar[i-1]-Ar[A[-1]-1]) # print(remain) p[s]=str(i) s+=1 print(''.join(p)) else: print(-1) ```
output
1
79,450
20
158,901
Provide tags and a correct Python 3 solution for this coding contest problem. Igor has fallen in love with Tanya. Now Igor wants to show his feelings and write a number on the fence opposite to Tanya's house. Igor thinks that the larger the number is, the more chance to win Tanya's heart he has. Unfortunately, Igor could only get v liters of paint. He did the math and concluded that digit d requires ad liters of paint. Besides, Igor heard that Tanya doesn't like zeroes. That's why Igor won't use them in his number. Help Igor find the maximum number he can write on the fence. Input The first line contains a positive integer v (0 ≀ v ≀ 106). The second line contains nine positive integers a1, a2, ..., a9 (1 ≀ ai ≀ 105). Output Print the maximum number Igor can write on the fence. If he has too little paint for any digit (so, he cannot write anything), print -1. Examples Input 5 5 4 3 2 1 2 3 4 5 Output 55555 Input 2 9 11 1 12 5 8 9 10 6 Output 33 Input 0 1 1 1 1 1 1 1 1 1 Output -1
instruction
0
79,451
20
158,902
Tags: data structures, dp, greedy, implementation Correct Solution: ``` import sys import math as mt import bisect #input=sys.stdin.readline #t=int(input()) t=1 def ncr_util(): inv[0]=inv[1]=1 fact[0]=fact[1]=1 for i in range(2,300001): inv[i]=(inv[i%p]*(p-p//i))%p for i in range(1,300001): inv[i]=(inv[i-1]*inv[i])%p fact[i]=(fact[i-1]*i)%p def solve(): d={} j=1 for i in range(9): d[l[i]]=i+1 mini=min(l[:]) x=n//mini rem=n%mini #print(123,mini,d[mini]) ans=[d[mini]]*(x) #print(ans,l) for i in range(len(ans)): x,rem1=d[mini],rem for j in range(d[mini],9): if l[j]<=rem+mini: x=j+1 rem1=rem+mini-l[j] ans[i]=x rem=rem1 if x==0: return [-1] else: return ans for _ in range(t): n=int(input()) #n1=int(input()) #s=input() #n=int(input()) #n,m=(map(int,input().split())) #n1=n #a=int(input()) #b=int(input()) #a,b,c,r=map(int,input().split()) #x2,y2=map(int,input().split()) #n=int(input()) #s=input() #s1=input() #p=input() l=list(map(int,input().split())) #l=str(n) #l.sort(reverse=True) #l2.sort(reverse=True) #l1.sort(reverse=True) print(*solve(),sep="") ```
output
1
79,451
20
158,903