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 has two strings a and b of the same length n. The strings consist only of lucky digits. Petya can perform operations of two types: * replace any one digit from string a by its opposite (i.e., replace 4 by 7 and 7 by 4); * swap any pair of digits in string a. Petya is interested in the minimum number of operations that are needed to make string a equal to string b. Help him with the task. Input The first and the second line contains strings a and b, correspondingly. Strings a and b have equal lengths and contain only lucky digits. The strings are not empty, their length does not exceed 105. Output Print on the single line the single number β€” the minimum number of operations needed to convert string a into string b. Examples Input 47 74 Output 1 Input 774 744 Output 1 Input 777 444 Output 3 Note In the first sample it is enough simply to swap the first and the second digit. In the second sample we should replace the second digit with its opposite. In the third number we should replace all three digits with their opposites.
instruction
0
13,520
20
27,040
Tags: greedy, implementation Correct Solution: ``` a = input() b = input() n = len(a) x = 0 y = 0 for i in range(n): if a[i] == '4' and b[i] == '7': x += 1 if a[i] == '7' and b[i] == '4': y += 1 print(max(x, y)) ```
output
1
13,520
20
27,041
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 has two strings a and b of the same length n. The strings consist only of lucky digits. Petya can perform operations of two types: * replace any one digit from string a by its opposite (i.e., replace 4 by 7 and 7 by 4); * swap any pair of digits in string a. Petya is interested in the minimum number of operations that are needed to make string a equal to string b. Help him with the task. Input The first and the second line contains strings a and b, correspondingly. Strings a and b have equal lengths and contain only lucky digits. The strings are not empty, their length does not exceed 105. Output Print on the single line the single number β€” the minimum number of operations needed to convert string a into string b. Examples Input 47 74 Output 1 Input 774 744 Output 1 Input 777 444 Output 3 Note In the first sample it is enough simply to swap the first and the second digit. In the second sample we should replace the second digit with its opposite. In the third number we should replace all three digits with their opposites.
instruction
0
13,521
20
27,042
Tags: greedy, implementation Correct Solution: ``` c47,c74=0,0 a,b=input(),input() for i in range(len(a)): if a[i]==b[i]:continue if a[i]=='4': c47+=1 else: c74+=1 print(max(c47,c74)) ```
output
1
13,521
20
27,043
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 has two strings a and b of the same length n. The strings consist only of lucky digits. Petya can perform operations of two types: * replace any one digit from string a by its opposite (i.e., replace 4 by 7 and 7 by 4); * swap any pair of digits in string a. Petya is interested in the minimum number of operations that are needed to make string a equal to string b. Help him with the task. Input The first and the second line contains strings a and b, correspondingly. Strings a and b have equal lengths and contain only lucky digits. The strings are not empty, their length does not exceed 105. Output Print on the single line the single number β€” the minimum number of operations needed to convert string a into string b. Examples Input 47 74 Output 1 Input 774 744 Output 1 Input 777 444 Output 3 Note In the first sample it is enough simply to swap the first and the second digit. In the second sample we should replace the second digit with its opposite. In the third number we should replace all three digits with their opposites.
instruction
0
13,522
20
27,044
Tags: greedy, implementation Correct Solution: ``` a=input() b=input() k1=0 k2=0 for i in range (len(a)): if a[i]!=b[i]: if a[i]=='4': k1+=1 else: k2+=1 d=max(k1,k2) print (d) ```
output
1
13,522
20
27,045
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 has two strings a and b of the same length n. The strings consist only of lucky digits. Petya can perform operations of two types: * replace any one digit from string a by its opposite (i.e., replace 4 by 7 and 7 by 4); * swap any pair of digits in string a. Petya is interested in the minimum number of operations that are needed to make string a equal to string b. Help him with the task. Input The first and the second line contains strings a and b, correspondingly. Strings a and b have equal lengths and contain only lucky digits. The strings are not empty, their length does not exceed 105. Output Print on the single line the single number β€” the minimum number of operations needed to convert string a into string b. Examples Input 47 74 Output 1 Input 774 744 Output 1 Input 777 444 Output 3 Note In the first sample it is enough simply to swap the first and the second digit. In the second sample we should replace the second digit with its opposite. In the third number we should replace all three digits with their opposites.
instruction
0
13,523
20
27,046
Tags: greedy, implementation Correct Solution: ``` import sys read=sys.stdin.buffer.readline mi=lambda:map(int,read().split()) li=lambda:list(mi()) cin=lambda:int(read()) a=input() b=input() d={'4':0,'7':0} for i in range(len(a)): if a[i]!=b[i]: d[b[i]]+=1 print(max(d['4'],d['7'])) ```
output
1
13,523
20
27,047
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 has two strings a and b of the same length n. The strings consist only of lucky digits. Petya can perform operations of two types: * replace any one digit from string a by its opposite (i.e., replace 4 by 7 and 7 by 4); * swap any pair of digits in string a. Petya is interested in the minimum number of operations that are needed to make string a equal to string b. Help him with the task. Input The first and the second line contains strings a and b, correspondingly. Strings a and b have equal lengths and contain only lucky digits. The strings are not empty, their length does not exceed 105. Output Print on the single line the single number β€” the minimum number of operations needed to convert string a into string b. Examples Input 47 74 Output 1 Input 774 744 Output 1 Input 777 444 Output 3 Note In the first sample it is enough simply to swap the first and the second digit. In the second sample we should replace the second digit with its opposite. In the third number we should replace all three digits with their opposites. Submitted Solution: ``` def solve(s1,s2): x,y = 0,0 for i in range(len(s1)): if s1[i] == '4' and s2[i] == '7': x += 1 elif s1[i] == '7' and s2[i] == '4': y += 1 print(max(x,y)) s1,s2 = input(),input() if __name__ == '__main__': solve(s1,s2) ```
instruction
0
13,524
20
27,048
Yes
output
1
13,524
20
27,049
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 has two strings a and b of the same length n. The strings consist only of lucky digits. Petya can perform operations of two types: * replace any one digit from string a by its opposite (i.e., replace 4 by 7 and 7 by 4); * swap any pair of digits in string a. Petya is interested in the minimum number of operations that are needed to make string a equal to string b. Help him with the task. Input The first and the second line contains strings a and b, correspondingly. Strings a and b have equal lengths and contain only lucky digits. The strings are not empty, their length does not exceed 105. Output Print on the single line the single number β€” the minimum number of operations needed to convert string a into string b. Examples Input 47 74 Output 1 Input 774 744 Output 1 Input 777 444 Output 3 Note In the first sample it is enough simply to swap the first and the second digit. In the second sample we should replace the second digit with its opposite. In the third number we should replace all three digits with their opposites. Submitted Solution: ``` a=input() b=input() da={'4':0,'7':0} db={'4':0,'7':0} for i in a: da[i]+=1 for i in b: db[i]+=1 dif=0 for i in range(len(a)): if(a[i]!=b[i]): dif+=1 ans=0 if(da==db): ans=dif//2 else: x=abs(da['4']-db['4']) ans+=x dif-=x ans+=(dif//2) print(ans) ```
instruction
0
13,525
20
27,050
Yes
output
1
13,525
20
27,051
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 has two strings a and b of the same length n. The strings consist only of lucky digits. Petya can perform operations of two types: * replace any one digit from string a by its opposite (i.e., replace 4 by 7 and 7 by 4); * swap any pair of digits in string a. Petya is interested in the minimum number of operations that are needed to make string a equal to string b. Help him with the task. Input The first and the second line contains strings a and b, correspondingly. Strings a and b have equal lengths and contain only lucky digits. The strings are not empty, their length does not exceed 105. Output Print on the single line the single number β€” the minimum number of operations needed to convert string a into string b. Examples Input 47 74 Output 1 Input 774 744 Output 1 Input 777 444 Output 3 Note In the first sample it is enough simply to swap the first and the second digit. In the second sample we should replace the second digit with its opposite. In the third number we should replace all three digits with their opposites. Submitted Solution: ``` a=input() b=input() count4=0 count7=0 for i in range(0,len(a)): if a[i]!=b[i]: if ord(a[i])-48 == 4: count4+=1 else: count7+=1 print(abs(count4-count7)+min(count4,count7)) ```
instruction
0
13,526
20
27,052
Yes
output
1
13,526
20
27,053
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 has two strings a and b of the same length n. The strings consist only of lucky digits. Petya can perform operations of two types: * replace any one digit from string a by its opposite (i.e., replace 4 by 7 and 7 by 4); * swap any pair of digits in string a. Petya is interested in the minimum number of operations that are needed to make string a equal to string b. Help him with the task. Input The first and the second line contains strings a and b, correspondingly. Strings a and b have equal lengths and contain only lucky digits. The strings are not empty, their length does not exceed 105. Output Print on the single line the single number β€” the minimum number of operations needed to convert string a into string b. Examples Input 47 74 Output 1 Input 774 744 Output 1 Input 777 444 Output 3 Note In the first sample it is enough simply to swap the first and the second digit. In the second sample we should replace the second digit with its opposite. In the third number we should replace all three digits with their opposites. Submitted Solution: ``` a = input() b = input() l = len(a) d = {'4':0,'7':0} for i in range(l): if a[i] != b[i]: d[a[i]] += 1 vals = d.values() print(min(vals) + (max(vals)-min(vals))) ```
instruction
0
13,527
20
27,054
Yes
output
1
13,527
20
27,055
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 has two strings a and b of the same length n. The strings consist only of lucky digits. Petya can perform operations of two types: * replace any one digit from string a by its opposite (i.e., replace 4 by 7 and 7 by 4); * swap any pair of digits in string a. Petya is interested in the minimum number of operations that are needed to make string a equal to string b. Help him with the task. Input The first and the second line contains strings a and b, correspondingly. Strings a and b have equal lengths and contain only lucky digits. The strings are not empty, their length does not exceed 105. Output Print on the single line the single number β€” the minimum number of operations needed to convert string a into string b. Examples Input 47 74 Output 1 Input 774 744 Output 1 Input 777 444 Output 3 Note In the first sample it is enough simply to swap the first and the second digit. In the second sample we should replace the second digit with its opposite. In the third number we should replace all three digits with their opposites. Submitted Solution: ``` a=input() b=input() l1=list(a) l2=list(b) l3=[] for i in range(len(l1)): if(l1[i]!=l2[i]): l3.append(i) i=0 sum1=0 while(i<len(l3)-1): if((l3[i+1]-l3[i])==1): if(l1[l3[i]]==l1[l3[i+1]]): l1[l3[i]]=l2[l3[i]] sum1=sum1+1 i=i+1 else: l1[l3[i]]=l2[l3[i]] l1[l3[i+1]]=l2[l3[i+1]] sum1=sum1+1 i=i+2 else: l1[l3[i]]=l2[l3[i]] sum1=sum1+1 i=i+1 if(l1[l3[len(l3)-1]] != l2[l3[len(l3)-1]]): sum1=sum1+1 print(sum1) ```
instruction
0
13,528
20
27,056
No
output
1
13,528
20
27,057
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 has two strings a and b of the same length n. The strings consist only of lucky digits. Petya can perform operations of two types: * replace any one digit from string a by its opposite (i.e., replace 4 by 7 and 7 by 4); * swap any pair of digits in string a. Petya is interested in the minimum number of operations that are needed to make string a equal to string b. Help him with the task. Input The first and the second line contains strings a and b, correspondingly. Strings a and b have equal lengths and contain only lucky digits. The strings are not empty, their length does not exceed 105. Output Print on the single line the single number β€” the minimum number of operations needed to convert string a into string b. Examples Input 47 74 Output 1 Input 774 744 Output 1 Input 777 444 Output 3 Note In the first sample it is enough simply to swap the first and the second digit. In the second sample we should replace the second digit with its opposite. In the third number we should replace all three digits with their opposites. Submitted Solution: ``` def question3(): A = list(input()) B = list(input()) count = 0 for i in range(len(A)): if i != len(A) - 1 : if A[i] != B[i]: if A[i+1] != B[i+1] and A[i] != B[i]: count += 1 A[i],A[i+1] = A[i+1],A[i] else: count += 1 A[i] = B[i] else: if A[i] != B[i]: count += 1 A[i] = B[i] return count remained_test_cases = 1 while remained_test_cases > 0: print(question3()) remained_test_cases -= 1 ```
instruction
0
13,529
20
27,058
No
output
1
13,529
20
27,059
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 has two strings a and b of the same length n. The strings consist only of lucky digits. Petya can perform operations of two types: * replace any one digit from string a by its opposite (i.e., replace 4 by 7 and 7 by 4); * swap any pair of digits in string a. Petya is interested in the minimum number of operations that are needed to make string a equal to string b. Help him with the task. Input The first and the second line contains strings a and b, correspondingly. Strings a and b have equal lengths and contain only lucky digits. The strings are not empty, their length does not exceed 105. Output Print on the single line the single number β€” the minimum number of operations needed to convert string a into string b. Examples Input 47 74 Output 1 Input 774 744 Output 1 Input 777 444 Output 3 Note In the first sample it is enough simply to swap the first and the second digit. In the second sample we should replace the second digit with its opposite. In the third number we should replace all three digits with their opposites. Submitted Solution: ``` def question3(): A = list(input()) B = list(input()) count = 0 for i in range(len(A)): if i != len(A) - 1 : if A[i] != B[i]: if A[i+1] != B[i+1] and A[i] != A[i+1]: count += 1 A[i],A[i+1] = A[i+1],A[i] else: count += 1 A[i] = B[i] else: if A[i] != B[i]: count += 1 A[i] = B[i] # print("a ",A) return count remained_test_cases = 1 while remained_test_cases > 0: print(question3()) remained_test_cases -= 1 ```
instruction
0
13,530
20
27,060
No
output
1
13,530
20
27,061
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 has two strings a and b of the same length n. The strings consist only of lucky digits. Petya can perform operations of two types: * replace any one digit from string a by its opposite (i.e., replace 4 by 7 and 7 by 4); * swap any pair of digits in string a. Petya is interested in the minimum number of operations that are needed to make string a equal to string b. Help him with the task. Input The first and the second line contains strings a and b, correspondingly. Strings a and b have equal lengths and contain only lucky digits. The strings are not empty, their length does not exceed 105. Output Print on the single line the single number β€” the minimum number of operations needed to convert string a into string b. Examples Input 47 74 Output 1 Input 774 744 Output 1 Input 777 444 Output 3 Note In the first sample it is enough simply to swap the first and the second digit. In the second sample we should replace the second digit with its opposite. In the third number we should replace all three digits with their opposites. Submitted Solution: ``` from collections import * a, b = [list(input()) for i in range(2)] ans, d4, d7 = 0, deque([]), deque([]) for i in range(len(a)): if a[i] != b[i]: if a[i] == '4': d4.append(i) else: d7.append(i) for i in range(len(a)): if a[i] != b[i]: if a[i] == '4' and d7: a[i], a[d7[0]] = a[d7[0]], a[i] d7.popleft() elif a[i] == '7' and d4: a[i], a[d4[0]] = a[d4[0]], a[i] d4.popleft() ans += 1 print(ans) ```
instruction
0
13,531
20
27,062
No
output
1
13,531
20
27,063
Provide tags and a correct Python 3 solution for this coding contest problem. One day, after a difficult lecture a diligent student Sasha saw a graffitied desk in the classroom. She came closer and read: "Find such positive integer n, that among numbers n + 1, n + 2, ..., 2Β·n there are exactly m numbers which binary representation contains exactly k digits one". The girl got interested in the task and she asked you to help her solve it. Sasha knows that you are afraid of large numbers, so she guaranteed that there is an answer that doesn't exceed 1018. Input The first line contains two space-separated integers, m and k (0 ≀ m ≀ 1018; 1 ≀ k ≀ 64). Output Print the required number n (1 ≀ n ≀ 1018). If there are multiple answers, print any of them. Examples Input 1 1 Output 1 Input 3 2 Output 5
instruction
0
13,641
20
27,282
Tags: binary search, bitmasks, combinatorics, dp, math Correct Solution: ``` import sys def b(n): c = 0 while n: if n & 1: c += 1 n //= 2 return c c = {} def f(n, k): if (n, k) in c.keys(): return c[(n, k)] if n == 1: return 1 if k == 1 else 0 c[(n, k)] = f(n // 2, k) + f(n // 2, k - 1) + int(n & 1 and b(n // 2) == k - 1) return c[(n, k)] m, k = map(int, input().split()) hi = int(1e18) lo = 1 while (hi - lo >= 0): mid = (lo + hi) // 2 val = f(mid, k) if val == m: print(mid) sys.exit() elif val < m: lo = mid + 1 else: hi = mid - 1 ```
output
1
13,641
20
27,283
Provide tags and a correct Python 3 solution for this coding contest problem. One day, after a difficult lecture a diligent student Sasha saw a graffitied desk in the classroom. She came closer and read: "Find such positive integer n, that among numbers n + 1, n + 2, ..., 2Β·n there are exactly m numbers which binary representation contains exactly k digits one". The girl got interested in the task and she asked you to help her solve it. Sasha knows that you are afraid of large numbers, so she guaranteed that there is an answer that doesn't exceed 1018. Input The first line contains two space-separated integers, m and k (0 ≀ m ≀ 1018; 1 ≀ k ≀ 64). Output Print the required number n (1 ≀ n ≀ 1018). If there are multiple answers, print any of them. Examples Input 1 1 Output 1 Input 3 2 Output 5
instruction
0
13,642
20
27,284
Tags: binary search, bitmasks, combinatorics, dp, math Correct Solution: ``` MX_BIT = 64 C = [[int(0) for i in range(MX_BIT)] for j in range(MX_BIT)] def ck(x, i): return (x>>i) & 1 def tot_bits(x): x = bin(x)[2:] return len(x) def mkt(): C[0][0] = 1 for i in range (1, MX_BIT): for j in range (i+1): C[i][j] = C[i-1][j] + (C[i-1][j-1] if j else 0) def solve(x, k): a = 0 for i in reversed(range(MX_BIT)): if ck(x, i) != 0: a += C[i][k] k -= 1 if k == 0: break return a mkt() m, k = list(input().split()) m = int(m) k = int(k) l = 1 r = 1e18 if not m: l = 1 else: while l < r: mid = int((l + r) // 2) if (solve(2*mid, k) - solve(mid, k)) < m : l = mid + 1 else: r = mid print(l) ```
output
1
13,642
20
27,285
Provide tags and a correct Python 3 solution for this coding contest problem. One day, after a difficult lecture a diligent student Sasha saw a graffitied desk in the classroom. She came closer and read: "Find such positive integer n, that among numbers n + 1, n + 2, ..., 2Β·n there are exactly m numbers which binary representation contains exactly k digits one". The girl got interested in the task and she asked you to help her solve it. Sasha knows that you are afraid of large numbers, so she guaranteed that there is an answer that doesn't exceed 1018. Input The first line contains two space-separated integers, m and k (0 ≀ m ≀ 1018; 1 ≀ k ≀ 64). Output Print the required number n (1 ≀ n ≀ 1018). If there are multiple answers, print any of them. Examples Input 1 1 Output 1 Input 3 2 Output 5
instruction
0
13,643
20
27,286
Tags: binary search, bitmasks, combinatorics, dp, math Correct Solution: ``` def dfs(n, k, cache = {}): # if number of bits is bigger than the number's bits of the number's bits is less than 0 if k > n or k < 0: return 0 # if num bits is 0 or num bits is equivalent to the number's bits if k == 0 or k == n: return 1 # # if k*2 > n: k = n-k # Check is already calculated if (n, k) in cache: return cache[(n, k)] # Use dfs addition for case where certain bit is 1 or certain bit is 0 z = cache[(n, k)] = dfs(n-1, k-1) + dfs(n-1, k) return z def bits(n): b = 0 while n: if n&1: b += 1 n >>= 1 return b def count(n, k): z, b, c = 0, 63, 0 for b in reversed(range(64)): # Taking n and checking if bit is 1 or not if (n>>b)&1: z += dfs(b, k-c) c += 1 if not k: break return z + (bits(n) == k) def solve(m, k): # Binary Search for number 1-10^18 low, high = 1, 10**18 while low < high: mid = (low+high)//2 if count(2*mid, k) - count(mid, k) < m: low = mid+1 else: high = mid return high m, k = [int(x) for x in input().split()] print(solve(m, k)) ```
output
1
13,643
20
27,287
Provide tags and a correct Python 3 solution for this coding contest problem. One day, after a difficult lecture a diligent student Sasha saw a graffitied desk in the classroom. She came closer and read: "Find such positive integer n, that among numbers n + 1, n + 2, ..., 2Β·n there are exactly m numbers which binary representation contains exactly k digits one". The girl got interested in the task and she asked you to help her solve it. Sasha knows that you are afraid of large numbers, so she guaranteed that there is an answer that doesn't exceed 1018. Input The first line contains two space-separated integers, m and k (0 ≀ m ≀ 1018; 1 ≀ k ≀ 64). Output Print the required number n (1 ≀ n ≀ 1018). If there are multiple answers, print any of them. Examples Input 1 1 Output 1 Input 3 2 Output 5
instruction
0
13,644
20
27,288
Tags: binary search, bitmasks, combinatorics, dp, math Correct Solution: ``` N = 70 C = [[0 for _ in range(N)] for _ in range(N)] for i in range(N): C[i][0] = C[i][i] = 1 for j in range(1, i): C[i][j] = C[i - 1][j - 1] + C[i - 1][j] l, r = 1, int(1e19) m, k = [int(x) for x in input().split(' ')] k -= 1 def ok(x: int): s = bin(x)[2:] s = s[::-1] t = k ans = 0 for i in range(len(s) - 1, -1, -1): if s[i] == "1": ans += C[i][t] t -= 1 if t < 0: break return ans >= m while l < r: mid = (l + r) >> 1 if ok(mid): r = mid else: l = mid + 1 print(l) ```
output
1
13,644
20
27,289
Provide tags and a correct Python 3 solution for this coding contest problem. One day, after a difficult lecture a diligent student Sasha saw a graffitied desk in the classroom. She came closer and read: "Find such positive integer n, that among numbers n + 1, n + 2, ..., 2Β·n there are exactly m numbers which binary representation contains exactly k digits one". The girl got interested in the task and she asked you to help her solve it. Sasha knows that you are afraid of large numbers, so she guaranteed that there is an answer that doesn't exceed 1018. Input The first line contains two space-separated integers, m and k (0 ≀ m ≀ 1018; 1 ≀ k ≀ 64). Output Print the required number n (1 ≀ n ≀ 1018). If there are multiple answers, print any of them. Examples Input 1 1 Output 1 Input 3 2 Output 5
instruction
0
13,645
20
27,290
Tags: binary search, bitmasks, combinatorics, dp, math Correct Solution: ``` comb = [[0 for i in range(67)] for j in range(67)] for i in range(67): comb[i][0], comb[i][i] = 1, 1 for j in range(1, i): comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j] def calc(x): cnt = 0 digit = [] while (x > 0): digit.append(x % 2) x //= 2 cnt += 1 ans, one = 0, 0 for i in reversed(range(cnt)): if (digit[i] == 1): if (k - one >= 0): ans += comb[i][k - one] one += 1 return ans m, k = map(int, input().split()) lcur, rcur = 0, 2 ** 64 while (lcur + 2 <= rcur): mid = (lcur + rcur) // 2 if (calc(mid * 2) - calc(mid) < m): lcur = mid else: rcur = mid print(rcur) ```
output
1
13,645
20
27,291
Provide tags and a correct Python 3 solution for this coding contest problem. One day, after a difficult lecture a diligent student Sasha saw a graffitied desk in the classroom. She came closer and read: "Find such positive integer n, that among numbers n + 1, n + 2, ..., 2Β·n there are exactly m numbers which binary representation contains exactly k digits one". The girl got interested in the task and she asked you to help her solve it. Sasha knows that you are afraid of large numbers, so she guaranteed that there is an answer that doesn't exceed 1018. Input The first line contains two space-separated integers, m and k (0 ≀ m ≀ 1018; 1 ≀ k ≀ 64). Output Print the required number n (1 ≀ n ≀ 1018). If there are multiple answers, print any of them. Examples Input 1 1 Output 1 Input 3 2 Output 5
instruction
0
13,646
20
27,292
Tags: binary search, bitmasks, combinatorics, dp, math Correct Solution: ``` def dfs(n, k, cache = {}): # if number of bits is bigger than the number's bits of the number's bits is less than 0 if k > n or k < 0: return 0 # if num bits is 0 or num bits is equivalent to the number's bits if k == 0 or k == n: return 1 if k*2 > n: k = n-k # Check is already calculated if (n, k) in cache: return cache[(n, k)] # Use dfs addition for case where certain bit is 1 or certain bit is 0 z = cache[(n, k)] = dfs(n-1, k-1) + dfs(n-1, k) return z def bits(n): b = 0 while n: if n&1: b += 1 n >>= 1 return b def count(n, k): z, b, c = 0, 63, 0 for b in reversed(range(64)): # Taking n and checking if bit is 1 or not if (n>>b)&1: z += dfs(b, k-c) c += 1 if not k: break return z + (bits(n) == k) def solve(m, k): # Binary Search for number 1-10^18 low, high = 1, 10**18 while low < high: mid = (low+high)//2 if count(2*mid, k) - count(mid, k) < m: low = mid+1 else: high = mid return high m, k = [int(x) for x in input().split()] print(solve(m, k)) ```
output
1
13,646
20
27,293
Provide tags and a correct Python 3 solution for this coding contest problem. One day, after a difficult lecture a diligent student Sasha saw a graffitied desk in the classroom. She came closer and read: "Find such positive integer n, that among numbers n + 1, n + 2, ..., 2Β·n there are exactly m numbers which binary representation contains exactly k digits one". The girl got interested in the task and she asked you to help her solve it. Sasha knows that you are afraid of large numbers, so she guaranteed that there is an answer that doesn't exceed 1018. Input The first line contains two space-separated integers, m and k (0 ≀ m ≀ 1018; 1 ≀ k ≀ 64). Output Print the required number n (1 ≀ n ≀ 1018). If there are multiple answers, print any of them. Examples Input 1 1 Output 1 Input 3 2 Output 5
instruction
0
13,647
20
27,294
Tags: binary search, bitmasks, combinatorics, dp, math Correct Solution: ``` def dfs(n, k, cache = {}): # if number of bits is bigger than the number's bits of the number's bits is less than 0 if k > n or k < 0: return 0 # if num bits is 0 or num bits is equivalent to the number's bits if k == 0 or k == n: return 1 # This optimization is not necessary but flips the 0s and the 1s # if k*2 > n: k = n-k # Check is already calculated if (n, k) in cache: return cache[(n, k)] # Use dfs addition for case where certain bit is 1 or certain bit is 0 z = cache[(n, k)] = dfs(n-1, k-1) + dfs(n-1, k) return z def bits(n): b = 0 while n: if n&1: b += 1 n >>= 1 return b def count(n, k): z, b, c = 0, 63, 0 for b in reversed(range(64)): # Taking n and checking if certain bit is 1 or not # This sums for every mod power of 2 that exists to account for every case if (n>>b)&1: # calculates by subtracting for bits not accounted for z += dfs(b, k-c) c += 1 # if not k: break return z + (bits(n) == k) def solve(m, k): # Binary Search for number 1-10^18 low, high = 1, 10**18 while low < high: mid = (low+high)//2 if count(2*mid, k) - count(mid, k) < m: low = mid+1 else: high = mid return high m, k = [int(x) for x in input().split()] print(solve(m, k)) ```
output
1
13,647
20
27,295
Provide tags and a correct Python 3 solution for this coding contest problem. One day, after a difficult lecture a diligent student Sasha saw a graffitied desk in the classroom. She came closer and read: "Find such positive integer n, that among numbers n + 1, n + 2, ..., 2Β·n there are exactly m numbers which binary representation contains exactly k digits one". The girl got interested in the task and she asked you to help her solve it. Sasha knows that you are afraid of large numbers, so she guaranteed that there is an answer that doesn't exceed 1018. Input The first line contains two space-separated integers, m and k (0 ≀ m ≀ 1018; 1 ≀ k ≀ 64). Output Print the required number n (1 ≀ n ≀ 1018). If there are multiple answers, print any of them. Examples Input 1 1 Output 1 Input 3 2 Output 5
instruction
0
13,648
20
27,296
Tags: binary search, bitmasks, combinatorics, dp, math Correct Solution: ``` def nck(n, k, cache = {}): if k > n or k < 0: return 0 if k == 0 or k == n: return 1 if k*2 > n: k = n-k if (n, k) in cache: return cache[(n, k)] z = cache[(n, k)] = nck(n-1, k-1) + nck(n-1, k) return z def bits(n): b = 0 while n: if n&1: b += 1 n >>= 1 return b def count(n, k): z, b, c = 0, 63, 0 for b in reversed(range(64)): if (n>>b)&1: z += nck(b, k-c) c += 1 if not k: break return z + (bits(n) == k) def solve(m, k): lo, hi = 1, 10**18 while lo < hi: mi = (lo+hi)//2 if count(2*mi, k) - count(mi, k) < m: lo = mi+1 else: hi = mi return hi m, k = [int(x) for x in input().split()] print(solve(m, k)) ```
output
1
13,648
20
27,297
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day, after a difficult lecture a diligent student Sasha saw a graffitied desk in the classroom. She came closer and read: "Find such positive integer n, that among numbers n + 1, n + 2, ..., 2Β·n there are exactly m numbers which binary representation contains exactly k digits one". The girl got interested in the task and she asked you to help her solve it. Sasha knows that you are afraid of large numbers, so she guaranteed that there is an answer that doesn't exceed 1018. Input The first line contains two space-separated integers, m and k (0 ≀ m ≀ 1018; 1 ≀ k ≀ 64). Output Print the required number n (1 ≀ n ≀ 1018). If there are multiple answers, print any of them. Examples Input 1 1 Output 1 Input 3 2 Output 5 Submitted Solution: ``` from math import factorial as f def C(n, m): if n < m: return 0 return f(n) // ( f(n - m ) * f(m) ) m, k = map(int, input().split()) ans = 1 for bit in reversed(range(65)): if k == 0: break if C(bit, k - 1) < m: ans += ( 1 << bit ) m -= C(bit, k - 1) k -= 1 print(ans) ```
instruction
0
13,649
20
27,298
Yes
output
1
13,649
20
27,299
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day, after a difficult lecture a diligent student Sasha saw a graffitied desk in the classroom. She came closer and read: "Find such positive integer n, that among numbers n + 1, n + 2, ..., 2Β·n there are exactly m numbers which binary representation contains exactly k digits one". The girl got interested in the task and she asked you to help her solve it. Sasha knows that you are afraid of large numbers, so she guaranteed that there is an answer that doesn't exceed 1018. Input The first line contains two space-separated integers, m and k (0 ≀ m ≀ 1018; 1 ≀ k ≀ 64). Output Print the required number n (1 ≀ n ≀ 1018). If there are multiple answers, print any of them. Examples Input 1 1 Output 1 Input 3 2 Output 5 Submitted Solution: ``` def dfs(n, k, cache = {}): # if number of bits is bigger than the number's bits of the number's bits is less than 0 if k > n or k < 0: return 0 # if num bits is 0 or num bits is equivalent to the number's bits if k == 0 or k == n: return 1 # This optimization is not necessary but flips the 0s and the 1s # if k*2 > n: k = n-k # Check is already calculated if (n, k) in cache: return cache[(n, k)] # Use dfs addition for case where certain bit is 1 or certain bit is 0 z = cache[(n, k)] = dfs(n-1, k-1) + dfs(n-1, k) return z def bits(n): # counts number of 1s in the number b = 0 while n: if n & 1: b += 1 n >>= 1 return b def count(n, k): z, b, c = 0, 63, 0 for b in reversed(range(64)): # Taking n and checking if certain bit is 1 or not # This sums for every mod power of 2 that exists to account for every case if (n>>b)&1: # calculates by subtracting for bits not accounted for z += dfs(b, k-c) c += 1 # Unnecessary code # if not k: break # if original number has same number of 1s as digits required, add 1 return z + (bits(n) == k) def solve(m, k): # Binary Search for number 1-10^18 low, high = 1, 10**18 while low < high: mid = (low+high)//2 if count(2*mid, k) - count(mid, k) < m: low = mid+1 else: high = mid return high m, k = [int(x) for x in input().split()] print(solve(m, k)) ```
instruction
0
13,650
20
27,300
Yes
output
1
13,650
20
27,301
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day, after a difficult lecture a diligent student Sasha saw a graffitied desk in the classroom. She came closer and read: "Find such positive integer n, that among numbers n + 1, n + 2, ..., 2Β·n there are exactly m numbers which binary representation contains exactly k digits one". The girl got interested in the task and she asked you to help her solve it. Sasha knows that you are afraid of large numbers, so she guaranteed that there is an answer that doesn't exceed 1018. Input The first line contains two space-separated integers, m and k (0 ≀ m ≀ 1018; 1 ≀ k ≀ 64). Output Print the required number n (1 ≀ n ≀ 1018). If there are multiple answers, print any of them. Examples Input 1 1 Output 1 Input 3 2 Output 5 Submitted Solution: ``` dp = dict() def cnt(n, k): if k < 0: return 0 if n == 0: if k == 0: return 1 else: return 0 else: if (n, k) in dp.keys(): return dp[(n, k)] else: dp[(n, k)] = cnt(n//2, k) + cnt(n//2, k-1) return dp[(n, k)] m, k = map(int, input().split()) lo = 1 hi = 10**18 ans = -1 while lo <= hi: mid = (lo+hi)//2 if cnt(2 * mid, k) - cnt(mid, k) > m: hi = mid - 1 elif cnt(2 * mid, k) - cnt(mid, k) == m: ans = mid break else: lo = mid + 1 print(ans) ```
instruction
0
13,651
20
27,302
No
output
1
13,651
20
27,303
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day, after a difficult lecture a diligent student Sasha saw a graffitied desk in the classroom. She came closer and read: "Find such positive integer n, that among numbers n + 1, n + 2, ..., 2Β·n there are exactly m numbers which binary representation contains exactly k digits one". The girl got interested in the task and she asked you to help her solve it. Sasha knows that you are afraid of large numbers, so she guaranteed that there is an answer that doesn't exceed 1018. Input The first line contains two space-separated integers, m and k (0 ≀ m ≀ 1018; 1 ≀ k ≀ 64). Output Print the required number n (1 ≀ n ≀ 1018). If there are multiple answers, print any of them. Examples Input 1 1 Output 1 Input 3 2 Output 5 Submitted Solution: ``` #!/usr/bin/python import math m, k = map(int, input().strip(' ').split(' ')) def solve(x): ans = 0 tot = 0 for i in reversed(range(1, int(math.log2(x)+1))): if x & (1 << i): ans += math.comb(i, k-tot) tot += 1 if tot > k: return ans return ans def judge(x): return solve(x*2)-solve(x) >= m l, r = 1, 2 while not judge(r): l, r = r, r*2 ans = -1 while l <= r: mid = (l+r) >> 1 if judge(mid): ans, r = mid, mid-1 else: l = mid+1 print(ans) ```
instruction
0
13,652
20
27,304
No
output
1
13,652
20
27,305
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day, after a difficult lecture a diligent student Sasha saw a graffitied desk in the classroom. She came closer and read: "Find such positive integer n, that among numbers n + 1, n + 2, ..., 2Β·n there are exactly m numbers which binary representation contains exactly k digits one". The girl got interested in the task and she asked you to help her solve it. Sasha knows that you are afraid of large numbers, so she guaranteed that there is an answer that doesn't exceed 1018. Input The first line contains two space-separated integers, m and k (0 ≀ m ≀ 1018; 1 ≀ k ≀ 64). Output Print the required number n (1 ≀ n ≀ 1018). If there are multiple answers, print any of them. Examples Input 1 1 Output 1 Input 3 2 Output 5 Submitted Solution: ``` import math n = input() n = n.split(" ") t = [int(i) for i in n] m = t[0] k = t[1] l = m r = 2*m+1 def check(inp): s = bin(int(inp)) s = s[2:] num = int(s) ans = 0 while num >= 1 : ans = ans + num%10 num = num / 10 return int(ans) while l < r: mid = (l+r)/2; if check(mid) == int(k): print(int(mid)) break elif check(mid) < k: l = mid + 1 else: r = mid - 1 ```
instruction
0
13,653
20
27,306
No
output
1
13,653
20
27,307
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day, after a difficult lecture a diligent student Sasha saw a graffitied desk in the classroom. She came closer and read: "Find such positive integer n, that among numbers n + 1, n + 2, ..., 2Β·n there are exactly m numbers which binary representation contains exactly k digits one". The girl got interested in the task and she asked you to help her solve it. Sasha knows that you are afraid of large numbers, so she guaranteed that there is an answer that doesn't exceed 1018. Input The first line contains two space-separated integers, m and k (0 ≀ m ≀ 1018; 1 ≀ k ≀ 64). Output Print the required number n (1 ≀ n ≀ 1018). If there are multiple answers, print any of them. Examples Input 1 1 Output 1 Input 3 2 Output 5 Submitted Solution: ``` #!/usr/bin/python import math m, k = map(int, input().strip(' ').split(' ')) def solve(x): ans = 0 tot = 0 for i in reversed(range(1, int(math.log2(x)+1))): if x & (1 << i): ans += math.comb(i, k-tot) tot += 1 if tot == k: return ans return ans l, r = 1, 2**(k+2) ans = -1 while l <= r: mid = (l+r) >> 1 if solve(mid*2)-solve(mid) >= m: ans = mid r = mid-1 else: l = mid+1 print(ans) ```
instruction
0
13,654
20
27,308
No
output
1
13,654
20
27,309
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Problem statement Cards with ranks of $ 2 $ and $ 8 $ are powerful in card game millionaires. Therefore, we call an integer consisting of only the numbers $ 2 $ and $ 8 $ in $ 10 $ decimal notation a good integer. The best integers are listed from the smallest to $ 2, 8, 22, 28, 82, 88, \ cdots $. Let $ n $ be a positive integer. When $ n $ can be expressed in the form of a product of good integers, find the maximum product. If you can't, output $ -1 $. Constraint $ 1 \ leq n \ leq 10 ^ {18} $ sample Sample input 1 1 Sample output 1 -1 Sample input 2 2 Sample output 2 1 Sample input 3 88 Sample output 3 3 It can be expressed as $ 2 \ times 2 \ times 22 $. Sample input 4 100 Sample output 4 -1 Sample input 5 173553147234869248 Sample output 5 11 It can be expressed as $ 2 ^ 6 \ times 28 \ times 2222 ^ 3 \ times 8828 $. input $ n $ output Print the answer on the $ 1 $ line. Example Input 1 Output -1 Submitted Solution: ``` N = int(input()) goods = ["2", "8"] for i in range(9): goods += ["2" + g for g in goods] + ["8" + g for g in goods] goods = list(map(int, goods)) del goods[1] def isgood(n): for c in str(n): if(c != '2' and c != '8'): return False return True def ma(n, mi, nowma): if(n == 1): return 0 if(n % 2 != 0): return -1 mama = int(n**(1 / nowma)) g = 2 i = mi mamama = -1 if(isgood(n)): mamama = 1 while(g < mama + 3): if(n % g == 0): k = n // g newnowma = 2 if(mamama > 2): newnowma = mamama if(newnowma < nowma - 1): newnowma = nowma - 1 tma = ma(k, i, newnowma) t = tma + 1 if tma != -1 else -1 if(t > mamama): mamama = t i += 1 g = goods[i] # print(g) return mamama if(N == 1): print(-1) else: print(ma(N, 0, 2)) ```
instruction
0
14,107
20
28,214
No
output
1
14,107
20
28,215
Provide tags and a correct Python 3 solution for this coding contest problem. Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya and his friend Vasya play an interesting game. Petya randomly chooses an integer p from the interval [pl, pr] and Vasya chooses an integer v from the interval [vl, vr] (also randomly). Both players choose their integers equiprobably. Find the probability that the interval [min(v, p), max(v, p)] contains exactly k lucky numbers. Input The single line contains five integers pl, pr, vl, vr and k (1 ≀ pl ≀ pr ≀ 109, 1 ≀ vl ≀ vr ≀ 109, 1 ≀ k ≀ 1000). Output On the single line print the result with an absolute error of no more than 10 - 9. Examples Input 1 10 1 10 2 Output 0.320000000000 Input 5 6 8 10 1 Output 1.000000000000 Note Consider that [a, b] denotes an interval of integers; this interval includes the boundaries. That is, <image> In first case there are 32 suitable pairs: (1, 7), (1, 8), (1, 9), (1, 10), (2, 7), (2, 8), (2, 9), (2, 10), (3, 7), (3, 8), (3, 9), (3, 10), (4, 7), (4, 8), (4, 9), (4, 10), (7, 1), (7, 2), (7, 3), (7, 4), (8, 1), (8, 2), (8, 3), (8, 4), (9, 1), (9, 2), (9, 3), (9, 4), (10, 1), (10, 2), (10, 3), (10, 4). Total number of possible pairs is 10Β·10 = 100, so answer is 32 / 100. In second case Petya always get number less than Vasya and the only lucky 7 is between this numbers, so there will be always 1 lucky number.
instruction
0
14,186
20
28,372
Tags: brute force, probabilities Correct Solution: ``` s = list() def rec(x): if x > 100000000000: return s.append(x) rec(x * 10 + 4) rec(x * 10 + 7) def f(l1, r1, l2, r2): l1 = max(l1, l2) r1 = min(r1, r2) return max(r1 - l1 + 1, 0) def main(): rec(0) s.sort() args = input().split() pl, pr, vl, vr, k = int(args[0]), int(args[1]), int(args[2]), int(args[3]), int(args[4]) ans = 0 i = 1 while i + k < len(s): l1 = s[i - 1] + 1 r1 = s[i] l2 = s[i + k - 1] r2 = s[i + k] - 1 a = f(l1, r1, vl, vr) * f(l2, r2, pl, pr) b = f(l1, r1, pl, pr) * f(l2, r2, vl, vr) ans += a + b if k == 1 and a > 0 and b > 0: ans -= 1 i += 1 all = (pr - pl + 1) * (vr - vl + 1) print(1.0 * ans / all) if __name__ == '__main__': main() ```
output
1
14,186
20
28,373
Provide tags and a correct Python 3 solution for this coding contest problem. Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya and his friend Vasya play an interesting game. Petya randomly chooses an integer p from the interval [pl, pr] and Vasya chooses an integer v from the interval [vl, vr] (also randomly). Both players choose their integers equiprobably. Find the probability that the interval [min(v, p), max(v, p)] contains exactly k lucky numbers. Input The single line contains five integers pl, pr, vl, vr and k (1 ≀ pl ≀ pr ≀ 109, 1 ≀ vl ≀ vr ≀ 109, 1 ≀ k ≀ 1000). Output On the single line print the result with an absolute error of no more than 10 - 9. Examples Input 1 10 1 10 2 Output 0.320000000000 Input 5 6 8 10 1 Output 1.000000000000 Note Consider that [a, b] denotes an interval of integers; this interval includes the boundaries. That is, <image> In first case there are 32 suitable pairs: (1, 7), (1, 8), (1, 9), (1, 10), (2, 7), (2, 8), (2, 9), (2, 10), (3, 7), (3, 8), (3, 9), (3, 10), (4, 7), (4, 8), (4, 9), (4, 10), (7, 1), (7, 2), (7, 3), (7, 4), (8, 1), (8, 2), (8, 3), (8, 4), (9, 1), (9, 2), (9, 3), (9, 4), (10, 1), (10, 2), (10, 3), (10, 4). Total number of possible pairs is 10Β·10 = 100, so answer is 32 / 100. In second case Petya always get number less than Vasya and the only lucky 7 is between this numbers, so there will be always 1 lucky number.
instruction
0
14,187
20
28,374
Tags: brute force, probabilities Correct Solution: ``` def gen(n, cur): if n == 0: global arr arr.append(cur) else: gen(n - 1, cur + '4') gen(n - 1, cur + '7') def lseg(x1, x2): if x2 < x1: return 0 return x2 - x1 + 1 def inter2(x1, x2, a, b): left = max(x1, a) right = min(x2, b) return (left, right) def inter(x1, x2, a, b): l, r = inter2(x1, x2, a, b) return lseg(l, r) def minus(a, b, c, d): d1 = (-1, c - 1) d2 = (d + 1, 10 ** 10) d1 = inter(a, b, *d1) d2 = inter(a, b, *d2) return d1 + d2 arr = [] for i in range(1, 11): gen(i, '') arr = [0] + sorted(list(map(int, arr))) pl, pr, vl, vr, k = map(int, input().split()) ans = 0 for start in range(1, len(arr) - k + 1): if arr[start + k - 1] > max(vr, pr): break if arr[start] < min(pl, vl): continue goleft = inter(pl, pr, arr[start - 1] + 1, arr[start]) goright = inter(vl, vr, arr[start + k - 1], arr[start + k] - 1) left, right = inter2(pl, pr, arr[start - 1] + 1, arr[start]), \ inter2(vl, vr, arr[start + k - 1], arr[start + k] - 1) ans += goleft * goright left1 = inter2(pl, pr, arr[start + k - 1], arr[start + k] - 1) right1 = inter2(vl, vr, arr[start - 1] + 1, arr[start]) ans += minus(right1[0], right1[1], right[0], right[1]) * lseg(*left1) ans += (lseg(*right1) - minus(right1[0], right1[1], right[0], right[1])) \ * minus(left1[0], left1[1], left[0], left[1]) ans /= (pr - pl + 1) * (vr - vl + 1) print(ans) ```
output
1
14,187
20
28,375
Provide tags and a correct Python 3 solution for this coding contest problem. Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya and his friend Vasya play an interesting game. Petya randomly chooses an integer p from the interval [pl, pr] and Vasya chooses an integer v from the interval [vl, vr] (also randomly). Both players choose their integers equiprobably. Find the probability that the interval [min(v, p), max(v, p)] contains exactly k lucky numbers. Input The single line contains five integers pl, pr, vl, vr and k (1 ≀ pl ≀ pr ≀ 109, 1 ≀ vl ≀ vr ≀ 109, 1 ≀ k ≀ 1000). Output On the single line print the result with an absolute error of no more than 10 - 9. Examples Input 1 10 1 10 2 Output 0.320000000000 Input 5 6 8 10 1 Output 1.000000000000 Note Consider that [a, b] denotes an interval of integers; this interval includes the boundaries. That is, <image> In first case there are 32 suitable pairs: (1, 7), (1, 8), (1, 9), (1, 10), (2, 7), (2, 8), (2, 9), (2, 10), (3, 7), (3, 8), (3, 9), (3, 10), (4, 7), (4, 8), (4, 9), (4, 10), (7, 1), (7, 2), (7, 3), (7, 4), (8, 1), (8, 2), (8, 3), (8, 4), (9, 1), (9, 2), (9, 3), (9, 4), (10, 1), (10, 2), (10, 3), (10, 4). Total number of possible pairs is 10Β·10 = 100, so answer is 32 / 100. In second case Petya always get number less than Vasya and the only lucky 7 is between this numbers, so there will be always 1 lucky number.
instruction
0
14,188
20
28,376
Tags: brute force, probabilities Correct Solution: ``` import itertools as it all_lucky = [] for length in range(1, 10): for comb in it.product(['7', '4'], repeat=length): all_lucky += [int(''.join(comb))] all_lucky.sort() # print(len(all_lucky)) pl, pr, vl, vr, k = map(int, input().split()) result = 0 def inters_len(a, b, c, d): a, b = sorted([a, b]) c, d = sorted([c, d]) return (max([a, c]), min([b, d])) def check_for_intervals(pl, pr, vl, vr): global result for i in range(1, len(all_lucky) - k): le, re = i, i + k - 1 a, b = inters_len(all_lucky[le - 1] + 1, all_lucky[le], pl, pr) left_len = max([0, b - a + 1]) c, d = inters_len(all_lucky[re], all_lucky[re + 1] - 1, vl, vr) right_len = max([0, d - c + 1]) result += (left_len / (pr - pl + 1)) * (right_len / (vr - vl + 1)) if b == c and left_len * right_len > 1e-6: result -= (1 / (pr - pl + 1) / (vr - vl + 1)) / 2 a, b = inters_len(0, all_lucky[0], pl, pr) left_len = max([0, b - a + 1]) c, d = inters_len(all_lucky[k - 1], all_lucky[k] - 1, vl, vr) right_len = max([0, d - c + 1]) #print((left_len / (pr - pl + 1)) * (right_len / (vr - vl + 1))) #print(left_len, right_len) result += (left_len / (pr - pl + 1)) * (right_len / (vr - vl + 1)) if b == c and left_len * right_len > 1e-6: result -= (1 / (pr - pl + 1) / (vr - vl + 1)) / 2 a, b = inters_len(all_lucky[-(k + 1)] + 1, all_lucky[-k], pl, pr) left_len = max([0, b - a + 1]) c, d = inters_len(all_lucky[-1], 10**9, vl, vr) right_len = max([0, d - c + 1]) #print((left_len / (pr - pl + 1)) * (right_len / (vr - vl + 1))) result += (left_len / (pr - pl + 1)) * (right_len / (vr - vl + 1)) if b == c and left_len * right_len > 1e-6: result -= (1 / (pr - pl + 1) / (vr - vl + 1)) / 2 #print(all_lucky[:5]) if k != len(all_lucky): check_for_intervals(pl, pr, vl, vr) check_for_intervals(vl, vr, pl, pr) else: a, b = inters_len(0, all_lucky[0], pl, pr) left_len = max([0, b - a + 1]) c, d = inters_len(all_lucky[-1], 10**9, vl, vr) right_len = max([0, d - c + 1]) result += (left_len / (pr - pl + 1)) * (right_len / (vr - vl + 1)) if b == c and left_len * right_len > 1e-6: result -= (1 / (pr - pl + 1) / (vr - vl + 1)) / 2 a, b = inters_len(0, all_lucky[0], vl, vr) left_len = max([0, b - a + 1]) c, d = inters_len(all_lucky[-1], 10**9, pl, pr) right_len = max([0, d - c + 1]) result += (left_len / (vr - vl + 1)) * (right_len / (pr - pl + 1)) if b == c and left_len * right_len > 1e-6: result -= (1 / (pr - pl + 1) / (vr - vl + 1)) / 2 print(result) ```
output
1
14,188
20
28,377
Provide tags and a correct Python 3 solution for this coding contest problem. Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya and his friend Vasya play an interesting game. Petya randomly chooses an integer p from the interval [pl, pr] and Vasya chooses an integer v from the interval [vl, vr] (also randomly). Both players choose their integers equiprobably. Find the probability that the interval [min(v, p), max(v, p)] contains exactly k lucky numbers. Input The single line contains five integers pl, pr, vl, vr and k (1 ≀ pl ≀ pr ≀ 109, 1 ≀ vl ≀ vr ≀ 109, 1 ≀ k ≀ 1000). Output On the single line print the result with an absolute error of no more than 10 - 9. Examples Input 1 10 1 10 2 Output 0.320000000000 Input 5 6 8 10 1 Output 1.000000000000 Note Consider that [a, b] denotes an interval of integers; this interval includes the boundaries. That is, <image> In first case there are 32 suitable pairs: (1, 7), (1, 8), (1, 9), (1, 10), (2, 7), (2, 8), (2, 9), (2, 10), (3, 7), (3, 8), (3, 9), (3, 10), (4, 7), (4, 8), (4, 9), (4, 10), (7, 1), (7, 2), (7, 3), (7, 4), (8, 1), (8, 2), (8, 3), (8, 4), (9, 1), (9, 2), (9, 3), (9, 4), (10, 1), (10, 2), (10, 3), (10, 4). Total number of possible pairs is 10Β·10 = 100, so answer is 32 / 100. In second case Petya always get number less than Vasya and the only lucky 7 is between this numbers, so there will be always 1 lucky number.
instruction
0
14,189
20
28,378
Tags: brute force, probabilities Correct Solution: ``` def gen_len(l): gen = [] for i in range(2 ** l): k = int(bin(i)[2:].rjust(l, '0').replace('0', '4').replace('1', '7')) if k <= 10 ** 9: gen.append(k) return gen def pairs_with_k_len(a, k): l = 0 r = k - 1 while r < len(a): yield l, r l += 1 r += 1 def get_intersection_length(l1, r1, l2, r2): return max(min(r1, r2) - max(l1, l2) + 1, 0) def main(): gen = set() for i in range(1, 10): for e in gen_len(i): gen.add(e) gen = list(sorted(gen)) pl, pr, vl, vr, k = map(int, input().split()) denominator = (pr - pl + 1) * (vr - vl + 1) p = (pl, pr) v = (vl, vr) count = 0 for l, r in pairs_with_k_len(gen, k): if gen[l] >= min(pl, vl) and gen[r] <= max(pr, vr): l1 = gen[l - 1] if l != 0 else 0 r1 = gen[l] l2 = gen[r] r2 = gen[r + 1] if r != len(gen) - 1 else 10**9 + 1 count += (get_intersection_length(l1 + 1, r1, pl, pr) * get_intersection_length(l2, r2 - 1, vl, vr)) count += (get_intersection_length(l1 + 1, r1, vl, vr) * get_intersection_length(l2, r2 - 1, pl, pr)) if k == 1 and get_intersection_length(vl, vr, pl, pr) != 0: count -= 1 print(f"{(count / denominator):.{12}f}") if __name__ == '__main__': main() ```
output
1
14,189
20
28,379
Provide tags and a correct Python 3 solution for this coding contest problem. Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya and his friend Vasya play an interesting game. Petya randomly chooses an integer p from the interval [pl, pr] and Vasya chooses an integer v from the interval [vl, vr] (also randomly). Both players choose their integers equiprobably. Find the probability that the interval [min(v, p), max(v, p)] contains exactly k lucky numbers. Input The single line contains five integers pl, pr, vl, vr and k (1 ≀ pl ≀ pr ≀ 109, 1 ≀ vl ≀ vr ≀ 109, 1 ≀ k ≀ 1000). Output On the single line print the result with an absolute error of no more than 10 - 9. Examples Input 1 10 1 10 2 Output 0.320000000000 Input 5 6 8 10 1 Output 1.000000000000 Note Consider that [a, b] denotes an interval of integers; this interval includes the boundaries. That is, <image> In first case there are 32 suitable pairs: (1, 7), (1, 8), (1, 9), (1, 10), (2, 7), (2, 8), (2, 9), (2, 10), (3, 7), (3, 8), (3, 9), (3, 10), (4, 7), (4, 8), (4, 9), (4, 10), (7, 1), (7, 2), (7, 3), (7, 4), (8, 1), (8, 2), (8, 3), (8, 4), (9, 1), (9, 2), (9, 3), (9, 4), (10, 1), (10, 2), (10, 3), (10, 4). Total number of possible pairs is 10Β·10 = 100, so answer is 32 / 100. In second case Petya always get number less than Vasya and the only lucky 7 is between this numbers, so there will be always 1 lucky number.
instruction
0
14,190
20
28,380
Tags: brute force, probabilities Correct Solution: ``` import itertools def generate_happy(): happy_digits = '47' happies = [] for num_len in range(1, 10): happies.extend(itertools.product(happy_digits, repeat=num_len)) return [int(''.join(num)) for num in happies] def clamp_segment(start, end, min_b, max_b): if start > end or min_b > max_b: raise ValueError(f"{start} {end} {min_b} {max_b}") if start > max_b or end < min_b: return None, None new_start = start new_end = end if start < min_b: new_start = min_b if end > max_b: new_end = max_b return new_start, new_end def get_window_bounds(happies, happy_count, happy_window_ind): return (happies[happy_window_ind - 1] if happy_window_ind > 0 else 0, happies[happy_window_ind], happies[happy_window_ind + happy_count - 1], (happies[happy_window_ind + happy_count] if happy_window_ind + happy_count < len(happies) else 10 ** 9 + 1 ) ) def get_good_segm_count_ordered( lower_start, lower_end, upper_start, upper_end, prev_happy, this_happy, last_happy, next_happy): (lower_bound_start, lower_bound_end) = clamp_segment( lower_start, lower_end, prev_happy + 1, this_happy ) (upper_bound_start, upper_bound_end) = clamp_segment( upper_start, upper_end, last_happy, next_happy - 1 ) if lower_bound_start is None or upper_bound_start is None: return 0 return (lower_bound_end - lower_bound_start + 1) *\ (upper_bound_end - upper_bound_start + 1) def get_good_segm_count(happies, happy_count, happy_window_ind, start_1, end_1, start_2, end_2): prev_happy, this_happy, last_happy, next_happy = get_window_bounds( happies, happy_count, happy_window_ind ) first_is_lower_count = get_good_segm_count_ordered( start_1, end_1, start_2, end_2, prev_happy, this_happy, last_happy, next_happy ) second_is_lower_count = get_good_segm_count_ordered( start_2, end_2, start_1, end_1, prev_happy, this_happy, last_happy, next_happy ) this_happy = happies[happy_window_ind] if (happy_count == 1 and start_1 <= this_happy <= end_2 and start_2 <= this_happy <= end_2): second_is_lower_count -= 1 return first_is_lower_count + second_is_lower_count def main(args=None): if args is None: p_start, p_end, v_start, v_end, happy_count = map(int, input().split()) else: p_start, p_end, v_start, v_end, happy_count = args happies = generate_happy() good_segments_count = 0 for happy_window_ind in range(len(happies) - happy_count + 1): good_segments_count += get_good_segm_count( happies, happy_count, happy_window_ind, p_start, p_end, v_start, v_end ) # print(get_good_segm_count( # happies, happy_count, happy_window_ind, # p_start, p_end, v_start, v_end # ), happy_window_ind) all_segments_count = (p_end - p_start + 1) * (v_end - v_start + 1) return good_segments_count / all_segments_count print(main()) ```
output
1
14,190
20
28,381
Provide tags and a correct Python 3 solution for this coding contest problem. Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya and his friend Vasya play an interesting game. Petya randomly chooses an integer p from the interval [pl, pr] and Vasya chooses an integer v from the interval [vl, vr] (also randomly). Both players choose their integers equiprobably. Find the probability that the interval [min(v, p), max(v, p)] contains exactly k lucky numbers. Input The single line contains five integers pl, pr, vl, vr and k (1 ≀ pl ≀ pr ≀ 109, 1 ≀ vl ≀ vr ≀ 109, 1 ≀ k ≀ 1000). Output On the single line print the result with an absolute error of no more than 10 - 9. Examples Input 1 10 1 10 2 Output 0.320000000000 Input 5 6 8 10 1 Output 1.000000000000 Note Consider that [a, b] denotes an interval of integers; this interval includes the boundaries. That is, <image> In first case there are 32 suitable pairs: (1, 7), (1, 8), (1, 9), (1, 10), (2, 7), (2, 8), (2, 9), (2, 10), (3, 7), (3, 8), (3, 9), (3, 10), (4, 7), (4, 8), (4, 9), (4, 10), (7, 1), (7, 2), (7, 3), (7, 4), (8, 1), (8, 2), (8, 3), (8, 4), (9, 1), (9, 2), (9, 3), (9, 4), (10, 1), (10, 2), (10, 3), (10, 4). Total number of possible pairs is 10Β·10 = 100, so answer is 32 / 100. In second case Petya always get number less than Vasya and the only lucky 7 is between this numbers, so there will be always 1 lucky number.
instruction
0
14,191
20
28,382
Tags: brute force, probabilities Correct Solution: ``` import itertools as it all_lucky = [] for length in range(1, 10): for comb in it.product(['7', '4'], repeat=length): all_lucky += [int(''.join(comb))] all_lucky.sort() # print(len(all_lucky)) pl, pr, vl, vr, k = map(int, input().split()) result = 0 def inters_len(a, b, c, d): a, b = sorted([a, b]) c, d = sorted([c, d]) return (max([a, c]), min([b, d])) def check_for_intervals(pl, pr, vl, vr): global result for i in range(1, len(all_lucky) - k): le, re = i, i + k - 1 a, b = inters_len(all_lucky[le - 1] + 1, all_lucky[le], pl, pr) left_len = max([0, b - a + 1]) c, d = inters_len(all_lucky[re], all_lucky[re + 1] - 1, vl, vr) right_len = max([0, d - c + 1]) result += (left_len / (pr - pl + 1)) * (right_len / (vr - vl + 1)) if b == c and left_len * right_len > 1e-6: result -= (1 / (pr - pl + 1) / (vr - vl + 1)) / 2 a, b = inters_len(0, all_lucky[0], pl, pr) left_len = max([0, b - a + 1]) c, d = inters_len(all_lucky[k - 1], all_lucky[k] - 1, vl, vr) right_len = max([0, d - c + 1]) #print((left_len / (pr - pl + 1)) * (right_len / (vr - vl + 1))) #print(left_len, right_len) result += (left_len / (pr - pl + 1)) * (right_len / (vr - vl + 1)) if b == c and left_len * right_len > 1e-6: result -= (1 / (pr - pl + 1) / (vr - vl + 1)) / 2 a, b = inters_len(all_lucky[-(k + 1)] + 1, all_lucky[-k], pl, pr) left_len = max([0, b - a + 1]) c, d = inters_len(all_lucky[-1], 10**9, vl, vr) right_len = max([0, d - c + 1]) #print((left_len / (pr - pl + 1)) * (right_len / (vr - vl + 1))) result += (left_len / (pr - pl + 1)) * (right_len / (vr - vl + 1)) if b == c and left_len * right_len > 1e-6: result -= (1 / (pr - pl + 1) / (vr - vl + 1)) / 2 #print(all_lucky[:5]) if k != len(all_lucky): check_for_intervals(pl, pr, vl, vr) check_for_intervals(vl, vr, pl, pr) else: a, b = inters_len(0, all_lucky[0], pl, pr) left_len = max([0, b - a + 1]) c, d = inters_len(all_lucky[-1], 10**9, vl, vr) right_len = max([0, d - c + 1]) result += (left_len / (pr - pl + 1)) * (right_len / (vr - vl + 1)) if b == c and left_len * right_len > 1e-6: result -= (1 / (pr - pl + 1) / (vr - vl + 1)) / 2 a, b = inters_len(0, all_lucky[0], vl, vr) left_len = max([0, b - a + 1]) c, d = inters_len(all_lucky[-1], 10**9, pl, pr) right_len = max([0, d - c + 1]) result += (left_len / (vr - vl + 1)) * (right_len / (pr - pl + 1)) if b == c and left_len * right_len > 1e-6: result -= (1 / (pr - pl + 1) / (vr - vl + 1)) / 2 print(result) # Made By Mostafa_Khaled ```
output
1
14,191
20
28,383
Provide tags and a correct Python 3 solution for this coding contest problem. Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya and his friend Vasya play an interesting game. Petya randomly chooses an integer p from the interval [pl, pr] and Vasya chooses an integer v from the interval [vl, vr] (also randomly). Both players choose their integers equiprobably. Find the probability that the interval [min(v, p), max(v, p)] contains exactly k lucky numbers. Input The single line contains five integers pl, pr, vl, vr and k (1 ≀ pl ≀ pr ≀ 109, 1 ≀ vl ≀ vr ≀ 109, 1 ≀ k ≀ 1000). Output On the single line print the result with an absolute error of no more than 10 - 9. Examples Input 1 10 1 10 2 Output 0.320000000000 Input 5 6 8 10 1 Output 1.000000000000 Note Consider that [a, b] denotes an interval of integers; this interval includes the boundaries. That is, <image> In first case there are 32 suitable pairs: (1, 7), (1, 8), (1, 9), (1, 10), (2, 7), (2, 8), (2, 9), (2, 10), (3, 7), (3, 8), (3, 9), (3, 10), (4, 7), (4, 8), (4, 9), (4, 10), (7, 1), (7, 2), (7, 3), (7, 4), (8, 1), (8, 2), (8, 3), (8, 4), (9, 1), (9, 2), (9, 3), (9, 4), (10, 1), (10, 2), (10, 3), (10, 4). Total number of possible pairs is 10Β·10 = 100, so answer is 32 / 100. In second case Petya always get number less than Vasya and the only lucky 7 is between this numbers, so there will be always 1 lucky number.
instruction
0
14,192
20
28,384
Tags: brute force, probabilities Correct Solution: ``` #!/usr/bin/env python3 import itertools pl,pr,vl,vr,k = map(int, input().split()) l = min(pl, vl) r = max(pr, vr) # Generate all lucky numbers with the appropriate number of digits # O(3**max_nr_digits) = O(3**9) < 20000 max_nr_digits = len(str(r)) lucky_numbers = [] for nr_digits in range(1,max_nr_digits+1): lucky_numbers.extend(int(''.join(i)) for i in itertools.product("47", repeat=nr_digits)) # Filter so we only have lucky numbers that can be in the intervals lucky_numbers = [nr for nr in lucky_numbers if (l <= nr) and (nr <= r)] lucky_numbers.sort() if len(lucky_numbers) < k: print("%.12f" % 0.0) exit() lucky_numbers.insert(0,l-1) lucky_numbers.append(r+1) total_pairs = (pr-pl+1) * (vr-vl+1) good_pairs = 0 for start_index in range(len(lucky_numbers)-k-1): (a,b) = lucky_numbers[start_index], lucky_numbers[start_index+1] (c,d) = lucky_numbers[start_index+k], lucky_numbers[start_index+k+1] # A pair will have lucky_numbers[start_index+1 : start_index+1+k] in its interval when: # The smallest number of the pair is larger than a, but at most b # The largest number of the pair is at least c, but smaller than d good_pairs += max((min(b,pr)-max(a+1,pl)+1),0)*max((min(d-1,vr)-max(c,vl)+1),0) good_pairs += max((min(b,vr)-max(a+1,vl)+1),0)*max((min(d-1,pr)-max(c,pl)+1),0) if (b == c) and (pl <= b) and (b <= pr) and (vl <=b) and (b <= vr): # Prevent double counting of the pair (b,c) when b == c and both p and v can supply the value good_pairs -= 1 print("%.12f" % (good_pairs / total_pairs)) ```
output
1
14,192
20
28,385
Provide tags and a correct Python 3 solution for this coding contest problem. Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya and his friend Vasya play an interesting game. Petya randomly chooses an integer p from the interval [pl, pr] and Vasya chooses an integer v from the interval [vl, vr] (also randomly). Both players choose their integers equiprobably. Find the probability that the interval [min(v, p), max(v, p)] contains exactly k lucky numbers. Input The single line contains five integers pl, pr, vl, vr and k (1 ≀ pl ≀ pr ≀ 109, 1 ≀ vl ≀ vr ≀ 109, 1 ≀ k ≀ 1000). Output On the single line print the result with an absolute error of no more than 10 - 9. Examples Input 1 10 1 10 2 Output 0.320000000000 Input 5 6 8 10 1 Output 1.000000000000 Note Consider that [a, b] denotes an interval of integers; this interval includes the boundaries. That is, <image> In first case there are 32 suitable pairs: (1, 7), (1, 8), (1, 9), (1, 10), (2, 7), (2, 8), (2, 9), (2, 10), (3, 7), (3, 8), (3, 9), (3, 10), (4, 7), (4, 8), (4, 9), (4, 10), (7, 1), (7, 2), (7, 3), (7, 4), (8, 1), (8, 2), (8, 3), (8, 4), (9, 1), (9, 2), (9, 3), (9, 4), (10, 1), (10, 2), (10, 3), (10, 4). Total number of possible pairs is 10Β·10 = 100, so answer is 32 / 100. In second case Petya always get number less than Vasya and the only lucky 7 is between this numbers, so there will be always 1 lucky number.
instruction
0
14,193
20
28,386
Tags: brute force, probabilities Correct Solution: ``` #!/usr/bin/env python3 vl, vr, pl, pr, k = map(int, input().split()) lucky = [4, 7] sz = 0 for i in range(1, 9): base = 10 ** i psz, sz = sz, len(lucky) for j in [4 * base, 7 * base]: for pos in range(psz, sz): lucky.append(j + lucky[pos]) ans = 0 for i in range(0, len(lucky)-k+1): ll, lr = 1 if i == 0 else lucky[i-1] + 1, lucky[i] rl, rr = lucky[i+k-1], 1_000_000_000 if i+k == len(lucky) else lucky[i+k] - 1 vc = max(0, min(vr, lr) - max(vl, ll) + 1) pc = max(0, min(pr, rr) - max(pl, rl) + 1) cnt1 = vc * pc vc = max(0, min(pr, lr) - max(pl, ll) + 1) pc = max(0, min(vr, rr) - max(vl, rl) + 1) cnt2 = vc * pc ans += cnt1 + cnt2 if k == 1 and cnt1 > 0 and cnt2 > 0: ans -= 1 print(ans / ((vr - vl + 1) * (pr - pl + 1))) ```
output
1
14,193
20
28,387
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya and his friend Vasya play an interesting game. Petya randomly chooses an integer p from the interval [pl, pr] and Vasya chooses an integer v from the interval [vl, vr] (also randomly). Both players choose their integers equiprobably. Find the probability that the interval [min(v, p), max(v, p)] contains exactly k lucky numbers. Input The single line contains five integers pl, pr, vl, vr and k (1 ≀ pl ≀ pr ≀ 109, 1 ≀ vl ≀ vr ≀ 109, 1 ≀ k ≀ 1000). Output On the single line print the result with an absolute error of no more than 10 - 9. Examples Input 1 10 1 10 2 Output 0.320000000000 Input 5 6 8 10 1 Output 1.000000000000 Note Consider that [a, b] denotes an interval of integers; this interval includes the boundaries. That is, <image> In first case there are 32 suitable pairs: (1, 7), (1, 8), (1, 9), (1, 10), (2, 7), (2, 8), (2, 9), (2, 10), (3, 7), (3, 8), (3, 9), (3, 10), (4, 7), (4, 8), (4, 9), (4, 10), (7, 1), (7, 2), (7, 3), (7, 4), (8, 1), (8, 2), (8, 3), (8, 4), (9, 1), (9, 2), (9, 3), (9, 4), (10, 1), (10, 2), (10, 3), (10, 4). Total number of possible pairs is 10Β·10 = 100, so answer is 32 / 100. In second case Petya always get number less than Vasya and the only lucky 7 is between this numbers, so there will be always 1 lucky number. Submitted Solution: ``` import time def happy(a, b): min_len = len(str(a)) max_len = len(str(b)) #count = 0 for length in range(min_len, max_len+1): for happy in get_happy(length): if happy < a: continue if happy > b: break #count += 1 yield happy def to_bin(n, length): v = bin(n)[2:] return '4'*(length - len(v))+v def get_happy(length): for i in range(2**length): v = to_bin(i, length) v = v.replace('0', '4') v = v.replace('1', '7') yield int(v) def calculate_num_in_zone(l1, l2, r1, r2, content, value): left_target = -1 right_target = -1 right_value = r1 left_value = l1 for index in range(len(content)): if index < len(content) - 1: if content[index] <= right_value < content[index+1]: right_target = index if content[index] <= left_value < content[index+1]: left_target = index else: if content[index] <= right_value: right_target = index if content[index] <= left_value: left_target = index if right_target - left_target + 1 < value: right_target += value - (right_target - left_target) if right_target >= len(content) or content[right_target] > r2: return 0 right_value = max(content[right_target], r1) if right_target - left_target > value: left_target += (right_target - left_target) - value if left_target >= len(content) or content[left_target] > l2: return 0 left_value = max(content[left_target], l1) left_finished = False right_finished = False count = 0 while not left_finished and not right_finished: next_left = l2 add_left = False if next_left == left_value and left_value in content: add_left = True elif next_left != left_value: add_left = left_value not in content if left_target + 1 < len(content) and l2 > content[left_target + 1]: next_left = content[left_target + 1] next_right = r2 if right_target + 1 < len(content) and r2 > content[right_target + 1]: next_right = content[right_target + 1] add_right = False if next_right == right_value and right_value in content: add_right = True elif next_right != right_value: add_right = next_right not in content left_number = next_left - left_value + (1 if add_left else 0) right_number = next_right - right_value + (1 if add_right else 0) add = left_number * right_number count += add left_target += 1 right_target += 1 left_value = next_left right_value = next_right if left_target >= len(content) or content[left_target] > l2: left_finished = True if right_target >= len(content) or content[right_target] > r2: right_finished = True return count if __name__ == "__main__": pl, pr, vl, vr, k = list(map(int, input().split())) a = (pr - pl + 1) * (vr - vl + 1) l1, l2, r1, r2 = pl, pr, vl, vr if r1 < l1: l1, l2, r1, r2 = vl, vr, pl, pr happy_in_left = list(happy(l1, l2)) happy_in_right = list(happy(r1, r2)) happy_in_total = list(happy(l1, max(r2, l2))) f = 0 if r1 >= l2: f = calculate_num_in_zone(l1, l2, r1, r2, happy_in_total, k) elif r1 < l2 <= r2: f = calculate_num_in_zone(l1, l2, r1, r2, happy_in_total, k) f += calculate_num_in_zone(r1, l2, r1, l2, happy_in_total, k) wrong = 0 if k == 1: for h1 in happy_in_left: if h1 in happy_in_right: wrong += 1 f -= wrong else: f = calculate_num_in_zone(l1, r2, r1, r2, happy_in_total, k) f += calculate_num_in_zone(r1, r2, r1, l2, happy_in_total, k) print(f/a) ```
instruction
0
14,194
20
28,388
No
output
1
14,194
20
28,389
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya and his friend Vasya play an interesting game. Petya randomly chooses an integer p from the interval [pl, pr] and Vasya chooses an integer v from the interval [vl, vr] (also randomly). Both players choose their integers equiprobably. Find the probability that the interval [min(v, p), max(v, p)] contains exactly k lucky numbers. Input The single line contains five integers pl, pr, vl, vr and k (1 ≀ pl ≀ pr ≀ 109, 1 ≀ vl ≀ vr ≀ 109, 1 ≀ k ≀ 1000). Output On the single line print the result with an absolute error of no more than 10 - 9. Examples Input 1 10 1 10 2 Output 0.320000000000 Input 5 6 8 10 1 Output 1.000000000000 Note Consider that [a, b] denotes an interval of integers; this interval includes the boundaries. That is, <image> In first case there are 32 suitable pairs: (1, 7), (1, 8), (1, 9), (1, 10), (2, 7), (2, 8), (2, 9), (2, 10), (3, 7), (3, 8), (3, 9), (3, 10), (4, 7), (4, 8), (4, 9), (4, 10), (7, 1), (7, 2), (7, 3), (7, 4), (8, 1), (8, 2), (8, 3), (8, 4), (9, 1), (9, 2), (9, 3), (9, 4), (10, 1), (10, 2), (10, 3), (10, 4). Total number of possible pairs is 10Β·10 = 100, so answer is 32 / 100. In second case Petya always get number less than Vasya and the only lucky 7 is between this numbers, so there will be always 1 lucky number. Submitted Solution: ``` def gen(n, cur): if n == 0: global arr arr.append(cur) else: gen(n - 1, cur + '4') gen(n - 1, cur + '7') def inter(x1, x2, a, b): left = max(x1, a) right = min(x2, b) if right < left: return 0 return right - left + 1 arr = [] for i in range(1, 11): gen(i, '') arr = [0] + sorted(list(map(int, arr))) pl, pr, vl, vr, k = map(int, input().split()) ans = 0 for start in range(1, len(arr) - k + 1): if arr[start + k - 1] > max(vr, pr): break if arr[start] < min(pl, vl): continue goleft = inter(pl, pr, arr[start - 1] + 1, arr[start]) goright = inter(vl, vr, arr[start + k - 1], arr[start + k] - 1) ans += goleft * goright goright = inter(vl, vr, arr[start - 1] + 1, arr[start]) goleft = inter(pl, pr, arr[start + k - 1], arr[start + k] - 1) ans += goleft * goright ans /= (pr - pl + 1) * (vr - vl + 1) print(ans) ```
instruction
0
14,195
20
28,390
No
output
1
14,195
20
28,391
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya and his friend Vasya play an interesting game. Petya randomly chooses an integer p from the interval [pl, pr] and Vasya chooses an integer v from the interval [vl, vr] (also randomly). Both players choose their integers equiprobably. Find the probability that the interval [min(v, p), max(v, p)] contains exactly k lucky numbers. Input The single line contains five integers pl, pr, vl, vr and k (1 ≀ pl ≀ pr ≀ 109, 1 ≀ vl ≀ vr ≀ 109, 1 ≀ k ≀ 1000). Output On the single line print the result with an absolute error of no more than 10 - 9. Examples Input 1 10 1 10 2 Output 0.320000000000 Input 5 6 8 10 1 Output 1.000000000000 Note Consider that [a, b] denotes an interval of integers; this interval includes the boundaries. That is, <image> In first case there are 32 suitable pairs: (1, 7), (1, 8), (1, 9), (1, 10), (2, 7), (2, 8), (2, 9), (2, 10), (3, 7), (3, 8), (3, 9), (3, 10), (4, 7), (4, 8), (4, 9), (4, 10), (7, 1), (7, 2), (7, 3), (7, 4), (8, 1), (8, 2), (8, 3), (8, 4), (9, 1), (9, 2), (9, 3), (9, 4), (10, 1), (10, 2), (10, 3), (10, 4). Total number of possible pairs is 10Β·10 = 100, so answer is 32 / 100. In second case Petya always get number less than Vasya and the only lucky 7 is between this numbers, so there will be always 1 lucky number. Submitted Solution: ``` import itertools as it all_lucky = [] for length in range(1, 9): for comb in it.product(['7', '4'], repeat=length): all_lucky += [int(''.join(comb))] all_lucky.sort() # print(len(all_lucky)) pl, pr, vl, vr, k = map(int, input().split()) result = 0 def inters_len(a, b, c, d): a, b = sorted([a, b]) c, d = sorted([c, d]) return max([0, (min([b, d]) - max([a, c]) + 1)]) def check_for_intervals(pl, pr, vl, vr): global result for i in range(1, len(all_lucky) - k): le, re = i, i + k - 1 left_len = inters_len(all_lucky[le - 1] + 1, all_lucky[le], pl, pr) right_len = inters_len(all_lucky[re], all_lucky[re + 1] - 1, vl, vr) result += (left_len / (pr - pl + 1)) * (right_len / (vr - vl + 1)) left_len = inters_len(all_lucky[le - 1] + 1, all_lucky[le], vl, vr) right_len = inters_len(all_lucky[re], all_lucky[re + 1] - 1, pl, pr) result += (left_len / (vr - vl + 1)) * (right_len / (pr - pl + 1)) left_len = inters_len(0, all_lucky[0], pl, pr) right_len = inters_len(all_lucky[k - 1], all_lucky[k] - 1, vl, vr) #print((left_len / (pr - pl + 1)) * (right_len / (vr - vl + 1))) #print(left_len, right_len) result += (left_len / (pr - pl + 1)) * (right_len / (vr - vl + 1)) left_len = inters_len(0, all_lucky[0], vl, vr) right_len = inters_len(all_lucky[k - 1], all_lucky[k] - 1, pl, pr) #print((left_len / (pr - pl + 1)) * (right_len / (vr - vl + 1))) #print(left_len, right_len) result += (left_len / (vr - vl + 1)) * (right_len / (pr - pl + 1)) left_len = inters_len(all_lucky[-(k + 1)] + 1, all_lucky[-k], pl, pr) right_len = inters_len(all_lucky[-1], 10**9, vl, vr) #print((left_len / (pr - pl + 1)) * (right_len / (vr - vl + 1))) result += (left_len / (pr - pl + 1)) * (right_len / (vr - vl + 1)) left_len = inters_len(all_lucky[-(k + 1)] + 1, all_lucky[-k], vl, vr) right_len = inters_len(all_lucky[-1], 10**9, pl, pr) #print((left_len / (pr - pl + 1)) * (right_len / (vr - vl + 1))) result += (left_len / (vr - vl + 1)) * (right_len / (pr - pl + 1)) #print(all_lucky[:5]) if k != len(all_lucky): check_for_intervals(pl, pr, vl, vr) else: left_len = inters_len(0, all_lucky[0], pl, pr) right_len = inters_len(all_lucky[-1], 10**9, vl, vr) result += (left_len / (pr - pl + 1)) * (right_len / (vr - vl + 1)) left_len = inters_len(0, all_lucky[0], vl, vr) right_len = inters_len(all_lucky[-1], 10**9, pl, pr) result += (left_len / (vr - vl + 1)) * (right_len / (pr - pl + 1)) print(result) ```
instruction
0
14,196
20
28,392
No
output
1
14,196
20
28,393
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya and his friend Vasya play an interesting game. Petya randomly chooses an integer p from the interval [pl, pr] and Vasya chooses an integer v from the interval [vl, vr] (also randomly). Both players choose their integers equiprobably. Find the probability that the interval [min(v, p), max(v, p)] contains exactly k lucky numbers. Input The single line contains five integers pl, pr, vl, vr and k (1 ≀ pl ≀ pr ≀ 109, 1 ≀ vl ≀ vr ≀ 109, 1 ≀ k ≀ 1000). Output On the single line print the result with an absolute error of no more than 10 - 9. Examples Input 1 10 1 10 2 Output 0.320000000000 Input 5 6 8 10 1 Output 1.000000000000 Note Consider that [a, b] denotes an interval of integers; this interval includes the boundaries. That is, <image> In first case there are 32 suitable pairs: (1, 7), (1, 8), (1, 9), (1, 10), (2, 7), (2, 8), (2, 9), (2, 10), (3, 7), (3, 8), (3, 9), (3, 10), (4, 7), (4, 8), (4, 9), (4, 10), (7, 1), (7, 2), (7, 3), (7, 4), (8, 1), (8, 2), (8, 3), (8, 4), (9, 1), (9, 2), (9, 3), (9, 4), (10, 1), (10, 2), (10, 3), (10, 4). Total number of possible pairs is 10Β·10 = 100, so answer is 32 / 100. In second case Petya always get number less than Vasya and the only lucky 7 is between this numbers, so there will be always 1 lucky number. Submitted Solution: ``` import time def happy(a, b): min_len = len(str(a)) max_len = len(str(b)) #count = 0 for length in range(min_len, max_len+1): for happy in get_happy(length): if happy < a: continue if happy > b: break #count += 1 yield happy def to_bin(n, length): v = bin(n)[2:] return '4'*(length - len(v))+v def get_happy(length): for i in range(2**length): v = to_bin(i, length) v = v.replace('0', '4') v = v.replace('1', '7') yield int(v) def calculate_num_in_zone(l1, l2, r1, r2, content, value): left_target = 0 right_target = 0 right_value = r1 left_value = l1 l1_in_content = False r2_in_content = False for index in range(len(content)): if index < len(content) - 1: if content[index] <= right_value < content[index+1]: right_target = index if content[index] <= left_value < content[index+1]: left_target = index else: if content[index] <= right_value: right_target = index if content[index] <= left_value: left_target = index if l1 == content[index]: l1_in_content = True if r2 == content[index]: r2_in_content = True if right_target - left_target + 1 < value: right_target += value - (right_target - left_target) if right_target >= len(content) or content[right_target] > r2: return 0 right_value = max(content[right_target], r1) if right_target - left_target + 1 > value: left_target += (right_target - left_target) - value if left_target >= len(content) or content[left_target] > l2: return 0 left_value = max(content[left_target], l1) left_finished = False right_finished = False count = 0 while not left_finished and not right_finished: next_left = l2 add_left = (left_value == l1 and not l1_in_content) or next_left == left_value if left_target + 1 < len(content) and l2 > content[left_target + 1]: next_left = content[left_target + 1] next_right = r2 if right_target + 1 < len(content) and r2 > content[right_target + 1]: next_right = content[right_target + 1] add_right = (next_right == r2 and not r2_in_content) or next_right == right_value left_number = next_left - left_value + (1 if add_left else 0) right_number = next_right - right_value + (1 if add_right else 0) add = left_number * right_number count += add left_target += 1 right_target += 1 left_value = next_left right_value = next_right if left_target >= len(content) or content[left_target] > l2: left_finished = True if right_target >= len(content) or content[right_target] > r2: right_finished = True return count if __name__ == "__main__": pl, pr, vl, vr, k = list(map(int, input().split())) a = (pr - pl + 1) * (vr - vl + 1) l1, l2, r1, r2 = pl, pr, vl, vr if r1 < l1: l1, l2, r1, r2 = vl, vr, pl, pr happy_in_left = list(happy(l1, l2)) happy_in_right = list(happy(r1, r2)) happy_in_total = list(happy(l1, max(r2, l2))) f = 0 if r1 >= l2: f = calculate_num_in_zone(l1, l2, r1, r2, happy_in_total, k) elif r1 < l2 <= r2: f = calculate_num_in_zone(l1, l2, r1, r2, happy_in_total, k) f += calculate_num_in_zone(r1, l2, r1, l2, happy_in_total, k) else: f = calculate_num_in_zone(l1, r2, r1, r2, happy_in_total, k) f += calculate_num_in_zone(r1, r2, r1, l2, happy_in_total, k) print(f/a) ```
instruction
0
14,197
20
28,394
No
output
1
14,197
20
28,395
Provide tags and a correct Python 3 solution for this coding contest problem. Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers. Let's remember how Fibonacci numbers can be calculated. F0 = 0, F1 = 1, and all the next numbers are Fi = Fi - 2 + Fi - 1. So, Fibonacci numbers make a sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13, ... If you haven't run away from the PC in fear, you have to help the virus. Your task is to divide given Fibonacci number n by three not necessary different Fibonacci numbers or say that it is impossible. Input The input contains of a single integer n (0 ≀ n < 109) β€” the number that should be represented by the rules described above. It is guaranteed that n is a Fibonacci number. Output Output three required numbers: a, b and c. If there is no answer for the test you have to print "I'm too stupid to solve this problem" without the quotes. If there are multiple answers, print any of them. Examples Input 3 Output 1 1 1 Input 13 Output 2 3 8
instruction
0
14,433
20
28,866
Tags: brute force, constructive algorithms, implementation, number theory Correct Solution: ``` def hexa(n): l=[] l.append(0) l.append(1) i=2 while n not in l: l.append(l[i-1]+l[i-2]) i=i+1 m=l.index(n) if n==1: return("1 0 0") elif n==2: return("0 1 1") elif n==0: return("0 0 0") elif n==3: return("1 1 1") else: return(str(l[m-1])+" "+str(l[m-3])+" "+str(l[m-4])) n=int(input()) print(hexa(n)) ```
output
1
14,433
20
28,867
Provide tags and a correct Python 3 solution for this coding contest problem. Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers. Let's remember how Fibonacci numbers can be calculated. F0 = 0, F1 = 1, and all the next numbers are Fi = Fi - 2 + Fi - 1. So, Fibonacci numbers make a sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13, ... If you haven't run away from the PC in fear, you have to help the virus. Your task is to divide given Fibonacci number n by three not necessary different Fibonacci numbers or say that it is impossible. Input The input contains of a single integer n (0 ≀ n < 109) β€” the number that should be represented by the rules described above. It is guaranteed that n is a Fibonacci number. Output Output three required numbers: a, b and c. If there is no answer for the test you have to print "I'm too stupid to solve this problem" without the quotes. If there are multiple answers, print any of them. Examples Input 3 Output 1 1 1 Input 13 Output 2 3 8
instruction
0
14,434
20
28,868
Tags: brute force, constructive algorithms, implementation, number theory Correct Solution: ``` n=int(input()) if n==0: print(0,0,0) elif n==1: print(0,0,1) elif n==2: print(0,1,1) else: old = 0 i = 1 old = 1 vold= 1 while i<n: vold = old old = i i= old+vold print(0,old,vold) ```
output
1
14,434
20
28,869
Provide tags and a correct Python 3 solution for this coding contest problem. Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers. Let's remember how Fibonacci numbers can be calculated. F0 = 0, F1 = 1, and all the next numbers are Fi = Fi - 2 + Fi - 1. So, Fibonacci numbers make a sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13, ... If you haven't run away from the PC in fear, you have to help the virus. Your task is to divide given Fibonacci number n by three not necessary different Fibonacci numbers or say that it is impossible. Input The input contains of a single integer n (0 ≀ n < 109) β€” the number that should be represented by the rules described above. It is guaranteed that n is a Fibonacci number. Output Output three required numbers: a, b and c. If there is no answer for the test you have to print "I'm too stupid to solve this problem" without the quotes. If there are multiple answers, print any of them. Examples Input 3 Output 1 1 1 Input 13 Output 2 3 8
instruction
0
14,435
20
28,870
Tags: brute force, constructive algorithms, implementation, number theory Correct Solution: ``` def f(num): global fib for i in fib: for j in fib: for k in fib: if i + j + k == num: print(i, j, k) return print("I'm too stupid to solve this problem") n = int(input()) fib = [0, 1] while fib[-1] + fib[-2] < 1e9: fib.append(fib[-1] + fib[-2]) f(n) # [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, # 46368, 75025, 121393, 196418, 317811, 514229, 832040, 1346269, 2178309, 3524578, 5702887, 9227465, 14930352, # 24157817, 39088169, 63245986, 102334155, 165580141, 267914296, 433494437, 701408733] ```
output
1
14,435
20
28,871
Provide tags and a correct Python 3 solution for this coding contest problem. Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers. Let's remember how Fibonacci numbers can be calculated. F0 = 0, F1 = 1, and all the next numbers are Fi = Fi - 2 + Fi - 1. So, Fibonacci numbers make a sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13, ... If you haven't run away from the PC in fear, you have to help the virus. Your task is to divide given Fibonacci number n by three not necessary different Fibonacci numbers or say that it is impossible. Input The input contains of a single integer n (0 ≀ n < 109) β€” the number that should be represented by the rules described above. It is guaranteed that n is a Fibonacci number. Output Output three required numbers: a, b and c. If there is no answer for the test you have to print "I'm too stupid to solve this problem" without the quotes. If there are multiple answers, print any of them. Examples Input 3 Output 1 1 1 Input 13 Output 2 3 8
instruction
0
14,436
20
28,872
Tags: brute force, constructive algorithms, implementation, number theory Correct Solution: ``` n=int(input()) fibo=[0,1] for i in range(50): fibo.append(fibo[i+1]+fibo[i]) i=fibo.index(n) if i>2: print(fibo[i-2],fibo[i-2],fibo[i-3]) elif n==1: print('0 0 1') elif n==0: print("0 0 0") ```
output
1
14,436
20
28,873
Provide tags and a correct Python 3 solution for this coding contest problem. Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers. Let's remember how Fibonacci numbers can be calculated. F0 = 0, F1 = 1, and all the next numbers are Fi = Fi - 2 + Fi - 1. So, Fibonacci numbers make a sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13, ... If you haven't run away from the PC in fear, you have to help the virus. Your task is to divide given Fibonacci number n by three not necessary different Fibonacci numbers or say that it is impossible. Input The input contains of a single integer n (0 ≀ n < 109) β€” the number that should be represented by the rules described above. It is guaranteed that n is a Fibonacci number. Output Output three required numbers: a, b and c. If there is no answer for the test you have to print "I'm too stupid to solve this problem" without the quotes. If there are multiple answers, print any of them. Examples Input 3 Output 1 1 1 Input 13 Output 2 3 8
instruction
0
14,437
20
28,874
Tags: brute force, constructive algorithms, implementation, number theory Correct Solution: ``` def binarysearch(L,left,right,k): mid=(left+right)//2 if(L[left]==k): return left elif(L[right]==k): return right elif(L[mid]==k): return mid elif(L[right]<k) or (L[left]>k): return -1 elif(L[mid]<k): return binarysearch(L,mid+1,right,k) elif(L[mid]>k): return binarysearch(L,left,mid,k) else: return -1 def theorem(n): if(n==0): return '0'+' '+'0'+' '+'0' elif(n==1): return '1'+' '+'0'+' '+'0' elif(n==2): return '1'+' '+'1'+' '+'0' elif(n==3): return '1'+' '+'1'+' '+'1' else: L=[0,1,1]+[-1]*(43) for i in range(2,len(L)): L[i]=L[i-1]+L[i-2] k=binarysearch(L,0,len(L)-1,n) return str(L[k-2])+" "+str(L[k-2])+" "+str(L[k-3]) n=int(input()) print(theorem(n)) ```
output
1
14,437
20
28,875
Provide tags and a correct Python 3 solution for this coding contest problem. Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers. Let's remember how Fibonacci numbers can be calculated. F0 = 0, F1 = 1, and all the next numbers are Fi = Fi - 2 + Fi - 1. So, Fibonacci numbers make a sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13, ... If you haven't run away from the PC in fear, you have to help the virus. Your task is to divide given Fibonacci number n by three not necessary different Fibonacci numbers or say that it is impossible. Input The input contains of a single integer n (0 ≀ n < 109) β€” the number that should be represented by the rules described above. It is guaranteed that n is a Fibonacci number. Output Output three required numbers: a, b and c. If there is no answer for the test you have to print "I'm too stupid to solve this problem" without the quotes. If there are multiple answers, print any of them. Examples Input 3 Output 1 1 1 Input 13 Output 2 3 8
instruction
0
14,438
20
28,876
Tags: brute force, constructive algorithms, implementation, number theory Correct Solution: ``` # Name : Jugal Kishore Chanda # East West University # Dept of Cse n = int(input()) print("0 0 {}".format(n)) ```
output
1
14,438
20
28,877
Provide tags and a correct Python 3 solution for this coding contest problem. Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers. Let's remember how Fibonacci numbers can be calculated. F0 = 0, F1 = 1, and all the next numbers are Fi = Fi - 2 + Fi - 1. So, Fibonacci numbers make a sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13, ... If you haven't run away from the PC in fear, you have to help the virus. Your task is to divide given Fibonacci number n by three not necessary different Fibonacci numbers or say that it is impossible. Input The input contains of a single integer n (0 ≀ n < 109) β€” the number that should be represented by the rules described above. It is guaranteed that n is a Fibonacci number. Output Output three required numbers: a, b and c. If there is no answer for the test you have to print "I'm too stupid to solve this problem" without the quotes. If there are multiple answers, print any of them. Examples Input 3 Output 1 1 1 Input 13 Output 2 3 8
instruction
0
14,439
20
28,878
Tags: brute force, constructive algorithms, implementation, number theory Correct Solution: ``` n = int(input()) re_list = [0] a, b = 0, 1 while b < n: re_list.append(b) a, b = b, a+b if n == 0: print("0 0 0") elif n == 1: print("0 0 1") else: print(0, re_list[-2], re_list[-1]) ```
output
1
14,439
20
28,879
Provide tags and a correct Python 3 solution for this coding contest problem. Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers. Let's remember how Fibonacci numbers can be calculated. F0 = 0, F1 = 1, and all the next numbers are Fi = Fi - 2 + Fi - 1. So, Fibonacci numbers make a sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13, ... If you haven't run away from the PC in fear, you have to help the virus. Your task is to divide given Fibonacci number n by three not necessary different Fibonacci numbers or say that it is impossible. Input The input contains of a single integer n (0 ≀ n < 109) β€” the number that should be represented by the rules described above. It is guaranteed that n is a Fibonacci number. Output Output three required numbers: a, b and c. If there is no answer for the test you have to print "I'm too stupid to solve this problem" without the quotes. If there are multiple answers, print any of them. Examples Input 3 Output 1 1 1 Input 13 Output 2 3 8
instruction
0
14,440
20
28,880
Tags: brute force, constructive algorithms, implementation, number theory Correct Solution: ``` def calc(foo): if foo == 2: print("0 1 1") return if foo == 3: print("1 1 1") return if foo == 0: print("0 0 0") return if foo == 1: print("1 0 0") return fibo = [0, 1] while fibo[-1] < foo and fibo[-1] + fibo[-2] < foo: fibo.append(fibo[-1] + fibo[-2]) verifier = fibo[-1] + fibo[-3] + fibo[-4] if verifier != foo: print("I'm too stupid to solve this problem") return print(fibo[-1], fibo[-3], fibo[-4]) return num = int(input()) calc(num) ```
output
1
14,440
20
28,881
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers. Let's remember how Fibonacci numbers can be calculated. F0 = 0, F1 = 1, and all the next numbers are Fi = Fi - 2 + Fi - 1. So, Fibonacci numbers make a sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13, ... If you haven't run away from the PC in fear, you have to help the virus. Your task is to divide given Fibonacci number n by three not necessary different Fibonacci numbers or say that it is impossible. Input The input contains of a single integer n (0 ≀ n < 109) β€” the number that should be represented by the rules described above. It is guaranteed that n is a Fibonacci number. Output Output three required numbers: a, b and c. If there is no answer for the test you have to print "I'm too stupid to solve this problem" without the quotes. If there are multiple answers, print any of them. Examples Input 3 Output 1 1 1 Input 13 Output 2 3 8 Submitted Solution: ``` #119A def main(): from sys import stdin, stdout a=[0,1,1] for _ in range(43): a.append(a[-1]+a[-2]) #print(a) #print(len(a)) #print(a[-1]) n = int(stdin.readline()) if n==0: print(0,0,0) return fp = 0 sp = 45 while fp<sp: if a[fp]+a[sp] == n: break elif a[fp]+a[sp] < n: fp+=1 elif a[fp]+a[sp] > n: sp-=1 if a[fp]+a[sp]==n: stdout.write(str(a[fp])+' '+str(a[sp-2])+' '+str(a[sp-1])+'\n') else: stdout.write("I'm too stupid to solve this problem\n") if __name__=='__main__': main() ```
instruction
0
14,441
20
28,882
Yes
output
1
14,441
20
28,883
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers. Let's remember how Fibonacci numbers can be calculated. F0 = 0, F1 = 1, and all the next numbers are Fi = Fi - 2 + Fi - 1. So, Fibonacci numbers make a sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13, ... If you haven't run away from the PC in fear, you have to help the virus. Your task is to divide given Fibonacci number n by three not necessary different Fibonacci numbers or say that it is impossible. Input The input contains of a single integer n (0 ≀ n < 109) β€” the number that should be represented by the rules described above. It is guaranteed that n is a Fibonacci number. Output Output three required numbers: a, b and c. If there is no answer for the test you have to print "I'm too stupid to solve this problem" without the quotes. If there are multiple answers, print any of them. Examples Input 3 Output 1 1 1 Input 13 Output 2 3 8 Submitted Solution: ``` t=int(input()) c=0 d=1 a=[0,1] while d<t: sum=c+d a.append(sum) c=d d=sum x=0 w=1 j=0 k=0 l=0 if t==0: print("0 0 0") w=0 elif t==1: print("0 0 1") w=0 elif t==2: print("0 1 1") w=0 else: while x+2<a.index(t)-1: if a[len(a)-2]+a[len(a)-4]+a[len(a)-5]==t: print(f"{a[len(a)-5]} {a[len(a)-4]} {a[len(a)-2]}") w=0 break else: x+=1 if w==1: print("I'm too stupid to solve this problem") ```
instruction
0
14,442
20
28,884
Yes
output
1
14,442
20
28,885
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers. Let's remember how Fibonacci numbers can be calculated. F0 = 0, F1 = 1, and all the next numbers are Fi = Fi - 2 + Fi - 1. So, Fibonacci numbers make a sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13, ... If you haven't run away from the PC in fear, you have to help the virus. Your task is to divide given Fibonacci number n by three not necessary different Fibonacci numbers or say that it is impossible. Input The input contains of a single integer n (0 ≀ n < 109) β€” the number that should be represented by the rules described above. It is guaranteed that n is a Fibonacci number. Output Output three required numbers: a, b and c. If there is no answer for the test you have to print "I'm too stupid to solve this problem" without the quotes. If there are multiple answers, print any of them. Examples Input 3 Output 1 1 1 Input 13 Output 2 3 8 Submitted Solution: ``` buffer=[1,1,2,3,5] n=int(input()) if n==0: print(0,0,0) elif n==1: print(1,0,0) elif n==2: print(1,0,1) elif n==3: print(1,1,1) else: while buffer[-1]!=n: buffer.append(buffer[-1]+buffer[-2]) del(buffer[0]) print(buffer[0],buffer[1],buffer[3]) ```
instruction
0
14,443
20
28,886
Yes
output
1
14,443
20
28,887