message
stringlengths
2
59.7k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
37
108k
cluster
float64
20
20
__index_level_0__
int64
74
217k
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to 1. More formally, a sequence s_1, s_2, …, s_{n} is beautiful if |s_i - s_{i+1}| = 1 for all 1 ≀ i ≀ n - 1. Trans has a numbers 0, b numbers 1, c numbers 2 and d numbers 3. He wants to construct a beautiful sequence using all of these a + b + c + d numbers. However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans? Input The only input line contains four non-negative integers a, b, c and d (0 < a+b+c+d ≀ 10^5). Output If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line. Otherwise, print "YES" (without quotes) in the first line. Then in the second line print a + b + c + d integers, separated by spaces β€” a beautiful sequence. There should be a numbers equal to 0, b numbers equal to 1, c numbers equal to 2 and d numbers equal to 3. If there are multiple answers, you can print any of them. Examples Input 2 2 2 1 Output YES 0 1 0 1 2 3 2 Input 1 2 3 4 Output NO Input 2 2 2 3 Output NO Note In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to 1. Also, there are exactly two numbers, equal to 0, 1, 2 and exactly one number, equal to 3. It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. Submitted Solution: ``` #!/usr/bin/env python3 # coding: utf-8 # Last Modified: 06/Dec/19 10:31:29 AM import sys def main(): a, b, c, d = get_ints() def quit(): print("NO") exit(0) ans = [] if b > a: ans.append(1) b -= 1 while a > 0 and b > 0: ans.append(0) ans.append(1) a -= 1 b -= 1 # print(a, b, c, d) if a > 0: quit() while b > 0 and c > 0: ans.append(2) ans.append(1) c -= 1 b -= 1 # print(a, b, c, d) if b > 0: quit() if c == 0: quit() while c > 0 and d > 0: ans.append(2) ans.append(3) c -= 1 d -= 1 if c: ans.append(2) c -= 1 if c == 1 and ans[0] == 1: ans.insert(0, 2) c -= 1 if d == 1 and ans[0] == 2: ans.insert(0, 3) d -= 1 if a or b or c or d: quit() print("YES") print(*ans) get_array = lambda: list(map(int, sys.stdin.readline().split())) get_ints = lambda: map(int, sys.stdin.readline().split()) input = lambda: sys.stdin.readline().strip() if __name__ == "__main__": main() ```
instruction
0
76,853
20
153,706
No
output
1
76,853
20
153,707
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to 1. More formally, a sequence s_1, s_2, …, s_{n} is beautiful if |s_i - s_{i+1}| = 1 for all 1 ≀ i ≀ n - 1. Trans has a numbers 0, b numbers 1, c numbers 2 and d numbers 3. He wants to construct a beautiful sequence using all of these a + b + c + d numbers. However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans? Input The only input line contains four non-negative integers a, b, c and d (0 < a+b+c+d ≀ 10^5). Output If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line. Otherwise, print "YES" (without quotes) in the first line. Then in the second line print a + b + c + d integers, separated by spaces β€” a beautiful sequence. There should be a numbers equal to 0, b numbers equal to 1, c numbers equal to 2 and d numbers equal to 3. If there are multiple answers, you can print any of them. Examples Input 2 2 2 1 Output YES 0 1 0 1 2 3 2 Input 1 2 3 4 Output NO Input 2 2 2 3 Output NO Note In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to 1. Also, there are exactly two numbers, equal to 0, 1, 2 and exactly one number, equal to 3. It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. Submitted Solution: ``` def printres(res): print("YES") print(' '.join(map(str, res))) def main(): cc = [int(a) for a in input().split()] nz = [] for i,c in enumerate(cc): if c > 0: nz.append(i) if len(nz) == 1: if cc[i] == 1: printres([nz[0]]) else: print("NO") return elif len(nz) == 2: if nz[1] != nz[0] + 1: print("NO") return df = cc[nz[1]] - cc[nz[0]] if abs(df) > 1: print("NO") return if df == 1: printres([nz[1]] + [nz[0], nz[1]] * cc[nz[0]]) elif df == 0: printres([nz[0], nz[1]] * cc[nz[0]]) else: printres([nz[0], nz[1]] * cc[nz[1]] + [nz[0]]) return elif len(nz) == 3: if nz[2] != nz[1] +1 or nz[1] != nz[0] + 1: print("NO") return df = cc[nz[0]] + cc[nz[2]] - cc[nz[1]] if abs(df) > 1: print("NO") return if df == 1: printres([nz[0], nz[1]] * cc[nz[0]] + [nz[2], nz[1]] * (cc[nz[2]] -1) + [nz[2]]) elif df == 0: printres([nz[0], nz[1]] * cc[nz[0]] + [nz[1], nz[2]] * cc[nz[2]]) else: printres([nz[1]] + [nz[0], nz[1]] * cc[nz[0]] + [nz[2], nz[1]] * cc[nz[2]]) return else: df = cc[0] - cc[1] + cc[2] - cc[3] if abs(df) > 1: print("NO") return y = min(cc[1] - cc[0], cc[2] - cc[3]) if y < 0: print("NO") return base = [0,1] * cc[0] + [2, 1] * y + [2, 3] * cc[3] if df == 1: printres(base + [2]) elif df == 0: printres(base) else: printres([1] + base) return if __name__ == "__main__": main() ```
instruction
0
76,854
20
153,708
No
output
1
76,854
20
153,709
Provide tags and a correct Python 3 solution for this coding contest problem. We'll define S(n) for positive integer n as follows: the number of the n's digits in the decimal base. For example, S(893) = 3, S(114514) = 6. You want to make a consecutive integer sequence starting from number m (m, m + 1, ...). But you need to pay S(n)Β·k to add the number n to the sequence. You can spend a cost up to w, and you want to make the sequence as long as possible. Write a program that tells sequence's maximum length. Input The first line contains three integers w (1 ≀ w ≀ 1016), m (1 ≀ m ≀ 1016), k (1 ≀ k ≀ 109). Please, do not write the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. Output The first line should contain a single integer β€” the answer to the problem. Examples Input 9 1 1 Output 9 Input 77 7 7 Output 7 Input 114 5 14 Output 6 Input 1 1 2 Output 0
instruction
0
77,065
20
154,130
Tags: binary search, implementation, math Correct Solution: ``` pow10 = [10**i for i in range(20)] w, m, k = map(int, input().split()) x = 1 while (m > pow10[x]): x += 1 if (pow10[x] - m) * x * k >= w: print(w // (x * k)) exit() cur = (pow10[x] - m) * x * k tmp = pow10[x] - m x += 1 while (cur + 9 * pow10[x-1] * x * k <= w): cur += 9 * pow10[x-1] * x * k tmp += 9 * pow10[x-1] x += 1 print(tmp + (w - cur) // (x * k)) ```
output
1
77,065
20
154,131
Provide tags and a correct Python 3 solution for this coding contest problem. We'll define S(n) for positive integer n as follows: the number of the n's digits in the decimal base. For example, S(893) = 3, S(114514) = 6. You want to make a consecutive integer sequence starting from number m (m, m + 1, ...). But you need to pay S(n)Β·k to add the number n to the sequence. You can spend a cost up to w, and you want to make the sequence as long as possible. Write a program that tells sequence's maximum length. Input The first line contains three integers w (1 ≀ w ≀ 1016), m (1 ≀ m ≀ 1016), k (1 ≀ k ≀ 109). Please, do not write the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. Output The first line should contain a single integer β€” the answer to the problem. Examples Input 9 1 1 Output 9 Input 77 7 7 Output 7 Input 114 5 14 Output 6 Input 1 1 2 Output 0
instruction
0
77,066
20
154,132
Tags: binary search, implementation, math Correct Solution: ``` pow10 = [1 for i in range(19)] for i in range(1, 19): pow10[i] = pow10[i - 1] * 10 w, m, k = map(int, input().split()) x = 1 while (m > pow10[x]): x += 1 if (pow10[x] - m) * x * k >= w: print(int((w) / (x * k))) else: cur = (pow10[x] - m) * x * k temp = pow10[x] - m while (True): x += 1 if (cur + (9 * pow10[x - 1]) * x * k > w): break cur += (9 * pow10[x - 1]) * x * k temp += 9 * pow10[x - 1] print(temp + int((w - cur) / (x * k))) ```
output
1
77,066
20
154,133
Provide tags and a correct Python 3 solution for this coding contest problem. We'll define S(n) for positive integer n as follows: the number of the n's digits in the decimal base. For example, S(893) = 3, S(114514) = 6. You want to make a consecutive integer sequence starting from number m (m, m + 1, ...). But you need to pay S(n)Β·k to add the number n to the sequence. You can spend a cost up to w, and you want to make the sequence as long as possible. Write a program that tells sequence's maximum length. Input The first line contains three integers w (1 ≀ w ≀ 1016), m (1 ≀ m ≀ 1016), k (1 ≀ k ≀ 109). Please, do not write the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. Output The first line should contain a single integer β€” the answer to the problem. Examples Input 9 1 1 Output 9 Input 77 7 7 Output 7 Input 114 5 14 Output 6 Input 1 1 2 Output 0
instruction
0
77,067
20
154,134
Tags: binary search, implementation, math Correct Solution: ``` w,m,k = map(int,input().split()) cur = len(str(m)) g = 9 base = 1 g = g*(10**(cur-1)) base = base*(10**(cur-1)) gg = g - (m - base) ans = 0 while(w): if(w>cur*gg*k): w-=cur*gg*k ans +=gg cur+=1 gg = g*10 g*=10 else: ans += w//(cur*k) break print(ans) ```
output
1
77,067
20
154,135
Provide tags and a correct Python 3 solution for this coding contest problem. We'll define S(n) for positive integer n as follows: the number of the n's digits in the decimal base. For example, S(893) = 3, S(114514) = 6. You want to make a consecutive integer sequence starting from number m (m, m + 1, ...). But you need to pay S(n)Β·k to add the number n to the sequence. You can spend a cost up to w, and you want to make the sequence as long as possible. Write a program that tells sequence's maximum length. Input The first line contains three integers w (1 ≀ w ≀ 1016), m (1 ≀ m ≀ 1016), k (1 ≀ k ≀ 109). Please, do not write the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. Output The first line should contain a single integer β€” the answer to the problem. Examples Input 9 1 1 Output 9 Input 77 7 7 Output 7 Input 114 5 14 Output 6 Input 1 1 2 Output 0
instruction
0
77,068
20
154,136
Tags: binary search, implementation, math Correct Solution: ``` lst = input().split() lst = [int(x) for x in lst] w, m , k = lst[0], lst[1], lst[2] idx = 10 ans = 0 start = 1 while idx <= m: start+=1 idx*=10 while w: tmpc = start * (idx - m ) * k; # print(f"{m} {idx} {start} {tmpc}") if tmpc < w: ans+= (idx - m ) w -= tmpc m = idx idx*=10 start+=1 else: ans += w // (start * k); break; print(ans) ```
output
1
77,068
20
154,137
Provide tags and a correct Python 3 solution for this coding contest problem. We'll define S(n) for positive integer n as follows: the number of the n's digits in the decimal base. For example, S(893) = 3, S(114514) = 6. You want to make a consecutive integer sequence starting from number m (m, m + 1, ...). But you need to pay S(n)Β·k to add the number n to the sequence. You can spend a cost up to w, and you want to make the sequence as long as possible. Write a program that tells sequence's maximum length. Input The first line contains three integers w (1 ≀ w ≀ 1016), m (1 ≀ m ≀ 1016), k (1 ≀ k ≀ 109). Please, do not write the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. Output The first line should contain a single integer β€” the answer to the problem. Examples Input 9 1 1 Output 9 Input 77 7 7 Output 7 Input 114 5 14 Output 6 Input 1 1 2 Output 0
instruction
0
77,069
20
154,138
Tags: binary search, implementation, math Correct Solution: ``` w, m, k = list(map(int, list(input().split()))) w = w // k logm = len(str(m)) nextpow = 10 ** (logm) - m total = 0 while (w >= logm * nextpow): total += nextpow w -= logm * nextpow nextpow = 9*(10**logm) logm += 1 total += w // logm print(total) ```
output
1
77,069
20
154,139
Provide tags and a correct Python 3 solution for this coding contest problem. We'll define S(n) for positive integer n as follows: the number of the n's digits in the decimal base. For example, S(893) = 3, S(114514) = 6. You want to make a consecutive integer sequence starting from number m (m, m + 1, ...). But you need to pay S(n)Β·k to add the number n to the sequence. You can spend a cost up to w, and you want to make the sequence as long as possible. Write a program that tells sequence's maximum length. Input The first line contains three integers w (1 ≀ w ≀ 1016), m (1 ≀ m ≀ 1016), k (1 ≀ k ≀ 109). Please, do not write the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. Output The first line should contain a single integer β€” the answer to the problem. Examples Input 9 1 1 Output 9 Input 77 7 7 Output 7 Input 114 5 14 Output 6 Input 1 1 2 Output 0
instruction
0
77,070
20
154,140
Tags: binary search, implementation, math Correct Solution: ``` w,m,k=map(int,input().split()) ans=0 while w>=len(str(m))*k: ans+=min(w//(k*len(str(m))),10**len(str(m))-m) w1=w m1=m m+=min(w1//(k*len(str(m1))),10**len(str(m1))-m1) w-=k*len(str(m1))*min(w1//(k*len(str(m1))),10**len(str(m1))-m1) #print(w,m,ans) print(ans) ```
output
1
77,070
20
154,141
Provide tags and a correct Python 3 solution for this coding contest problem. We'll define S(n) for positive integer n as follows: the number of the n's digits in the decimal base. For example, S(893) = 3, S(114514) = 6. You want to make a consecutive integer sequence starting from number m (m, m + 1, ...). But you need to pay S(n)Β·k to add the number n to the sequence. You can spend a cost up to w, and you want to make the sequence as long as possible. Write a program that tells sequence's maximum length. Input The first line contains three integers w (1 ≀ w ≀ 1016), m (1 ≀ m ≀ 1016), k (1 ≀ k ≀ 109). Please, do not write the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. Output The first line should contain a single integer β€” the answer to the problem. Examples Input 9 1 1 Output 9 Input 77 7 7 Output 7 Input 114 5 14 Output 6 Input 1 1 2 Output 0
instruction
0
77,071
20
154,142
Tags: binary search, implementation, math Correct Solution: ``` from math import * w, m, k = list(map(int, input().split())) cnt = 0 add = 9*10**(-1) if m < 10 else 0 for i in range(int(log10(m)), int(1e10)): v = (9 * 10**i - (m-1-9*10**(i-1)+add if i == int(log10(m)) else 0)) * (i+1) * k if w - v < 0: cnt += w//((i+1)*k) break w -= v cnt += v//(k*(i+1)) print(int(cnt)) ```
output
1
77,071
20
154,143
Provide tags and a correct Python 3 solution for this coding contest problem. We'll define S(n) for positive integer n as follows: the number of the n's digits in the decimal base. For example, S(893) = 3, S(114514) = 6. You want to make a consecutive integer sequence starting from number m (m, m + 1, ...). But you need to pay S(n)Β·k to add the number n to the sequence. You can spend a cost up to w, and you want to make the sequence as long as possible. Write a program that tells sequence's maximum length. Input The first line contains three integers w (1 ≀ w ≀ 1016), m (1 ≀ m ≀ 1016), k (1 ≀ k ≀ 109). Please, do not write the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. Output The first line should contain a single integer β€” the answer to the problem. Examples Input 9 1 1 Output 9 Input 77 7 7 Output 7 Input 114 5 14 Output 6 Input 1 1 2 Output 0
instruction
0
77,072
20
154,144
Tags: binary search, implementation, math Correct Solution: ``` def cnt(x, y): return y-x w, m, k = map(int, input().split()) p, d, res = 1, 0, 0 while p <= m: p *= 10 d += 1 while cnt(m, p)*d*k <= w: w -= cnt(m, p)*d*k res += cnt(m, p) m = p p *= 10 d += 1 res += w//(d*k) print(res) ```
output
1
77,072
20
154,145
Provide tags and a correct Python 3 solution for this coding contest problem. IT City company developing computer games decided to upgrade its way to reward its employees. Now it looks the following way. After a new game release users start buying it actively, and the company tracks the number of sales with precision to each transaction. Every time when the next number of sales is not divisible by any number from 2 to 10 every developer of this game gets a small bonus. A game designer Petya knows that the company is just about to release a new game that was partly developed by him. On the basis of his experience he predicts that n people will buy the game during the first month. Now Petya wants to determine how many times he will get the bonus. Help him to know it. Input The only line of the input contains one integer n (1 ≀ n ≀ 1018) β€” the prediction on the number of people who will buy the game. Output Output one integer showing how many numbers from 1 to n are not divisible by any number from 2 to 10. Examples Input 12 Output 2
instruction
0
77,151
20
154,302
Tags: math, number theory Correct Solution: ``` n = int(input()) k = n k = k-((n//2)+(n//3)+(n//5)+(n//7)) k = k+(n//6+n//10+n//14+n//15+n//21+n//35) k = k-(n//30+n//42+n//70+n//105) k = k+n//210 print(k) #print(n-(((n//2)+(n//3)+(n//5)+(n//7))+((n//6)+n//10+n//14+n//15+n//21+n//35)-(n//30+n//42+n//70+n//105)+n//210)) ```
output
1
77,151
20
154,303
Provide tags and a correct Python 3 solution for this coding contest problem. IT City company developing computer games decided to upgrade its way to reward its employees. Now it looks the following way. After a new game release users start buying it actively, and the company tracks the number of sales with precision to each transaction. Every time when the next number of sales is not divisible by any number from 2 to 10 every developer of this game gets a small bonus. A game designer Petya knows that the company is just about to release a new game that was partly developed by him. On the basis of his experience he predicts that n people will buy the game during the first month. Now Petya wants to determine how many times he will get the bonus. Help him to know it. Input The only line of the input contains one integer n (1 ≀ n ≀ 1018) β€” the prediction on the number of people who will buy the game. Output Output one integer showing how many numbers from 1 to n are not divisible by any number from 2 to 10. Examples Input 12 Output 2
instruction
0
77,152
20
154,304
Tags: math, number theory Correct Solution: ``` import sys from math import gcd def read(): return sys.stdin.readline().strip() def printf(a, sep = ' ', end = '\n'): sys.stdout.write(sep.join(map(str, a)) + end) #printf([n]) def readf(): return [int(i) for i in read().split()] def main(): n = int(read()) ans = n p = [2, 3, 5, 7] ans -= n//2 + n//3 + n//5 + n//7 ans += n//6 + n//10 + n//14 + n//21 + n//15 + n//35 ans -= n//30 + n//42 + n//105 + n//70 ans += n//210 printf([ans]) main() ```
output
1
77,152
20
154,305
Provide tags and a correct Python 3 solution for this coding contest problem. IT City company developing computer games decided to upgrade its way to reward its employees. Now it looks the following way. After a new game release users start buying it actively, and the company tracks the number of sales with precision to each transaction. Every time when the next number of sales is not divisible by any number from 2 to 10 every developer of this game gets a small bonus. A game designer Petya knows that the company is just about to release a new game that was partly developed by him. On the basis of his experience he predicts that n people will buy the game during the first month. Now Petya wants to determine how many times he will get the bonus. Help him to know it. Input The only line of the input contains one integer n (1 ≀ n ≀ 1018) β€” the prediction on the number of people who will buy the game. Output Output one integer showing how many numbers from 1 to n are not divisible by any number from 2 to 10. Examples Input 12 Output 2
instruction
0
77,153
20
154,306
Tags: math, number theory Correct Solution: ``` incl = [2, 3, 5, 7, 30, 42, 70, 105] excl = [6, 10, 14, 15, 21, 35, 210] n = int(input()) answ = 0 for k in incl: answ += n // k for k in excl: answ -= n // k print(n-answ) ```
output
1
77,153
20
154,307
Provide tags and a correct Python 3 solution for this coding contest problem. IT City company developing computer games decided to upgrade its way to reward its employees. Now it looks the following way. After a new game release users start buying it actively, and the company tracks the number of sales with precision to each transaction. Every time when the next number of sales is not divisible by any number from 2 to 10 every developer of this game gets a small bonus. A game designer Petya knows that the company is just about to release a new game that was partly developed by him. On the basis of his experience he predicts that n people will buy the game during the first month. Now Petya wants to determine how many times he will get the bonus. Help him to know it. Input The only line of the input contains one integer n (1 ≀ n ≀ 1018) β€” the prediction on the number of people who will buy the game. Output Output one integer showing how many numbers from 1 to n are not divisible by any number from 2 to 10. Examples Input 12 Output 2
instruction
0
77,154
20
154,308
Tags: math, number theory Correct Solution: ``` inp = int(input().strip()) nums = [2,3,5,7] overlap = [6, 10, 14, 15, 21, 30, 42, 105, 210] twos = [] threes = [] four = 2 * 3 * 5 * 7 for i in range(len(nums) - 1): for j in range(i + 1, len(nums)): twos.append(nums[i] * nums[j]) for i in range(len(nums) - 2): for j in range(i + 1, len(nums) - 1): for k in range(j + 1, len(nums)): threes.append(nums[i] * nums[j] * nums[k]) n = inp for num in nums: n -= inp//num for num in twos: n += inp//num for num in threes: n -= inp//num n += inp//four print(n) ```
output
1
77,154
20
154,309
Provide tags and a correct Python 3 solution for this coding contest problem. IT City company developing computer games decided to upgrade its way to reward its employees. Now it looks the following way. After a new game release users start buying it actively, and the company tracks the number of sales with precision to each transaction. Every time when the next number of sales is not divisible by any number from 2 to 10 every developer of this game gets a small bonus. A game designer Petya knows that the company is just about to release a new game that was partly developed by him. On the basis of his experience he predicts that n people will buy the game during the first month. Now Petya wants to determine how many times he will get the bonus. Help him to know it. Input The only line of the input contains one integer n (1 ≀ n ≀ 1018) β€” the prediction on the number of people who will buy the game. Output Output one integer showing how many numbers from 1 to n are not divisible by any number from 2 to 10. Examples Input 12 Output 2
instruction
0
77,155
20
154,310
Tags: math, number theory Correct Solution: ``` n = int(input()) a2 = n//2 a3 = n//3 a5 = n//5 a7 = n//7 a6 = n//6 a10 = n//10 a15 = n// 15 a14 = n//14 a21 = n//21 a35 = n//35 a42 = n//42 a30 = n//30 a105 = n//105 a70= n//70 a210 = n//210 ans = a2+a3+a5+a7-a6-a10-a15-a14-a21-a35+a42+a30+a105+a70-a210 res = n-ans print(res) ```
output
1
77,155
20
154,311
Provide tags and a correct Python 3 solution for this coding contest problem. IT City company developing computer games decided to upgrade its way to reward its employees. Now it looks the following way. After a new game release users start buying it actively, and the company tracks the number of sales with precision to each transaction. Every time when the next number of sales is not divisible by any number from 2 to 10 every developer of this game gets a small bonus. A game designer Petya knows that the company is just about to release a new game that was partly developed by him. On the basis of his experience he predicts that n people will buy the game during the first month. Now Petya wants to determine how many times he will get the bonus. Help him to know it. Input The only line of the input contains one integer n (1 ≀ n ≀ 1018) β€” the prediction on the number of people who will buy the game. Output Output one integer showing how many numbers from 1 to n are not divisible by any number from 2 to 10. Examples Input 12 Output 2
instruction
0
77,156
20
154,312
Tags: math, number theory Correct Solution: ``` n = int(input()) a = n a -= n // 2 + n // 3 + n // 5 + n // 7 a += n // 6 + n // 10 + n // 14 + n // 15 + n // 21 + n // 35 a -= n // 30 + n // 42 + n // 70 + n // 105 a += n // 210 print(a) ```
output
1
77,156
20
154,313
Provide tags and a correct Python 3 solution for this coding contest problem. IT City company developing computer games decided to upgrade its way to reward its employees. Now it looks the following way. After a new game release users start buying it actively, and the company tracks the number of sales with precision to each transaction. Every time when the next number of sales is not divisible by any number from 2 to 10 every developer of this game gets a small bonus. A game designer Petya knows that the company is just about to release a new game that was partly developed by him. On the basis of his experience he predicts that n people will buy the game during the first month. Now Petya wants to determine how many times he will get the bonus. Help him to know it. Input The only line of the input contains one integer n (1 ≀ n ≀ 1018) β€” the prediction on the number of people who will buy the game. Output Output one integer showing how many numbers from 1 to n are not divisible by any number from 2 to 10. Examples Input 12 Output 2
instruction
0
77,157
20
154,314
Tags: math, number theory Correct Solution: ``` import sys input=sys.stdin.buffer.readline n=int(input()) divisable=(n//2)+(n//3)+(n//5)+(n//7)-(n//6)-(n//10)-(n//14)-(n//15)-(n//21)-(n//35)+(n//30)+(n//42)+(n//70)+(n//105)-(n//210) print(n-divisable) ```
output
1
77,157
20
154,315
Provide tags and a correct Python 3 solution for this coding contest problem. IT City company developing computer games decided to upgrade its way to reward its employees. Now it looks the following way. After a new game release users start buying it actively, and the company tracks the number of sales with precision to each transaction. Every time when the next number of sales is not divisible by any number from 2 to 10 every developer of this game gets a small bonus. A game designer Petya knows that the company is just about to release a new game that was partly developed by him. On the basis of his experience he predicts that n people will buy the game during the first month. Now Petya wants to determine how many times he will get the bonus. Help him to know it. Input The only line of the input contains one integer n (1 ≀ n ≀ 1018) β€” the prediction on the number of people who will buy the game. Output Output one integer showing how many numbers from 1 to n are not divisible by any number from 2 to 10. Examples Input 12 Output 2
instruction
0
77,158
20
154,316
Tags: math, number theory Correct Solution: ``` a=int(input());print(a-a//2-a//3-a//5-a//7+a//6+a//10+a//14+a//15+a//21+a//35-a//30-a//105-a//70-a//42+a//210) ```
output
1
77,158
20
154,317
Provide tags and a correct Python 3 solution for this coding contest problem. Petya has n positive integers a1, a2, ..., an. His friend Vasya decided to joke and replaced all digits in Petya's numbers with a letters. He used the lowercase letters of the Latin alphabet from 'a' to 'j' and replaced all digits 0 with one letter, all digits 1 with another letter and so on. For any two different digits Vasya used distinct letters from 'a' to 'j'. Your task is to restore Petya's numbers. The restored numbers should be positive integers without leading zeros. Since there can be multiple ways to do it, determine the minimum possible sum of all Petya's numbers after the restoration. It is guaranteed that before Vasya's joke all Petya's numbers did not have leading zeros. Input The first line contains a single integer n (1 ≀ n ≀ 1 000) β€” the number of Petya's numbers. Each of the following lines contains non-empty string si consisting of lowercase Latin letters from 'a' to 'j' β€” the Petya's numbers after Vasya's joke. The length of each string does not exceed six characters. Output Determine the minimum sum of all Petya's numbers after the restoration. The restored numbers should be positive integers without leading zeros. It is guaranteed that the correct restore (without leading zeros) exists for all given tests. Examples Input 3 ab de aj Output 47 Input 5 abcdef ghij bdef accbd g Output 136542 Input 3 aa jj aa Output 44 Note In the first example, you need to replace the letter 'a' with the digit 1, the letter 'b' with the digit 0, the letter 'd' with the digit 2, the letter 'e' with the digit 3, and the letter 'j' with the digit 4. So after the restoration numbers will look like [10, 23, 14]. The sum of them is equal to 47, which is the minimum possible sum of the numbers after the correct restoration. In the second example the numbers after the restoration can look like: [120468, 3579, 2468, 10024, 3]. In the second example the numbers after the restoration can look like: [11, 22, 11].
instruction
0
77,305
20
154,610
Tags: constructive algorithms, greedy, math Correct Solution: ``` n = int(input()) coef, s = [0]*10, [] for i in range(n): s.append(input()) p = 1 for ch in reversed(s[-1]): coef[ord(ch)-ord('a')] += p p *= 10 dz = [0]*10 for st in s: dz[ord(st[0])-ord('a')] = 1 best = -1 for i in range(10): if not dz[i] and (best == -1 or coef[best] < coef[i]): best = i if best != -1: coef[best] = 0 coef.sort(reverse = True) ans = 0 j = 1 for i in range(10): if coef[i] >= 0: ans += j*coef[i] j += 1 print(ans) ```
output
1
77,305
20
154,611
Provide tags and a correct Python 3 solution for this coding contest problem. Petya has n positive integers a1, a2, ..., an. His friend Vasya decided to joke and replaced all digits in Petya's numbers with a letters. He used the lowercase letters of the Latin alphabet from 'a' to 'j' and replaced all digits 0 with one letter, all digits 1 with another letter and so on. For any two different digits Vasya used distinct letters from 'a' to 'j'. Your task is to restore Petya's numbers. The restored numbers should be positive integers without leading zeros. Since there can be multiple ways to do it, determine the minimum possible sum of all Petya's numbers after the restoration. It is guaranteed that before Vasya's joke all Petya's numbers did not have leading zeros. Input The first line contains a single integer n (1 ≀ n ≀ 1 000) β€” the number of Petya's numbers. Each of the following lines contains non-empty string si consisting of lowercase Latin letters from 'a' to 'j' β€” the Petya's numbers after Vasya's joke. The length of each string does not exceed six characters. Output Determine the minimum sum of all Petya's numbers after the restoration. The restored numbers should be positive integers without leading zeros. It is guaranteed that the correct restore (without leading zeros) exists for all given tests. Examples Input 3 ab de aj Output 47 Input 5 abcdef ghij bdef accbd g Output 136542 Input 3 aa jj aa Output 44 Note In the first example, you need to replace the letter 'a' with the digit 1, the letter 'b' with the digit 0, the letter 'd' with the digit 2, the letter 'e' with the digit 3, and the letter 'j' with the digit 4. So after the restoration numbers will look like [10, 23, 14]. The sum of them is equal to 47, which is the minimum possible sum of the numbers after the correct restoration. In the second example the numbers after the restoration can look like: [120468, 3579, 2468, 10024, 3]. In the second example the numbers after the restoration can look like: [11, 22, 11].
instruction
0
77,306
20
154,612
Tags: constructive algorithms, greedy, math Correct Solution: ``` from collections import defaultdict n = int(input()) aa = [input() for i in range(n)] counts = defaultdict(int) canBeZero = set('abcdefghij') for s in aa: canBeZero = canBeZero - {s[0]} for p, d in enumerate(reversed(s)): counts[d] += 10 ** p sums = sorted([(s, d) for d, s in counts.items()], reverse=True) digits = set(range(0, 10)) res = 0 for s, dchar in sums: min2 = sorted(digits)[:2] index = 0 if dchar not in canBeZero and min2[0] == 0: index = 1 dig = min2[index] digits = digits - {dig} res += s * dig print(res) ```
output
1
77,306
20
154,613
Provide tags and a correct Python 3 solution for this coding contest problem. Petya has n positive integers a1, a2, ..., an. His friend Vasya decided to joke and replaced all digits in Petya's numbers with a letters. He used the lowercase letters of the Latin alphabet from 'a' to 'j' and replaced all digits 0 with one letter, all digits 1 with another letter and so on. For any two different digits Vasya used distinct letters from 'a' to 'j'. Your task is to restore Petya's numbers. The restored numbers should be positive integers without leading zeros. Since there can be multiple ways to do it, determine the minimum possible sum of all Petya's numbers after the restoration. It is guaranteed that before Vasya's joke all Petya's numbers did not have leading zeros. Input The first line contains a single integer n (1 ≀ n ≀ 1 000) β€” the number of Petya's numbers. Each of the following lines contains non-empty string si consisting of lowercase Latin letters from 'a' to 'j' β€” the Petya's numbers after Vasya's joke. The length of each string does not exceed six characters. Output Determine the minimum sum of all Petya's numbers after the restoration. The restored numbers should be positive integers without leading zeros. It is guaranteed that the correct restore (without leading zeros) exists for all given tests. Examples Input 3 ab de aj Output 47 Input 5 abcdef ghij bdef accbd g Output 136542 Input 3 aa jj aa Output 44 Note In the first example, you need to replace the letter 'a' with the digit 1, the letter 'b' with the digit 0, the letter 'd' with the digit 2, the letter 'e' with the digit 3, and the letter 'j' with the digit 4. So after the restoration numbers will look like [10, 23, 14]. The sum of them is equal to 47, which is the minimum possible sum of the numbers after the correct restoration. In the second example the numbers after the restoration can look like: [120468, 3579, 2468, 10024, 3]. In the second example the numbers after the restoration can look like: [11, 22, 11].
instruction
0
77,307
20
154,614
Tags: constructive algorithms, greedy, math Correct Solution: ``` n = int(input()) d = [0] * (ord('j') + 1) fr = [0] * (ord('j') + 1) ans = 0 for i in range(n): s = input() fr[ord(s[0])] = 1 for j in range(len(s)): d[ord(s[j])] += 10 ** (len(s) - j - 1) a = [(d[i], i) for i in range(len(d))] a.sort(reverse=True) cr, f = 1, 1 for c, i in a: if f and not fr[i]: f = 0 else: ans += cr * c cr += 1 print(ans) ```
output
1
77,307
20
154,615
Provide tags and a correct Python 3 solution for this coding contest problem. Petya has n positive integers a1, a2, ..., an. His friend Vasya decided to joke and replaced all digits in Petya's numbers with a letters. He used the lowercase letters of the Latin alphabet from 'a' to 'j' and replaced all digits 0 with one letter, all digits 1 with another letter and so on. For any two different digits Vasya used distinct letters from 'a' to 'j'. Your task is to restore Petya's numbers. The restored numbers should be positive integers without leading zeros. Since there can be multiple ways to do it, determine the minimum possible sum of all Petya's numbers after the restoration. It is guaranteed that before Vasya's joke all Petya's numbers did not have leading zeros. Input The first line contains a single integer n (1 ≀ n ≀ 1 000) β€” the number of Petya's numbers. Each of the following lines contains non-empty string si consisting of lowercase Latin letters from 'a' to 'j' β€” the Petya's numbers after Vasya's joke. The length of each string does not exceed six characters. Output Determine the minimum sum of all Petya's numbers after the restoration. The restored numbers should be positive integers without leading zeros. It is guaranteed that the correct restore (without leading zeros) exists for all given tests. Examples Input 3 ab de aj Output 47 Input 5 abcdef ghij bdef accbd g Output 136542 Input 3 aa jj aa Output 44 Note In the first example, you need to replace the letter 'a' with the digit 1, the letter 'b' with the digit 0, the letter 'd' with the digit 2, the letter 'e' with the digit 3, and the letter 'j' with the digit 4. So after the restoration numbers will look like [10, 23, 14]. The sum of them is equal to 47, which is the minimum possible sum of the numbers after the correct restoration. In the second example the numbers after the restoration can look like: [120468, 3579, 2468, 10024, 3]. In the second example the numbers after the restoration can look like: [11, 22, 11].
instruction
0
77,308
20
154,616
Tags: constructive algorithms, greedy, math Correct Solution: ``` import re import sys exit=sys.exit from bisect import bisect_left as bsl,bisect_right as bsr from collections import Counter,defaultdict as ddict,deque from functools import lru_cache cache=lru_cache(None) from heapq import * from itertools import * from math import inf from pprint import pprint as pp enum=enumerate ri=lambda:int(rln()) ris=lambda:list(map(int,rfs())) rln=sys.stdin.readline rl=lambda:rln().rstrip('\n') rfs=lambda:rln().split() mod=1000000007 d4=[(0,-1),(1,0),(0,1),(-1,0)] d8=[(-1,-1),(0,-1),(1,-1),(-1,0),(1,0),(-1,1),(0,1),(1,1)] ######################################################################## n=ri() a=[rl() for _ in range(n)] first=set() cnt=ddict(int) for s in a: first.add(s[0]) p=1 for c in reversed(s): cnt[c]+=p p*=10 mp={} z=0 v=1 for c in sorted(cnt,key=lambda c:-cnt[c]): if not z and c not in first: mp[c]=0 z=1 else: mp[c]=v v+=1 ans=0 for s in a: v=0 for c in s: v=10*v+mp[c] ans+=v print(ans) ```
output
1
77,308
20
154,617
Provide tags and a correct Python 3 solution for this coding contest problem. Petya has n positive integers a1, a2, ..., an. His friend Vasya decided to joke and replaced all digits in Petya's numbers with a letters. He used the lowercase letters of the Latin alphabet from 'a' to 'j' and replaced all digits 0 with one letter, all digits 1 with another letter and so on. For any two different digits Vasya used distinct letters from 'a' to 'j'. Your task is to restore Petya's numbers. The restored numbers should be positive integers without leading zeros. Since there can be multiple ways to do it, determine the minimum possible sum of all Petya's numbers after the restoration. It is guaranteed that before Vasya's joke all Petya's numbers did not have leading zeros. Input The first line contains a single integer n (1 ≀ n ≀ 1 000) β€” the number of Petya's numbers. Each of the following lines contains non-empty string si consisting of lowercase Latin letters from 'a' to 'j' β€” the Petya's numbers after Vasya's joke. The length of each string does not exceed six characters. Output Determine the minimum sum of all Petya's numbers after the restoration. The restored numbers should be positive integers without leading zeros. It is guaranteed that the correct restore (without leading zeros) exists for all given tests. Examples Input 3 ab de aj Output 47 Input 5 abcdef ghij bdef accbd g Output 136542 Input 3 aa jj aa Output 44 Note In the first example, you need to replace the letter 'a' with the digit 1, the letter 'b' with the digit 0, the letter 'd' with the digit 2, the letter 'e' with the digit 3, and the letter 'j' with the digit 4. So after the restoration numbers will look like [10, 23, 14]. The sum of them is equal to 47, which is the minimum possible sum of the numbers after the correct restoration. In the second example the numbers after the restoration can look like: [120468, 3579, 2468, 10024, 3]. In the second example the numbers after the restoration can look like: [11, 22, 11].
instruction
0
77,309
20
154,618
Tags: constructive algorithms, greedy, math Correct Solution: ``` from sys import stdin,stdout from math import gcd,sqrt,factorial,pi,inf from collections import deque,defaultdict from bisect import bisect,bisect_left from time import time from itertools import permutations as per from heapq import heapify,heappush,heappop,heappushpop input=stdin.readline R=lambda:map(int,input().split()) I=lambda:int(input()) S=lambda:input().rstrip('\r\n') L=lambda:list(R()) P=lambda x:stdout.write(str(x)+'\n') lcm=lambda x,y:(x*y)//gcd(x,y) nCr=lambda x,y:(f[x]*inv((f[y]*f[x-y])%N))%N inv=lambda x:pow(x,N-2,N) sm=lambda x:(x**2+x)//2 N=10**9+7 v=[0]*26 p=[0]*26 for i in range(I()): s=S()[::-1] p[ord(s[-1])-97]=1 for i,j in enumerate(s): v[ord(j)-97]+=(10**i) v=sorted(enumerate(v),reverse=True,key=lambda x:x[1]) a=list(range(27))[::-1] ans=0 for i,j in v: if p[i]: if not a[-1]: ans+=j*a.pop(-2) else: ans+=j*a.pop() else: ans+=j*a.pop() print(ans) ```
output
1
77,309
20
154,619
Provide tags and a correct Python 3 solution for this coding contest problem. Petya has n positive integers a1, a2, ..., an. His friend Vasya decided to joke and replaced all digits in Petya's numbers with a letters. He used the lowercase letters of the Latin alphabet from 'a' to 'j' and replaced all digits 0 with one letter, all digits 1 with another letter and so on. For any two different digits Vasya used distinct letters from 'a' to 'j'. Your task is to restore Petya's numbers. The restored numbers should be positive integers without leading zeros. Since there can be multiple ways to do it, determine the minimum possible sum of all Petya's numbers after the restoration. It is guaranteed that before Vasya's joke all Petya's numbers did not have leading zeros. Input The first line contains a single integer n (1 ≀ n ≀ 1 000) β€” the number of Petya's numbers. Each of the following lines contains non-empty string si consisting of lowercase Latin letters from 'a' to 'j' β€” the Petya's numbers after Vasya's joke. The length of each string does not exceed six characters. Output Determine the minimum sum of all Petya's numbers after the restoration. The restored numbers should be positive integers without leading zeros. It is guaranteed that the correct restore (without leading zeros) exists for all given tests. Examples Input 3 ab de aj Output 47 Input 5 abcdef ghij bdef accbd g Output 136542 Input 3 aa jj aa Output 44 Note In the first example, you need to replace the letter 'a' with the digit 1, the letter 'b' with the digit 0, the letter 'd' with the digit 2, the letter 'e' with the digit 3, and the letter 'j' with the digit 4. So after the restoration numbers will look like [10, 23, 14]. The sum of them is equal to 47, which is the minimum possible sum of the numbers after the correct restoration. In the second example the numbers after the restoration can look like: [120468, 3579, 2468, 10024, 3]. In the second example the numbers after the restoration can look like: [11, 22, 11].
instruction
0
77,310
20
154,620
Tags: constructive algorithms, greedy, math Correct Solution: ``` import math import operator num = int(input()) total = 0 store = {} nonzero = [] _max = 0 for i in range(num): _in = input() if _max < len(_in): _max = len(_in) if _in[0] not in nonzero: nonzero.append(_in[0]) for j in range(len(_in)-1,-1,-1): if _in[j] in store: store[_in[j]] += pow(10,len(_in)-j-1) else: store[_in[j]] = pow(10,len(_in)-j-1) x = store sorted_x = sorted(x.items(), key=operator.itemgetter(1)) used = False cur = 1 for i in range(len(sorted_x)-1,-1,-1): if sorted_x[i][0] not in nonzero and used == False: used = True else: total += sorted_x[i][1] * cur cur += 1 print(total) ```
output
1
77,310
20
154,621
Provide tags and a correct Python 3 solution for this coding contest problem. Petya has n positive integers a1, a2, ..., an. His friend Vasya decided to joke and replaced all digits in Petya's numbers with a letters. He used the lowercase letters of the Latin alphabet from 'a' to 'j' and replaced all digits 0 with one letter, all digits 1 with another letter and so on. For any two different digits Vasya used distinct letters from 'a' to 'j'. Your task is to restore Petya's numbers. The restored numbers should be positive integers without leading zeros. Since there can be multiple ways to do it, determine the minimum possible sum of all Petya's numbers after the restoration. It is guaranteed that before Vasya's joke all Petya's numbers did not have leading zeros. Input The first line contains a single integer n (1 ≀ n ≀ 1 000) β€” the number of Petya's numbers. Each of the following lines contains non-empty string si consisting of lowercase Latin letters from 'a' to 'j' β€” the Petya's numbers after Vasya's joke. The length of each string does not exceed six characters. Output Determine the minimum sum of all Petya's numbers after the restoration. The restored numbers should be positive integers without leading zeros. It is guaranteed that the correct restore (without leading zeros) exists for all given tests. Examples Input 3 ab de aj Output 47 Input 5 abcdef ghij bdef accbd g Output 136542 Input 3 aa jj aa Output 44 Note In the first example, you need to replace the letter 'a' with the digit 1, the letter 'b' with the digit 0, the letter 'd' with the digit 2, the letter 'e' with the digit 3, and the letter 'j' with the digit 4. So after the restoration numbers will look like [10, 23, 14]. The sum of them is equal to 47, which is the minimum possible sum of the numbers after the correct restoration. In the second example the numbers after the restoration can look like: [120468, 3579, 2468, 10024, 3]. In the second example the numbers after the restoration can look like: [11, 22, 11].
instruction
0
77,311
20
154,622
Tags: constructive algorithms, greedy, math Correct Solution: ``` #! /usr/bin/env python3 #------------------------------------------------ # Author: krishna # Created: Sun Dec 24 17:45:40 IST 2017 # File Name: 910c.py # USAGE: # 910c.py # Description: # #------------------------------------------------ import sys, operator data = [] c = int(sys.stdin.readline().rstrip()) for i in range(c): data.append(sys.stdin.readline().rstrip()) maxLen = max(len(line) for line in data) cantTakeZero = [line[0] for line in data] for i in range(len(data)): data[i] = ('0' * (maxLen - len(data[i]))) + data[i] count = {chr(i):0 for i in range(ord('a'), ord('k'))} for i in range(maxLen): for line in data: if (line[i] == '0'): continue count[line[i]] += 1 count = {k: v * 10 for (k,v) in count.items()} count = {k: int(v / 10) for (k,v) in count.items()} code = {} counter = 1 zeroUsed = 0 # For given column, fix the values for k in (sorted(count.items(), key=operator.itemgetter(1), reverse=True)): if (k[0] in code): continue if (zeroUsed == 0) and ((k[0] in cantTakeZero) == False): code[k[0]] = 0 zeroUsed = 1 else: code[k[0]] = counter counter += 1 s = 0 for i in range(maxLen): for line in data: if (line[i] != '0'): s += code[line[i]] s *= 10 # print(sorted(code.items())) print(int(s / 10)) ```
output
1
77,311
20
154,623
Provide tags and a correct Python 3 solution for this coding contest problem. Petya has n positive integers a1, a2, ..., an. His friend Vasya decided to joke and replaced all digits in Petya's numbers with a letters. He used the lowercase letters of the Latin alphabet from 'a' to 'j' and replaced all digits 0 with one letter, all digits 1 with another letter and so on. For any two different digits Vasya used distinct letters from 'a' to 'j'. Your task is to restore Petya's numbers. The restored numbers should be positive integers without leading zeros. Since there can be multiple ways to do it, determine the minimum possible sum of all Petya's numbers after the restoration. It is guaranteed that before Vasya's joke all Petya's numbers did not have leading zeros. Input The first line contains a single integer n (1 ≀ n ≀ 1 000) β€” the number of Petya's numbers. Each of the following lines contains non-empty string si consisting of lowercase Latin letters from 'a' to 'j' β€” the Petya's numbers after Vasya's joke. The length of each string does not exceed six characters. Output Determine the minimum sum of all Petya's numbers after the restoration. The restored numbers should be positive integers without leading zeros. It is guaranteed that the correct restore (without leading zeros) exists for all given tests. Examples Input 3 ab de aj Output 47 Input 5 abcdef ghij bdef accbd g Output 136542 Input 3 aa jj aa Output 44 Note In the first example, you need to replace the letter 'a' with the digit 1, the letter 'b' with the digit 0, the letter 'd' with the digit 2, the letter 'e' with the digit 3, and the letter 'j' with the digit 4. So after the restoration numbers will look like [10, 23, 14]. The sum of them is equal to 47, which is the minimum possible sum of the numbers after the correct restoration. In the second example the numbers after the restoration can look like: [120468, 3579, 2468, 10024, 3]. In the second example the numbers after the restoration can look like: [11, 22, 11].
instruction
0
77,312
20
154,624
Tags: constructive algorithms, greedy, math Correct Solution: ``` from collections import defaultdict n = int(input()) is_first = [] d = defaultdict(int) ans = 0 for _ in range(n): s = input() slen = len(s) for i in range(slen): t = s[i] if i == 0: if t not in is_first: is_first.append(t) num = 10 ** (slen - i - 1) d[t] += num l = sorted(d.items(), key=lambda v: v[1], reverse=True) for i,x in enumerate(l): if x[0] not in is_first: l.pop(i) break for i,x in enumerate(l): ans += x[1] * (i+1) print(ans) ```
output
1
77,312
20
154,625
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya has n positive integers a1, a2, ..., an. His friend Vasya decided to joke and replaced all digits in Petya's numbers with a letters. He used the lowercase letters of the Latin alphabet from 'a' to 'j' and replaced all digits 0 with one letter, all digits 1 with another letter and so on. For any two different digits Vasya used distinct letters from 'a' to 'j'. Your task is to restore Petya's numbers. The restored numbers should be positive integers without leading zeros. Since there can be multiple ways to do it, determine the minimum possible sum of all Petya's numbers after the restoration. It is guaranteed that before Vasya's joke all Petya's numbers did not have leading zeros. Input The first line contains a single integer n (1 ≀ n ≀ 1 000) β€” the number of Petya's numbers. Each of the following lines contains non-empty string si consisting of lowercase Latin letters from 'a' to 'j' β€” the Petya's numbers after Vasya's joke. The length of each string does not exceed six characters. Output Determine the minimum sum of all Petya's numbers after the restoration. The restored numbers should be positive integers without leading zeros. It is guaranteed that the correct restore (without leading zeros) exists for all given tests. Examples Input 3 ab de aj Output 47 Input 5 abcdef ghij bdef accbd g Output 136542 Input 3 aa jj aa Output 44 Note In the first example, you need to replace the letter 'a' with the digit 1, the letter 'b' with the digit 0, the letter 'd' with the digit 2, the letter 'e' with the digit 3, and the letter 'j' with the digit 4. So after the restoration numbers will look like [10, 23, 14]. The sum of them is equal to 47, which is the minimum possible sum of the numbers after the correct restoration. In the second example the numbers after the restoration can look like: [120468, 3579, 2468, 10024, 3]. In the second example the numbers after the restoration can look like: [11, 22, 11]. Submitted Solution: ``` from collections import Counter inp = [input() for _ in range(int(input()))] weight = Counter() for word in inp: len_w = len(word) - 1 for i, l in enumerate(word): weight[l] += 10**(len_w - i) digit_map = {ord(x):0 for x in weight} non_start = set(weight) - {x[0] for x in inp} if non_start: most_nonstart = max(non_start, key=weight.get) digit_map[ord(most_nonstart)] = '0' del weight[most_nonstart] digit_ord = (ord(k) for k, v in weight.most_common()) for i, w in enumerate(digit_ord, ord('1')): digit_map[w] = i print(sum(int(x.translate(digit_map)) for x in inp)) ```
instruction
0
77,313
20
154,626
Yes
output
1
77,313
20
154,627
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya has n positive integers a1, a2, ..., an. His friend Vasya decided to joke and replaced all digits in Petya's numbers with a letters. He used the lowercase letters of the Latin alphabet from 'a' to 'j' and replaced all digits 0 with one letter, all digits 1 with another letter and so on. For any two different digits Vasya used distinct letters from 'a' to 'j'. Your task is to restore Petya's numbers. The restored numbers should be positive integers without leading zeros. Since there can be multiple ways to do it, determine the minimum possible sum of all Petya's numbers after the restoration. It is guaranteed that before Vasya's joke all Petya's numbers did not have leading zeros. Input The first line contains a single integer n (1 ≀ n ≀ 1 000) β€” the number of Petya's numbers. Each of the following lines contains non-empty string si consisting of lowercase Latin letters from 'a' to 'j' β€” the Petya's numbers after Vasya's joke. The length of each string does not exceed six characters. Output Determine the minimum sum of all Petya's numbers after the restoration. The restored numbers should be positive integers without leading zeros. It is guaranteed that the correct restore (without leading zeros) exists for all given tests. Examples Input 3 ab de aj Output 47 Input 5 abcdef ghij bdef accbd g Output 136542 Input 3 aa jj aa Output 44 Note In the first example, you need to replace the letter 'a' with the digit 1, the letter 'b' with the digit 0, the letter 'd' with the digit 2, the letter 'e' with the digit 3, and the letter 'j' with the digit 4. So after the restoration numbers will look like [10, 23, 14]. The sum of them is equal to 47, which is the minimum possible sum of the numbers after the correct restoration. In the second example the numbers after the restoration can look like: [120468, 3579, 2468, 10024, 3]. In the second example the numbers after the restoration can look like: [11, 22, 11]. Submitted Solution: ``` from collections import OrderedDict num_list = [n for n in range(0, 10)] n = int(input()) char_priority_dict = {} zero_is_permitted = {} inputs = [] for c in 'abcdefghij': char_priority_dict[c] = 0 zero_is_permitted[c] = True for i in range(n): s = input() inputs.append(s) zero_is_permitted[s[0]] = False reversed_s = s[::-1] # reversed for (j, c) in enumerate(reversed_s): char_priority_dict[c] += 10 ** j char_priority_dict = OrderedDict(sorted(char_priority_dict.items(), key=lambda x: x[1], reverse=True)) char_num_dict = {} for char in char_priority_dict.keys(): if 0 in num_list: if zero_is_permitted[char]: char_num_dict[char] = 0 num_list.remove(0) else : char_num_dict[char] = num_list[1] num_list.remove(num_list[1]) else: char_num_dict[char] = num_list[0] num_list.remove(num_list[0]) keys = ''.join(list(char_num_dict.keys())) values = ''.join(list(map(str, char_num_dict.values()))) restored_values = [] for s in inputs: restored_values.append(int(s.translate(s.maketrans(keys, values)))) print(sum(restored_values)) ```
instruction
0
77,314
20
154,628
Yes
output
1
77,314
20
154,629
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya has n positive integers a1, a2, ..., an. His friend Vasya decided to joke and replaced all digits in Petya's numbers with a letters. He used the lowercase letters of the Latin alphabet from 'a' to 'j' and replaced all digits 0 with one letter, all digits 1 with another letter and so on. For any two different digits Vasya used distinct letters from 'a' to 'j'. Your task is to restore Petya's numbers. The restored numbers should be positive integers without leading zeros. Since there can be multiple ways to do it, determine the minimum possible sum of all Petya's numbers after the restoration. It is guaranteed that before Vasya's joke all Petya's numbers did not have leading zeros. Input The first line contains a single integer n (1 ≀ n ≀ 1 000) β€” the number of Petya's numbers. Each of the following lines contains non-empty string si consisting of lowercase Latin letters from 'a' to 'j' β€” the Petya's numbers after Vasya's joke. The length of each string does not exceed six characters. Output Determine the minimum sum of all Petya's numbers after the restoration. The restored numbers should be positive integers without leading zeros. It is guaranteed that the correct restore (without leading zeros) exists for all given tests. Examples Input 3 ab de aj Output 47 Input 5 abcdef ghij bdef accbd g Output 136542 Input 3 aa jj aa Output 44 Note In the first example, you need to replace the letter 'a' with the digit 1, the letter 'b' with the digit 0, the letter 'd' with the digit 2, the letter 'e' with the digit 3, and the letter 'j' with the digit 4. So after the restoration numbers will look like [10, 23, 14]. The sum of them is equal to 47, which is the minimum possible sum of the numbers after the correct restoration. In the second example the numbers after the restoration can look like: [120468, 3579, 2468, 10024, 3]. In the second example the numbers after the restoration can look like: [11, 22, 11]. Submitted Solution: ``` # ---------------------------iye ha aam zindegi--------------------------------------------- import math import heapq, bisect import sys from collections import deque, defaultdict from fractions import Fraction mod = 10 ** 9 + 7 mod1 = 998244353 # ------------------------------warmup---------------------------- import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # -------------------game starts now----------------------------------------------------import math class TreeNode: def __init__(self, k, v): self.key = k self.value = v self.left = None self.right = None self.parent = None self.height = 1 self.num_left = 1 self.num_total = 1 class AvlTree: def __init__(self): self._tree = None def add(self, k, v): if not self._tree: self._tree = TreeNode(k, v) return node = self._add(k, v) if node: self._rebalance(node) def _add(self, k, v): node = self._tree while node: if k < node.key: if node.left: node = node.left else: node.left = TreeNode(k, v) node.left.parent = node return node.left elif node.key < k: if node.right: node = node.right else: node.right = TreeNode(k, v) node.right.parent = node return node.right else: node.value = v return @staticmethod def get_height(x): return x.height if x else 0 @staticmethod def get_num_total(x): return x.num_total if x else 0 def _rebalance(self, node): n = node while n: lh = self.get_height(n.left) rh = self.get_height(n.right) n.height = max(lh, rh) + 1 balance_factor = lh - rh n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right) n.num_left = 1 + self.get_num_total(n.left) if balance_factor > 1: if self.get_height(n.left.left) < self.get_height(n.left.right): self._rotate_left(n.left) self._rotate_right(n) elif balance_factor < -1: if self.get_height(n.right.right) < self.get_height(n.right.left): self._rotate_right(n.right) self._rotate_left(n) else: n = n.parent def _remove_one(self, node): """ Side effect!!! Changes node. Node should have exactly one child """ replacement = node.left or node.right if node.parent: if AvlTree._is_left(node): node.parent.left = replacement else: node.parent.right = replacement replacement.parent = node.parent node.parent = None else: self._tree = replacement replacement.parent = None node.left = None node.right = None node.parent = None self._rebalance(replacement) def _remove_leaf(self, node): if node.parent: if AvlTree._is_left(node): node.parent.left = None else: node.parent.right = None self._rebalance(node.parent) else: self._tree = None node.parent = None node.left = None node.right = None def remove(self, k): node = self._get_node(k) if not node: return if AvlTree._is_leaf(node): self._remove_leaf(node) return if node.left and node.right: nxt = AvlTree._get_next(node) node.key = nxt.key node.value = nxt.value if self._is_leaf(nxt): self._remove_leaf(nxt) else: self._remove_one(nxt) self._rebalance(node) else: self._remove_one(node) def get(self, k): node = self._get_node(k) return node.value if node else -1 def _get_node(self, k): if not self._tree: return None node = self._tree while node: if k < node.key: node = node.left elif node.key < k: node = node.right else: return node return None def get_at(self, pos): x = pos + 1 node = self._tree while node: if x < node.num_left: node = node.left elif node.num_left < x: x -= node.num_left node = node.right else: return (node.key, node.value) raise IndexError("Out of ranges") @staticmethod def _is_left(node): return node.parent.left and node.parent.left == node @staticmethod def _is_leaf(node): return node.left is None and node.right is None def _rotate_right(self, node): if not node.parent: self._tree = node.left node.left.parent = None elif AvlTree._is_left(node): node.parent.left = node.left node.left.parent = node.parent else: node.parent.right = node.left node.left.parent = node.parent bk = node.left.right node.left.right = node node.parent = node.left node.left = bk if bk: bk.parent = node node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1 node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right) node.num_left = 1 + self.get_num_total(node.left) def _rotate_left(self, node): if not node.parent: self._tree = node.right node.right.parent = None elif AvlTree._is_left(node): node.parent.left = node.right node.right.parent = node.parent else: node.parent.right = node.right node.right.parent = node.parent bk = node.right.left node.right.left = node node.parent = node.right node.right = bk if bk: bk.parent = node node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1 node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right) node.num_left = 1 + self.get_num_total(node.left) @staticmethod def _get_next(node): if not node.right: return node.parent n = node.right while n.left: n = n.left return n avl=AvlTree() #-----------------------------------------------binary seacrh tree--------------------------------------- class SegmentTree1: def __init__(self, data, default='z', 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) # -------------------game starts now----------------------------------------------------import math class SegmentTree: def __init__(self, data, default=0, func=lambda a, b: a * a + b * 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) # -------------------------------iye ha chutiya zindegi------------------------------------- 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 # --------------------------------------iye ha combinations ka zindegi--------------------------------- def powm(a, n, m): if a == 1 or n == 0: return 1 if n % 2 == 0: s = powm(a, n // 2, m) return s * s % m else: return a * powm(a, n - 1, m) % m # --------------------------------------iye ha power ka zindegi--------------------------------- def sort_list(list1, list2): zipped_pairs = zip(list2, list1) z = [x for _, x in sorted(zipped_pairs)] return z # --------------------------------------------------product---------------------------------------- def product(l): por = 1 for i in range(len(l)): por *= l[i] return por # --------------------------------------------------binary---------------------------------------- def binarySearchCount(arr, n, key): left = 0 right = n - 1 count = 0 while (left <= right): mid = int((right + left)/ 2) # Check if middle element is # less than or equal to key if (arr[mid]<=key): count = mid+1 left = mid + 1 # If key is smaller, ignore right half else: right = mid - 1 return count # --------------------------------------------------binary---------------------------------------- def countdig(n): c = 0 while (n > 0): n //= 10 c += 1 return c def countGreater( arr,n, k): l = 0 r = n - 1 # Stores the index of the left most element # from the array which is greater than k leftGreater = n # Finds number of elements greater than k while (l <= r): m = int(l + (r - l) / 2) if (arr[m] >= k): leftGreater = m r = m - 1 # If mid element is less than # or equal to k update l else: l = m + 1 # Return the count of elements # greater than k return (n - leftGreater) # --------------------------------------------------binary------------------------------------ n=int(input()) l=[] m=0 for i in range(n): l.append(list(input())) m=max(m,len(l[-1])) count=[0 for i in range(10)] f=[0 for i in range(10)] for i in range(n): for j in range(len(l[i])): f[ord(l[i][0])-97]=1 count[ord(l[i][j])-97]+=pow(10,len(l[i])-j) r=0 t=1 ans=[0]*10 for i in range(10): m=count.index(max(count)) if f[m]==1: ans[m]=t count[m]=-1 t+=1 else: if r==0: ans[m]=0 count[m] = -1 r=1 else: ans[m]=t count[m] = -1 t+=1 ans1=0 for i in range(n): s="" for j in range(len(l[i])): s=s+str(ans[ord(l[i][j])-97]) ans1+=int(s) print(ans1) ```
instruction
0
77,315
20
154,630
Yes
output
1
77,315
20
154,631
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya has n positive integers a1, a2, ..., an. His friend Vasya decided to joke and replaced all digits in Petya's numbers with a letters. He used the lowercase letters of the Latin alphabet from 'a' to 'j' and replaced all digits 0 with one letter, all digits 1 with another letter and so on. For any two different digits Vasya used distinct letters from 'a' to 'j'. Your task is to restore Petya's numbers. The restored numbers should be positive integers without leading zeros. Since there can be multiple ways to do it, determine the minimum possible sum of all Petya's numbers after the restoration. It is guaranteed that before Vasya's joke all Petya's numbers did not have leading zeros. Input The first line contains a single integer n (1 ≀ n ≀ 1 000) β€” the number of Petya's numbers. Each of the following lines contains non-empty string si consisting of lowercase Latin letters from 'a' to 'j' β€” the Petya's numbers after Vasya's joke. The length of each string does not exceed six characters. Output Determine the minimum sum of all Petya's numbers after the restoration. The restored numbers should be positive integers without leading zeros. It is guaranteed that the correct restore (without leading zeros) exists for all given tests. Examples Input 3 ab de aj Output 47 Input 5 abcdef ghij bdef accbd g Output 136542 Input 3 aa jj aa Output 44 Note In the first example, you need to replace the letter 'a' with the digit 1, the letter 'b' with the digit 0, the letter 'd' with the digit 2, the letter 'e' with the digit 3, and the letter 'j' with the digit 4. So after the restoration numbers will look like [10, 23, 14]. The sum of them is equal to 47, which is the minimum possible sum of the numbers after the correct restoration. In the second example the numbers after the restoration can look like: [120468, 3579, 2468, 10024, 3]. In the second example the numbers after the restoration can look like: [11, 22, 11]. Submitted Solution: ``` def sumArr(ax): sm=0 for i in range(len(ax)): sm+=(10**i)*ax[i] return sm n=int(input()) arr={} la='abcdefghij' for i in la: arr.update({i:{'m':[0,0,0,0,0,0],'not0':False,'sm':0}}) while (n>0): n-=1 x=input()[::-1] L=len(x) for i in range(L): arr[x[i]]['m'][i]+=1 if i==L-1: arr[x[i]]['not0']=True arrF=[] arrT=[] for i in la: arr[i]['sm']=sumArr(arr[i]['m']) if arr[i]['not0']: arrT.append(arr[i]['sm']) else: arrF.append(arr[i]['sm']) arrF=sorted(arrF) arrT=sorted(arrT) arrF=arrF[::-1] arrT=arrT[::-1] iaT=0 if len(arrF)>0: iaF=1 arrQ=[arrF[0]] else: iaF=0 arrQ=[0] for i in range(9): mF,mT=-1,-1 if iaT<len(arrT): mT=arrT[iaT] if iaF<len(arrF): mF=arrF[iaF] if mF>=mT: arrQ.append(mF) iaF+=1 else: arrQ.append(mT) iaT+=1 sm=0 for i in range(len(arrQ)): sm+=arrQ[i]*i print(sm) ```
instruction
0
77,316
20
154,632
Yes
output
1
77,316
20
154,633
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya has n positive integers a1, a2, ..., an. His friend Vasya decided to joke and replaced all digits in Petya's numbers with a letters. He used the lowercase letters of the Latin alphabet from 'a' to 'j' and replaced all digits 0 with one letter, all digits 1 with another letter and so on. For any two different digits Vasya used distinct letters from 'a' to 'j'. Your task is to restore Petya's numbers. The restored numbers should be positive integers without leading zeros. Since there can be multiple ways to do it, determine the minimum possible sum of all Petya's numbers after the restoration. It is guaranteed that before Vasya's joke all Petya's numbers did not have leading zeros. Input The first line contains a single integer n (1 ≀ n ≀ 1 000) β€” the number of Petya's numbers. Each of the following lines contains non-empty string si consisting of lowercase Latin letters from 'a' to 'j' β€” the Petya's numbers after Vasya's joke. The length of each string does not exceed six characters. Output Determine the minimum sum of all Petya's numbers after the restoration. The restored numbers should be positive integers without leading zeros. It is guaranteed that the correct restore (without leading zeros) exists for all given tests. Examples Input 3 ab de aj Output 47 Input 5 abcdef ghij bdef accbd g Output 136542 Input 3 aa jj aa Output 44 Note In the first example, you need to replace the letter 'a' with the digit 1, the letter 'b' with the digit 0, the letter 'd' with the digit 2, the letter 'e' with the digit 3, and the letter 'j' with the digit 4. So after the restoration numbers will look like [10, 23, 14]. The sum of them is equal to 47, which is the minimum possible sum of the numbers after the correct restoration. In the second example the numbers after the restoration can look like: [120468, 3579, 2468, 10024, 3]. In the second example the numbers after the restoration can look like: [11, 22, 11]. Submitted Solution: ``` n = int(input()) s = [input() for _ in range(n)] t = max(len(i) for i in s) v = {} p = 1 z = set() f = 1 for i in range(n): z.add(s[i][0]) s[i] = ' ' * (t - len(s[i])) + s[i] for i in range(t): for j in range(n): if s[j][i] == ' ': continue if s[j][i] not in v: if s[j][i] in z: v[s[j][i]] = p p += 1 else: if f: v[s[j][i]] = 0 f = 0 else: v[s[j][i]] = p p += 1 ans = 0 for i in range(n): t = 1 for j in range(len(s[i]) - 1, -1, -1): if s[i][j] == ' ': continue ans += t * v[s[i][j]] t *= 10 print(ans) ```
instruction
0
77,317
20
154,634
No
output
1
77,317
20
154,635
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya has n positive integers a1, a2, ..., an. His friend Vasya decided to joke and replaced all digits in Petya's numbers with a letters. He used the lowercase letters of the Latin alphabet from 'a' to 'j' and replaced all digits 0 with one letter, all digits 1 with another letter and so on. For any two different digits Vasya used distinct letters from 'a' to 'j'. Your task is to restore Petya's numbers. The restored numbers should be positive integers without leading zeros. Since there can be multiple ways to do it, determine the minimum possible sum of all Petya's numbers after the restoration. It is guaranteed that before Vasya's joke all Petya's numbers did not have leading zeros. Input The first line contains a single integer n (1 ≀ n ≀ 1 000) β€” the number of Petya's numbers. Each of the following lines contains non-empty string si consisting of lowercase Latin letters from 'a' to 'j' β€” the Petya's numbers after Vasya's joke. The length of each string does not exceed six characters. Output Determine the minimum sum of all Petya's numbers after the restoration. The restored numbers should be positive integers without leading zeros. It is guaranteed that the correct restore (without leading zeros) exists for all given tests. Examples Input 3 ab de aj Output 47 Input 5 abcdef ghij bdef accbd g Output 136542 Input 3 aa jj aa Output 44 Note In the first example, you need to replace the letter 'a' with the digit 1, the letter 'b' with the digit 0, the letter 'd' with the digit 2, the letter 'e' with the digit 3, and the letter 'j' with the digit 4. So after the restoration numbers will look like [10, 23, 14]. The sum of them is equal to 47, which is the minimum possible sum of the numbers after the correct restoration. In the second example the numbers after the restoration can look like: [120468, 3579, 2468, 10024, 3]. In the second example the numbers after the restoration can look like: [11, 22, 11]. Submitted Solution: ``` n = int(input()) perm = [] for i in range(n): perm.append(input()) if n==6 and 'fhe' in perm and 'chafj' in perm: print(42773) exit(0) elif n==8 and 'e' in perm and 'j' in perm: print(429631) exit(0) d = {} for i in range(n - 1): for j in range(n - i - 1): if len(perm[j]) < len(perm[j + 1]): perm[j], perm[j + 1] = perm[j + 1], perm[j] mx = len(perm[0]) larr=[] for i in perm: larr.append(len(i)) for i in range(n): if len(perm[i]) != mx: perm[i]= "$"*(mx - len(perm[i]))+perm[i] p1, p2 = 1, 0 for i in range(mx): if i == 0: for j in perm: if j[i] not in d and j[i]!='$': d[j[i]] = p1 p1+=1 else: for j in perm: if j[i] not in d and j[i] != '$': if p2 == 0: flag = 1 for k in range(n): if perm[k][mx-larr[k]] == j[i]: flag = 0 break if flag == 0: d[j[i]] = p1 p1 += 1 else: d[j[i]] = p2 p2 += 1 else: d[j[i]] = p1 p1 += 1 ans=0 for i in range(n): j=mx-1 base=1 while perm[i][j]!='$' and j>=0: ans+=base*d[perm[i][j]] j-=1 base*=10 print(ans) ```
instruction
0
77,318
20
154,636
No
output
1
77,318
20
154,637
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya has n positive integers a1, a2, ..., an. His friend Vasya decided to joke and replaced all digits in Petya's numbers with a letters. He used the lowercase letters of the Latin alphabet from 'a' to 'j' and replaced all digits 0 with one letter, all digits 1 with another letter and so on. For any two different digits Vasya used distinct letters from 'a' to 'j'. Your task is to restore Petya's numbers. The restored numbers should be positive integers without leading zeros. Since there can be multiple ways to do it, determine the minimum possible sum of all Petya's numbers after the restoration. It is guaranteed that before Vasya's joke all Petya's numbers did not have leading zeros. Input The first line contains a single integer n (1 ≀ n ≀ 1 000) β€” the number of Petya's numbers. Each of the following lines contains non-empty string si consisting of lowercase Latin letters from 'a' to 'j' β€” the Petya's numbers after Vasya's joke. The length of each string does not exceed six characters. Output Determine the minimum sum of all Petya's numbers after the restoration. The restored numbers should be positive integers without leading zeros. It is guaranteed that the correct restore (without leading zeros) exists for all given tests. Examples Input 3 ab de aj Output 47 Input 5 abcdef ghij bdef accbd g Output 136542 Input 3 aa jj aa Output 44 Note In the first example, you need to replace the letter 'a' with the digit 1, the letter 'b' with the digit 0, the letter 'd' with the digit 2, the letter 'e' with the digit 3, and the letter 'j' with the digit 4. So after the restoration numbers will look like [10, 23, 14]. The sum of them is equal to 47, which is the minimum possible sum of the numbers after the correct restoration. In the second example the numbers after the restoration can look like: [120468, 3579, 2468, 10024, 3]. In the second example the numbers after the restoration can look like: [11, 22, 11]. Submitted Solution: ``` import re import sys exit=sys.exit from bisect import bisect_left as bsl,bisect_right as bsr from collections import Counter,defaultdict as ddict,deque from functools import lru_cache cache=lru_cache(None) from heapq import * from itertools import * from math import inf from pprint import pprint as pp enum=enumerate ri=lambda:int(rln()) ris=lambda:list(map(int,rfs())) rln=sys.stdin.readline rl=lambda:rln().rstrip('\n') rfs=lambda:rln().split() mod=1000000007 d4=[(0,-1),(1,0),(0,1),(-1,0)] d8=[(-1,-1),(0,-1),(1,-1),(-1,0),(1,0),(-1,1),(0,1),(1,1)] ######################################################################## n=ri() a=[rl() for _ in range(n)] maxlen=max(map(len,a)) first=set() for i in range(n): k=len(a[i]) first.add(a[i][0]) a[i]='.'*(maxlen-k)+a[i] pos=[[] for _ in range(6)] for j in range(maxlen): freq=ddict(int) for i in range(n): if a[i][j]=='.': continue freq[a[i][j]]+=1 pos[j]=freq @cache def key(c): ret=[] for i in range(maxlen): ret.append(-pos[i].get(c,0)) return ret mp={} z=0 v=1 for c in sorted('abcdefghij',key=key): if c in mp: continue if not z and c not in first: mp[c]=0 z=1 else: mp[c]=v v+=1 ans=0 for i in range(n): v=0 for j in range(maxlen): if a[i][j]=='.': continue v=v*10+mp[a[i][j]] ans+=v print(ans) ```
instruction
0
77,319
20
154,638
No
output
1
77,319
20
154,639
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya has n positive integers a1, a2, ..., an. His friend Vasya decided to joke and replaced all digits in Petya's numbers with a letters. He used the lowercase letters of the Latin alphabet from 'a' to 'j' and replaced all digits 0 with one letter, all digits 1 with another letter and so on. For any two different digits Vasya used distinct letters from 'a' to 'j'. Your task is to restore Petya's numbers. The restored numbers should be positive integers without leading zeros. Since there can be multiple ways to do it, determine the minimum possible sum of all Petya's numbers after the restoration. It is guaranteed that before Vasya's joke all Petya's numbers did not have leading zeros. Input The first line contains a single integer n (1 ≀ n ≀ 1 000) β€” the number of Petya's numbers. Each of the following lines contains non-empty string si consisting of lowercase Latin letters from 'a' to 'j' β€” the Petya's numbers after Vasya's joke. The length of each string does not exceed six characters. Output Determine the minimum sum of all Petya's numbers after the restoration. The restored numbers should be positive integers without leading zeros. It is guaranteed that the correct restore (without leading zeros) exists for all given tests. Examples Input 3 ab de aj Output 47 Input 5 abcdef ghij bdef accbd g Output 136542 Input 3 aa jj aa Output 44 Note In the first example, you need to replace the letter 'a' with the digit 1, the letter 'b' with the digit 0, the letter 'd' with the digit 2, the letter 'e' with the digit 3, and the letter 'j' with the digit 4. So after the restoration numbers will look like [10, 23, 14]. The sum of them is equal to 47, which is the minimum possible sum of the numbers after the correct restoration. In the second example the numbers after the restoration can look like: [120468, 3579, 2468, 10024, 3]. In the second example the numbers after the restoration can look like: [11, 22, 11]. 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 import threading from collections import defaultdict BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") #-------------------game starts now----------------------------------------------------- n=int(input()) l=0 a=list() for i in range (n): s=input() l=max(l,len(s)) a.append(s) char=['a','b','c','d','e','f','g','h','i','j'] b=[[] for i in range (10)] for c in range (10): for i in range (l): ct=0 for j in range (n): if i<len(a[j]): if a[j][i]==char[c]: ct+=1 b[c].append(ct) b[c].append(char[c]) b.sort(reverse=True) #print(b) ind=1 ch=1 d=dict() for i in range (10): c=b[i][-1] if ch==1: if b[i][0]==0: ch=0 d[c]=str(0) else: d[c]=str(ind) ind+=1 else: d[c]=str(ind) ind+=1 r=0 for i in a: s="" for j in i: s+=d[j] s=int(s) r+=s print(r) ```
instruction
0
77,320
20
154,640
No
output
1
77,320
20
154,641
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are working as an analyst in a company working on a new system for big data storage. This system will store n different objects. Each object should have a unique ID. To create the system, you choose the parameters of the system β€” integers m β‰₯ 1 and b_{1}, b_{2}, …, b_{m}. With these parameters an ID of some object in the system is an array of integers [a_{1}, a_{2}, …, a_{m}] where 1 ≀ a_{i} ≀ b_{i} holds for every 1 ≀ i ≀ m. Developers say that production costs are proportional to βˆ‘_{i=1}^{m} b_{i}. You are asked to choose parameters m and b_{i} so that the system will be able to assign unique IDs to n different objects and production costs are minimized. Note that you don't have to use all available IDs. Input In the only line of input there is one positive integer n. The length of the decimal representation of n is no greater than 1.5 β‹… 10^{6}. The integer does not contain leading zeros. Output Print one number β€” minimal value of βˆ‘_{i=1}^{m} b_{i}. Examples Input 36 Output 10 Input 37 Output 11 Input 12345678901234567890123456789 Output 177 Submitted Solution: ``` from math import ceil from decimal import Decimal, ROUND_CEILING, getcontext getcontext().prec = 1024+512 X = Decimal(input()).ln() D3 = Decimal(3).ln() D2 = Decimal(2).ln() c1 = (X / D3).to_integral_exact(rounding=ROUND_CEILING) X -= D2 c2 = (X / D3).to_integral_exact(rounding=ROUND_CEILING) X -= D2 c3 = (X / D3).to_integral_exact(rounding=ROUND_CEILING) print(max(1,int(min([3*c1, 3*c2, 3*c3+4])))) ```
instruction
0
77,339
20
154,678
No
output
1
77,339
20
154,679
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are working as an analyst in a company working on a new system for big data storage. This system will store n different objects. Each object should have a unique ID. To create the system, you choose the parameters of the system β€” integers m β‰₯ 1 and b_{1}, b_{2}, …, b_{m}. With these parameters an ID of some object in the system is an array of integers [a_{1}, a_{2}, …, a_{m}] where 1 ≀ a_{i} ≀ b_{i} holds for every 1 ≀ i ≀ m. Developers say that production costs are proportional to βˆ‘_{i=1}^{m} b_{i}. You are asked to choose parameters m and b_{i} so that the system will be able to assign unique IDs to n different objects and production costs are minimized. Note that you don't have to use all available IDs. Input In the only line of input there is one positive integer n. The length of the decimal representation of n is no greater than 1.5 β‹… 10^{6}. The integer does not contain leading zeros. Output Print one number β€” minimal value of βˆ‘_{i=1}^{m} b_{i}. Examples Input 36 Output 10 Input 37 Output 11 Input 12345678901234567890123456789 Output 177 Submitted Solution: ``` from decimal import Decimal, ROUND_CEILING, getcontext getcontext().prec = 1400 X = Decimal(input()).ln() D3 = Decimal(3).ln() D2 = Decimal(2).ln() c1 = (X / D3).to_integral_exact(rounding=ROUND_CEILING)*3 X -= D2 c2 = (X / D3).to_integral_exact(rounding=ROUND_CEILING)*3 + 2 X -= D2 c3 = (X / D3).to_integral_exact(rounding=ROUND_CEILING)*3 + 4 print(max(1,int(min([c1, c2, c3])))) ```
instruction
0
77,340
20
154,680
No
output
1
77,340
20
154,681
Provide a correct Python 3 solution for this coding contest problem. AtCoder Inc. has decided to lock the door of its office with a 3-digit PIN code. The company has an N-digit lucky number, S. Takahashi, the president, will erase N-3 digits from S and concatenate the remaining 3 digits without changing the order to set the PIN code. How many different PIN codes can he set this way? Both the lucky number and the PIN code may begin with a 0. Constraints * 4 \leq N \leq 30000 * S is a string of length N consisting of digits. Input Input is given from Standard Input in the following format: N S Output Print the number of different PIN codes Takahashi can set. Examples Input 4 0224 Output 3 Input 6 123123 Output 17 Input 19 3141592653589793238 Output 329
instruction
0
77,373
20
154,746
"Correct Solution: ``` n=int(input()) s=input() numbers=[str(i).zfill(3) for i in range(1000)] count=0 for num in numbers: j=0 for i in range(n): if num[j]==s[i]: j+=1 if j==3: break if j==3: count+=1 print(count) ```
output
1
77,373
20
154,747
Provide a correct Python 3 solution for this coding contest problem. AtCoder Inc. has decided to lock the door of its office with a 3-digit PIN code. The company has an N-digit lucky number, S. Takahashi, the president, will erase N-3 digits from S and concatenate the remaining 3 digits without changing the order to set the PIN code. How many different PIN codes can he set this way? Both the lucky number and the PIN code may begin with a 0. Constraints * 4 \leq N \leq 30000 * S is a string of length N consisting of digits. Input Input is given from Standard Input in the following format: N S Output Print the number of different PIN codes Takahashi can set. Examples Input 4 0224 Output 3 Input 6 123123 Output 17 Input 19 3141592653589793238 Output 329
instruction
0
77,374
20
154,748
"Correct Solution: ``` a=[set(),set(),set()] n=int(input()) s=input() for i in s: for j in a[1]: a[2].add(j+i) for j in a[0]: a[1].add(j+i) a[0].add(i) print(len(a[2])) ```
output
1
77,374
20
154,749
Provide a correct Python 3 solution for this coding contest problem. AtCoder Inc. has decided to lock the door of its office with a 3-digit PIN code. The company has an N-digit lucky number, S. Takahashi, the president, will erase N-3 digits from S and concatenate the remaining 3 digits without changing the order to set the PIN code. How many different PIN codes can he set this way? Both the lucky number and the PIN code may begin with a 0. Constraints * 4 \leq N \leq 30000 * S is a string of length N consisting of digits. Input Input is given from Standard Input in the following format: N S Output Print the number of different PIN codes Takahashi can set. Examples Input 4 0224 Output 3 Input 6 123123 Output 17 Input 19 3141592653589793238 Output 329
instruction
0
77,375
20
154,750
"Correct Solution: ``` N=input() S=input() ans=0 for i in range(1000): n=str(i).zfill(3) x=S.find(n[0]) y=S.find(n[1],x+1) z=S.find(n[2],y+1) if x!=-1 and y!=-1 and z!=-1: ans+=1 print(ans) ```
output
1
77,375
20
154,751
Provide a correct Python 3 solution for this coding contest problem. AtCoder Inc. has decided to lock the door of its office with a 3-digit PIN code. The company has an N-digit lucky number, S. Takahashi, the president, will erase N-3 digits from S and concatenate the remaining 3 digits without changing the order to set the PIN code. How many different PIN codes can he set this way? Both the lucky number and the PIN code may begin with a 0. Constraints * 4 \leq N \leq 30000 * S is a string of length N consisting of digits. Input Input is given from Standard Input in the following format: N S Output Print the number of different PIN codes Takahashi can set. Examples Input 4 0224 Output 3 Input 6 123123 Output 17 Input 19 3141592653589793238 Output 329
instruction
0
77,376
20
154,752
"Correct Solution: ``` n = int(input()) s = input() ans = 0 for i in range(10): for j in range(10): l = s.find(str(i)) r = s.rfind(str(j)) if l != -1 and r != -1 and l<r: ans += len(set(s[l+1:r])) print(ans) ```
output
1
77,376
20
154,753
Provide a correct Python 3 solution for this coding contest problem. AtCoder Inc. has decided to lock the door of its office with a 3-digit PIN code. The company has an N-digit lucky number, S. Takahashi, the president, will erase N-3 digits from S and concatenate the remaining 3 digits without changing the order to set the PIN code. How many different PIN codes can he set this way? Both the lucky number and the PIN code may begin with a 0. Constraints * 4 \leq N \leq 30000 * S is a string of length N consisting of digits. Input Input is given from Standard Input in the following format: N S Output Print the number of different PIN codes Takahashi can set. Examples Input 4 0224 Output 3 Input 6 123123 Output 17 Input 19 3141592653589793238 Output 329
instruction
0
77,377
20
154,754
"Correct Solution: ``` n = int(input()) s = input() result = 0 for i in range(1000): x = format(i, "03") p = 0 for j in range(n): if s[j]==x[p]: p += 1 if p==3: result += 1 break print(result) ```
output
1
77,377
20
154,755
Provide a correct Python 3 solution for this coding contest problem. AtCoder Inc. has decided to lock the door of its office with a 3-digit PIN code. The company has an N-digit lucky number, S. Takahashi, the president, will erase N-3 digits from S and concatenate the remaining 3 digits without changing the order to set the PIN code. How many different PIN codes can he set this way? Both the lucky number and the PIN code may begin with a 0. Constraints * 4 \leq N \leq 30000 * S is a string of length N consisting of digits. Input Input is given from Standard Input in the following format: N S Output Print the number of different PIN codes Takahashi can set. Examples Input 4 0224 Output 3 Input 6 123123 Output 17 Input 19 3141592653589793238 Output 329
instruction
0
77,378
20
154,756
"Correct Solution: ``` N = int(input()) S = input() s1 = set() s2 = set() s3 = set() for c in S: for c2 in s2: s3.add(c2+c) for c1 in s1: s2.add(c1+c) s1.add(c) print(len(s3)) ```
output
1
77,378
20
154,757
Provide a correct Python 3 solution for this coding contest problem. AtCoder Inc. has decided to lock the door of its office with a 3-digit PIN code. The company has an N-digit lucky number, S. Takahashi, the president, will erase N-3 digits from S and concatenate the remaining 3 digits without changing the order to set the PIN code. How many different PIN codes can he set this way? Both the lucky number and the PIN code may begin with a 0. Constraints * 4 \leq N \leq 30000 * S is a string of length N consisting of digits. Input Input is given from Standard Input in the following format: N S Output Print the number of different PIN codes Takahashi can set. Examples Input 4 0224 Output 3 Input 6 123123 Output 17 Input 19 3141592653589793238 Output 329
instruction
0
77,379
20
154,758
"Correct Solution: ``` N = int(input()) S = input() ans = 0 for i in range(1000): s = str(i).zfill(3) index = 0 for j in range(N): if s[index] == S[j]: index += 1 if index == 3: ans += 1 break print(ans) ```
output
1
77,379
20
154,759
Provide a correct Python 3 solution for this coding contest problem. AtCoder Inc. has decided to lock the door of its office with a 3-digit PIN code. The company has an N-digit lucky number, S. Takahashi, the president, will erase N-3 digits from S and concatenate the remaining 3 digits without changing the order to set the PIN code. How many different PIN codes can he set this way? Both the lucky number and the PIN code may begin with a 0. Constraints * 4 \leq N \leq 30000 * S is a string of length N consisting of digits. Input Input is given from Standard Input in the following format: N S Output Print the number of different PIN codes Takahashi can set. Examples Input 4 0224 Output 3 Input 6 123123 Output 17 Input 19 3141592653589793238 Output 329
instruction
0
77,380
20
154,760
"Correct Solution: ``` n = int(input()) s = input() a = 0 for i in range(1000): i = '%03d' % i ss = s for c in i: p = ss.find(c) if p == -1: break ss = ss[p + 1:] else: a += 1 print(a) ```
output
1
77,380
20
154,761
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. AtCoder Inc. has decided to lock the door of its office with a 3-digit PIN code. The company has an N-digit lucky number, S. Takahashi, the president, will erase N-3 digits from S and concatenate the remaining 3 digits without changing the order to set the PIN code. How many different PIN codes can he set this way? Both the lucky number and the PIN code may begin with a 0. Constraints * 4 \leq N \leq 30000 * S is a string of length N consisting of digits. Input Input is given from Standard Input in the following format: N S Output Print the number of different PIN codes Takahashi can set. Examples Input 4 0224 Output 3 Input 6 123123 Output 17 Input 19 3141592653589793238 Output 329 Submitted Solution: ``` n = input() s = input() a = set() def do(a,s,t): if len(t)==0: return a if len(s) == 2: return do(a,s,t[1:]) | {s + t[0]} else: return do(a,s,t[1:]) | do(a,s+t[0],t[1:]) print(len(do(a,"",s))) ```
instruction
0
77,388
20
154,776
No
output
1
77,388
20
154,777
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a huge decimal number consisting of n digits. It is guaranteed that this number has no leading zeros. Each digit of this number is either 0 or 1. You may perform several (possibly zero) operations with this number. During each operation you are allowed to change any digit of your number; you may change 0 to 1 or 1 to 0. It is possible that after some operation you can obtain a number with leading zeroes, but it does not matter for this problem. You are also given two integers 0 ≀ y < x < n. Your task is to calculate the minimum number of operations you should perform to obtain the number that has remainder 10^y modulo 10^x. In other words, the obtained number should have remainder 10^y when divided by 10^x. Input The first line of the input contains three integers n, x, y (0 ≀ y < x < n ≀ 2 β‹… 10^5) β€” the length of the number and the integers x and y, respectively. The second line of the input contains one decimal number consisting of n digits, each digit of this number is either 0 or 1. It is guaranteed that the first digit of the number is 1. Output Print one integer β€” the minimum number of operations you should perform to obtain the number having remainder 10^y modulo 10^x. In other words, the obtained number should have remainder 10^y when divided by 10^x. Examples Input 11 5 2 11010100101 Output 1 Input 11 5 1 11010100101 Output 3 Note In the first example the number will be 11010100100 after performing one operation. It has remainder 100 modulo 100000. In the second example the number will be 11010100010 after performing three operations. It has remainder 10 modulo 100000.
instruction
0
77,593
20
155,186
Tags: implementation, math Correct Solution: ``` nxy = input() n, x, y = [int(num) for num in nxy.split(' ')] s = input() ans = 0 for i in range(n-1,n-x-1,-1): #print(n-y,s[i]) if i==n-y-1 and s[i]=='0': ans += 1 elif i!=n-y-1 and s[i]=='1': ans += 1 print(ans) ```
output
1
77,593
20
155,187
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a huge decimal number consisting of n digits. It is guaranteed that this number has no leading zeros. Each digit of this number is either 0 or 1. You may perform several (possibly zero) operations with this number. During each operation you are allowed to change any digit of your number; you may change 0 to 1 or 1 to 0. It is possible that after some operation you can obtain a number with leading zeroes, but it does not matter for this problem. You are also given two integers 0 ≀ y < x < n. Your task is to calculate the minimum number of operations you should perform to obtain the number that has remainder 10^y modulo 10^x. In other words, the obtained number should have remainder 10^y when divided by 10^x. Input The first line of the input contains three integers n, x, y (0 ≀ y < x < n ≀ 2 β‹… 10^5) β€” the length of the number and the integers x and y, respectively. The second line of the input contains one decimal number consisting of n digits, each digit of this number is either 0 or 1. It is guaranteed that the first digit of the number is 1. Output Print one integer β€” the minimum number of operations you should perform to obtain the number having remainder 10^y modulo 10^x. In other words, the obtained number should have remainder 10^y when divided by 10^x. Examples Input 11 5 2 11010100101 Output 1 Input 11 5 1 11010100101 Output 3 Note In the first example the number will be 11010100100 after performing one operation. It has remainder 100 modulo 100000. In the second example the number will be 11010100010 after performing three operations. It has remainder 10 modulo 100000.
instruction
0
77,594
20
155,188
Tags: implementation, math Correct Solution: ``` n, x, y = [int(i) for i in input().split()] s = list(input()) s = s[::-1] ct = 0 for i in range(n): idx = i+1 if i < y and s[i] == '1': s[i] = '0' ct += 1 if i == y and s[i] == '0': ct += 1 s[i] = '1' if i>y and i<x and s[i]=='1': ct += 1 s[i] = '0' print(ct) ```
output
1
77,594
20
155,189
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a huge decimal number consisting of n digits. It is guaranteed that this number has no leading zeros. Each digit of this number is either 0 or 1. You may perform several (possibly zero) operations with this number. During each operation you are allowed to change any digit of your number; you may change 0 to 1 or 1 to 0. It is possible that after some operation you can obtain a number with leading zeroes, but it does not matter for this problem. You are also given two integers 0 ≀ y < x < n. Your task is to calculate the minimum number of operations you should perform to obtain the number that has remainder 10^y modulo 10^x. In other words, the obtained number should have remainder 10^y when divided by 10^x. Input The first line of the input contains three integers n, x, y (0 ≀ y < x < n ≀ 2 β‹… 10^5) β€” the length of the number and the integers x and y, respectively. The second line of the input contains one decimal number consisting of n digits, each digit of this number is either 0 or 1. It is guaranteed that the first digit of the number is 1. Output Print one integer β€” the minimum number of operations you should perform to obtain the number having remainder 10^y modulo 10^x. In other words, the obtained number should have remainder 10^y when divided by 10^x. Examples Input 11 5 2 11010100101 Output 1 Input 11 5 1 11010100101 Output 3 Note In the first example the number will be 11010100100 after performing one operation. It has remainder 100 modulo 100000. In the second example the number will be 11010100010 after performing three operations. It has remainder 10 modulo 100000.
instruction
0
77,595
20
155,190
Tags: implementation, math Correct Solution: ``` n, x, y = map(int, input().split()) s = input() mod = list(s[n-x:n]) before = mod[0:len(mod) - y - 1] after = mod[len(mod) - y-1: len(mod)] if after[0] == '1': print(before.count('1') + after.count('1') - 1) elif after[0] == '0': print(before.count('1') + after.count('1') + 1) ```
output
1
77,595
20
155,191
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a huge decimal number consisting of n digits. It is guaranteed that this number has no leading zeros. Each digit of this number is either 0 or 1. You may perform several (possibly zero) operations with this number. During each operation you are allowed to change any digit of your number; you may change 0 to 1 or 1 to 0. It is possible that after some operation you can obtain a number with leading zeroes, but it does not matter for this problem. You are also given two integers 0 ≀ y < x < n. Your task is to calculate the minimum number of operations you should perform to obtain the number that has remainder 10^y modulo 10^x. In other words, the obtained number should have remainder 10^y when divided by 10^x. Input The first line of the input contains three integers n, x, y (0 ≀ y < x < n ≀ 2 β‹… 10^5) β€” the length of the number and the integers x and y, respectively. The second line of the input contains one decimal number consisting of n digits, each digit of this number is either 0 or 1. It is guaranteed that the first digit of the number is 1. Output Print one integer β€” the minimum number of operations you should perform to obtain the number having remainder 10^y modulo 10^x. In other words, the obtained number should have remainder 10^y when divided by 10^x. Examples Input 11 5 2 11010100101 Output 1 Input 11 5 1 11010100101 Output 3 Note In the first example the number will be 11010100100 after performing one operation. It has remainder 100 modulo 100000. In the second example the number will be 11010100010 after performing three operations. It has remainder 10 modulo 100000.
instruction
0
77,596
20
155,192
Tags: implementation, math Correct Solution: ``` n, x, y = map(int, input().strip().split()) s = list(input()) tobe = ['0' for i in range(x)] tobe[-y-1] = '1' s = s[-x: ] c = 0 for i in range(len(s)): if s[i] != tobe[i]: c+=1 print(c) ```
output
1
77,596
20
155,193
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a huge decimal number consisting of n digits. It is guaranteed that this number has no leading zeros. Each digit of this number is either 0 or 1. You may perform several (possibly zero) operations with this number. During each operation you are allowed to change any digit of your number; you may change 0 to 1 or 1 to 0. It is possible that after some operation you can obtain a number with leading zeroes, but it does not matter for this problem. You are also given two integers 0 ≀ y < x < n. Your task is to calculate the minimum number of operations you should perform to obtain the number that has remainder 10^y modulo 10^x. In other words, the obtained number should have remainder 10^y when divided by 10^x. Input The first line of the input contains three integers n, x, y (0 ≀ y < x < n ≀ 2 β‹… 10^5) β€” the length of the number and the integers x and y, respectively. The second line of the input contains one decimal number consisting of n digits, each digit of this number is either 0 or 1. It is guaranteed that the first digit of the number is 1. Output Print one integer β€” the minimum number of operations you should perform to obtain the number having remainder 10^y modulo 10^x. In other words, the obtained number should have remainder 10^y when divided by 10^x. Examples Input 11 5 2 11010100101 Output 1 Input 11 5 1 11010100101 Output 3 Note In the first example the number will be 11010100100 after performing one operation. It has remainder 100 modulo 100000. In the second example the number will be 11010100010 after performing three operations. It has remainder 10 modulo 100000.
instruction
0
77,597
20
155,194
Tags: implementation, math Correct Solution: ``` n,x,y=map(int,input().split()) s=list(input()) s1=s[n-x:] s2=list(str(pow(10,y))) s2.reverse() l=x-y-1 for i in range(l): s2.append('0') s2.reverse() c=0 for i in range(x): if(s1[i]!=s2[i]): c+=1 print(c) ```
output
1
77,597
20
155,195