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. Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers. Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Roma's got n positive integers. He wonders, how many of those integers have not more than k lucky digits? Help him, write the program that solves the problem. Input The first line contains two integers n, k (1 ≀ n, k ≀ 100). The second line contains n integers ai (1 ≀ ai ≀ 109) β€” the numbers that Roma has. The numbers in the lines are separated by single spaces. Output In a single line print a single integer β€” the answer to the problem. Examples Input 3 4 1 2 4 Output 3 Input 3 2 447 44 77 Output 2 Note In the first sample all numbers contain at most four lucky digits, so the answer is 3. In the second sample number 447 doesn't fit in, as it contains more than two lucky digits. All other numbers are fine, so the answer is 2.
instruction
0
23,153
20
46,306
Tags: implementation Correct Solution: ``` a, b = map(int, input().split()) ar = input().split() rez = 0 for i in ar: if i.count('4') + i.count('7') <= b: rez += 1 print(rez) ```
output
1
23,153
20
46,307
Provide tags and a correct Python 3 solution for this coding contest problem. Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers. Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Roma's got n positive integers. He wonders, how many of those integers have not more than k lucky digits? Help him, write the program that solves the problem. Input The first line contains two integers n, k (1 ≀ n, k ≀ 100). The second line contains n integers ai (1 ≀ ai ≀ 109) β€” the numbers that Roma has. The numbers in the lines are separated by single spaces. Output In a single line print a single integer β€” the answer to the problem. Examples Input 3 4 1 2 4 Output 3 Input 3 2 447 44 77 Output 2 Note In the first sample all numbers contain at most four lucky digits, so the answer is 3. In the second sample number 447 doesn't fit in, as it contains more than two lucky digits. All other numbers are fine, so the answer is 2.
instruction
0
23,154
20
46,308
Tags: implementation Correct Solution: ``` # bsdk idhar kya dekhne ko aaya hai, khud kr!!! # from math import * # from itertools import * # import random n, k = map(int, input().split()) arr = list(map(str, input().split())) count_ = 0 for i in arr: if (i.count("4") + i.count("7")) > k: continue else: count_ += 1 print(count_) ```
output
1
23,154
20
46,309
Provide tags and a correct Python 3 solution for this coding contest problem. Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers. Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Roma's got n positive integers. He wonders, how many of those integers have not more than k lucky digits? Help him, write the program that solves the problem. Input The first line contains two integers n, k (1 ≀ n, k ≀ 100). The second line contains n integers ai (1 ≀ ai ≀ 109) β€” the numbers that Roma has. The numbers in the lines are separated by single spaces. Output In a single line print a single integer β€” the answer to the problem. Examples Input 3 4 1 2 4 Output 3 Input 3 2 447 44 77 Output 2 Note In the first sample all numbers contain at most four lucky digits, so the answer is 3. In the second sample number 447 doesn't fit in, as it contains more than two lucky digits. All other numbers are fine, so the answer is 2.
instruction
0
23,155
20
46,310
Tags: implementation Correct Solution: ``` n,k = list(map(int,input().split())) a = list(map(str,input().split())) count=0 for i in a: x=i.count('4') y=i.count('7') if x+y > k: count+=1 print(len(a)-count) ```
output
1
23,155
20
46,311
Provide tags and a correct Python 3 solution for this coding contest problem. Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers. Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Roma's got n positive integers. He wonders, how many of those integers have not more than k lucky digits? Help him, write the program that solves the problem. Input The first line contains two integers n, k (1 ≀ n, k ≀ 100). The second line contains n integers ai (1 ≀ ai ≀ 109) β€” the numbers that Roma has. The numbers in the lines are separated by single spaces. Output In a single line print a single integer β€” the answer to the problem. Examples Input 3 4 1 2 4 Output 3 Input 3 2 447 44 77 Output 2 Note In the first sample all numbers contain at most four lucky digits, so the answer is 3. In the second sample number 447 doesn't fit in, as it contains more than two lucky digits. All other numbers are fine, so the answer is 2.
instruction
0
23,156
20
46,312
Tags: implementation Correct Solution: ``` n, k = map(int, input().split()) L = [int(x) for x in input().split()] ct = 0 for pp in L : c = 0 p = int(pp) while (p >= 1) : if (p % 10 == 4) or (p % 10 == 7) : c = c + 1 p = int(p / 10) if (c <= k) : ct += 1 print(ct) ```
output
1
23,156
20
46,313
Provide tags and a correct Python 3 solution for this coding contest problem. Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers. Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Roma's got n positive integers. He wonders, how many of those integers have not more than k lucky digits? Help him, write the program that solves the problem. Input The first line contains two integers n, k (1 ≀ n, k ≀ 100). The second line contains n integers ai (1 ≀ ai ≀ 109) β€” the numbers that Roma has. The numbers in the lines are separated by single spaces. Output In a single line print a single integer β€” the answer to the problem. Examples Input 3 4 1 2 4 Output 3 Input 3 2 447 44 77 Output 2 Note In the first sample all numbers contain at most four lucky digits, so the answer is 3. In the second sample number 447 doesn't fit in, as it contains more than two lucky digits. All other numbers are fine, so the answer is 2.
instruction
0
23,157
20
46,314
Tags: implementation Correct Solution: ``` import math from collections import defaultdict ml=lambda:map(int,input().split()) ll=lambda:list(map(int,input().split())) ii=lambda:int(input()) ip=lambda:list(input()) ips=lambda:input().split() """========main code===============""" a,b=ml() ans=0 l=list(input().split()) for i in l: k=i w=0 for i in k: if(i=='4' or i=='7'): w+=1 if(w<=b): ans+=1 print(ans) ```
output
1
23,157
20
46,315
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers. Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Roma's got n positive integers. He wonders, how many of those integers have not more than k lucky digits? Help him, write the program that solves the problem. Input The first line contains two integers n, k (1 ≀ n, k ≀ 100). The second line contains n integers ai (1 ≀ ai ≀ 109) β€” the numbers that Roma has. The numbers in the lines are separated by single spaces. Output In a single line print a single integer β€” the answer to the problem. Examples Input 3 4 1 2 4 Output 3 Input 3 2 447 44 77 Output 2 Note In the first sample all numbers contain at most four lucky digits, so the answer is 3. In the second sample number 447 doesn't fit in, as it contains more than two lucky digits. All other numbers are fine, so the answer is 2. Submitted Solution: ``` # cook your dish here n,k = map(int, input().split()) l = list(map(str, input().split())) ans =0 for i in l: if(i.count('4') + i.count('7') <= k): ans += 1 print(ans) ```
instruction
0
23,158
20
46,316
Yes
output
1
23,158
20
46,317
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers. Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Roma's got n positive integers. He wonders, how many of those integers have not more than k lucky digits? Help him, write the program that solves the problem. Input The first line contains two integers n, k (1 ≀ n, k ≀ 100). The second line contains n integers ai (1 ≀ ai ≀ 109) β€” the numbers that Roma has. The numbers in the lines are separated by single spaces. Output In a single line print a single integer β€” the answer to the problem. Examples Input 3 4 1 2 4 Output 3 Input 3 2 447 44 77 Output 2 Note In the first sample all numbers contain at most four lucky digits, so the answer is 3. In the second sample number 447 doesn't fit in, as it contains more than two lucky digits. All other numbers are fine, so the answer is 2. Submitted Solution: ``` a=input() a=a.split() a1=int(a[0]) a2=int(a[1]) b=input() b=b.split() con=0 for k in range (a1): d=b[k].count("7") e=b[k].count("4") z=d+e if z<=a2: con=con+1 print(con) ```
instruction
0
23,159
20
46,318
Yes
output
1
23,159
20
46,319
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers. Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Roma's got n positive integers. He wonders, how many of those integers have not more than k lucky digits? Help him, write the program that solves the problem. Input The first line contains two integers n, k (1 ≀ n, k ≀ 100). The second line contains n integers ai (1 ≀ ai ≀ 109) β€” the numbers that Roma has. The numbers in the lines are separated by single spaces. Output In a single line print a single integer β€” the answer to the problem. Examples Input 3 4 1 2 4 Output 3 Input 3 2 447 44 77 Output 2 Note In the first sample all numbers contain at most four lucky digits, so the answer is 3. In the second sample number 447 doesn't fit in, as it contains more than two lucky digits. All other numbers are fine, so the answer is 2. Submitted Solution: ``` n,k=map(int,input().split()) l=list(map(int,input().split())) c=0 for i in l: x=str(i) if x.count('4')+x.count('7')<=k: c+=1 print(c) ```
instruction
0
23,160
20
46,320
Yes
output
1
23,160
20
46,321
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers. Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Roma's got n positive integers. He wonders, how many of those integers have not more than k lucky digits? Help him, write the program that solves the problem. Input The first line contains two integers n, k (1 ≀ n, k ≀ 100). The second line contains n integers ai (1 ≀ ai ≀ 109) β€” the numbers that Roma has. The numbers in the lines are separated by single spaces. Output In a single line print a single integer β€” the answer to the problem. Examples Input 3 4 1 2 4 Output 3 Input 3 2 447 44 77 Output 2 Note In the first sample all numbers contain at most four lucky digits, so the answer is 3. In the second sample number 447 doesn't fit in, as it contains more than two lucky digits. All other numbers are fine, so the answer is 2. Submitted Solution: ``` n, k = map(int, input().split()) a = list(input().split()) ans = 0 for i in range(n): if a[i].count('4') + a[i].count('7') <= k: ans += 1 print(ans) ```
instruction
0
23,161
20
46,322
Yes
output
1
23,161
20
46,323
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers. Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Roma's got n positive integers. He wonders, how many of those integers have not more than k lucky digits? Help him, write the program that solves the problem. Input The first line contains two integers n, k (1 ≀ n, k ≀ 100). The second line contains n integers ai (1 ≀ ai ≀ 109) β€” the numbers that Roma has. The numbers in the lines are separated by single spaces. Output In a single line print a single integer β€” the answer to the problem. Examples Input 3 4 1 2 4 Output 3 Input 3 2 447 44 77 Output 2 Note In the first sample all numbers contain at most four lucky digits, so the answer is 3. In the second sample number 447 doesn't fit in, as it contains more than two lucky digits. All other numbers are fine, so the answer is 2. Submitted Solution: ``` n,k=map(int,input().split()) a=input().split() count=0 for i in range(n): x=a.count('4')+a.count('7') if x<=k: count+=1 print(count) ```
instruction
0
23,162
20
46,324
No
output
1
23,162
20
46,325
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers. Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Roma's got n positive integers. He wonders, how many of those integers have not more than k lucky digits? Help him, write the program that solves the problem. Input The first line contains two integers n, k (1 ≀ n, k ≀ 100). The second line contains n integers ai (1 ≀ ai ≀ 109) β€” the numbers that Roma has. The numbers in the lines are separated by single spaces. Output In a single line print a single integer β€” the answer to the problem. Examples Input 3 4 1 2 4 Output 3 Input 3 2 447 44 77 Output 2 Note In the first sample all numbers contain at most four lucky digits, so the answer is 3. In the second sample number 447 doesn't fit in, as it contains more than two lucky digits. All other numbers are fine, so the answer is 2. Submitted Solution: ``` n,k=map(int,input().split()) a=list(input().split()) m=0 for i in a: x=i.count('4' and '7') if x<k: m+=1 print(m) ```
instruction
0
23,163
20
46,326
No
output
1
23,163
20
46,327
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers. Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Roma's got n positive integers. He wonders, how many of those integers have not more than k lucky digits? Help him, write the program that solves the problem. Input The first line contains two integers n, k (1 ≀ n, k ≀ 100). The second line contains n integers ai (1 ≀ ai ≀ 109) β€” the numbers that Roma has. The numbers in the lines are separated by single spaces. Output In a single line print a single integer β€” the answer to the problem. Examples Input 3 4 1 2 4 Output 3 Input 3 2 447 44 77 Output 2 Note In the first sample all numbers contain at most four lucky digits, so the answer is 3. In the second sample number 447 doesn't fit in, as it contains more than two lucky digits. All other numbers are fine, so the answer is 2. Submitted Solution: ``` nk = input() s = input() k = nk.split()[1] lucky = 0 ans = 0 for i in s.split(' '): for m in range(len(i)): if i[m]=='4' or i[m]=='7': lucky += 1 if lucky<=int(k): ans+=1 print(ans) ```
instruction
0
23,164
20
46,328
No
output
1
23,164
20
46,329
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers. Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Roma's got n positive integers. He wonders, how many of those integers have not more than k lucky digits? Help him, write the program that solves the problem. Input The first line contains two integers n, k (1 ≀ n, k ≀ 100). The second line contains n integers ai (1 ≀ ai ≀ 109) β€” the numbers that Roma has. The numbers in the lines are separated by single spaces. Output In a single line print a single integer β€” the answer to the problem. Examples Input 3 4 1 2 4 Output 3 Input 3 2 447 44 77 Output 2 Note In the first sample all numbers contain at most four lucky digits, so the answer is 3. In the second sample number 447 doesn't fit in, as it contains more than two lucky digits. All other numbers are fine, so the answer is 2. Submitted Solution: ``` def getLuckyCount(num) : return len([i for i in num if i == '4' or '7']) n , k = map(int , input().split(" ")) numbers = input().split(" ") print(len([i for i in numbers if getLuckyCount(i) <= k])) ```
instruction
0
23,165
20
46,330
No
output
1
23,165
20
46,331
Provide tags and a correct Python 3 solution for this coding contest problem. Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits. Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a1, a2, ..., an / k and b1, b2, ..., bn / k. Let's split the phone number into blocks of length k. The first block will be formed by digits from the phone number that are on positions 1, 2,..., k, the second block will be formed by digits from the phone number that are on positions k + 1, k + 2, ..., 2Β·k and so on. Pasha considers a phone number good, if the i-th block doesn't start from the digit bi and is divisible by ai if represented as an integer. To represent the block of length k as an integer, let's write it out as a sequence c1, c2,...,ck. Then the integer is calculated as the result of the expression c1Β·10k - 1 + c2Β·10k - 2 + ... + ck. Pasha asks you to calculate the number of good phone numbers of length n, for the given k, ai and bi. As this number can be too big, print it modulo 109 + 7. Input The first line of the input contains two integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ min(n, 9)) β€” the length of all phone numbers and the length of each block, respectively. It is guaranteed that n is divisible by k. The second line of the input contains n / k space-separated positive integers β€” sequence a1, a2, ..., an / k (1 ≀ ai < 10k). The third line of the input contains n / k space-separated positive integers β€” sequence b1, b2, ..., bn / k (0 ≀ bi ≀ 9). Output Print a single integer β€” the number of good phone numbers of length n modulo 109 + 7. Examples Input 6 2 38 56 49 7 3 4 Output 8 Input 8 2 1 22 3 44 5 4 3 2 Output 32400 Note In the first test sample good phone numbers are: 000000, 000098, 005600, 005698, 380000, 380098, 385600, 385698.
instruction
0
23,310
20
46,620
Tags: binary search, math Correct Solution: ``` n, k = map(int, input().split()) ara = list(map( int, input().split())) arb = list(map( int, input().split())) sum1 = 1; p_k = 10**k p_k1 = 10**(k - 1) p_k2 = 10**(k - 2) M = 10**9 + 7 for i in range(n // k): k = 0 if (p_k % ara[i] == 0): k = -1 if ((arb[i] + 1) * p_k1 % ara[i] == 0): k = k + 1 if ((arb[i]) * p_k1 % ara[i] == 0): k = k - 1 sum1 *= p_k // ara[i] - p_k1 * (arb[i] + 1) // ara[i] + p_k1 * (arb[i]) // ara[i] + k + 1 #first = p_k1 * arb[i] // ara[i] * (ara[i] + 1) #print(p_k // ara[i] + k + 1, p_k1 * (arb[i] + 1) // ara[i], p_k1 * (arb[i]) // ara[i]) #sum1 *= p_k // ara[i] + 1 - p_k1 // first sum1 = sum1 % M print(sum1 % (10**9+7)) ```
output
1
23,310
20
46,621
Provide tags and a correct Python 3 solution for this coding contest problem. Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits. Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a1, a2, ..., an / k and b1, b2, ..., bn / k. Let's split the phone number into blocks of length k. The first block will be formed by digits from the phone number that are on positions 1, 2,..., k, the second block will be formed by digits from the phone number that are on positions k + 1, k + 2, ..., 2Β·k and so on. Pasha considers a phone number good, if the i-th block doesn't start from the digit bi and is divisible by ai if represented as an integer. To represent the block of length k as an integer, let's write it out as a sequence c1, c2,...,ck. Then the integer is calculated as the result of the expression c1Β·10k - 1 + c2Β·10k - 2 + ... + ck. Pasha asks you to calculate the number of good phone numbers of length n, for the given k, ai and bi. As this number can be too big, print it modulo 109 + 7. Input The first line of the input contains two integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ min(n, 9)) β€” the length of all phone numbers and the length of each block, respectively. It is guaranteed that n is divisible by k. The second line of the input contains n / k space-separated positive integers β€” sequence a1, a2, ..., an / k (1 ≀ ai < 10k). The third line of the input contains n / k space-separated positive integers β€” sequence b1, b2, ..., bn / k (0 ≀ bi ≀ 9). Output Print a single integer β€” the number of good phone numbers of length n modulo 109 + 7. Examples Input 6 2 38 56 49 7 3 4 Output 8 Input 8 2 1 22 3 44 5 4 3 2 Output 32400 Note In the first test sample good phone numbers are: 000000, 000098, 005600, 005698, 380000, 380098, 385600, 385698.
instruction
0
23,311
20
46,622
Tags: binary search, math Correct Solution: ``` n1=input() q,w=n1.split() n=int(q) k=int(w) n2=input() A1=n2.split() n3=input() B1=n3.split() x="" y="" A=[] B=[] for i in range(0,n//k): A.append(int(A1[i])) B.append(int(B1[i])) for i in range(0,k-1): x+='0' y+='9' fin=0 for i in range(0,n//k): ans=int('9'+y)//A[i]+1 #print(ans) h=int(str(B[i])+x) g=int(str(B[i])+y) d=g-g%A[i] #print(d) #rint(h) if(d>=h): ans-=(((d-h)//A[i])+1) if(fin==0 and ans>0): fin=1 fin=(fin*ans)%1000000007 print(fin) ```
output
1
23,311
20
46,623
Provide tags and a correct Python 3 solution for this coding contest problem. Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits. Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a1, a2, ..., an / k and b1, b2, ..., bn / k. Let's split the phone number into blocks of length k. The first block will be formed by digits from the phone number that are on positions 1, 2,..., k, the second block will be formed by digits from the phone number that are on positions k + 1, k + 2, ..., 2Β·k and so on. Pasha considers a phone number good, if the i-th block doesn't start from the digit bi and is divisible by ai if represented as an integer. To represent the block of length k as an integer, let's write it out as a sequence c1, c2,...,ck. Then the integer is calculated as the result of the expression c1Β·10k - 1 + c2Β·10k - 2 + ... + ck. Pasha asks you to calculate the number of good phone numbers of length n, for the given k, ai and bi. As this number can be too big, print it modulo 109 + 7. Input The first line of the input contains two integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ min(n, 9)) β€” the length of all phone numbers and the length of each block, respectively. It is guaranteed that n is divisible by k. The second line of the input contains n / k space-separated positive integers β€” sequence a1, a2, ..., an / k (1 ≀ ai < 10k). The third line of the input contains n / k space-separated positive integers β€” sequence b1, b2, ..., bn / k (0 ≀ bi ≀ 9). Output Print a single integer β€” the number of good phone numbers of length n modulo 109 + 7. Examples Input 6 2 38 56 49 7 3 4 Output 8 Input 8 2 1 22 3 44 5 4 3 2 Output 32400 Note In the first test sample good phone numbers are: 000000, 000098, 005600, 005698, 380000, 380098, 385600, 385698.
instruction
0
23,312
20
46,624
Tags: binary search, math Correct Solution: ``` def get_multypler(k, a, b): res = (10 ** k - 1) // a + 1 bad_residue = (a - ((10 ** (k - 1)) * b) % a) % a suf = (10 ** (k - 1)) - 1 minus = suf // a + (1 if (bad_residue <= suf % a) else 0) return res - minus n, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) ans = 1 for i in range(n // k): ans *= get_multypler(k, a[i], b[i]) ans %= 10 ** 9 + 7 print(ans) ```
output
1
23,312
20
46,625
Provide tags and a correct Python 3 solution for this coding contest problem. Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits. Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a1, a2, ..., an / k and b1, b2, ..., bn / k. Let's split the phone number into blocks of length k. The first block will be formed by digits from the phone number that are on positions 1, 2,..., k, the second block will be formed by digits from the phone number that are on positions k + 1, k + 2, ..., 2Β·k and so on. Pasha considers a phone number good, if the i-th block doesn't start from the digit bi and is divisible by ai if represented as an integer. To represent the block of length k as an integer, let's write it out as a sequence c1, c2,...,ck. Then the integer is calculated as the result of the expression c1Β·10k - 1 + c2Β·10k - 2 + ... + ck. Pasha asks you to calculate the number of good phone numbers of length n, for the given k, ai and bi. As this number can be too big, print it modulo 109 + 7. Input The first line of the input contains two integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ min(n, 9)) β€” the length of all phone numbers and the length of each block, respectively. It is guaranteed that n is divisible by k. The second line of the input contains n / k space-separated positive integers β€” sequence a1, a2, ..., an / k (1 ≀ ai < 10k). The third line of the input contains n / k space-separated positive integers β€” sequence b1, b2, ..., bn / k (0 ≀ bi ≀ 9). Output Print a single integer β€” the number of good phone numbers of length n modulo 109 + 7. Examples Input 6 2 38 56 49 7 3 4 Output 8 Input 8 2 1 22 3 44 5 4 3 2 Output 32400 Note In the first test sample good phone numbers are: 000000, 000098, 005600, 005698, 380000, 380098, 385600, 385698.
instruction
0
23,313
20
46,626
Tags: binary search, math Correct Solution: ``` from math import * MOD = 1000000007 n, k = map(int, input().split()) a = [int(i) for i in input().split()] b = [int(i) for i in input().split()] res = 1 for i in range(n // k): cont = ceil(10**k / a[i]) - ceil((b[i] + 1) * 10**(k-1) / a[i]) + ceil(b[i] * 10**(k-1) / a[i]) # print(cont) res = (res * cont) % MOD print(res) ```
output
1
23,313
20
46,627
Provide tags and a correct Python 3 solution for this coding contest problem. Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits. Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a1, a2, ..., an / k and b1, b2, ..., bn / k. Let's split the phone number into blocks of length k. The first block will be formed by digits from the phone number that are on positions 1, 2,..., k, the second block will be formed by digits from the phone number that are on positions k + 1, k + 2, ..., 2Β·k and so on. Pasha considers a phone number good, if the i-th block doesn't start from the digit bi and is divisible by ai if represented as an integer. To represent the block of length k as an integer, let's write it out as a sequence c1, c2,...,ck. Then the integer is calculated as the result of the expression c1Β·10k - 1 + c2Β·10k - 2 + ... + ck. Pasha asks you to calculate the number of good phone numbers of length n, for the given k, ai and bi. As this number can be too big, print it modulo 109 + 7. Input The first line of the input contains two integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ min(n, 9)) β€” the length of all phone numbers and the length of each block, respectively. It is guaranteed that n is divisible by k. The second line of the input contains n / k space-separated positive integers β€” sequence a1, a2, ..., an / k (1 ≀ ai < 10k). The third line of the input contains n / k space-separated positive integers β€” sequence b1, b2, ..., bn / k (0 ≀ bi ≀ 9). Output Print a single integer β€” the number of good phone numbers of length n modulo 109 + 7. Examples Input 6 2 38 56 49 7 3 4 Output 8 Input 8 2 1 22 3 44 5 4 3 2 Output 32400 Note In the first test sample good phone numbers are: 000000, 000098, 005600, 005698, 380000, 380098, 385600, 385698.
instruction
0
23,314
20
46,628
Tags: binary search, math Correct Solution: ``` n, k = [ int(_) for _ in input().split()] a = [int(_) for _ in input().split()] b = [int(_) for _ in input().split()] MOD = 10**9 + 7 ans = 1 for i in range(n // k): alls = (10 ** k - 1) // a[i] + 1 subt = ((b[i] * (10 ** (k - 1))) + (10 ** (k - 1) - 1)) // a[i] subt -= (b[i] * (10 ** (k - 1)) - 1) // a[i] alls -= subt ans *= alls ans %= MOD print(ans) ```
output
1
23,314
20
46,629
Provide tags and a correct Python 3 solution for this coding contest problem. Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits. Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a1, a2, ..., an / k and b1, b2, ..., bn / k. Let's split the phone number into blocks of length k. The first block will be formed by digits from the phone number that are on positions 1, 2,..., k, the second block will be formed by digits from the phone number that are on positions k + 1, k + 2, ..., 2Β·k and so on. Pasha considers a phone number good, if the i-th block doesn't start from the digit bi and is divisible by ai if represented as an integer. To represent the block of length k as an integer, let's write it out as a sequence c1, c2,...,ck. Then the integer is calculated as the result of the expression c1Β·10k - 1 + c2Β·10k - 2 + ... + ck. Pasha asks you to calculate the number of good phone numbers of length n, for the given k, ai and bi. As this number can be too big, print it modulo 109 + 7. Input The first line of the input contains two integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ min(n, 9)) β€” the length of all phone numbers and the length of each block, respectively. It is guaranteed that n is divisible by k. The second line of the input contains n / k space-separated positive integers β€” sequence a1, a2, ..., an / k (1 ≀ ai < 10k). The third line of the input contains n / k space-separated positive integers β€” sequence b1, b2, ..., bn / k (0 ≀ bi ≀ 9). Output Print a single integer β€” the number of good phone numbers of length n modulo 109 + 7. Examples Input 6 2 38 56 49 7 3 4 Output 8 Input 8 2 1 22 3 44 5 4 3 2 Output 32400 Note In the first test sample good phone numbers are: 000000, 000098, 005600, 005698, 380000, 380098, 385600, 385698.
instruction
0
23,315
20
46,630
Tags: binary search, math Correct Solution: ``` def c(a, b, k): v = (10 ** k - 1) // a + 1 v -= (10 ** (k - 1) * (b + 1) - 1) // a - (10 ** (k - 1) * b - 1) // a return v MOD, v = 1000000007, 1 n, k = map(int, input().split()) for a, b in zip(map(int, input().split()), map(int, input().split())): v = (v * c(a, b, k)) % MOD print(v) ```
output
1
23,315
20
46,631
Provide tags and a correct Python 3 solution for this coding contest problem. Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits. Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a1, a2, ..., an / k and b1, b2, ..., bn / k. Let's split the phone number into blocks of length k. The first block will be formed by digits from the phone number that are on positions 1, 2,..., k, the second block will be formed by digits from the phone number that are on positions k + 1, k + 2, ..., 2Β·k and so on. Pasha considers a phone number good, if the i-th block doesn't start from the digit bi and is divisible by ai if represented as an integer. To represent the block of length k as an integer, let's write it out as a sequence c1, c2,...,ck. Then the integer is calculated as the result of the expression c1Β·10k - 1 + c2Β·10k - 2 + ... + ck. Pasha asks you to calculate the number of good phone numbers of length n, for the given k, ai and bi. As this number can be too big, print it modulo 109 + 7. Input The first line of the input contains two integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ min(n, 9)) β€” the length of all phone numbers and the length of each block, respectively. It is guaranteed that n is divisible by k. The second line of the input contains n / k space-separated positive integers β€” sequence a1, a2, ..., an / k (1 ≀ ai < 10k). The third line of the input contains n / k space-separated positive integers β€” sequence b1, b2, ..., bn / k (0 ≀ bi ≀ 9). Output Print a single integer β€” the number of good phone numbers of length n modulo 109 + 7. Examples Input 6 2 38 56 49 7 3 4 Output 8 Input 8 2 1 22 3 44 5 4 3 2 Output 32400 Note In the first test sample good phone numbers are: 000000, 000098, 005600, 005698, 380000, 380098, 385600, 385698.
instruction
0
23,316
20
46,632
Tags: binary search, math Correct Solution: ``` import math n, k = [int(x) for x in input().split()] a = [int(x) for x in input().split()] b = [int(x) for x in input().split()] c = 1 for i in range(n // k): count = (10 ** k - 1) // a[i] + 1 mmin = b[i] * (10 ** (k-1)) mmax = (b[i] + 1) * (10 ** (k-1)) - 1 mcount = mmax // a[i] - math.ceil(mmin / a[i]) + 1 c = (c * (count - mcount)) % ((10 ** 9) + 7) print(c) ```
output
1
23,316
20
46,633
Provide tags and a correct Python 3 solution for this coding contest problem. Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits. Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a1, a2, ..., an / k and b1, b2, ..., bn / k. Let's split the phone number into blocks of length k. The first block will be formed by digits from the phone number that are on positions 1, 2,..., k, the second block will be formed by digits from the phone number that are on positions k + 1, k + 2, ..., 2Β·k and so on. Pasha considers a phone number good, if the i-th block doesn't start from the digit bi and is divisible by ai if represented as an integer. To represent the block of length k as an integer, let's write it out as a sequence c1, c2,...,ck. Then the integer is calculated as the result of the expression c1Β·10k - 1 + c2Β·10k - 2 + ... + ck. Pasha asks you to calculate the number of good phone numbers of length n, for the given k, ai and bi. As this number can be too big, print it modulo 109 + 7. Input The first line of the input contains two integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ min(n, 9)) β€” the length of all phone numbers and the length of each block, respectively. It is guaranteed that n is divisible by k. The second line of the input contains n / k space-separated positive integers β€” sequence a1, a2, ..., an / k (1 ≀ ai < 10k). The third line of the input contains n / k space-separated positive integers β€” sequence b1, b2, ..., bn / k (0 ≀ bi ≀ 9). Output Print a single integer β€” the number of good phone numbers of length n modulo 109 + 7. Examples Input 6 2 38 56 49 7 3 4 Output 8 Input 8 2 1 22 3 44 5 4 3 2 Output 32400 Note In the first test sample good phone numbers are: 000000, 000098, 005600, 005698, 380000, 380098, 385600, 385698.
instruction
0
23,317
20
46,634
Tags: binary search, math Correct Solution: ``` MOD=10**9+7 n,k=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) k1,k2,ans=10**k,10**(k-1),1 for i in range(n//k): z,x=a[i],b[i] if b[i]>0: c=(x*k2-1)//z+(k1-1)//z-((x+1)*k2-1)//z+1 else: c=(k1-1)//z-(k2-1)//z ans=ans*c%MOD print(ans) ```
output
1
23,317
20
46,635
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits. Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a1, a2, ..., an / k and b1, b2, ..., bn / k. Let's split the phone number into blocks of length k. The first block will be formed by digits from the phone number that are on positions 1, 2,..., k, the second block will be formed by digits from the phone number that are on positions k + 1, k + 2, ..., 2Β·k and so on. Pasha considers a phone number good, if the i-th block doesn't start from the digit bi and is divisible by ai if represented as an integer. To represent the block of length k as an integer, let's write it out as a sequence c1, c2,...,ck. Then the integer is calculated as the result of the expression c1Β·10k - 1 + c2Β·10k - 2 + ... + ck. Pasha asks you to calculate the number of good phone numbers of length n, for the given k, ai and bi. As this number can be too big, print it modulo 109 + 7. Input The first line of the input contains two integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ min(n, 9)) β€” the length of all phone numbers and the length of each block, respectively. It is guaranteed that n is divisible by k. The second line of the input contains n / k space-separated positive integers β€” sequence a1, a2, ..., an / k (1 ≀ ai < 10k). The third line of the input contains n / k space-separated positive integers β€” sequence b1, b2, ..., bn / k (0 ≀ bi ≀ 9). Output Print a single integer β€” the number of good phone numbers of length n modulo 109 + 7. Examples Input 6 2 38 56 49 7 3 4 Output 8 Input 8 2 1 22 3 44 5 4 3 2 Output 32400 Note In the first test sample good phone numbers are: 000000, 000098, 005600, 005698, 380000, 380098, 385600, 385698. Submitted Solution: ``` n,k = map(int,input().split()) a = list(map(int,input().split())) b = list(map(int,input().split())) answer = list() for i in range(n//k): res = 0 m = '1'+'0'*k m = int(m)-1 q = str(b[i]) + '9' * (k-1) q = int(q) c = str(b[i]-1) + '9' * (k-1) c = int(c) c = max(c,-1) #print(m,q,c) res = (m//a[i]+1) - q//a[i] + c//a[i] answer.append(res) resa = 1 #print(answer) if sum(answer)==0: print(0) else: for i in answer: resa = (resa*i)%1000000007 print(resa) ```
instruction
0
23,318
20
46,636
Yes
output
1
23,318
20
46,637
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits. Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a1, a2, ..., an / k and b1, b2, ..., bn / k. Let's split the phone number into blocks of length k. The first block will be formed by digits from the phone number that are on positions 1, 2,..., k, the second block will be formed by digits from the phone number that are on positions k + 1, k + 2, ..., 2Β·k and so on. Pasha considers a phone number good, if the i-th block doesn't start from the digit bi and is divisible by ai if represented as an integer. To represent the block of length k as an integer, let's write it out as a sequence c1, c2,...,ck. Then the integer is calculated as the result of the expression c1Β·10k - 1 + c2Β·10k - 2 + ... + ck. Pasha asks you to calculate the number of good phone numbers of length n, for the given k, ai and bi. As this number can be too big, print it modulo 109 + 7. Input The first line of the input contains two integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ min(n, 9)) β€” the length of all phone numbers and the length of each block, respectively. It is guaranteed that n is divisible by k. The second line of the input contains n / k space-separated positive integers β€” sequence a1, a2, ..., an / k (1 ≀ ai < 10k). The third line of the input contains n / k space-separated positive integers β€” sequence b1, b2, ..., bn / k (0 ≀ bi ≀ 9). Output Print a single integer β€” the number of good phone numbers of length n modulo 109 + 7. Examples Input 6 2 38 56 49 7 3 4 Output 8 Input 8 2 1 22 3 44 5 4 3 2 Output 32400 Note In the first test sample good phone numbers are: 000000, 000098, 005600, 005698, 380000, 380098, 385600, 385698. Submitted Solution: ``` import sys input = sys.stdin.readline n, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) MOD = 10**9+7 ans = 1 for ai, bi in zip(a, b): if bi==0: h = 10**(k-1)-1 cnt = h//ai+1 else: h = bi*10**(k-1)+10**(k-1)-1 l = (bi-1)*10**(k-1)+10**(k-1)-1 cnt = h//ai-l//ai ans *= (10**k-1)//ai+1-cnt ans %= MOD print(ans) ```
instruction
0
23,319
20
46,638
Yes
output
1
23,319
20
46,639
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits. Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a1, a2, ..., an / k and b1, b2, ..., bn / k. Let's split the phone number into blocks of length k. The first block will be formed by digits from the phone number that are on positions 1, 2,..., k, the second block will be formed by digits from the phone number that are on positions k + 1, k + 2, ..., 2Β·k and so on. Pasha considers a phone number good, if the i-th block doesn't start from the digit bi and is divisible by ai if represented as an integer. To represent the block of length k as an integer, let's write it out as a sequence c1, c2,...,ck. Then the integer is calculated as the result of the expression c1Β·10k - 1 + c2Β·10k - 2 + ... + ck. Pasha asks you to calculate the number of good phone numbers of length n, for the given k, ai and bi. As this number can be too big, print it modulo 109 + 7. Input The first line of the input contains two integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ min(n, 9)) β€” the length of all phone numbers and the length of each block, respectively. It is guaranteed that n is divisible by k. The second line of the input contains n / k space-separated positive integers β€” sequence a1, a2, ..., an / k (1 ≀ ai < 10k). The third line of the input contains n / k space-separated positive integers β€” sequence b1, b2, ..., bn / k (0 ≀ bi ≀ 9). Output Print a single integer β€” the number of good phone numbers of length n modulo 109 + 7. Examples Input 6 2 38 56 49 7 3 4 Output 8 Input 8 2 1 22 3 44 5 4 3 2 Output 32400 Note In the first test sample good phone numbers are: 000000, 000098, 005600, 005698, 380000, 380098, 385600, 385698. Submitted Solution: ``` M = 10**9 + 7 def good(k, a, b): t = (10**k - 1) // a + 1 s = (b * 10**(k-1) - 1) // a + 1 e = ((b+1) * 10**(k-1) - 1) // a + 1 return (t - (e - s)) % M def total_good(k, ai, bi): p = 1 for a, b in zip(ai, bi): p = (p * good(k, a, b)) % M return p if __name__ == '__main__': n, k = map(int, input().split()) assert n % k == 0 ai = map(int, input().split()) bi = map(int, input().split()) print(total_good(k, ai, bi)) ```
instruction
0
23,320
20
46,640
Yes
output
1
23,320
20
46,641
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits. Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a1, a2, ..., an / k and b1, b2, ..., bn / k. Let's split the phone number into blocks of length k. The first block will be formed by digits from the phone number that are on positions 1, 2,..., k, the second block will be formed by digits from the phone number that are on positions k + 1, k + 2, ..., 2Β·k and so on. Pasha considers a phone number good, if the i-th block doesn't start from the digit bi and is divisible by ai if represented as an integer. To represent the block of length k as an integer, let's write it out as a sequence c1, c2,...,ck. Then the integer is calculated as the result of the expression c1Β·10k - 1 + c2Β·10k - 2 + ... + ck. Pasha asks you to calculate the number of good phone numbers of length n, for the given k, ai and bi. As this number can be too big, print it modulo 109 + 7. Input The first line of the input contains two integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ min(n, 9)) β€” the length of all phone numbers and the length of each block, respectively. It is guaranteed that n is divisible by k. The second line of the input contains n / k space-separated positive integers β€” sequence a1, a2, ..., an / k (1 ≀ ai < 10k). The third line of the input contains n / k space-separated positive integers β€” sequence b1, b2, ..., bn / k (0 ≀ bi ≀ 9). Output Print a single integer β€” the number of good phone numbers of length n modulo 109 + 7. Examples Input 6 2 38 56 49 7 3 4 Output 8 Input 8 2 1 22 3 44 5 4 3 2 Output 32400 Note In the first test sample good phone numbers are: 000000, 000098, 005600, 005698, 380000, 380098, 385600, 385698. Submitted Solution: ``` R = lambda : map(int,input().split()) n,k = R() t = 1 mod = 10**9+7 def gn(x,p): if x < 0: return 0 return x//p+1 def solve(a,b,k): if k == 1: return 9//a if b%a==0 else 9//a+1 m = b*pow(10,k-1,a)%a w = 10**(k-1)-1+m r = gn(10**k-1,a)-(gn(w,a)-gn(m-1,a)) return r a = list(R()) b = list(R()) for i in range(len(a)): t *= solve(a[i],b[i],k) t %= mod print(t%mod) ```
instruction
0
23,321
20
46,642
Yes
output
1
23,321
20
46,643
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits. Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a1, a2, ..., an / k and b1, b2, ..., bn / k. Let's split the phone number into blocks of length k. The first block will be formed by digits from the phone number that are on positions 1, 2,..., k, the second block will be formed by digits from the phone number that are on positions k + 1, k + 2, ..., 2Β·k and so on. Pasha considers a phone number good, if the i-th block doesn't start from the digit bi and is divisible by ai if represented as an integer. To represent the block of length k as an integer, let's write it out as a sequence c1, c2,...,ck. Then the integer is calculated as the result of the expression c1Β·10k - 1 + c2Β·10k - 2 + ... + ck. Pasha asks you to calculate the number of good phone numbers of length n, for the given k, ai and bi. As this number can be too big, print it modulo 109 + 7. Input The first line of the input contains two integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ min(n, 9)) β€” the length of all phone numbers and the length of each block, respectively. It is guaranteed that n is divisible by k. The second line of the input contains n / k space-separated positive integers β€” sequence a1, a2, ..., an / k (1 ≀ ai < 10k). The third line of the input contains n / k space-separated positive integers β€” sequence b1, b2, ..., bn / k (0 ≀ bi ≀ 9). Output Print a single integer β€” the number of good phone numbers of length n modulo 109 + 7. Examples Input 6 2 38 56 49 7 3 4 Output 8 Input 8 2 1 22 3 44 5 4 3 2 Output 32400 Note In the first test sample good phone numbers are: 000000, 000098, 005600, 005698, 380000, 380098, 385600, 385698. Submitted Solution: ``` n,k=map(int,input().split()) a=input().split() b=input().split() ans = 1 for i in range(0,n//k): a[i]=int(a[i]) b[i]=int(b[i]) cnt1 = ((10**k-1)//a[i]+1) cnt2 = ((b[i]+1)*(10**(k-1))-1)//a[i] cnt3 = ((b[i])*(10**(k-1))-1)//a[i] ans *= cnt1-(cnt2-cnt3) print(ans) ```
instruction
0
23,322
20
46,644
No
output
1
23,322
20
46,645
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits. Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a1, a2, ..., an / k and b1, b2, ..., bn / k. Let's split the phone number into blocks of length k. The first block will be formed by digits from the phone number that are on positions 1, 2,..., k, the second block will be formed by digits from the phone number that are on positions k + 1, k + 2, ..., 2Β·k and so on. Pasha considers a phone number good, if the i-th block doesn't start from the digit bi and is divisible by ai if represented as an integer. To represent the block of length k as an integer, let's write it out as a sequence c1, c2,...,ck. Then the integer is calculated as the result of the expression c1Β·10k - 1 + c2Β·10k - 2 + ... + ck. Pasha asks you to calculate the number of good phone numbers of length n, for the given k, ai and bi. As this number can be too big, print it modulo 109 + 7. Input The first line of the input contains two integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ min(n, 9)) β€” the length of all phone numbers and the length of each block, respectively. It is guaranteed that n is divisible by k. The second line of the input contains n / k space-separated positive integers β€” sequence a1, a2, ..., an / k (1 ≀ ai < 10k). The third line of the input contains n / k space-separated positive integers β€” sequence b1, b2, ..., bn / k (0 ≀ bi ≀ 9). Output Print a single integer β€” the number of good phone numbers of length n modulo 109 + 7. Examples Input 6 2 38 56 49 7 3 4 Output 8 Input 8 2 1 22 3 44 5 4 3 2 Output 32400 Note In the first test sample good phone numbers are: 000000, 000098, 005600, 005698, 380000, 380098, 385600, 385698. Submitted Solution: ``` def check(s1, s2, k): s1 = '0' * (k - len(s1)) + s1 for i in range(min(len(s1), len(s2))): if s1[i] == s2[i]: return False return True def f(a, c, k, b): i = 1 while True: if len(str(c[-i] + a[-i])) <= k: c[-i] += a[-i] if check(str(c[-i]), str(b[-i]), k): return c else: c[-i] = 0 i += 1 if i > len(c): return None n, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) cnt = 0 c = [0] * (n // k) for i in range(1, k + 1): if not check(str(c[-i]), str(b[-i]), k): c = f(a, c, k, b) if c != None: cnt += 1 while True: c = f(a, c, k, b) if c == None: break cnt += 1 print(cnt) ```
instruction
0
23,323
20
46,646
No
output
1
23,323
20
46,647
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits. Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a1, a2, ..., an / k and b1, b2, ..., bn / k. Let's split the phone number into blocks of length k. The first block will be formed by digits from the phone number that are on positions 1, 2,..., k, the second block will be formed by digits from the phone number that are on positions k + 1, k + 2, ..., 2Β·k and so on. Pasha considers a phone number good, if the i-th block doesn't start from the digit bi and is divisible by ai if represented as an integer. To represent the block of length k as an integer, let's write it out as a sequence c1, c2,...,ck. Then the integer is calculated as the result of the expression c1Β·10k - 1 + c2Β·10k - 2 + ... + ck. Pasha asks you to calculate the number of good phone numbers of length n, for the given k, ai and bi. As this number can be too big, print it modulo 109 + 7. Input The first line of the input contains two integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ min(n, 9)) β€” the length of all phone numbers and the length of each block, respectively. It is guaranteed that n is divisible by k. The second line of the input contains n / k space-separated positive integers β€” sequence a1, a2, ..., an / k (1 ≀ ai < 10k). The third line of the input contains n / k space-separated positive integers β€” sequence b1, b2, ..., bn / k (0 ≀ bi ≀ 9). Output Print a single integer β€” the number of good phone numbers of length n modulo 109 + 7. Examples Input 6 2 38 56 49 7 3 4 Output 8 Input 8 2 1 22 3 44 5 4 3 2 Output 32400 Note In the first test sample good phone numbers are: 000000, 000098, 005600, 005698, 380000, 380098, 385600, 385698. Submitted Solution: ``` def get_multypler(k, a, b): res = (10 ** k) // a + (1 if (10 ** k) % a != 0 else 0) bad_residue = (a - ((10 ** (k - 1)) * b) % a) % a suf = (10 ** (k - 1)) minus = suf // a + (1 if (bad_residue <= suf % a) else 0) return res - minus n, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) ans = 1 for i in range(n // k): ans *= get_multypler(k, a[i], b[i]) ans %= 10 ** 9 + 7 print(ans) ```
instruction
0
23,324
20
46,648
No
output
1
23,324
20
46,649
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits. Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a1, a2, ..., an / k and b1, b2, ..., bn / k. Let's split the phone number into blocks of length k. The first block will be formed by digits from the phone number that are on positions 1, 2,..., k, the second block will be formed by digits from the phone number that are on positions k + 1, k + 2, ..., 2Β·k and so on. Pasha considers a phone number good, if the i-th block doesn't start from the digit bi and is divisible by ai if represented as an integer. To represent the block of length k as an integer, let's write it out as a sequence c1, c2,...,ck. Then the integer is calculated as the result of the expression c1Β·10k - 1 + c2Β·10k - 2 + ... + ck. Pasha asks you to calculate the number of good phone numbers of length n, for the given k, ai and bi. As this number can be too big, print it modulo 109 + 7. Input The first line of the input contains two integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ min(n, 9)) β€” the length of all phone numbers and the length of each block, respectively. It is guaranteed that n is divisible by k. The second line of the input contains n / k space-separated positive integers β€” sequence a1, a2, ..., an / k (1 ≀ ai < 10k). The third line of the input contains n / k space-separated positive integers β€” sequence b1, b2, ..., bn / k (0 ≀ bi ≀ 9). Output Print a single integer β€” the number of good phone numbers of length n modulo 109 + 7. Examples Input 6 2 38 56 49 7 3 4 Output 8 Input 8 2 1 22 3 44 5 4 3 2 Output 32400 Note In the first test sample good phone numbers are: 000000, 000098, 005600, 005698, 380000, 380098, 385600, 385698. Submitted Solution: ``` n, k = map(int, input().split()) ans = 1 a = list(map(int, input().split())) b = list(map(int, input().split())) def ch1(x, k) : re = x for i in range(k - 1) : re = re * 10 + 9 return re ch = ch1(9, k) for i in range(n // k) : ans *= (ch // a[i] - ch1(b[i], k) // a[i] + ch1(b[i] - 1, k) // a[i]) + 1 print(ans) ```
instruction
0
23,325
20
46,650
No
output
1
23,325
20
46,651
Provide tags and a correct Python 3 solution for this coding contest problem. In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second β€” number B, etc. till column 26 that is marked by Z. Then there are two-letter numbers: column 27 has number AA, 28 β€” AB, column 52 is marked by AZ. After ZZ there follow three-letter numbers, etc. The rows are marked by integer numbers starting with 1. The cell name is the concatenation of the column and the row numbers. For example, BC23 is the name for the cell that is in column 55, row 23. Sometimes another numeration system is used: RXCY, where X and Y are integer numbers, showing the column and the row numbers respectfully. For instance, R23C55 is the cell from the previous example. Your task is to write a program that reads the given sequence of cell coordinates and produce each item written according to the rules of another numeration system. Input The first line of the input contains integer number n (1 ≀ n ≀ 105), the number of coordinates in the test. Then there follow n lines, each of them contains coordinates. All the coordinates are correct, there are no cells with the column and/or the row numbers larger than 106 . Output Write n lines, each line should contain a cell coordinates in the other numeration system. Examples Input 2 R23C55 BC23 Output BC23 R23C55
instruction
0
24,080
20
48,160
Tags: implementation, math Correct Solution: ``` __author__ = 'Darren' from sys import stdin def solve(): n = int(next(stdin)) while n > 0: line = next(stdin).strip() c_pos = line.find('C') if line[0] == 'R' and line[1].isdigit() and c_pos != -1: case_1(line[1:c_pos], line[c_pos+1:]) else: for d_pos in range(len(line)): if line[d_pos].isdigit(): break case_2(line[d_pos:], line[:d_pos]) n -= 1 def case_1(row, col): col = int(col) roman_col = [] while col > 0: mod = col % 26 mod = mod if mod else 26 roman_col.append(chr(mod + 64)) # ord('A') - 1 = 64 col = (col - mod) // 26 col = ''.join(reversed(roman_col)) print('{}{}'.format(col, row)) def case_2(row, col): digit_col = 0 for c in col: digit_col = digit_col * 26 + (ord(c) - 64) # ord('A') - 1 = 64 print('R{}C{}'.format(row, digit_col)) if __name__ == '__main__': solve() ```
output
1
24,080
20
48,161
Provide tags and a correct Python 3 solution for this coding contest problem. In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second β€” number B, etc. till column 26 that is marked by Z. Then there are two-letter numbers: column 27 has number AA, 28 β€” AB, column 52 is marked by AZ. After ZZ there follow three-letter numbers, etc. The rows are marked by integer numbers starting with 1. The cell name is the concatenation of the column and the row numbers. For example, BC23 is the name for the cell that is in column 55, row 23. Sometimes another numeration system is used: RXCY, where X and Y are integer numbers, showing the column and the row numbers respectfully. For instance, R23C55 is the cell from the previous example. Your task is to write a program that reads the given sequence of cell coordinates and produce each item written according to the rules of another numeration system. Input The first line of the input contains integer number n (1 ≀ n ≀ 105), the number of coordinates in the test. Then there follow n lines, each of them contains coordinates. All the coordinates are correct, there are no cells with the column and/or the row numbers larger than 106 . Output Write n lines, each line should contain a cell coordinates in the other numeration system. Examples Input 2 R23C55 BC23 Output BC23 R23C55
instruction
0
24,082
20
48,164
Tags: implementation, math Correct Solution: ``` import re import math n = int(input()) inputList = [] outputList = [] #print(ord('A'))#65 #print(chr(98))#b for i in range(n):#n iputs inputList.append(input()) #CASE ONE: #if it has two letters and the second char is a number #that is an RXCY type #RC245 is not our case #R23C4 is #R234C765 is str1 = inputList[i] if (len(re.findall('[A-Z]', str1)) == 2) and (re.findall('\d', str1[1])):#two capital letters && the nd char is a number firstNum = str1[1: str1.find("C")]#extract the X number in RXCY secondNum = int(str1[str1.find("C") + 1:])#extract the Y number in RXCY resultStr1 = '' while secondNum > 0: remaining = (secondNum % 26) if remaining == 0:#Z as in R228C494 remaining = 26 secondNum = ((secondNum - remaining) / 26) resultStr1 = chr(int(remaining + ord('A') - 1)) + resultStr1#add the lettertothe beginning of the string resultStr1 += firstNum#add the X number to the end of the string outputList.append(resultStr1) #CASE TWO else: str2 = inputList[i] searchList = re.findall('[A-Z]', str2)#the letters sum = 0 for k in range(len(searchList)):#loop through the letters m = len(searchList) - k -1 #n - index - 1 sum += (ord(searchList[k]) - 64) * (math.pow(26, m)) #char * 26^(n-1-index) where n is the total number of letter resultStr2 = "R" + ( ''.join(re.findall('\d', str2)) ) + "C" # R + the numbers in the string + C resultStr2 += str(int(sum)) # the string value of the sum outputList.append(resultStr2) for i in outputList: print(i) ```
output
1
24,082
20
48,165
Provide tags and a correct Python 3 solution for this coding contest problem. In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second β€” number B, etc. till column 26 that is marked by Z. Then there are two-letter numbers: column 27 has number AA, 28 β€” AB, column 52 is marked by AZ. After ZZ there follow three-letter numbers, etc. The rows are marked by integer numbers starting with 1. The cell name is the concatenation of the column and the row numbers. For example, BC23 is the name for the cell that is in column 55, row 23. Sometimes another numeration system is used: RXCY, where X and Y are integer numbers, showing the column and the row numbers respectfully. For instance, R23C55 is the cell from the previous example. Your task is to write a program that reads the given sequence of cell coordinates and produce each item written according to the rules of another numeration system. Input The first line of the input contains integer number n (1 ≀ n ≀ 105), the number of coordinates in the test. Then there follow n lines, each of them contains coordinates. All the coordinates are correct, there are no cells with the column and/or the row numbers larger than 106 . Output Write n lines, each line should contain a cell coordinates in the other numeration system. Examples Input 2 R23C55 BC23 Output BC23 R23C55
instruction
0
24,083
20
48,166
Tags: implementation, math Correct Solution: ``` s="" for n in range(int(input())): x = input() a=b=0 for c in x: if '0' <= c <= '9': b=10*b+int(c) elif b: a,b=x[1:].split('C') b=int(b) v="" while b: b-=1 v=chr(65+b%26)+v b//=26 s+= v + a + "\n" break else: a=26*a+ord(c)-64 else: s+="R" + str(b) + "C" + str(a) + "\n" print(s[0:-1]) ```
output
1
24,083
20
48,167
Provide tags and a correct Python 3 solution for this coding contest problem. In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second β€” number B, etc. till column 26 that is marked by Z. Then there are two-letter numbers: column 27 has number AA, 28 β€” AB, column 52 is marked by AZ. After ZZ there follow three-letter numbers, etc. The rows are marked by integer numbers starting with 1. The cell name is the concatenation of the column and the row numbers. For example, BC23 is the name for the cell that is in column 55, row 23. Sometimes another numeration system is used: RXCY, where X and Y are integer numbers, showing the column and the row numbers respectfully. For instance, R23C55 is the cell from the previous example. Your task is to write a program that reads the given sequence of cell coordinates and produce each item written according to the rules of another numeration system. Input The first line of the input contains integer number n (1 ≀ n ≀ 105), the number of coordinates in the test. Then there follow n lines, each of them contains coordinates. All the coordinates are correct, there are no cells with the column and/or the row numbers larger than 106 . Output Write n lines, each line should contain a cell coordinates in the other numeration system. Examples Input 2 R23C55 BC23 Output BC23 R23C55
instruction
0
24,084
20
48,168
Tags: implementation, math Correct Solution: ``` # -*- coding: utf-8 -*- import re lst = [] k = int(input()) for i in range(k): strg = input() end = strg.find('C') if end < 2 or strg[1:end].isalpha(): r_num = re.findall(r"\d+\.?\d*",strg) c_num = re.findall(r"[A-Z]+",strg) cc_l = [] ssum = 0 l = len(c_num[0]) for j in list(c_num[0]): ssum += (ord(j)-64)*(26**(l-1)) l -= 1 r_no = r_num[0] c_no = str(ssum) print('R' + r_no + 'C' + c_no) else: a,b = strg[1:].split('C') x = int(b) s='' while x: m = x//26 n = x%26 if n == 0: n = 26 m -= 1 x = m s = chr(n+64) + s print(s + a) ```
output
1
24,084
20
48,169
Provide tags and a correct Python 3 solution for this coding contest problem. In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second β€” number B, etc. till column 26 that is marked by Z. Then there are two-letter numbers: column 27 has number AA, 28 β€” AB, column 52 is marked by AZ. After ZZ there follow three-letter numbers, etc. The rows are marked by integer numbers starting with 1. The cell name is the concatenation of the column and the row numbers. For example, BC23 is the name for the cell that is in column 55, row 23. Sometimes another numeration system is used: RXCY, where X and Y are integer numbers, showing the column and the row numbers respectfully. For instance, R23C55 is the cell from the previous example. Your task is to write a program that reads the given sequence of cell coordinates and produce each item written according to the rules of another numeration system. Input The first line of the input contains integer number n (1 ≀ n ≀ 105), the number of coordinates in the test. Then there follow n lines, each of them contains coordinates. All the coordinates are correct, there are no cells with the column and/or the row numbers larger than 106 . Output Write n lines, each line should contain a cell coordinates in the other numeration system. Examples Input 2 R23C55 BC23 Output BC23 R23C55
instruction
0
24,085
20
48,170
Tags: implementation, math Correct Solution: ``` # coding: utf-8 # encoding = utf-8 import re # δΈ­ζ–‡ MAX_NUMBER = 26 countInBitArray = [1] def countInBit(w): if w >= len(countInBitArray): count = countInBit(w - 1) * MAX_NUMBER countInBitArray.append(count) return countInBitArray[w] countBeforeBitArray = [0] def countBeforeBit(w): if w >= len(countBeforeBitArray): count = countBeforeBit(w - 1) + countInBit(w) countBeforeBitArray.append(count) return countBeforeBitArray[w] def rcToExcel(column, row): w = 1 while True: if column <= countBeforeBit(w): break w += 1 column -= countBeforeBit(w - 1) column -= 1 s = '' for i in range(0, w): s = chr(column % MAX_NUMBER + 65) + s column = column // MAX_NUMBER return s + str(row) def excelToRC(columnStr, row): column = 0 for i in range(0, len(columnStr)): column = column * MAX_NUMBER + ord(columnStr[i]) - 65 column += countBeforeBit(len(columnStr) - 1) + 1 return 'R' + str(row) + 'C' + str(column) def solve(coord): if isExcel(coord): # BC23 match = re.match('([A-Z]+)(\d+)', coord) column = match.group(1) row = int(match.group(2)) return excelToRC(column, row) else: # RC match = re.match('R(\d+)C(\d+)', coord) row = int(match.group(1)) column = int(match.group(2)) return rcToExcel(column, row) def isExcel(coord): match = re.match('^[A-Z]+\d+$', coord) return match def read(): n = int(input()) a = [] for i in range(0, n): coord = input() a.append(solve(coord)) return a def write(a): for i in range(0, len(a)): print(a[i]) if __name__ == '__main__': a = read() write(a) ```
output
1
24,085
20
48,171
Provide tags and a correct Python 3 solution for this coding contest problem. In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second β€” number B, etc. till column 26 that is marked by Z. Then there are two-letter numbers: column 27 has number AA, 28 β€” AB, column 52 is marked by AZ. After ZZ there follow three-letter numbers, etc. The rows are marked by integer numbers starting with 1. The cell name is the concatenation of the column and the row numbers. For example, BC23 is the name for the cell that is in column 55, row 23. Sometimes another numeration system is used: RXCY, where X and Y are integer numbers, showing the column and the row numbers respectfully. For instance, R23C55 is the cell from the previous example. Your task is to write a program that reads the given sequence of cell coordinates and produce each item written according to the rules of another numeration system. Input The first line of the input contains integer number n (1 ≀ n ≀ 105), the number of coordinates in the test. Then there follow n lines, each of them contains coordinates. All the coordinates are correct, there are no cells with the column and/or the row numbers larger than 106 . Output Write n lines, each line should contain a cell coordinates in the other numeration system. Examples Input 2 R23C55 BC23 Output BC23 R23C55
instruction
0
24,086
20
48,172
Tags: implementation, math Correct Solution: ``` import re def to_num(val): ans = 0 for c in val: ans = 26*ans + ord(c) - ord('A') + 1 return ans def to_let(val): val = int(val) ans = "" while val: ans = chr((val-1)%26 + ord('A')) + ans val = (val-(val-1)%26)// 26 #print(ans, val) return ans N = int(input()) for i in range(N): ar = re.split('(\d+)', input())[:-1] #print(ar) if len(ar) == 2: print("R", ar[1], "C", to_num(ar[0]), sep='') else: print(to_let(ar[3]), ar[1], sep='') ```
output
1
24,086
20
48,173
Provide tags and a correct Python 3 solution for this coding contest problem. In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second β€” number B, etc. till column 26 that is marked by Z. Then there are two-letter numbers: column 27 has number AA, 28 β€” AB, column 52 is marked by AZ. After ZZ there follow three-letter numbers, etc. The rows are marked by integer numbers starting with 1. The cell name is the concatenation of the column and the row numbers. For example, BC23 is the name for the cell that is in column 55, row 23. Sometimes another numeration system is used: RXCY, where X and Y are integer numbers, showing the column and the row numbers respectfully. For instance, R23C55 is the cell from the previous example. Your task is to write a program that reads the given sequence of cell coordinates and produce each item written according to the rules of another numeration system. Input The first line of the input contains integer number n (1 ≀ n ≀ 105), the number of coordinates in the test. Then there follow n lines, each of them contains coordinates. All the coordinates are correct, there are no cells with the column and/or the row numbers larger than 106 . Output Write n lines, each line should contain a cell coordinates in the other numeration system. Examples Input 2 R23C55 BC23 Output BC23 R23C55
instruction
0
24,087
20
48,174
Tags: implementation, math Correct Solution: ``` import re def convertToNum(col): result = 0 for i in range(len(col)): result += (26 ** i) * (ord(col[len(col) - i - 1]) - 64) return result def convertToUgly(n): if n <= 26: return chr(n + 64) else: if n % 26 == 0: return convertToUgly(n // 26 - 1) + "Z" else: return convertToUgly(n // 26) + chr(n % 26 + 64) n = int(input()) for i in range(n): query = input() if re.search("R[0-9]+C[0-9]+", query): indexOfS = query.index("C") print(convertToUgly(int(query[indexOfS + 1:])) + str(query[1:indexOfS])) else: col = 0 row = 0 for j in range(len(query)): if ord(query[j]) >= 48 and ord(query[j]) <= 57: print("R" + str(int(query[j:])) + "C" + str(convertToNum(query[:j]))) break ```
output
1
24,087
20
48,175
Provide tags and a correct Python 3 solution for this coding contest problem. Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed to be an integer. Reliable sources have informed the financier Anton of some information about the exchange rate of currency you all know against the burle for tomorrow. Now Anton knows that tomorrow the exchange rate will be an even number, which can be obtained from the present rate by swapping exactly two distinct digits in it. Of all the possible values that meet these conditions, the exchange rate for tomorrow will be the maximum possible. It is guaranteed that today the exchange rate is an odd positive integer n. Help Anton to determine the exchange rate of currency you all know for tomorrow! Input The first line contains an odd positive integer n β€” the exchange rate of currency you all know for today. The length of number n's representation is within range from 2 to 105, inclusive. The representation of n doesn't contain any leading zeroes. Output If the information about tomorrow's exchange rate is inconsistent, that is, there is no integer that meets the condition, print - 1. Otherwise, print the exchange rate of currency you all know against the burle for tomorrow. This should be the maximum possible number of those that are even and that are obtained from today's exchange rate by swapping exactly two digits. Exchange rate representation should not contain leading zeroes. Examples Input 527 Output 572 Input 4573 Output 3574 Input 1357997531 Output -1
instruction
0
24,232
20
48,464
Tags: greedy, math, strings Correct Solution: ``` t = input() last = int(t[-1]) even = [int(x) for x in t if int(x)%2] last_even = None for i,c in enumerate(t): as_int = int(c) if as_int%2: continue last_even = i if as_int>last:continue print (t[:i] + t[-1] + t[i+1:-1] +t[i]) break else: if last_even is None: print (-1) else: print (t[:last_even] + t[-1] + t[last_even+1:-1] + t[last_even]) ```
output
1
24,232
20
48,465
Provide tags and a correct Python 3 solution for this coding contest problem. Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed to be an integer. Reliable sources have informed the financier Anton of some information about the exchange rate of currency you all know against the burle for tomorrow. Now Anton knows that tomorrow the exchange rate will be an even number, which can be obtained from the present rate by swapping exactly two distinct digits in it. Of all the possible values that meet these conditions, the exchange rate for tomorrow will be the maximum possible. It is guaranteed that today the exchange rate is an odd positive integer n. Help Anton to determine the exchange rate of currency you all know for tomorrow! Input The first line contains an odd positive integer n β€” the exchange rate of currency you all know for today. The length of number n's representation is within range from 2 to 105, inclusive. The representation of n doesn't contain any leading zeroes. Output If the information about tomorrow's exchange rate is inconsistent, that is, there is no integer that meets the condition, print - 1. Otherwise, print the exchange rate of currency you all know against the burle for tomorrow. This should be the maximum possible number of those that are even and that are obtained from today's exchange rate by swapping exactly two digits. Exchange rate representation should not contain leading zeroes. Examples Input 527 Output 572 Input 4573 Output 3574 Input 1357997531 Output -1
instruction
0
24,236
20
48,472
Tags: greedy, math, strings Correct Solution: ``` n=list(input()) f=True z=-1 for i in range(len(n)): if (int(n[i])%2==0): if int(n[i])<int(n[-1]): n[i],n[-1] = n[-1],n[i] an = ''.join(n) f= False z=0 break else: z= i if z==-1: an=-1 elif f: n[-1],n[z]=n[z],n[-1] an=''.join(n) elif z==-1: an=-1 print(an) ```
output
1
24,236
20
48,473
Provide tags and a correct Python 3 solution for this coding contest problem. Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed to be an integer. Reliable sources have informed the financier Anton of some information about the exchange rate of currency you all know against the burle for tomorrow. Now Anton knows that tomorrow the exchange rate will be an even number, which can be obtained from the present rate by swapping exactly two distinct digits in it. Of all the possible values that meet these conditions, the exchange rate for tomorrow will be the maximum possible. It is guaranteed that today the exchange rate is an odd positive integer n. Help Anton to determine the exchange rate of currency you all know for tomorrow! Input The first line contains an odd positive integer n β€” the exchange rate of currency you all know for today. The length of number n's representation is within range from 2 to 105, inclusive. The representation of n doesn't contain any leading zeroes. Output If the information about tomorrow's exchange rate is inconsistent, that is, there is no integer that meets the condition, print - 1. Otherwise, print the exchange rate of currency you all know against the burle for tomorrow. This should be the maximum possible number of those that are even and that are obtained from today's exchange rate by swapping exactly two digits. Exchange rate representation should not contain leading zeroes. Examples Input 527 Output 572 Input 4573 Output 3574 Input 1357997531 Output -1
instruction
0
24,239
20
48,478
Tags: greedy, math, strings Correct Solution: ``` n = input() temp = index = -1 for i in range(len(n)): digit = n[i] if int(digit) % 2 == 0: temp = i if digit < n[-1]: index = i break if index == -1: if temp == -1: print(-1) exit() index = temp print(n[0:index] + n[-1] + n[index+1:-1] + n[index]) ```
output
1
24,239
20
48,479
Provide a correct Python 3 solution for this coding contest problem. Sitting in a station waiting room, Joisino is gazing at her train ticket. The ticket is numbered with four digits A, B, C and D in this order, each between 0 and 9 (inclusive). In the formula A op1 B op2 C op3 D = 7, replace each of the symbols op1, op2 and op3 with `+` or `-` so that the formula holds. The given input guarantees that there is a solution. If there are multiple solutions, any of them will be accepted. Constraints * 0≀A,B,C,D≀9 * All input values are integers. * It is guaranteed that there is a solution. Input Input is given from Standard Input in the following format: ABCD Output Print the formula you made, including the part `=7`. Use the signs `+` and `-`. Do not print a space between a digit and a sign. Examples Input 1222 Output 1+2+2+2=7 Input 0290 Output 0-2+9+0=7 Input 3242 Output 3+2+4-2=7
instruction
0
24,589
20
49,178
"Correct Solution: ``` n = input() lis = ["+", "-"] for x in lis: for y in lis: for z in lis: p = n[0] + x + n[1] + y + n[2] + z + n[3] if eval(p) == 7: print(p + "=7") exit() ```
output
1
24,589
20
49,179
Provide tags and a correct Python 3 solution for this coding contest problem. Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya loves long lucky numbers very much. He is interested in the minimum lucky number d that meets some condition. Let cnt(x) be the number of occurrences of number x in number d as a substring. For example, if d = 747747, then cnt(4) = 2, cnt(7) = 4, cnt(47) = 2, cnt(74) = 2. Petya wants the following condition to fulfil simultaneously: cnt(4) = a1, cnt(7) = a2, cnt(47) = a3, cnt(74) = a4. Petya is not interested in the occurrences of other numbers. Help him cope with this task. Input The single line contains four integers a1, a2, a3 and a4 (1 ≀ a1, a2, a3, a4 ≀ 106). Output On the single line print without leading zeroes the answer to the problem β€” the minimum lucky number d such, that cnt(4) = a1, cnt(7) = a2, cnt(47) = a3, cnt(74) = a4. If such number does not exist, print the single number "-1" (without the quotes). Examples Input 2 2 1 1 Output 4774 Input 4 7 3 1 Output -1
instruction
0
24,968
20
49,936
Tags: constructive algorithms Correct Solution: ``` a, b, u, v = map(int, input().split()) k = u - 1 x, y = u < v, k < v d = min(a, b) < max(u, v) or abs(u - v) > 1 or a == b == u == v t = '7' * x + '4' * (a - y - k) + '74' * k + '7' * (b - x - k) + '4' * y if a == y + k: t = t[-2:] + t[:-2] print(-1 if d else t) ```
output
1
24,968
20
49,937
Provide tags and a correct Python 3 solution for this coding contest problem. Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya loves long lucky numbers very much. He is interested in the minimum lucky number d that meets some condition. Let cnt(x) be the number of occurrences of number x in number d as a substring. For example, if d = 747747, then cnt(4) = 2, cnt(7) = 4, cnt(47) = 2, cnt(74) = 2. Petya wants the following condition to fulfil simultaneously: cnt(4) = a1, cnt(7) = a2, cnt(47) = a3, cnt(74) = a4. Petya is not interested in the occurrences of other numbers. Help him cope with this task. Input The single line contains four integers a1, a2, a3 and a4 (1 ≀ a1, a2, a3, a4 ≀ 106). Output On the single line print without leading zeroes the answer to the problem β€” the minimum lucky number d such, that cnt(4) = a1, cnt(7) = a2, cnt(47) = a3, cnt(74) = a4. If such number does not exist, print the single number "-1" (without the quotes). Examples Input 2 2 1 1 Output 4774 Input 4 7 3 1 Output -1
instruction
0
24,969
20
49,938
Tags: constructive algorithms Correct Solution: ``` from itertools import repeat from math import floor,ceil def fill(s,a1,a2,a3,a4,c4,c7): if a1<c4 or a2<c7: return None f = s.index('4') sv = s.rindex('7') s = ''.join([s[:f],'4'*(a1-c4),s[f:sv],'7'*(a2-c7),s[sv:]]) return s a1,a2,a3,a4 = [int(x) for x in input().split()] if abs(a3-a4)>1: print(-1) else: s = '' if a3>a1 or a3>a2 or a4>a1 or a4>a2: print(-1) exit(0) c4 = 0 c7 = 0 if a3>a4: s = ''.join(repeat('47',a3)) c4 = int(len(s)/2) c7 = len(s)-c4 s = fill(s, a1, a2, a3, a4, c4, c7) if s: print(s) else: print(-1) elif a3<a4: s = ''.join(repeat('74',a4)) c7 = int(len(s)/2) c4 = len(s)-c7 s = fill(s, a1, a2, a3, a4, c4, c7) if s: print(s) else: print(-1) elif a3==a4: s = ''.join(repeat('47',a3))+'4' c4 = ceil(len(s)/2) c7 = len(s)-c4 s = fill(s, a1, a2, a3, a4, c4, c7) if s: print(s) else: s = ''.join(repeat('74',a3))+'7' c7 = ceil(len(s)/2) c4 = len(s)-c7 s = fill(s, a1, a2, a3, a4, c4, c7) if s: print(s) else: print(-1) ```
output
1
24,969
20
49,939
Provide tags and a correct Python 3 solution for this coding contest problem. Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya loves long lucky numbers very much. He is interested in the minimum lucky number d that meets some condition. Let cnt(x) be the number of occurrences of number x in number d as a substring. For example, if d = 747747, then cnt(4) = 2, cnt(7) = 4, cnt(47) = 2, cnt(74) = 2. Petya wants the following condition to fulfil simultaneously: cnt(4) = a1, cnt(7) = a2, cnt(47) = a3, cnt(74) = a4. Petya is not interested in the occurrences of other numbers. Help him cope with this task. Input The single line contains four integers a1, a2, a3 and a4 (1 ≀ a1, a2, a3, a4 ≀ 106). Output On the single line print without leading zeroes the answer to the problem β€” the minimum lucky number d such, that cnt(4) = a1, cnt(7) = a2, cnt(47) = a3, cnt(74) = a4. If such number does not exist, print the single number "-1" (without the quotes). Examples Input 2 2 1 1 Output 4774 Input 4 7 3 1 Output -1
instruction
0
24,970
20
49,940
Tags: constructive algorithms Correct Solution: ``` from math import * from fractions import * from sys import * def li(): return list(map(int, input().split(" "))) a = li() if abs(a[2]-a[3]) > 1: print(-1) exit() if a[2] == a[3]: ans = "47"*a[2]+"4" elif a[2] > a[3]: ans = "47"*a[2] else: ans = "74"*a[3] f = a[0]-ans.count("4") s = a[1]-ans.count("7") shit =False if s < 0 or f < 0: if(a[2] == a[3]): ans = "74"*a[2]+"7" shit = True f = a[0]-ans.count("4") s = a[1]-ans.count("7") if s < 0 or f < 0: ans = "-1" elif s>0 or f>0: s+=1 f+=1 if ans[:2] == "47": if(ans[-1] == "4"): ans = "4"*f + "7" + ans[2:-1] + "7"*(s-1) + "4" else: ans = "4"*f + "7" + ans[2:] + "7"*(s-1) else: if(ans[-1] == "4"): ans = "7" + "4"*f + ans[2:-1] + "7"*(s-1) + "4" else: ans = "7" + "4"*f + ans[2:] + "7"*(s-1) print(ans) ```
output
1
24,970
20
49,941
Provide tags and a correct Python 3 solution for this coding contest problem. Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya loves long lucky numbers very much. He is interested in the minimum lucky number d that meets some condition. Let cnt(x) be the number of occurrences of number x in number d as a substring. For example, if d = 747747, then cnt(4) = 2, cnt(7) = 4, cnt(47) = 2, cnt(74) = 2. Petya wants the following condition to fulfil simultaneously: cnt(4) = a1, cnt(7) = a2, cnt(47) = a3, cnt(74) = a4. Petya is not interested in the occurrences of other numbers. Help him cope with this task. Input The single line contains four integers a1, a2, a3 and a4 (1 ≀ a1, a2, a3, a4 ≀ 106). Output On the single line print without leading zeroes the answer to the problem β€” the minimum lucky number d such, that cnt(4) = a1, cnt(7) = a2, cnt(47) = a3, cnt(74) = a4. If such number does not exist, print the single number "-1" (without the quotes). Examples Input 2 2 1 1 Output 4774 Input 4 7 3 1 Output -1
instruction
0
24,971
20
49,942
Tags: constructive algorithms Correct Solution: ``` a, b, c, d = input().strip().split() a = int(a) b = int(b) c = int(c) d = int(d) if abs(c - d) > 1 or min(a, b) < max(c, d) or a == b == c == d: print(-1) exit() if c == d: if a == c: ans = '74' * c + '7' * (b - c) else: ans = '4' * (a - c - 1) + '47' * c + '7' * (b - c) + '4' elif c > d: ans = '4' * (a - c) + '47' * c + '7' * (b - c) else: ans = '7' + '4' * (a - c) + '74' * (c - 1) + '7' * (b - c) + '4' print(ans) ```
output
1
24,971
20
49,943
Provide tags and a correct Python 3 solution for this coding contest problem. Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya loves long lucky numbers very much. He is interested in the minimum lucky number d that meets some condition. Let cnt(x) be the number of occurrences of number x in number d as a substring. For example, if d = 747747, then cnt(4) = 2, cnt(7) = 4, cnt(47) = 2, cnt(74) = 2. Petya wants the following condition to fulfil simultaneously: cnt(4) = a1, cnt(7) = a2, cnt(47) = a3, cnt(74) = a4. Petya is not interested in the occurrences of other numbers. Help him cope with this task. Input The single line contains four integers a1, a2, a3 and a4 (1 ≀ a1, a2, a3, a4 ≀ 106). Output On the single line print without leading zeroes the answer to the problem β€” the minimum lucky number d such, that cnt(4) = a1, cnt(7) = a2, cnt(47) = a3, cnt(74) = a4. If such number does not exist, print the single number "-1" (without the quotes). Examples Input 2 2 1 1 Output 4774 Input 4 7 3 1 Output -1
instruction
0
24,972
20
49,944
Tags: constructive algorithms Correct Solution: ``` a, b, c, d = map(int, input().split(' ')) if (a+b) - (c+d) < 1: print(-1) quit() if c == d: if a == c: if (b-a < 0): print(-1) quit() print('74' * d + '7' * (b-a)) quit() if ((b-c) < 0 or (a-c-1) < 0): print(-1) quit() print('4' * (a-c-1) + '47' * c + '7' * (b - c) + '4') quit() if c + 1 == d: if (a-c-1 < 0 or b-c-1 < 0): print(-1) quit() print('7' + '4' * (a-c-1) + '47' * c + '7' * (b-1-c) + '4') quit() if d + 1 == c: if a-c < 0 or b-c < 0: print(-1) quit() print('4'*(a-c) + '47' * (c) + '7' * (b-c)) quit() print(-1) quit() ```
output
1
24,972
20
49,945
Provide tags and a correct Python 3 solution for this coding contest problem. Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya loves long lucky numbers very much. He is interested in the minimum lucky number d that meets some condition. Let cnt(x) be the number of occurrences of number x in number d as a substring. For example, if d = 747747, then cnt(4) = 2, cnt(7) = 4, cnt(47) = 2, cnt(74) = 2. Petya wants the following condition to fulfil simultaneously: cnt(4) = a1, cnt(7) = a2, cnt(47) = a3, cnt(74) = a4. Petya is not interested in the occurrences of other numbers. Help him cope with this task. Input The single line contains four integers a1, a2, a3 and a4 (1 ≀ a1, a2, a3, a4 ≀ 106). Output On the single line print without leading zeroes the answer to the problem β€” the minimum lucky number d such, that cnt(4) = a1, cnt(7) = a2, cnt(47) = a3, cnt(74) = a4. If such number does not exist, print the single number "-1" (without the quotes). Examples Input 2 2 1 1 Output 4774 Input 4 7 3 1 Output -1
instruction
0
24,973
20
49,946
Tags: constructive algorithms Correct Solution: ``` A = [int(_) for _ in input().split()] if abs(A[3]-A[2]) > 1: print(-1) elif A[2] > A[3]: if A[0] < A[2] or A[1] < A[2]: print(-1) else: A[0] -= A[2] A[1] -= A[2] print("4"*A[0]+"47"*A[2]+"7"*A[1]) elif A[3] > A[2]: if A[0] < A[3] or A[1] < A[3]: print(-1) else: A[0] -= A[3]-1 A[1] -= A[3]-1 print("7"+"4"*A[0]+"74"*(A[3]-2)+"7"*A[1]+"4") else: if A[2]+1 <= A[0] and A[3] <= A[1]: A[0] -= A[2]+1 A[1] -= A[3] print("4"*A[0]+"47"*A[2]+"7"*A[1]+"4") elif A[2] <= A[0] and A[3]+1 <= A[1]: A[1] -= A[3] print("74"*A[3]+"7"*A[1]) else: print(-1) ```
output
1
24,973
20
49,947
Provide tags and a correct Python 3 solution for this coding contest problem. Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya loves long lucky numbers very much. He is interested in the minimum lucky number d that meets some condition. Let cnt(x) be the number of occurrences of number x in number d as a substring. For example, if d = 747747, then cnt(4) = 2, cnt(7) = 4, cnt(47) = 2, cnt(74) = 2. Petya wants the following condition to fulfil simultaneously: cnt(4) = a1, cnt(7) = a2, cnt(47) = a3, cnt(74) = a4. Petya is not interested in the occurrences of other numbers. Help him cope with this task. Input The single line contains four integers a1, a2, a3 and a4 (1 ≀ a1, a2, a3, a4 ≀ 106). Output On the single line print without leading zeroes the answer to the problem β€” the minimum lucky number d such, that cnt(4) = a1, cnt(7) = a2, cnt(47) = a3, cnt(74) = a4. If such number does not exist, print the single number "-1" (without the quotes). Examples Input 2 2 1 1 Output 4774 Input 4 7 3 1 Output -1
instruction
0
24,974
20
49,948
Tags: constructive algorithms Correct Solution: ``` a1,a2,a3,a4=map(int,input().split()) L=[] def Solve(a1,a2,a3,a4): if(a3-a4<-1 or a3-a4>1 or a1<a3 or a1<a4 or a2<a3 or a2<a4): return -1 elif(a3-a4==0): Ans="47"*a3 Ans+="4" if(a1-a3==0 and a2-a4==0): return -1 elif(a1-a3==0): return "74"*a3+"7"*(a2-a4) return "4"*(a1-a3-1)+Ans[:len(Ans)-1]+"7"*(a2-a4)+"4" elif(a3-a4==1): if(a2==a4): return -1 Ans="47"*a3 Ans="4"*(a1-a3)+Ans+"7"*(a2-a4-1) return Ans else: if(a3==a1): return -1 Ans="74"*a4 Ans="7"+"4"*(a1-a3-1)+Ans[1:len(Ans)-1]+"7"*(a2-a4)+"4" return Ans print(Solve(a1,a2,a3,a4)) # Made By Mostafa_Khaled ```
output
1
24,974
20
49,949
Provide tags and a correct Python 3 solution for this coding contest problem. Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya loves long lucky numbers very much. He is interested in the minimum lucky number d that meets some condition. Let cnt(x) be the number of occurrences of number x in number d as a substring. For example, if d = 747747, then cnt(4) = 2, cnt(7) = 4, cnt(47) = 2, cnt(74) = 2. Petya wants the following condition to fulfil simultaneously: cnt(4) = a1, cnt(7) = a2, cnt(47) = a3, cnt(74) = a4. Petya is not interested in the occurrences of other numbers. Help him cope with this task. Input The single line contains four integers a1, a2, a3 and a4 (1 ≀ a1, a2, a3, a4 ≀ 106). Output On the single line print without leading zeroes the answer to the problem β€” the minimum lucky number d such, that cnt(4) = a1, cnt(7) = a2, cnt(47) = a3, cnt(74) = a4. If such number does not exist, print the single number "-1" (without the quotes). Examples Input 2 2 1 1 Output 4774 Input 4 7 3 1 Output -1
instruction
0
24,975
20
49,950
Tags: constructive algorithms Correct Solution: ``` import sys a, b, c, d = map(int, sys.stdin.readline().split(' ')) if c == d + 1: if a < c or b < c: print(-1) else: ans = '4' * (a - c) + "47" * c + '7' * (b - c) print (ans) elif c + 1 == d: if a < d or b < d: print(-1) else: ans = "74" * d ans = ans[0:1] + '4' * (a - d) + ans[1 : len(ans) - 1] + '7' * (b - d) + ans[len(ans) - 1 : len(ans)] print(ans) elif c == d: if a >= c + 1 and b >= c: ans = "47" * c + '4' ans = '4' * (a - (c + 1)) + ans[0 : len(ans) - 1] + '7' * (b - c) + ans[len(ans) - 1 : len(ans)] print(ans) elif a == c and b >= c + 1: ans = "74" * c + '7' + '7' * (b - (c + 1)) print(ans) else: print(-1) else: print(-1) ```
output
1
24,975
20
49,951
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya loves long lucky numbers very much. He is interested in the minimum lucky number d that meets some condition. Let cnt(x) be the number of occurrences of number x in number d as a substring. For example, if d = 747747, then cnt(4) = 2, cnt(7) = 4, cnt(47) = 2, cnt(74) = 2. Petya wants the following condition to fulfil simultaneously: cnt(4) = a1, cnt(7) = a2, cnt(47) = a3, cnt(74) = a4. Petya is not interested in the occurrences of other numbers. Help him cope with this task. Input The single line contains four integers a1, a2, a3 and a4 (1 ≀ a1, a2, a3, a4 ≀ 106). Output On the single line print without leading zeroes the answer to the problem β€” the minimum lucky number d such, that cnt(4) = a1, cnt(7) = a2, cnt(47) = a3, cnt(74) = a4. If such number does not exist, print the single number "-1" (without the quotes). Examples Input 2 2 1 1 Output 4774 Input 4 7 3 1 Output -1 Submitted Solution: ``` a1,a2,a3,a4=map(int,input().split()) L=[] def Solve(a1,a2,a3,a4): if(a3-a4<-1 or a3-a4>1 or a1<a3 or a1<a4 or a2<a3 or a2<a4): return -1 elif(a3-a4==0): Ans="47"*a3 Ans+="4" if(a1-a3==0 and a2-a4==0): return -1 elif(a1-a3==0): return "74"*a3+"7"*(a2-a4) return "4"*(a1-a3-1)+Ans[:len(Ans)-1]+"7"*(a2-a4)+"4" elif(a3-a4==1): if(a2==a4): return -1 Ans="47"*a3 Ans="4"*(a1-a3)+Ans+"7"*(a2-a4-1) return Ans else: if(a3==a1): return -1 Ans="74"*a4 Ans="7"+"4"*(a1-a3-1)+Ans[1:len(Ans)-1]+"7"*(a2-a4)+"4" return Ans print(Solve(a1,a2,a3,a4)) ```
instruction
0
24,976
20
49,952
Yes
output
1
24,976
20
49,953
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya loves long lucky numbers very much. He is interested in the minimum lucky number d that meets some condition. Let cnt(x) be the number of occurrences of number x in number d as a substring. For example, if d = 747747, then cnt(4) = 2, cnt(7) = 4, cnt(47) = 2, cnt(74) = 2. Petya wants the following condition to fulfil simultaneously: cnt(4) = a1, cnt(7) = a2, cnt(47) = a3, cnt(74) = a4. Petya is not interested in the occurrences of other numbers. Help him cope with this task. Input The single line contains four integers a1, a2, a3 and a4 (1 ≀ a1, a2, a3, a4 ≀ 106). Output On the single line print without leading zeroes the answer to the problem β€” the minimum lucky number d such, that cnt(4) = a1, cnt(7) = a2, cnt(47) = a3, cnt(74) = a4. If such number does not exist, print the single number "-1" (without the quotes). Examples Input 2 2 1 1 Output 4774 Input 4 7 3 1 Output -1 Submitted Solution: ``` a1,a2,a3,a4 = map(int,input().split()) if abs(a3 - a4) > 1: print(-1) else: if a3 == a4: if a1 < 2 and a2 < 2: print(-1) else: if a1 - 1 >= a3 and a2 >= a3: print("4"*(a1-a3-1) + "47"*a3 + "7"*(a2-a3)+"4") elif a2 - 1 >= a3 and a1 >= a3: print("7" + "47"*a3 + "7"*(a2-a3-1)) else: print(-1) elif a3 > a4: a1 = a1 - a3 a2 = a2 - a3 if a1 < 0 or a2 < 0: print(-1) else: print("4"*a1+"47"*a3+"7"*a2) elif a4 > a3: a1 = a1 - a4 a2 = a2 - a4 if a1 < 0 or a2 < 0: print(-1) else: print("7" + "4"*a1 + "47"*a3 + "7"*a2 + "4") ```
instruction
0
24,977
20
49,954
Yes
output
1
24,977
20
49,955