message
stringlengths
2
59.7k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
37
108k
cluster
float64
20
20
__index_level_0__
int64
74
217k
Provide tags and a correct Python 3 solution for this coding contest problem. Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. Its length equals n (n is always even). Petya calls a ticket lucky if the ticket's number is a lucky number and the sum of digits in the first half (the sum of the first n / 2 digits) equals the sum of digits in the second half (the sum of the last n / 2 digits). Check if the given ticket is lucky. Input The first line contains an even integer n (2 ≀ n ≀ 50) β€” the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly n β€” the ticket number. The number may contain leading zeros. Output On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes). Examples Input 2 47 Output NO Input 4 4738 Output NO Input 4 4774 Output YES Note In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4 β‰  7). In the second sample the ticket number is not the lucky number.
instruction
0
19,658
20
39,316
Tags: implementation Correct Solution: ``` n=int(input()) a=input().strip() if sorted(set(a))!=['4','7'] and sorted(set(a))!=['7'] and sorted(set(a))!=['4']: print("NO") else: x=[int(i) for i in a[:n//2]] y=[int(i) for i in a[n//2:]] if sum(x)==sum(y): print("YES") else: print("NO") ```
output
1
19,658
20
39,317
Provide tags and a correct Python 3 solution for this coding contest problem. Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. Its length equals n (n is always even). Petya calls a ticket lucky if the ticket's number is a lucky number and the sum of digits in the first half (the sum of the first n / 2 digits) equals the sum of digits in the second half (the sum of the last n / 2 digits). Check if the given ticket is lucky. Input The first line contains an even integer n (2 ≀ n ≀ 50) β€” the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly n β€” the ticket number. The number may contain leading zeros. Output On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes). Examples Input 2 47 Output NO Input 4 4738 Output NO Input 4 4774 Output YES Note In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4 β‰  7). In the second sample the ticket number is not the lucky number.
instruction
0
19,659
20
39,318
Tags: implementation Correct Solution: ``` f='yes' n=int(input()) a=input() b='47' for i in range(n): if a[i] not in b: f='no' if f=='no': print('NO') else: m1=0 m2=0 for i in range(n//2): m1+=int(a[i]) for i in range(n//2,n): m2+=int(a[i]) if m1==m2: print('YES') else: print('NO') ```
output
1
19,659
20
39,319
Provide tags and a correct Python 3 solution for this coding contest problem. Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. Its length equals n (n is always even). Petya calls a ticket lucky if the ticket's number is a lucky number and the sum of digits in the first half (the sum of the first n / 2 digits) equals the sum of digits in the second half (the sum of the last n / 2 digits). Check if the given ticket is lucky. Input The first line contains an even integer n (2 ≀ n ≀ 50) β€” the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly n β€” the ticket number. The number may contain leading zeros. Output On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes). Examples Input 2 47 Output NO Input 4 4738 Output NO Input 4 4774 Output YES Note In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4 β‰  7). In the second sample the ticket number is not the lucky number.
instruction
0
19,660
20
39,320
Tags: implementation Correct Solution: ``` n = int(input().strip()) k = input().strip() ll = [] o = True for i in k: if i in ['4','7']: ll.append(int(i)) else: o = False break if o == True: print('YES' if sum(ll[0:n//2]) == sum(ll[n//2:]) else 'NO') else: print('NO') ```
output
1
19,660
20
39,321
Provide tags and a correct Python 3 solution for this coding contest problem. Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. Its length equals n (n is always even). Petya calls a ticket lucky if the ticket's number is a lucky number and the sum of digits in the first half (the sum of the first n / 2 digits) equals the sum of digits in the second half (the sum of the last n / 2 digits). Check if the given ticket is lucky. Input The first line contains an even integer n (2 ≀ n ≀ 50) β€” the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly n β€” the ticket number. The number may contain leading zeros. Output On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes). Examples Input 2 47 Output NO Input 4 4738 Output NO Input 4 4774 Output YES Note In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4 β‰  7). In the second sample the ticket number is not the lucky number.
instruction
0
19,661
20
39,322
Tags: implementation Correct Solution: ``` l = int(input()) n = input() array = list(set([int(x) for x in n])) array.sort() n = [int(x) for x in n] if array == [4, 7] or array == [4] or array == [7]: s1, s2 = 0, 0 for i in range(int(l/2)): s1 += n[i] n.reverse() for i in range(int(l/2)): s2 += n[i] if s1 == s2: print('YES') else: print('NO') else: print('NO') ```
output
1
19,661
20
39,323
Provide tags and a correct Python 3 solution for this coding contest problem. Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. Its length equals n (n is always even). Petya calls a ticket lucky if the ticket's number is a lucky number and the sum of digits in the first half (the sum of the first n / 2 digits) equals the sum of digits in the second half (the sum of the last n / 2 digits). Check if the given ticket is lucky. Input The first line contains an even integer n (2 ≀ n ≀ 50) β€” the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly n β€” the ticket number. The number may contain leading zeros. Output On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes). Examples Input 2 47 Output NO Input 4 4738 Output NO Input 4 4774 Output YES Note In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4 β‰  7). In the second sample the ticket number is not the lucky number.
instruction
0
19,662
20
39,324
Tags: implementation Correct Solution: ``` import sys value = int(input()) array = list(str(input())) firstHalf = 0 secHalf = 0 for i in range(0, int(value/2)): buffer = int(array[i]) if buffer==4 or buffer==7: firstHalf += buffer else: print("NO") sys.exit() for i in range(int(value/2), value): buffer = int(array[i]) if buffer == 4 or buffer == 7: secHalf += buffer else: print("NO") sys.exit() if firstHalf == secHalf: print("YES") else: print("NO") ```
output
1
19,662
20
39,325
Provide tags and a correct Python 3 solution for this coding contest problem. Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. Its length equals n (n is always even). Petya calls a ticket lucky if the ticket's number is a lucky number and the sum of digits in the first half (the sum of the first n / 2 digits) equals the sum of digits in the second half (the sum of the last n / 2 digits). Check if the given ticket is lucky. Input The first line contains an even integer n (2 ≀ n ≀ 50) β€” the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly n β€” the ticket number. The number may contain leading zeros. Output On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes). Examples Input 2 47 Output NO Input 4 4738 Output NO Input 4 4774 Output YES Note In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4 β‰  7). In the second sample the ticket number is not the lucky number.
instruction
0
19,663
20
39,326
Tags: implementation Correct Solution: ``` num=int(input()) a=list(map(int,input())) l4=l7=0 for i in range(num): if a[i]==4: l4+=1 elif a[i]==7: l7+=1 else: break if l4+l7!=num: print("NO") else: h=num//2 s0=sum(a[:h]);s1=sum(a[h:]) if s0!=s1: print("NO") else: print("YES") ```
output
1
19,663
20
39,327
Provide tags and a correct Python 3 solution for this coding contest problem. Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. Its length equals n (n is always even). Petya calls a ticket lucky if the ticket's number is a lucky number and the sum of digits in the first half (the sum of the first n / 2 digits) equals the sum of digits in the second half (the sum of the last n / 2 digits). Check if the given ticket is lucky. Input The first line contains an even integer n (2 ≀ n ≀ 50) β€” the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly n β€” the ticket number. The number may contain leading zeros. Output On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes). Examples Input 2 47 Output NO Input 4 4738 Output NO Input 4 4774 Output YES Note In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4 β‰  7). In the second sample the ticket number is not the lucky number.
instruction
0
19,664
20
39,328
Tags: implementation Correct Solution: ``` n=int(input()) s=input() if s.count("4")+s.count("7")!=n: print("NO") else: if (sum(int(s[i]) for i in range(0,n//2)))==(sum(int(s[j]) for j in range(n//2,n))): print("YES") else:print("NO") ```
output
1
19,664
20
39,329
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. Its length equals n (n is always even). Petya calls a ticket lucky if the ticket's number is a lucky number and the sum of digits in the first half (the sum of the first n / 2 digits) equals the sum of digits in the second half (the sum of the last n / 2 digits). Check if the given ticket is lucky. Input The first line contains an even integer n (2 ≀ n ≀ 50) β€” the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly n β€” the ticket number. The number may contain leading zeros. Output On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes). Examples Input 2 47 Output NO Input 4 4738 Output NO Input 4 4774 Output YES Note In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4 β‰  7). In the second sample the ticket number is not the lucky number. Submitted Solution: ``` n = int(input()) l = list(input()) set_ = set(l) if len(set_) > 2: print('NO') exit() if len(set_) == 1: if '7' in set_ or '4' in set_: print('YES') exit() else: print('NO') exit() else: if '7' in set_ and '4' in set_: li = [int(l[i]) for i in range(n)] if sum(li[:n//2]) == sum(li[n//2:]): print('YES') else: print('NO') else: print('NO') ```
instruction
0
19,665
20
39,330
Yes
output
1
19,665
20
39,331
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. Its length equals n (n is always even). Petya calls a ticket lucky if the ticket's number is a lucky number and the sum of digits in the first half (the sum of the first n / 2 digits) equals the sum of digits in the second half (the sum of the last n / 2 digits). Check if the given ticket is lucky. Input The first line contains an even integer n (2 ≀ n ≀ 50) β€” the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly n β€” the ticket number. The number may contain leading zeros. Output On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes). Examples Input 2 47 Output NO Input 4 4738 Output NO Input 4 4774 Output YES Note In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4 β‰  7). In the second sample the ticket number is not the lucky number. Submitted Solution: ``` a=int(input()) b=str(input()) c=sorted(b) d=len(set(c)) if(d==1 and c[0]=='4'): print("YES") elif(d==1 and c[0]=='7'): print("YES") elif(d==2 and c[0]=='4' and c[len(c)-1]=='7'): q=b.count('4') w=b.count('7') if(q%2==0 and w%2==0): print("YES") else: print("NO") else: print("NO") ```
instruction
0
19,666
20
39,332
Yes
output
1
19,666
20
39,333
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. Its length equals n (n is always even). Petya calls a ticket lucky if the ticket's number is a lucky number and the sum of digits in the first half (the sum of the first n / 2 digits) equals the sum of digits in the second half (the sum of the last n / 2 digits). Check if the given ticket is lucky. Input The first line contains an even integer n (2 ≀ n ≀ 50) β€” the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly n β€” the ticket number. The number may contain leading zeros. Output On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes). Examples Input 2 47 Output NO Input 4 4738 Output NO Input 4 4774 Output YES Note In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4 β‰  7). In the second sample the ticket number is not the lucky number. Submitted Solution: ``` n = int(input()) l = [int(i) for i in input()] print('YES' if l.count(7) + l.count(4) == n and sum(l[:n//2]) == sum(l[n//2:]) else 'NO') ```
instruction
0
19,667
20
39,334
Yes
output
1
19,667
20
39,335
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. Its length equals n (n is always even). Petya calls a ticket lucky if the ticket's number is a lucky number and the sum of digits in the first half (the sum of the first n / 2 digits) equals the sum of digits in the second half (the sum of the last n / 2 digits). Check if the given ticket is lucky. Input The first line contains an even integer n (2 ≀ n ≀ 50) β€” the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly n β€” the ticket number. The number may contain leading zeros. Output On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes). Examples Input 2 47 Output NO Input 4 4738 Output NO Input 4 4774 Output YES Note In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4 β‰  7). In the second sample the ticket number is not the lucky number. Submitted Solution: ``` # import sys # sys.stdin=open("input.in",'r') # sys.stdout=open("ou.out",'w') n=int(input()) s=list(map(int,input())) a=set(s) if a=={4,7} or a=={7} or a=={4}: if sum(s[:n//2])==sum(s[n//2:]): print("YES") else: print("NO") else: print("NO") ```
instruction
0
19,668
20
39,336
Yes
output
1
19,668
20
39,337
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. Its length equals n (n is always even). Petya calls a ticket lucky if the ticket's number is a lucky number and the sum of digits in the first half (the sum of the first n / 2 digits) equals the sum of digits in the second half (the sum of the last n / 2 digits). Check if the given ticket is lucky. Input The first line contains an even integer n (2 ≀ n ≀ 50) β€” the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly n β€” the ticket number. The number may contain leading zeros. Output On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes). Examples Input 2 47 Output NO Input 4 4738 Output NO Input 4 4774 Output YES Note In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4 β‰  7). In the second sample the ticket number is not the lucky number. Submitted Solution: ``` n=int(input()) k=input() li=[] if sorted(set(k))==['4','7']: for i in k: li.append(i) if sum(int(li[i]) for i in range(0, n//2))==sum(int(li[j]) for j in range((n//2), n)): print('YES') else: print('NO') else: print('NO') ```
instruction
0
19,669
20
39,338
No
output
1
19,669
20
39,339
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. Its length equals n (n is always even). Petya calls a ticket lucky if the ticket's number is a lucky number and the sum of digits in the first half (the sum of the first n / 2 digits) equals the sum of digits in the second half (the sum of the last n / 2 digits). Check if the given ticket is lucky. Input The first line contains an even integer n (2 ≀ n ≀ 50) β€” the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly n β€” the ticket number. The number may contain leading zeros. Output On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes). Examples Input 2 47 Output NO Input 4 4738 Output NO Input 4 4774 Output YES Note In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4 β‰  7). In the second sample the ticket number is not the lucky number. Submitted Solution: ``` n=int(input()) b=str(input()) a=n//2 c=b[0:a] d=b[a::] sum1=0 sum2=0 jj=0 for i in range(len(c)): if int(c[i])==4 or int(c[i])==7: sum1+=int(c[i]) else: jj=1 break if int(d[i])==4 or int(c[i])==7: sum2+=int(d[i]) else: jj=1 break if jj==0: if sum1==sum2: print("YES") else: print("NO") else: print("NO") ```
instruction
0
19,670
20
39,340
No
output
1
19,670
20
39,341
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. Its length equals n (n is always even). Petya calls a ticket lucky if the ticket's number is a lucky number and the sum of digits in the first half (the sum of the first n / 2 digits) equals the sum of digits in the second half (the sum of the last n / 2 digits). Check if the given ticket is lucky. Input The first line contains an even integer n (2 ≀ n ≀ 50) β€” the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly n β€” the ticket number. The number may contain leading zeros. Output On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes). Examples Input 2 47 Output NO Input 4 4738 Output NO Input 4 4774 Output YES Note In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4 β‰  7). In the second sample the ticket number is not the lucky number. Submitted Solution: ``` n = int(input()) x = str(input()) lucky=["4","7"] def summ(): x1=x[0:n//2] x2=x[n//2:n] y1=x[0:n//2] y2=x[n//2:n] x1=x1.find("5") y1=y1.find("7") x2=x2.find("7") y2=y2.find("5") if x1==x2==y1==y2: return True else: return False for i in range(0,n) : if x[i] in lucky and summ() : print("lucky") break else: print("NO") ```
instruction
0
19,671
20
39,342
No
output
1
19,671
20
39,343
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. Its length equals n (n is always even). Petya calls a ticket lucky if the ticket's number is a lucky number and the sum of digits in the first half (the sum of the first n / 2 digits) equals the sum of digits in the second half (the sum of the last n / 2 digits). Check if the given ticket is lucky. Input The first line contains an even integer n (2 ≀ n ≀ 50) β€” the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly n β€” the ticket number. The number may contain leading zeros. Output On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes). Examples Input 2 47 Output NO Input 4 4738 Output NO Input 4 4774 Output YES Note In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4 β‰  7). In the second sample the ticket number is not the lucky number. Submitted Solution: ``` # import sys # sys.stdin = open("test.in","r") # sys.stdout = open("test.out.py","w") n=int(input()) a=input() for i in range(n): if a[i]!='4' or a[i]!='7': print('NO') exit() if a[-1]=='7' or a[-1]=='4': b,c=0,0 for i in range(n//2): b+=int(a[i]) for i in range(n//2,n): c+=int(a[i]) if b==c: print('YES') else: print('NO') else: print('NO') ```
instruction
0
19,672
20
39,344
No
output
1
19,672
20
39,345
Provide tags and a correct Python 3 solution for this coding contest problem. In the probability theory the following paradox called Benford's law is known: "In many lists of random numbers taken from real sources, numbers starting with digit 1 occur much more often than numbers starting with any other digit" (that's the simplest form of the law). Having read about it on Codeforces, the Hedgehog got intrigued by the statement and wishes to thoroughly explore it. He finds the following similar problem interesting in particular: there are N random variables, the i-th of which can take any integer value from some segment [Li;Ri] (all numbers from this segment are equiprobable). It means that the value of the i-th quantity can be equal to any integer number from a given interval [Li;Ri] with probability 1 / (Ri - Li + 1). The Hedgehog wants to know the probability of the event that the first digits of at least K% of those values will be equal to one. In other words, let us consider some set of fixed values of these random variables and leave only the first digit (the MSD β€” most significant digit) of each value. Then let's count how many times the digit 1 is encountered and if it is encountered in at least K per cent of those N values, than such set of values will be called a good one. You have to find the probability that a set of values of the given random variables will be a good one. Input The first line contains number N which is the number of random variables (1 ≀ N ≀ 1000). Then follow N lines containing pairs of numbers Li, Ri, each of whom is a description of a random variable. It is guaranteed that 1 ≀ Li ≀ Ri ≀ 1018. The last line contains an integer K (0 ≀ K ≀ 100). All the numbers in the input file are integers. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d). Output Print the required probability. Print the fractional number with such a precision that the relative or absolute error of the result won't exceed 10 - 9. Examples Input 1 1 2 50 Output 0.500000000000000 Input 2 1 2 9 11 50 Output 0.833333333333333
instruction
0
19,828
20
39,656
Tags: dp, math, probabilities Correct Solution: ``` def num_ones(a,b): '''returns how many nums start with digit 1 in [a,b]''' if a==0: if b==0: return 0 ans=0 b=str(b) for i in range(1,len(b)): ans+=10**(i-1) if b[0]=='1': x=b[1:] if x=='': x=0 else: x=int(x) ans+=x+1 else: ans+=10**(len(b)-1) return ans return num_ones(0,b)-num_ones(0,a-1) def dp(far,need): '''returns prob that the first far vars have at least need 1s''' if DP[far][need]!=-1: return DP[far][need] if need>(far+1): return 0 if need==0: return 1 if far==0: return L[0] ans=L[far]*dp(far-1,need-1)+(1-L[far])*dp(far-1,need) DP[far][need]=ans return ans n=int(input()) L=[] for i in range(n): s=list(map(int,input().split())) L.append(num_ones(s[0],s[1])/(s[1]-s[0]+1)) k=int(input()) atLeast=int((n*k-1)/100)+1 if k==0: atLeast=0 DP=[] for i in range(n): DP.append([-1]*(atLeast+5)) print(round(dp(n-1,atLeast),10)) ```
output
1
19,828
20
39,657
Provide tags and a correct Python 3 solution for this coding contest problem. In the probability theory the following paradox called Benford's law is known: "In many lists of random numbers taken from real sources, numbers starting with digit 1 occur much more often than numbers starting with any other digit" (that's the simplest form of the law). Having read about it on Codeforces, the Hedgehog got intrigued by the statement and wishes to thoroughly explore it. He finds the following similar problem interesting in particular: there are N random variables, the i-th of which can take any integer value from some segment [Li;Ri] (all numbers from this segment are equiprobable). It means that the value of the i-th quantity can be equal to any integer number from a given interval [Li;Ri] with probability 1 / (Ri - Li + 1). The Hedgehog wants to know the probability of the event that the first digits of at least K% of those values will be equal to one. In other words, let us consider some set of fixed values of these random variables and leave only the first digit (the MSD β€” most significant digit) of each value. Then let's count how many times the digit 1 is encountered and if it is encountered in at least K per cent of those N values, than such set of values will be called a good one. You have to find the probability that a set of values of the given random variables will be a good one. Input The first line contains number N which is the number of random variables (1 ≀ N ≀ 1000). Then follow N lines containing pairs of numbers Li, Ri, each of whom is a description of a random variable. It is guaranteed that 1 ≀ Li ≀ Ri ≀ 1018. The last line contains an integer K (0 ≀ K ≀ 100). All the numbers in the input file are integers. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d). Output Print the required probability. Print the fractional number with such a precision that the relative or absolute error of the result won't exceed 10 - 9. Examples Input 1 1 2 50 Output 0.500000000000000 Input 2 1 2 9 11 50 Output 0.833333333333333
instruction
0
19,829
20
39,658
Tags: dp, math, probabilities Correct Solution: ``` import sys input=lambda:sys.stdin.readline().strip() print=lambda s:sys.stdout.write(str(s)+"\n") nn=int(input()) dp=[1] + [0]*(nn+1) for _ in range(nn): l, r = map(int, input().split()) c = 1 n = 0 for _ in range(19): n += max(0, min(r, 2 * c - 1) - max(l, c) + 1) c *= 10 p=n/(r-l+1) dp=[dp[0]*(1-p)]+[dp[j]*(1-p)+dp[j-1]*p for j in range(1,nn+1)] from math import * print (sum(dp[int(ceil(nn*int(input())/100)):])) ```
output
1
19,829
20
39,659
Provide tags and a correct Python 3 solution for this coding contest problem. In the probability theory the following paradox called Benford's law is known: "In many lists of random numbers taken from real sources, numbers starting with digit 1 occur much more often than numbers starting with any other digit" (that's the simplest form of the law). Having read about it on Codeforces, the Hedgehog got intrigued by the statement and wishes to thoroughly explore it. He finds the following similar problem interesting in particular: there are N random variables, the i-th of which can take any integer value from some segment [Li;Ri] (all numbers from this segment are equiprobable). It means that the value of the i-th quantity can be equal to any integer number from a given interval [Li;Ri] with probability 1 / (Ri - Li + 1). The Hedgehog wants to know the probability of the event that the first digits of at least K% of those values will be equal to one. In other words, let us consider some set of fixed values of these random variables and leave only the first digit (the MSD β€” most significant digit) of each value. Then let's count how many times the digit 1 is encountered and if it is encountered in at least K per cent of those N values, than such set of values will be called a good one. You have to find the probability that a set of values of the given random variables will be a good one. Input The first line contains number N which is the number of random variables (1 ≀ N ≀ 1000). Then follow N lines containing pairs of numbers Li, Ri, each of whom is a description of a random variable. It is guaranteed that 1 ≀ Li ≀ Ri ≀ 1018. The last line contains an integer K (0 ≀ K ≀ 100). All the numbers in the input file are integers. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d). Output Print the required probability. Print the fractional number with such a precision that the relative or absolute error of the result won't exceed 10 - 9. Examples Input 1 1 2 50 Output 0.500000000000000 Input 2 1 2 9 11 50 Output 0.833333333333333
instruction
0
19,830
20
39,660
Tags: dp, math, probabilities Correct Solution: ``` # in = open("input.txt", "r") # out = open("output.txt", "w") # long double p[maxn]; # long double dp[maxn][maxn]; # # int solution() { # # int n, k; # scanf("%d", &n); # for(int i = 0; i < n; i++) { # ll l, r; # scanf("%lld%lld", &l, &r); # r++; # ll cnt = 0, all = r - l; # for(ll i = 1, j = 1; j <= 18; j++, i *= 10) { # ll u = i * 2, d = i; # cnt += (u > r ? r : (u < l ? l : u)) - (d > r ? r : (d < l ? l : d)); # } # p[i] = ((long double)1.) * cnt / all; # } # scanf("%d", &k); # k = (n * k + 99) / 100; # # dp[0][0] = ((long double)1.); # for(int i = 0; i < n; i++) { # for(int j = 0; j < n; j++) { # dp[i + 1][j + 1] += dp[i][j] * p[i]; # dp[i + 1][j] += dp[i][j] * (((long double)1.) - p[i]); # } # } # # long double ans = 0.; # for(int j = k; j <= n; j++) { # ans += dp[n][j]; # } # printf("%.15lf", (double)ans); from decimal import * p = [0 for i in range(1010)] dp = [[0 for i in range(1010)] for i in range(1010)] n = int(input()) for i in range(n): l, r = map(int, input().split()) r += 1 cnt, all = 0, r - l ii = 1 for j in range(19): u, d = ii * 2, ii cnt += (r if u > r else (l if u < l else u)) - (r if d > r else (l if d < l else d)) ii *= 10 p[i] = (cnt) / (all) k = int(input()) k = (n * k + 99) // 100 dp[0][0] = (1) for i in range(n): for j in range(n): dp[i][j] = (dp[i][j]) dp[i + 1][j] = (dp[i + 1][j]) dp[i + 1][j + 1] = (dp[i + 1][j + 1]) dp[i + 1][j + 1] += dp[i][j] * p[i] dp[i + 1][j] += dp[i][j] * ((1) - p[i]) ans = (0) for j in range(k, n + 1): ans += dp[n][j] print(ans); import time, sys sys.stderr.write('{0:.3f} ms\n'.format(time.clock() * 1000)) ```
output
1
19,830
20
39,661
Provide tags and a correct Python 3 solution for this coding contest problem. In the probability theory the following paradox called Benford's law is known: "In many lists of random numbers taken from real sources, numbers starting with digit 1 occur much more often than numbers starting with any other digit" (that's the simplest form of the law). Having read about it on Codeforces, the Hedgehog got intrigued by the statement and wishes to thoroughly explore it. He finds the following similar problem interesting in particular: there are N random variables, the i-th of which can take any integer value from some segment [Li;Ri] (all numbers from this segment are equiprobable). It means that the value of the i-th quantity can be equal to any integer number from a given interval [Li;Ri] with probability 1 / (Ri - Li + 1). The Hedgehog wants to know the probability of the event that the first digits of at least K% of those values will be equal to one. In other words, let us consider some set of fixed values of these random variables and leave only the first digit (the MSD β€” most significant digit) of each value. Then let's count how many times the digit 1 is encountered and if it is encountered in at least K per cent of those N values, than such set of values will be called a good one. You have to find the probability that a set of values of the given random variables will be a good one. Input The first line contains number N which is the number of random variables (1 ≀ N ≀ 1000). Then follow N lines containing pairs of numbers Li, Ri, each of whom is a description of a random variable. It is guaranteed that 1 ≀ Li ≀ Ri ≀ 1018. The last line contains an integer K (0 ≀ K ≀ 100). All the numbers in the input file are integers. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d). Output Print the required probability. Print the fractional number with such a precision that the relative or absolute error of the result won't exceed 10 - 9. Examples Input 1 1 2 50 Output 0.500000000000000 Input 2 1 2 9 11 50 Output 0.833333333333333
instruction
0
19,831
20
39,662
Tags: dp, math, probabilities Correct Solution: ``` def num_ones(a,b): '''returns how many nums start with digit 1 in [a,b]''' if a==0: if b==0: return 0 ans=0 b=str(b) for i in range(1,len(b)): ans+=10**(i-1) if b[0]=='1': x=b[1:] if x=='': x=0 else: x=int(x) ans+=(x+1) else: ans+=10**(len(b)-1) return ans return num_ones(0,b)-num_ones(0,a-1) def dp(far,need): '''returns prob that the first far vars have at least need 1s''' if DP[far][need]!=-1: return DP[far][need] if need>(far+1): return 0 if need==0: return 1 if far==0: return L[0] ans=L[far]*dp(far-1,need-1)+(1-L[far])*dp(far-1,need) DP[far][need]=ans return ans n=int(input()) L=[] for i in range(n): s=list(map(int,input().split())) L.append(num_ones(s[0],s[1])/(s[1]-s[0]+1)) k=int(input()) atLeast=int((n*k-1)/100)+1 if k==0: atLeast=0 DP=[] for i in range(n): DP.append([-1]*(atLeast+5)) print(round(dp(n-1,atLeast),10)) ```
output
1
19,831
20
39,663
Provide tags and a correct Python 3 solution for this coding contest problem. In the probability theory the following paradox called Benford's law is known: "In many lists of random numbers taken from real sources, numbers starting with digit 1 occur much more often than numbers starting with any other digit" (that's the simplest form of the law). Having read about it on Codeforces, the Hedgehog got intrigued by the statement and wishes to thoroughly explore it. He finds the following similar problem interesting in particular: there are N random variables, the i-th of which can take any integer value from some segment [Li;Ri] (all numbers from this segment are equiprobable). It means that the value of the i-th quantity can be equal to any integer number from a given interval [Li;Ri] with probability 1 / (Ri - Li + 1). The Hedgehog wants to know the probability of the event that the first digits of at least K% of those values will be equal to one. In other words, let us consider some set of fixed values of these random variables and leave only the first digit (the MSD β€” most significant digit) of each value. Then let's count how many times the digit 1 is encountered and if it is encountered in at least K per cent of those N values, than such set of values will be called a good one. You have to find the probability that a set of values of the given random variables will be a good one. Input The first line contains number N which is the number of random variables (1 ≀ N ≀ 1000). Then follow N lines containing pairs of numbers Li, Ri, each of whom is a description of a random variable. It is guaranteed that 1 ≀ Li ≀ Ri ≀ 1018. The last line contains an integer K (0 ≀ K ≀ 100). All the numbers in the input file are integers. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d). Output Print the required probability. Print the fractional number with such a precision that the relative or absolute error of the result won't exceed 10 - 9. Examples Input 1 1 2 50 Output 0.500000000000000 Input 2 1 2 9 11 50 Output 0.833333333333333
instruction
0
19,832
20
39,664
Tags: dp, math, probabilities Correct Solution: ``` import math def get_count(x): if x == 0: return 0 y = 10 ** (len(str(x)) - 1) d = x // y if d == 1: count = x - y + 1 else: count = y #print(x, math.log10(x), int(math.log10(x)), y, d, count) while y > 1: y //= 10 count += y #print('get_count(%d) -> %d' % (x, count)) return count n = int(input()) total = [ 1.0 ] for i in range(n): low, high = map(int, input().split()) count = get_count(high) - get_count(low - 1) p = count / (high - low + 1) new_total = [ 0.0 for i in range(len(total) + 1) ] for i, q in enumerate(total): new_total[i] += (1 - p) * q new_total[i + 1] += p * q total = new_total k = int(input()) result = 1.0 for i in range(math.ceil(n * k / 100)): result -= total[i] #print(total) print(result) ```
output
1
19,832
20
39,665
Provide tags and a correct Python 3 solution for this coding contest problem. In the probability theory the following paradox called Benford's law is known: "In many lists of random numbers taken from real sources, numbers starting with digit 1 occur much more often than numbers starting with any other digit" (that's the simplest form of the law). Having read about it on Codeforces, the Hedgehog got intrigued by the statement and wishes to thoroughly explore it. He finds the following similar problem interesting in particular: there are N random variables, the i-th of which can take any integer value from some segment [Li;Ri] (all numbers from this segment are equiprobable). It means that the value of the i-th quantity can be equal to any integer number from a given interval [Li;Ri] with probability 1 / (Ri - Li + 1). The Hedgehog wants to know the probability of the event that the first digits of at least K% of those values will be equal to one. In other words, let us consider some set of fixed values of these random variables and leave only the first digit (the MSD β€” most significant digit) of each value. Then let's count how many times the digit 1 is encountered and if it is encountered in at least K per cent of those N values, than such set of values will be called a good one. You have to find the probability that a set of values of the given random variables will be a good one. Input The first line contains number N which is the number of random variables (1 ≀ N ≀ 1000). Then follow N lines containing pairs of numbers Li, Ri, each of whom is a description of a random variable. It is guaranteed that 1 ≀ Li ≀ Ri ≀ 1018. The last line contains an integer K (0 ≀ K ≀ 100). All the numbers in the input file are integers. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d). Output Print the required probability. Print the fractional number with such a precision that the relative or absolute error of the result won't exceed 10 - 9. Examples Input 1 1 2 50 Output 0.500000000000000 Input 2 1 2 9 11 50 Output 0.833333333333333
instruction
0
19,833
20
39,666
Tags: dp, math, probabilities Correct Solution: ``` from sys import stdin tps = [1] for i in range(20): tps.append(tps[-1]*10) def findprob(l, r): sl = str(l) sr = str(r) ans = 0 if (sl[0] == '1' and sr[0] == '1' and len(sl) == len(sr)): if l == r == 1: ans += 1 else: ans += int(sr[1:]) - int(sl[1:]) + 1 else: if (sl[0] == '1'): if l == 1: ans += 1 else: ans += tps[len(sl)-1] - int(sl[1:]) if (sr[0] == '1'): if r == 1: ans += 1 else: ans += int(sr[1:]) + 1 mx = len(sr) - int(sr[0] == '1') for i in range(len(sl), mx): ans += tps[i] return ans/(r-l+1) n = int(stdin.readline()) p = [0 for i in range(n)] for i in range(n): l, r = map(int, stdin.readline().split()) p[i] = findprob(l, r) np = [1-p[i] for i in range(n)] for i in range(n-2, -1, -1): np[i] *= np[i+1] np.append(1) k = int(stdin.readline()) w = (n*k)//100 + int(bool((n*k)%100)) dp = [list([0 for i in range(n)]) for j in range(n)] probsms = [0 for i in range(n)] curp = 1 for i in range(n): dp[i][0] = p[i]*curp curp *= (1-p[i]) probsms[0] += dp[i][0]*np[i+1] for j in range(1, n): curs = dp[j-1][j-1] for i in range(j, n): dp[i][j] = (curs*p[i]) probsms[j] += dp[i][j]*np[i+1] curs *= (1-p[i]) curs += dp[i][j-1] if w == 0: print(1) else: print(sum(probsms[w-1:])) ```
output
1
19,833
20
39,667
Provide tags and a correct Python 3 solution for this coding contest problem. In the probability theory the following paradox called Benford's law is known: "In many lists of random numbers taken from real sources, numbers starting with digit 1 occur much more often than numbers starting with any other digit" (that's the simplest form of the law). Having read about it on Codeforces, the Hedgehog got intrigued by the statement and wishes to thoroughly explore it. He finds the following similar problem interesting in particular: there are N random variables, the i-th of which can take any integer value from some segment [Li;Ri] (all numbers from this segment are equiprobable). It means that the value of the i-th quantity can be equal to any integer number from a given interval [Li;Ri] with probability 1 / (Ri - Li + 1). The Hedgehog wants to know the probability of the event that the first digits of at least K% of those values will be equal to one. In other words, let us consider some set of fixed values of these random variables and leave only the first digit (the MSD β€” most significant digit) of each value. Then let's count how many times the digit 1 is encountered and if it is encountered in at least K per cent of those N values, than such set of values will be called a good one. You have to find the probability that a set of values of the given random variables will be a good one. Input The first line contains number N which is the number of random variables (1 ≀ N ≀ 1000). Then follow N lines containing pairs of numbers Li, Ri, each of whom is a description of a random variable. It is guaranteed that 1 ≀ Li ≀ Ri ≀ 1018. The last line contains an integer K (0 ≀ K ≀ 100). All the numbers in the input file are integers. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d). Output Print the required probability. Print the fractional number with such a precision that the relative or absolute error of the result won't exceed 10 - 9. Examples Input 1 1 2 50 Output 0.500000000000000 Input 2 1 2 9 11 50 Output 0.833333333333333
instruction
0
19,834
20
39,668
Tags: dp, math, probabilities Correct Solution: ``` def f(n): s=str(n) l=len(s) tot=0 tot+=(10**(l-1)-1)//9 tot+=min(n-10**(l-1)+1,10**(l-1)) return tot n=int(input()) dp=[[0 for i in range(n+1)]for j in range(n+1)] dp[0][0]=1 for i in range(1,n+1): l,r=map(int,input().split()) tot=f(r)-f(l-1) tot1=r-l+1 j=i while(j>=0): if j>=1: dp[i][j]+=(tot/tot1)*dp[i-1][j-1] dp[i][j]+=(1-(tot/tot1))*dp[i-1][j] j+=-1 k=float(input()) k=k/100 ans=0 for j in range(n+1): if (j/n)>=k: ans+=dp[n][j] print(ans) ```
output
1
19,834
20
39,669
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In the probability theory the following paradox called Benford's law is known: "In many lists of random numbers taken from real sources, numbers starting with digit 1 occur much more often than numbers starting with any other digit" (that's the simplest form of the law). Having read about it on Codeforces, the Hedgehog got intrigued by the statement and wishes to thoroughly explore it. He finds the following similar problem interesting in particular: there are N random variables, the i-th of which can take any integer value from some segment [Li;Ri] (all numbers from this segment are equiprobable). It means that the value of the i-th quantity can be equal to any integer number from a given interval [Li;Ri] with probability 1 / (Ri - Li + 1). The Hedgehog wants to know the probability of the event that the first digits of at least K% of those values will be equal to one. In other words, let us consider some set of fixed values of these random variables and leave only the first digit (the MSD β€” most significant digit) of each value. Then let's count how many times the digit 1 is encountered and if it is encountered in at least K per cent of those N values, than such set of values will be called a good one. You have to find the probability that a set of values of the given random variables will be a good one. Input The first line contains number N which is the number of random variables (1 ≀ N ≀ 1000). Then follow N lines containing pairs of numbers Li, Ri, each of whom is a description of a random variable. It is guaranteed that 1 ≀ Li ≀ Ri ≀ 1018. The last line contains an integer K (0 ≀ K ≀ 100). All the numbers in the input file are integers. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d). Output Print the required probability. Print the fractional number with such a precision that the relative or absolute error of the result won't exceed 10 - 9. Examples Input 1 1 2 50 Output 0.500000000000000 Input 2 1 2 9 11 50 Output 0.833333333333333 Submitted Solution: ``` def num_ones(a,b): '''returns how many nums start with digit 1 in [a,b]''' if a==0: if b==0: return 0 ans=0 b=str(b) for i in range(1,len(b)): ans+=10**(i-1) if b[0]=='1': x=b[1:] if x=='': x=0 else: x=int(x) ans+=x+1 else: ans+=10**(len(b)-1) return ans return num_ones(0,b)-num_ones(0,a-1) def dp(far,need): '''returns prob that the first far vars have at least need 1s''' if DP[far][need]!=-1: return DP[far][need] if need>(far+1): return 0 if need==0: return 1 if far==0: return L[0] ans=L[far]*dp(far-1,need-1)+(1-L[far])*dp(far-1,need) DP[far][need]=ans return ans n=int(input()) L=[] for i in range(n): s=list(map(int,input().split())) L.append(num_ones(s[0],s[1])/(s[1]-s[0]+1)) k=int(input()) atLeast=int((n*k-1)/100)+1 DP=[] for i in range(n): DP.append([-1]*(atLeast+5)) print(round(dp(n-1,atLeast),10)) ```
instruction
0
19,835
20
39,670
No
output
1
19,835
20
39,671
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In the probability theory the following paradox called Benford's law is known: "In many lists of random numbers taken from real sources, numbers starting with digit 1 occur much more often than numbers starting with any other digit" (that's the simplest form of the law). Having read about it on Codeforces, the Hedgehog got intrigued by the statement and wishes to thoroughly explore it. He finds the following similar problem interesting in particular: there are N random variables, the i-th of which can take any integer value from some segment [Li;Ri] (all numbers from this segment are equiprobable). It means that the value of the i-th quantity can be equal to any integer number from a given interval [Li;Ri] with probability 1 / (Ri - Li + 1). The Hedgehog wants to know the probability of the event that the first digits of at least K% of those values will be equal to one. In other words, let us consider some set of fixed values of these random variables and leave only the first digit (the MSD β€” most significant digit) of each value. Then let's count how many times the digit 1 is encountered and if it is encountered in at least K per cent of those N values, than such set of values will be called a good one. You have to find the probability that a set of values of the given random variables will be a good one. Input The first line contains number N which is the number of random variables (1 ≀ N ≀ 1000). Then follow N lines containing pairs of numbers Li, Ri, each of whom is a description of a random variable. It is guaranteed that 1 ≀ Li ≀ Ri ≀ 1018. The last line contains an integer K (0 ≀ K ≀ 100). All the numbers in the input file are integers. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d). Output Print the required probability. Print the fractional number with such a precision that the relative or absolute error of the result won't exceed 10 - 9. Examples Input 1 1 2 50 Output 0.500000000000000 Input 2 1 2 9 11 50 Output 0.833333333333333 Submitted Solution: ``` import math def get_count(x): if x == 0: return 0 y = 10 ** int(math.log10(x)) d = x // y if d == 1: count = x - y + 1 else: count = y while y > 1: y //= 10 count += y #print('get_count(%d) -> %d' % (x, count)) return count n = int(input()) total = [ 1.0 ] for i in range(n): low, high = map(int, input().split()) count = get_count(high) - get_count(low - 1) p = count / (high - low + 1) new_total = [ 0.0 for i in range(len(total) + 1) ] for i, q in enumerate(total): new_total[i] += (1 - p) * q new_total[i + 1] += p * q total = new_total k = int(input()) result = 1.0 for i in range(math.ceil(n * k / 100)): result -= total[i] #print(total) print(result) ```
instruction
0
19,836
20
39,672
No
output
1
19,836
20
39,673
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In the probability theory the following paradox called Benford's law is known: "In many lists of random numbers taken from real sources, numbers starting with digit 1 occur much more often than numbers starting with any other digit" (that's the simplest form of the law). Having read about it on Codeforces, the Hedgehog got intrigued by the statement and wishes to thoroughly explore it. He finds the following similar problem interesting in particular: there are N random variables, the i-th of which can take any integer value from some segment [Li;Ri] (all numbers from this segment are equiprobable). It means that the value of the i-th quantity can be equal to any integer number from a given interval [Li;Ri] with probability 1 / (Ri - Li + 1). The Hedgehog wants to know the probability of the event that the first digits of at least K% of those values will be equal to one. In other words, let us consider some set of fixed values of these random variables and leave only the first digit (the MSD β€” most significant digit) of each value. Then let's count how many times the digit 1 is encountered and if it is encountered in at least K per cent of those N values, than such set of values will be called a good one. You have to find the probability that a set of values of the given random variables will be a good one. Input The first line contains number N which is the number of random variables (1 ≀ N ≀ 1000). Then follow N lines containing pairs of numbers Li, Ri, each of whom is a description of a random variable. It is guaranteed that 1 ≀ Li ≀ Ri ≀ 1018. The last line contains an integer K (0 ≀ K ≀ 100). All the numbers in the input file are integers. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d). Output Print the required probability. Print the fractional number with such a precision that the relative or absolute error of the result won't exceed 10 - 9. Examples Input 1 1 2 50 Output 0.500000000000000 Input 2 1 2 9 11 50 Output 0.833333333333333 Submitted Solution: ``` import sys input=lambda:sys.stdin.readline().strip() print=lambda s:sys.stdout.write(str(s)+"\n") nn=int(input()) dp=[1] + [0]*(nn+1) for _ in range(nn): l, r = map(int, input().split()) c = 1 n = 0 for _ in range(10): n += max(0, min(r, 2 * c - 1) - max(l, c) + 1) # [1000, 1999] c *= 10 p=n/(r-l+1)#probability #blessrng no floating point error? dp=[dp[0]*(1-p)]+[dp[j]*(1-p)+dp[j-1]*p for j in range(1,nn+1)] # print(dp) #YOU WANT AT LEAST K #AT LEAST K PERCENT # >=N*K/100 # print(dp) from math import * print (sum(dp[int(ceil(nn*int(input())/100)):])) ```
instruction
0
19,837
20
39,674
No
output
1
19,837
20
39,675
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In the probability theory the following paradox called Benford's law is known: "In many lists of random numbers taken from real sources, numbers starting with digit 1 occur much more often than numbers starting with any other digit" (that's the simplest form of the law). Having read about it on Codeforces, the Hedgehog got intrigued by the statement and wishes to thoroughly explore it. He finds the following similar problem interesting in particular: there are N random variables, the i-th of which can take any integer value from some segment [Li;Ri] (all numbers from this segment are equiprobable). It means that the value of the i-th quantity can be equal to any integer number from a given interval [Li;Ri] with probability 1 / (Ri - Li + 1). The Hedgehog wants to know the probability of the event that the first digits of at least K% of those values will be equal to one. In other words, let us consider some set of fixed values of these random variables and leave only the first digit (the MSD β€” most significant digit) of each value. Then let's count how many times the digit 1 is encountered and if it is encountered in at least K per cent of those N values, than such set of values will be called a good one. You have to find the probability that a set of values of the given random variables will be a good one. Input The first line contains number N which is the number of random variables (1 ≀ N ≀ 1000). Then follow N lines containing pairs of numbers Li, Ri, each of whom is a description of a random variable. It is guaranteed that 1 ≀ Li ≀ Ri ≀ 1018. The last line contains an integer K (0 ≀ K ≀ 100). All the numbers in the input file are integers. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d). Output Print the required probability. Print the fractional number with such a precision that the relative or absolute error of the result won't exceed 10 - 9. Examples Input 1 1 2 50 Output 0.500000000000000 Input 2 1 2 9 11 50 Output 0.833333333333333 Submitted Solution: ``` import sys from decimal import * getcontext().prec=200 input=lambda:sys.stdin.readline().strip() print=lambda s:sys.stdout.write(str(s)+"\n") nn=int(input()) dp=[1] + [0]*(nn+1) for _ in range(nn): l, r = map(int, input().split()) c = 1 n = 0 for _ in range(10): n += max(0, min(r, 2 * c - 1) - max(l, c) + 1) # [1000, 1999] c *= 10 p=Decimal(n)/Decimal(r-l+1)#probability #blessrng no floating point error? dp=[dp[0]*(1-p)]+[dp[j]*(1-p)+dp[j-1]*p for j in range(1,nn+1)] # print(dp) #YOU WANT AT LEAST K #AT LEAST K PERCENT # >=N*K/100 # print(dp) from math import * print (sum(dp[int(ceil(nn*int(input())/100)):])) ```
instruction
0
19,838
20
39,676
No
output
1
19,838
20
39,677
Provide tags and a correct Python 3 solution for this coding contest problem. While Patrick was gone shopping, Spongebob decided to play a little trick on his friend. The naughty Sponge browsed through Patrick's personal stuff and found a sequence a1, a2, ..., am of length m, consisting of integers from 1 to n, not necessarily distinct. Then he picked some sequence f1, f2, ..., fn of length n and for each number ai got number bi = fai. To finish the prank he erased the initial sequence ai. It's hard to express how sad Patrick was when he returned home from shopping! We will just say that Spongebob immediately got really sorry about what he has done and he is now trying to restore the original sequence. Help him do this or determine that this is impossible. Input The first line of the input contains two integers n and m (1 ≀ n, m ≀ 100 000) β€” the lengths of sequences fi and bi respectively. The second line contains n integers, determining sequence f1, f2, ..., fn (1 ≀ fi ≀ n). The last line contains m integers, determining sequence b1, b2, ..., bm (1 ≀ bi ≀ n). Output Print "Possible" if there is exactly one sequence ai, such that bi = fai for all i from 1 to m. Then print m integers a1, a2, ..., am. If there are multiple suitable sequences ai, print "Ambiguity". If Spongebob has made a mistake in his calculations and no suitable sequence ai exists, print "Impossible". Examples Input 3 3 3 2 1 1 2 3 Output Possible 3 2 1 Input 3 3 1 1 1 1 1 1 Output Ambiguity Input 3 3 1 2 1 3 3 3 Output Impossible Note In the first sample 3 is replaced by 1 and vice versa, while 2 never changes. The answer exists and is unique. In the second sample all numbers are replaced by 1, so it is impossible to unambiguously restore the original sequence. In the third sample fi β‰  3 for all i, so no sequence ai transforms into such bi and we can say for sure that Spongebob has made a mistake.
instruction
0
19,839
20
39,678
Tags: implementation Correct Solution: ``` import sys n,m = map(int , input().split()) f = list(map(int , input().split())) b = list(map(int , input().split())) cnt = [0 for i in range(n+1)] indx = [ -1 for i in range(n+1)] for i in range(n): cnt[f[i]] += 1 indx[f[i]] = i + 1 ans = [] for num in b: if cnt[num] == 0 : print("Impossible") sys.exit() for num in b: if cnt[num] >= 2: print("Ambiguity") sys.exit() ans.append(indx[num]) print("Possible") for num in ans: print(num, end = ' ') ```
output
1
19,839
20
39,679
Provide tags and a correct Python 3 solution for this coding contest problem. While Patrick was gone shopping, Spongebob decided to play a little trick on his friend. The naughty Sponge browsed through Patrick's personal stuff and found a sequence a1, a2, ..., am of length m, consisting of integers from 1 to n, not necessarily distinct. Then he picked some sequence f1, f2, ..., fn of length n and for each number ai got number bi = fai. To finish the prank he erased the initial sequence ai. It's hard to express how sad Patrick was when he returned home from shopping! We will just say that Spongebob immediately got really sorry about what he has done and he is now trying to restore the original sequence. Help him do this or determine that this is impossible. Input The first line of the input contains two integers n and m (1 ≀ n, m ≀ 100 000) β€” the lengths of sequences fi and bi respectively. The second line contains n integers, determining sequence f1, f2, ..., fn (1 ≀ fi ≀ n). The last line contains m integers, determining sequence b1, b2, ..., bm (1 ≀ bi ≀ n). Output Print "Possible" if there is exactly one sequence ai, such that bi = fai for all i from 1 to m. Then print m integers a1, a2, ..., am. If there are multiple suitable sequences ai, print "Ambiguity". If Spongebob has made a mistake in his calculations and no suitable sequence ai exists, print "Impossible". Examples Input 3 3 3 2 1 1 2 3 Output Possible 3 2 1 Input 3 3 1 1 1 1 1 1 Output Ambiguity Input 3 3 1 2 1 3 3 3 Output Impossible Note In the first sample 3 is replaced by 1 and vice versa, while 2 never changes. The answer exists and is unique. In the second sample all numbers are replaced by 1, so it is impossible to unambiguously restore the original sequence. In the third sample fi β‰  3 for all i, so no sequence ai transforms into such bi and we can say for sure that Spongebob has made a mistake.
instruction
0
19,840
20
39,680
Tags: implementation Correct Solution: ``` import sys def main(): n, m = map(int, input().split()) f = list(map(int, sys.stdin.readline().split())) b = list(map(int, sys.stdin.readline().split())) f = [0]+f b = [0]+b imf = set() d = set() g = [0]*(n+1) for i in range(1,n+1): if f[i] in imf: d.add(f[i]) else: imf.add(f[i]) g[f[i]] = i for i in range(1,m+1): if b[i] not in imf: print("Impossible") return for i in range(1,m+1): if b[i] in d: print("Ambiguity") return print("Possible") for i in range(1,m): print(g[b[i]], end=" ") print(g[b[m]]) main() ```
output
1
19,840
20
39,681
Provide tags and a correct Python 3 solution for this coding contest problem. While Patrick was gone shopping, Spongebob decided to play a little trick on his friend. The naughty Sponge browsed through Patrick's personal stuff and found a sequence a1, a2, ..., am of length m, consisting of integers from 1 to n, not necessarily distinct. Then he picked some sequence f1, f2, ..., fn of length n and for each number ai got number bi = fai. To finish the prank he erased the initial sequence ai. It's hard to express how sad Patrick was when he returned home from shopping! We will just say that Spongebob immediately got really sorry about what he has done and he is now trying to restore the original sequence. Help him do this or determine that this is impossible. Input The first line of the input contains two integers n and m (1 ≀ n, m ≀ 100 000) β€” the lengths of sequences fi and bi respectively. The second line contains n integers, determining sequence f1, f2, ..., fn (1 ≀ fi ≀ n). The last line contains m integers, determining sequence b1, b2, ..., bm (1 ≀ bi ≀ n). Output Print "Possible" if there is exactly one sequence ai, such that bi = fai for all i from 1 to m. Then print m integers a1, a2, ..., am. If there are multiple suitable sequences ai, print "Ambiguity". If Spongebob has made a mistake in his calculations and no suitable sequence ai exists, print "Impossible". Examples Input 3 3 3 2 1 1 2 3 Output Possible 3 2 1 Input 3 3 1 1 1 1 1 1 Output Ambiguity Input 3 3 1 2 1 3 3 3 Output Impossible Note In the first sample 3 is replaced by 1 and vice versa, while 2 never changes. The answer exists and is unique. In the second sample all numbers are replaced by 1, so it is impossible to unambiguously restore the original sequence. In the third sample fi β‰  3 for all i, so no sequence ai transforms into such bi and we can say for sure that Spongebob has made a mistake.
instruction
0
19,841
20
39,682
Tags: implementation Correct Solution: ``` n,m=map(int,input().split()) f=list(map(int,input().split())) b=list(map(int,input().split())) a=[-1]*100050 for i in range(n): if a[f[i]]==-1:a[f[i]]=i else :a[f[i]]=-2 for i in b: if a[i]==-1:exit(print('Impossible')) for i in b: if a[i]==-2:exit(print('Ambiguity')) print('Possible') for i in b:print(a[i]+1,end=' ') # Made By Mostafa_Khaled ```
output
1
19,841
20
39,683
Provide tags and a correct Python 3 solution for this coding contest problem. While Patrick was gone shopping, Spongebob decided to play a little trick on his friend. The naughty Sponge browsed through Patrick's personal stuff and found a sequence a1, a2, ..., am of length m, consisting of integers from 1 to n, not necessarily distinct. Then he picked some sequence f1, f2, ..., fn of length n and for each number ai got number bi = fai. To finish the prank he erased the initial sequence ai. It's hard to express how sad Patrick was when he returned home from shopping! We will just say that Spongebob immediately got really sorry about what he has done and he is now trying to restore the original sequence. Help him do this or determine that this is impossible. Input The first line of the input contains two integers n and m (1 ≀ n, m ≀ 100 000) β€” the lengths of sequences fi and bi respectively. The second line contains n integers, determining sequence f1, f2, ..., fn (1 ≀ fi ≀ n). The last line contains m integers, determining sequence b1, b2, ..., bm (1 ≀ bi ≀ n). Output Print "Possible" if there is exactly one sequence ai, such that bi = fai for all i from 1 to m. Then print m integers a1, a2, ..., am. If there are multiple suitable sequences ai, print "Ambiguity". If Spongebob has made a mistake in his calculations and no suitable sequence ai exists, print "Impossible". Examples Input 3 3 3 2 1 1 2 3 Output Possible 3 2 1 Input 3 3 1 1 1 1 1 1 Output Ambiguity Input 3 3 1 2 1 3 3 3 Output Impossible Note In the first sample 3 is replaced by 1 and vice versa, while 2 never changes. The answer exists and is unique. In the second sample all numbers are replaced by 1, so it is impossible to unambiguously restore the original sequence. In the third sample fi β‰  3 for all i, so no sequence ai transforms into such bi and we can say for sure that Spongebob has made a mistake.
instruction
0
19,842
20
39,684
Tags: implementation Correct Solution: ``` #!/usr/bin/env python3 # 599B_sponge.py - Codeforces.com/problemset/problem/599/B by Sergey 2015 import unittest import sys ############################################################################### # Sponge Class (Main Program) ############################################################################### class Sponge: """ Sponge representation """ def __init__(self, test_inputs=None): """ Default constructor """ it = iter(test_inputs.split("\n")) if test_inputs else None def uinput(): return next(it) if it else sys.stdin.readline().rstrip() # Reading single elements [self.n, self.m] = map(int, uinput().split()) # Reading a single line of multiple elements self.numf = list(map(int, uinput().split())) # Reading a single line of multiple elements self.numb = list(map(int, uinput().split())) self.fd = {} self.fdn = {} for (i, n) in enumerate(self.numf): self.fd[n] = self.fd.setdefault(n, 0) + 1 self.fdn[n] = i + 1 def calculate(self): """ Main calcualtion function of the class """ result = [] for n in self.numb: if n not in self.fd: return "Impossible" result.append(self.fdn[n]) for n in self.numb: if self.fd[n] > 1: return "Ambiguity" return "Possible\n" + " ".join(map(str, result)) ############################################################################### # Unit Tests ############################################################################### class unitTests(unittest.TestCase): def test_single_test(self): """ Sponge class testing """ # Constructor test test = "3 3\n3 2 1\n1 2 3" d = Sponge(test) self.assertEqual(d.n, 3) self.assertEqual(d.m, 3) self.assertEqual(d.numf, [3, 2, 1]) self.assertEqual(d.numb, [1, 2, 3]) # Sample test self.assertEqual(Sponge(test).calculate(), "Possible\n3 2 1") # Sample test test = "3 3\n1 1 3\n1 2" self.assertEqual(Sponge(test).calculate(), "Impossible") # Sample test test = "3 3\n1 1 1\n1 1 1" self.assertEqual(Sponge(test).calculate(), "Ambiguity") # My tests test = "" # self.assertEqual(Sponge(test).calculate(), "0") # Time limit test # self.time_limit_test(5000) def time_limit_test(self, nmax): """ Timelimit testing """ import random import timeit # Random inputs test = str(nmax) + " " + str(nmax) + "\n" numnums = [str(i) + " " + str(i+1) for i in range(nmax)] test += "\n".join(numnums) + "\n" nums = [random.randint(1, 10000) for i in range(nmax)] test += " ".join(map(str, nums)) + "\n" # Run the test start = timeit.default_timer() d = Sponge(test) calc = timeit.default_timer() d.calculate() stop = timeit.default_timer() print("\nTimelimit Test: " + "{0:.3f}s (init {1:.3f}s calc {2:.3f}s)". format(stop-start, calc-start, stop-calc)) if __name__ == "__main__": # Avoiding recursion limitaions sys.setrecursionlimit(100000) if sys.argv[-1] == "-ut": unittest.main(argv=[" "]) # Print the result string sys.stdout.write(Sponge().calculate()) ```
output
1
19,842
20
39,685
Provide tags and a correct Python 3 solution for this coding contest problem. While Patrick was gone shopping, Spongebob decided to play a little trick on his friend. The naughty Sponge browsed through Patrick's personal stuff and found a sequence a1, a2, ..., am of length m, consisting of integers from 1 to n, not necessarily distinct. Then he picked some sequence f1, f2, ..., fn of length n and for each number ai got number bi = fai. To finish the prank he erased the initial sequence ai. It's hard to express how sad Patrick was when he returned home from shopping! We will just say that Spongebob immediately got really sorry about what he has done and he is now trying to restore the original sequence. Help him do this or determine that this is impossible. Input The first line of the input contains two integers n and m (1 ≀ n, m ≀ 100 000) β€” the lengths of sequences fi and bi respectively. The second line contains n integers, determining sequence f1, f2, ..., fn (1 ≀ fi ≀ n). The last line contains m integers, determining sequence b1, b2, ..., bm (1 ≀ bi ≀ n). Output Print "Possible" if there is exactly one sequence ai, such that bi = fai for all i from 1 to m. Then print m integers a1, a2, ..., am. If there are multiple suitable sequences ai, print "Ambiguity". If Spongebob has made a mistake in his calculations and no suitable sequence ai exists, print "Impossible". Examples Input 3 3 3 2 1 1 2 3 Output Possible 3 2 1 Input 3 3 1 1 1 1 1 1 Output Ambiguity Input 3 3 1 2 1 3 3 3 Output Impossible Note In the first sample 3 is replaced by 1 and vice versa, while 2 never changes. The answer exists and is unique. In the second sample all numbers are replaced by 1, so it is impossible to unambiguously restore the original sequence. In the third sample fi β‰  3 for all i, so no sequence ai transforms into such bi and we can say for sure that Spongebob has made a mistake.
instruction
0
19,845
20
39,690
Tags: implementation Correct Solution: ``` #!/usr/bin/env python3 n,m = [int(ii) for ii in input().split(' ')] f = [int(ii)-1 for ii in input().split(' ')] b = [int(ii)-1 for ii in input().split(' ')] mp = dict([]) for i in range(n): if f[i] in mp: mp[f[i]].append(i) else: mp[f[i]] = [i] res = "Possible" for i in range(m): if b[i] in mp: if len(mp[b[i]])>1: res = "Ambiguity" else: res = "Impossible" break print(res) if res=="Possible": print (' '.join(str(mp[b[i]][0]+1) for i in range(m))) ```
output
1
19,845
20
39,691
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. While Patrick was gone shopping, Spongebob decided to play a little trick on his friend. The naughty Sponge browsed through Patrick's personal stuff and found a sequence a1, a2, ..., am of length m, consisting of integers from 1 to n, not necessarily distinct. Then he picked some sequence f1, f2, ..., fn of length n and for each number ai got number bi = fai. To finish the prank he erased the initial sequence ai. It's hard to express how sad Patrick was when he returned home from shopping! We will just say that Spongebob immediately got really sorry about what he has done and he is now trying to restore the original sequence. Help him do this or determine that this is impossible. Input The first line of the input contains two integers n and m (1 ≀ n, m ≀ 100 000) β€” the lengths of sequences fi and bi respectively. The second line contains n integers, determining sequence f1, f2, ..., fn (1 ≀ fi ≀ n). The last line contains m integers, determining sequence b1, b2, ..., bm (1 ≀ bi ≀ n). Output Print "Possible" if there is exactly one sequence ai, such that bi = fai for all i from 1 to m. Then print m integers a1, a2, ..., am. If there are multiple suitable sequences ai, print "Ambiguity". If Spongebob has made a mistake in his calculations and no suitable sequence ai exists, print "Impossible". Examples Input 3 3 3 2 1 1 2 3 Output Possible 3 2 1 Input 3 3 1 1 1 1 1 1 Output Ambiguity Input 3 3 1 2 1 3 3 3 Output Impossible Note In the first sample 3 is replaced by 1 and vice versa, while 2 never changes. The answer exists and is unique. In the second sample all numbers are replaced by 1, so it is impossible to unambiguously restore the original sequence. In the third sample fi β‰  3 for all i, so no sequence ai transforms into such bi and we can say for sure that Spongebob has made a mistake. Submitted Solution: ``` # Fast IO (only use in integer input) or take care about string import os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n,m = map(int,input().split()) f = list(map(int,input().split())) b = list(map(int,input().split())) countF = [0] * n countB = [0] * n for elem in f: countF[elem-1] += 1 for elem in b: countB[elem-1] += 1 isAmbiguous = False isImpossible = False a = [0] * m for i in range(n): if countF[i] == 0 and countB[i] != 0: isImpossible = True break if countF[i] >= 2 and countB[i] != 0: isAmbiguous = True if isImpossible: print("Impossible") elif isAmbiguous: print("Ambiguity") else: FInverse = [0] * n for i in range(n): FInverse[f[i] - 1] = i for i in range(m): a[i] = FInverse[b[i] - 1] + 1 ans = [] for elem in a: ans.append(str(elem)) print("Possible") print(' '.join(ans)) ```
instruction
0
19,848
20
39,696
Yes
output
1
19,848
20
39,697
Provide tags and a correct Python 3 solution for this coding contest problem. A correct expression of the form a+b=c was written; a, b and c are non-negative integers without leading zeros. In this expression, the plus and equally signs were lost. The task is to restore the expression. In other words, one character '+' and one character '=' should be inserted into given sequence of digits so that: * character'+' is placed on the left of character '=', * characters '+' and '=' split the sequence into three non-empty subsequences consisting of digits (let's call the left part a, the middle part β€” b and the right part β€” c), * all the three parts a, b and c do not contain leading zeros, * it is true that a+b=c. It is guaranteed that in given tests answer always exists. Input The first line contains a non-empty string consisting of digits. The length of the string does not exceed 106. Output Output the restored expression. If there are several solutions, you can print any of them. Note that the answer at first should contain two terms (divided with symbol '+'), and then the result of their addition, before which symbol'=' should be. Do not separate numbers and operation signs with spaces. Strictly follow the output format given in the examples. If you remove symbol '+' and symbol '=' from answer string you should get a string, same as string from the input data. Examples Input 12345168 Output 123+45=168 Input 099 Output 0+9=9 Input 199100 Output 1+99=100 Input 123123123456456456579579579 Output 123123123+456456456=579579579
instruction
0
19,977
20
39,954
Tags: brute force, hashing, math Correct Solution: ``` def modgroup(M = 10**9+7, invn = 0) : exec(f'''class mod{M} : inv = [None] * {invn} if {invn} >= 2 : inv[1] = 1 for i in range(2, {invn}) : inv[i] = (({M}-{M}//i)*inv[{M}%i])%{M} def __init__(self, n = 0) : self.n = n % {M} __repr__ = lambda self : str(self.n) + '%{M}' __int__ = lambda self : self.n __eq__ = lambda a,b : a.n == b.n __add__ = lambda a,b : __class__(a.n + b.n) __sub__ = lambda a,b : __class__(a.n - b.n) __mul__ = lambda a,b : __class__(a.n * b.n) __pow__ = lambda a,b : __class__(pow(a.n, b.n, {M})) __truediv__ = lambda a,b : __class__(a.n * pow(b.n, {M-2}, {M})) __floordiv__ = lambda a,b : __class__(a.n * __class__.inv[b.n]) ''') return eval(f'mod{M}') def solution() : s = input() l = len(s) mod = modgroup() num = [mod(0)] * (l+1) # num[i] = int(s[:i]) <mod> shift = [mod(1)] * (l+1) # shift[i] = 10**i <mod> for i,x in enumerate(s, 1) : num[i] = num[i-1] * mod(10) + mod(int(x)) shift[i] = shift[i-1] * mod(10) def mod_check(la, lb, lc) : a,b,c = num[la], num[la+lb], num[la+lb+lc] c -= b * shift[lc] b -= a * shift[lb] return a + b == c for lc in range(l//3+bool(l%3), l//2+1) : for lb in (lc, lc-1, l-lc*2, l-lc*2+1) : la = l - lc - lb if la < 1 or lb < 1 or lc < 1 : continue if la > lc or lb > lc : continue if not mod_check(la, lb, lc) : continue print(f'{s[:la]}+{s[la:la+lb]}={s[la+lb:la+lb+lc]}') return solution() ```
output
1
19,977
20
39,955
Provide tags and a correct Python 3 solution for this coding contest problem. A correct expression of the form a+b=c was written; a, b and c are non-negative integers without leading zeros. In this expression, the plus and equally signs were lost. The task is to restore the expression. In other words, one character '+' and one character '=' should be inserted into given sequence of digits so that: * character'+' is placed on the left of character '=', * characters '+' and '=' split the sequence into three non-empty subsequences consisting of digits (let's call the left part a, the middle part β€” b and the right part β€” c), * all the three parts a, b and c do not contain leading zeros, * it is true that a+b=c. It is guaranteed that in given tests answer always exists. Input The first line contains a non-empty string consisting of digits. The length of the string does not exceed 106. Output Output the restored expression. If there are several solutions, you can print any of them. Note that the answer at first should contain two terms (divided with symbol '+'), and then the result of their addition, before which symbol'=' should be. Do not separate numbers and operation signs with spaces. Strictly follow the output format given in the examples. If you remove symbol '+' and symbol '=' from answer string you should get a string, same as string from the input data. Examples Input 12345168 Output 123+45=168 Input 099 Output 0+9=9 Input 199100 Output 1+99=100 Input 123123123456456456579579579 Output 123123123+456456456=579579579
instruction
0
19,978
20
39,956
Tags: brute force, hashing, math Correct Solution: ``` def modgroup(M = 10**9+7, invn = 0) : exec(f'''class mod{M} : inv = [None] * {invn+1} if {invn+1} >= 2 : inv[1] = 1 for i in range(2, {invn+1}) : inv[i] = (({M} - {M}//i) * inv[{M}%i]) %{M} def __init__(self, n = 0) : self.n = n % {M} __repr__ = lambda self : str(self.n) + '%{M}' __int__ = lambda self : self.n __eq__ = lambda a,b : int(a)%{M} == int(b)%{M} __add__ = lambda a,b : __class__(a.n + int(b)) __sub__ = lambda a,b : __class__(a.n - int(b)) __mul__ = lambda a,b : __class__(a.n * int(b)) __radd__ = lambda a,b : __class__(b + a.n) __rsub__ = lambda a,b : __class__(b - a.n) __rmul__ = lambda a,b : __class__(b * a.n) def __pow__(a,b) : a, ret = int(a), 1 while b : if b & 1 : ret = (ret * a) % {M} a = (a * a) % {M} b >>= 1 return __class__(ret) def __truediv__(a,b) : return __class__(a.n * __class__.__pow__(b, {M-2})) def __floordiv__(a,b) : return __class__(a.n * __class__.inv[b]) ''') return eval(f'mod{M}') def solution() : s = input() l = len(s) mod = modgroup() num = [mod(0)] * (l+1) # num[i] = int(s[:i]) <mod> shift = [mod(1)] * (l+1) # shift[i] = 10**i <mod> for i,x in enumerate(s, 1) : num[i] = num[i-1] * 10 + int(x) shift[i] = shift[i-1] * 10 def mod_check(la, lb, lc) : a,b,c = num[la], num[la+lb], num[la+lb+lc] c -= b * shift[lc] b -= a * shift[lb] return a + b == c for lc in range(l//3+bool(l%3), l//2+1) : for lb in (lc, lc-1, l-lc*2, l-lc*2+1) : la = l - lc - lb if la < 1 or lb < 1 or lc < 1 : continue if la > lc or lb > lc : continue if not mod_check(la, lb, lc) : continue print(f'{s[:la]}+{s[la:la+lb]}={s[la+lb:la+lb+lc]}') return solution() ```
output
1
19,978
20
39,957
Provide tags and a correct Python 3 solution for this coding contest problem. A correct expression of the form a+b=c was written; a, b and c are non-negative integers without leading zeros. In this expression, the plus and equally signs were lost. The task is to restore the expression. In other words, one character '+' and one character '=' should be inserted into given sequence of digits so that: * character'+' is placed on the left of character '=', * characters '+' and '=' split the sequence into three non-empty subsequences consisting of digits (let's call the left part a, the middle part β€” b and the right part β€” c), * all the three parts a, b and c do not contain leading zeros, * it is true that a+b=c. It is guaranteed that in given tests answer always exists. Input The first line contains a non-empty string consisting of digits. The length of the string does not exceed 106. Output Output the restored expression. If there are several solutions, you can print any of them. Note that the answer at first should contain two terms (divided with symbol '+'), and then the result of their addition, before which symbol'=' should be. Do not separate numbers and operation signs with spaces. Strictly follow the output format given in the examples. If you remove symbol '+' and symbol '=' from answer string you should get a string, same as string from the input data. Examples Input 12345168 Output 123+45=168 Input 099 Output 0+9=9 Input 199100 Output 1+99=100 Input 123123123456456456579579579 Output 123123123+456456456=579579579
instruction
0
19,979
20
39,958
Tags: brute force, hashing, math Correct Solution: ``` def modgroup(M = 10**9+7, invn = 0) : exec(f'''class mod{M} : inv = [None] * {invn} if {invn} >= 2 : inv[1] = 1 for i in range(2, {invn}) : inv[i] = (({M}-{M}//i)*inv[{M}%i])%{M} def __init__(self, n = 0) : self.n = n % {M} __repr__ = lambda self : str(self.n) + '%{M}' __int__ = lambda self : self.n __eq__ = lambda a,b : a.n == b.n __add__ = lambda a,b : __class__(a.n + b.n) __sub__ = lambda a,b : __class__(a.n - b.n) __mul__ = lambda a,b : __class__(a.n * b.n) __pow__ = lambda a,b : __class__(pow(a.n, b.n, {M})) __truediv__ = lambda a,b : __class__(a.n * pow(b.n, {M-2}, {M})) __floordiv__ = lambda a,b : __class__(a.n * __class__.inv[b.n]) ''') return eval(f'mod{M}') def solution() : s = input() l = len(s) mod = modgroup() num = [mod(0)] * (l+1) # num[i] = int(s[:i]) <mod> shift = [mod(1)] * (l+1) # shift[i] = 10**i <mod> for i,x in enumerate(s, 1) : num[i] = num[i-1] * mod(10) + mod(int(x)) shift[i] = shift[i-1] * mod(10) def mod_check(la, lb, lc) : a,b,c = num[la], num[la+lb], num[la+lb+lc] c -= b * shift[lc] b -= a * shift[lb] return a + b == c for lc in range(l//3+bool(l%3), l//2+1) : for lb in (lc, lc-1, l-lc*2, l-lc*2+1) : la = l - lc - lb if la < 1 or lb < 1 or lc < 1 : continue if la > lc or lb > lc : continue if not mod_check(la, lb, lc) : continue a,b,c = s[:la], s[la:la+lb], s[la+lb:la+lb+lc] print(f'{a}+{b}={c}'); return solution() ```
output
1
19,979
20
39,959
Provide tags and a correct Python 3 solution for this coding contest problem. Little Petya loves inequations. Help him find n positive integers a1, a2, ..., an, such that the following two conditions are satisfied: * a12 + a22 + ... + an2 β‰₯ x * a1 + a2 + ... + an ≀ y Input The first line contains three space-separated integers n, x and y (1 ≀ n ≀ 105, 1 ≀ x ≀ 1012, 1 ≀ y ≀ 106). Please do not use the %lld specificator to read or write 64-bit integers in Π‘++. It is recommended to use cin, cout streams or the %I64d specificator. Output Print n positive integers that satisfy the conditions, one integer per line. If such numbers do not exist, print a single number "-1". If there are several solutions, print any of them. Examples Input 5 15 15 Output 4 4 1 1 2 Input 2 3 2 Output -1 Input 1 99 11 Output 11
instruction
0
20,334
20
40,668
Tags: greedy Correct Solution: ``` n,x,y=map(int, input().split()) if n>y: print(-1) else: z=y-(n-1) if z**2 + (n-1)<x: print(-1) else: for i in range(n-1): print(1) print(z) ```
output
1
20,334
20
40,669
Provide tags and a correct Python 3 solution for this coding contest problem. Little Petya loves inequations. Help him find n positive integers a1, a2, ..., an, such that the following two conditions are satisfied: * a12 + a22 + ... + an2 β‰₯ x * a1 + a2 + ... + an ≀ y Input The first line contains three space-separated integers n, x and y (1 ≀ n ≀ 105, 1 ≀ x ≀ 1012, 1 ≀ y ≀ 106). Please do not use the %lld specificator to read or write 64-bit integers in Π‘++. It is recommended to use cin, cout streams or the %I64d specificator. Output Print n positive integers that satisfy the conditions, one integer per line. If such numbers do not exist, print a single number "-1". If there are several solutions, print any of them. Examples Input 5 15 15 Output 4 4 1 1 2 Input 2 3 2 Output -1 Input 1 99 11 Output 11
instruction
0
20,335
20
40,670
Tags: greedy Correct Solution: ``` n,x,y=[int(p) for p in input().split()] if n>y or (y-n+1)**2 + n - 1<x: print(-1) else: y='\n'.join(map(str,[y-n+1]+[1]*(n-1))) print(y) ```
output
1
20,335
20
40,671
Provide tags and a correct Python 3 solution for this coding contest problem. Little Petya loves inequations. Help him find n positive integers a1, a2, ..., an, such that the following two conditions are satisfied: * a12 + a22 + ... + an2 β‰₯ x * a1 + a2 + ... + an ≀ y Input The first line contains three space-separated integers n, x and y (1 ≀ n ≀ 105, 1 ≀ x ≀ 1012, 1 ≀ y ≀ 106). Please do not use the %lld specificator to read or write 64-bit integers in Π‘++. It is recommended to use cin, cout streams or the %I64d specificator. Output Print n positive integers that satisfy the conditions, one integer per line. If such numbers do not exist, print a single number "-1". If there are several solutions, print any of them. Examples Input 5 15 15 Output 4 4 1 1 2 Input 2 3 2 Output -1 Input 1 99 11 Output 11
instruction
0
20,336
20
40,672
Tags: greedy Correct Solution: ``` n,x,y=map(int,input().split()) if(y<n): print(-1) elif((y-n+1)**2+(n-1)>=x): print(y-n+1) for i in range(n-1): print(1) else: print(-1) ```
output
1
20,336
20
40,673
Provide tags and a correct Python 3 solution for this coding contest problem. Little Petya loves inequations. Help him find n positive integers a1, a2, ..., an, such that the following two conditions are satisfied: * a12 + a22 + ... + an2 β‰₯ x * a1 + a2 + ... + an ≀ y Input The first line contains three space-separated integers n, x and y (1 ≀ n ≀ 105, 1 ≀ x ≀ 1012, 1 ≀ y ≀ 106). Please do not use the %lld specificator to read or write 64-bit integers in Π‘++. It is recommended to use cin, cout streams or the %I64d specificator. Output Print n positive integers that satisfy the conditions, one integer per line. If such numbers do not exist, print a single number "-1". If there are several solutions, print any of them. Examples Input 5 15 15 Output 4 4 1 1 2 Input 2 3 2 Output -1 Input 1 99 11 Output 11
instruction
0
20,337
20
40,674
Tags: greedy Correct Solution: ``` n, x, y = list(map(int, input().split())) if y >= n and n - 1 + (y - n + 1) ** 2 >= x: print(' '.join(map(str, [1] * (n - 1) + [y - n + 1]))) else: print(-1) ```
output
1
20,337
20
40,675
Provide tags and a correct Python 3 solution for this coding contest problem. Little Petya loves inequations. Help him find n positive integers a1, a2, ..., an, such that the following two conditions are satisfied: * a12 + a22 + ... + an2 β‰₯ x * a1 + a2 + ... + an ≀ y Input The first line contains three space-separated integers n, x and y (1 ≀ n ≀ 105, 1 ≀ x ≀ 1012, 1 ≀ y ≀ 106). Please do not use the %lld specificator to read or write 64-bit integers in Π‘++. It is recommended to use cin, cout streams or the %I64d specificator. Output Print n positive integers that satisfy the conditions, one integer per line. If such numbers do not exist, print a single number "-1". If there are several solutions, print any of them. Examples Input 5 15 15 Output 4 4 1 1 2 Input 2 3 2 Output -1 Input 1 99 11 Output 11
instruction
0
20,338
20
40,676
Tags: greedy Correct Solution: ``` n,x,y=[int(p) for p in input().split()] if n>y or (y-n+1)**2 + n - 1<x: print(-1) else: print(y-n+1) for i in range(1,n): print(1) ```
output
1
20,338
20
40,677
Provide tags and a correct Python 3 solution for this coding contest problem. Little Petya loves inequations. Help him find n positive integers a1, a2, ..., an, such that the following two conditions are satisfied: * a12 + a22 + ... + an2 β‰₯ x * a1 + a2 + ... + an ≀ y Input The first line contains three space-separated integers n, x and y (1 ≀ n ≀ 105, 1 ≀ x ≀ 1012, 1 ≀ y ≀ 106). Please do not use the %lld specificator to read or write 64-bit integers in Π‘++. It is recommended to use cin, cout streams or the %I64d specificator. Output Print n positive integers that satisfy the conditions, one integer per line. If such numbers do not exist, print a single number "-1". If there are several solutions, print any of them. Examples Input 5 15 15 Output 4 4 1 1 2 Input 2 3 2 Output -1 Input 1 99 11 Output 11
instruction
0
20,339
20
40,678
Tags: greedy Correct Solution: ``` n, x, y = map(int, input().split()) if (n - 1 + (y - n + 1) ** 2 >= x and y > n - 1): print('1 '* (n - 1) + str(y - n + 1)) else: print(-1) ```
output
1
20,339
20
40,679
Provide tags and a correct Python 3 solution for this coding contest problem. Little Petya loves inequations. Help him find n positive integers a1, a2, ..., an, such that the following two conditions are satisfied: * a12 + a22 + ... + an2 β‰₯ x * a1 + a2 + ... + an ≀ y Input The first line contains three space-separated integers n, x and y (1 ≀ n ≀ 105, 1 ≀ x ≀ 1012, 1 ≀ y ≀ 106). Please do not use the %lld specificator to read or write 64-bit integers in Π‘++. It is recommended to use cin, cout streams or the %I64d specificator. Output Print n positive integers that satisfy the conditions, one integer per line. If such numbers do not exist, print a single number "-1". If there are several solutions, print any of them. Examples Input 5 15 15 Output 4 4 1 1 2 Input 2 3 2 Output -1 Input 1 99 11 Output 11
instruction
0
20,340
20
40,680
Tags: greedy Correct Solution: ``` n,x,y=map(int,input().split()) sl=y-(n-1) sm=n-1+sl**2 if sl<=0 or sm<x: print(-1) else: for i in range(n-1): print(1) print(sl) ```
output
1
20,340
20
40,681
Provide tags and a correct Python 3 solution for this coding contest problem. Little Petya loves inequations. Help him find n positive integers a1, a2, ..., an, such that the following two conditions are satisfied: * a12 + a22 + ... + an2 β‰₯ x * a1 + a2 + ... + an ≀ y Input The first line contains three space-separated integers n, x and y (1 ≀ n ≀ 105, 1 ≀ x ≀ 1012, 1 ≀ y ≀ 106). Please do not use the %lld specificator to read or write 64-bit integers in Π‘++. It is recommended to use cin, cout streams or the %I64d specificator. Output Print n positive integers that satisfy the conditions, one integer per line. If such numbers do not exist, print a single number "-1". If there are several solutions, print any of them. Examples Input 5 15 15 Output 4 4 1 1 2 Input 2 3 2 Output -1 Input 1 99 11 Output 11
instruction
0
20,341
20
40,682
Tags: greedy Correct Solution: ``` n, x, y = map(int, input().split()) if n > y: print(-1) else: left = y - n left += 1 if left ** 2 + n - 1 >= x: print(left) for _ in range(n - 1): print(1) else: print(-1) ```
output
1
20,341
20
40,683
Provide tags and a correct Python 3 solution for this coding contest problem. There are n digital panels placed in a straight line. Each panel can show any digit from 0 to 9. Initially, all panels show 0. Every second, the digit shown by each panel increases by 1. In other words, at the end of every second, a panel that showed 9 would now show 0, a panel that showed 0 would now show 1, a panel that showed 1 would now show 2, and so on. When a panel is paused, the digit displayed on the panel does not change in the subsequent seconds. You must pause exactly one of these panels, at any second you wish. Then, the panels adjacent to it get paused one second later, the panels adjacent to those get paused 2 seconds later, and so on. In other words, if you pause panel x, panel y (for all valid y) would be paused exactly |xβˆ’y| seconds later. For example, suppose there are 4 panels, and the 3-rd panel is paused when the digit 9 is on it. * The panel 1 pauses 2 seconds later, so it has the digit 1; * the panel 2 pauses 1 second later, so it has the digit 0; * the panel 4 pauses 1 second later, so it has the digit 0. The resulting 4-digit number is 1090. Note that this example is not optimal for n = 4. Once all panels have been paused, you write the digits displayed on them from left to right, to form an n digit number (it can consist of leading zeros). What is the largest possible number you can get? Initially, all panels show 0. Input The first line of the input contains a single integer t (1 ≀ t ≀ 100) β€” the number of test cases. Each test case consists of a single line containing a single integer n (1 ≀ n ≀ 2β‹…10^5). It is guaranteed that the sum of n over all test cases does not exceed 2β‹…10^5. Output For each test case, print the largest number you can achieve, if you pause one panel optimally. Example Input 2 1 2 Output 9 98 Note In the first test case, it is optimal to pause the first panel when the number 9 is displayed on it. In the second test case, it is optimal to pause the second panel when the number 8 is displayed on it.
instruction
0
20,484
20
40,968
Tags: constructive algorithms, greedy, math Correct Solution: ``` t = int(input()) def solve(): n = int(input()) if n == 1 : print(9) elif n == 2: print(98) elif n == 3: print(989) else: x = 0 print(989, end = "") for _ in range(n-3): print(x, end = "") x += 1 if x == 10: x=0 print("") while(t): solve() t -= 1 ```
output
1
20,484
20
40,969
Provide tags and a correct Python 3 solution for this coding contest problem. There are n digital panels placed in a straight line. Each panel can show any digit from 0 to 9. Initially, all panels show 0. Every second, the digit shown by each panel increases by 1. In other words, at the end of every second, a panel that showed 9 would now show 0, a panel that showed 0 would now show 1, a panel that showed 1 would now show 2, and so on. When a panel is paused, the digit displayed on the panel does not change in the subsequent seconds. You must pause exactly one of these panels, at any second you wish. Then, the panels adjacent to it get paused one second later, the panels adjacent to those get paused 2 seconds later, and so on. In other words, if you pause panel x, panel y (for all valid y) would be paused exactly |xβˆ’y| seconds later. For example, suppose there are 4 panels, and the 3-rd panel is paused when the digit 9 is on it. * The panel 1 pauses 2 seconds later, so it has the digit 1; * the panel 2 pauses 1 second later, so it has the digit 0; * the panel 4 pauses 1 second later, so it has the digit 0. The resulting 4-digit number is 1090. Note that this example is not optimal for n = 4. Once all panels have been paused, you write the digits displayed on them from left to right, to form an n digit number (it can consist of leading zeros). What is the largest possible number you can get? Initially, all panels show 0. Input The first line of the input contains a single integer t (1 ≀ t ≀ 100) β€” the number of test cases. Each test case consists of a single line containing a single integer n (1 ≀ n ≀ 2β‹…10^5). It is guaranteed that the sum of n over all test cases does not exceed 2β‹…10^5. Output For each test case, print the largest number you can achieve, if you pause one panel optimally. Example Input 2 1 2 Output 9 98 Note In the first test case, it is optimal to pause the first panel when the number 9 is displayed on it. In the second test case, it is optimal to pause the second panel when the number 8 is displayed on it.
instruction
0
20,485
20
40,970
Tags: constructive algorithms, greedy, math Correct Solution: ``` for _ in range(int(input())): n=int(input()) if n==1:print(9) elif n==2:print(98) elif n==3:print(989) else: print(989,end="") if n<=13: for i in range(n-3): print(i,end="") print() else: s="0123456789" p=(n-3)//10 l=(n-3)%10 print("0123456789"*p+s[:l],end="") print() ```
output
1
20,485
20
40,971
Provide tags and a correct Python 3 solution for this coding contest problem. There are n digital panels placed in a straight line. Each panel can show any digit from 0 to 9. Initially, all panels show 0. Every second, the digit shown by each panel increases by 1. In other words, at the end of every second, a panel that showed 9 would now show 0, a panel that showed 0 would now show 1, a panel that showed 1 would now show 2, and so on. When a panel is paused, the digit displayed on the panel does not change in the subsequent seconds. You must pause exactly one of these panels, at any second you wish. Then, the panels adjacent to it get paused one second later, the panels adjacent to those get paused 2 seconds later, and so on. In other words, if you pause panel x, panel y (for all valid y) would be paused exactly |xβˆ’y| seconds later. For example, suppose there are 4 panels, and the 3-rd panel is paused when the digit 9 is on it. * The panel 1 pauses 2 seconds later, so it has the digit 1; * the panel 2 pauses 1 second later, so it has the digit 0; * the panel 4 pauses 1 second later, so it has the digit 0. The resulting 4-digit number is 1090. Note that this example is not optimal for n = 4. Once all panels have been paused, you write the digits displayed on them from left to right, to form an n digit number (it can consist of leading zeros). What is the largest possible number you can get? Initially, all panels show 0. Input The first line of the input contains a single integer t (1 ≀ t ≀ 100) β€” the number of test cases. Each test case consists of a single line containing a single integer n (1 ≀ n ≀ 2β‹…10^5). It is guaranteed that the sum of n over all test cases does not exceed 2β‹…10^5. Output For each test case, print the largest number you can achieve, if you pause one panel optimally. Example Input 2 1 2 Output 9 98 Note In the first test case, it is optimal to pause the first panel when the number 9 is displayed on it. In the second test case, it is optimal to pause the second panel when the number 8 is displayed on it.
instruction
0
20,486
20
40,972
Tags: constructive algorithms, greedy, math Correct Solution: ``` import sys input = sys.stdin.readline for i in range(int(input())): n = int(input()) tmp = ['9','8','9'] if n<=3: tmp = tmp[:n] tmp = ''.join(tmp) else: for i in range(n-3): tmp.append(str((i)%10)) tmp = ''.join(tmp) print(tmp) ```
output
1
20,486
20
40,973
Provide tags and a correct Python 3 solution for this coding contest problem. There are n digital panels placed in a straight line. Each panel can show any digit from 0 to 9. Initially, all panels show 0. Every second, the digit shown by each panel increases by 1. In other words, at the end of every second, a panel that showed 9 would now show 0, a panel that showed 0 would now show 1, a panel that showed 1 would now show 2, and so on. When a panel is paused, the digit displayed on the panel does not change in the subsequent seconds. You must pause exactly one of these panels, at any second you wish. Then, the panels adjacent to it get paused one second later, the panels adjacent to those get paused 2 seconds later, and so on. In other words, if you pause panel x, panel y (for all valid y) would be paused exactly |xβˆ’y| seconds later. For example, suppose there are 4 panels, and the 3-rd panel is paused when the digit 9 is on it. * The panel 1 pauses 2 seconds later, so it has the digit 1; * the panel 2 pauses 1 second later, so it has the digit 0; * the panel 4 pauses 1 second later, so it has the digit 0. The resulting 4-digit number is 1090. Note that this example is not optimal for n = 4. Once all panels have been paused, you write the digits displayed on them from left to right, to form an n digit number (it can consist of leading zeros). What is the largest possible number you can get? Initially, all panels show 0. Input The first line of the input contains a single integer t (1 ≀ t ≀ 100) β€” the number of test cases. Each test case consists of a single line containing a single integer n (1 ≀ n ≀ 2β‹…10^5). It is guaranteed that the sum of n over all test cases does not exceed 2β‹…10^5. Output For each test case, print the largest number you can achieve, if you pause one panel optimally. Example Input 2 1 2 Output 9 98 Note In the first test case, it is optimal to pause the first panel when the number 9 is displayed on it. In the second test case, it is optimal to pause the second panel when the number 8 is displayed on it.
instruction
0
20,487
20
40,974
Tags: constructive algorithms, greedy, math Correct Solution: ``` from collections import Counter import string import math import sys # sys.setrecursionlimit(10**6) from fractions import Fraction def array_int(): return [int(i) for i in sys.stdin.readline().split()] def vary(arrber_of_variables): if arrber_of_variables==1: return int(sys.stdin.readline()) if arrber_of_variables>=2: return map(int,sys.stdin.readline().split()) def makedict(var): return dict(Counter(var)) testcases=vary(1) for _ in range(testcases): n=vary(1) s=[9,8,9] if n<3: print(*s[:n],sep="") continue p=0 while n-3>0: s.append(p%10) p+=1 n-=1 print(*s,sep="") ```
output
1
20,487
20
40,975
Provide tags and a correct Python 3 solution for this coding contest problem. There are n digital panels placed in a straight line. Each panel can show any digit from 0 to 9. Initially, all panels show 0. Every second, the digit shown by each panel increases by 1. In other words, at the end of every second, a panel that showed 9 would now show 0, a panel that showed 0 would now show 1, a panel that showed 1 would now show 2, and so on. When a panel is paused, the digit displayed on the panel does not change in the subsequent seconds. You must pause exactly one of these panels, at any second you wish. Then, the panels adjacent to it get paused one second later, the panels adjacent to those get paused 2 seconds later, and so on. In other words, if you pause panel x, panel y (for all valid y) would be paused exactly |xβˆ’y| seconds later. For example, suppose there are 4 panels, and the 3-rd panel is paused when the digit 9 is on it. * The panel 1 pauses 2 seconds later, so it has the digit 1; * the panel 2 pauses 1 second later, so it has the digit 0; * the panel 4 pauses 1 second later, so it has the digit 0. The resulting 4-digit number is 1090. Note that this example is not optimal for n = 4. Once all panels have been paused, you write the digits displayed on them from left to right, to form an n digit number (it can consist of leading zeros). What is the largest possible number you can get? Initially, all panels show 0. Input The first line of the input contains a single integer t (1 ≀ t ≀ 100) β€” the number of test cases. Each test case consists of a single line containing a single integer n (1 ≀ n ≀ 2β‹…10^5). It is guaranteed that the sum of n over all test cases does not exceed 2β‹…10^5. Output For each test case, print the largest number you can achieve, if you pause one panel optimally. Example Input 2 1 2 Output 9 98 Note In the first test case, it is optimal to pause the first panel when the number 9 is displayed on it. In the second test case, it is optimal to pause the second panel when the number 8 is displayed on it.
instruction
0
20,488
20
40,976
Tags: constructive algorithms, greedy, math Correct Solution: ``` t=int(input()) l=[] m=0 s1='9890123456789' s2='0123456789' for i in range(t): n=int(input()) if(n==0): print(0) elif(n<=13): print(s1[0:n]) else: x=n-3 y=x//10 r=x%10 stri="989"+(y*s2)+(s2[0:r]) print(stri) ```
output
1
20,488
20
40,977
Provide tags and a correct Python 3 solution for this coding contest problem. There are n digital panels placed in a straight line. Each panel can show any digit from 0 to 9. Initially, all panels show 0. Every second, the digit shown by each panel increases by 1. In other words, at the end of every second, a panel that showed 9 would now show 0, a panel that showed 0 would now show 1, a panel that showed 1 would now show 2, and so on. When a panel is paused, the digit displayed on the panel does not change in the subsequent seconds. You must pause exactly one of these panels, at any second you wish. Then, the panels adjacent to it get paused one second later, the panels adjacent to those get paused 2 seconds later, and so on. In other words, if you pause panel x, panel y (for all valid y) would be paused exactly |xβˆ’y| seconds later. For example, suppose there are 4 panels, and the 3-rd panel is paused when the digit 9 is on it. * The panel 1 pauses 2 seconds later, so it has the digit 1; * the panel 2 pauses 1 second later, so it has the digit 0; * the panel 4 pauses 1 second later, so it has the digit 0. The resulting 4-digit number is 1090. Note that this example is not optimal for n = 4. Once all panels have been paused, you write the digits displayed on them from left to right, to form an n digit number (it can consist of leading zeros). What is the largest possible number you can get? Initially, all panels show 0. Input The first line of the input contains a single integer t (1 ≀ t ≀ 100) β€” the number of test cases. Each test case consists of a single line containing a single integer n (1 ≀ n ≀ 2β‹…10^5). It is guaranteed that the sum of n over all test cases does not exceed 2β‹…10^5. Output For each test case, print the largest number you can achieve, if you pause one panel optimally. Example Input 2 1 2 Output 9 98 Note In the first test case, it is optimal to pause the first panel when the number 9 is displayed on it. In the second test case, it is optimal to pause the second panel when the number 8 is displayed on it.
instruction
0
20,489
20
40,978
Tags: constructive algorithms, greedy, math Correct Solution: ``` import sys from functools import reduce from collections import Counter import time import datetime import math # def time_t(): # print("Current date and time: " , datetime.datetime.now()) # print("Current year: ", datetime.date.today().strftime("%Y")) # print("Month of year: ", datetime.date.today().strftime("%B")) # print("Week number of the year: ", datetime.date.today().strftime("%W")) # print("Weekday of the week: ", datetime.date.today().strftime("%w")) # print("Day of year: ", datetime.date.today().strftime("%j")) # print("Day of the month : ", datetime.date.today().strftime("%d")) # print("Day of week: ", datetime.date.today().strftime("%A")) def ip(): return int(sys.stdin.readline()) # def sip(): return sys.stdin.readline() def sip() : return input() def mip(): return map(int,sys.stdin.readline().split()) def mips(): return map(str,sys.stdin.readline().split()) def lip(): return list(map(int,sys.stdin.readline().split())) def matip(n,m): lst=[] for i in range(n): arr = lip() lst.insert(i,arr) return lst def factors(n): # find the factors of a number return list(set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))) def minJumps(arr, n): #to reach from 0 to n-1 in the array in minimum steps jumps = [0 for i in range(n)] if (n == 0) or (arr[0] == 0): return float('inf') jumps[0] = 0 for i in range(1, n): jumps[i] = float('inf') for j in range(i): if (i <= j + arr[j]) and (jumps[j] != float('inf')): jumps[i] = min(jumps[i], jumps[j] + 1) break return jumps[n-1] def dic(arr): # converting list into dict of count return Counter(arr) def check_prime(n): if n<2: return False for i in range(2,int(n**(0.5))+1,2): if n%i==0: return False return True # --------------------------------------------------------- # # sys.stdin = open('input.txt','r') # sys.stdout = open('output.txt','w') # --------------------------------------------------------- # t = ip() while t: t-=1 n = ip() print(9,end='') val = 8 for i in range(n-1): print(val,end='') val+=1 if val==10: val = 0 print() # print(time.process_time()) ```
output
1
20,489
20
40,979
Provide tags and a correct Python 3 solution for this coding contest problem. There are n digital panels placed in a straight line. Each panel can show any digit from 0 to 9. Initially, all panels show 0. Every second, the digit shown by each panel increases by 1. In other words, at the end of every second, a panel that showed 9 would now show 0, a panel that showed 0 would now show 1, a panel that showed 1 would now show 2, and so on. When a panel is paused, the digit displayed on the panel does not change in the subsequent seconds. You must pause exactly one of these panels, at any second you wish. Then, the panels adjacent to it get paused one second later, the panels adjacent to those get paused 2 seconds later, and so on. In other words, if you pause panel x, panel y (for all valid y) would be paused exactly |xβˆ’y| seconds later. For example, suppose there are 4 panels, and the 3-rd panel is paused when the digit 9 is on it. * The panel 1 pauses 2 seconds later, so it has the digit 1; * the panel 2 pauses 1 second later, so it has the digit 0; * the panel 4 pauses 1 second later, so it has the digit 0. The resulting 4-digit number is 1090. Note that this example is not optimal for n = 4. Once all panels have been paused, you write the digits displayed on them from left to right, to form an n digit number (it can consist of leading zeros). What is the largest possible number you can get? Initially, all panels show 0. Input The first line of the input contains a single integer t (1 ≀ t ≀ 100) β€” the number of test cases. Each test case consists of a single line containing a single integer n (1 ≀ n ≀ 2β‹…10^5). It is guaranteed that the sum of n over all test cases does not exceed 2β‹…10^5. Output For each test case, print the largest number you can achieve, if you pause one panel optimally. Example Input 2 1 2 Output 9 98 Note In the first test case, it is optimal to pause the first panel when the number 9 is displayed on it. In the second test case, it is optimal to pause the second panel when the number 8 is displayed on it.
instruction
0
20,490
20
40,980
Tags: constructive algorithms, greedy, math Correct Solution: ``` s = '989' + '0123456789' * 20000 T = int(input()) for _ in range(T): N = int(input()) print(s[:N]) ```
output
1
20,490
20
40,981