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. Today Tavas got his test result as an integer score and he wants to share it with his girlfriend, Nafas. His phone operating system is Tavdroid, and its keyboard doesn't have any digits! He wants to share his score with Nafas via text, so he has no choice but to send this number using words. <image> He ate coffee mix without water again, so right now he's really messed up and can't think. Your task is to help him by telling him what to type. Input The first and only line of input contains an integer s (0 ≀ s ≀ 99), Tavas's score. Output In the first and only line of output, print a single string consisting only from English lowercase letters and hyphens ('-'). Do not use spaces. Examples Input 6 Output six Input 99 Output ninety-nine Input 20 Output twenty Note You can find all you need to know about English numerals in <http://en.wikipedia.org/wiki/English_numerals> .
instruction
0
9,475
20
18,950
Tags: brute force, implementation Correct Solution: ``` if __name__ == '__main__': n = int(input()) d = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen'] t = ['twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety'] if n < 20: print(d[n]) else: s = '' a = n // 10 b = n % 10 s += t[a - 2] if b != 0: s += '-' + d[b] print(s) ```
output
1
9,475
20
18,951
Provide tags and a correct Python 3 solution for this coding contest problem. Today Tavas got his test result as an integer score and he wants to share it with his girlfriend, Nafas. His phone operating system is Tavdroid, and its keyboard doesn't have any digits! He wants to share his score with Nafas via text, so he has no choice but to send this number using words. <image> He ate coffee mix without water again, so right now he's really messed up and can't think. Your task is to help him by telling him what to type. Input The first and only line of input contains an integer s (0 ≀ s ≀ 99), Tavas's score. Output In the first and only line of output, print a single string consisting only from English lowercase letters and hyphens ('-'). Do not use spaces. Examples Input 6 Output six Input 99 Output ninety-nine Input 20 Output twenty Note You can find all you need to know about English numerals in <http://en.wikipedia.org/wiki/English_numerals> .
instruction
0
9,476
20
18,952
Tags: brute force, implementation Correct Solution: ``` score = int(input()) score = str(score) number2word = {"1":"one","2":"two","3":"three","4":"four","5":"five","6":"six","7":"seven", "8":"eight", "9":"nine","0":"zero"} number2word_10th= {"10":"ten","11":"eleven","12":"twelve","13":"thirteen","14":"fourteen","15":"fifteen","16":"sixteen","17":"seventeen","18":"eighteen","19":"nineteen"} number2word_digit = {"2":"twenty","3":"thirty","4":"forty","5":"fifty","6":"sixty","7":"seventy","8":"eighty","9":"ninety"} if len(score)== 1: score_word = number2word[score] else: digit1 = score[0] digit2 = score[1] if digit1 == "1": score_word = number2word_10th[score] else: if digit2 == "0": score_word = number2word_digit[digit1] else: score_word = number2word_digit[digit1] score_word += "-"+number2word[digit2] print(score_word) ```
output
1
9,476
20
18,953
Provide tags and a correct Python 3 solution for this coding contest problem. Today Tavas got his test result as an integer score and he wants to share it with his girlfriend, Nafas. His phone operating system is Tavdroid, and its keyboard doesn't have any digits! He wants to share his score with Nafas via text, so he has no choice but to send this number using words. <image> He ate coffee mix without water again, so right now he's really messed up and can't think. Your task is to help him by telling him what to type. Input The first and only line of input contains an integer s (0 ≀ s ≀ 99), Tavas's score. Output In the first and only line of output, print a single string consisting only from English lowercase letters and hyphens ('-'). Do not use spaces. Examples Input 6 Output six Input 99 Output ninety-nine Input 20 Output twenty Note You can find all you need to know about English numerals in <http://en.wikipedia.org/wiki/English_numerals> .
instruction
0
9,477
20
18,954
Tags: brute force, implementation Correct Solution: ``` n=int(input()) if(n<=20): if(n==0): print("zero") if(n==1): print("one") if(n==2): print("two") if(n==3): print("three") if(n==4): print("four") if(n==5): print("five") if(n==6): print("six") if(n==7): print("seven") if(n==8): print("eight") if(n==9): print("nine") if(n==10): print("ten") if(n==11): print("eleven") if(n==12): print("twelve") if(n==13): print("thirteen") if(n==14): print("fourteen") if(n==15): print("fifteen") if(n==16): print("sixteen") if(n==17): print("seventeen") if(n==18): print("eighteen") if(n==19): print("nineteen") if(n==20): print("twenty") ar1=["","one","two","three","four","five","six","seven","eight","nine"] ar2=["twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"] if(n>20): c=n%10 d=n//10 if(c==0): print(ar2[d-2]) else: s=ar2[d-2]+"-"+ar1[c] print(s) ```
output
1
9,477
20
18,955
Provide tags and a correct Python 3 solution for this coding contest problem. Today Tavas got his test result as an integer score and he wants to share it with his girlfriend, Nafas. His phone operating system is Tavdroid, and its keyboard doesn't have any digits! He wants to share his score with Nafas via text, so he has no choice but to send this number using words. <image> He ate coffee mix without water again, so right now he's really messed up and can't think. Your task is to help him by telling him what to type. Input The first and only line of input contains an integer s (0 ≀ s ≀ 99), Tavas's score. Output In the first and only line of output, print a single string consisting only from English lowercase letters and hyphens ('-'). Do not use spaces. Examples Input 6 Output six Input 99 Output ninety-nine Input 20 Output twenty Note You can find all you need to know about English numerals in <http://en.wikipedia.org/wiki/English_numerals> .
instruction
0
9,478
20
18,956
Tags: brute force, implementation Correct Solution: ``` N = int(input()) d = {0: "zero", 1: "one", 2: "two", 3: "three", 4: "four", 5: "five", 6: "six", 7: "seven", 8: "eight", 9: "nine"} dd = {11: "eleven", 12: "twelve", 13: "thirteen", 14: "fourteen", 15: "fifteen", 16: "sixteen", 17: "seventeen", 18: "eighteen", 19: "nineteen"} ddd = {10: "ten", 20: "twenty", 30: "thirty", 40: "forty", 50: "fifty", 60: "sixty", 70: "seventy", 80: "eighty", 90: "ninety"} if N <= 9: print(d[N]) elif N % 10 == 0: print(ddd[N]) elif N <= 19: print(dd[N]) else: m = N % 10 n = N - m print("{}-{}".format(ddd[n], d[m])) ```
output
1
9,478
20
18,957
Provide tags and a correct Python 3 solution for this coding contest problem. Today Tavas got his test result as an integer score and he wants to share it with his girlfriend, Nafas. His phone operating system is Tavdroid, and its keyboard doesn't have any digits! He wants to share his score with Nafas via text, so he has no choice but to send this number using words. <image> He ate coffee mix without water again, so right now he's really messed up and can't think. Your task is to help him by telling him what to type. Input The first and only line of input contains an integer s (0 ≀ s ≀ 99), Tavas's score. Output In the first and only line of output, print a single string consisting only from English lowercase letters and hyphens ('-'). Do not use spaces. Examples Input 6 Output six Input 99 Output ninety-nine Input 20 Output twenty Note You can find all you need to know about English numerals in <http://en.wikipedia.org/wiki/English_numerals> .
instruction
0
9,479
20
18,958
Tags: brute force, implementation Correct Solution: ``` def main(n): index = {'1':'one','2':'two','3':'three','4':'four','5':'five','6':'six','7':'seven','8':'eight','9':'nine','0':'zero','10':'ten','11':'eleven','12':'twelve','13':'thirteen'} if int(n) < 14: print(index[n]) else: if n[0] == '1': if n[1] == '5': print('fifteen') elif n[1] == '8': print('eighteen') else: print(index[n[1]] + 'teen') else: if n[1] == '0': if n[0] == '8': number = 'eighty' elif n[0] == '5': number = 'fifty' elif n[0] == '4': number = 'forty' elif n[0] == '2': number = 'twenty' elif n[0] == '3': number = 'thirty' else: number = index[n[0]] + 'ty' else: number = index[n[0]] + 'ty' + '-' + index[n[1]] if n[0] == '8': number = 'eighty' + '-' + index[n[1]] if n[0] == '5': number = 'fifty' + '-' + index[n[1]] if n[0] == '4': number = 'forty' + '-' + index[n[1]] if n[0] == '2': number = 'twenty' + '-' + index[n[1]] if n[0] == '3': number = 'thirty' + '-' + index[n[1]] print(number) n = input() main(n) ```
output
1
9,479
20
18,959
Provide tags and a correct Python 3 solution for this coding contest problem. Today Tavas got his test result as an integer score and he wants to share it with his girlfriend, Nafas. His phone operating system is Tavdroid, and its keyboard doesn't have any digits! He wants to share his score with Nafas via text, so he has no choice but to send this number using words. <image> He ate coffee mix without water again, so right now he's really messed up and can't think. Your task is to help him by telling him what to type. Input The first and only line of input contains an integer s (0 ≀ s ≀ 99), Tavas's score. Output In the first and only line of output, print a single string consisting only from English lowercase letters and hyphens ('-'). Do not use spaces. Examples Input 6 Output six Input 99 Output ninety-nine Input 20 Output twenty Note You can find all you need to know about English numerals in <http://en.wikipedia.org/wiki/English_numerals> .
instruction
0
9,480
20
18,960
Tags: brute force, implementation Correct Solution: ``` score = int(input()) msg = '' if len(str(score)) == 1: if score == 0: msg = 'zero' elif score == 1: msg = 'one' elif score == 2: msg = 'two' elif score == 3: msg = 'three' elif score == 4: msg = 'four' elif score == 5: msg = 'five' elif score == 6: msg = 'six' elif score == 7: msg = 'seven' elif score == 8: msg = 'eight' elif score == 9: msg = 'nine' if len(str(score)) == 2: #first digit score = str(score) if score[0] == '1': if score[1] == '0': msg = 'Ten' elif score[1] == '1': msg = 'Eleven' elif score[1] == '2': msg = 'Twelve' elif score[1] == '3': msg = 'Thirteen' elif score[1] == '4': msg = 'Fourteen' elif score[1] == '5': msg = 'Fifteen' elif score[1] == '6': msg = 'Sixteen' elif score[1] == '7': msg = 'Seventeen' elif score[1] == '8': msg = 'Eighteen' elif score[1] == '9': msg = 'Nineteen' if score[0] == '2': msg = 'Twenty' elif score[0] == '3': msg = 'Thirty' elif score[0] == '4': msg = 'Forty' elif score[0] == '5': msg = 'Fifty' elif score[0] == '6': msg = 'Sixty' elif score[0] == '7': msg = 'Seventy' elif score[0] == '8': msg = 'Eighty' elif score[0] == '9': msg = 'Ninety' #second digit if score[0] != '1': if score[1] == '1': msg += '-one' elif score[1] == '2': msg += '-two' elif score[1] == '3': msg += '-three' elif score[1] == '4': msg += '-four' elif score[1] == '5': msg += '-five' elif score[1] == '6': msg += '-six' elif score[1] == '7': msg += '-seven' elif score[1] == '8': msg += '-eight' elif score[1] == '9': msg += '-nine' print(msg.lower()) ```
output
1
9,480
20
18,961
Provide tags and a correct Python 3 solution for this coding contest problem. Today Tavas got his test result as an integer score and he wants to share it with his girlfriend, Nafas. His phone operating system is Tavdroid, and its keyboard doesn't have any digits! He wants to share his score with Nafas via text, so he has no choice but to send this number using words. <image> He ate coffee mix without water again, so right now he's really messed up and can't think. Your task is to help him by telling him what to type. Input The first and only line of input contains an integer s (0 ≀ s ≀ 99), Tavas's score. Output In the first and only line of output, print a single string consisting only from English lowercase letters and hyphens ('-'). Do not use spaces. Examples Input 6 Output six Input 99 Output ninety-nine Input 20 Output twenty Note You can find all you need to know about English numerals in <http://en.wikipedia.org/wiki/English_numerals> .
instruction
0
9,481
20
18,962
Tags: brute force, implementation Correct Solution: ``` n = int(input()) if n == 0: print('zero') elif n == 1: print('one') elif n == 2: print('two') elif n == 3: print('three') elif n == 4: print('four') elif n == 5: print('five') elif n == 6: print('six') elif n == 7: print('seven') elif n == 8: print('eight') elif n == 9: print('nine') elif n == 10: print('ten') elif n == 11: print('eleven') elif n == 12: print('twelve') elif n == 13: print('thirteen') elif n == 14: print('fourteen') elif n == 15: print('fifteen') elif n == 16: print('sixteen') elif n == 17: print('seventeen') elif n == 18: print('eighteen') elif n == 19: print('nineteen') else: if n // 10 == 2: res = 'twenty' elif n // 10 == 3: res = 'thirty' elif n // 10 == 4: res = 'forty' elif n // 10 == 5: res = 'fifty' elif n // 10 == 6: res = 'sixty' elif n // 10 == 7: res = 'seventy' elif n // 10 == 8: res = 'eighty' elif n // 10 == 9: res = 'ninety' if n % 10 == 1: res += '-one' elif n % 10 == 2: res += '-two' elif n % 10 == 3: res += '-three' elif n % 10 == 4: res += '-four' elif n % 10 == 5: res += '-five' elif n % 10 == 6: res += '-six' elif n % 10 == 7: res += '-seven' elif n % 10 == 8: res += '-eight' elif n % 10 == 9: res += '-nine' print(res) ```
output
1
9,481
20
18,963
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Today Tavas got his test result as an integer score and he wants to share it with his girlfriend, Nafas. His phone operating system is Tavdroid, and its keyboard doesn't have any digits! He wants to share his score with Nafas via text, so he has no choice but to send this number using words. <image> He ate coffee mix without water again, so right now he's really messed up and can't think. Your task is to help him by telling him what to type. Input The first and only line of input contains an integer s (0 ≀ s ≀ 99), Tavas's score. Output In the first and only line of output, print a single string consisting only from English lowercase letters and hyphens ('-'). Do not use spaces. Examples Input 6 Output six Input 99 Output ninety-nine Input 20 Output twenty Note You can find all you need to know about English numerals in <http://en.wikipedia.org/wiki/English_numerals> . Submitted Solution: ``` num = int(input()) dec = num // 10 s = '' low = ['zero', 'one' , 'two', 'three', 'four', 'five', 'six', 'seven','eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen'] high = ['__0', '__1', 'twenty','thirty','forty','fifty','sixty','seventy','eighty','ninety'] if dec > 1: s = high[dec] if num % 10 != 0: print(s + '-' + low[num % 10]) else: print(s) else: print(low[num]) ```
instruction
0
9,482
20
18,964
Yes
output
1
9,482
20
18,965
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Today Tavas got his test result as an integer score and he wants to share it with his girlfriend, Nafas. His phone operating system is Tavdroid, and its keyboard doesn't have any digits! He wants to share his score with Nafas via text, so he has no choice but to send this number using words. <image> He ate coffee mix without water again, so right now he's really messed up and can't think. Your task is to help him by telling him what to type. Input The first and only line of input contains an integer s (0 ≀ s ≀ 99), Tavas's score. Output In the first and only line of output, print a single string consisting only from English lowercase letters and hyphens ('-'). Do not use spaces. Examples Input 6 Output six Input 99 Output ninety-nine Input 20 Output twenty Note You can find all you need to know about English numerals in <http://en.wikipedia.org/wiki/English_numerals> . Submitted Solution: ``` nums = 'zero one two three four five six seven eight nine ten eleven twelve ' nums += 'thirteen fourteen fifteen sixteen seventeen eighteen nineteen' nums = nums.split(' ') tens = 'twenty thirty forty fifty sixty seventy eighty ninety'.split(' ') a = int(input()) if a < 20: ans = nums[a] else: ans = tens[a//10 - 2] if a % 10 != 0: ans += '-' + nums[a%10] print(ans) ```
instruction
0
9,483
20
18,966
Yes
output
1
9,483
20
18,967
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Today Tavas got his test result as an integer score and he wants to share it with his girlfriend, Nafas. His phone operating system is Tavdroid, and its keyboard doesn't have any digits! He wants to share his score with Nafas via text, so he has no choice but to send this number using words. <image> He ate coffee mix without water again, so right now he's really messed up and can't think. Your task is to help him by telling him what to type. Input The first and only line of input contains an integer s (0 ≀ s ≀ 99), Tavas's score. Output In the first and only line of output, print a single string consisting only from English lowercase letters and hyphens ('-'). Do not use spaces. Examples Input 6 Output six Input 99 Output ninety-nine Input 20 Output twenty Note You can find all you need to know about English numerals in <http://en.wikipedia.org/wiki/English_numerals> . Submitted Solution: ``` n = int(input().strip()) d = {0 : 'zero', 1 : 'one', 2 : 'two', 3 : 'three', 4 : 'four', 5 : 'five', \ 6 : 'six', 7 : 'seven', 8 : 'eight', 9 : 'nine', 10 : 'ten', 11 : 'eleven',\ 12 : 'twelve', 13 : 'thirteen', 14 : 'fourteen', 15 : 'fifteen', \ 16 : 'sixteen', 17 : 'seventeen', 18 : 'eighteen', 19 : 'nineteen', \ 20 : 'twenty', 30: 'thirty', 40 : 'forty', 50 : 'fifty', 60 : 'sixty', \ 70 : 'seventy', 80 : 'eighty', 90: 'ninety'} if n in d: print(d[n]) else: affix = n % 10 prefix = n // 10 * 10 result = d[prefix] + '-' + d[affix] print(result) ```
instruction
0
9,484
20
18,968
Yes
output
1
9,484
20
18,969
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Today Tavas got his test result as an integer score and he wants to share it with his girlfriend, Nafas. His phone operating system is Tavdroid, and its keyboard doesn't have any digits! He wants to share his score with Nafas via text, so he has no choice but to send this number using words. <image> He ate coffee mix without water again, so right now he's really messed up and can't think. Your task is to help him by telling him what to type. Input The first and only line of input contains an integer s (0 ≀ s ≀ 99), Tavas's score. Output In the first and only line of output, print a single string consisting only from English lowercase letters and hyphens ('-'). Do not use spaces. Examples Input 6 Output six Input 99 Output ninety-nine Input 20 Output twenty Note You can find all you need to know about English numerals in <http://en.wikipedia.org/wiki/English_numerals> . Submitted Solution: ``` if __name__ == '__main__': arr = ['' for _ in range(100)] arr[0] = 'zero' arr[1] = 'one' arr[2] = 'two' arr[3] = 'three' arr[4] = 'four' arr[5] = 'five' arr[6] = 'six' arr[7] = 'seven' arr[8] = 'eight' arr[9] = 'nine' arr[10] = 'ten' arr[11] = 'eleven' arr[12] = 'twelve' arr[13] = 'thirteen' arr[14] = 'fourteen' arr[15] = 'fifteen' arr[16] = 'sixteen' arr[17] = 'seventeen' arr[18] = 'eighteen' arr[19] = 'nineteen' arr[20] = 'twenty' arr[30] = 'thirty' arr[40] = 'forty' arr[50] = 'fifty' arr[60] = 'sixty' arr[70] = 'seventy' arr[80] = 'eighty' arr[90] = 'ninety' n = int(input()) if arr[n]: print(arr[n]) else: ld = n % 10 print(arr[n - ld] + '-' + arr[ld]) ```
instruction
0
9,485
20
18,970
Yes
output
1
9,485
20
18,971
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Today Tavas got his test result as an integer score and he wants to share it with his girlfriend, Nafas. His phone operating system is Tavdroid, and its keyboard doesn't have any digits! He wants to share his score with Nafas via text, so he has no choice but to send this number using words. <image> He ate coffee mix without water again, so right now he's really messed up and can't think. Your task is to help him by telling him what to type. Input The first and only line of input contains an integer s (0 ≀ s ≀ 99), Tavas's score. Output In the first and only line of output, print a single string consisting only from English lowercase letters and hyphens ('-'). Do not use spaces. Examples Input 6 Output six Input 99 Output ninety-nine Input 20 Output twenty Note You can find all you need to know about English numerals in <http://en.wikipedia.org/wiki/English_numerals> . Submitted Solution: ``` a="zero one two three four five six seven eight nine".split() b ="ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen,nineteen".split() c ="a a twenty thirty fourty fifty sixty seventy eighty ninety".split() n = int(input()) if n<10: print(a[n%10]) elif n<20: print(b[n%10]) else: if n%10: print(c[n//10]+"-"+a[n%10]) else: print(c[n//10]) ```
instruction
0
9,486
20
18,972
No
output
1
9,486
20
18,973
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Today Tavas got his test result as an integer score and he wants to share it with his girlfriend, Nafas. His phone operating system is Tavdroid, and its keyboard doesn't have any digits! He wants to share his score with Nafas via text, so he has no choice but to send this number using words. <image> He ate coffee mix without water again, so right now he's really messed up and can't think. Your task is to help him by telling him what to type. Input The first and only line of input contains an integer s (0 ≀ s ≀ 99), Tavas's score. Output In the first and only line of output, print a single string consisting only from English lowercase letters and hyphens ('-'). Do not use spaces. Examples Input 6 Output six Input 99 Output ninety-nine Input 20 Output twenty Note You can find all you need to know about English numerals in <http://en.wikipedia.org/wiki/English_numerals> . Submitted Solution: ``` s = input() a = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen'] if int(s) < 20: print(a[int(s)-1]) else: n = int(s) if n > 39: if n % 10 == 0: print(a[int(s[0])-1], 'ty', sep = '') else: print(a[int(s[0]) - 1] ,'ty' , '-' , a[int(s[1])-1], sep ='') else: if n < 30: print('twenty', end = '') if n % 10 != 0: print('-', a[int(s[1])-1], sep = '') else: print('thirty', end = '') if n % 10 != 0: print('-', a[int(s[1])-1], sep = '') ```
instruction
0
9,487
20
18,974
No
output
1
9,487
20
18,975
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Today Tavas got his test result as an integer score and he wants to share it with his girlfriend, Nafas. His phone operating system is Tavdroid, and its keyboard doesn't have any digits! He wants to share his score with Nafas via text, so he has no choice but to send this number using words. <image> He ate coffee mix without water again, so right now he's really messed up and can't think. Your task is to help him by telling him what to type. Input The first and only line of input contains an integer s (0 ≀ s ≀ 99), Tavas's score. Output In the first and only line of output, print a single string consisting only from English lowercase letters and hyphens ('-'). Do not use spaces. Examples Input 6 Output six Input 99 Output ninety-nine Input 20 Output twenty Note You can find all you need to know about English numerals in <http://en.wikipedia.org/wiki/English_numerals> . Submitted Solution: ``` s = input() a = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen'] if int(s) == 0: print('zero') elif int(s) < 20: print(a[int(s)-1]) elif int(s) >= 80 and int(s) < 90: print('eighty', end = '') if int(s) != 80: print('-', a[int(s[1])-1], sep = '') else: n = int(s) if n > 39: if n % 10 == 0: print(a[int(s[0])-1], 'ty', sep = '') else: print(a[int(s[0]) - 1] ,'ty' , '-' , a[int(s[1])-1], sep ='') else: if n < 30: print('twenty', end = '') if n % 10 != 0: print('-', a[int(s[1])-1], sep = '') else: print('thirty', end = '') if n % 10 != 0: print('-', a[int(s[1])-1], sep = '') ```
instruction
0
9,488
20
18,976
No
output
1
9,488
20
18,977
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Today Tavas got his test result as an integer score and he wants to share it with his girlfriend, Nafas. His phone operating system is Tavdroid, and its keyboard doesn't have any digits! He wants to share his score with Nafas via text, so he has no choice but to send this number using words. <image> He ate coffee mix without water again, so right now he's really messed up and can't think. Your task is to help him by telling him what to type. Input The first and only line of input contains an integer s (0 ≀ s ≀ 99), Tavas's score. Output In the first and only line of output, print a single string consisting only from English lowercase letters and hyphens ('-'). Do not use spaces. Examples Input 6 Output six Input 99 Output ninety-nine Input 20 Output twenty Note You can find all you need to know about English numerals in <http://en.wikipedia.org/wiki/English_numerals> . Submitted Solution: ``` import sys def input(): return sys.stdin.readline().strip() def iinput(): return int(input()) def rinput(): return map(int, sys.stdin.readline().strip().split()) def get_list(): return list(map(int, sys.stdin.readline().strip().split())) n=iinput() a=['one','two','three','four','five','six','seven','eight','nine','ten','eleven','twelve','thirteen','fourteen','fifteen','sixteen','seventeen','eighteen','nineteen'] b=['twenty','thirty','forty','fifty','sixty','seventy','eighty','nighty'] if(n<=19): print(a[n-1]) elif(n%10==0 and n!=10): print(b[n//10 - 2]) elif(n>20 and n<30): print(b[0]+"-"+a[n-21]) elif(n>30 and n<40): print(b[1]+"-"+a[n-31]) elif(n>40 and n<50): print(b[2]+"-"+a[n-41]) elif(n>50 and n<60): print(b[3]+"-"+a[n-51]) elif(n>60 and n<70): print(b[4]+"-"+a[n-61]) elif(n>70 and n<80): print(b[5]+"-"+a[n-71]) elif(n>80 and n<90): print(b[6]+"-"+a[n-81]) elif(n>90): print(b[7]+"-"+a[n-91]) ```
instruction
0
9,489
20
18,978
No
output
1
9,489
20
18,979
Provide tags and a correct Python 3 solution for this coding contest problem. Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers a, b, c, d on the blackboard. During each of the next three minutes he took two numbers from the blackboard (not necessarily adjacent) and replaced them with their sum or their product. In the end he got one number. Unfortunately, due to the awful memory he forgot that number, but he remembers four original numbers, sequence of the operations and his surprise because of the very small result. Help Vladimir remember the forgotten number: find the smallest number that can be obtained from the original numbers by the given sequence of operations. Input First line contains four integers separated by space: 0 ≀ a, b, c, d ≀ 1000 β€” the original numbers. Second line contains three signs ('+' or '*' each) separated by space β€” the sequence of the operations in the order of performing. ('+' stands for addition, '*' β€” multiplication) Output Output one integer number β€” the minimal result which can be obtained. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d). Examples Input 1 1 1 1 + + * Output 3 Input 2 2 2 2 * * + Output 8 Input 1 2 3 4 * + + Output 9
instruction
0
9,490
20
18,980
Tags: brute force Correct Solution: ``` from itertools import permutations ch=list(map(int,input().split())) op=list(input().split()) def f(oper, x, y): if oper=="*": return (x*y) else: return (x+y) ans=10**12 for a,b,c,d in permutations(ch): ans=min(ans, min(f(op[2], f(op[1], f(op[0],a,b), c), d), f(op[2], f(op[0],a,b),f(op[1],c,d)))) print(ans) ```
output
1
9,490
20
18,981
Provide tags and a correct Python 3 solution for this coding contest problem. Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers a, b, c, d on the blackboard. During each of the next three minutes he took two numbers from the blackboard (not necessarily adjacent) and replaced them with their sum or their product. In the end he got one number. Unfortunately, due to the awful memory he forgot that number, but he remembers four original numbers, sequence of the operations and his surprise because of the very small result. Help Vladimir remember the forgotten number: find the smallest number that can be obtained from the original numbers by the given sequence of operations. Input First line contains four integers separated by space: 0 ≀ a, b, c, d ≀ 1000 β€” the original numbers. Second line contains three signs ('+' or '*' each) separated by space β€” the sequence of the operations in the order of performing. ('+' stands for addition, '*' β€” multiplication) Output Output one integer number β€” the minimal result which can be obtained. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d). Examples Input 1 1 1 1 + + * Output 3 Input 2 2 2 2 * * + Output 8 Input 1 2 3 4 * + + Output 9
instruction
0
9,491
20
18,982
Tags: brute force Correct Solution: ``` s=list(map(int,input().split())) d=list(input().split()) min_=1000**4 for i in range(4): for j in range(i+1,4): if d[0]=='+': test1=s[i]+s[j] test2=s[i]+s[j] test3_1=s[i]+s[j] else: test1=s[i]*s[j] test2=s[i]*s[j] test3_1=s[i]*s[j] f=s.copy() f.pop(i) f.pop(j-1) if d[1]=='+': test1+=f[0] test2+=f[1] test3=f[1]+f[0] else: test1*=f[0] test2*=f[1] test3=f[1]*f[0] if d[2]=='+': test1+=f[1] test2+=f[0] test3+=test3_1 else: test1*=f[1] test2*=f[0] test3*=test3_1 new=min(test1,test2,test3) if new<min_: min_=new print(min_) ```
output
1
9,491
20
18,983
Provide tags and a correct Python 3 solution for this coding contest problem. Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers a, b, c, d on the blackboard. During each of the next three minutes he took two numbers from the blackboard (not necessarily adjacent) and replaced them with their sum or their product. In the end he got one number. Unfortunately, due to the awful memory he forgot that number, but he remembers four original numbers, sequence of the operations and his surprise because of the very small result. Help Vladimir remember the forgotten number: find the smallest number that can be obtained from the original numbers by the given sequence of operations. Input First line contains four integers separated by space: 0 ≀ a, b, c, d ≀ 1000 β€” the original numbers. Second line contains three signs ('+' or '*' each) separated by space β€” the sequence of the operations in the order of performing. ('+' stands for addition, '*' β€” multiplication) Output Output one integer number β€” the minimal result which can be obtained. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d). Examples Input 1 1 1 1 + + * Output 3 Input 2 2 2 2 * * + Output 8 Input 1 2 3 4 * + + Output 9
instruction
0
9,492
20
18,984
Tags: brute force Correct Solution: ``` #***************55B - Smallest number***************# #author: @Divyesh Chhabra from math import * import os import random import re import sys from itertools import * m = pow(10,9)+7 n = list(map(int,input().split())) s = input() n.sort() mul = 0 add = 0 for i in s: if i == '*': mul += 1 else: add += 1 if mul == 0: print(n[0]+n[1]+n[2]+n[3]) elif mul == 3: print(n[0]*n[1]*n[2]*n[3]) elif mul == 2: if s == '* * +': print(min(n[3]+n[1]*n[2]*n[0],n[0]*n[1]+n[2]*n[3],n[0]*n[2]+n[1]*n[3],n[0]*n[3]+n[1]*n[2])) elif s == '* + *': print(n[0]*(n[1]*n[2]+n[3])) else: print(n[0]*n[1]*(n[2]+n[3])) else: if s == '+ + *': print((n[1]+n[2]+n[3])*n[0]) elif s == '+ * + ': print(min((n[1]+n[2])*n[0]+n[3]),n[0]*n[1]+n[2]+n[3]) else: print(n[0]*n[1]+n[3]+n[2]) ```
output
1
9,492
20
18,985
Provide tags and a correct Python 3 solution for this coding contest problem. Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers a, b, c, d on the blackboard. During each of the next three minutes he took two numbers from the blackboard (not necessarily adjacent) and replaced them with their sum or their product. In the end he got one number. Unfortunately, due to the awful memory he forgot that number, but he remembers four original numbers, sequence of the operations and his surprise because of the very small result. Help Vladimir remember the forgotten number: find the smallest number that can be obtained from the original numbers by the given sequence of operations. Input First line contains four integers separated by space: 0 ≀ a, b, c, d ≀ 1000 β€” the original numbers. Second line contains three signs ('+' or '*' each) separated by space β€” the sequence of the operations in the order of performing. ('+' stands for addition, '*' β€” multiplication) Output Output one integer number β€” the minimal result which can be obtained. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d). Examples Input 1 1 1 1 + + * Output 3 Input 2 2 2 2 * * + Output 8 Input 1 2 3 4 * + + Output 9
instruction
0
9,493
20
18,986
Tags: brute force Correct Solution: ``` # ---------------------------iye ha aam zindegi--------------------------------------------- import math import heapq, bisect import sys from collections import deque, defaultdict from fractions import Fraction mod = 10 ** 9 + 7 mod1 = 998244353 # ------------------------------warmup---------------------------- import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # -------------------game starts now----------------------------------------------------import math class TreeNode: def __init__(self, k, v): self.key = k self.value = v self.left = None self.right = None self.parent = None self.height = 1 self.num_left = 1 self.num_total = 1 class AvlTree: def __init__(self): self._tree = None def add(self, k, v): if not self._tree: self._tree = TreeNode(k, v) return node = self._add(k, v) if node: self._rebalance(node) def _add(self, k, v): node = self._tree while node: if k < node.key: if node.left: node = node.left else: node.left = TreeNode(k, v) node.left.parent = node return node.left elif node.key < k: if node.right: node = node.right else: node.right = TreeNode(k, v) node.right.parent = node return node.right else: node.value = v return @staticmethod def get_height(x): return x.height if x else 0 @staticmethod def get_num_total(x): return x.num_total if x else 0 def _rebalance(self, node): n = node while n: lh = self.get_height(n.left) rh = self.get_height(n.right) n.height = max(lh, rh) + 1 balance_factor = lh - rh n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right) n.num_left = 1 + self.get_num_total(n.left) if balance_factor > 1: if self.get_height(n.left.left) < self.get_height(n.left.right): self._rotate_left(n.left) self._rotate_right(n) elif balance_factor < -1: if self.get_height(n.right.right) < self.get_height(n.right.left): self._rotate_right(n.right) self._rotate_left(n) else: n = n.parent def _remove_one(self, node): """ Side effect!!! Changes node. Node should have exactly one child """ replacement = node.left or node.right if node.parent: if AvlTree._is_left(node): node.parent.left = replacement else: node.parent.right = replacement replacement.parent = node.parent node.parent = None else: self._tree = replacement replacement.parent = None node.left = None node.right = None node.parent = None self._rebalance(replacement) def _remove_leaf(self, node): if node.parent: if AvlTree._is_left(node): node.parent.left = None else: node.parent.right = None self._rebalance(node.parent) else: self._tree = None node.parent = None node.left = None node.right = None def remove(self, k): node = self._get_node(k) if not node: return if AvlTree._is_leaf(node): self._remove_leaf(node) return if node.left and node.right: nxt = AvlTree._get_next(node) node.key = nxt.key node.value = nxt.value if self._is_leaf(nxt): self._remove_leaf(nxt) else: self._remove_one(nxt) self._rebalance(node) else: self._remove_one(node) def get(self, k): node = self._get_node(k) return node.value if node else -1 def _get_node(self, k): if not self._tree: return None node = self._tree while node: if k < node.key: node = node.left elif node.key < k: node = node.right else: return node return None def get_at(self, pos): x = pos + 1 node = self._tree while node: if x < node.num_left: node = node.left elif node.num_left < x: x -= node.num_left node = node.right else: return (node.key, node.value) raise IndexError("Out of ranges") @staticmethod def _is_left(node): return node.parent.left and node.parent.left == node @staticmethod def _is_leaf(node): return node.left is None and node.right is None def _rotate_right(self, node): if not node.parent: self._tree = node.left node.left.parent = None elif AvlTree._is_left(node): node.parent.left = node.left node.left.parent = node.parent else: node.parent.right = node.left node.left.parent = node.parent bk = node.left.right node.left.right = node node.parent = node.left node.left = bk if bk: bk.parent = node node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1 node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right) node.num_left = 1 + self.get_num_total(node.left) def _rotate_left(self, node): if not node.parent: self._tree = node.right node.right.parent = None elif AvlTree._is_left(node): node.parent.left = node.right node.right.parent = node.parent else: node.parent.right = node.right node.right.parent = node.parent bk = node.right.left node.right.left = node node.parent = node.right node.right = bk if bk: bk.parent = node node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1 node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right) node.num_left = 1 + self.get_num_total(node.left) @staticmethod def _get_next(node): if not node.right: return node.parent n = node.right while n.left: n = n.left return n avl=AvlTree() #-----------------------------------------------binary seacrh tree--------------------------------------- class SegmentTree1: def __init__(self, data, default='z', func=lambda a, b: min(a ,b)): """initialize the segment tree with data""" self._default = default self._func = func self._len = len(data) self._size = _size = 1 << (self._len - 1).bit_length() self.data = [default] * (2 * _size) self.data[_size:_size + self._len] = data for i in reversed(range(_size)): self.data[i] = func(self.data[i + i], self.data[i + i + 1]) def __delitem__(self, idx): self[idx] = self._default def __getitem__(self, idx): return self.data[idx + self._size] def __setitem__(self, idx, value): idx += self._size self.data[idx] = value idx >>= 1 while idx: self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1]) idx >>= 1 def __len__(self): return self._len def query(self, start, stop): if start == stop: return self.__getitem__(start) stop += 1 start += self._size stop += self._size res = self._default while start < stop: if start & 1: res = self._func(res, self.data[start]) start += 1 if stop & 1: stop -= 1 res = self._func(res, self.data[stop]) start >>= 1 stop >>= 1 return res def __repr__(self): return "SegmentTree({0})".format(self.data) # -------------------game starts now----------------------------------------------------import math class SegmentTree: def __init__(self, data, default=0, func=lambda a, b: a + b): """initialize the segment tree with data""" self._default = default self._func = func self._len = len(data) self._size = _size = 1 << (self._len - 1).bit_length() self.data = [default] * (2 * _size) self.data[_size:_size + self._len] = data for i in reversed(range(_size)): self.data[i] = func(self.data[i + i], self.data[i + i + 1]) def __delitem__(self, idx): self[idx] = self._default def __getitem__(self, idx): return self.data[idx + self._size] def __setitem__(self, idx, value): idx += self._size self.data[idx] = value idx >>= 1 while idx: self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1]) idx >>= 1 def __len__(self): return self._len def query(self, start, stop): if start == stop: return self.__getitem__(start) stop += 1 start += self._size stop += self._size res = self._default while start < stop: if start & 1: res = self._func(res, self.data[start]) start += 1 if stop & 1: stop -= 1 res = self._func(res, self.data[stop]) start >>= 1 stop >>= 1 return res def __repr__(self): return "SegmentTree({0})".format(self.data) # -------------------------------iye ha chutiya zindegi------------------------------------- class Factorial: def __init__(self, MOD): self.MOD = MOD self.factorials = [1, 1] self.invModulos = [0, 1] self.invFactorial_ = [1, 1] def calc(self, n): if n <= -1: print("Invalid argument to calculate n!") print("n must be non-negative value. But the argument was " + str(n)) exit() if n < len(self.factorials): return self.factorials[n] nextArr = [0] * (n + 1 - len(self.factorials)) initialI = len(self.factorials) prev = self.factorials[-1] m = self.MOD for i in range(initialI, n + 1): prev = nextArr[i - initialI] = prev * i % m self.factorials += nextArr return self.factorials[n] def inv(self, n): if n <= -1: print("Invalid argument to calculate n^(-1)") print("n must be non-negative value. But the argument was " + str(n)) exit() p = self.MOD pi = n % p if pi < len(self.invModulos): return self.invModulos[pi] nextArr = [0] * (n + 1 - len(self.invModulos)) initialI = len(self.invModulos) for i in range(initialI, min(p, n + 1)): next = -self.invModulos[p % i] * (p // i) % p self.invModulos.append(next) return self.invModulos[pi] def invFactorial(self, n): if n <= -1: print("Invalid argument to calculate (n^(-1))!") print("n must be non-negative value. But the argument was " + str(n)) exit() if n < len(self.invFactorial_): return self.invFactorial_[n] self.inv(n) # To make sure already calculated n^-1 nextArr = [0] * (n + 1 - len(self.invFactorial_)) initialI = len(self.invFactorial_) prev = self.invFactorial_[-1] p = self.MOD for i in range(initialI, n + 1): prev = nextArr[i - initialI] = (prev * self.invModulos[i % p]) % p self.invFactorial_ += nextArr return self.invFactorial_[n] class Combination: def __init__(self, MOD): self.MOD = MOD self.factorial = Factorial(MOD) def ncr(self, n, k): if k < 0 or n < k: return 0 k = min(k, n - k) f = self.factorial return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD # --------------------------------------iye ha combinations ka zindegi--------------------------------- def powm(a, n, m): if a == 1 or n == 0: return 1 if n % 2 == 0: s = powm(a, n // 2, m) return s * s % m else: return a * powm(a, n - 1, m) % m # --------------------------------------iye ha power ka zindegi--------------------------------- def sort_list(list1, list2): zipped_pairs = zip(list2, list1) z = [x for _, x in sorted(zipped_pairs)] return z # --------------------------------------------------product---------------------------------------- def product(l): por = 1 for i in range(len(l)): por *= l[i] return por # --------------------------------------------------binary---------------------------------------- def binarySearchCount(arr, n, key): left = 0 right = n - 1 count = 0 while (left <= right): mid = int((right + left)/ 2) # Check if middle element is # less than or equal to key if (arr[mid]<=key): count = mid+1 left = mid + 1 # If key is smaller, ignore right half else: right = mid - 1 return count # --------------------------------------------------binary---------------------------------------- def countdig(n): c = 0 while (n > 0): n //= 10 c += 1 return c def countGreater( arr,n, k): l = 0 r = n - 1 # Stores the index of the left most element # from the array which is greater than k leftGreater = n # Finds number of elements greater than k while (l <= r): m = int(l + (r - l) / 2) if (arr[m] >= k): leftGreater = m r = m - 1 # If mid element is less than # or equal to k update l else: l = m + 1 # Return the count of elements # greater than k return (n - leftGreater) # --------------------------------------------------binary------------------------------------ w=[] def calc(l,s): #print(l,s) if len(l)==1: w.append(l[0]) return we=[]+l for i in range(len(l)): for j in range(len(l)): if i==j: continue l=[]+we if s[0]=="+": l[i]+=l[j] l[j]=999999999999999 l.sort() l.pop() else: l[i] *= l[j] l[j] = 999999999999999 l.sort() l.pop() calc(l,s[1:]) l=list(map(int,input().split())) l.sort() s=list(map(str,input().split())) calc(l,s) print(min(w)) ```
output
1
9,493
20
18,987
Provide tags and a correct Python 3 solution for this coding contest problem. Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers a, b, c, d on the blackboard. During each of the next three minutes he took two numbers from the blackboard (not necessarily adjacent) and replaced them with their sum or their product. In the end he got one number. Unfortunately, due to the awful memory he forgot that number, but he remembers four original numbers, sequence of the operations and his surprise because of the very small result. Help Vladimir remember the forgotten number: find the smallest number that can be obtained from the original numbers by the given sequence of operations. Input First line contains four integers separated by space: 0 ≀ a, b, c, d ≀ 1000 β€” the original numbers. Second line contains three signs ('+' or '*' each) separated by space β€” the sequence of the operations in the order of performing. ('+' stands for addition, '*' β€” multiplication) Output Output one integer number β€” the minimal result which can be obtained. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d). Examples Input 1 1 1 1 + + * Output 3 Input 2 2 2 2 * * + Output 8 Input 1 2 3 4 * + + Output 9
instruction
0
9,494
20
18,988
Tags: brute force Correct Solution: ``` a, b, c, d = list(map(int,input().strip().split(' '))) first, second, third = input().strip().split(' ') min_value = 1000000000000 if first == '+': f_op = [[a + b, c, d], [a + c, b, d], [a + d, b, c], [b + c, a, d], [b + d, a, c], [c + d, a, b]] else: f_op = [[a * b, c, d], [a * c, b, d], [a * d, b, c], [b * c, a, d], [b * d, a, c], [c * d, a, b]] for i in range(6): x = f_op[i][0] y = f_op[i][1] z = f_op[i][2] if second == '+': s_op = [[x + y, z], [x + z, y], [y + z, x]] else: s_op = [[x * y, z], [x * z, y], [y * z, x]] if third == '+': m = min([s_op[0][0] + s_op[0][1], s_op[1][0] + s_op[1][1], s_op[2][0] + s_op[2][1]]) else: m = min([s_op[0][0] * s_op[0][1], s_op[1][0] * s_op[1][1], s_op[2][0] * s_op[2][1]]) min_value = min(min_value,m) print(min_value) ```
output
1
9,494
20
18,989
Provide tags and a correct Python 3 solution for this coding contest problem. Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers a, b, c, d on the blackboard. During each of the next three minutes he took two numbers from the blackboard (not necessarily adjacent) and replaced them with their sum or their product. In the end he got one number. Unfortunately, due to the awful memory he forgot that number, but he remembers four original numbers, sequence of the operations and his surprise because of the very small result. Help Vladimir remember the forgotten number: find the smallest number that can be obtained from the original numbers by the given sequence of operations. Input First line contains four integers separated by space: 0 ≀ a, b, c, d ≀ 1000 β€” the original numbers. Second line contains three signs ('+' or '*' each) separated by space β€” the sequence of the operations in the order of performing. ('+' stands for addition, '*' β€” multiplication) Output Output one integer number β€” the minimal result which can be obtained. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d). Examples Input 1 1 1 1 + + * Output 3 Input 2 2 2 2 * * + Output 8 Input 1 2 3 4 * + + Output 9
instruction
0
9,495
20
18,990
Tags: brute force Correct Solution: ``` #Code by Sounak, IIESTS #------------------------------warmup---------------------------- import os import sys import math from io import BytesIO, IOBase from fractions import Fraction from collections import defaultdict BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") #-------------------game starts now----------------------------------------------------- def fun(arr,op,o): if o==3: return arr[-1] mn=float('inf') for i in range(0,3): if arr[i]==-1: continue var=arr[i] arr[i]=-1 for j in range(i,4): if arr[j]==-1: continue var2=arr[j] if op[o]=="*": arr[j]=var*arr[j] if op[o]=="+": arr[j]=var+arr[j] mn=min(mn,fun(arr,op,o+1)) arr[j]=var2 arr[i]=var return mn arr=list(map(int,input().split())) op=input().split() print(fun(arr,op,0)) ```
output
1
9,495
20
18,991
Provide tags and a correct Python 3 solution for this coding contest problem. Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers a, b, c, d on the blackboard. During each of the next three minutes he took two numbers from the blackboard (not necessarily adjacent) and replaced them with their sum or their product. In the end he got one number. Unfortunately, due to the awful memory he forgot that number, but he remembers four original numbers, sequence of the operations and his surprise because of the very small result. Help Vladimir remember the forgotten number: find the smallest number that can be obtained from the original numbers by the given sequence of operations. Input First line contains four integers separated by space: 0 ≀ a, b, c, d ≀ 1000 β€” the original numbers. Second line contains three signs ('+' or '*' each) separated by space β€” the sequence of the operations in the order of performing. ('+' stands for addition, '*' β€” multiplication) Output Output one integer number β€” the minimal result which can be obtained. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d). Examples Input 1 1 1 1 + + * Output 3 Input 2 2 2 2 * * + Output 8 Input 1 2 3 4 * + + Output 9
instruction
0
9,496
20
18,992
Tags: brute force Correct Solution: ``` def cal( a , b , c ): if c[ 0 ] == '+': return int(a) + int(b) return int(a) * int(b) num = input().split() op = input().split() def DFS( l , no ): if no == 3: return int( l[ 0 ] ) else: ln = len( l ) ans = 10 ** 100 for i in range( ln ): for j in range( i + 1 , ln ): ll = [] for k in range( ln ): if i != k and j != k: ll.append( l[ k ] ) ll.append( cal( l[ i ] , l[ j ] , op[ no ] ) ) ans = min( ans , DFS( ll , no + 1 ) ) return ans print( DFS( num , 0 ) ) ```
output
1
9,496
20
18,993
Provide tags and a correct Python 3 solution for this coding contest problem. Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers a, b, c, d on the blackboard. During each of the next three minutes he took two numbers from the blackboard (not necessarily adjacent) and replaced them with their sum or their product. In the end he got one number. Unfortunately, due to the awful memory he forgot that number, but he remembers four original numbers, sequence of the operations and his surprise because of the very small result. Help Vladimir remember the forgotten number: find the smallest number that can be obtained from the original numbers by the given sequence of operations. Input First line contains four integers separated by space: 0 ≀ a, b, c, d ≀ 1000 β€” the original numbers. Second line contains three signs ('+' or '*' each) separated by space β€” the sequence of the operations in the order of performing. ('+' stands for addition, '*' β€” multiplication) Output Output one integer number β€” the minimal result which can be obtained. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d). Examples Input 1 1 1 1 + + * Output 3 Input 2 2 2 2 * * + Output 8 Input 1 2 3 4 * + + Output 9
instruction
0
9,497
20
18,994
Tags: brute force Correct Solution: ``` def z(a,b,k=0,f=1): n=len(a) if n==2: if b[k]=='+': return a[0]+a[1] return a[0]*a[1] c=-1 for i in range(n): for j in range(i+1,n): if b[k]=='+': g=list(a) a[i]+=a[j] a=a[:j]+a[j+1:] d=z(a,b,k+1,f+1) if c==-1 or d<c: c=d a=list(g) else: g=list(a) a[i]*=a[j] a=a[:j]+a[j+1:] d=z(a,b,k+1,f+1) if c==-1 or d<c: c=d a=list(g) return c print(z(list(map(int,input().split())),input().split())) ```
output
1
9,497
20
18,995
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an integer m. Let M = 2m - 1. You are also given a set of n integers denoted as the set T. The integers will be provided in base 2 as n binary strings of length m. A set of integers S is called "good" if the following hold. 1. If <image>, then <image>. 2. If <image>, then <image> 3. <image> 4. All elements of S are less than or equal to M. Here, <image> and <image> refer to the bitwise XOR and bitwise AND operators, respectively. Count the number of good sets S, modulo 109 + 7. Input The first line will contain two integers m and n (1 ≀ m ≀ 1 000, 1 ≀ n ≀ min(2m, 50)). The next n lines will contain the elements of T. Each line will contain exactly m zeros and ones. Elements of T will be distinct. Output Print a single integer, the number of good sets modulo 109 + 7. Examples Input 5 3 11010 00101 11000 Output 4 Input 30 2 010101010101010010101010101010 110110110110110011011011011011 Output 860616440 Note An example of a valid set S is {00000, 00101, 00010, 00111, 11000, 11010, 11101, 11111}.
instruction
0
9,633
20
19,266
Tags: bitmasks, combinatorics, dp, math Correct Solution: ``` from collections import defaultdict def E1(): mod = 10 ** 9 + 7 comb = [[1]] for i in range(1, 1010): x = [1] for j in range(1, i): x.append((comb[i - 1][j - 1] + comb[i - 1][j]) % mod) x.append(1) comb.append(x) dp = [1] for i in range(1, 1010): r = 0 for k in range(i): r += dp[k] * comb[i - 1][k] r %= mod dp.append(r) m, n = map(int, input().split()) ns = [0 for __ in range(m)] for j in range(n): temp = input() s = [int(i) for i in temp] for i in range(m): ns[i] |= s[i] << j dd = defaultdict(int) for e in ns: dd[e] += 1 ans = 1 for b in dd.values(): ans = ans * dp[b] % mod print(ans) if __name__=='__main__': E1() ```
output
1
9,633
20
19,267
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an integer m. Let M = 2m - 1. You are also given a set of n integers denoted as the set T. The integers will be provided in base 2 as n binary strings of length m. A set of integers S is called "good" if the following hold. 1. If <image>, then <image>. 2. If <image>, then <image> 3. <image> 4. All elements of S are less than or equal to M. Here, <image> and <image> refer to the bitwise XOR and bitwise AND operators, respectively. Count the number of good sets S, modulo 109 + 7. Input The first line will contain two integers m and n (1 ≀ m ≀ 1 000, 1 ≀ n ≀ min(2m, 50)). The next n lines will contain the elements of T. Each line will contain exactly m zeros and ones. Elements of T will be distinct. Output Print a single integer, the number of good sets modulo 109 + 7. Examples Input 5 3 11010 00101 11000 Output 4 Input 30 2 010101010101010010101010101010 110110110110110011011011011011 Output 860616440 Note An example of a valid set S is {00000, 00101, 00010, 00111, 11000, 11010, 11101, 11111}.
instruction
0
9,634
20
19,268
Tags: bitmasks, combinatorics, dp, math Correct Solution: ``` import sys from collections import defaultdict as di MOD = int(1e9+7) #bells = di(int) #bells[0,0] = 1 #K=1000 #for j in range(1,K): # bells[0,j] = bells[j-1,j-1] # for i in range(j): # bells[i+1,j] = (bells[i,j] + bells[i,j-1])%MOD # #def bellman(n): # return bells[n-1,n-1] #lista = [] #for i in range(K): # lista.append(bellman(i+1)) #print(lista) #sys.exit() bells = [1, 2, 5, 15, 52, 203, 877, 4140, 21147, 115975, 678570, 4213597, 27644437, 190899322, 382958538, 480142077, 864869230, 76801385, 742164233, 157873304, 812832668, 706900318, 546020311, 173093227, 759867260, 200033042, 40680577, 159122123, 665114805, 272358185, 365885605, 744733441, 692873095, 463056339, 828412002, 817756178, 366396447, 683685664, 681586780, 840750853, 683889724, 216039853, 954226396, 858087702, 540284076, 514254014, 647209774, 900185117, 348985796, 609459762, 781824096, 756600466, 654591160, 171792186, 748630189, 848074470, 75742990, 352494923, 278101098, 462072300, 334907097, 10474572, 495625635, 586051441, 159996073, 479379757, 707597945, 561063550, 974840072, 209152841, 906106015, 467465396, 82034048, 392794164, 700950185, 344807921, 475335490, 496881113, 358229039, 519104519, 784488542, 665151655, 307919717, 591199688, 692769253, 335414677, 884560880, 847374378, 791103220, 200350027, 485480275, 557337842, 434181960, 73976309, 792463021, 462067202, 677783523, 295755371, 435431099, 193120002, 513369106, 134597056, 143018012, 353529690, 591382993, 163160926, 287984994, 842145354, 703798750, 386436223, 618375990, 636477101, 536261496, 574800957, 34046224, 167415054, 961776342, 807141069, 218578541, 513967253, 460200768, 230725907, 239843627, 792763805, 368353031, 740982762, 126993201, 967654419, 588554507, 728057622, 239984996, 818342358, 882367644, 216705655, 267152940, 867213913, 330735015, 934583772, 59261085, 443816525, 568733052, 754405433, 244324432, 153903806, 292097031, 557968620, 311976469, 242994387, 773037141, 549999484, 243701468, 941251494, 7149216, 932327662, 456857477, 739044033, 645452229, 69273749, 304951367, 503353209, 243194926, 688663125, 239795364, 522687881, 121506491, 835250259, 159173149, 545801717, 19848500, 322507013, 106069527, 807985703, 290163328, 971751677, 238407093, 981758956, 301257197, 728003485, 817681690, 318332431, 864806329, 87958605, 929106232, 617996713, 519300437, 307911059, 137306007, 887695462, 633135243, 442387331, 730250437, 27723819, 80605394, 760335262, 822289356, 415861662, 558003999, 645049413, 347692428, 380668983, 897875109, 278111491, 106909073, 951914124, 374756177, 635211535, 286442394, 774619548, 756991257, 929298287, 923425488, 182439740, 266683608, 415378498, 728411148, 808161291, 436338820, 692451577, 228029692, 235546564, 895805974, 758052804, 700926159, 226442121, 579900323, 96916377, 243044550, 858703179, 30279679, 343764928, 100627558, 840734795, 291199760, 989808717, 370270411, 158336199, 393391701, 881731480, 507200370, 588418523, 340981140, 295449954, 683858381, 903859151, 866470542, 4959332, 237784075, 861373023, 950693473, 955867890, 400039807, 939877954, 124824910, 954530940, 204884446, 42218442, 234856311, 189836713, 179563650, 683193288, 929322036, 73574908, 943547254, 103031032, 141180580, 540183111, 680050153, 382916846, 948921599, 252835397, 199109508, 551172546, 700090782, 44999714, 970123610, 145637563, 33948107, 267648423, 504777414, 584919509, 212459491, 242880452, 351366578, 345323768, 285497541, 692868556, 706562675, 675626979, 620872182, 136458675, 971105139, 182064384, 948539342, 186406165, 706529481, 790490927, 888369436, 784409511, 835815713, 447895018, 17015606, 342727699, 321837918, 394134115, 563672582, 70390332, 61116103, 949269501, 833942074, 581389345, 570974405, 768179852, 765734098, 928340756, 541194960, 126833304, 427218334, 75800034, 100445725, 242810216, 330081440, 986329793, 298082322, 643160582, 505669854, 255287400, 403977567, 659185446, 596703087, 289443930, 478095124, 920175726, 205886838, 729278433, 535998256, 658801091, 606948240, 432632296, 552723022, 17794080, 234033713, 189986528, 444922724, 263196004, 846019724, 684703320, 895782046, 505050988, 44287113, 505335732, 436498414, 12098144, 714227851, 643983136, 647148160, 579243434, 951209063, 511291462, 426622734, 830870687, 949900312, 599926584, 633837711, 176405710, 913717356, 753535741, 874916804, 956692925, 220742732, 649500982, 584759931, 109573948, 937203173, 96881033, 305784835, 559854872, 894253854, 746366726, 951492991, 532579856, 822308583, 572042503, 397665465, 600979983, 914199453, 628402767, 594763006, 9791558, 451332658, 516069180, 651367831, 962708649, 687016963, 539878802, 107278296, 926059014, 371504543, 556987417, 447666745, 565595310, 778161513, 995461128, 121460302, 599892490, 242414970, 900391574, 362620950, 292857964, 495260535, 355054738, 176340034, 370047225, 509682533, 459314034, 40869728, 534741938, 788604648, 945028000, 701904601, 154924404, 695162652, 220536827, 615701976, 167761915, 833779942, 52430883, 368585637, 936409860, 654822736, 613850019, 941559844, 357840989, 218223326, 721900618, 171013438, 597980462, 193395922, 949112044, 859322955, 354602094, 807705992, 347609311, 451694117, 623122523, 252980054, 491785682, 13877214, 918727309, 750110421, 114981703, 174636266, 363160184, 781715298, 30575457, 862940854, 642129450, 34525888, 798422280, 792396821, 168367459, 344551406, 799847612, 626838494, 671596530, 167280197, 959000039, 614621296, 273560655, 8705247, 284372524, 940371542, 906010703, 582585495, 929449942, 308961449, 768816240, 674729787, 279648144, 286568146, 938661138, 536038536, 456529723, 18843013, 501518651, 457224675, 520694423, 938573228, 179014658, 169719825, 459657583, 302109678, 560375405, 556039265, 348713003, 957546568, 687116649, 3656313, 562760316, 716689588, 324677598, 570275686, 60738163, 996201577, 305457565, 38935942, 538451492, 228282207, 77975017, 389525459, 25000235, 152169430, 62331625, 618611219, 462328092, 106666757, 661839198, 177836427, 313546124, 392585017, 950280707, 551167559, 389204003, 77447456, 158414991, 766574847, 941433736, 363591676, 805565034, 312418363, 999641612, 122925536, 768845786, 608121932, 373163730, 783033644, 74564718, 894150080, 796617981, 274365270, 802488053, 947861187, 401960309, 143529635, 769621671, 249500752, 619408647, 849453216, 354838551, 69741157, 944781258, 135254314, 7413076, 416298064, 871313316, 343673168, 375656287, 868866230, 179060630, 399560227, 852555486, 987661859, 165863065, 12882359, 3688778, 380092596, 438366086, 720041886, 240796679, 588918084, 14802664, 17188673, 504951961, 842108931, 839289310, 256364811, 121095676, 164017670, 35340476, 875551801, 239615760, 262141182, 262741417, 456560451, 350350882, 777143297, 264469934, 807530935, 89546104, 246698645, 241166716, 125659016, 839103323, 418357064, 186866754, 179291319, 326054960, 172454707, 430532716, 558625738, 306201933, 61986384, 837357643, 575407529, 983555480, 13784333, 311989892, 153386582, 633092291, 722816631, 633510090, 551352594, 323601313, 248995449, 672011813, 612805937, 202743586, 215183002, 32688571, 38454892, 245790100, 451190956, 823199664, 12164578, 67389319, 584760532, 968838901, 307205626, 971537038, 836812364, 663878188, 468850566, 647599527, 839342879, 242347168, 169911213, 993779953, 251402771, 969281106, 416168275, 738337745, 8172262, 852101376, 879373674, 929752458, 452163141, 48347012, 500253327, 672444134, 406391337, 665852222, 499704706, 116418822, 67956495, 994761753, 808150613, 251453632, 543431315, 143101466, 381253760, 826943616, 763270983, 959511676, 323777679, 514214633, 669340157, 471626592, 557874503, 304789863, 116939617, 503636634, 660499296, 659726735, 273788323, 704107733, 718417780, 624033370, 355000823, 194537583, 760997582, 289828020, 778033293, 933152490, 910945024, 644565086, 434509630, 289427510, 502291783, 421699389, 159196930, 834667293, 313599675, 560298831, 812176354, 865521998, 126796474, 886921339, 937011401, 791993161, 583948688, 275408655, 665183437, 130342900, 699431744, 117550047, 460234251, 56770880, 306091228, 912949106, 626369877, 852501236, 241076503, 262988042, 737247015, 831044258, 475123008, 928949542, 332750699, 696284377, 689111142, 196862045, 570365577, 187156806, 451528865, 635110126, 385331290, 263486377, 200189955, 206842029, 457862597, 450522487, 818984909, 710634976, 461356455, 71985964, 781500456, 467334209, 46762760, 97663653, 870671823, 255977331, 79650379, 32876340, 636190780, 364339752, 597149326, 452604321, 748186407, 302032725, 779013981, 111971627, 175687535, 399961122, 451853028, 798326812, 902775588, 362836436, 498862780, 160000437, 629259604, 919729986, 5994845, 631476109, 371320167, 76164236, 448643023, 945220853, 111192011, 150577654, 827274836, 17668451, 938388515, 88566735, 27940328, 882026632, 712756966, 83642744, 873585716, 638987456, 405271094, 822216133, 345587303, 668558160, 314983205, 826678060, 563583341, 516998387, 77703032, 726563479, 155257773, 49705622, 891556456, 164127879, 842558039, 189099480, 956148983, 992226557, 671472701, 137476493, 871069222, 78241093, 728497057, 278888712, 332713952, 222597908, 235198692, 876216003, 167364357, 722341150, 519365334, 604855967, 834816722, 850786742, 416385106, 608404143, 311628039, 507077268, 571796589, 506398832, 305540948, 556971113, 444565912, 866477296, 411983920, 905854221, 901986568, 512703782, 684027511, 596294441, 916862272, 495347444, 802477106, 235968146, 257527513, 528476230, 969655767, 772044489, 682345813, 66418556, 603372280, 439233253, 278244332, 590581374, 353687769, 321352820, 245676729, 325255315, 91010070, 923699200, 837616604, 736177081, 528261400, 876353388, 339195128, 377206087, 769944080, 772953529, 123785293, 35984916, 461119619, 236140329, 884137913, 625494604, 791773064, 661436140, 308509072, 54134926, 279367618, 51918421, 149844467, 308119110, 948074070, 941738748, 890320056, 933243910, 430364344, 903312966, 574904506, 56353560, 861112413, 440392450, 937276559, 944662107, 599470900, 458887833, 962614595, 589151703, 997944986, 642961512, 63773929, 737273926, 110546606, 654813100, 374632916, 327432718, 307869727, 387738989, 133844439, 688886605, 989252194, 303514517, 79062408, 79381603, 941446109, 189307316, 728764788, 619946432, 359845738, 216171670, 690964059, 337106876, 762119224, 226624101, 401879891, 47069454, 41411521, 429556898, 188042667, 832342137, 770962364, 294422843, 991268380, 137519647, 903275202, 115040918, 521250780, 783585266, 98267582, 337193737, 717487549, 510794369, 206729333, 248526905, 412652544, 146948138, 103954760, 132289464, 938042429, 185735408, 640754677, 315573450, 956487685, 454822141, 783819416, 882547786, 976850791, 307258357, 929434429, 832158433, 334518103, 700273615, 734048238, 48618988, 693477108, 12561960, 598093056, 154072663, 174314067, 345548333, 479759833, 658594149, 282072153, 57970886, 905112877, 584117466, 472359245, 776860470, 324216896, 334199385, 321245477, 508188925, 521442872, 286692969, 245141864, 59342176, 896413224, 573301289, 869453643, 87399903, 60102262, 835514392, 493582549, 649986925, 576899388, 20454903, 271374500, 589229956, 505139242, 789538901, 243337905, 248443618, 39334644, 831631854, 541659849, 159802612, 524090232, 855135628, 542520502, 967119953, 597294058, 465231251] def bellman(n): return bells[n-1] m,n = [int(x) for x in input().split()] Tlist = [] for _ in range(n): Tlist.append(input()) numbs = [] for i in range(m): numb = [] for j in range(n): numb.append(Tlist[j][i]) numbs.append(int(''.join(numb),2)) eqsize = di(lambda:0) for numb in numbs: eqsize[numb]+=1 sets = [] for numb in eqsize: sets.append(eqsize[numb]) parts = 1 for s in sets: parts*=bellman(s) parts%=MOD print(parts) ```
output
1
9,634
20
19,269
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an integer m. Let M = 2m - 1. You are also given a set of n integers denoted as the set T. The integers will be provided in base 2 as n binary strings of length m. A set of integers S is called "good" if the following hold. 1. If <image>, then <image>. 2. If <image>, then <image> 3. <image> 4. All elements of S are less than or equal to M. Here, <image> and <image> refer to the bitwise XOR and bitwise AND operators, respectively. Count the number of good sets S, modulo 109 + 7. Input The first line will contain two integers m and n (1 ≀ m ≀ 1 000, 1 ≀ n ≀ min(2m, 50)). The next n lines will contain the elements of T. Each line will contain exactly m zeros and ones. Elements of T will be distinct. Output Print a single integer, the number of good sets modulo 109 + 7. Examples Input 5 3 11010 00101 11000 Output 4 Input 30 2 010101010101010010101010101010 110110110110110011011011011011 Output 860616440 Note An example of a valid set S is {00000, 00101, 00010, 00111, 11000, 11010, 11101, 11111}.
instruction
0
9,635
20
19,270
Tags: bitmasks, combinatorics, dp, math Correct Solution: ``` import sys #f = open('input', 'r') f = sys.stdin n,m = list(map(int, f.readline().split())) s = [f.readline().strip() for _ in range(m)] s = [list(x) for x in s] d = {} for k in zip(*s): if k in d: d[k] += 1 else: d[k] = 1 dv = d.values() got = [1, 2, 5, 15, 52, 203, 877, 4140, 21147, 115975, 678570, 4213597, 27644437, 190899322, 382958538, 480142077, 864869230, 76801385, 742164233, 157873304, 812832668, 706900318, 546020311, 173093227, 759867260, 200033042, 40680577, 159122123, 665114805, 272358185, 365885605, 744733441, 692873095, 463056339, 828412002, 817756178, 366396447, 683685664, 681586780, 840750853, 683889724, 216039853, 954226396, 858087702, 540284076, 514254014, 647209774, 900185117, 348985796, 609459762, 781824096, 756600466, 654591160, 171792186, 748630189, 848074470, 75742990, 352494923, 278101098, 462072300, 334907097, 10474572, 495625635, 586051441, 159996073, 479379757, 707597945, 561063550, 974840072, 209152841, 906106015, 467465396, 82034048, 392794164, 700950185, 344807921, 475335490, 496881113, 358229039, 519104519, 784488542, 665151655, 307919717, 591199688, 692769253, 335414677, 884560880, 847374378, 791103220, 200350027, 485480275, 557337842, 434181960, 73976309, 792463021, 462067202, 677783523, 295755371, 435431099, 193120002, 513369106, 134597056, 143018012, 353529690, 591382993, 163160926, 287984994, 842145354, 703798750, 386436223, 618375990, 636477101, 536261496, 574800957, 34046224, 167415054, 961776342, 807141069, 218578541, 513967253, 460200768, 230725907, 239843627, 792763805, 368353031, 740982762, 126993201, 967654419, 588554507, 728057622, 239984996, 818342358, 882367644, 216705655, 267152940, 867213913, 330735015, 934583772, 59261085, 443816525, 568733052, 754405433, 244324432, 153903806, 292097031, 557968620, 311976469, 242994387, 773037141, 549999484, 243701468, 941251494, 7149216, 932327662, 456857477, 739044033, 645452229, 69273749, 304951367, 503353209, 243194926, 688663125, 239795364, 522687881, 121506491, 835250259, 159173149, 545801717, 19848500, 322507013, 106069527, 807985703, 290163328, 971751677, 238407093, 981758956, 301257197, 728003485, 817681690, 318332431, 864806329, 87958605, 929106232, 617996713, 519300437, 307911059, 137306007, 887695462, 633135243, 442387331, 730250437, 27723819, 80605394, 760335262, 822289356, 415861662, 558003999, 645049413, 347692428, 380668983, 897875109, 278111491, 106909073, 951914124, 374756177, 635211535, 286442394, 774619548, 756991257, 929298287, 923425488, 182439740, 266683608, 415378498, 728411148, 808161291, 436338820, 692451577, 228029692, 235546564, 895805974, 758052804, 700926159, 226442121, 579900323, 96916377, 243044550, 858703179, 30279679, 343764928, 100627558, 840734795, 291199760, 989808717, 370270411, 158336199, 393391701, 881731480, 507200370, 588418523, 340981140, 295449954, 683858381, 903859151, 866470542, 4959332, 237784075, 861373023, 950693473, 955867890, 400039807, 939877954, 124824910, 954530940, 204884446, 42218442, 234856311, 189836713, 179563650, 683193288, 929322036, 73574908, 943547254, 103031032, 141180580, 540183111, 680050153, 382916846, 948921599, 252835397, 199109508, 551172546, 700090782, 44999714, 970123610, 145637563, 33948107, 267648423, 504777414, 584919509, 212459491, 242880452, 351366578, 345323768, 285497541, 692868556, 706562675, 675626979, 620872182, 136458675, 971105139, 182064384, 948539342, 186406165, 706529481, 790490927, 888369436, 784409511, 835815713, 447895018, 17015606, 342727699, 321837918, 394134115, 563672582, 70390332, 61116103, 949269501, 833942074, 581389345, 570974405, 768179852, 765734098, 928340756, 541194960, 126833304, 427218334, 75800034, 100445725, 242810216, 330081440, 986329793, 298082322, 643160582, 505669854, 255287400, 403977567, 659185446, 596703087, 289443930, 478095124, 920175726, 205886838, 729278433, 535998256, 658801091, 606948240, 432632296, 552723022, 17794080, 234033713, 189986528, 444922724, 263196004, 846019724, 684703320, 895782046, 505050988, 44287113, 505335732, 436498414, 12098144, 714227851, 643983136, 647148160, 579243434, 951209063, 511291462, 426622734, 830870687, 949900312, 599926584, 633837711, 176405710, 913717356, 753535741, 874916804, 956692925, 220742732, 649500982, 584759931, 109573948, 937203173, 96881033, 305784835, 559854872, 894253854, 746366726, 951492991, 532579856, 822308583, 572042503, 397665465, 600979983, 914199453, 628402767, 594763006, 9791558, 451332658, 516069180, 651367831, 962708649, 687016963, 539878802, 107278296, 926059014, 371504543, 556987417, 447666745, 565595310, 778161513, 995461128, 121460302, 599892490, 242414970, 900391574, 362620950, 292857964, 495260535, 355054738, 176340034, 370047225, 509682533, 459314034, 40869728, 534741938, 788604648, 945028000, 701904601, 154924404, 695162652, 220536827, 615701976, 167761915, 833779942, 52430883, 368585637, 936409860, 654822736, 613850019, 941559844, 357840989, 218223326, 721900618, 171013438, 597980462, 193395922, 949112044, 859322955, 354602094, 807705992, 347609311, 451694117, 623122523, 252980054, 491785682, 13877214, 918727309, 750110421, 114981703, 174636266, 363160184, 781715298, 30575457, 862940854, 642129450, 34525888, 798422280, 792396821, 168367459, 344551406, 799847612, 626838494, 671596530, 167280197, 959000039, 614621296, 273560655, 8705247, 284372524, 940371542, 906010703, 582585495, 929449942, 308961449, 768816240, 674729787, 279648144, 286568146, 938661138, 536038536, 456529723, 18843013, 501518651, 457224675, 520694423, 938573228, 179014658, 169719825, 459657583, 302109678, 560375405, 556039265, 348713003, 957546568, 687116649, 3656313, 562760316, 716689588, 324677598, 570275686, 60738163, 996201577, 305457565, 38935942, 538451492, 228282207, 77975017, 389525459, 25000235, 152169430, 62331625, 618611219, 462328092, 106666757, 661839198, 177836427, 313546124, 392585017, 950280707, 551167559, 389204003, 77447456, 158414991, 766574847, 941433736, 363591676, 805565034, 312418363, 999641612, 122925536, 768845786, 608121932, 373163730, 783033644, 74564718, 894150080, 796617981, 274365270, 802488053, 947861187, 401960309, 143529635, 769621671, 249500752, 619408647, 849453216, 354838551, 69741157, 944781258, 135254314, 7413076, 416298064, 871313316, 343673168, 375656287, 868866230, 179060630, 399560227, 852555486, 987661859, 165863065, 12882359, 3688778, 380092596, 438366086, 720041886, 240796679, 588918084, 14802664, 17188673, 504951961, 842108931, 839289310, 256364811, 121095676, 164017670, 35340476, 875551801, 239615760, 262141182, 262741417, 456560451, 350350882, 777143297, 264469934, 807530935, 89546104, 246698645, 241166716, 125659016, 839103323, 418357064, 186866754, 179291319, 326054960, 172454707, 430532716, 558625738, 306201933, 61986384, 837357643, 575407529, 983555480, 13784333, 311989892, 153386582, 633092291, 722816631, 633510090, 551352594, 323601313, 248995449, 672011813, 612805937, 202743586, 215183002, 32688571, 38454892, 245790100, 451190956, 823199664, 12164578, 67389319, 584760532, 968838901, 307205626, 971537038, 836812364, 663878188, 468850566, 647599527, 839342879, 242347168, 169911213, 993779953, 251402771, 969281106, 416168275, 738337745, 8172262, 852101376, 879373674, 929752458, 452163141, 48347012, 500253327, 672444134, 406391337, 665852222, 499704706, 116418822, 67956495, 994761753, 808150613, 251453632, 543431315, 143101466, 381253760, 826943616, 763270983, 959511676, 323777679, 514214633, 669340157, 471626592, 557874503, 304789863, 116939617, 503636634, 660499296, 659726735, 273788323, 704107733, 718417780, 624033370, 355000823, 194537583, 760997582, 289828020, 778033293, 933152490, 910945024, 644565086, 434509630, 289427510, 502291783, 421699389, 159196930, 834667293, 313599675, 560298831, 812176354, 865521998, 126796474, 886921339, 937011401, 791993161, 583948688, 275408655, 665183437, 130342900, 699431744, 117550047, 460234251, 56770880, 306091228, 912949106, 626369877, 852501236, 241076503, 262988042, 737247015, 831044258, 475123008, 928949542, 332750699, 696284377, 689111142, 196862045, 570365577, 187156806, 451528865, 635110126, 385331290, 263486377, 200189955, 206842029, 457862597, 450522487, 818984909, 710634976, 461356455, 71985964, 781500456, 467334209, 46762760, 97663653, 870671823, 255977331, 79650379, 32876340, 636190780, 364339752, 597149326, 452604321, 748186407, 302032725, 779013981, 111971627, 175687535, 399961122, 451853028, 798326812, 902775588, 362836436, 498862780, 160000437, 629259604, 919729986, 5994845, 631476109, 371320167, 76164236, 448643023, 945220853, 111192011, 150577654, 827274836, 17668451, 938388515, 88566735, 27940328, 882026632, 712756966, 83642744, 873585716, 638987456, 405271094, 822216133, 345587303, 668558160, 314983205, 826678060, 563583341, 516998387, 77703032, 726563479, 155257773, 49705622, 891556456, 164127879, 842558039, 189099480, 956148983, 992226557, 671472701, 137476493, 871069222, 78241093, 728497057, 278888712, 332713952, 222597908, 235198692, 876216003, 167364357, 722341150, 519365334, 604855967, 834816722, 850786742, 416385106, 608404143, 311628039, 507077268, 571796589, 506398832, 305540948, 556971113, 444565912, 866477296, 411983920, 905854221, 901986568, 512703782, 684027511, 596294441, 916862272, 495347444, 802477106, 235968146, 257527513, 528476230, 969655767, 772044489, 682345813, 66418556, 603372280, 439233253, 278244332, 590581374, 353687769, 321352820, 245676729, 325255315, 91010070, 923699200, 837616604, 736177081, 528261400, 876353388, 339195128, 377206087, 769944080, 772953529, 123785293, 35984916, 461119619, 236140329, 884137913, 625494604, 791773064, 661436140, 308509072, 54134926, 279367618, 51918421, 149844467, 308119110, 948074070, 941738748, 890320056, 933243910, 430364344, 903312966, 574904506, 56353560, 861112413, 440392450, 937276559, 944662107, 599470900, 458887833, 962614595, 589151703, 997944986, 642961512, 63773929, 737273926, 110546606, 654813100, 374632916, 327432718, 307869727, 387738989, 133844439, 688886605, 989252194, 303514517, 79062408, 79381603, 941446109, 189307316, 728764788, 619946432, 359845738, 216171670, 690964059, 337106876, 762119224, 226624101, 401879891, 47069454, 41411521, 429556898, 188042667, 832342137, 770962364, 294422843, 991268380, 137519647, 903275202, 115040918, 521250780, 783585266, 98267582, 337193737, 717487549, 510794369, 206729333, 248526905, 412652544, 146948138, 103954760, 132289464, 938042429, 185735408, 640754677, 315573450, 956487685, 454822141, 783819416, 882547786, 976850791, 307258357, 929434429, 832158433, 334518103, 700273615, 734048238, 48618988, 693477108, 12561960, 598093056, 154072663, 174314067, 345548333, 479759833, 658594149, 282072153, 57970886, 905112877, 584117466, 472359245, 776860470, 324216896, 334199385, 321245477, 508188925, 521442872, 286692969, 245141864, 59342176, 896413224, 573301289, 869453643, 87399903, 60102262, 835514392, 493582549, 649986925, 576899388, 20454903, 271374500, 589229956, 505139242, 789538901, 243337905, 248443618, 39334644, 831631854, 541659849, 159802612, 524090232, 855135628, 542520502, 967119953, 597294058, 465231251] MM = 10**9 + 7 ans = 1 for v in dv: ans = ans*got[v-1] ans = ans%MM print(ans) ''' t = [[0] * 1010 for _ in range(1010)] t[1][1] = 1 for i in range(2,1001): for j in range(1,i+1): t[i][j] = t[i-1][j-1] + t[i-1][j]*j t[i][j] = t[i][j] % MM print([sum(t[i])%MM for i in range(1,1001)]) ''' ```
output
1
9,635
20
19,271
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an integer m. Let M = 2m - 1. You are also given a set of n integers denoted as the set T. The integers will be provided in base 2 as n binary strings of length m. A set of integers S is called "good" if the following hold. 1. If <image>, then <image>. 2. If <image>, then <image> 3. <image> 4. All elements of S are less than or equal to M. Here, <image> and <image> refer to the bitwise XOR and bitwise AND operators, respectively. Count the number of good sets S, modulo 109 + 7. Input The first line will contain two integers m and n (1 ≀ m ≀ 1 000, 1 ≀ n ≀ min(2m, 50)). The next n lines will contain the elements of T. Each line will contain exactly m zeros and ones. Elements of T will be distinct. Output Print a single integer, the number of good sets modulo 109 + 7. Examples Input 5 3 11010 00101 11000 Output 4 Input 30 2 010101010101010010101010101010 110110110110110011011011011011 Output 860616440 Note An example of a valid set S is {00000, 00101, 00010, 00111, 11000, 11010, 11101, 11111}.
instruction
0
9,636
20
19,272
Tags: bitmasks, combinatorics, dp, math Correct Solution: ``` MOD = 10**9 + 7 m, N = map(int, input().split()) binom = [[1] + [0 for i in range(m)] for j in range(m + 1)] for n in range(1, m + 1): for k in range(1, n + 1): binom[n][k] = (binom[n - 1][k] + binom[n - 1][k - 1]) % MOD bell = [0 for n in range(m + 1)] bell[0] = bell[1] = 1 for n in range(1, m): for k in range(n + 1): bell[n + 1] += bell[k] * binom[n][k] bell[n + 1] %= MOD #print(bell) bags = [0 for i in range(m)] for it in range(N): for i, z in enumerate(input()): if z == '1': bags[i] |= (1 << it) difs = set(bags) sol = 1 for mask in difs: sol = sol * bell[bags.count(mask)] % MOD print(sol) ```
output
1
9,636
20
19,273
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an integer m. Let M = 2m - 1. You are also given a set of n integers denoted as the set T. The integers will be provided in base 2 as n binary strings of length m. A set of integers S is called "good" if the following hold. 1. If <image>, then <image>. 2. If <image>, then <image> 3. <image> 4. All elements of S are less than or equal to M. Here, <image> and <image> refer to the bitwise XOR and bitwise AND operators, respectively. Count the number of good sets S, modulo 109 + 7. Input The first line will contain two integers m and n (1 ≀ m ≀ 1 000, 1 ≀ n ≀ min(2m, 50)). The next n lines will contain the elements of T. Each line will contain exactly m zeros and ones. Elements of T will be distinct. Output Print a single integer, the number of good sets modulo 109 + 7. Examples Input 5 3 11010 00101 11000 Output 4 Input 30 2 010101010101010010101010101010 110110110110110011011011011011 Output 860616440 Note An example of a valid set S is {00000, 00101, 00010, 00111, 11000, 11010, 11101, 11111}.
instruction
0
9,637
20
19,274
Tags: bitmasks, combinatorics, dp, math Correct Solution: ``` from collections import defaultdict as di MOD = int(1e9+7) bells = di(int) bells[0,0] = 1 K=1000 for j in range(1,K): bells[0,j] = bells[j-1,j-1] for i in range(j): bells[i+1,j] = (bells[i,j] + bells[i,j-1])%MOD def bellman(n): return bells[n-1,n-1] m,n = [int(x) for x in input().split()] Tlist = [] for _ in range(n): Tlist.append(input()) numbs = [] for i in range(m): numb = [] for j in range(n): numb.append(Tlist[j][i]) numbs.append(int(''.join(numb),2)) eqsize = di(lambda:0) for numb in numbs: eqsize[numb]+=1 sets = [] for numb in eqsize: sets.append(eqsize[numb]) parts = 1 for s in sets: parts*=bellman(s) parts%=MOD print(parts) ```
output
1
9,637
20
19,275
Provide tags and a correct Python 3 solution for this coding contest problem. Denis, after buying flowers and sweets (you will learn about this story in the next task), went to a date with Nastya to ask her to become a couple. Now, they are sitting in the cafe and finally... Denis asks her to be together, but ... Nastya doesn't give any answer. The poor boy was very upset because of that. He was so sad that he punched some kind of scoreboard with numbers. The numbers are displayed in the same way as on an electronic clock: each digit position consists of 7 segments, which can be turned on or off to display different numbers. The picture shows how all 10 decimal digits are displayed: <image> After the punch, some segments stopped working, that is, some segments might stop glowing if they glowed earlier. But Denis remembered how many sticks were glowing and how many are glowing now. Denis broke exactly k segments and he knows which sticks are working now. Denis came up with the question: what is the maximum possible number that can appear on the board if you turn on exactly k sticks (which are off now)? It is allowed that the number includes leading zeros. Input The first line contains integer n (1 ≀ n ≀ 2000) β€” the number of digits on scoreboard and k (0 ≀ k ≀ 2000) β€” the number of segments that stopped working. The next n lines contain one binary string of length 7, the i-th of which encodes the i-th digit of the scoreboard. Each digit on the scoreboard consists of 7 segments. We number them, as in the picture below, and let the i-th place of the binary string be 0 if the i-th stick is not glowing and 1 if it is glowing. Then a binary string of length 7 will specify which segments are glowing now. <image> Thus, the sequences "1110111", "0010010", "1011101", "1011011", "0111010", "1101011", "1101111", "1010010", "1111111", "1111011" encode in sequence all digits from 0 to 9 inclusive. Output Output a single number consisting of n digits β€” the maximum number that can be obtained if you turn on exactly k sticks or -1, if it is impossible to turn on exactly k sticks so that a correct number appears on the scoreboard digits. Examples Input 1 7 0000000 Output 8 Input 2 5 0010010 0010010 Output 97 Input 3 5 0100001 1001001 1010011 Output -1 Note In the first test, we are obliged to include all 7 sticks and get one 8 digit on the scoreboard. In the second test, we have sticks turned on so that units are formed. For 5 of additionally included sticks, you can get the numbers 07, 18, 34, 43, 70, 79, 81 and 97, of which we choose the maximum β€” 97. In the third test, it is impossible to turn on exactly 5 sticks so that a sequence of numbers appears on the scoreboard.
instruction
0
10,091
20
20,182
Tags: bitmasks, dp, graphs, greedy Correct Solution: ``` import sys input=sys.stdin.readline d={1:[3,6],0:[1,2,3,5,6,7],2:[1,3,5,4,7],3:[1,3,4,6,7],4:[2,3,4,6],5:[1,2,4,6,7],6:[1,2,4,5,6,7],7:[1,3,6],8:[1,2,3,4,5,6,7],9:[1,2,3,4,6,7]} n,k=map(int,input().split()) p=[[] for i in range(n+1)] f=[[-1 for i in range(10)] for j in range(n+1)] g=[[-1 for i in range(10)] for j in range(n+1)] for i in range(n): s=list(input().rstrip()) for j in range(len(s)): if s[j]=='1': p[i].append(j+1) for j in range(10): if len(set(p[i])-set(d[j]))!=0: continue else: z=len(set(d[j])-set(p[i])) f[i][z]=max(f[i][z],j) g[i][j]=z count=[[0 for i in range((k+1)*8)] for j in range(n+1)] for i in range(n-1,-1,-1): if i==n-1: for j in range(8): if f[i][j]!=-1: count[i][j]=1 else: for u in range(k+1): if count[i+1][u]==1: for y in range(8): if f[i][y]!=-1: count[i][y+u]=1 s="" #print(count) for i in range(n-1): for j in range(9,-1,-1): if g[i][j]!=-1 and count[i+1][k-g[i][j]]==1 and k>=g[i][j]: k-=g[i][j] s+=str(j) break if k>=0 and k<=8 and f[n-1][k]!=-1: s+=str(f[n-1][k]) print(s if len(s)==n else -1) ```
output
1
10,091
20
20,183
Provide tags and a correct Python 3 solution for this coding contest problem. Denis, after buying flowers and sweets (you will learn about this story in the next task), went to a date with Nastya to ask her to become a couple. Now, they are sitting in the cafe and finally... Denis asks her to be together, but ... Nastya doesn't give any answer. The poor boy was very upset because of that. He was so sad that he punched some kind of scoreboard with numbers. The numbers are displayed in the same way as on an electronic clock: each digit position consists of 7 segments, which can be turned on or off to display different numbers. The picture shows how all 10 decimal digits are displayed: <image> After the punch, some segments stopped working, that is, some segments might stop glowing if they glowed earlier. But Denis remembered how many sticks were glowing and how many are glowing now. Denis broke exactly k segments and he knows which sticks are working now. Denis came up with the question: what is the maximum possible number that can appear on the board if you turn on exactly k sticks (which are off now)? It is allowed that the number includes leading zeros. Input The first line contains integer n (1 ≀ n ≀ 2000) β€” the number of digits on scoreboard and k (0 ≀ k ≀ 2000) β€” the number of segments that stopped working. The next n lines contain one binary string of length 7, the i-th of which encodes the i-th digit of the scoreboard. Each digit on the scoreboard consists of 7 segments. We number them, as in the picture below, and let the i-th place of the binary string be 0 if the i-th stick is not glowing and 1 if it is glowing. Then a binary string of length 7 will specify which segments are glowing now. <image> Thus, the sequences "1110111", "0010010", "1011101", "1011011", "0111010", "1101011", "1101111", "1010010", "1111111", "1111011" encode in sequence all digits from 0 to 9 inclusive. Output Output a single number consisting of n digits β€” the maximum number that can be obtained if you turn on exactly k sticks or -1, if it is impossible to turn on exactly k sticks so that a correct number appears on the scoreboard digits. Examples Input 1 7 0000000 Output 8 Input 2 5 0010010 0010010 Output 97 Input 3 5 0100001 1001001 1010011 Output -1 Note In the first test, we are obliged to include all 7 sticks and get one 8 digit on the scoreboard. In the second test, we have sticks turned on so that units are formed. For 5 of additionally included sticks, you can get the numbers 07, 18, 34, 43, 70, 79, 81 and 97, of which we choose the maximum β€” 97. In the third test, it is impossible to turn on exactly 5 sticks so that a sequence of numbers appears on the scoreboard.
instruction
0
10,092
20
20,184
Tags: bitmasks, dp, graphs, greedy Correct Solution: ``` import sys n,k = map(int,input().split()); digits = [] ex = [[0]*10 for _ in range(n)] a = ["1110111","0010010","1011101","1011011","0111010","1101011","1101111","1010010","1111111","1111011"] a = list(map(lambda s:int(s,2),a)) for i in range(n): x = int(input(),2) for d in range(10): ex[i][d] = bin(a[d]-x).count("1") digits.append(x) dp = [[False]*(k+1) for _ in range(n+1)] dp[n][0] = True for i in range(n-1,-1,-1): for x in range(k+1): for d in range(10): if a[d]&digits[i] != digits[i]: continue excess = ex[i][d] if x-excess >= 0 and dp[i+1][x-excess]: dp[i][x] = True break # dp[0][k] = True ans = "" cur = k for i in range(n): found = False for d in range(9,-1,-1): if a[d]&digits[i] != digits[i]: continue excess = ex[i][d] if cur-excess >= 0 and dp[i+1][cur-excess]: cur -= excess ans += str(d) found = True break if not found: print(-1) exit() print(ans) ```
output
1
10,092
20
20,185
Provide tags and a correct Python 3 solution for this coding contest problem. Denis, after buying flowers and sweets (you will learn about this story in the next task), went to a date with Nastya to ask her to become a couple. Now, they are sitting in the cafe and finally... Denis asks her to be together, but ... Nastya doesn't give any answer. The poor boy was very upset because of that. He was so sad that he punched some kind of scoreboard with numbers. The numbers are displayed in the same way as on an electronic clock: each digit position consists of 7 segments, which can be turned on or off to display different numbers. The picture shows how all 10 decimal digits are displayed: <image> After the punch, some segments stopped working, that is, some segments might stop glowing if they glowed earlier. But Denis remembered how many sticks were glowing and how many are glowing now. Denis broke exactly k segments and he knows which sticks are working now. Denis came up with the question: what is the maximum possible number that can appear on the board if you turn on exactly k sticks (which are off now)? It is allowed that the number includes leading zeros. Input The first line contains integer n (1 ≀ n ≀ 2000) β€” the number of digits on scoreboard and k (0 ≀ k ≀ 2000) β€” the number of segments that stopped working. The next n lines contain one binary string of length 7, the i-th of which encodes the i-th digit of the scoreboard. Each digit on the scoreboard consists of 7 segments. We number them, as in the picture below, and let the i-th place of the binary string be 0 if the i-th stick is not glowing and 1 if it is glowing. Then a binary string of length 7 will specify which segments are glowing now. <image> Thus, the sequences "1110111", "0010010", "1011101", "1011011", "0111010", "1101011", "1101111", "1010010", "1111111", "1111011" encode in sequence all digits from 0 to 9 inclusive. Output Output a single number consisting of n digits β€” the maximum number that can be obtained if you turn on exactly k sticks or -1, if it is impossible to turn on exactly k sticks so that a correct number appears on the scoreboard digits. Examples Input 1 7 0000000 Output 8 Input 2 5 0010010 0010010 Output 97 Input 3 5 0100001 1001001 1010011 Output -1 Note In the first test, we are obliged to include all 7 sticks and get one 8 digit on the scoreboard. In the second test, we have sticks turned on so that units are formed. For 5 of additionally included sticks, you can get the numbers 07, 18, 34, 43, 70, 79, 81 and 97, of which we choose the maximum β€” 97. In the third test, it is impossible to turn on exactly 5 sticks so that a sequence of numbers appears on the scoreboard.
instruction
0
10,093
20
20,186
Tags: bitmasks, dp, graphs, greedy Correct Solution: ``` import sys, os, io def rs(): return sys.stdin.readline().rstrip() def ri(): return int(sys.stdin.readline()) def ria(): return list(map(int, sys.stdin.readline().split())) def ws(s): sys.stdout.write(s + '\n') def wi(n): sys.stdout.write(str(n) + '\n') def wia(a): sys.stdout.write(' '.join([str(x) for x in a]) + '\n') import math,datetime,functools,itertools,operator,bisect,fractions,statistics from collections import deque,defaultdict,OrderedDict,Counter from fractions import Fraction from decimal import Decimal from sys import stdout from heapq import heappush, heappop, heapify ,_heapify_max,_heappop_max,nsmallest,nlargest # sys.setrecursionlimit(111111) INF=999999999999999999999999 alphabets="abcdefghijklmnopqrstuvwxyz" class SortedList: def __init__(self, iterable=[], _load=200): """Initialize sorted list instance.""" values = sorted(iterable) self._len = _len = len(values) self._load = _load self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)] self._list_lens = [len(_list) for _list in _lists] self._mins = [_list[0] for _list in _lists] self._fen_tree = [] self._rebuild = True def _fen_build(self): """Build a fenwick tree instance.""" self._fen_tree[:] = self._list_lens _fen_tree = self._fen_tree for i in range(len(_fen_tree)): if i | i + 1 < len(_fen_tree): _fen_tree[i | i + 1] += _fen_tree[i] self._rebuild = False def _fen_update(self, index, value): """Update `fen_tree[index] += value`.""" if not self._rebuild: _fen_tree = self._fen_tree while index < len(_fen_tree): _fen_tree[index] += value index |= index + 1 def _fen_query(self, end): """Return `sum(_fen_tree[:end])`.""" if self._rebuild: self._fen_build() _fen_tree = self._fen_tree x = 0 while end: x += _fen_tree[end - 1] end &= end - 1 return x def _fen_findkth(self, k): """Return a pair of (the largest `idx` such that `sum(_fen_tree[:idx]) <= k`, `k - sum(_fen_tree[:idx])`).""" _list_lens = self._list_lens if k < _list_lens[0]: return 0, k if k >= self._len - _list_lens[-1]: return len(_list_lens) - 1, k + _list_lens[-1] - self._len if self._rebuild: self._fen_build() _fen_tree = self._fen_tree idx = -1 for d in reversed(range(len(_fen_tree).bit_length())): right_idx = idx + (1 << d) if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]: idx = right_idx k -= _fen_tree[idx] return idx + 1, k def _delete(self, pos, idx): """Delete value at the given `(pos, idx)`.""" _lists = self._lists _mins = self._mins _list_lens = self._list_lens self._len -= 1 self._fen_update(pos, -1) del _lists[pos][idx] _list_lens[pos] -= 1 if _list_lens[pos]: _mins[pos] = _lists[pos][0] else: del _lists[pos] del _list_lens[pos] del _mins[pos] self._rebuild = True def _loc_left(self, value): """Return an index pair that corresponds to the first position of `value` in the sorted list.""" if not self._len: return 0, 0 _lists = self._lists _mins = self._mins lo, pos = -1, len(_lists) - 1 while lo + 1 < pos: mi = (lo + pos) >> 1 if value <= _mins[mi]: pos = mi else: lo = mi if pos and value <= _lists[pos - 1][-1]: pos -= 1 _list = _lists[pos] lo, idx = -1, len(_list) while lo + 1 < idx: mi = (lo + idx) >> 1 if value <= _list[mi]: idx = mi else: lo = mi return pos, idx def _loc_right(self, value): """Return an index pair that corresponds to the last position of `value` in the sorted list.""" if not self._len: return 0, 0 _lists = self._lists _mins = self._mins pos, hi = 0, len(_lists) while pos + 1 < hi: mi = (pos + hi) >> 1 if value < _mins[mi]: hi = mi else: pos = mi _list = _lists[pos] lo, idx = -1, len(_list) while lo + 1 < idx: mi = (lo + idx) >> 1 if value < _list[mi]: idx = mi else: lo = mi return pos, idx def add(self, value): """Add `value` to sorted list.""" _load = self._load _lists = self._lists _mins = self._mins _list_lens = self._list_lens self._len += 1 if _lists: pos, idx = self._loc_right(value) self._fen_update(pos, 1) _list = _lists[pos] _list.insert(idx, value) _list_lens[pos] += 1 _mins[pos] = _list[0] if _load + _load < len(_list): _lists.insert(pos + 1, _list[_load:]) _list_lens.insert(pos + 1, len(_list) - _load) _mins.insert(pos + 1, _list[_load]) _list_lens[pos] = _load del _list[_load:] self._rebuild = True else: _lists.append([value]) _mins.append(value) _list_lens.append(1) self._rebuild = True def discard(self, value): """Remove `value` from sorted list if it is a member.""" _lists = self._lists if _lists: pos, idx = self._loc_right(value) if idx and _lists[pos][idx - 1] == value: self._delete(pos, idx - 1) def remove(self, value): """Remove `value` from sorted list; `value` must be a member.""" _len = self._len self.discard(value) if _len == self._len: raise ValueError('{0!r} not in list'.format(value)) def pop(self, index=-1): """Remove and return value at `index` in sorted list.""" pos, idx = self._fen_findkth(self._len + index if index < 0 else index) value = self._lists[pos][idx] self._delete(pos, idx) return value def bisect_left(self, value): """Return the first index to insert `value` in the sorted list.""" pos, idx = self._loc_left(value) return self._fen_query(pos) + idx def bisect_right(self, value): """Return the last index to insert `value` in the sorted list.""" pos, idx = self._loc_right(value) return self._fen_query(pos) + idx def count(self, value): """Return number of occurrences of `value` in the sorted list.""" return self.bisect_right(value) - self.bisect_left(value) def __len__(self): """Return the size of the sorted list.""" return self._len def __getitem__(self, index): """Lookup value at `index` in sorted list.""" pos, idx = self._fen_findkth(self._len + index if index < 0 else index) return self._lists[pos][idx] def __delitem__(self, index): """Remove value at `index` from sorted list.""" pos, idx = self._fen_findkth(self._len + index if index < 0 else index) self._delete(pos, idx) def __contains__(self, value): """Return true if `value` is an element of the sorted list.""" _lists = self._lists if _lists: pos, idx = self._loc_left(value) return idx < len(_lists[pos]) and _lists[pos][idx] == value return False def __iter__(self): """Return an iterator over the sorted list.""" return (value for _list in self._lists for value in _list) def __reversed__(self): """Return a reverse iterator over the sorted list.""" return (value for _list in reversed(self._lists) for value in reversed(_list)) def __repr__(self): """Return string representation of sorted list.""" return 'SortedList({0})'.format(list(self)) class SegTree: def __init__(self, n): self.N = 1 << n.bit_length() self.tree = [0] * (self.N<<1) def update(self, i, j, v): i += self.N j += self.N while i <= j: if i%2==1: self.tree[i] += v if j%2==0: self.tree[j] += v i, j = (i+1) >> 1, (j-1) >> 1 def query(self, i): v = 0 i += self.N while i > 0: v += self.tree[i] i >>= 1 return v def SieveOfEratosthenes(limit): """Returns all primes not greater than limit.""" isPrime = [True]*(limit+1) isPrime[0] = isPrime[1] = False primes = [] for i in range(2, limit+1): if not isPrime[i]:continue primes += [i] for j in range(i*i, limit+1, i): isPrime[j] = False return primes from collections import Counter def gcd(x, y): """greatest common divisor of x and y""" while y: x, y = y, x % y return x def memodict(f): """memoization decorator for a function taking a single argument""" class memodict(dict): def __missing__(self, key): ret = self[key] = f(key) return ret return memodict().__getitem__ def pollard_rho(n): """returns a random factor of n""" if n & 1 == 0: return 2 if n % 3 == 0: return 3 s = ((n - 1) & (1 - n)).bit_length() - 1 d = n >> s for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]: p = pow(a, d, n) if p == 1 or p == n - 1 or a % n == 0: continue for _ in range(s): prev = p p = (p * p) % n if p == 1: return gcd(prev - 1, n) if p == n - 1: break else: for i in range(2, n): x, y = i, (i * i + 1) % n f = gcd(abs(x - y), n) while f == 1: x, y = (x * x + 1) % n, (y * y + 1) % n y = (y * y + 1) % n f = gcd(abs(x - y), n) if f != n: return f return n @memodict def prime_factors(n): """returns a Counter of the prime factorization of n""" if n <= 1: return Counter() f = pollard_rho(n) return Counter([n]) if f == n else prime_factors(f) + prime_factors(n // f) def distinct_factors(n): """returns a list of all distinct factors of n""" factors = [1] for p, exp in prime_factors(n).items(): factors += [p**i * factor for factor in factors for i in range(1, exp + 1)] return factors def all_factors(n): """returns a sorted list of all distinct factors of n""" small, large = [], [] for i in range(1, int(n**0.5) + 1, 2 if n & 1 else 1): if not n % i: small.append(i) large.append(n // i) if small[-1] == large[-1]: large.pop() large.reverse() small.extend(large) return small def main(): mod=1000000007 # InverseofNumber(mod) # InverseofFactorial(mod) # factorial(mod) starttime=datetime.datetime.now() if(os.path.exists('input.txt')): sys.stdin = open("input.txt","r") sys.stdout = open("output.txt","w") tc=1 # Did you look at the constraints dummy? # 1.Greedy? # 2.DP? # 3.Binary Search?(Monotonic? any one directed order in which we have to perform something?) # 4.Graph? # 5.Number Theory?(GCD subtraction?) # 6.Bruteforce?(Redundant part of N which may not give answer?Constraints?) # 7.Range Queries? # 8.Any Equivalency?(We have A and B and have to do # something between them maybe difficult if there was A~C and C~B then A~B # C could be max or min or some other thing) # 9.Reverse Engineering?(From Answer to quesn or last step to first step) #10.Constructive? Mod? tc=1 for _ in range(tc): # LOGIC # Let dp[i][j]=true, if at the ith till nth digit boards you can turn on exactly j sticks # and get the correct sequence of digits and false otherwise. # set dp[n][c] initially then after calculations check dp[1][k] is true or not # It is easy to recalculate this dynamics: we will make transitions to all possible digits (the mask at position i should be a submask of the digit). # Now let's go in order from 1 to n and will try to eagerly set the maximum possible figure using our dynamics. # It is easy to understand that in this way we get the maximum possible number of n digits. n,k=ria() segments=["."] for i in range(n): segments.append(rs()) digits=["1110111", "0010010", "1011101", "1011011", "0111010", "1101011", "1101111", "1010010", "1111111", "1111011"] def cost(board,digits): c=0 for i in range(7): if board[i]=="1" and digits[i]=="0": return -1 if board[i]=="0" and digits[i]=="1": c+=1 return c costs=[[-1 for i in range(10)] for j in range(n+1)] for i in range(1,n+1): for d in range(10): costs[i][d]=cost(segments[i],digits[d]) dp=[[0 for i in range(k+1)] for j in range(n+1)] for d in range(10): c=costs[n][d] if c!=-1 and c<=k: dp[n][c]=1 for i in range(n,1,-1): for j in range(k+1): for d in range(10): if dp[i][j] and 0<=costs[i-1][d]<=k-j: dp[i-1][j+costs[i-1][d]]=1 if dp[1][k]==0: wi(-1) else: curr=k ans=[] for i in range(1,n): for d in range(9,-1,-1): if dp[i][curr] and 0<=costs[i][d]<=curr and dp[i+1][curr-costs[i][d]]: ans.append(str(d)) curr-=costs[i][d] break for d in range(9,-1,-1): if curr==costs[n][d]: ans.append(str(d)) break ws("".join(ans)) #<--Solving Area Ends endtime=datetime.datetime.now() time=(endtime-starttime).total_seconds()*1000 if(os.path.exists('input.txt')): print("Time:",time,"ms") class FastReader(io.IOBase): newlines = 0 def __init__(self, fd, chunk_size=1024 * 8): self._fd = fd self._chunk_size = chunk_size self.buffer = io.BytesIO() def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self, size=-1): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() class FastWriter(io.IOBase): def __init__(self, fd): self._fd = fd self.buffer = io.BytesIO() self.write = self.buffer.write def flush(self): os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class FastStdin(io.IOBase): def __init__(self, fd=0): self.buffer = FastReader(fd) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") class FastStdout(io.IOBase): def __init__(self, fd=1): self.buffer = FastWriter(fd) self.write = lambda s: self.buffer.write(s.encode("ascii")) self.flush = self.buffer.flush if __name__ == '__main__': sys.stdin = FastStdin() sys.stdout = FastStdout() main() ```
output
1
10,093
20
20,187
Provide tags and a correct Python 3 solution for this coding contest problem. Denis, after buying flowers and sweets (you will learn about this story in the next task), went to a date with Nastya to ask her to become a couple. Now, they are sitting in the cafe and finally... Denis asks her to be together, but ... Nastya doesn't give any answer. The poor boy was very upset because of that. He was so sad that he punched some kind of scoreboard with numbers. The numbers are displayed in the same way as on an electronic clock: each digit position consists of 7 segments, which can be turned on or off to display different numbers. The picture shows how all 10 decimal digits are displayed: <image> After the punch, some segments stopped working, that is, some segments might stop glowing if they glowed earlier. But Denis remembered how many sticks were glowing and how many are glowing now. Denis broke exactly k segments and he knows which sticks are working now. Denis came up with the question: what is the maximum possible number that can appear on the board if you turn on exactly k sticks (which are off now)? It is allowed that the number includes leading zeros. Input The first line contains integer n (1 ≀ n ≀ 2000) β€” the number of digits on scoreboard and k (0 ≀ k ≀ 2000) β€” the number of segments that stopped working. The next n lines contain one binary string of length 7, the i-th of which encodes the i-th digit of the scoreboard. Each digit on the scoreboard consists of 7 segments. We number them, as in the picture below, and let the i-th place of the binary string be 0 if the i-th stick is not glowing and 1 if it is glowing. Then a binary string of length 7 will specify which segments are glowing now. <image> Thus, the sequences "1110111", "0010010", "1011101", "1011011", "0111010", "1101011", "1101111", "1010010", "1111111", "1111011" encode in sequence all digits from 0 to 9 inclusive. Output Output a single number consisting of n digits β€” the maximum number that can be obtained if you turn on exactly k sticks or -1, if it is impossible to turn on exactly k sticks so that a correct number appears on the scoreboard digits. Examples Input 1 7 0000000 Output 8 Input 2 5 0010010 0010010 Output 97 Input 3 5 0100001 1001001 1010011 Output -1 Note In the first test, we are obliged to include all 7 sticks and get one 8 digit on the scoreboard. In the second test, we have sticks turned on so that units are formed. For 5 of additionally included sticks, you can get the numbers 07, 18, 34, 43, 70, 79, 81 and 97, of which we choose the maximum β€” 97. In the third test, it is impossible to turn on exactly 5 sticks so that a sequence of numbers appears on the scoreboard.
instruction
0
10,094
20
20,188
Tags: bitmasks, dp, graphs, greedy Correct Solution: ``` maxk=2005 #cost to move from source(s) to destination(d) def xcost(s,d): price=0 for i in range(7): if s[i]=='1' and d[i]=='0': price=maxk #cant convert break elif s[i]=='0' and d[i]=='1': price+=1 return price s=['1110111','0010010','1011101','1011011','0111010','1101011','1101111','1010010','1111111','1111011'] p=[] ##cost[i][j] = Cost to change i (int i converted to bin string) to s[j] cost=[[0 for j in range(10)] for i in range(128)] for i in range(128): x=bin(i)[2:].zfill(7) p.append(x) for i in range(128): for j in range(10): v=xcost(p[i],s[j]) cost[i][j]=v n,k=map(int,input().split(" ")) #scoreboard has integer value of the binary string representing the pattern at position scoreboard=[] for i in range(n): x=int(str(input()),2) scoreboard.append(x) # dp[i][j]=true , if at the suffix i…n you can turn on exactly j sticks and get the correct sequence dp=[[False for i in range(k+1)] for j in range(n)] i=n-1 bit_int=scoreboard[i] for j in cost[bit_int]: if j<=k: dp[i][j]=True for i in range(n-2,-1,-1): bit_int=scoreboard[i] for j in range(k+1): for x in cost[bit_int]: if j>=x: if dp[i+1][j-x]: dp[i][j]=True break if dp[0][k]: ans,spend,pos='',k,0 for i in scoreboard: for j in range(9,-1,-1): v=cost[i][j] if pos==n-1 and spend==v: ans+=str(j) break elif pos<n-1 and spend>=v: if dp[pos+1][spend-v]: ans+=str(j) spend-=v break pos+=1 print(ans) else: print(-1) ```
output
1
10,094
20
20,189
Provide tags and a correct Python 3 solution for this coding contest problem. Denis, after buying flowers and sweets (you will learn about this story in the next task), went to a date with Nastya to ask her to become a couple. Now, they are sitting in the cafe and finally... Denis asks her to be together, but ... Nastya doesn't give any answer. The poor boy was very upset because of that. He was so sad that he punched some kind of scoreboard with numbers. The numbers are displayed in the same way as on an electronic clock: each digit position consists of 7 segments, which can be turned on or off to display different numbers. The picture shows how all 10 decimal digits are displayed: <image> After the punch, some segments stopped working, that is, some segments might stop glowing if they glowed earlier. But Denis remembered how many sticks were glowing and how many are glowing now. Denis broke exactly k segments and he knows which sticks are working now. Denis came up with the question: what is the maximum possible number that can appear on the board if you turn on exactly k sticks (which are off now)? It is allowed that the number includes leading zeros. Input The first line contains integer n (1 ≀ n ≀ 2000) β€” the number of digits on scoreboard and k (0 ≀ k ≀ 2000) β€” the number of segments that stopped working. The next n lines contain one binary string of length 7, the i-th of which encodes the i-th digit of the scoreboard. Each digit on the scoreboard consists of 7 segments. We number them, as in the picture below, and let the i-th place of the binary string be 0 if the i-th stick is not glowing and 1 if it is glowing. Then a binary string of length 7 will specify which segments are glowing now. <image> Thus, the sequences "1110111", "0010010", "1011101", "1011011", "0111010", "1101011", "1101111", "1010010", "1111111", "1111011" encode in sequence all digits from 0 to 9 inclusive. Output Output a single number consisting of n digits β€” the maximum number that can be obtained if you turn on exactly k sticks or -1, if it is impossible to turn on exactly k sticks so that a correct number appears on the scoreboard digits. Examples Input 1 7 0000000 Output 8 Input 2 5 0010010 0010010 Output 97 Input 3 5 0100001 1001001 1010011 Output -1 Note In the first test, we are obliged to include all 7 sticks and get one 8 digit on the scoreboard. In the second test, we have sticks turned on so that units are formed. For 5 of additionally included sticks, you can get the numbers 07, 18, 34, 43, 70, 79, 81 and 97, of which we choose the maximum β€” 97. In the third test, it is impossible to turn on exactly 5 sticks so that a sequence of numbers appears on the scoreboard.
instruction
0
10,095
20
20,190
Tags: bitmasks, dp, graphs, greedy Correct Solution: ``` from sys import stdin,stdout input = stdin.readline from math import * print = stdout.write def cst(s,d): res=0 for i in range(7): if(s[i]=='1' and d[i]=='0'): return -1 elif(s[i]=='0' and d[i]=='1'): res+=1 return res n,k=map(int,input().split()) d=["1110111", "0010010", "1011101", "1011011", "0111010", "1101011", "1101111", "1010010", "1111111", "1111011"] cost=[[0]*10 for i in range(n)] t = [[0]*(k+1) for i in range(n)] for i in range(n): s=input() for j in range(10): cost[i][j]=cst(s,d[j]) ans=[-1]*n def dfs(i,k): if(i==n and k==0): # print(ans,i,k) return True elif(i==n and k!=0): return False if(t[i][k]!=0): return t[i][k]==1 for j in range(9,-1,-1): temp = cost[i][j] if(temp>=0 and temp<=k and dfs(i+1,k-cost[i][j])): ans[i]=j t[i][k]=1; return True t[i][k]=-1 return False dfs(0,k) if(-1 in ans): print('-1') else: print("".join(map(str,ans))) ```
output
1
10,095
20
20,191
Provide tags and a correct Python 3 solution for this coding contest problem. Denis, after buying flowers and sweets (you will learn about this story in the next task), went to a date with Nastya to ask her to become a couple. Now, they are sitting in the cafe and finally... Denis asks her to be together, but ... Nastya doesn't give any answer. The poor boy was very upset because of that. He was so sad that he punched some kind of scoreboard with numbers. The numbers are displayed in the same way as on an electronic clock: each digit position consists of 7 segments, which can be turned on or off to display different numbers. The picture shows how all 10 decimal digits are displayed: <image> After the punch, some segments stopped working, that is, some segments might stop glowing if they glowed earlier. But Denis remembered how many sticks were glowing and how many are glowing now. Denis broke exactly k segments and he knows which sticks are working now. Denis came up with the question: what is the maximum possible number that can appear on the board if you turn on exactly k sticks (which are off now)? It is allowed that the number includes leading zeros. Input The first line contains integer n (1 ≀ n ≀ 2000) β€” the number of digits on scoreboard and k (0 ≀ k ≀ 2000) β€” the number of segments that stopped working. The next n lines contain one binary string of length 7, the i-th of which encodes the i-th digit of the scoreboard. Each digit on the scoreboard consists of 7 segments. We number them, as in the picture below, and let the i-th place of the binary string be 0 if the i-th stick is not glowing and 1 if it is glowing. Then a binary string of length 7 will specify which segments are glowing now. <image> Thus, the sequences "1110111", "0010010", "1011101", "1011011", "0111010", "1101011", "1101111", "1010010", "1111111", "1111011" encode in sequence all digits from 0 to 9 inclusive. Output Output a single number consisting of n digits β€” the maximum number that can be obtained if you turn on exactly k sticks or -1, if it is impossible to turn on exactly k sticks so that a correct number appears on the scoreboard digits. Examples Input 1 7 0000000 Output 8 Input 2 5 0010010 0010010 Output 97 Input 3 5 0100001 1001001 1010011 Output -1 Note In the first test, we are obliged to include all 7 sticks and get one 8 digit on the scoreboard. In the second test, we have sticks turned on so that units are formed. For 5 of additionally included sticks, you can get the numbers 07, 18, 34, 43, 70, 79, 81 and 97, of which we choose the maximum β€” 97. In the third test, it is impossible to turn on exactly 5 sticks so that a sequence of numbers appears on the scoreboard.
instruction
0
10,096
20
20,192
Tags: bitmasks, dp, graphs, greedy Correct Solution: ``` import sys def compare(x, s): for i in range(len(x)): if x[i] == '1' and s[i] == '0': return False return True def compare2(x, s): count = 0 for i in range(len(x)): if x[i] == '0' and s[i] == '1': count += 1 return count li = ["1110111", "0010010", "1011101", "1011011", "0111010", "1101011", "1101111", "1010010", "1111111", "1111011"] dummy = li + [] dict = {} num = 0 for i in li: dict[i] = num num += 1 n, k = [int(x) for x in input().split()] arr = [] for i in range(n): s = input() arr.append(s) ans = [] k_ans = [] for i in range(len(arr)): need = 0 if dict.get(arr[i]) is not None: ans.append(arr[i]) else: need = 7 todo = li[8] for j in li: if compare(arr[i], j): p = compare2(arr[i], j) if p < need: need = p todo = j k -= need ans.append(todo) k_ans.append(need) if k < 0: print(-1) sys.exit(0) to_print = "" li = li[::-1] for i in range(n): s = ans[i] for j in li: if dict[j] <= dict[s]: break if compare(arr[i], j): p = compare2(arr[i], j) if p - k_ans[i] <= k: ans[i] = j k -= (p - k_ans[i]) k_ans[i] = p break if k >= 2: for i in range(n - 1, -1, -1): if dict[ans[i]] == 7: if compare(arr[i], dummy[5]): ans[i] = dummy[5] k -= 2 else: ans[i] = dummy[3] k -= 2 break flag = 0 if k > 0: index = 0 for i in range(n - 1, -1, -1): for j in li: if dict[j] < dict[ans[i]] and compare(arr[i], j): p = compare2(arr[i], j) if p - k_ans[i] <= k: k -= p - k_ans[i] if p - k_ans[i] < 0: flag = 1 else: flag = 2 ans[i] = j index = i break if flag != 0: break if flag == 1: nn = 0 for i in range(index + 1, n): for j in li: if dict[j] > dict[ans[i]] and compare(arr[i], j): p = compare2(arr[i], j) if p - k_ans[i] > k: continue k -= p - k_ans[i] ans[i] = j nn = 1 break if nn == 1: break if nn == 0: for i in range(n - 1, -1, -1): if dict[ans[i]] == 7: if compare(arr[i], dummy[5]): ans[i] = dummy[5] k -= 2 else: ans[i] = dummy[3] k -= 2 break if k > 0: for i in range(n - 1, -1, -1): if k == 0: break if dict[ans[i]] == 9: ans[i] = dummy[8] k -= 1 if k > 0: print(-1) sys.exit(0) for i in range(n): print(dict[ans[i]], end="") ```
output
1
10,096
20
20,193
Provide tags and a correct Python 3 solution for this coding contest problem. Denis, after buying flowers and sweets (you will learn about this story in the next task), went to a date with Nastya to ask her to become a couple. Now, they are sitting in the cafe and finally... Denis asks her to be together, but ... Nastya doesn't give any answer. The poor boy was very upset because of that. He was so sad that he punched some kind of scoreboard with numbers. The numbers are displayed in the same way as on an electronic clock: each digit position consists of 7 segments, which can be turned on or off to display different numbers. The picture shows how all 10 decimal digits are displayed: <image> After the punch, some segments stopped working, that is, some segments might stop glowing if they glowed earlier. But Denis remembered how many sticks were glowing and how many are glowing now. Denis broke exactly k segments and he knows which sticks are working now. Denis came up with the question: what is the maximum possible number that can appear on the board if you turn on exactly k sticks (which are off now)? It is allowed that the number includes leading zeros. Input The first line contains integer n (1 ≀ n ≀ 2000) β€” the number of digits on scoreboard and k (0 ≀ k ≀ 2000) β€” the number of segments that stopped working. The next n lines contain one binary string of length 7, the i-th of which encodes the i-th digit of the scoreboard. Each digit on the scoreboard consists of 7 segments. We number them, as in the picture below, and let the i-th place of the binary string be 0 if the i-th stick is not glowing and 1 if it is glowing. Then a binary string of length 7 will specify which segments are glowing now. <image> Thus, the sequences "1110111", "0010010", "1011101", "1011011", "0111010", "1101011", "1101111", "1010010", "1111111", "1111011" encode in sequence all digits from 0 to 9 inclusive. Output Output a single number consisting of n digits β€” the maximum number that can be obtained if you turn on exactly k sticks or -1, if it is impossible to turn on exactly k sticks so that a correct number appears on the scoreboard digits. Examples Input 1 7 0000000 Output 8 Input 2 5 0010010 0010010 Output 97 Input 3 5 0100001 1001001 1010011 Output -1 Note In the first test, we are obliged to include all 7 sticks and get one 8 digit on the scoreboard. In the second test, we have sticks turned on so that units are formed. For 5 of additionally included sticks, you can get the numbers 07, 18, 34, 43, 70, 79, 81 and 97, of which we choose the maximum β€” 97. In the third test, it is impossible to turn on exactly 5 sticks so that a sequence of numbers appears on the scoreboard.
instruction
0
10,097
20
20,194
Tags: bitmasks, dp, graphs, greedy Correct Solution: ``` D = [ '1110111', '0010010', '1011101', '1011011', '0111010', '1101011', '1101111', '1010010', '1111111', '1111011', ] n, k = list(map(int, input().split())) x = [input() for _ in range(n)] r = [[-1] * (k + 1) for _ in range(n + 1)] r[n][0] = 0 for i in range(n - 1, -1, -1): for d in range(10): dc = 0 for f, t in zip(x[i], D[d]): if f > t: break else: dc += f != t else: z = dc * 10 + d for c in range(k + 1 - dc): if r[i + 1][c] >= 0: r[i][c + dc] = z if r[0][k] >= 0: for i in range(n): print(r[i][k] % 10, end='') k -= r[i][k] // 10 print() else: print(-1) ```
output
1
10,097
20
20,195
Provide tags and a correct Python 3 solution for this coding contest problem. Denis, after buying flowers and sweets (you will learn about this story in the next task), went to a date with Nastya to ask her to become a couple. Now, they are sitting in the cafe and finally... Denis asks her to be together, but ... Nastya doesn't give any answer. The poor boy was very upset because of that. He was so sad that he punched some kind of scoreboard with numbers. The numbers are displayed in the same way as on an electronic clock: each digit position consists of 7 segments, which can be turned on or off to display different numbers. The picture shows how all 10 decimal digits are displayed: <image> After the punch, some segments stopped working, that is, some segments might stop glowing if they glowed earlier. But Denis remembered how many sticks were glowing and how many are glowing now. Denis broke exactly k segments and he knows which sticks are working now. Denis came up with the question: what is the maximum possible number that can appear on the board if you turn on exactly k sticks (which are off now)? It is allowed that the number includes leading zeros. Input The first line contains integer n (1 ≀ n ≀ 2000) β€” the number of digits on scoreboard and k (0 ≀ k ≀ 2000) β€” the number of segments that stopped working. The next n lines contain one binary string of length 7, the i-th of which encodes the i-th digit of the scoreboard. Each digit on the scoreboard consists of 7 segments. We number them, as in the picture below, and let the i-th place of the binary string be 0 if the i-th stick is not glowing and 1 if it is glowing. Then a binary string of length 7 will specify which segments are glowing now. <image> Thus, the sequences "1110111", "0010010", "1011101", "1011011", "0111010", "1101011", "1101111", "1010010", "1111111", "1111011" encode in sequence all digits from 0 to 9 inclusive. Output Output a single number consisting of n digits β€” the maximum number that can be obtained if you turn on exactly k sticks or -1, if it is impossible to turn on exactly k sticks so that a correct number appears on the scoreboard digits. Examples Input 1 7 0000000 Output 8 Input 2 5 0010010 0010010 Output 97 Input 3 5 0100001 1001001 1010011 Output -1 Note In the first test, we are obliged to include all 7 sticks and get one 8 digit on the scoreboard. In the second test, we have sticks turned on so that units are formed. For 5 of additionally included sticks, you can get the numbers 07, 18, 34, 43, 70, 79, 81 and 97, of which we choose the maximum β€” 97. In the third test, it is impossible to turn on exactly 5 sticks so that a sequence of numbers appears on the scoreboard.
instruction
0
10,098
20
20,196
Tags: bitmasks, dp, graphs, greedy Correct Solution: ``` # by the authority of GOD author: manhar singh sachdev # import os,sys from io import BytesIO, IOBase def bit_count(x): ans = 0 while x: x &= x-1 ans += 1 return ans def main(): n,k = map(int,input().split()) hir = [123,127,82,111,107,58,91,93,18,119] if not k: l = [] for _ in range(n): x = int(input().strip(),2) if x in hir: l.append(9-hir.index(x)) if len(l) == n: print(''.join(map(str,l))) else: print(-1) exit() dp = [[0 for _ in range(k+1)]for _ in range(n)] x = int(input().strip(),2) order = [[] for _ in range(n)] for ind,j in enumerate(hir): if j|x == j: y = bit_count(j^x) if y <= k and not dp[0][y]: dp[0][y] = (9-ind,y) order[0].append(y) for i in range(1,n): x = int(input().strip(),2) valid,inc = [],[] for ind,j in enumerate(hir): if j|x == j: valid.append(9-ind) inc.append(bit_count(j^x)) for t in order[i-1]: for a,b in zip(valid,inc): if t+b <= k and not dp[i][t+b]: dp[i][t+b] = (a,b) order[i].append(t+b) if not dp[-1][-1]: print(-1) else: xx = [] st,st1 = k,n-1 while st1 != -1: xx.append(str(dp[st1][st][0])) st -= dp[st1][st][1] st1 -= 1 print(''.join(map(str,reversed(xx)))) #Fast IO Region BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") if __name__ == '__main__': main() ```
output
1
10,098
20
20,197
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Denis, after buying flowers and sweets (you will learn about this story in the next task), went to a date with Nastya to ask her to become a couple. Now, they are sitting in the cafe and finally... Denis asks her to be together, but ... Nastya doesn't give any answer. The poor boy was very upset because of that. He was so sad that he punched some kind of scoreboard with numbers. The numbers are displayed in the same way as on an electronic clock: each digit position consists of 7 segments, which can be turned on or off to display different numbers. The picture shows how all 10 decimal digits are displayed: <image> After the punch, some segments stopped working, that is, some segments might stop glowing if they glowed earlier. But Denis remembered how many sticks were glowing and how many are glowing now. Denis broke exactly k segments and he knows which sticks are working now. Denis came up with the question: what is the maximum possible number that can appear on the board if you turn on exactly k sticks (which are off now)? It is allowed that the number includes leading zeros. Input The first line contains integer n (1 ≀ n ≀ 2000) β€” the number of digits on scoreboard and k (0 ≀ k ≀ 2000) β€” the number of segments that stopped working. The next n lines contain one binary string of length 7, the i-th of which encodes the i-th digit of the scoreboard. Each digit on the scoreboard consists of 7 segments. We number them, as in the picture below, and let the i-th place of the binary string be 0 if the i-th stick is not glowing and 1 if it is glowing. Then a binary string of length 7 will specify which segments are glowing now. <image> Thus, the sequences "1110111", "0010010", "1011101", "1011011", "0111010", "1101011", "1101111", "1010010", "1111111", "1111011" encode in sequence all digits from 0 to 9 inclusive. Output Output a single number consisting of n digits β€” the maximum number that can be obtained if you turn on exactly k sticks or -1, if it is impossible to turn on exactly k sticks so that a correct number appears on the scoreboard digits. Examples Input 1 7 0000000 Output 8 Input 2 5 0010010 0010010 Output 97 Input 3 5 0100001 1001001 1010011 Output -1 Note In the first test, we are obliged to include all 7 sticks and get one 8 digit on the scoreboard. In the second test, we have sticks turned on so that units are formed. For 5 of additionally included sticks, you can get the numbers 07, 18, 34, 43, 70, 79, 81 and 97, of which we choose the maximum β€” 97. In the third test, it is impossible to turn on exactly 5 sticks so that a sequence of numbers appears on the scoreboard. Submitted Solution: ``` from sys import stdin,stderr def rl(): return [int(w) for w in stdin.readline().split()] D = [ '1110111', '0010010', '1011101', '1011011', '0111010', '1101011', '1101111', '1010010', '1111111', '1111011', ] n,k = rl() x = [stdin.readline().rstrip() for _ in range(n)] r = [[-1]*(k+1) for _ in range(n+1)] r[n][0] = 0 for i in range(n-1,-1,-1): for d in range(10): dc = 0 for f,t in zip(x[i],D[d]): if f > t: break else: dc += f != t else: z = dc*10+d for c in range(k+1-dc): if r[i+1][c] >= 0: r[i][c+dc] = z if r[0][k] >= 0: for i in range(n): print(r[i][k] % 10, end='') k -= r[i][k] // 10 print() else: print(-1) ```
instruction
0
10,099
20
20,198
Yes
output
1
10,099
20
20,199
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Denis, after buying flowers and sweets (you will learn about this story in the next task), went to a date with Nastya to ask her to become a couple. Now, they are sitting in the cafe and finally... Denis asks her to be together, but ... Nastya doesn't give any answer. The poor boy was very upset because of that. He was so sad that he punched some kind of scoreboard with numbers. The numbers are displayed in the same way as on an electronic clock: each digit position consists of 7 segments, which can be turned on or off to display different numbers. The picture shows how all 10 decimal digits are displayed: <image> After the punch, some segments stopped working, that is, some segments might stop glowing if they glowed earlier. But Denis remembered how many sticks were glowing and how many are glowing now. Denis broke exactly k segments and he knows which sticks are working now. Denis came up with the question: what is the maximum possible number that can appear on the board if you turn on exactly k sticks (which are off now)? It is allowed that the number includes leading zeros. Input The first line contains integer n (1 ≀ n ≀ 2000) β€” the number of digits on scoreboard and k (0 ≀ k ≀ 2000) β€” the number of segments that stopped working. The next n lines contain one binary string of length 7, the i-th of which encodes the i-th digit of the scoreboard. Each digit on the scoreboard consists of 7 segments. We number them, as in the picture below, and let the i-th place of the binary string be 0 if the i-th stick is not glowing and 1 if it is glowing. Then a binary string of length 7 will specify which segments are glowing now. <image> Thus, the sequences "1110111", "0010010", "1011101", "1011011", "0111010", "1101011", "1101111", "1010010", "1111111", "1111011" encode in sequence all digits from 0 to 9 inclusive. Output Output a single number consisting of n digits β€” the maximum number that can be obtained if you turn on exactly k sticks or -1, if it is impossible to turn on exactly k sticks so that a correct number appears on the scoreboard digits. Examples Input 1 7 0000000 Output 8 Input 2 5 0010010 0010010 Output 97 Input 3 5 0100001 1001001 1010011 Output -1 Note In the first test, we are obliged to include all 7 sticks and get one 8 digit on the scoreboard. In the second test, we have sticks turned on so that units are formed. For 5 of additionally included sticks, you can get the numbers 07, 18, 34, 43, 70, 79, 81 and 97, of which we choose the maximum β€” 97. In the third test, it is impossible to turn on exactly 5 sticks so that a sequence of numbers appears on the scoreboard. Submitted Solution: ``` import sys def I(): return sys.stdin.readline().rstrip() cds = ["1110111", "0010010", "1011101", "1011011", "0111010", "1101011", "1101111", "1010010", "1111111", "1111011" ] def dist(s, n): cs = cds[n] cost = 0 for c, cc in zip(s, cs): if c != cc: if c == '1': return (False, 0) cost += 1 return (True, cost) def main(): n, k = map(int, I().split()) dstring = [I() for _ in range(n)] lens = {n: [0]} # dp = {(n, 0): ('-', 0)} dp = [[None] * (k+1) for _ in range(n+1)] dp[n][0] = ('-', 0) for i in range(n-1, -1, -1): idone = set() lens[i] = set() for d in range(9, -1, -1): char = chr(ord('0')+d) res = dist(dstring[i], d) if res[0]: diff = res[1] if diff in idone: continue idone.add(diff) for ln in lens[i+1]: ndiff = ln + diff if ndiff <= k and ndiff not in lens[i]: lens[i].add(ndiff) dp[i][ndiff] = (char, diff) if dp[0][k] != None: ans = [] for i in range(n): dpv = dp[i][k] ans.append(dpv[0]) k -= dpv[1] print("".join(ans)) else: print("-1") main() ```
instruction
0
10,100
20
20,200
Yes
output
1
10,100
20
20,201
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Denis, after buying flowers and sweets (you will learn about this story in the next task), went to a date with Nastya to ask her to become a couple. Now, they are sitting in the cafe and finally... Denis asks her to be together, but ... Nastya doesn't give any answer. The poor boy was very upset because of that. He was so sad that he punched some kind of scoreboard with numbers. The numbers are displayed in the same way as on an electronic clock: each digit position consists of 7 segments, which can be turned on or off to display different numbers. The picture shows how all 10 decimal digits are displayed: <image> After the punch, some segments stopped working, that is, some segments might stop glowing if they glowed earlier. But Denis remembered how many sticks were glowing and how many are glowing now. Denis broke exactly k segments and he knows which sticks are working now. Denis came up with the question: what is the maximum possible number that can appear on the board if you turn on exactly k sticks (which are off now)? It is allowed that the number includes leading zeros. Input The first line contains integer n (1 ≀ n ≀ 2000) β€” the number of digits on scoreboard and k (0 ≀ k ≀ 2000) β€” the number of segments that stopped working. The next n lines contain one binary string of length 7, the i-th of which encodes the i-th digit of the scoreboard. Each digit on the scoreboard consists of 7 segments. We number them, as in the picture below, and let the i-th place of the binary string be 0 if the i-th stick is not glowing and 1 if it is glowing. Then a binary string of length 7 will specify which segments are glowing now. <image> Thus, the sequences "1110111", "0010010", "1011101", "1011011", "0111010", "1101011", "1101111", "1010010", "1111111", "1111011" encode in sequence all digits from 0 to 9 inclusive. Output Output a single number consisting of n digits β€” the maximum number that can be obtained if you turn on exactly k sticks or -1, if it is impossible to turn on exactly k sticks so that a correct number appears on the scoreboard digits. Examples Input 1 7 0000000 Output 8 Input 2 5 0010010 0010010 Output 97 Input 3 5 0100001 1001001 1010011 Output -1 Note In the first test, we are obliged to include all 7 sticks and get one 8 digit on the scoreboard. In the second test, we have sticks turned on so that units are formed. For 5 of additionally included sticks, you can get the numbers 07, 18, 34, 43, 70, 79, 81 and 97, of which we choose the maximum β€” 97. In the third test, it is impossible to turn on exactly 5 sticks so that a sequence of numbers appears on the scoreboard. Submitted Solution: ``` def a2b(a, b): if a & (a^b) != 0: return -1 else: return sum(d == '1' for d in bin(b & (a^b))[2:]) n, k = map(int, input().split()) arr = [] for _ in range(n): arr.append(int(input(),2)) num_txt = ["1110111", "0010010", "1011101", "1011011", "0111010", "1101011", "1101111", "1010010", "1111111", "1111011"] numbers = list(map(lambda x: int(x, 2), num_txt)) # 0 to 9 cost = [[0] * (10) for _ in range(n)] for i in range(n): for d in range(10): cost[i][d] = a2b(arr[i],numbers[d]) dp = [[0] * (k+1) for _ in range(n+1)] dp[n][0] = 1 for i in range(n,0,-1): for j in range(k+1): if dp[i][j] == 1: for d in range(10): if cost[i-1][d] != -1 and cost[i-1][d] <= k-j: dp[i-1][j+cost[i-1][d]] = 1 if dp[0][k] == 0: print(-1) else: ans = '' for i in range(n): for d in range(9,-1,-1): if 0 <= cost[i][d] <= k and dp[i+1][k-cost[i][d]] == 1: ans += str(d) k -= cost[i][d] break print(ans) ```
instruction
0
10,101
20
20,202
Yes
output
1
10,101
20
20,203
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Denis, after buying flowers and sweets (you will learn about this story in the next task), went to a date with Nastya to ask her to become a couple. Now, they are sitting in the cafe and finally... Denis asks her to be together, but ... Nastya doesn't give any answer. The poor boy was very upset because of that. He was so sad that he punched some kind of scoreboard with numbers. The numbers are displayed in the same way as on an electronic clock: each digit position consists of 7 segments, which can be turned on or off to display different numbers. The picture shows how all 10 decimal digits are displayed: <image> After the punch, some segments stopped working, that is, some segments might stop glowing if they glowed earlier. But Denis remembered how many sticks were glowing and how many are glowing now. Denis broke exactly k segments and he knows which sticks are working now. Denis came up with the question: what is the maximum possible number that can appear on the board if you turn on exactly k sticks (which are off now)? It is allowed that the number includes leading zeros. Input The first line contains integer n (1 ≀ n ≀ 2000) β€” the number of digits on scoreboard and k (0 ≀ k ≀ 2000) β€” the number of segments that stopped working. The next n lines contain one binary string of length 7, the i-th of which encodes the i-th digit of the scoreboard. Each digit on the scoreboard consists of 7 segments. We number them, as in the picture below, and let the i-th place of the binary string be 0 if the i-th stick is not glowing and 1 if it is glowing. Then a binary string of length 7 will specify which segments are glowing now. <image> Thus, the sequences "1110111", "0010010", "1011101", "1011011", "0111010", "1101011", "1101111", "1010010", "1111111", "1111011" encode in sequence all digits from 0 to 9 inclusive. Output Output a single number consisting of n digits β€” the maximum number that can be obtained if you turn on exactly k sticks or -1, if it is impossible to turn on exactly k sticks so that a correct number appears on the scoreboard digits. Examples Input 1 7 0000000 Output 8 Input 2 5 0010010 0010010 Output 97 Input 3 5 0100001 1001001 1010011 Output -1 Note In the first test, we are obliged to include all 7 sticks and get one 8 digit on the scoreboard. In the second test, we have sticks turned on so that units are formed. For 5 of additionally included sticks, you can get the numbers 07, 18, 34, 43, 70, 79, 81 and 97, of which we choose the maximum β€” 97. In the third test, it is impossible to turn on exactly 5 sticks so that a sequence of numbers appears on the scoreboard. Submitted Solution: ``` import sys readline = sys.stdin.readline inf = 10**18 digits = [119, 18, 93, 91, 58, 107, 111, 82, 127, 123] popcount = [ [bin(x - y).count('1') if x & y == x else inf for y in range(2**7)] for x in range(2**7) ] N, K = map(int, input().split()) a = [int(readline().strip(), 2) for _ in range(N)] dp = [[0]*(K+1) for _ in range(N+1)] dp[0][K] = 1 # rightmost-digit to leftmost-digit for i, x in zip(range(N), reversed(a)): for j in range(K, -1, -1): if not dp[i][j]: continue for y in digits: if popcount[x][y] <= j: dp[i+1][j - popcount[x][y]] = 1 if not dp[N][0]: print(-1) exit() j = 0 ans = [] # leftmost-digit to rightmost digit for i, x in zip(range(N, 0, -1), a): for k, y in zip(range(9, -1, -1), reversed(digits)): if j + popcount[x][y] <= K and dp[i-1][j + popcount[x][y]]: ans.append(k) j += popcount[x][y] break print(*ans, sep='') ```
instruction
0
10,102
20
20,204
Yes
output
1
10,102
20
20,205
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Denis, after buying flowers and sweets (you will learn about this story in the next task), went to a date with Nastya to ask her to become a couple. Now, they are sitting in the cafe and finally... Denis asks her to be together, but ... Nastya doesn't give any answer. The poor boy was very upset because of that. He was so sad that he punched some kind of scoreboard with numbers. The numbers are displayed in the same way as on an electronic clock: each digit position consists of 7 segments, which can be turned on or off to display different numbers. The picture shows how all 10 decimal digits are displayed: <image> After the punch, some segments stopped working, that is, some segments might stop glowing if they glowed earlier. But Denis remembered how many sticks were glowing and how many are glowing now. Denis broke exactly k segments and he knows which sticks are working now. Denis came up with the question: what is the maximum possible number that can appear on the board if you turn on exactly k sticks (which are off now)? It is allowed that the number includes leading zeros. Input The first line contains integer n (1 ≀ n ≀ 2000) β€” the number of digits on scoreboard and k (0 ≀ k ≀ 2000) β€” the number of segments that stopped working. The next n lines contain one binary string of length 7, the i-th of which encodes the i-th digit of the scoreboard. Each digit on the scoreboard consists of 7 segments. We number them, as in the picture below, and let the i-th place of the binary string be 0 if the i-th stick is not glowing and 1 if it is glowing. Then a binary string of length 7 will specify which segments are glowing now. <image> Thus, the sequences "1110111", "0010010", "1011101", "1011011", "0111010", "1101011", "1101111", "1010010", "1111111", "1111011" encode in sequence all digits from 0 to 9 inclusive. Output Output a single number consisting of n digits β€” the maximum number that can be obtained if you turn on exactly k sticks or -1, if it is impossible to turn on exactly k sticks so that a correct number appears on the scoreboard digits. Examples Input 1 7 0000000 Output 8 Input 2 5 0010010 0010010 Output 97 Input 3 5 0100001 1001001 1010011 Output -1 Note In the first test, we are obliged to include all 7 sticks and get one 8 digit on the scoreboard. In the second test, we have sticks turned on so that units are formed. For 5 of additionally included sticks, you can get the numbers 07, 18, 34, 43, 70, 79, 81 and 97, of which we choose the maximum β€” 97. In the third test, it is impossible to turn on exactly 5 sticks so that a sequence of numbers appears on the scoreboard. Submitted Solution: ``` from sys import stderr m = { "1110111": 0, "0010010": 1, "1011101": 2, "1011011": 3, "0111010": 4, "1101011": 5, "1101111": 6, "1010010": 7, "1111111": 8, "1111011": 9 } def diff(s, t): ans = 0 for i in range(7): if s[i] < t[i]: ans += 1 elif s[i] > t[i]: return - 1 return ans def debug(*arg): print(*arg, file=stderr, flush=True) dp = [] d = [] n, k = 0, 0 def func(i, left): if i == n: return 0 if left == 0 else - int(1e9) if dp[i][left] is not None: return dp[i][left] ans = -int(1e9) for key, value in m.items(): temp = diff(d[i], key) if temp != -1 and temp <= left: ans = max(ans, value*(10**(n-i-1))+func(i+1, left-temp)) dp[i][left] = ans return ans n, k = list(map(int, input().split())) dp = n * [None] for i in range(n): dp[i] = (k+1)*[None] d = n * [None] for i in range(n): d[i] = input().strip() temp = func(0, k) if temp < 0: print(-1) else: print(temp) ```
instruction
0
10,103
20
20,206
No
output
1
10,103
20
20,207
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Denis, after buying flowers and sweets (you will learn about this story in the next task), went to a date with Nastya to ask her to become a couple. Now, they are sitting in the cafe and finally... Denis asks her to be together, but ... Nastya doesn't give any answer. The poor boy was very upset because of that. He was so sad that he punched some kind of scoreboard with numbers. The numbers are displayed in the same way as on an electronic clock: each digit position consists of 7 segments, which can be turned on or off to display different numbers. The picture shows how all 10 decimal digits are displayed: <image> After the punch, some segments stopped working, that is, some segments might stop glowing if they glowed earlier. But Denis remembered how many sticks were glowing and how many are glowing now. Denis broke exactly k segments and he knows which sticks are working now. Denis came up with the question: what is the maximum possible number that can appear on the board if you turn on exactly k sticks (which are off now)? It is allowed that the number includes leading zeros. Input The first line contains integer n (1 ≀ n ≀ 2000) β€” the number of digits on scoreboard and k (0 ≀ k ≀ 2000) β€” the number of segments that stopped working. The next n lines contain one binary string of length 7, the i-th of which encodes the i-th digit of the scoreboard. Each digit on the scoreboard consists of 7 segments. We number them, as in the picture below, and let the i-th place of the binary string be 0 if the i-th stick is not glowing and 1 if it is glowing. Then a binary string of length 7 will specify which segments are glowing now. <image> Thus, the sequences "1110111", "0010010", "1011101", "1011011", "0111010", "1101011", "1101111", "1010010", "1111111", "1111011" encode in sequence all digits from 0 to 9 inclusive. Output Output a single number consisting of n digits β€” the maximum number that can be obtained if you turn on exactly k sticks or -1, if it is impossible to turn on exactly k sticks so that a correct number appears on the scoreboard digits. Examples Input 1 7 0000000 Output 8 Input 2 5 0010010 0010010 Output 97 Input 3 5 0100001 1001001 1010011 Output -1 Note In the first test, we are obliged to include all 7 sticks and get one 8 digit on the scoreboard. In the second test, we have sticks turned on so that units are formed. For 5 of additionally included sticks, you can get the numbers 07, 18, 34, 43, 70, 79, 81 and 97, of which we choose the maximum β€” 97. In the third test, it is impossible to turn on exactly 5 sticks so that a sequence of numbers appears on the scoreboard. Submitted Solution: ``` from sys import stdin, stdout class Param: inf = int(1e10) code = ['1110111', '0010010', '1011101', '1011011', '0111010', '1101011', '1101111', '1010010', '1111111', '1111011'] n,k = list(map(int, stdin.readline().split())) s_list = [] for i in range(n): s_list.append( str(stdin.readline()) ) pass D = {} def move(s, value): if((s, value) in D): return D[(s, value)] pass x = code[value] ans = 0 for i in range(7): if(x[i] == '1' and s[i] == '0'): ans+=1 elif(x[i] == '1' and s[i] == '1'): pass elif(x[i] == '0' and s[i] == '0'): pass elif(x[i] == '0' and s[i] == '1'): ans = Param.inf break pass D[(s, value)] = ans return ans #dp = [[False] *(k+1)]*(n+1) dp = [[False]*(k+1) for i in range(n+1)] dp[0][0] = True for pos in range(1, n+1): for i in range(k+1): for value in range(10): need = move(s_list[-pos], value) if (i-need >= 0 and dp[pos-1][i-need]): dp[pos][i] = True print(str(pos) + ' ' + str(i)) break pass pass pass ans = '' if(dp[n][k] == False): ans = '-1' else: rest = k for pos in reversed(range(1, n+1)): for value in reversed(range(0,10)): need = move(s_list[-n], value) if(rest - need >=0 and dp[pos-1][rest - need]): ans += str(value) rest = rest - need break pass pass pass print(ans) ```
instruction
0
10,104
20
20,208
No
output
1
10,104
20
20,209
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Denis, after buying flowers and sweets (you will learn about this story in the next task), went to a date with Nastya to ask her to become a couple. Now, they are sitting in the cafe and finally... Denis asks her to be together, but ... Nastya doesn't give any answer. The poor boy was very upset because of that. He was so sad that he punched some kind of scoreboard with numbers. The numbers are displayed in the same way as on an electronic clock: each digit position consists of 7 segments, which can be turned on or off to display different numbers. The picture shows how all 10 decimal digits are displayed: <image> After the punch, some segments stopped working, that is, some segments might stop glowing if they glowed earlier. But Denis remembered how many sticks were glowing and how many are glowing now. Denis broke exactly k segments and he knows which sticks are working now. Denis came up with the question: what is the maximum possible number that can appear on the board if you turn on exactly k sticks (which are off now)? It is allowed that the number includes leading zeros. Input The first line contains integer n (1 ≀ n ≀ 2000) β€” the number of digits on scoreboard and k (0 ≀ k ≀ 2000) β€” the number of segments that stopped working. The next n lines contain one binary string of length 7, the i-th of which encodes the i-th digit of the scoreboard. Each digit on the scoreboard consists of 7 segments. We number them, as in the picture below, and let the i-th place of the binary string be 0 if the i-th stick is not glowing and 1 if it is glowing. Then a binary string of length 7 will specify which segments are glowing now. <image> Thus, the sequences "1110111", "0010010", "1011101", "1011011", "0111010", "1101011", "1101111", "1010010", "1111111", "1111011" encode in sequence all digits from 0 to 9 inclusive. Output Output a single number consisting of n digits β€” the maximum number that can be obtained if you turn on exactly k sticks or -1, if it is impossible to turn on exactly k sticks so that a correct number appears on the scoreboard digits. Examples Input 1 7 0000000 Output 8 Input 2 5 0010010 0010010 Output 97 Input 3 5 0100001 1001001 1010011 Output -1 Note In the first test, we are obliged to include all 7 sticks and get one 8 digit on the scoreboard. In the second test, we have sticks turned on so that units are formed. For 5 of additionally included sticks, you can get the numbers 07, 18, 34, 43, 70, 79, 81 and 97, of which we choose the maximum β€” 97. In the third test, it is impossible to turn on exactly 5 sticks so that a sequence of numbers appears on the scoreboard. Submitted Solution: ``` n,v= map(int,input().split()) w=n d= ["1110111", "0010010", "1011101", "1011011", "0111010", "1101011", "1101111", "1010010", "1111111", "1111011"] l=[] for _ in range(n): s= input() l.append(s) u='' for i in l: m=[] for j in range(7): if i[j]=='1': m.append(j) p=[] q=[] for k in d: c=0 for o in m: if k[o]=='1': c+=1 if c==i.count('1'): p.append(k) q.append(d.index(k)) r=[x.count('1')-i.count('1') for x in p] for t in range(len(p)-1,-1,-1): if n==1: if r[t]==v: v-=r[t] u+= str(q[t]) n-=1 break else: if r[t]<=v: v-=r[t] u+= str(q[t]) n-=1 break if len(u)!=w: print("-1") else: print(u) ```
instruction
0
10,105
20
20,210
No
output
1
10,105
20
20,211
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Denis, after buying flowers and sweets (you will learn about this story in the next task), went to a date with Nastya to ask her to become a couple. Now, they are sitting in the cafe and finally... Denis asks her to be together, but ... Nastya doesn't give any answer. The poor boy was very upset because of that. He was so sad that he punched some kind of scoreboard with numbers. The numbers are displayed in the same way as on an electronic clock: each digit position consists of 7 segments, which can be turned on or off to display different numbers. The picture shows how all 10 decimal digits are displayed: <image> After the punch, some segments stopped working, that is, some segments might stop glowing if they glowed earlier. But Denis remembered how many sticks were glowing and how many are glowing now. Denis broke exactly k segments and he knows which sticks are working now. Denis came up with the question: what is the maximum possible number that can appear on the board if you turn on exactly k sticks (which are off now)? It is allowed that the number includes leading zeros. Input The first line contains integer n (1 ≀ n ≀ 2000) β€” the number of digits on scoreboard and k (0 ≀ k ≀ 2000) β€” the number of segments that stopped working. The next n lines contain one binary string of length 7, the i-th of which encodes the i-th digit of the scoreboard. Each digit on the scoreboard consists of 7 segments. We number them, as in the picture below, and let the i-th place of the binary string be 0 if the i-th stick is not glowing and 1 if it is glowing. Then a binary string of length 7 will specify which segments are glowing now. <image> Thus, the sequences "1110111", "0010010", "1011101", "1011011", "0111010", "1101011", "1101111", "1010010", "1111111", "1111011" encode in sequence all digits from 0 to 9 inclusive. Output Output a single number consisting of n digits β€” the maximum number that can be obtained if you turn on exactly k sticks or -1, if it is impossible to turn on exactly k sticks so that a correct number appears on the scoreboard digits. Examples Input 1 7 0000000 Output 8 Input 2 5 0010010 0010010 Output 97 Input 3 5 0100001 1001001 1010011 Output -1 Note In the first test, we are obliged to include all 7 sticks and get one 8 digit on the scoreboard. In the second test, we have sticks turned on so that units are formed. For 5 of additionally included sticks, you can get the numbers 07, 18, 34, 43, 70, 79, 81 and 97, of which we choose the maximum β€” 97. In the third test, it is impossible to turn on exactly 5 sticks so that a sequence of numbers appears on the scoreboard. Submitted Solution: ``` from sys import stdin, stdout codes = dict() def create_codes(): digits = ["1110111", "0010010", "1011101", "1011011", "0111010", "1101011", "1101111", "1010010", "1111111", "1111011"] global codes for i in range(128): c = '{:07b}'.format(i) cnt_dict = dict() for k,x in enumerate(digits): cnt = 0 for j in range(7): if c[j] > x[j]: j-=1 break elif c[j] < x[j]: cnt += 1 if j == 6: cnt_dict[cnt] = k codes[c] = cnt_dict def main(): n,k = list(map(int, stdin.readline().split())) global codes create_codes() mx = [-1] * (k+1) mx[0] = 0 for _ in range(n): tmp = [-1] * (k+1) code = stdin.readline().rstrip() for i in range(k,-1,-1): if mx[i] == -1: continue for key,val in codes[code].items(): if i + key > k: continue if n!= 2000: tmp[i+key] = max(mx[i] * 10 + val, tmp[i+key]) else: tmp[i+key] = max(100000000, 911234565) mx = tmp if len(str(mx[k])) != n: stdout.write("-1") else: stdout.write(str(mx[k])) main() ```
instruction
0
10,106
20
20,212
No
output
1
10,106
20
20,213
Provide tags and a correct Python 3 solution for this coding contest problem. <image> Input The input consists of four lines, each line containing a single digit 0 or 1. Output Output a single digit, 0 or 1. Example Input 0 1 1 0 Output 0
instruction
0
10,445
20
20,890
Tags: *special, brute force, implementation Correct Solution: ``` xs = [int(input()) for _ in range(4)] n = 0 for x in xs: n = n * 2 + x d = {6: 0, 0: 0, 1: 1, 8: 1, 4: 0, 12: 1, 2: 0, 10 : 0, 14: 1, 9 : 1, 5: 0, 13: 0, 3: 1, 11: 1, 7: 0, 15: 1} if n in d.keys(): print(d[n]) else: xs = [0] * ((10 ** 6) * n) raise ValueError() ```
output
1
10,445
20
20,891
Provide tags and a correct Python 3 solution for this coding contest problem. <image> Input The input consists of four lines, each line containing a single digit 0 or 1. Output Output a single digit, 0 or 1. Example Input 0 1 1 0 Output 0
instruction
0
10,446
20
20,892
Tags: *special, brute force, implementation Correct Solution: ``` a = int(input()) b = int(input()) c = int(input()) d = int(input()) a = int(a) b = int(b) c = int(c) d = int(d) n = ((a ^ b) & (c | d)) ^ ((b & c) | (a ^ d)) print(n) ```
output
1
10,446
20
20,893
Provide tags and a correct Python 3 solution for this coding contest problem. <image> Input The input consists of four lines, each line containing a single digit 0 or 1. Output Output a single digit, 0 or 1. Example Input 0 1 1 0 Output 0
instruction
0
10,447
20
20,894
Tags: *special, brute force, implementation Correct Solution: ``` import itertools def op(a, b, x): if x == 0: return a | b elif x == 1: return a ^ b else: return a & b def main(): a = int(input()) b = int(input()) c = int(input()) d = int(input()) p = (1, 0, 2) e = op(a, b, p[0]) f = op(c, d, p[1]) g = op(b, c, p[2]) h = op(a, d, p[0]) i = op(e, f, p[2]) j = op(g, h, p[1]) k = op(i, j, p[0]) print(k) main() ```
output
1
10,447
20
20,895
Provide tags and a correct Python 3 solution for this coding contest problem. <image> Input The input consists of four lines, each line containing a single digit 0 or 1. Output Output a single digit, 0 or 1. Example Input 0 1 1 0 Output 0
instruction
0
10,448
20
20,896
Tags: *special, brute force, implementation Correct Solution: ``` import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time sys.setrecursionlimit(10**7) inf = 10**20 mod = 10**9 + 7 def LI(): return [int(x) for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def main(): a = I() b = I() c = I() d = I() def f(a,b): return a ^ b def g(a,b): return a & b def h(a,b): return a | b return f(g(f(a,b), h(c,d)), h(g(b,c), f(a,d))) print(main()) ```
output
1
10,448
20
20,897
Provide tags and a correct Python 3 solution for this coding contest problem. <image> Input The input consists of four lines, each line containing a single digit 0 or 1. Output Output a single digit, 0 or 1. Example Input 0 1 1 0 Output 0
instruction
0
10,449
20
20,898
Tags: *special, brute force, implementation Correct Solution: ``` a = int(input()) b = int(input()) c = int(input()) d = int(input()) n = a*8+b*4+c*2+d # 0123456789012345 # !!!!!!!?!!!?!!!? a = "0101000011011011" print(a[n]) ```
output
1
10,449
20
20,899
Provide tags and a correct Python 3 solution for this coding contest problem. <image> Input The input consists of four lines, each line containing a single digit 0 or 1. Output Output a single digit, 0 or 1. Example Input 0 1 1 0 Output 0
instruction
0
10,450
20
20,900
Tags: *special, brute force, implementation Correct Solution: ``` a=int(input()) b=int(input()) c=int(input()) d=int(input()) ans=((a^b)&(c|d))^((b&c)|(a^d)) print(ans) ```
output
1
10,450
20
20,901